diff --git a/dist/xeokit-sdk.cjs.js b/dist/xeokit-sdk.cjs.js index 2a7a9d548..13731cb39 100644 --- a/dist/xeokit-sdk.cjs.js +++ b/dist/xeokit-sdk.cjs.js @@ -62642,7 +62642,7 @@ class TrianglesInstancingOcclusionRenderer extends VBOSceneModelTriangleInstanci src.push("bool isPerspectiveMatrix(mat4 m) {"); src.push(" return (m[2][3] == - 1.0);"); src.push("}"); - src.push("in float isPerspective;"); + src.push("out float isPerspective;"); } if (clipping) { src.push("out vec4 vWorldPosition;"); diff --git a/dist/xeokit-sdk.es.js b/dist/xeokit-sdk.es.js index bbfd81b6e..5a009fdc7 100644 --- a/dist/xeokit-sdk.es.js +++ b/dist/xeokit-sdk.es.js @@ -62638,7 +62638,7 @@ class TrianglesInstancingOcclusionRenderer extends VBOSceneModelTriangleInstanci src.push("bool isPerspectiveMatrix(mat4 m) {"); src.push(" return (m[2][3] == - 1.0);"); src.push("}"); - src.push("in float isPerspective;"); + src.push("out float isPerspective;"); } if (clipping) { src.push("out vec4 vWorldPosition;"); diff --git a/dist/xeokit-sdk.es5.js b/dist/xeokit-sdk.es5.js index 9a97f7eff..0e197932e 100644 --- a/dist/xeokit-sdk.es5.js +++ b/dist/xeokit-sdk.es5.js @@ -16339,7 +16339,7 @@ src.push("int pickFlag = int(flags) >> 12 & 0xF;");src.push("if (pickFlag != ren src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); ");src.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));");src.push(" vWorldNormal = worldNormal;");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push("vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry normals fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i251=0;_i251> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);");src.push("}");return src;}}]);return TrianglesInstancingPickNormalsRenderer;}(VBOSceneModelTriangleInstancingRenderer);/** * @private */var TrianglesInstancingOcclusionRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl26){_inherits(TrianglesInstancingOcclusionRenderer,_VBOSceneModelTriangl26);var _super92=_createSuper(TrianglesInstancingOcclusionRenderer);function TrianglesInstancingOcclusionRenderer(){_classCallCheck(this,TrianglesInstancingOcclusionRenderer);return _super92.apply(this,arguments);}_createClass(TrianglesInstancingOcclusionRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing occlusion vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 color;");src.push("in float flags;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix -src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");this._addMatricesUniformBlockLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("in float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT +src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");this._addMatricesUniformBlockLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT // renderPass = COLOR_OPAQUE | COLOR_TRANSPARENT src.push("int colorFlag = int(flags) & 0xF;");src.push("if (colorFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push("vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing occlusion fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i252=0;_i252> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i253=0;_i253 0.0) { discard; }");src.push("}");}src.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); ");// Occluders are blue if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}}]);return TrianglesInstancingOcclusionRenderer;}(VBOSceneModelTriangleInstancingRenderer);/** diff --git a/dist/xeokit-sdk.min.cjs.js b/dist/xeokit-sdk.min.cjs.js index 99ebdaf4b..dc662f288 100644 --- a/dist/xeokit-sdk.min.cjs.js +++ b/dist/xeokit-sdk.min.cjs.js @@ -7,7 +7,7 @@ * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT */ -function es(e,t){t.length;const s=e.length,n=[],i=[],a=e=>{for(let s=0,n=e.meshIds.length;s{const s=t[e];let n,i;if(s.positionsCompressed){const e=wt.getPositionsBounds(s.positionsCompressed);n=wt.decompressPosition(e.min,s.positionsDecodeMatrix,[]),i=wt.decompressPosition(e.max,s.positionsDecodeMatrix,[])}else{const e=wt.getPositionsBounds(s.positions);n=e.min,i=e.max}n[0]+=s.origin[0],n[1]+=s.origin[1],n[2]+=s.origin[2],i[0]+=s.origin[0],i[1]+=s.origin[1],i[2]+=s.origin[2],h.expandAABB3Point3(l,n),h.expandAABB3Point3(l,i),o+=s.numPrimitives})),n[r]={aabb:l,numPrimitives:o,entityId:s.id}}let r,l=[],o={};if(Object.keys(n).length>0){r=function(e){const t=[];for(let s=0,n=e.length;s{s=Math.max(s,e.entity.id)}));const n=new Array(s+1);t.forEach((t=>{n[t.entity.id]=e.objects[t.entity.xeokitId]})),this._internalNodesList=n,this._lastVisibleFrameOfNodes=new Array(n.length),this._lastVisibleFrameOfNodes.fill(0)}_searchVisibleNodesWithFrustumCulling(){return this._aabbTree.searchCustom(((e,t)=>this._aabbIntersectsCameraFrustum(e,t)),(e=>this._aabbContainedInCameraFrustum(e)))}_markVisibleFrameOfVisibleNodes(e,t){const s=this._lastVisibleFrameOfNodes;for(let n=0,i=e.length;nthis._frustumProps.CAM_FACTOR_1?(s|=r<0?64:128,s&=-17):s&=-33;const l=is(h.dotVec3(i,this._frustumProps.up),a);Math.abs(l)>this._frustumProps.CAM_FACTOR_2?(s|=l<0?1024:2048,s&=-257):s&=-513}return 4&s&&8&s&&(s|=4096),64&s&&128&s&&(s|=8192),1024&s&&2048&s&&(s|=16384),e._check=s,s}}class rs{constructor(e,t){this.sceneModel=t,this.entities=[],this.meshes=[],this.finalized=!1}addEntity(e){if(this.finalized)throw"Already finalized";this.entities.push(e)}addMesh(e){if(this.finalized)throw"Already finalized";this.meshes.push(e)}finalize(e){if(this.finalized)throw"Already finalized";this.finalized=!0,this.VFCState=new as,this.VFCState.initializeVFCState(this.entities,this.meshes),this.VFCState.finalize(this.sceneModel,e),this._onSceneRendering=this.sceneModel.scene.on("rendering",(()=>this.applyViewFrustumCulling.call(this)))}applyViewFrustumCulling(){this.finalized&&this.VFCState.applyViewFrustumCulling(this.sceneModel)}destroy(){this.finalized&&this.sceneModel.off(this._onSceneRendering)}}class ls extends C{constructor(e,t={}){super(e,t),this._scene=e,this._vfcManagers={},this._vfcManagerList=[],this.enabled=t.enabled,this._init()}_init(){this._scene.on("rendering",(()=>{for(let e=0,t=this._vfcManagerList.length;e{this.glRedraw()})),this.canvas.on("webglContextFailed",(()=>{alert("xeokit failed to find WebGL!")})),this._renderer=new He(this,{transparent:n,alphaDepthMask:i}),this._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1;let e=null;this.getHash=function(){if(e)return e;const t=this.sectionPlanes;if(0===t.length)return this.hash=";";const s=[];for(let e=0,n=t.length;e0&&e.push("/lm"),this.reflectionMaps.length>0&&e.push("/rm"),e.push(";"),s=e.join(""),s},this.addLight=function(e){this.lights.push(e),n=null,s=null},this.removeLight=function(e){for(let t=0,i=this.lights.length;t{this._renderer.imageDirty()})),this.lod=new Xt(this,{enabled:t.lodEnabled}),this.vfc=new ls(this,{enabled:t.vfcEnabled})}_initDefaults(){}_addComponent(e){if(e.id&&this.components[e.id]&&(this.error("Component "+y.inQuotes(e.id)+" already exists in Scene - ignoring ID, will randomly-generate instead"),e.id=null),!e.id)for(void 0===window.nextID&&(window.nextID=0),e.id="__"+window.nextID++;this.components[e.id];)e.id=h.createUUID();this.components[e.id]=e;const t=e.type;let s=this.types[e.type];s||(s=this.types[t]={}),s[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}_removeComponent(e){var t=e.id,s=e.type;delete this.components[t];const n=this.types[s];n&&(delete n[t],y.isEmptyObject(n)&&delete this.types[s]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}_sectionPlaneCreated(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}_bitmapCreated(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}_lineSetCreated(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}_lightCreated(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}_lightMapCreated(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}_reflectionMapCreated(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}_sectionPlaneDestroyed(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}_bitmapDestroyed(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}_lineSetDestroyed(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}_lightDestroyed(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}_lightMapDestroyed(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}_reflectionMapDestroyed(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}_registerModel(e){this.models[e.id]=e,this._modelIds=null}_deregisterModel(e){const t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}_registerObject(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}_deregisterObject(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}_objectVisibilityUpdated(e,t=!0){e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}_objectXRayedUpdated(e,t=!0){e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}_objectHighlightedUpdated(e,t=!0){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null,t&&this.fire("objectHighlighted",e,!0)}_objectSelectedUpdated(e,t=!0){e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}_objectColorizeUpdated(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}_objectOpacityUpdated(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}_objectOffsetUpdated(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}_webglContextLost(){this.canvas.spinner.processes++;for(const e in this.components)if(this.components.hasOwnProperty(e)){const t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}_webglContextRestored(){const e=this.canvas.gl;for(const t in this.components)if(this.components.hasOwnProperty(t)){const s=this.components[t];s._webglContextRestored&&s._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}get capabilities(){return this._renderer.capabilities}get entityOffsetsEnabled(){return this._entityOffsetsEnabled}get pickSurfacePrecisionEnabled(){return!1}get logarithmicDepthBufferEnabled(){return this._logarithmicDepthBufferEnabled}set pbrEnabled(e){this._pbrEnabled=!!e,this.glRedraw()}get pbrEnabled(){return this._pbrEnabled}set dtxEnabled(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}get dtxEnabled(){return this._dtxEnabled}set colorTextureEnabled(e){this._colorTextureEnabled=!!e,this.glRedraw()}get colorTextureEnabled(){return this._colorTextureEnabled}doOcclusionTest(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}render(e){e&&P.runTasks();const t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),!e&&!this._renderer.needsRender())return;t.sceneId=this.id;const s=this._passes,n=this._clearEachPass;let i,a;for(i=0;ii&&(i=e[3]),e[4]>a&&(a=e[4]),e[5]>r&&(r=e[5]),c=!0}c||(t=-100,s=-100,n=-100,i=100,a=100,r=100),this._aabb[0]=t,this._aabb[1]=s,this._aabb[2]=n,this._aabb[3]=i,this._aabb[4]=a,this._aabb[5]=r,this._aabbDirty=!1}return this._aabb}_setAABBDirty(){this._aabbDirty=!0,this.fire("boundary")}pick(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");const s=e.includeEntities||e.include;s&&(e.includeEntityIds=os(this,s));const n=e.excludeEntities||e.exclude;return n&&(e.excludeEntityIds=os(this,n)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=this._renderer.pick(e,t))?(t.entity&&t.entity.fire&&t.entity.fire("picked",t),t):void 0}snapPick(e){return this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapMode||"vertex")}clear(){var e;for(const t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}clearLights(){const e=Object.keys(this.lights);for(let t=0,s=e.length;t{if(e.collidable){const o=e.aabb;o[0]a&&(a=o[3]),o[4]>r&&(r=o[4]),o[5]>l&&(l=o[5]),t=!0}})),t){const e=h.AABB3();return e[0]=s,e[1]=n,e[2]=i,e[3]=a,e[4]=r,e[5]=l,e}return this.aabb}setObjectsVisible(e,t){return this.withObjects(e,(e=>{const s=e.visible!==t;return e.visible=t,s}))}setObjectsCollidable(e,t){return this.withObjects(e,(e=>{const s=e.collidable!==t;return e.collidable=t,s}))}setObjectsCulled(e,t){return this.withObjects(e,(e=>{const s=e.culled!==t;return e.culled=t,s}))}setObjectsSelected(e,t){return this.withObjects(e,(e=>{const s=e.selected!==t;return e.selected=t,s}))}setObjectsHighlighted(e,t){return this.withObjects(e,(e=>{const s=e.highlighted!==t;return e.highlighted=t,s}))}setObjectsXRayed(e,t){return this.withObjects(e,(e=>{const s=e.xrayed!==t;return e.xrayed=t,s}))}setObjectsEdges(e,t){return this.withObjects(e,(e=>{const s=e.edges!==t;return e.edges=t,s}))}setObjectsColorized(e,t){return this.withObjects(e,(e=>{e.colorize=t}))}setObjectsOpacity(e,t){return this.withObjects(e,(e=>{const s=e.opacity!==t;return e.opacity=t,s}))}setObjectsPickable(e,t){return this.withObjects(e,(e=>{const s=e.pickable!==t;return e.pickable=t,s}))}setObjectsOffset(e,t){this.withObjects(e,(e=>{e.offset=t}))}withObjects(e,t){y.isString(e)&&(e=[e]);let s=!1;for(let n=0,i=e.length;n0,o=!!i.compressGeometry,c=[];c.push("#version 300 es"),c.push("// Lambertian drawing vertex shader"),c.push("in vec3 position;"),c.push("uniform mat4 modelMatrix;"),c.push("uniform mat4 viewMatrix;"),c.push("uniform mat4 projMatrix;"),c.push("uniform vec4 colorize;"),c.push("uniform vec3 offset;"),o&&c.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(c.push("uniform float logDepthBufFC;"),c.push("out float vFragDepth;"),c.push("bool isPerspectiveMatrix(mat4 m) {"),c.push(" return (m[2][3] == - 1.0);"),c.push("}"),c.push("out float isPerspective;"));l&&c.push("out vec4 vWorldPosition;");if(c.push("uniform vec4 lightAmbient;"),c.push("uniform vec4 materialColor;"),c.push("uniform vec3 materialEmissive;"),i.normalsBuf){c.push("in vec3 normal;"),c.push("uniform mat4 modelNormalMatrix;"),c.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=n.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),c.push(" }"),c.push(" return normalize(v);"),c.push("}"))}c.push("out vec4 vColor;"),"points"===i.primitiveName&&c.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(c.push("void billboard(inout mat4 mat) {"),c.push(" mat[0][0] = 1.0;"),c.push(" mat[0][1] = 0.0;"),c.push(" mat[0][2] = 0.0;"),"spherical"===a&&(c.push(" mat[1][0] = 0.0;"),c.push(" mat[1][1] = 1.0;"),c.push(" mat[1][2] = 0.0;")),c.push(" mat[2][0] = 0.0;"),c.push(" mat[2][1] = 0.0;"),c.push(" mat[2][2] =1.0;"),c.push("}"));c.push("void main(void) {"),c.push("vec4 localPosition = vec4(position, 1.0); "),c.push("vec4 worldPosition;"),o&&c.push("localPosition = positionsDecodeMatrix * localPosition;");i.normalsBuf&&(o?c.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):c.push("vec4 localNormal = vec4(normal, 0.0); "),c.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),c.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));c.push("mat4 viewMatrix2 = viewMatrix;"),c.push("mat4 modelMatrix2 = modelMatrix;"),r&&c.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===a||"cylindrical"===a?(c.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),c.push("billboard(modelMatrix2);"),c.push("billboard(viewMatrix2);"),c.push("billboard(modelViewMatrix);"),i.normalsBuf&&(c.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),c.push("billboard(modelNormalMatrix2);"),c.push("billboard(viewNormalMatrix2);"),c.push("billboard(modelViewNormalMatrix);")),c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i.normalsBuf&&c.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(c.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),c.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),c.push("float lambertian = 1.0;"),i.normalsBuf)for(let e=0,t=n.lights.length;e0,a=t.gammaOutput,r=[];r.push("#version 300 es"),r.push("// Lambertian drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(i){r.push("in vec4 vWorldPosition;"),r.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),r.push("}")}"points"===n.primitiveName&&(r.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),r.push("float r = dot(cxy, cxy);"),r.push("if (r > 1.0) {"),r.push(" discard;"),r.push("}"));t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");a?r.push("outColor = linearToGamma(vColor, gammaFactor);"):r.push("outColor = vColor;");return r.push("}"),r}(e)):(this.vertex=function(e){const t=e.scene;e._material;const s=e._state,n=t._sectionPlanesState,i=e._geometry._state,a=t._lightsState;let r;const l=s.billboard,o=s.background,c=s.stationary,u=function(e){if(!e._geometry._state.uvBuf)return!1;const t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),h=As(e),p=n.sectionPlanes.length>0,A=ps(e),d=!!i.compressGeometry,f=[];f.push("#version 300 es"),f.push("// Drawing vertex shader"),f.push("in vec3 position;"),d&&f.push("uniform mat4 positionsDecodeMatrix;");f.push("uniform mat4 modelMatrix;"),f.push("uniform mat4 viewMatrix;"),f.push("uniform mat4 projMatrix;"),f.push("out vec3 vViewPosition;"),f.push("uniform vec3 offset;"),p&&f.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(f.push("uniform float logDepthBufFC;"),f.push("out float vFragDepth;"),f.push("bool isPerspectiveMatrix(mat4 m) {"),f.push(" return (m[2][3] == - 1.0);"),f.push("}"),f.push("out float isPerspective;"));a.lightMaps.length>0&&f.push("out vec3 vWorldNormal;");if(h){f.push("in vec3 normal;"),f.push("uniform mat4 modelNormalMatrix;"),f.push("uniform mat4 viewNormalMatrix;"),f.push("out vec3 vViewNormal;");for(let e=0,t=a.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),f.push(" }"),f.push(" return normalize(v);"),f.push("}"))}u&&(f.push("in vec2 uv;"),f.push("out vec2 vUV;"),d&&f.push("uniform mat3 uvDecodeMatrix;"));i.colors&&(f.push("in vec4 color;"),f.push("out vec4 vColor;"));"points"===i.primitiveName&&f.push("uniform float pointSize;");"spherical"!==l&&"cylindrical"!==l||(f.push("void billboard(inout mat4 mat) {"),f.push(" mat[0][0] = 1.0;"),f.push(" mat[0][1] = 0.0;"),f.push(" mat[0][2] = 0.0;"),"spherical"===l&&(f.push(" mat[1][0] = 0.0;"),f.push(" mat[1][1] = 1.0;"),f.push(" mat[1][2] = 0.0;")),f.push(" mat[2][0] = 0.0;"),f.push(" mat[2][1] = 0.0;"),f.push(" mat[2][2] =1.0;"),f.push("}"));if(A){f.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(let e=0,t=a.lights.length;e0&&f.push("vWorldNormal = worldNormal;"),f.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),f.push("vec3 tmpVec3;"),f.push("float lightDist;");for(let e=0,t=a.lights.length;e0,o=As(e),c=n.uvBuf,u="PhongMaterial"===r.type,h="MetallicMaterial"===r.type,p="SpecularMaterial"===r.type,A=ps(e);t.gammaInput;const d=t.gammaOutput,f=[];f.push("#version 300 es"),f.push("// Drawing fragment shader"),f.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),f.push("precision highp float;"),f.push("precision highp int;"),f.push("#else"),f.push("precision mediump float;"),f.push("precision mediump int;"),f.push("#endif"),t.logarithmicDepthBufferEnabled&&(f.push("in float isPerspective;"),f.push("uniform float logDepthBufFC;"),f.push("in float vFragDepth;"));A&&(f.push("float unpackDepth (vec4 color) {"),f.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),f.push(" return dot(color, bitShift);"),f.push("}"));f.push("uniform float gammaFactor;"),f.push("vec4 linearToLinear( in vec4 value ) {"),f.push(" return value;"),f.push("}"),f.push("vec4 sRGBToLinear( in vec4 value ) {"),f.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),f.push("}"),f.push("vec4 gammaToLinear( in vec4 value) {"),f.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),f.push("}"),d&&(f.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),f.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),f.push("}"));if(l){f.push("in vec4 vWorldPosition;"),f.push("uniform bool clippable;");for(var I=0;I0&&(f.push("uniform samplerCube lightMap;"),f.push("uniform mat4 viewNormalMatrix;")),a.reflectionMaps.length>0&&f.push("uniform samplerCube reflectionMap;"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("uniform mat4 viewMatrix;"),f.push("#define PI 3.14159265359"),f.push("#define RECIPROCAL_PI 0.31830988618"),f.push("#define RECIPROCAL_PI2 0.15915494"),f.push("#define EPSILON 1e-6"),f.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),f.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),f.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),f.push("}"),f.push("struct IncidentLight {"),f.push(" vec3 color;"),f.push(" vec3 direction;"),f.push("};"),f.push("struct ReflectedLight {"),f.push(" vec3 diffuse;"),f.push(" vec3 specular;"),f.push("};"),f.push("struct Geometry {"),f.push(" vec3 position;"),f.push(" vec3 viewNormal;"),f.push(" vec3 worldNormal;"),f.push(" vec3 viewEyeDir;"),f.push("};"),f.push("struct Material {"),f.push(" vec3 diffuseColor;"),f.push(" float specularRoughness;"),f.push(" vec3 specularColor;"),f.push(" float shine;"),f.push("};"),u&&((a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = "+hs[a.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),f.push(" radiance *= PI;"),f.push(" reflectedLight.specular += radiance;")),f.push("}")),f.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),f.push(" vec3 irradiance = dotNL * directLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),f.push("}")),(h||p)&&(f.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),f.push(" float r = ggxRoughness + 0.0001;"),f.push(" return (2.0 / (r * r) - 2.0);"),f.push("}"),f.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),f.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),f.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),f.push("}"),a.reflectionMaps.length>0&&(f.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),f.push(" vec3 envMapColor = "+hs[a.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),f.push(" return envMapColor;"),f.push("}")),f.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),f.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),f.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),f.push("}"),f.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" return 1.0 / ( gl * gv );"),f.push("}"),f.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" return 0.5 / max( gv + gl, EPSILON );"),f.push("}"),f.push("float D_GGX(const in float alpha, const in float dotNH) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),f.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float alpha = ( roughness * roughness );"),f.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),f.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),f.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),f.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),f.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),f.push(" vec3 F = F_Schlick( specularColor, dotLH );"),f.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),f.push(" float D = D_GGX( alpha, dotNH );"),f.push(" return F * (G * D);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),f.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),f.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),f.push(" vec4 r = roughness * c0 + c1;"),f.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),f.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),f.push(" return specularColor * AB.x + AB.y;"),f.push("}"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),f.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),f.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),f.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),f.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),f.push("}")),f.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),f.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),f.push("}")));f.push("in vec3 vViewPosition;"),n.colors&&f.push("in vec4 vColor;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._occlusionMap||s._alphaMap)&&f.push("in vec2 vUV;");o&&(a.lightMaps.length>0&&f.push("in vec3 vWorldNormal;"),f.push("in vec3 vViewNormal;"));r.ambient&&f.push("uniform vec3 materialAmbient;");r.baseColor&&f.push("uniform vec3 materialBaseColor;");void 0!==r.alpha&&null!==r.alpha&&f.push("uniform vec4 materialAlphaModeCutoff;");r.emissive&&f.push("uniform vec3 materialEmissive;");r.diffuse&&f.push("uniform vec3 materialDiffuse;");void 0!==r.glossiness&&null!==r.glossiness&&f.push("uniform float materialGlossiness;");void 0!==r.shininess&&null!==r.shininess&&f.push("uniform float materialShininess;");r.specular&&f.push("uniform vec3 materialSpecular;");void 0!==r.metallic&&null!==r.metallic&&f.push("uniform float materialMetallic;");void 0!==r.roughness&&null!==r.roughness&&f.push("uniform float materialRoughness;");void 0!==r.specularF0&&null!==r.specularF0&&f.push("uniform float materialSpecularF0;");c&&s._ambientMap&&(f.push("uniform sampler2D ambientMap;"),s._ambientMap._state.matrix&&f.push("uniform mat4 ambientMapMatrix;"));c&&s._baseColorMap&&(f.push("uniform sampler2D baseColorMap;"),s._baseColorMap._state.matrix&&f.push("uniform mat4 baseColorMapMatrix;"));c&&s._diffuseMap&&(f.push("uniform sampler2D diffuseMap;"),s._diffuseMap._state.matrix&&f.push("uniform mat4 diffuseMapMatrix;"));c&&s._emissiveMap&&(f.push("uniform sampler2D emissiveMap;"),s._emissiveMap._state.matrix&&f.push("uniform mat4 emissiveMapMatrix;"));o&&c&&s._metallicMap&&(f.push("uniform sampler2D metallicMap;"),s._metallicMap._state.matrix&&f.push("uniform mat4 metallicMapMatrix;"));o&&c&&s._roughnessMap&&(f.push("uniform sampler2D roughnessMap;"),s._roughnessMap._state.matrix&&f.push("uniform mat4 roughnessMapMatrix;"));o&&c&&s._metallicRoughnessMap&&(f.push("uniform sampler2D metallicRoughnessMap;"),s._metallicRoughnessMap._state.matrix&&f.push("uniform mat4 metallicRoughnessMapMatrix;"));o&&s._normalMap&&(f.push("uniform sampler2D normalMap;"),s._normalMap._state.matrix&&f.push("uniform mat4 normalMapMatrix;"),f.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),f.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),f.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),f.push(" vec2 st0 = dFdx( uv.st );"),f.push(" vec2 st1 = dFdy( uv.st );"),f.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),f.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),f.push(" vec3 N = normalize( surf_norm );"),f.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),f.push(" mat3 tsn = mat3( S, T, N );"),f.push(" return normalize( tsn * mapN );"),f.push("}"));c&&s._occlusionMap&&(f.push("uniform sampler2D occlusionMap;"),s._occlusionMap._state.matrix&&f.push("uniform mat4 occlusionMapMatrix;"));c&&s._alphaMap&&(f.push("uniform sampler2D alphaMap;"),s._alphaMap._state.matrix&&f.push("uniform mat4 alphaMapMatrix;"));o&&c&&s._specularMap&&(f.push("uniform sampler2D specularMap;"),s._specularMap._state.matrix&&f.push("uniform mat4 specularMapMatrix;"));o&&c&&s._glossinessMap&&(f.push("uniform sampler2D glossinessMap;"),s._glossinessMap._state.matrix&&f.push("uniform mat4 glossinessMapMatrix;"));o&&c&&s._specularGlossinessMap&&(f.push("uniform sampler2D materialSpecularGlossinessMap;"),s._specularGlossinessMap._state.matrix&&f.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));o&&(s._diffuseFresnel||s._specularFresnel||s._alphaFresnel||s._emissiveFresnel||s._reflectivityFresnel)&&(f.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),f.push(" float fr = abs(dot(eyeDir, normal));"),f.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),f.push(" return pow(finalFr, power);"),f.push("}"),s._diffuseFresnel&&(f.push("uniform float diffuseFresnelCenterBias;"),f.push("uniform float diffuseFresnelEdgeBias;"),f.push("uniform float diffuseFresnelPower;"),f.push("uniform vec3 diffuseFresnelCenterColor;"),f.push("uniform vec3 diffuseFresnelEdgeColor;")),s._specularFresnel&&(f.push("uniform float specularFresnelCenterBias;"),f.push("uniform float specularFresnelEdgeBias;"),f.push("uniform float specularFresnelPower;"),f.push("uniform vec3 specularFresnelCenterColor;"),f.push("uniform vec3 specularFresnelEdgeColor;")),s._alphaFresnel&&(f.push("uniform float alphaFresnelCenterBias;"),f.push("uniform float alphaFresnelEdgeBias;"),f.push("uniform float alphaFresnelPower;"),f.push("uniform vec3 alphaFresnelCenterColor;"),f.push("uniform vec3 alphaFresnelEdgeColor;")),s._reflectivityFresnel&&(f.push("uniform float materialSpecularF0FresnelCenterBias;"),f.push("uniform float materialSpecularF0FresnelEdgeBias;"),f.push("uniform float materialSpecularF0FresnelPower;"),f.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),f.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),s._emissiveFresnel&&(f.push("uniform float emissiveFresnelCenterBias;"),f.push("uniform float emissiveFresnelEdgeBias;"),f.push("uniform float emissiveFresnelPower;"),f.push("uniform vec3 emissiveFresnelCenterColor;"),f.push("uniform vec3 emissiveFresnelEdgeColor;")));if(f.push("uniform vec4 lightAmbient;"),o)for(let e=0,t=a.lights.length;e 0.0) { discard; }"),f.push("}")}"points"===n.primitiveName&&(f.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),f.push("float r = dot(cxy, cxy);"),f.push("if (r > 1.0) {"),f.push(" discard;"),f.push("}"));f.push("float occlusion = 1.0;"),r.ambient?f.push("vec3 ambientColor = materialAmbient;"):f.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");r.diffuse?f.push("vec3 diffuseColor = materialDiffuse;"):r.baseColor?f.push("vec3 diffuseColor = materialBaseColor;"):f.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");n.colors&&f.push("diffuseColor *= vColor.rgb;");r.emissive?f.push("vec3 emissiveColor = materialEmissive;"):f.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");r.specular?f.push("vec3 specular = materialSpecular;"):f.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==r.alpha?f.push("float alpha = materialAlphaModeCutoff[0];"):f.push("float alpha = 1.0;");n.colors&&f.push("alpha *= vColor.a;");void 0!==r.glossiness?f.push("float glossiness = materialGlossiness;"):f.push("float glossiness = 1.0;");void 0!==r.metallic?f.push("float metallic = materialMetallic;"):f.push("float metallic = 1.0;");void 0!==r.roughness?f.push("float roughness = materialRoughness;"):f.push("float roughness = 1.0;");void 0!==r.specularF0?f.push("float specularF0 = materialSpecularF0;"):f.push("float specularF0 = 1.0;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._occlusionMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._alphaMap)&&(f.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),f.push("vec2 textureCoord;"));c&&s._ambientMap&&(s._ambientMap._state.matrix?f.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),f.push("ambientTexel = "+hs[s._ambientMap._state.encoding]+"(ambientTexel);"),f.push("ambientColor *= ambientTexel.rgb;"));c&&s._diffuseMap&&(s._diffuseMap._state.matrix?f.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),f.push("diffuseTexel = "+hs[s._diffuseMap._state.encoding]+"(diffuseTexel);"),f.push("diffuseColor *= diffuseTexel.rgb;"),f.push("alpha *= diffuseTexel.a;"));c&&s._baseColorMap&&(s._baseColorMap._state.matrix?f.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),f.push("baseColorTexel = "+hs[s._baseColorMap._state.encoding]+"(baseColorTexel);"),f.push("diffuseColor *= baseColorTexel.rgb;"),f.push("alpha *= baseColorTexel.a;"));c&&s._emissiveMap&&(s._emissiveMap._state.matrix?f.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),f.push("emissiveTexel = "+hs[s._emissiveMap._state.encoding]+"(emissiveTexel);"),f.push("emissiveColor = emissiveTexel.rgb;"));c&&s._alphaMap&&(s._alphaMap._state.matrix?f.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("alpha *= texture(alphaMap, textureCoord).r;"));c&&s._occlusionMap&&(s._occlusionMap._state.matrix?f.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(o&&(a.lights.length>0||a.lightMaps.length>0||a.reflectionMaps.length>0)){c&&s._normalMap?(s._normalMap._state.matrix?f.push("textureCoord = (normalMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):f.push("vec3 viewNormal = normalize(vViewNormal);"),c&&s._specularMap&&(s._specularMap._state.matrix?f.push("textureCoord = (specularMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("specular *= texture(specularMap, textureCoord).rgb;")),c&&s._glossinessMap&&(s._glossinessMap._state.matrix?f.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("glossiness *= texture(glossinessMap, textureCoord).r;")),c&&s._specularGlossinessMap&&(s._specularGlossinessMap._state.matrix?f.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),f.push("specular *= specGlossRGB.rgb;"),f.push("glossiness *= specGlossRGB.a;")),c&&s._metallicMap&&(s._metallicMap._state.matrix?f.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("metallic *= texture(metallicMap, textureCoord).r;")),c&&s._roughnessMap&&(s._roughnessMap._state.matrix?f.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("roughness *= texture(roughnessMap, textureCoord).r;")),c&&s._metallicRoughnessMap&&(s._metallicRoughnessMap._state.matrix?f.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),f.push("metallic *= metalRoughRGB.b;"),f.push("roughness *= metalRoughRGB.g;")),f.push("vec3 viewEyeDir = normalize(-vViewPosition);"),s._diffuseFresnel&&(f.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),f.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),s._specularFresnel&&(f.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),f.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),s._alphaFresnel&&(f.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),f.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),s._emissiveFresnel&&(f.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),f.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),f.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),f.push(" discard;"),f.push("}"),f.push("IncidentLight light;"),f.push("Material material;"),f.push("Geometry geometry;"),f.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),f.push("vec3 viewLightDir;"),u&&(f.push("material.diffuseColor = diffuseColor;"),f.push("material.specularColor = specular;"),f.push("material.shine = materialShininess;")),p&&(f.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),f.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),f.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),f.push("material.specularColor = specular;")),h&&(f.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),f.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),f.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),f.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),f.push("geometry.position = vViewPosition;"),a.lightMaps.length>0&&f.push("geometry.worldNormal = normalize(vWorldNormal);"),f.push("geometry.viewNormal = viewNormal;"),f.push("geometry.viewEyeDir = viewEyeDir;"),u&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePhongLightMapping(geometry, material, reflectedLight);"),(p||h)&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePBRLightMapping(geometry, material, reflectedLight);"),f.push("float shadow = 1.0;"),f.push("float shadowAcneRemover = 0.007;"),f.push("vec3 fragmentDepth;"),f.push("float texelSize = 1.0 / 1024.0;"),f.push("float amountInLight = 0.0;"),f.push("vec3 shadowCoord;"),f.push("vec4 rgbaDepth;"),f.push("float depth;");for(let e=0,t=a.lights.length;e0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(u=0,h=a.sectionPlanes.length;u0&&i.lightMaps[0].texture&&this._uLightMap&&(l.bindTexture(this._uLightMap,i.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),i.reflectionMaps.length>0&&i.reflectionMaps[0].texture&&this._uReflectionMap&&(l.bindTexture(this._uReflectionMap,i.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),this._uGammaFactor&&n.uniform1f(this._uGammaFactor,s.gammaFactor),this._baseTextureUnit=e.textureUnit};class ms{constructor(e){this.vertex=function(e){const t=e.scene,s=t._lightsState,n=function(e){const t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),i=t._sectionPlanesState.sectionPlanes.length>0,a=!!e._geometry._state.compressGeometry,r=e._state.billboard,l=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// EmphasisFillShaderSource vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("uniform vec4 colorize;"),o.push("uniform vec3 offset;"),a&&o.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));i&&o.push("out vec4 vWorldPosition;");if(o.push("uniform vec4 lightAmbient;"),o.push("uniform vec4 fillColor;"),n){o.push("in vec3 normal;"),o.push("uniform mat4 modelNormalMatrix;"),o.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),o.push(" }"),o.push(" return normalize(v);"),o.push("}"))}o.push("out vec4 vColor;"),("spherical"===r||"cylindrical"===r)&&(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),o.push("vec4 worldPosition;"),a&&o.push("localPosition = positionsDecodeMatrix * localPosition;");n&&(a?o.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):o.push("vec4 localNormal = vec4(normal, 0.0); "),o.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),o.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),l&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===r||"cylindrical"===r?(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"),o.push("billboard(modelViewMatrix);"),n&&(o.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),o.push("billboard(modelNormalMatrix2);"),o.push("billboard(viewNormalMatrix2);"),o.push("billboard(modelViewNormalMatrix);")),o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));n&&o.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),n)for(let e=0,t=s.lights.length;e0,a=[];a.push("#version 300 es"),a.push("// Lambertian drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}"points"===e._geometry._state.primitiveName&&(a.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),a.push("float r = dot(cxy, cxy);"),a.push("if (r > 1.0) {"),a.push(" discard;"),a.push("}"));t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const vs=new e({}),ws=h.vec3(),gs=function(e,t){this.id=vs.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new ms(t),this._allocate(t)},Ts={};gs.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=Ts[t];return s||(s=new gs(t,e),Ts[t]=s,A.memory.programs++),s._useCount++,s},gs.prototype.put=function(){0==--this._useCount&&(vs.removeItem(this.id),this._program&&this._program.destroy(),delete Ts[this._hash],A.memory.programs--)},gs.prototype.webglContextRestored=function(){this._program=null},gs.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl,r=0===s?t._xrayMaterial._state:1===s?t._highlightMaterial._state:t._selectedMaterial._state,l=t._state,o=t._geometry._state,c=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,c?e.getRTCViewMatrix(l.originHash,c):i.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.viewNormalMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Edges drawing vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec4 edgeColor;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));s&&r.push("out vec4 vWorldPosition;");r.push("out vec4 vColor;"),("spherical"===i||"cylindrical"===i)&&(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r.push("vColor = edgeColor;"),s&&r.push("vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=e.scene._sectionPlanesState,n=e.scene.gammaOutput,i=s.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Edges drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const bs=new e({}),Ds=h.vec3(),Ps=function(e,t){this.id=bs.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Es(t),this._allocate(t)},Rs={};Ps.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=Rs[t];return s||(s=new Ps(t,e),Rs[t]=s,A.memory.programs++),s._useCount++,s},Ps.prototype.put=function(){0==--this._useCount&&(bs.removeItem(this.id),this._program&&this._program.destroy(),delete Rs[this._hash],A.memory.programs--)},Ps.prototype.webglContextRestored=function(){this._program=null},Ps.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl;let r;const l=t._state,o=t._geometry,c=o._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(l.originHash,u):i.viewMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh picking vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("out vec4 vViewPosition;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==i&&"cylindrical"!==i||(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"));r.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(i.push("uniform vec4 pickColor;"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = pickColor; "),i.push("}"),i}(e)}}const _s=h.vec3(),Bs=function(e,t){this._hash=e,this._shaderSource=new Cs(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Os={};Bs.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let s=Os[t];if(!s){if(s=new Bs(t,e),s.errors)return console.log(s.errors.join("\n")),null;Os[t]=s,A.memory.programs++}return s._useCount++,s},Bs.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Os[this._hash],A.memory.programs--)},Bs.prototype.webglContextRestored=function(){this._program=null},Bs.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(i.originHash,l):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t>24&255,u=o>>16&255,h=o>>8&255,p=255&o;n.uniform4f(this._uPickColor,p/255,h/255,u/255,c/255),r.indicesBuf?(n.drawElements(r.primitive,r.indicesBuf.numItems,r.indicesBuf.itemType,0),e.drawElements++):r.positions&&n.drawArrays(n.TRIANGLES,0,r.positions.numItems)},Bs.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new we(s,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0,n=!!e._geometry._state.compressGeometry;e._state.billboard,e._state.stationary;const i=[];i.push("#version 300 es"),i.push("// Surface picking vertex shader"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform vec3 offset;"),s&&(i.push("uniform bool clippable;"),i.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"));i.push("out vec4 vColor;"),n&&i.push("uniform mat4 positionsDecodeMatrix;");i.push("void main(void) {"),i.push("vec4 localPosition = vec4(position, 1.0); "),n&&i.push("localPosition = positionsDecodeMatrix * localPosition;");i.push(" vec4 worldPosition = modelMatrix * localPosition; "),i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),s&&i.push(" vWorldPosition = worldPosition;");i.push(" vColor = color;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return i.push("gl_Position = clipPos;"),i.push("}"),i}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Surface picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = vColor;"),i.push("}"),i}(e)}}const Ns=h.vec3(),xs=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Ss(t),this._allocate(t)},Ls={};xs.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=Ls[t];if(!s){if(s=new xs(t,e),s.errors)return console.log(s.errors.join("\n")),null;Ls[t]=s,A.memory.programs++}return s._useCount++,s},xs.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Ls[this._hash],A.memory.programs--)},xs.prototype.webglContextRestored=function(){this._program=null},xs.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry,l=t._geometry._state,o=t.origin,c=a.backfaces,u=a.frontface,h=s.camera.project,p=r._getPickTrianglePositions(),A=r._getPickTriangleColors();if(this._program.bind(),e.useProgram++,s.logarithmicDepthBufferEnabled){const e=2/(Math.log(h.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,e)}if(n.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCPickViewMatrix(i.originHash,o):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh occlusion vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push("}"),i}(e)}}const Fs=h.vec3(),Hs=function(e,t){this._hash=e,this._shaderSource=new Ms(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Us={};Hs.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";");let s=Us[t];if(!s){if(s=new Hs(t,e),s.errors)return console.log(s.errors.join("\n")),null;Us[t]=s,A.memory.programs++}return s._useCount++,s},Hs.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Us[this._hash],A.memory.programs--)},Hs.prototype.webglContextRestored=function(){this._program=null},Hs.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._material._state,a=t._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),i.id!==this._lastMaterialId){const t=i.backfaces;e.backfaces!==t&&(t?n.disable(n.CULL_FACE):n.enable(n.CULL_FACE),e.backfaces=t);const s=i.frontface;e.frontface!==s&&(s?n.frontFace(n.CCW):n.frontFace(n.CW),e.frontface=s),this._lastMaterialId=i.id}const o=s.camera;if(n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCViewMatrix(a.originHash,l):o.viewMatrix),a.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,s=!!e._geometry._state.compressGeometry,n=[];n.push("// Mesh shadow vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),n.push("uniform vec3 offset;"),s&&n.push("uniform mat4 positionsDecodeMatrix;");t&&n.push("out vec4 vWorldPosition;");n.push("void main(void) {"),n.push("vec4 localPosition = vec4(position, 1.0); "),n.push("vec4 worldPosition;"),s&&n.push("localPosition = positionsDecodeMatrix * localPosition;");n.push("worldPosition = modelMatrix * localPosition;"),n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&n.push("vWorldPosition = worldPosition;");return n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n}(e),this.fragment=function(e){const t=e.scene;t.canvas.gl;const s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("// Mesh shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}return i.push("outColor = encodeFloat(gl_FragCoord.z);"),i.push("}"),i}(e)}}const Vs=function(e,t){this._hash=e,this._shaderSource=new Gs(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},js={};Vs.get=function(e){const t=e.scene,s=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let n=js[s];if(!n){if(n=new Vs(s,e),n.errors)return console.log(n.errors.join("\n")),null;js[s]=n,A.memory.programs++}return n._useCount++,n},Vs.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete js[this._hash],A.memory.programs--)},Vs.prototype.webglContextRestored=function(){this._program=null},Vs.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene.canvas.gl,n=t._material._state,i=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.id!==this._lastMaterialId){const t=n.backfaces;e.backfaces!==t&&(t?s.disable(s.CULL_FACE):s.enable(s.CULL_FACE),e.backfaces=t);const i=n.frontface;e.frontface!==i&&(i?s.frontFace(s.CCW):s.frontFace(s.CW),e.frontface=i),e.lineWidth!==n.lineWidth&&(s.lineWidth(n.lineWidth),e.lineWidth=n.lineWidth),this._uPointSize&&s.uniform1i(this._uPointSize,n.pointSize),this._lastMaterialId=n.id}if(s.uniformMatrix4fv(this._uModelMatrix,s.FALSE,t.worldMatrix),i.combineGeometry){const n=t.vertexBufs;n.id!==this._lastVertexBufsId&&(n.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(n.positionsBuf,n.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),this._lastVertexBufsId=n.id)}this._uClippable&&s.uniform1i(this._uClippable,t._state.clippable),s.uniform3fv(this._uOffset,t._state.offset),i.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,i.positionsDecodeMatrix),i.combineGeometry?i.indicesBufCombined&&(i.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(i.positionsBuf,i.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),i.indicesBuf&&(i.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=i.id),i.combineGeometry?i.indicesBufCombined&&(s.drawElements(i.primitive,i.indicesBufCombined.numItems,i.indicesBufCombined.itemType,0),e.drawElements++):i.indicesBuf?(s.drawElements(i.primitive,i.indicesBuf.numItems,i.indicesBuf.itemType,0),e.drawElements++):i.positions&&(s.drawArrays(s.TRIANGLES,0,i.positions.numItems),e.drawArrays++)},Vs.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new we(s,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uShadowViewMatrix=n.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=n.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0){let e,t,i,a,r;for(let l=0,o=this._uSectionPlanes.length;l0)for(let s=0;s0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}const tn=function(){const e=h.vec3(),t=h.vec3(),s=h.vec3(),n=h.vec3(),i=h.vec3(),a=h.vec3(),r=h.vec4(),l=h.vec3(),o=h.vec3(),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3(),y=h.vec4(),m=h.vec4(),v=h.vec4(),w=h.vec3(),g=h.vec3(),T=h.vec3(),E=h.vec3(),b=h.vec3(),D=h.vec3(),P=h.vec3(),R=h.vec3(),C=h.vec3(),_=h.vec3(),O=h.vec3();return function(S,N,x,L){var M=L.primIndex;if(null!=M&&M>-1){const G=S.geometry._state,V=S.scene,j=V.camera,k=V.canvas;if("triangles"===G.primitiveName){L.primitive="triangle";const V=M,Q=G.indices,W=G.positions;let z,K,Y;if(Q){var F=Q[V+0],H=Q[V+1],U=Q[V+2];a[0]=F,a[1]=H,a[2]=U,L.indices=a,z=3*F,K=3*H,Y=3*U}else z=3*V,K=z+3,Y=K+3;if(s[0]=W[z+0],s[1]=W[z+1],s[2]=W[z+2],n[0]=W[K+0],n[1]=W[K+1],n[2]=W[K+2],i[0]=W[Y+0],i[1]=W[Y+1],i[2]=W[Y+2],G.compressGeometry){const e=G.positionsDecodeMatrix;e&&(wt.decompressPosition(s,e,s),wt.decompressPosition(n,e,n),wt.decompressPosition(i,e,i))}L.canvasPos?h.canvasPosToLocalRay(k.canvas,S.origin?B(N,S.origin):N,x,S.worldMatrix,L.canvasPos,e,t):L.origin&&L.direction&&h.worldRayToLocalRay(S.worldMatrix,L.origin,L.direction,e,t),h.normalizeVec3(t),h.rayPlaneIntersect(e,t,s,n,i,r),L.localPos=r,L.position=r,y[0]=r[0],y[1]=r[1],y[2]=r[2],y[3]=1,h.transformVec4(S.worldMatrix,y,m),l[0]=m[0],l[1]=m[1],l[2]=m[2],L.canvasPos&&S.origin&&(l[0]+=S.origin[0],l[1]+=S.origin[1],l[2]+=S.origin[2]),L.worldPos=l,h.transformVec4(j.matrix,m,v),o[0]=v[0],o[1]=v[1],o[2]=v[2],L.viewPos=o,h.cartesianToBarycentric(r,s,n,i,c),L.bary=c;const X=G.normals;if(X){if(G.compressGeometry){const e=3*F,t=3*H,s=3*U;wt.decompressNormal(X.subarray(e,e+2),u),wt.decompressNormal(X.subarray(t,t+2),p),wt.decompressNormal(X.subarray(s,s+2),A)}else u[0]=X[z],u[1]=X[z+1],u[2]=X[z+2],p[0]=X[K],p[1]=X[K+1],p[2]=X[K+2],A[0]=X[Y],A[1]=X[Y+1],A[2]=X[Y+2];const e=h.addVec3(h.addVec3(h.mulVec3Scalar(u,c[0],w),h.mulVec3Scalar(p,c[1],g),T),h.mulVec3Scalar(A,c[2],E),b);L.worldNormal=h.normalizeVec3(h.transformVec3(S.worldNormalMatrix,e,D))}const q=G.uv;if(q){if(d[0]=q[2*F],d[1]=q[2*F+1],f[0]=q[2*H],f[1]=q[2*H+1],I[0]=q[2*U],I[1]=q[2*U+1],G.compressGeometry){const e=G.uvDecodeMatrix;e&&(wt.decompressUV(d,e,d),wt.decompressUV(f,e,f),wt.decompressUV(I,e,I))}L.uv=h.addVec3(h.addVec3(h.mulVec2Scalar(d,c[0],P),h.mulVec2Scalar(f,c[1],R),C),h.mulVec2Scalar(I,c[2],_),O)}}}}}();function sn(e={}){let t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);let s=e.radiusBottom||1;s<0&&(console.error("negative radiusBottom not allowed - will invert"),s*=-1);let n=e.height||1;n<0&&(console.error("negative height not allowed - will invert"),n*=-1);let i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);let a=e.heightSegments||1;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),a<1&&(a=1);const r=!!e.openEnded;let l=e.center;const o=l?l[0]:0,c=l?l[1]:0,u=l?l[2]:0,h=n/2,p=n/a,A=2*Math.PI/i,d=1/i,f=(t-s)/a,I=[],m=[],v=[],w=[];let g,T,E,b,D,P,R,C,_,B,O;const S=(90-180*Math.atan(n/(s-t))/Math.PI)/90;for(g=0;g<=a;g++)for(D=t-g*f,P=h-g*p,T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),m.push(D*E),m.push(S),m.push(D*b),v.push(T*d),v.push(1*g/a),I.push(D*E+o),I.push(P+c),I.push(D*b+u);for(g=0;g0){for(_=I.length/3,m.push(0),m.push(1),m.push(0),v.push(.5),v.push(.5),I.push(0+o),I.push(h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,m.push(t*E),m.push(1),m.push(t*b),v.push(B),v.push(O),I.push(t*E+o),I.push(h+c),I.push(t*b+u);for(T=0;T0){for(_=I.length/3,m.push(0),m.push(-1),m.push(0),v.push(.5),v.push(.5),I.push(0+o),I.push(0-h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,m.push(s*E),m.push(-1),m.push(s*b),v.push(B),v.push(O),I.push(s*E+o),I.push(0-h+c),I.push(s*b+u);for(T=0;T":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function rn(e={}){var t=e.origin||[0,0,0],s=t[0],n=t[1],i=t[2],a=e.size||1,r=[],l=[],o=e.text;y.isNumeric(o)&&(o=""+o);for(var c,u,h,p,A,d,f,I,m,v=(o||"").split("\n"),w=0,g=0,T=.04,E=0;E0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length){const e=this._children.splice();let t;for(let s=0,n=e.length;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=Dn(s,this.wrapS);a&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,a);const r=Dn(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=Dn(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,_n(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,_n(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Dn(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Dn(s,this.magFilter)));const l=Dn(s,this.format,this.encoding),o=Dn(s,this.type),c=Cn(s,this.internalFormat,l,o,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,n,c,e[0].width,e[0].height);for(let t=0,n=e.length;t>t;return e+1}class Nn extends C{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new Ve({texture:new Rn({gl:this.scene.canvas.gl}),matrix:h.identityMat4(),hasMatrix:t.translate&&(0!==t.translate[0]||0!==t.translate[1])||!!t.rotate||t.scale&&(0!==t.scale[0]||0!==t.scale[1]),minFilter:this._checkMinFilter(t.minFilter),magFilter:this._checkMagFilter(t.magFilter),wrapS:this._checkWrapS(t.wrapS),wrapT:this._checkWrapT(t.wrapT),flipY:this._checkFlipY(t.flipY),encoding:this._checkEncoding(t.encoding)}),this._src=null,this._image=null,this._translate=h.vec2([0,0]),this._scale=h.vec2([1,1]),this._rotate=h.vec2([0,0]),this._matrixDirty=!1,this.translate=t.translate,this.scale=t.scale,this.rotate=t.rotate,t.src?this.src=t.src:t.image&&(this.image=t.image),A.memory.textures++}_checkMinFilter(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}_checkMagFilter(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}_checkWrapS(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkWrapT(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this._state.texture=new Rn({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}_update(){const e=this._state;if(this._matrixDirty){let t,s;0===this._translate[0]&&0===this._translate[1]||(t=h.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(s=h.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?h.mulMat4(t,s):s),0!==this._rotate&&(s=h.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?h.mulMat4(t,s):s),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=Bn(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}get image(){return this._image}set src(e){this.scene.loading++,this.scene.canvas.spinner.processes++;const t=this;let s=new Image;s.onload=function(){s=Bn(s),t._state.texture.setImage(s,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},s.src=e,this._src=e,this._image=null}get src(){return this._src}set translate(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}get translate(){return this._translate}set scale(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}get scale(){return this._scale}set rotate(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}get rotate(){return this._rotate}get minFilter(){return this._state.minFilter}get magFilter(){return this._state.magFilter}get wrapS(){return this._state.wrapS}get wrapT(){return this._state.wrapT}get flipY(){return this._state.flipY}get encoding(){return this._state.encoding}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),A.memory.textures--}}const xn=A.memory,Ln=h.AABB3();class Mn extends pt{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new Ve({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._aabb=null,this._obb=h.OBB3();const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(t.indices){var i;if(t.positionsDecodeMatrix);else{const e=wt.getPositionsBounds(t.positions),a=wt.compressPositions(t.positions,e.min,e.max);i=a.quantized,s.positionsDecodeMatrix=a.decodeMatrix,s.positionsBuf=new ge(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),xn.positions+=s.positionsBuf.numItems,h.positions3ToAABB3(t.positions,this._aabb),h.positions3ToAABB3(i,Ln,s.positionsDecodeMatrix),h.AABB3ToOBB3(Ln,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);s.colorsBuf=new ge(n,n.ARRAY_BUFFER,e,e.length,4,n.STATIC_DRAW),xn.colors+=s.colorsBuf.numItems}if(t.uv){const e=wt.getUVBounds(t.uv),i=wt.compressUVs(t.uv,e.min,e.max),a=i.quantized;s.uvDecodeMatrix=i.decodeMatrix,s.uvBuf=new ge(n,n.ARRAY_BUFFER,a,a.length,2,n.STATIC_DRAW),xn.uvs+=s.uvBuf.numItems}if(t.normals){const e=wt.compressNormals(t.normals);let i=s.compressGeometry;s.normalsBuf=new ge(n,n.ARRAY_BUFFER,e,e.length,3,n.STATIC_DRAW,i),xn.normals+=s.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);s.indicesBuf=new ge(n,n.ELEMENT_ARRAY_BUFFER,e,e.length,1,n.STATIC_DRAW),xn.indices+=s.indicesBuf.numItems;const a=At(i,e,s.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new ge(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),xn.meshes++}else this.error("Config expected: indices");else this.error("Config expected: positions")}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf}get primitive(){return this._state.primitiveName}get aabb(){return this._aabb}get obb(){return this._obb}get numTriangles(){return this._numTriangles}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),xn.meshes--}}var Fn={};function Hn(e={}){let t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);let s=e.divisions||1;s<0&&(console.error("negative divisions not allowed - will invert"),s*=-1),s<1&&(s=1),t=t||10,s=s||10;const n=t/s,i=t/2,a=[],r=[];let l=0;for(let e=0,t=-i;e<=s;e++,t+=n)a.push(-i),a.push(0),a.push(t),a.push(i),a.push(0),a.push(t),a.push(t),a.push(0),a.push(-i),a.push(t),a.push(0),a.push(i),r.push(l++),r.push(l++),r.push(l++),r.push(l++);return y.apply(e,{primitive:"lines",positions:a,indices:r})}function Un(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);let n=e.xSegments||1;n<0&&(console.error("negative xSegments not allowed - will invert"),n*=-1),n<1&&(n=1);let i=e.xSegments||1;i<0&&(console.error("negative zSegments not allowed - will invert"),i*=-1),i<1&&(i=1);const a=e.center,r=a?a[0]:0,l=a?a[1]:0,o=a?a[2]:0,c=t/2,u=s/2,h=Math.floor(n)||1,p=Math.floor(i)||1,A=h+1,d=p+1,f=t/h,I=s/p,m=new Float32Array(A*d*3),v=new Float32Array(A*d*3),w=new Float32Array(A*d*2);let g,T,E,b,D,P,R,C=0,_=0;for(g=0;g65535?Uint32Array:Uint16Array)(h*p*6);for(g=0;g360&&(a=360);const r=e.center;let l=r?r[0]:0,o=r?r[1]:0;const c=r?r[2]:0,u=[],p=[],A=[],d=[];let f,I,m,v,w,g,T,E,b,D,P,R;for(E=0;E<=i;E++)for(T=0;T<=n;T++)f=T/n*a,I=.785398+E/i*Math.PI*2,l=t*Math.cos(f),o=t*Math.sin(f),m=(t+s*Math.cos(I))*Math.cos(f),v=(t+s*Math.cos(I))*Math.sin(f),w=s*Math.sin(I),u.push(m+l),u.push(v+o),u.push(w+c),A.push(1-T/n),A.push(E/i),g=h.normalizeVec3(h.subVec3([m,v,w],[l,o,c],[]),[]),p.push(g[0]),p.push(g[1]),p.push(g[2]);for(E=1;E<=i;E++)for(T=1;T<=n;T++)b=(n+1)*E+T-1,D=(n+1)*(E-1)+T-1,P=(n+1)*(E-1)+T,R=(n+1)*E+T,d.push(b),d.push(D),d.push(P),d.push(P),d.push(R),d.push(b);return y.apply(e,{positions:u,normals:p,uv:A,indices:d})}Fn.load=function(e,t){var s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="arraybuffer",s.onload=function(e){t(e.target.response)},s.send()},Fn.save=function(e,t){var s="data:application/octet-stream;base64,"+btoa(Fn.parse._buffToStr(e));window.location.href=s},Fn.clone=function(e){return JSON.parse(JSON.stringify(e))},Fn.bin={},Fn.bin.f=new Float32Array(1),Fn.bin.fb=new Uint8Array(Fn.bin.f.buffer),Fn.bin.rf=function(e,t){for(var s=Fn.bin.f,n=Fn.bin.fb,i=0;i<4;i++)n[i]=e[t+i];return s[0]},Fn.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Fn.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Fn.bin.rASCII0=function(e,t){for(var s="";0!=e[t];)s+=String.fromCharCode(e[t++]);return s},Fn.bin.wf=function(e,t,s){new Float32Array(e.buffer,t,1)[0]=s},Fn.bin.wsl=function(e,t,s){e[t]=s,e[t+1]=s>>8},Fn.bin.wil=function(e,t,s){e[t]=s,e[t+1]=s>>8,e[t+2]=s>>16,e[t+3]},Fn.parse={},Fn.parse._buffToStr=function(e){for(var t=new Uint8Array(e),s="",n=0;ni&&(i=o),ca&&(a=c),ur&&(r=u)}return{min:{x:t,y:s,z:n},max:{x:i,y:a,z:r}}};class Vn extends C{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=h.vec3(t.pos||[0,0,0]),this._up=h.vec3(t.up||[0,1,0]),this._normal=h.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=h.vec3(),this._rtcPos=h.vec3(),this._imageSize=h.vec2(),this._texture=new Nn(this),this._image=new Image,"jpg"!==this._type&&"png"!==this._type&&(this.error('Unsupported type - defaulting to "jpg"'),this._type="jpg"),this._node=new yn(this,{matrix:h.inverseMat4(h.lookAtMat4v(this._pos,h.subVec3(this._pos,this._normal,h.mat4()),this._up,h.mat4())),children:[this._bitmapMesh=new en(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new Et(this,Un({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new Ct(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0})})]}),t.image?this.image=t.image:t.src?this.src=t.src:t.imageData&&(this.imageData=t.imageData),this.scene._bitmapCreated(this)}set visible(e){this._bitmapMesh.visible=e}get visible(){return this._bitmapMesh.visible}set image(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}get image(){return this._image}set src(e){if(e){this._image.onload=()=>{this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale()},this._image.src=e;switch(e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}}get src(){return this._image.src}set imageData(e){this._image.onload=()=>{this._texture.image=image,this._imageSize[0]=image.width,this._imageSize[1]=image.height,this._updateBitmapMeshScale()},this._image.src=e}get imageData(){const e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")}set type(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}get type(){return this._type}get pos(){return this._pos}get normal(){return this._normal}get up(){return this._up}set height(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}get height(){return this._height}set collidable(e){this._bitmapMesh.collidable=!1!==e}get collidable(){return this._bitmapMesh.collidable}set clippable(e){this._bitmapMesh.clippable=!1!==e}get clippable(){return this._bitmapMesh.clippable}set pickable(e){this._bitmapMesh.pickable=!1!==e}get pickable(){return this._bitmapMesh.pickable}set opacity(e){this._bitmapMesh.opacity=e}get opacity(){return this._bitmapMesh.opacity}destroy(){super.destroy(),this.scene._bitmapDestroyed(this)}_updateBitmapMeshScale(){const e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height*e,1,this._height]}}class jn extends C{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],this._origin=h.vec3(t.origin||[0,0,0]),t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e{var i=e-s,a=t-n;return Math.sqrt(i*i+a*a)};class $n 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._eventSubs={};var s=this.plugin.viewer.scene;this._originMarker=new Y(s,t.origin),this._targetMarker=new Y(s,t.target),this._originWorld=h.vec3(),this._targetWorld=h.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;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._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._lengthWire=new X(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._xAxisWire=new X(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._yAxisWire=new X(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._zAxisWire=new X(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._lengthLabel=new J(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._xAxisLabel=new J(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._yAxisLabel=new J(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._zAxisLabel=new J(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,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._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._onMetricsUnits=s.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=s.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=s.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;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._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=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._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0);const t=this._originMarker.viewPos[2],s=this._targetMarker.viewPos[2];if(t>-.3||s>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){h.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var n=this._pp,i=this._cp,a=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var r=a.top-t.top,l=a.left-t.left,o=e.canvas.boundary,c=o[2],u=o[3],p=0;const s=this.plugin.viewer.scene.metrics,f=s.scale,I=s.units,y=s.unitsInfo[I].abbrev;for(var A=0,d=n.length;A1?i.other:i.one,i?(i=si(i,[t]),s&&(i=si(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const a=this._events[t];return void 0!==a&&s(a),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function ti(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var s=e-t,n=e+t;s<0&&(s=0),n>1&&(n=1);var i=this.getPoint(s),a=this.getPoint(n),r=h.subVec3(a,i,[]);return h.normalizeVec3(r,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,s,n=[],i=this.getPoint(0),a=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),a+=h.lenVec3(h.subVec3(t,i,[])),n.push(a),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,a=n.length;s=t||e*n[a-1];for(var r,l=0,o=a-1;l<=o;)if((r=n[i=Math.floor(l+(o-l)/2)]-s)<0)l=i+1;else{if(!(r>0)){o=i;break}o=i-1}if(n[i=o]===s)return i/(a-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(a-1)}}class ii extends ni{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var s=(t.length-1)*e,n=Math.floor(s),i=s-n,a=t[0===n?n:n-1],r=t[n],l=t[n>t.length-2?t.length-1:n+1],o=t[n>t.length-3?t.length-1:n+2],c=h.vec3();return c[0]=h.catmullRomInterpolate(a[0],r[0],l[0],o[0],i),c[1]=h.catmullRomInterpolate(a[1],r[1],l[1],o[1],i),c[2]=h.catmullRomInterpolate(a[2],r[2],l[2],o[2],i),c}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const ai=h.vec3();const ri=h.vec3(),li=h.vec3(),oi=h.vec3(),ci=h.vec3(),ui=h.vec3();class hi extends C{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=h.vec3(),this._eye1=h.vec3(),this._up1=h.vec3(),this._look2=h.vec3(),this._eye2=h.vec3(),this._up2=h.vec3(),this._orthoScale1=1,this._orthoScale2=1,this._flying=!1,this._flyEyeLookUp=!1,this._flyingEye=!1,this._flyingLook=!1,this._callback=null,this._callbackScope=null,this._time1=null,this._time2=null,this.easing=!1!==t.easing,this.duration=t.duration,this.fit=t.fit,this.fitFOV=t.fitFOV,this.trail=t.trail}flyTo(e,t,s){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=s;const n=this.scene.camera,i=!!e.projection&&e.projection!==n.projection;let a,r,l,o,c;if(this._eye1[0]=n.eye[0],this._eye1[1]=n.eye[1],this._eye1[2]=n.eye[2],this._look1[0]=n.look[0],this._look1[1]=n.look[1],this._look1[2]=n.look[2],this._up1[0]=n.up[0],this._up1[1]=n.up[1],this._up1[2]=n.up[2],this._orthoScale1=n.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)a=e.aabb;else if(6===e.length)a=e;else if(e.eye&&e.look||e.up)r=e.eye,l=e.look,o=e.up;else if(e.eye)r=e.eye;else if(e.look)l=e.look;else{let n=e;if((y.isNumeric(n)||y.isString(n))&&(c=n,n=this.scene.components[c],!n))return this.error("Component not found: "+y.inQuotes(c)),void(t&&(s?t.call(s):t()));i||(a=n.aabb||this.scene.aabb)}const u=e.poi;if(a){if(a[3]=1;e>1&&(e=1);const s=this.easing?hi._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(h.subVec3(n.eye,n.look,ui),n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,oi),n.look=h.subVec3(oi,ui,li)):this._flyingLook&&(n.look=h.lerpVec3(s,0,1,this._look1,this._look2,li),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,ci)):this._flyingEyeLookUp&&(n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,oi),n.look=h.lerpVec3(s,0,1,this._look1,this._look2,li),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,ci)),this._projection2){const t="ortho"===this._projection2?hi._easeOutExpo(e,0,1,1):hi._easeInCubic(e,0,1,1);n.customProjection.matrix=h.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();P.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class pi extends C{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new hi(this),this._t=0,this.state=pi.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case pi.SCRUBBING:return;case pi.PLAYING:if(this._t+=this._playingRate*i,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=pi.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case pi.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=pi.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=pi.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=pi.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=pi.SCRUBBING,this._cameraFlightAnimation.flyTo(n,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=pi.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=pi.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=pi.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}pi.STOPPED=0,pi.SCRUBBING=1,pi.PLAYING=2,pi.PLAYING_TO=3;const Ai=h.vec3(),di=h.vec3();h.vec3();const fi=h.vec3([0,-1,0]),Ii=h.vec4([0,0,0,1]);function yi(e){if(!mi(e.width)||!mi(e.height)){const t=document.createElement("canvas");t.width=vi(e.width),t.height=vi(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function mi(e){return 0==(e&e-1)}function vi(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class wi extends C{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new Ve({texture:new Rn({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),A.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let a=0;a0){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;_i[0]=s,_i[1]=n,_i[2]=t.blendCutoff,_i[3]=t.blendFactor,l.uniform4fv(this._uSAOParams,_i),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===Pi[(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===Pi[(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===Pi[(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?Ci:Ri)}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 Si extends Oi{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 Ni extends Si{constructor(e,t){super(e,t,{instancing:!1,edges:!0})}}class xi extends Oi{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 Li extends xi{constructor(e,t){super(e,t,{instancing:!0,edges:!0})}}class Mi extends Oi{_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 Fi extends Oi{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 Hi extends Oi{_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 Ui extends Oi{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 Gi extends Si{_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 Vi extends Si{_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 ki extends Ni{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class Qi extends Ni{_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 Wi extends Si{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class zi extends Si{_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 Ki extends Si{_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 Yi extends Si{_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 Xi extends Si{_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 qi extends Si{_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 Ji extends Si{_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 Zi extends Si{_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 ea extends Si{_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 ia=h.mat4(),aa=h.mat4();function ra(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 ca(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 ua=h.vec3();class ha{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.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[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.snapPickCoordinateScale[0]=h.safeInv(p[0]),e.snapPickCoordinateScale[1]=h.safeInv(p[1]),e.snapPickCoordinateScale[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.snapPickLayerNumber),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 pa=h.vec3();class Aa{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.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[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.snapPickCoordinateScale[0]=h.safeInv(u[0]),e.snapPickCoordinateScale[1]=h.safeInv(u[1]),e.snapPickCoordinateScale[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.snapPickLayerNumber),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("gl_PointSize = 1.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("// 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 da{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 ha(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Aa(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const fa={};const Ia=h.mat4(),ya=h.mat4(),ma=h.vec4([0,0,0,1]),va=h.vec4([0,0,0,1]),wa=h.vec4([0,0,0,1]),ga=h.OBB3(),Ta=h.vec3(),Ea=h.vec3(),ba=h.vec3(),Da=h.vec3(),Pa=h.vec3(),Ra=h.vec3(),Ca=h.vec3();class _a{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=sa[t];return s||(s=new ta(e),sa[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete sa[t],s._destroy()}))),s}(e.model.scene),this._snapBatchingRenderers=function(e){const t=e.id;let s=fa[t];return s||(s=new da(e),fa[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete fa[t],s._destroy()}))),s}(e.model.scene),this._buffer=new na(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Ve({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=Ia;I?h.inverseMat4(h.transposeMat4(I,ya),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=oa(d,"floor","ceil"),l=ca(r),c=a(d,l),c>u&&(o=r,u=c),r=oa(d,"ceil","ceil"),l=ca(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):ra(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=wt.getUVBounds(s.uv),i=wt.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 Ba extends xi{_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 Oa extends xi{_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 Na extends Li{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 xa extends Li{_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 La extends xi{_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 Ma extends xi{_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 Fa extends xi{_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 Ha extends xi{_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 Ua extends xi{_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 Ga extends xi{_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 Va extends xi{_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 ja={3e3:"linearToLinear",3001:"sRGBToLinear"};class ka extends xi{_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 = "+ja[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 = "+ja[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 Wa extends xi{_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*I,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),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 qa=h.vec3();class Ja{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;e.snapPickOrigin[0]=l[0],e.snapPickOrigin[1]=l[1],e.snapPickOrigin[2]=l[2];const o=t.aabb,c=[h.safeInv(o[3]-o[0])*h.MAX_INT,h.safeInv(o[4]-o[1])*h.MAX_INT,h.safeInv(o[5]-o[2])*h.MAX_INT];if(e.snapPickCoordinateScale[0]=h.safeInv(c[0]),e.snapPickCoordinateScale[1]=h.safeInv(c[1]),e.snapPickCoordinateScale[2]=h.safeInv(c[2]),!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const u=i.camera;let p=u.eye;e.pickViewMatrix&&(p=e.pickOrigin||p);const A=[p[0]-l[0],p[1]-l[1],p[2]-l[2]];a.uniform3fv(this._uCameraEyeRtc,A),a.uniform2fv(this.uVectorA,e.snapVectorA),a.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),a.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),a.uniform3fv(this._uCoordinateScaler,c),a.uniform1i(this._uRenderPass,s),a.uniform1i(this._uPickInvisible,e.pickInvisible);const d=e.pickViewMatrix||u.viewMatrix,f=l?B(d,l):d;if(a.uniformMatrix4fv(this._uViewMatrix,!1,f),a.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),a.uniformMatrix4fv(this._uProjMatrix,!1,u.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);a.uniform1f(this._uLogDepthBufFC,t)}const I=i._sectionPlanesState.sectionPlanes.length;if(I>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*I,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),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("gl_PointSize = 1.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("// SnapInstancingDepthRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),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}}class Za{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 Xa(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Ja(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const $a={};const er=new Uint8Array(4),tr=new Float32Array(1),sr=h.vec4([0,0,0,1]),nr=h.vec4([0,0,0,1]),ir=h.vec4([0,0,0,1]),ar=new Float32Array(3),rr=h.vec3(),lr=h.vec3(),or=h.vec3(),cr=h.vec3(),ur=h.vec3(),hr=h.vec3(),pr=h.vec3();class Ar{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=Ka[t];return s||(s=new za(e),Ka[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Ka[t],s._destroy()}))),s}(e.model.scene),this._snapInstancingRenderers=function(e){const t=e.id;let s=$a[t];return s||(s=new Za(e),$a[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete $a[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new Ve({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";er[0]=t[0],er[1]=t[1],er[2]=t[2],er[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(er,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?Pi.NOT_RENDERED:s?Pi.COLOR_TRANSPARENT:Pi.COLOR_OPAQUE,h=!n||c?Pi.NOT_RENDERED:r?Pi.SILHOUETTE_SELECTED:a?Pi.SILHOUETTE_HIGHLIGHTED:i?Pi.SILHOUETTE_XRAYED:Pi.NOT_RENDERED;let p=0;p=!n||c?Pi.NOT_RENDERED:r?Pi.EDGES_SELECTED:a?Pi.EDGES_HIGHLIGHTED:i?Pi.EDGES_XRAYED:l?s?Pi.EDGES_COLOR_TRANSPARENT:Pi.EDGES_COLOR_OPAQUE:Pi.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Pi.PICK:Pi.NOT_RENDERED)<<12,A|=(t&F?1:0)<<16,tr[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(tr,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(ar[0]=t[0],ar[1]=t[1],ar[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(ar,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=sr,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 dr extends Hi{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 fr extends Hi{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 Ir{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 dr(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new fr(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const yr={};class mr{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]}}const vr=h.vec4([0,0,0,1]),wr=h.vec4([0,0,0,1]),gr=h.vec4([0,0,0,1]),Tr=h.OBB3();class Er{constructor(e){this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=yr[t];return s||(s=new Ir(e),yr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete yr[t],s._destroy()}))),s}(e.model.scene),this.model=e.model,this._buffer=new mr(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Ve({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=ra(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 Dr extends Ui{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// 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 Pr{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 br(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Dr(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const Rr={};const Cr=new Uint8Array(4),_r=new Float32Array(1),Br=h.vec4([0,0,0,1]),Or=h.vec4([0,0,0,1]),Sr=h.vec4([0,0,0,1]),Nr=new Float32Array(3);class xr{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=Rr[t];return s||(s=new Pr(e),Rr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Rr[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new Ve({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";Cr[0]=t[0],Cr[1]=t[1],Cr[2]=t[2],Cr[3]=t[3],this._state.colorsBuf.setData(Cr,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?Pi.NOT_RENDERED:s?Pi.COLOR_TRANSPARENT:Pi.COLOR_OPAQUE,h=!n||c?Pi.NOT_RENDERED:r?Pi.SILHOUETTE_SELECTED:a?Pi.SILHOUETTE_HIGHLIGHTED:i?Pi.SILHOUETTE_XRAYED:Pi.NOT_RENDERED;let p=0;p=!n||c?Pi.NOT_RENDERED:r?Pi.EDGES_SELECTED:a?Pi.EDGES_HIGHLIGHTED:i?Pi.EDGES_XRAYED:l?s?Pi.EDGES_COLOR_TRANSPARENT:Pi.EDGES_COLOR_OPAQUE:Pi.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Pi.PICK:Pi.NOT_RENDERED)<<12,A|=(t&F?255:0)<<16,_r[0]=A,this._state.flagsBuf.setData(_r,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Nr[0]=t[0],Nr[1]=t[1],Nr[2]=t[2],this._state.offsetsBuf.setData(Nr,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,Pi.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,Pi.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,Pi.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Pi.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Pi.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 Lr extends Mi{_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 Mr extends Mi{_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 Fr extends Mi{_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 Hr extends Mi{_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 Ur extends Mi{_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 Gr{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 Lr(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Mr(this._scene)),this._silhouetteRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Fr(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Hr(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new Ur(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 Vr={};class jr{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 kr=h.vec4(),Qr=h.vec4(),Wr=h.vec4([0,0,0,1]),zr=h.vec4([0,0,0,1]),Kr=h.vec4([0,0,0,1]),Yr=h.OBB3();class Xr{constructor(e){this.model=e.model,this.sortId="PointsBatchingLayer",this.layerIndex=e.layerIndex,this._pointsBatchingRenderers=function(e){const t=e.id;let s=Vr[t];return s||(s=new Gr(e),Vr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Vr[t],s._destroy()}))),s}(e.model.scene),this._buffer=new jr(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Ve({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=ra(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 Jr extends Fi{_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 Zr extends Fi{_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 $r extends Fi{_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 el extends Fi{_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 tl extends Fi{_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 sl extends Fi{_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 nl{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 qr(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Jr(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new tl(this._scene)),this._depthRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Zr(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new $r(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new el(this._scene)),this._occlusionRenderer}get shadowRenderer(){return this._shadowRenderer||(this._shadowRenderer=new sl(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 il={};const al=new Uint8Array(4),rl=new Float32Array(1),ll=h.vec4([0,0,0,1]),ol=h.vec4([0,0,0,1]),cl=h.vec4([0,0,0,1]),ul=new Float32Array(3);class hl{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=il[t];return s||(s=new nl(e),il[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete il[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new Ve({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";al[0]=t[0],al[1]=t[1],al[2]=t[2],this._state.colorsBuf.setData(al,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?Pi.NOT_RENDERED:s?Pi.COLOR_TRANSPARENT:Pi.COLOR_OPAQUE,h=!n||c?Pi.NOT_RENDERED:r?Pi.SILHOUETTE_SELECTED:a?Pi.SILHOUETTE_HIGHLIGHTED:i?Pi.SILHOUETTE_XRAYED:Pi.NOT_RENDERED;let p=0;p=!n||c?Pi.NOT_RENDERED:r?Pi.EDGES_SELECTED:a?Pi.EDGES_HIGHLIGHTED:i?Pi.EDGES_XRAYED:l?s?Pi.EDGES_COLOR_TRANSPARENT:Pi.EDGES_COLOR_OPAQUE:Pi.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Pi.PICK:Pi.NOT_RENDERED)<<12,A|=(t&F?255:0)<<16,rl[0]=A,this._state.flagsBuf.setData(rl,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(ul[0]=t[0],ul[1]=t[1],ul[2]=t[2],this._state.offsetsBuf.setData(ul,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,Pi.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,Pi.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,Pi.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Pi.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Pi.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,Pi.COLOR_OPAQUE)}drawShadow(e,t){}drawPickMesh(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,Pi.PICK)}drawPickDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,Pi.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 pl{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 Al{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const dl={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}};class fl{constructor(e,t,s){this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=s}itemStart(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}itemEnd(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}itemError(e){void 0!==this.onError&&this.onError(e)}resolveURL(e){return this.urlModifier?this.urlModifier(e):e}setURLModifier(e){return this.urlModifier=e,this}addHandler(e,t){return this.handlers.push(e,t),this}removeHandler(e){const t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}getHandler(e){for(let t=0,s=this.handlers.length;t{t&&t(i),this.manager.itemEnd(e)}),0),i;if(void 0!==ml[e])return void ml[e].push({onLoad:t,onProgress:s,onError:n});ml[e]=[],ml[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=ml[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=>{dl.add(e,t);const s=ml[e];delete ml[e];for(let e=0,n=s.length;e{const s=ml[e];if(void 0===s)throw this.manager.itemError(e),t;delete ml[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 wl{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 gl=0;class Tl{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 wl,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 vl;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new vl;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=Tl.BasisWorker.toString(),n=["/* constants */","let _EngineFormat = "+JSON.stringify(Tl.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(Tl.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(Tl.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}))})),gl>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),gl++}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(),gl--}}Tl.BasisFormat={ETC1S:0,UASTC_4x4:1},Tl.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},Tl.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},Tl.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 El[t],s.destroy()}))),s} +function es(e,t){t.length;const s=e.length,n=[],i=[],a=e=>{for(let s=0,n=e.meshIds.length;s{const s=t[e];let n,i;if(s.positionsCompressed){const e=wt.getPositionsBounds(s.positionsCompressed);n=wt.decompressPosition(e.min,s.positionsDecodeMatrix,[]),i=wt.decompressPosition(e.max,s.positionsDecodeMatrix,[])}else{const e=wt.getPositionsBounds(s.positions);n=e.min,i=e.max}n[0]+=s.origin[0],n[1]+=s.origin[1],n[2]+=s.origin[2],i[0]+=s.origin[0],i[1]+=s.origin[1],i[2]+=s.origin[2],h.expandAABB3Point3(l,n),h.expandAABB3Point3(l,i),o+=s.numPrimitives})),n[r]={aabb:l,numPrimitives:o,entityId:s.id}}let r,l=[],o={};if(Object.keys(n).length>0){r=function(e){const t=[];for(let s=0,n=e.length;s{s=Math.max(s,e.entity.id)}));const n=new Array(s+1);t.forEach((t=>{n[t.entity.id]=e.objects[t.entity.xeokitId]})),this._internalNodesList=n,this._lastVisibleFrameOfNodes=new Array(n.length),this._lastVisibleFrameOfNodes.fill(0)}_searchVisibleNodesWithFrustumCulling(){return this._aabbTree.searchCustom(((e,t)=>this._aabbIntersectsCameraFrustum(e,t)),(e=>this._aabbContainedInCameraFrustum(e)))}_markVisibleFrameOfVisibleNodes(e,t){const s=this._lastVisibleFrameOfNodes;for(let n=0,i=e.length;nthis._frustumProps.CAM_FACTOR_1?(s|=r<0?64:128,s&=-17):s&=-33;const l=is(h.dotVec3(i,this._frustumProps.up),a);Math.abs(l)>this._frustumProps.CAM_FACTOR_2?(s|=l<0?1024:2048,s&=-257):s&=-513}return 4&s&&8&s&&(s|=4096),64&s&&128&s&&(s|=8192),1024&s&&2048&s&&(s|=16384),e._check=s,s}}class rs{constructor(e,t){this.sceneModel=t,this.entities=[],this.meshes=[],this.finalized=!1}addEntity(e){if(this.finalized)throw"Already finalized";this.entities.push(e)}addMesh(e){if(this.finalized)throw"Already finalized";this.meshes.push(e)}finalize(e){if(this.finalized)throw"Already finalized";this.finalized=!0,this.VFCState=new as,this.VFCState.initializeVFCState(this.entities,this.meshes),this.VFCState.finalize(this.sceneModel,e),this._onSceneRendering=this.sceneModel.scene.on("rendering",(()=>this.applyViewFrustumCulling.call(this)))}applyViewFrustumCulling(){this.finalized&&this.VFCState.applyViewFrustumCulling(this.sceneModel)}destroy(){this.finalized&&this.sceneModel.off(this._onSceneRendering)}}class ls extends C{constructor(e,t={}){super(e,t),this._scene=e,this._vfcManagers={},this._vfcManagerList=[],this.enabled=t.enabled,this._init()}_init(){this._scene.on("rendering",(()=>{for(let e=0,t=this._vfcManagerList.length;e{this.glRedraw()})),this.canvas.on("webglContextFailed",(()=>{alert("xeokit failed to find WebGL!")})),this._renderer=new He(this,{transparent:n,alphaDepthMask:i}),this._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1;let e=null;this.getHash=function(){if(e)return e;const t=this.sectionPlanes;if(0===t.length)return this.hash=";";const s=[];for(let e=0,n=t.length;e0&&e.push("/lm"),this.reflectionMaps.length>0&&e.push("/rm"),e.push(";"),s=e.join(""),s},this.addLight=function(e){this.lights.push(e),n=null,s=null},this.removeLight=function(e){for(let t=0,i=this.lights.length;t{this._renderer.imageDirty()})),this.lod=new Xt(this,{enabled:t.lodEnabled}),this.vfc=new ls(this,{enabled:t.vfcEnabled})}_initDefaults(){}_addComponent(e){if(e.id&&this.components[e.id]&&(this.error("Component "+y.inQuotes(e.id)+" already exists in Scene - ignoring ID, will randomly-generate instead"),e.id=null),!e.id)for(void 0===window.nextID&&(window.nextID=0),e.id="__"+window.nextID++;this.components[e.id];)e.id=h.createUUID();this.components[e.id]=e;const t=e.type;let s=this.types[e.type];s||(s=this.types[t]={}),s[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}_removeComponent(e){var t=e.id,s=e.type;delete this.components[t];const n=this.types[s];n&&(delete n[t],y.isEmptyObject(n)&&delete this.types[s]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}_sectionPlaneCreated(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}_bitmapCreated(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}_lineSetCreated(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}_lightCreated(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}_lightMapCreated(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}_reflectionMapCreated(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}_sectionPlaneDestroyed(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}_bitmapDestroyed(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}_lineSetDestroyed(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}_lightDestroyed(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}_lightMapDestroyed(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}_reflectionMapDestroyed(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}_registerModel(e){this.models[e.id]=e,this._modelIds=null}_deregisterModel(e){const t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}_registerObject(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}_deregisterObject(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}_objectVisibilityUpdated(e,t=!0){e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}_objectXRayedUpdated(e,t=!0){e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}_objectHighlightedUpdated(e,t=!0){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null,t&&this.fire("objectHighlighted",e,!0)}_objectSelectedUpdated(e,t=!0){e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}_objectColorizeUpdated(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}_objectOpacityUpdated(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}_objectOffsetUpdated(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}_webglContextLost(){this.canvas.spinner.processes++;for(const e in this.components)if(this.components.hasOwnProperty(e)){const t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}_webglContextRestored(){const e=this.canvas.gl;for(const t in this.components)if(this.components.hasOwnProperty(t)){const s=this.components[t];s._webglContextRestored&&s._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}get capabilities(){return this._renderer.capabilities}get entityOffsetsEnabled(){return this._entityOffsetsEnabled}get pickSurfacePrecisionEnabled(){return!1}get logarithmicDepthBufferEnabled(){return this._logarithmicDepthBufferEnabled}set pbrEnabled(e){this._pbrEnabled=!!e,this.glRedraw()}get pbrEnabled(){return this._pbrEnabled}set dtxEnabled(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}get dtxEnabled(){return this._dtxEnabled}set colorTextureEnabled(e){this._colorTextureEnabled=!!e,this.glRedraw()}get colorTextureEnabled(){return this._colorTextureEnabled}doOcclusionTest(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}render(e){e&&P.runTasks();const t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),!e&&!this._renderer.needsRender())return;t.sceneId=this.id;const s=this._passes,n=this._clearEachPass;let i,a;for(i=0;ii&&(i=e[3]),e[4]>a&&(a=e[4]),e[5]>r&&(r=e[5]),c=!0}c||(t=-100,s=-100,n=-100,i=100,a=100,r=100),this._aabb[0]=t,this._aabb[1]=s,this._aabb[2]=n,this._aabb[3]=i,this._aabb[4]=a,this._aabb[5]=r,this._aabbDirty=!1}return this._aabb}_setAABBDirty(){this._aabbDirty=!0,this.fire("boundary")}pick(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");const s=e.includeEntities||e.include;s&&(e.includeEntityIds=os(this,s));const n=e.excludeEntities||e.exclude;return n&&(e.excludeEntityIds=os(this,n)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=this._renderer.pick(e,t))?(t.entity&&t.entity.fire&&t.entity.fire("picked",t),t):void 0}snapPick(e){return this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapMode||"vertex")}clear(){var e;for(const t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}clearLights(){const e=Object.keys(this.lights);for(let t=0,s=e.length;t{if(e.collidable){const o=e.aabb;o[0]a&&(a=o[3]),o[4]>r&&(r=o[4]),o[5]>l&&(l=o[5]),t=!0}})),t){const e=h.AABB3();return e[0]=s,e[1]=n,e[2]=i,e[3]=a,e[4]=r,e[5]=l,e}return this.aabb}setObjectsVisible(e,t){return this.withObjects(e,(e=>{const s=e.visible!==t;return e.visible=t,s}))}setObjectsCollidable(e,t){return this.withObjects(e,(e=>{const s=e.collidable!==t;return e.collidable=t,s}))}setObjectsCulled(e,t){return this.withObjects(e,(e=>{const s=e.culled!==t;return e.culled=t,s}))}setObjectsSelected(e,t){return this.withObjects(e,(e=>{const s=e.selected!==t;return e.selected=t,s}))}setObjectsHighlighted(e,t){return this.withObjects(e,(e=>{const s=e.highlighted!==t;return e.highlighted=t,s}))}setObjectsXRayed(e,t){return this.withObjects(e,(e=>{const s=e.xrayed!==t;return e.xrayed=t,s}))}setObjectsEdges(e,t){return this.withObjects(e,(e=>{const s=e.edges!==t;return e.edges=t,s}))}setObjectsColorized(e,t){return this.withObjects(e,(e=>{e.colorize=t}))}setObjectsOpacity(e,t){return this.withObjects(e,(e=>{const s=e.opacity!==t;return e.opacity=t,s}))}setObjectsPickable(e,t){return this.withObjects(e,(e=>{const s=e.pickable!==t;return e.pickable=t,s}))}setObjectsOffset(e,t){this.withObjects(e,(e=>{e.offset=t}))}withObjects(e,t){y.isString(e)&&(e=[e]);let s=!1;for(let n=0,i=e.length;n0,o=!!i.compressGeometry,c=[];c.push("#version 300 es"),c.push("// Lambertian drawing vertex shader"),c.push("in vec3 position;"),c.push("uniform mat4 modelMatrix;"),c.push("uniform mat4 viewMatrix;"),c.push("uniform mat4 projMatrix;"),c.push("uniform vec4 colorize;"),c.push("uniform vec3 offset;"),o&&c.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(c.push("uniform float logDepthBufFC;"),c.push("out float vFragDepth;"),c.push("bool isPerspectiveMatrix(mat4 m) {"),c.push(" return (m[2][3] == - 1.0);"),c.push("}"),c.push("out float isPerspective;"));l&&c.push("out vec4 vWorldPosition;");if(c.push("uniform vec4 lightAmbient;"),c.push("uniform vec4 materialColor;"),c.push("uniform vec3 materialEmissive;"),i.normalsBuf){c.push("in vec3 normal;"),c.push("uniform mat4 modelNormalMatrix;"),c.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=n.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),c.push(" }"),c.push(" return normalize(v);"),c.push("}"))}c.push("out vec4 vColor;"),"points"===i.primitiveName&&c.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(c.push("void billboard(inout mat4 mat) {"),c.push(" mat[0][0] = 1.0;"),c.push(" mat[0][1] = 0.0;"),c.push(" mat[0][2] = 0.0;"),"spherical"===a&&(c.push(" mat[1][0] = 0.0;"),c.push(" mat[1][1] = 1.0;"),c.push(" mat[1][2] = 0.0;")),c.push(" mat[2][0] = 0.0;"),c.push(" mat[2][1] = 0.0;"),c.push(" mat[2][2] =1.0;"),c.push("}"));c.push("void main(void) {"),c.push("vec4 localPosition = vec4(position, 1.0); "),c.push("vec4 worldPosition;"),o&&c.push("localPosition = positionsDecodeMatrix * localPosition;");i.normalsBuf&&(o?c.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):c.push("vec4 localNormal = vec4(normal, 0.0); "),c.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),c.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));c.push("mat4 viewMatrix2 = viewMatrix;"),c.push("mat4 modelMatrix2 = modelMatrix;"),r&&c.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===a||"cylindrical"===a?(c.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),c.push("billboard(modelMatrix2);"),c.push("billboard(viewMatrix2);"),c.push("billboard(modelViewMatrix);"),i.normalsBuf&&(c.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),c.push("billboard(modelNormalMatrix2);"),c.push("billboard(viewNormalMatrix2);"),c.push("billboard(modelViewNormalMatrix);")),c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i.normalsBuf&&c.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(c.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),c.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),c.push("float lambertian = 1.0;"),i.normalsBuf)for(let e=0,t=n.lights.length;e0,a=t.gammaOutput,r=[];r.push("#version 300 es"),r.push("// Lambertian drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(i){r.push("in vec4 vWorldPosition;"),r.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),r.push("}")}"points"===n.primitiveName&&(r.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),r.push("float r = dot(cxy, cxy);"),r.push("if (r > 1.0) {"),r.push(" discard;"),r.push("}"));t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");a?r.push("outColor = linearToGamma(vColor, gammaFactor);"):r.push("outColor = vColor;");return r.push("}"),r}(e)):(this.vertex=function(e){const t=e.scene;e._material;const s=e._state,n=t._sectionPlanesState,i=e._geometry._state,a=t._lightsState;let r;const l=s.billboard,o=s.background,c=s.stationary,u=function(e){if(!e._geometry._state.uvBuf)return!1;const t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),h=As(e),p=n.sectionPlanes.length>0,A=ps(e),d=!!i.compressGeometry,f=[];f.push("#version 300 es"),f.push("// Drawing vertex shader"),f.push("in vec3 position;"),d&&f.push("uniform mat4 positionsDecodeMatrix;");f.push("uniform mat4 modelMatrix;"),f.push("uniform mat4 viewMatrix;"),f.push("uniform mat4 projMatrix;"),f.push("out vec3 vViewPosition;"),f.push("uniform vec3 offset;"),p&&f.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(f.push("uniform float logDepthBufFC;"),f.push("out float vFragDepth;"),f.push("bool isPerspectiveMatrix(mat4 m) {"),f.push(" return (m[2][3] == - 1.0);"),f.push("}"),f.push("out float isPerspective;"));a.lightMaps.length>0&&f.push("out vec3 vWorldNormal;");if(h){f.push("in vec3 normal;"),f.push("uniform mat4 modelNormalMatrix;"),f.push("uniform mat4 viewNormalMatrix;"),f.push("out vec3 vViewNormal;");for(let e=0,t=a.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),f.push(" }"),f.push(" return normalize(v);"),f.push("}"))}u&&(f.push("in vec2 uv;"),f.push("out vec2 vUV;"),d&&f.push("uniform mat3 uvDecodeMatrix;"));i.colors&&(f.push("in vec4 color;"),f.push("out vec4 vColor;"));"points"===i.primitiveName&&f.push("uniform float pointSize;");"spherical"!==l&&"cylindrical"!==l||(f.push("void billboard(inout mat4 mat) {"),f.push(" mat[0][0] = 1.0;"),f.push(" mat[0][1] = 0.0;"),f.push(" mat[0][2] = 0.0;"),"spherical"===l&&(f.push(" mat[1][0] = 0.0;"),f.push(" mat[1][1] = 1.0;"),f.push(" mat[1][2] = 0.0;")),f.push(" mat[2][0] = 0.0;"),f.push(" mat[2][1] = 0.0;"),f.push(" mat[2][2] =1.0;"),f.push("}"));if(A){f.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(let e=0,t=a.lights.length;e0&&f.push("vWorldNormal = worldNormal;"),f.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),f.push("vec3 tmpVec3;"),f.push("float lightDist;");for(let e=0,t=a.lights.length;e0,o=As(e),c=n.uvBuf,u="PhongMaterial"===r.type,h="MetallicMaterial"===r.type,p="SpecularMaterial"===r.type,A=ps(e);t.gammaInput;const d=t.gammaOutput,f=[];f.push("#version 300 es"),f.push("// Drawing fragment shader"),f.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),f.push("precision highp float;"),f.push("precision highp int;"),f.push("#else"),f.push("precision mediump float;"),f.push("precision mediump int;"),f.push("#endif"),t.logarithmicDepthBufferEnabled&&(f.push("in float isPerspective;"),f.push("uniform float logDepthBufFC;"),f.push("in float vFragDepth;"));A&&(f.push("float unpackDepth (vec4 color) {"),f.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),f.push(" return dot(color, bitShift);"),f.push("}"));f.push("uniform float gammaFactor;"),f.push("vec4 linearToLinear( in vec4 value ) {"),f.push(" return value;"),f.push("}"),f.push("vec4 sRGBToLinear( in vec4 value ) {"),f.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),f.push("}"),f.push("vec4 gammaToLinear( in vec4 value) {"),f.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),f.push("}"),d&&(f.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),f.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),f.push("}"));if(l){f.push("in vec4 vWorldPosition;"),f.push("uniform bool clippable;");for(var I=0;I0&&(f.push("uniform samplerCube lightMap;"),f.push("uniform mat4 viewNormalMatrix;")),a.reflectionMaps.length>0&&f.push("uniform samplerCube reflectionMap;"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("uniform mat4 viewMatrix;"),f.push("#define PI 3.14159265359"),f.push("#define RECIPROCAL_PI 0.31830988618"),f.push("#define RECIPROCAL_PI2 0.15915494"),f.push("#define EPSILON 1e-6"),f.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),f.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),f.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),f.push("}"),f.push("struct IncidentLight {"),f.push(" vec3 color;"),f.push(" vec3 direction;"),f.push("};"),f.push("struct ReflectedLight {"),f.push(" vec3 diffuse;"),f.push(" vec3 specular;"),f.push("};"),f.push("struct Geometry {"),f.push(" vec3 position;"),f.push(" vec3 viewNormal;"),f.push(" vec3 worldNormal;"),f.push(" vec3 viewEyeDir;"),f.push("};"),f.push("struct Material {"),f.push(" vec3 diffuseColor;"),f.push(" float specularRoughness;"),f.push(" vec3 specularColor;"),f.push(" float shine;"),f.push("};"),u&&((a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = "+hs[a.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),f.push(" radiance *= PI;"),f.push(" reflectedLight.specular += radiance;")),f.push("}")),f.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),f.push(" vec3 irradiance = dotNL * directLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),f.push("}")),(h||p)&&(f.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),f.push(" float r = ggxRoughness + 0.0001;"),f.push(" return (2.0 / (r * r) - 2.0);"),f.push("}"),f.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),f.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),f.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),f.push("}"),a.reflectionMaps.length>0&&(f.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),f.push(" vec3 envMapColor = "+hs[a.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),f.push(" return envMapColor;"),f.push("}")),f.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),f.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),f.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),f.push("}"),f.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" return 1.0 / ( gl * gv );"),f.push("}"),f.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" return 0.5 / max( gv + gl, EPSILON );"),f.push("}"),f.push("float D_GGX(const in float alpha, const in float dotNH) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),f.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float alpha = ( roughness * roughness );"),f.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),f.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),f.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),f.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),f.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),f.push(" vec3 F = F_Schlick( specularColor, dotLH );"),f.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),f.push(" float D = D_GGX( alpha, dotNH );"),f.push(" return F * (G * D);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),f.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),f.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),f.push(" vec4 r = roughness * c0 + c1;"),f.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),f.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),f.push(" return specularColor * AB.x + AB.y;"),f.push("}"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),f.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),f.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),f.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),f.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),f.push("}")),f.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),f.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),f.push("}")));f.push("in vec3 vViewPosition;"),n.colors&&f.push("in vec4 vColor;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._occlusionMap||s._alphaMap)&&f.push("in vec2 vUV;");o&&(a.lightMaps.length>0&&f.push("in vec3 vWorldNormal;"),f.push("in vec3 vViewNormal;"));r.ambient&&f.push("uniform vec3 materialAmbient;");r.baseColor&&f.push("uniform vec3 materialBaseColor;");void 0!==r.alpha&&null!==r.alpha&&f.push("uniform vec4 materialAlphaModeCutoff;");r.emissive&&f.push("uniform vec3 materialEmissive;");r.diffuse&&f.push("uniform vec3 materialDiffuse;");void 0!==r.glossiness&&null!==r.glossiness&&f.push("uniform float materialGlossiness;");void 0!==r.shininess&&null!==r.shininess&&f.push("uniform float materialShininess;");r.specular&&f.push("uniform vec3 materialSpecular;");void 0!==r.metallic&&null!==r.metallic&&f.push("uniform float materialMetallic;");void 0!==r.roughness&&null!==r.roughness&&f.push("uniform float materialRoughness;");void 0!==r.specularF0&&null!==r.specularF0&&f.push("uniform float materialSpecularF0;");c&&s._ambientMap&&(f.push("uniform sampler2D ambientMap;"),s._ambientMap._state.matrix&&f.push("uniform mat4 ambientMapMatrix;"));c&&s._baseColorMap&&(f.push("uniform sampler2D baseColorMap;"),s._baseColorMap._state.matrix&&f.push("uniform mat4 baseColorMapMatrix;"));c&&s._diffuseMap&&(f.push("uniform sampler2D diffuseMap;"),s._diffuseMap._state.matrix&&f.push("uniform mat4 diffuseMapMatrix;"));c&&s._emissiveMap&&(f.push("uniform sampler2D emissiveMap;"),s._emissiveMap._state.matrix&&f.push("uniform mat4 emissiveMapMatrix;"));o&&c&&s._metallicMap&&(f.push("uniform sampler2D metallicMap;"),s._metallicMap._state.matrix&&f.push("uniform mat4 metallicMapMatrix;"));o&&c&&s._roughnessMap&&(f.push("uniform sampler2D roughnessMap;"),s._roughnessMap._state.matrix&&f.push("uniform mat4 roughnessMapMatrix;"));o&&c&&s._metallicRoughnessMap&&(f.push("uniform sampler2D metallicRoughnessMap;"),s._metallicRoughnessMap._state.matrix&&f.push("uniform mat4 metallicRoughnessMapMatrix;"));o&&s._normalMap&&(f.push("uniform sampler2D normalMap;"),s._normalMap._state.matrix&&f.push("uniform mat4 normalMapMatrix;"),f.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),f.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),f.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),f.push(" vec2 st0 = dFdx( uv.st );"),f.push(" vec2 st1 = dFdy( uv.st );"),f.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),f.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),f.push(" vec3 N = normalize( surf_norm );"),f.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),f.push(" mat3 tsn = mat3( S, T, N );"),f.push(" return normalize( tsn * mapN );"),f.push("}"));c&&s._occlusionMap&&(f.push("uniform sampler2D occlusionMap;"),s._occlusionMap._state.matrix&&f.push("uniform mat4 occlusionMapMatrix;"));c&&s._alphaMap&&(f.push("uniform sampler2D alphaMap;"),s._alphaMap._state.matrix&&f.push("uniform mat4 alphaMapMatrix;"));o&&c&&s._specularMap&&(f.push("uniform sampler2D specularMap;"),s._specularMap._state.matrix&&f.push("uniform mat4 specularMapMatrix;"));o&&c&&s._glossinessMap&&(f.push("uniform sampler2D glossinessMap;"),s._glossinessMap._state.matrix&&f.push("uniform mat4 glossinessMapMatrix;"));o&&c&&s._specularGlossinessMap&&(f.push("uniform sampler2D materialSpecularGlossinessMap;"),s._specularGlossinessMap._state.matrix&&f.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));o&&(s._diffuseFresnel||s._specularFresnel||s._alphaFresnel||s._emissiveFresnel||s._reflectivityFresnel)&&(f.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),f.push(" float fr = abs(dot(eyeDir, normal));"),f.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),f.push(" return pow(finalFr, power);"),f.push("}"),s._diffuseFresnel&&(f.push("uniform float diffuseFresnelCenterBias;"),f.push("uniform float diffuseFresnelEdgeBias;"),f.push("uniform float diffuseFresnelPower;"),f.push("uniform vec3 diffuseFresnelCenterColor;"),f.push("uniform vec3 diffuseFresnelEdgeColor;")),s._specularFresnel&&(f.push("uniform float specularFresnelCenterBias;"),f.push("uniform float specularFresnelEdgeBias;"),f.push("uniform float specularFresnelPower;"),f.push("uniform vec3 specularFresnelCenterColor;"),f.push("uniform vec3 specularFresnelEdgeColor;")),s._alphaFresnel&&(f.push("uniform float alphaFresnelCenterBias;"),f.push("uniform float alphaFresnelEdgeBias;"),f.push("uniform float alphaFresnelPower;"),f.push("uniform vec3 alphaFresnelCenterColor;"),f.push("uniform vec3 alphaFresnelEdgeColor;")),s._reflectivityFresnel&&(f.push("uniform float materialSpecularF0FresnelCenterBias;"),f.push("uniform float materialSpecularF0FresnelEdgeBias;"),f.push("uniform float materialSpecularF0FresnelPower;"),f.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),f.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),s._emissiveFresnel&&(f.push("uniform float emissiveFresnelCenterBias;"),f.push("uniform float emissiveFresnelEdgeBias;"),f.push("uniform float emissiveFresnelPower;"),f.push("uniform vec3 emissiveFresnelCenterColor;"),f.push("uniform vec3 emissiveFresnelEdgeColor;")));if(f.push("uniform vec4 lightAmbient;"),o)for(let e=0,t=a.lights.length;e 0.0) { discard; }"),f.push("}")}"points"===n.primitiveName&&(f.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),f.push("float r = dot(cxy, cxy);"),f.push("if (r > 1.0) {"),f.push(" discard;"),f.push("}"));f.push("float occlusion = 1.0;"),r.ambient?f.push("vec3 ambientColor = materialAmbient;"):f.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");r.diffuse?f.push("vec3 diffuseColor = materialDiffuse;"):r.baseColor?f.push("vec3 diffuseColor = materialBaseColor;"):f.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");n.colors&&f.push("diffuseColor *= vColor.rgb;");r.emissive?f.push("vec3 emissiveColor = materialEmissive;"):f.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");r.specular?f.push("vec3 specular = materialSpecular;"):f.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==r.alpha?f.push("float alpha = materialAlphaModeCutoff[0];"):f.push("float alpha = 1.0;");n.colors&&f.push("alpha *= vColor.a;");void 0!==r.glossiness?f.push("float glossiness = materialGlossiness;"):f.push("float glossiness = 1.0;");void 0!==r.metallic?f.push("float metallic = materialMetallic;"):f.push("float metallic = 1.0;");void 0!==r.roughness?f.push("float roughness = materialRoughness;"):f.push("float roughness = 1.0;");void 0!==r.specularF0?f.push("float specularF0 = materialSpecularF0;"):f.push("float specularF0 = 1.0;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._occlusionMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._alphaMap)&&(f.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),f.push("vec2 textureCoord;"));c&&s._ambientMap&&(s._ambientMap._state.matrix?f.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),f.push("ambientTexel = "+hs[s._ambientMap._state.encoding]+"(ambientTexel);"),f.push("ambientColor *= ambientTexel.rgb;"));c&&s._diffuseMap&&(s._diffuseMap._state.matrix?f.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),f.push("diffuseTexel = "+hs[s._diffuseMap._state.encoding]+"(diffuseTexel);"),f.push("diffuseColor *= diffuseTexel.rgb;"),f.push("alpha *= diffuseTexel.a;"));c&&s._baseColorMap&&(s._baseColorMap._state.matrix?f.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),f.push("baseColorTexel = "+hs[s._baseColorMap._state.encoding]+"(baseColorTexel);"),f.push("diffuseColor *= baseColorTexel.rgb;"),f.push("alpha *= baseColorTexel.a;"));c&&s._emissiveMap&&(s._emissiveMap._state.matrix?f.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),f.push("emissiveTexel = "+hs[s._emissiveMap._state.encoding]+"(emissiveTexel);"),f.push("emissiveColor = emissiveTexel.rgb;"));c&&s._alphaMap&&(s._alphaMap._state.matrix?f.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("alpha *= texture(alphaMap, textureCoord).r;"));c&&s._occlusionMap&&(s._occlusionMap._state.matrix?f.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(o&&(a.lights.length>0||a.lightMaps.length>0||a.reflectionMaps.length>0)){c&&s._normalMap?(s._normalMap._state.matrix?f.push("textureCoord = (normalMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):f.push("vec3 viewNormal = normalize(vViewNormal);"),c&&s._specularMap&&(s._specularMap._state.matrix?f.push("textureCoord = (specularMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("specular *= texture(specularMap, textureCoord).rgb;")),c&&s._glossinessMap&&(s._glossinessMap._state.matrix?f.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("glossiness *= texture(glossinessMap, textureCoord).r;")),c&&s._specularGlossinessMap&&(s._specularGlossinessMap._state.matrix?f.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),f.push("specular *= specGlossRGB.rgb;"),f.push("glossiness *= specGlossRGB.a;")),c&&s._metallicMap&&(s._metallicMap._state.matrix?f.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("metallic *= texture(metallicMap, textureCoord).r;")),c&&s._roughnessMap&&(s._roughnessMap._state.matrix?f.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("roughness *= texture(roughnessMap, textureCoord).r;")),c&&s._metallicRoughnessMap&&(s._metallicRoughnessMap._state.matrix?f.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),f.push("metallic *= metalRoughRGB.b;"),f.push("roughness *= metalRoughRGB.g;")),f.push("vec3 viewEyeDir = normalize(-vViewPosition);"),s._diffuseFresnel&&(f.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),f.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),s._specularFresnel&&(f.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),f.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),s._alphaFresnel&&(f.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),f.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),s._emissiveFresnel&&(f.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),f.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),f.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),f.push(" discard;"),f.push("}"),f.push("IncidentLight light;"),f.push("Material material;"),f.push("Geometry geometry;"),f.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),f.push("vec3 viewLightDir;"),u&&(f.push("material.diffuseColor = diffuseColor;"),f.push("material.specularColor = specular;"),f.push("material.shine = materialShininess;")),p&&(f.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),f.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),f.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),f.push("material.specularColor = specular;")),h&&(f.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),f.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),f.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),f.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),f.push("geometry.position = vViewPosition;"),a.lightMaps.length>0&&f.push("geometry.worldNormal = normalize(vWorldNormal);"),f.push("geometry.viewNormal = viewNormal;"),f.push("geometry.viewEyeDir = viewEyeDir;"),u&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePhongLightMapping(geometry, material, reflectedLight);"),(p||h)&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePBRLightMapping(geometry, material, reflectedLight);"),f.push("float shadow = 1.0;"),f.push("float shadowAcneRemover = 0.007;"),f.push("vec3 fragmentDepth;"),f.push("float texelSize = 1.0 / 1024.0;"),f.push("float amountInLight = 0.0;"),f.push("vec3 shadowCoord;"),f.push("vec4 rgbaDepth;"),f.push("float depth;");for(let e=0,t=a.lights.length;e0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(u=0,h=a.sectionPlanes.length;u0&&i.lightMaps[0].texture&&this._uLightMap&&(l.bindTexture(this._uLightMap,i.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),i.reflectionMaps.length>0&&i.reflectionMaps[0].texture&&this._uReflectionMap&&(l.bindTexture(this._uReflectionMap,i.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),this._uGammaFactor&&n.uniform1f(this._uGammaFactor,s.gammaFactor),this._baseTextureUnit=e.textureUnit};class ms{constructor(e){this.vertex=function(e){const t=e.scene,s=t._lightsState,n=function(e){const t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),i=t._sectionPlanesState.sectionPlanes.length>0,a=!!e._geometry._state.compressGeometry,r=e._state.billboard,l=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// EmphasisFillShaderSource vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("uniform vec4 colorize;"),o.push("uniform vec3 offset;"),a&&o.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));i&&o.push("out vec4 vWorldPosition;");if(o.push("uniform vec4 lightAmbient;"),o.push("uniform vec4 fillColor;"),n){o.push("in vec3 normal;"),o.push("uniform mat4 modelNormalMatrix;"),o.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),o.push(" }"),o.push(" return normalize(v);"),o.push("}"))}o.push("out vec4 vColor;"),("spherical"===r||"cylindrical"===r)&&(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),o.push("vec4 worldPosition;"),a&&o.push("localPosition = positionsDecodeMatrix * localPosition;");n&&(a?o.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):o.push("vec4 localNormal = vec4(normal, 0.0); "),o.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),o.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),l&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===r||"cylindrical"===r?(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"),o.push("billboard(modelViewMatrix);"),n&&(o.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),o.push("billboard(modelNormalMatrix2);"),o.push("billboard(viewNormalMatrix2);"),o.push("billboard(modelViewNormalMatrix);")),o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));n&&o.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),n)for(let e=0,t=s.lights.length;e0,a=[];a.push("#version 300 es"),a.push("// Lambertian drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}"points"===e._geometry._state.primitiveName&&(a.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),a.push("float r = dot(cxy, cxy);"),a.push("if (r > 1.0) {"),a.push(" discard;"),a.push("}"));t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const vs=new e({}),ws=h.vec3(),gs=function(e,t){this.id=vs.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new ms(t),this._allocate(t)},Ts={};gs.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=Ts[t];return s||(s=new gs(t,e),Ts[t]=s,A.memory.programs++),s._useCount++,s},gs.prototype.put=function(){0==--this._useCount&&(vs.removeItem(this.id),this._program&&this._program.destroy(),delete Ts[this._hash],A.memory.programs--)},gs.prototype.webglContextRestored=function(){this._program=null},gs.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl,r=0===s?t._xrayMaterial._state:1===s?t._highlightMaterial._state:t._selectedMaterial._state,l=t._state,o=t._geometry._state,c=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,c?e.getRTCViewMatrix(l.originHash,c):i.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.viewNormalMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Edges drawing vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec4 edgeColor;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));s&&r.push("out vec4 vWorldPosition;");r.push("out vec4 vColor;"),("spherical"===i||"cylindrical"===i)&&(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r.push("vColor = edgeColor;"),s&&r.push("vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=e.scene._sectionPlanesState,n=e.scene.gammaOutput,i=s.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Edges drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const bs=new e({}),Ds=h.vec3(),Ps=function(e,t){this.id=bs.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Es(t),this._allocate(t)},Rs={};Ps.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=Rs[t];return s||(s=new Ps(t,e),Rs[t]=s,A.memory.programs++),s._useCount++,s},Ps.prototype.put=function(){0==--this._useCount&&(bs.removeItem(this.id),this._program&&this._program.destroy(),delete Rs[this._hash],A.memory.programs--)},Ps.prototype.webglContextRestored=function(){this._program=null},Ps.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl;let r;const l=t._state,o=t._geometry,c=o._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(l.originHash,u):i.viewMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh picking vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("out vec4 vViewPosition;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==i&&"cylindrical"!==i||(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"));r.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(i.push("uniform vec4 pickColor;"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = pickColor; "),i.push("}"),i}(e)}}const _s=h.vec3(),Bs=function(e,t){this._hash=e,this._shaderSource=new Cs(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Os={};Bs.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let s=Os[t];if(!s){if(s=new Bs(t,e),s.errors)return console.log(s.errors.join("\n")),null;Os[t]=s,A.memory.programs++}return s._useCount++,s},Bs.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Os[this._hash],A.memory.programs--)},Bs.prototype.webglContextRestored=function(){this._program=null},Bs.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(i.originHash,l):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t>24&255,u=o>>16&255,h=o>>8&255,p=255&o;n.uniform4f(this._uPickColor,p/255,h/255,u/255,c/255),r.indicesBuf?(n.drawElements(r.primitive,r.indicesBuf.numItems,r.indicesBuf.itemType,0),e.drawElements++):r.positions&&n.drawArrays(n.TRIANGLES,0,r.positions.numItems)},Bs.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new we(s,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0,n=!!e._geometry._state.compressGeometry;e._state.billboard,e._state.stationary;const i=[];i.push("#version 300 es"),i.push("// Surface picking vertex shader"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform vec3 offset;"),s&&(i.push("uniform bool clippable;"),i.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"));i.push("out vec4 vColor;"),n&&i.push("uniform mat4 positionsDecodeMatrix;");i.push("void main(void) {"),i.push("vec4 localPosition = vec4(position, 1.0); "),n&&i.push("localPosition = positionsDecodeMatrix * localPosition;");i.push(" vec4 worldPosition = modelMatrix * localPosition; "),i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),s&&i.push(" vWorldPosition = worldPosition;");i.push(" vColor = color;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return i.push("gl_Position = clipPos;"),i.push("}"),i}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Surface picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = vColor;"),i.push("}"),i}(e)}}const Ns=h.vec3(),xs=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Ss(t),this._allocate(t)},Ls={};xs.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=Ls[t];if(!s){if(s=new xs(t,e),s.errors)return console.log(s.errors.join("\n")),null;Ls[t]=s,A.memory.programs++}return s._useCount++,s},xs.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Ls[this._hash],A.memory.programs--)},xs.prototype.webglContextRestored=function(){this._program=null},xs.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry,l=t._geometry._state,o=t.origin,c=a.backfaces,u=a.frontface,h=s.camera.project,p=r._getPickTrianglePositions(),A=r._getPickTriangleColors();if(this._program.bind(),e.useProgram++,s.logarithmicDepthBufferEnabled){const e=2/(Math.log(h.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,e)}if(n.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCPickViewMatrix(i.originHash,o):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh occlusion vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push("}"),i}(e)}}const Fs=h.vec3(),Hs=function(e,t){this._hash=e,this._shaderSource=new Ms(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Us={};Hs.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";");let s=Us[t];if(!s){if(s=new Hs(t,e),s.errors)return console.log(s.errors.join("\n")),null;Us[t]=s,A.memory.programs++}return s._useCount++,s},Hs.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Us[this._hash],A.memory.programs--)},Hs.prototype.webglContextRestored=function(){this._program=null},Hs.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._material._state,a=t._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),i.id!==this._lastMaterialId){const t=i.backfaces;e.backfaces!==t&&(t?n.disable(n.CULL_FACE):n.enable(n.CULL_FACE),e.backfaces=t);const s=i.frontface;e.frontface!==s&&(s?n.frontFace(n.CCW):n.frontFace(n.CW),e.frontface=s),this._lastMaterialId=i.id}const o=s.camera;if(n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCViewMatrix(a.originHash,l):o.viewMatrix),a.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,s=!!e._geometry._state.compressGeometry,n=[];n.push("// Mesh shadow vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),n.push("uniform vec3 offset;"),s&&n.push("uniform mat4 positionsDecodeMatrix;");t&&n.push("out vec4 vWorldPosition;");n.push("void main(void) {"),n.push("vec4 localPosition = vec4(position, 1.0); "),n.push("vec4 worldPosition;"),s&&n.push("localPosition = positionsDecodeMatrix * localPosition;");n.push("worldPosition = modelMatrix * localPosition;"),n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&n.push("vWorldPosition = worldPosition;");return n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n}(e),this.fragment=function(e){const t=e.scene;t.canvas.gl;const s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("// Mesh shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}return i.push("outColor = encodeFloat(gl_FragCoord.z);"),i.push("}"),i}(e)}}const Vs=function(e,t){this._hash=e,this._shaderSource=new Gs(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},js={};Vs.get=function(e){const t=e.scene,s=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let n=js[s];if(!n){if(n=new Vs(s,e),n.errors)return console.log(n.errors.join("\n")),null;js[s]=n,A.memory.programs++}return n._useCount++,n},Vs.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete js[this._hash],A.memory.programs--)},Vs.prototype.webglContextRestored=function(){this._program=null},Vs.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene.canvas.gl,n=t._material._state,i=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.id!==this._lastMaterialId){const t=n.backfaces;e.backfaces!==t&&(t?s.disable(s.CULL_FACE):s.enable(s.CULL_FACE),e.backfaces=t);const i=n.frontface;e.frontface!==i&&(i?s.frontFace(s.CCW):s.frontFace(s.CW),e.frontface=i),e.lineWidth!==n.lineWidth&&(s.lineWidth(n.lineWidth),e.lineWidth=n.lineWidth),this._uPointSize&&s.uniform1i(this._uPointSize,n.pointSize),this._lastMaterialId=n.id}if(s.uniformMatrix4fv(this._uModelMatrix,s.FALSE,t.worldMatrix),i.combineGeometry){const n=t.vertexBufs;n.id!==this._lastVertexBufsId&&(n.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(n.positionsBuf,n.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),this._lastVertexBufsId=n.id)}this._uClippable&&s.uniform1i(this._uClippable,t._state.clippable),s.uniform3fv(this._uOffset,t._state.offset),i.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,i.positionsDecodeMatrix),i.combineGeometry?i.indicesBufCombined&&(i.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(i.positionsBuf,i.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),i.indicesBuf&&(i.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=i.id),i.combineGeometry?i.indicesBufCombined&&(s.drawElements(i.primitive,i.indicesBufCombined.numItems,i.indicesBufCombined.itemType,0),e.drawElements++):i.indicesBuf?(s.drawElements(i.primitive,i.indicesBuf.numItems,i.indicesBuf.itemType,0),e.drawElements++):i.positions&&(s.drawArrays(s.TRIANGLES,0,i.positions.numItems),e.drawArrays++)},Vs.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new we(s,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uShadowViewMatrix=n.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=n.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0){let e,t,i,a,r;for(let l=0,o=this._uSectionPlanes.length;l0)for(let s=0;s0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}const tn=function(){const e=h.vec3(),t=h.vec3(),s=h.vec3(),n=h.vec3(),i=h.vec3(),a=h.vec3(),r=h.vec4(),l=h.vec3(),o=h.vec3(),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3(),y=h.vec4(),m=h.vec4(),v=h.vec4(),w=h.vec3(),g=h.vec3(),T=h.vec3(),E=h.vec3(),b=h.vec3(),D=h.vec3(),P=h.vec3(),R=h.vec3(),C=h.vec3(),_=h.vec3(),O=h.vec3();return function(S,N,x,L){var M=L.primIndex;if(null!=M&&M>-1){const G=S.geometry._state,V=S.scene,j=V.camera,k=V.canvas;if("triangles"===G.primitiveName){L.primitive="triangle";const V=M,Q=G.indices,W=G.positions;let z,K,Y;if(Q){var F=Q[V+0],H=Q[V+1],U=Q[V+2];a[0]=F,a[1]=H,a[2]=U,L.indices=a,z=3*F,K=3*H,Y=3*U}else z=3*V,K=z+3,Y=K+3;if(s[0]=W[z+0],s[1]=W[z+1],s[2]=W[z+2],n[0]=W[K+0],n[1]=W[K+1],n[2]=W[K+2],i[0]=W[Y+0],i[1]=W[Y+1],i[2]=W[Y+2],G.compressGeometry){const e=G.positionsDecodeMatrix;e&&(wt.decompressPosition(s,e,s),wt.decompressPosition(n,e,n),wt.decompressPosition(i,e,i))}L.canvasPos?h.canvasPosToLocalRay(k.canvas,S.origin?B(N,S.origin):N,x,S.worldMatrix,L.canvasPos,e,t):L.origin&&L.direction&&h.worldRayToLocalRay(S.worldMatrix,L.origin,L.direction,e,t),h.normalizeVec3(t),h.rayPlaneIntersect(e,t,s,n,i,r),L.localPos=r,L.position=r,y[0]=r[0],y[1]=r[1],y[2]=r[2],y[3]=1,h.transformVec4(S.worldMatrix,y,m),l[0]=m[0],l[1]=m[1],l[2]=m[2],L.canvasPos&&S.origin&&(l[0]+=S.origin[0],l[1]+=S.origin[1],l[2]+=S.origin[2]),L.worldPos=l,h.transformVec4(j.matrix,m,v),o[0]=v[0],o[1]=v[1],o[2]=v[2],L.viewPos=o,h.cartesianToBarycentric(r,s,n,i,c),L.bary=c;const X=G.normals;if(X){if(G.compressGeometry){const e=3*F,t=3*H,s=3*U;wt.decompressNormal(X.subarray(e,e+2),u),wt.decompressNormal(X.subarray(t,t+2),p),wt.decompressNormal(X.subarray(s,s+2),A)}else u[0]=X[z],u[1]=X[z+1],u[2]=X[z+2],p[0]=X[K],p[1]=X[K+1],p[2]=X[K+2],A[0]=X[Y],A[1]=X[Y+1],A[2]=X[Y+2];const e=h.addVec3(h.addVec3(h.mulVec3Scalar(u,c[0],w),h.mulVec3Scalar(p,c[1],g),T),h.mulVec3Scalar(A,c[2],E),b);L.worldNormal=h.normalizeVec3(h.transformVec3(S.worldNormalMatrix,e,D))}const q=G.uv;if(q){if(d[0]=q[2*F],d[1]=q[2*F+1],f[0]=q[2*H],f[1]=q[2*H+1],I[0]=q[2*U],I[1]=q[2*U+1],G.compressGeometry){const e=G.uvDecodeMatrix;e&&(wt.decompressUV(d,e,d),wt.decompressUV(f,e,f),wt.decompressUV(I,e,I))}L.uv=h.addVec3(h.addVec3(h.mulVec2Scalar(d,c[0],P),h.mulVec2Scalar(f,c[1],R),C),h.mulVec2Scalar(I,c[2],_),O)}}}}}();function sn(e={}){let t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);let s=e.radiusBottom||1;s<0&&(console.error("negative radiusBottom not allowed - will invert"),s*=-1);let n=e.height||1;n<0&&(console.error("negative height not allowed - will invert"),n*=-1);let i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);let a=e.heightSegments||1;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),a<1&&(a=1);const r=!!e.openEnded;let l=e.center;const o=l?l[0]:0,c=l?l[1]:0,u=l?l[2]:0,h=n/2,p=n/a,A=2*Math.PI/i,d=1/i,f=(t-s)/a,I=[],m=[],v=[],w=[];let g,T,E,b,D,P,R,C,_,B,O;const S=(90-180*Math.atan(n/(s-t))/Math.PI)/90;for(g=0;g<=a;g++)for(D=t-g*f,P=h-g*p,T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),m.push(D*E),m.push(S),m.push(D*b),v.push(T*d),v.push(1*g/a),I.push(D*E+o),I.push(P+c),I.push(D*b+u);for(g=0;g0){for(_=I.length/3,m.push(0),m.push(1),m.push(0),v.push(.5),v.push(.5),I.push(0+o),I.push(h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,m.push(t*E),m.push(1),m.push(t*b),v.push(B),v.push(O),I.push(t*E+o),I.push(h+c),I.push(t*b+u);for(T=0;T0){for(_=I.length/3,m.push(0),m.push(-1),m.push(0),v.push(.5),v.push(.5),I.push(0+o),I.push(0-h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,m.push(s*E),m.push(-1),m.push(s*b),v.push(B),v.push(O),I.push(s*E+o),I.push(0-h+c),I.push(s*b+u);for(T=0;T":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function rn(e={}){var t=e.origin||[0,0,0],s=t[0],n=t[1],i=t[2],a=e.size||1,r=[],l=[],o=e.text;y.isNumeric(o)&&(o=""+o);for(var c,u,h,p,A,d,f,I,m,v=(o||"").split("\n"),w=0,g=0,T=.04,E=0;E0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length){const e=this._children.splice();let t;for(let s=0,n=e.length;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=Dn(s,this.wrapS);a&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,a);const r=Dn(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=Dn(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,_n(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,_n(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Dn(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Dn(s,this.magFilter)));const l=Dn(s,this.format,this.encoding),o=Dn(s,this.type),c=Cn(s,this.internalFormat,l,o,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,n,c,e[0].width,e[0].height);for(let t=0,n=e.length;t>t;return e+1}class Nn extends C{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new Ve({texture:new Rn({gl:this.scene.canvas.gl}),matrix:h.identityMat4(),hasMatrix:t.translate&&(0!==t.translate[0]||0!==t.translate[1])||!!t.rotate||t.scale&&(0!==t.scale[0]||0!==t.scale[1]),minFilter:this._checkMinFilter(t.minFilter),magFilter:this._checkMagFilter(t.magFilter),wrapS:this._checkWrapS(t.wrapS),wrapT:this._checkWrapT(t.wrapT),flipY:this._checkFlipY(t.flipY),encoding:this._checkEncoding(t.encoding)}),this._src=null,this._image=null,this._translate=h.vec2([0,0]),this._scale=h.vec2([1,1]),this._rotate=h.vec2([0,0]),this._matrixDirty=!1,this.translate=t.translate,this.scale=t.scale,this.rotate=t.rotate,t.src?this.src=t.src:t.image&&(this.image=t.image),A.memory.textures++}_checkMinFilter(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}_checkMagFilter(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}_checkWrapS(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkWrapT(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this._state.texture=new Rn({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}_update(){const e=this._state;if(this._matrixDirty){let t,s;0===this._translate[0]&&0===this._translate[1]||(t=h.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(s=h.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?h.mulMat4(t,s):s),0!==this._rotate&&(s=h.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?h.mulMat4(t,s):s),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=Bn(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}get image(){return this._image}set src(e){this.scene.loading++,this.scene.canvas.spinner.processes++;const t=this;let s=new Image;s.onload=function(){s=Bn(s),t._state.texture.setImage(s,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},s.src=e,this._src=e,this._image=null}get src(){return this._src}set translate(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}get translate(){return this._translate}set scale(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}get scale(){return this._scale}set rotate(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}get rotate(){return this._rotate}get minFilter(){return this._state.minFilter}get magFilter(){return this._state.magFilter}get wrapS(){return this._state.wrapS}get wrapT(){return this._state.wrapT}get flipY(){return this._state.flipY}get encoding(){return this._state.encoding}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),A.memory.textures--}}const xn=A.memory,Ln=h.AABB3();class Mn extends pt{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new Ve({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._aabb=null,this._obb=h.OBB3();const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(t.indices){var i;if(t.positionsDecodeMatrix);else{const e=wt.getPositionsBounds(t.positions),a=wt.compressPositions(t.positions,e.min,e.max);i=a.quantized,s.positionsDecodeMatrix=a.decodeMatrix,s.positionsBuf=new ge(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),xn.positions+=s.positionsBuf.numItems,h.positions3ToAABB3(t.positions,this._aabb),h.positions3ToAABB3(i,Ln,s.positionsDecodeMatrix),h.AABB3ToOBB3(Ln,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);s.colorsBuf=new ge(n,n.ARRAY_BUFFER,e,e.length,4,n.STATIC_DRAW),xn.colors+=s.colorsBuf.numItems}if(t.uv){const e=wt.getUVBounds(t.uv),i=wt.compressUVs(t.uv,e.min,e.max),a=i.quantized;s.uvDecodeMatrix=i.decodeMatrix,s.uvBuf=new ge(n,n.ARRAY_BUFFER,a,a.length,2,n.STATIC_DRAW),xn.uvs+=s.uvBuf.numItems}if(t.normals){const e=wt.compressNormals(t.normals);let i=s.compressGeometry;s.normalsBuf=new ge(n,n.ARRAY_BUFFER,e,e.length,3,n.STATIC_DRAW,i),xn.normals+=s.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);s.indicesBuf=new ge(n,n.ELEMENT_ARRAY_BUFFER,e,e.length,1,n.STATIC_DRAW),xn.indices+=s.indicesBuf.numItems;const a=At(i,e,s.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new ge(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),xn.meshes++}else this.error("Config expected: indices");else this.error("Config expected: positions")}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf}get primitive(){return this._state.primitiveName}get aabb(){return this._aabb}get obb(){return this._obb}get numTriangles(){return this._numTriangles}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),xn.meshes--}}var Fn={};function Hn(e={}){let t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);let s=e.divisions||1;s<0&&(console.error("negative divisions not allowed - will invert"),s*=-1),s<1&&(s=1),t=t||10,s=s||10;const n=t/s,i=t/2,a=[],r=[];let l=0;for(let e=0,t=-i;e<=s;e++,t+=n)a.push(-i),a.push(0),a.push(t),a.push(i),a.push(0),a.push(t),a.push(t),a.push(0),a.push(-i),a.push(t),a.push(0),a.push(i),r.push(l++),r.push(l++),r.push(l++),r.push(l++);return y.apply(e,{primitive:"lines",positions:a,indices:r})}function Un(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);let n=e.xSegments||1;n<0&&(console.error("negative xSegments not allowed - will invert"),n*=-1),n<1&&(n=1);let i=e.xSegments||1;i<0&&(console.error("negative zSegments not allowed - will invert"),i*=-1),i<1&&(i=1);const a=e.center,r=a?a[0]:0,l=a?a[1]:0,o=a?a[2]:0,c=t/2,u=s/2,h=Math.floor(n)||1,p=Math.floor(i)||1,A=h+1,d=p+1,f=t/h,I=s/p,m=new Float32Array(A*d*3),v=new Float32Array(A*d*3),w=new Float32Array(A*d*2);let g,T,E,b,D,P,R,C=0,_=0;for(g=0;g65535?Uint32Array:Uint16Array)(h*p*6);for(g=0;g360&&(a=360);const r=e.center;let l=r?r[0]:0,o=r?r[1]:0;const c=r?r[2]:0,u=[],p=[],A=[],d=[];let f,I,m,v,w,g,T,E,b,D,P,R;for(E=0;E<=i;E++)for(T=0;T<=n;T++)f=T/n*a,I=.785398+E/i*Math.PI*2,l=t*Math.cos(f),o=t*Math.sin(f),m=(t+s*Math.cos(I))*Math.cos(f),v=(t+s*Math.cos(I))*Math.sin(f),w=s*Math.sin(I),u.push(m+l),u.push(v+o),u.push(w+c),A.push(1-T/n),A.push(E/i),g=h.normalizeVec3(h.subVec3([m,v,w],[l,o,c],[]),[]),p.push(g[0]),p.push(g[1]),p.push(g[2]);for(E=1;E<=i;E++)for(T=1;T<=n;T++)b=(n+1)*E+T-1,D=(n+1)*(E-1)+T-1,P=(n+1)*(E-1)+T,R=(n+1)*E+T,d.push(b),d.push(D),d.push(P),d.push(P),d.push(R),d.push(b);return y.apply(e,{positions:u,normals:p,uv:A,indices:d})}Fn.load=function(e,t){var s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="arraybuffer",s.onload=function(e){t(e.target.response)},s.send()},Fn.save=function(e,t){var s="data:application/octet-stream;base64,"+btoa(Fn.parse._buffToStr(e));window.location.href=s},Fn.clone=function(e){return JSON.parse(JSON.stringify(e))},Fn.bin={},Fn.bin.f=new Float32Array(1),Fn.bin.fb=new Uint8Array(Fn.bin.f.buffer),Fn.bin.rf=function(e,t){for(var s=Fn.bin.f,n=Fn.bin.fb,i=0;i<4;i++)n[i]=e[t+i];return s[0]},Fn.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Fn.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Fn.bin.rASCII0=function(e,t){for(var s="";0!=e[t];)s+=String.fromCharCode(e[t++]);return s},Fn.bin.wf=function(e,t,s){new Float32Array(e.buffer,t,1)[0]=s},Fn.bin.wsl=function(e,t,s){e[t]=s,e[t+1]=s>>8},Fn.bin.wil=function(e,t,s){e[t]=s,e[t+1]=s>>8,e[t+2]=s>>16,e[t+3]},Fn.parse={},Fn.parse._buffToStr=function(e){for(var t=new Uint8Array(e),s="",n=0;ni&&(i=o),ca&&(a=c),ur&&(r=u)}return{min:{x:t,y:s,z:n},max:{x:i,y:a,z:r}}};class Vn extends C{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=h.vec3(t.pos||[0,0,0]),this._up=h.vec3(t.up||[0,1,0]),this._normal=h.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=h.vec3(),this._rtcPos=h.vec3(),this._imageSize=h.vec2(),this._texture=new Nn(this),this._image=new Image,"jpg"!==this._type&&"png"!==this._type&&(this.error('Unsupported type - defaulting to "jpg"'),this._type="jpg"),this._node=new yn(this,{matrix:h.inverseMat4(h.lookAtMat4v(this._pos,h.subVec3(this._pos,this._normal,h.mat4()),this._up,h.mat4())),children:[this._bitmapMesh=new en(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new Et(this,Un({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new Ct(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0})})]}),t.image?this.image=t.image:t.src?this.src=t.src:t.imageData&&(this.imageData=t.imageData),this.scene._bitmapCreated(this)}set visible(e){this._bitmapMesh.visible=e}get visible(){return this._bitmapMesh.visible}set image(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}get image(){return this._image}set src(e){if(e){this._image.onload=()=>{this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale()},this._image.src=e;switch(e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}}get src(){return this._image.src}set imageData(e){this._image.onload=()=>{this._texture.image=image,this._imageSize[0]=image.width,this._imageSize[1]=image.height,this._updateBitmapMeshScale()},this._image.src=e}get imageData(){const e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")}set type(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}get type(){return this._type}get pos(){return this._pos}get normal(){return this._normal}get up(){return this._up}set height(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}get height(){return this._height}set collidable(e){this._bitmapMesh.collidable=!1!==e}get collidable(){return this._bitmapMesh.collidable}set clippable(e){this._bitmapMesh.clippable=!1!==e}get clippable(){return this._bitmapMesh.clippable}set pickable(e){this._bitmapMesh.pickable=!1!==e}get pickable(){return this._bitmapMesh.pickable}set opacity(e){this._bitmapMesh.opacity=e}get opacity(){return this._bitmapMesh.opacity}destroy(){super.destroy(),this.scene._bitmapDestroyed(this)}_updateBitmapMeshScale(){const e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height*e,1,this._height]}}class jn extends C{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],this._origin=h.vec3(t.origin||[0,0,0]),t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e{var i=e-s,a=t-n;return Math.sqrt(i*i+a*a)};class $n 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._eventSubs={};var s=this.plugin.viewer.scene;this._originMarker=new Y(s,t.origin),this._targetMarker=new Y(s,t.target),this._originWorld=h.vec3(),this._targetWorld=h.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;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._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._lengthWire=new X(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._xAxisWire=new X(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._yAxisWire=new X(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._zAxisWire=new X(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._lengthLabel=new J(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._xAxisLabel=new J(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._yAxisLabel=new J(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._zAxisLabel=new J(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,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._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._onMetricsUnits=s.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=s.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=s.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;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._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=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._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0);const t=this._originMarker.viewPos[2],s=this._targetMarker.viewPos[2];if(t>-.3||s>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){h.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var n=this._pp,i=this._cp,a=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var r=a.top-t.top,l=a.left-t.left,o=e.canvas.boundary,c=o[2],u=o[3],p=0;const s=this.plugin.viewer.scene.metrics,f=s.scale,I=s.units,y=s.unitsInfo[I].abbrev;for(var A=0,d=n.length;A1?i.other:i.one,i?(i=si(i,[t]),s&&(i=si(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const a=this._events[t];return void 0!==a&&s(a),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function ti(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var s=e-t,n=e+t;s<0&&(s=0),n>1&&(n=1);var i=this.getPoint(s),a=this.getPoint(n),r=h.subVec3(a,i,[]);return h.normalizeVec3(r,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,s,n=[],i=this.getPoint(0),a=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),a+=h.lenVec3(h.subVec3(t,i,[])),n.push(a),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,a=n.length;s=t||e*n[a-1];for(var r,l=0,o=a-1;l<=o;)if((r=n[i=Math.floor(l+(o-l)/2)]-s)<0)l=i+1;else{if(!(r>0)){o=i;break}o=i-1}if(n[i=o]===s)return i/(a-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(a-1)}}class ii extends ni{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var s=(t.length-1)*e,n=Math.floor(s),i=s-n,a=t[0===n?n:n-1],r=t[n],l=t[n>t.length-2?t.length-1:n+1],o=t[n>t.length-3?t.length-1:n+2],c=h.vec3();return c[0]=h.catmullRomInterpolate(a[0],r[0],l[0],o[0],i),c[1]=h.catmullRomInterpolate(a[1],r[1],l[1],o[1],i),c[2]=h.catmullRomInterpolate(a[2],r[2],l[2],o[2],i),c}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const ai=h.vec3();const ri=h.vec3(),li=h.vec3(),oi=h.vec3(),ci=h.vec3(),ui=h.vec3();class hi extends C{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=h.vec3(),this._eye1=h.vec3(),this._up1=h.vec3(),this._look2=h.vec3(),this._eye2=h.vec3(),this._up2=h.vec3(),this._orthoScale1=1,this._orthoScale2=1,this._flying=!1,this._flyEyeLookUp=!1,this._flyingEye=!1,this._flyingLook=!1,this._callback=null,this._callbackScope=null,this._time1=null,this._time2=null,this.easing=!1!==t.easing,this.duration=t.duration,this.fit=t.fit,this.fitFOV=t.fitFOV,this.trail=t.trail}flyTo(e,t,s){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=s;const n=this.scene.camera,i=!!e.projection&&e.projection!==n.projection;let a,r,l,o,c;if(this._eye1[0]=n.eye[0],this._eye1[1]=n.eye[1],this._eye1[2]=n.eye[2],this._look1[0]=n.look[0],this._look1[1]=n.look[1],this._look1[2]=n.look[2],this._up1[0]=n.up[0],this._up1[1]=n.up[1],this._up1[2]=n.up[2],this._orthoScale1=n.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)a=e.aabb;else if(6===e.length)a=e;else if(e.eye&&e.look||e.up)r=e.eye,l=e.look,o=e.up;else if(e.eye)r=e.eye;else if(e.look)l=e.look;else{let n=e;if((y.isNumeric(n)||y.isString(n))&&(c=n,n=this.scene.components[c],!n))return this.error("Component not found: "+y.inQuotes(c)),void(t&&(s?t.call(s):t()));i||(a=n.aabb||this.scene.aabb)}const u=e.poi;if(a){if(a[3]=1;e>1&&(e=1);const s=this.easing?hi._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(h.subVec3(n.eye,n.look,ui),n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,oi),n.look=h.subVec3(oi,ui,li)):this._flyingLook&&(n.look=h.lerpVec3(s,0,1,this._look1,this._look2,li),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,ci)):this._flyingEyeLookUp&&(n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,oi),n.look=h.lerpVec3(s,0,1,this._look1,this._look2,li),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,ci)),this._projection2){const t="ortho"===this._projection2?hi._easeOutExpo(e,0,1,1):hi._easeInCubic(e,0,1,1);n.customProjection.matrix=h.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();P.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class pi extends C{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new hi(this),this._t=0,this.state=pi.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case pi.SCRUBBING:return;case pi.PLAYING:if(this._t+=this._playingRate*i,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=pi.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case pi.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=pi.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=pi.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=pi.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=pi.SCRUBBING,this._cameraFlightAnimation.flyTo(n,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=pi.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=pi.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=pi.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}pi.STOPPED=0,pi.SCRUBBING=1,pi.PLAYING=2,pi.PLAYING_TO=3;const Ai=h.vec3(),di=h.vec3();h.vec3();const fi=h.vec3([0,-1,0]),Ii=h.vec4([0,0,0,1]);function yi(e){if(!mi(e.width)||!mi(e.height)){const t=document.createElement("canvas");t.width=vi(e.width),t.height=vi(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function mi(e){return 0==(e&e-1)}function vi(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class wi extends C{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new Ve({texture:new Rn({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),A.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let a=0;a0){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;_i[0]=s,_i[1]=n,_i[2]=t.blendCutoff,_i[3]=t.blendFactor,l.uniform4fv(this._uSAOParams,_i),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===Pi[(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===Pi[(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===Pi[(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?Ci:Ri)}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 Si extends Oi{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 Ni extends Si{constructor(e,t){super(e,t,{instancing:!1,edges:!0})}}class xi extends Oi{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 Li extends xi{constructor(e,t){super(e,t,{instancing:!0,edges:!0})}}class Mi extends Oi{_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 Fi extends Oi{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 Hi extends Oi{_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 Ui extends Oi{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 Gi extends Si{_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 Vi extends Si{_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 ki extends Ni{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class Qi extends Ni{_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 Wi extends Si{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class zi extends Si{_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 Ki extends Si{_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 Yi extends Si{_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 Xi extends Si{_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 qi extends Si{_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 Ji extends Si{_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 Zi extends Si{_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 ea extends Si{_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 ia=h.mat4(),aa=h.mat4();function ra(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 ca(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 ua=h.vec3();class ha{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.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[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.snapPickCoordinateScale[0]=h.safeInv(p[0]),e.snapPickCoordinateScale[1]=h.safeInv(p[1]),e.snapPickCoordinateScale[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.snapPickLayerNumber),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 pa=h.vec3();class Aa{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.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[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.snapPickCoordinateScale[0]=h.safeInv(u[0]),e.snapPickCoordinateScale[1]=h.safeInv(u[1]),e.snapPickCoordinateScale[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.snapPickLayerNumber),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("gl_PointSize = 1.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("// 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 da{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 ha(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Aa(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const fa={};const Ia=h.mat4(),ya=h.mat4(),ma=h.vec4([0,0,0,1]),va=h.vec4([0,0,0,1]),wa=h.vec4([0,0,0,1]),ga=h.OBB3(),Ta=h.vec3(),Ea=h.vec3(),ba=h.vec3(),Da=h.vec3(),Pa=h.vec3(),Ra=h.vec3(),Ca=h.vec3();class _a{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=sa[t];return s||(s=new ta(e),sa[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete sa[t],s._destroy()}))),s}(e.model.scene),this._snapBatchingRenderers=function(e){const t=e.id;let s=fa[t];return s||(s=new da(e),fa[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete fa[t],s._destroy()}))),s}(e.model.scene),this._buffer=new na(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Ve({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=Ia;I?h.inverseMat4(h.transposeMat4(I,ya),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=oa(d,"floor","ceil"),l=ca(r),c=a(d,l),c>u&&(o=r,u=c),r=oa(d,"ceil","ceil"),l=ca(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):ra(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=wt.getUVBounds(s.uv),i=wt.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 Ba extends xi{_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 Oa extends xi{_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 Na extends Li{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 xa extends Li{_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 La extends xi{_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 Ma extends xi{_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 Fa extends xi{_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 Ha extends xi{_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("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 = 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 Ua extends xi{_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 Ga extends xi{_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 Va extends xi{_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 ja={3e3:"linearToLinear",3001:"sRGBToLinear"};class ka extends xi{_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 = "+ja[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 = "+ja[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 Wa extends xi{_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*I,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),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 qa=h.vec3();class Ja{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;e.snapPickOrigin[0]=l[0],e.snapPickOrigin[1]=l[1],e.snapPickOrigin[2]=l[2];const o=t.aabb,c=[h.safeInv(o[3]-o[0])*h.MAX_INT,h.safeInv(o[4]-o[1])*h.MAX_INT,h.safeInv(o[5]-o[2])*h.MAX_INT];if(e.snapPickCoordinateScale[0]=h.safeInv(c[0]),e.snapPickCoordinateScale[1]=h.safeInv(c[1]),e.snapPickCoordinateScale[2]=h.safeInv(c[2]),!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const u=i.camera;let p=u.eye;e.pickViewMatrix&&(p=e.pickOrigin||p);const A=[p[0]-l[0],p[1]-l[1],p[2]-l[2]];a.uniform3fv(this._uCameraEyeRtc,A),a.uniform2fv(this.uVectorA,e.snapVectorA),a.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),a.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),a.uniform3fv(this._uCoordinateScaler,c),a.uniform1i(this._uRenderPass,s),a.uniform1i(this._uPickInvisible,e.pickInvisible);const d=e.pickViewMatrix||u.viewMatrix,f=l?B(d,l):d;if(a.uniformMatrix4fv(this._uViewMatrix,!1,f),a.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),a.uniformMatrix4fv(this._uProjMatrix,!1,u.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);a.uniform1f(this._uLogDepthBufFC,t)}const I=i._sectionPlanesState.sectionPlanes.length;if(I>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*I,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),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("gl_PointSize = 1.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("// SnapInstancingDepthRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),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}}class Za{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 Xa(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Ja(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const $a={};const er=new Uint8Array(4),tr=new Float32Array(1),sr=h.vec4([0,0,0,1]),nr=h.vec4([0,0,0,1]),ir=h.vec4([0,0,0,1]),ar=new Float32Array(3),rr=h.vec3(),lr=h.vec3(),or=h.vec3(),cr=h.vec3(),ur=h.vec3(),hr=h.vec3(),pr=h.vec3();class Ar{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=Ka[t];return s||(s=new za(e),Ka[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Ka[t],s._destroy()}))),s}(e.model.scene),this._snapInstancingRenderers=function(e){const t=e.id;let s=$a[t];return s||(s=new Za(e),$a[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete $a[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new Ve({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";er[0]=t[0],er[1]=t[1],er[2]=t[2],er[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(er,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?Pi.NOT_RENDERED:s?Pi.COLOR_TRANSPARENT:Pi.COLOR_OPAQUE,h=!n||c?Pi.NOT_RENDERED:r?Pi.SILHOUETTE_SELECTED:a?Pi.SILHOUETTE_HIGHLIGHTED:i?Pi.SILHOUETTE_XRAYED:Pi.NOT_RENDERED;let p=0;p=!n||c?Pi.NOT_RENDERED:r?Pi.EDGES_SELECTED:a?Pi.EDGES_HIGHLIGHTED:i?Pi.EDGES_XRAYED:l?s?Pi.EDGES_COLOR_TRANSPARENT:Pi.EDGES_COLOR_OPAQUE:Pi.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Pi.PICK:Pi.NOT_RENDERED)<<12,A|=(t&F?1:0)<<16,tr[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(tr,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(ar[0]=t[0],ar[1]=t[1],ar[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(ar,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=sr,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 dr extends Hi{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 fr extends Hi{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 Ir{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 dr(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new fr(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const yr={};class mr{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]}}const vr=h.vec4([0,0,0,1]),wr=h.vec4([0,0,0,1]),gr=h.vec4([0,0,0,1]),Tr=h.OBB3();class Er{constructor(e){this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=yr[t];return s||(s=new Ir(e),yr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete yr[t],s._destroy()}))),s}(e.model.scene),this.model=e.model,this._buffer=new mr(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Ve({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=ra(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 Dr extends Ui{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// 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 Pr{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 br(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Dr(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const Rr={};const Cr=new Uint8Array(4),_r=new Float32Array(1),Br=h.vec4([0,0,0,1]),Or=h.vec4([0,0,0,1]),Sr=h.vec4([0,0,0,1]),Nr=new Float32Array(3);class xr{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=Rr[t];return s||(s=new Pr(e),Rr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Rr[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new Ve({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";Cr[0]=t[0],Cr[1]=t[1],Cr[2]=t[2],Cr[3]=t[3],this._state.colorsBuf.setData(Cr,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?Pi.NOT_RENDERED:s?Pi.COLOR_TRANSPARENT:Pi.COLOR_OPAQUE,h=!n||c?Pi.NOT_RENDERED:r?Pi.SILHOUETTE_SELECTED:a?Pi.SILHOUETTE_HIGHLIGHTED:i?Pi.SILHOUETTE_XRAYED:Pi.NOT_RENDERED;let p=0;p=!n||c?Pi.NOT_RENDERED:r?Pi.EDGES_SELECTED:a?Pi.EDGES_HIGHLIGHTED:i?Pi.EDGES_XRAYED:l?s?Pi.EDGES_COLOR_TRANSPARENT:Pi.EDGES_COLOR_OPAQUE:Pi.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Pi.PICK:Pi.NOT_RENDERED)<<12,A|=(t&F?255:0)<<16,_r[0]=A,this._state.flagsBuf.setData(_r,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Nr[0]=t[0],Nr[1]=t[1],Nr[2]=t[2],this._state.offsetsBuf.setData(Nr,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,Pi.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,Pi.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,Pi.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Pi.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Pi.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 Lr extends Mi{_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 Mr extends Mi{_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 Fr extends Mi{_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 Hr extends Mi{_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 Ur extends Mi{_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 Gr{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 Lr(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Mr(this._scene)),this._silhouetteRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Fr(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Hr(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new Ur(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 Vr={};class jr{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 kr=h.vec4(),Qr=h.vec4(),Wr=h.vec4([0,0,0,1]),zr=h.vec4([0,0,0,1]),Kr=h.vec4([0,0,0,1]),Yr=h.OBB3();class Xr{constructor(e){this.model=e.model,this.sortId="PointsBatchingLayer",this.layerIndex=e.layerIndex,this._pointsBatchingRenderers=function(e){const t=e.id;let s=Vr[t];return s||(s=new Gr(e),Vr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Vr[t],s._destroy()}))),s}(e.model.scene),this._buffer=new jr(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Ve({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=ra(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 Jr extends Fi{_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 Zr extends Fi{_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 $r extends Fi{_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 el extends Fi{_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 tl extends Fi{_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 sl extends Fi{_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 nl{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 qr(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Jr(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new tl(this._scene)),this._depthRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Zr(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new $r(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new el(this._scene)),this._occlusionRenderer}get shadowRenderer(){return this._shadowRenderer||(this._shadowRenderer=new sl(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 il={};const al=new Uint8Array(4),rl=new Float32Array(1),ll=h.vec4([0,0,0,1]),ol=h.vec4([0,0,0,1]),cl=h.vec4([0,0,0,1]),ul=new Float32Array(3);class hl{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=il[t];return s||(s=new nl(e),il[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete il[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new Ve({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";al[0]=t[0],al[1]=t[1],al[2]=t[2],this._state.colorsBuf.setData(al,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?Pi.NOT_RENDERED:s?Pi.COLOR_TRANSPARENT:Pi.COLOR_OPAQUE,h=!n||c?Pi.NOT_RENDERED:r?Pi.SILHOUETTE_SELECTED:a?Pi.SILHOUETTE_HIGHLIGHTED:i?Pi.SILHOUETTE_XRAYED:Pi.NOT_RENDERED;let p=0;p=!n||c?Pi.NOT_RENDERED:r?Pi.EDGES_SELECTED:a?Pi.EDGES_HIGHLIGHTED:i?Pi.EDGES_XRAYED:l?s?Pi.EDGES_COLOR_TRANSPARENT:Pi.EDGES_COLOR_OPAQUE:Pi.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Pi.PICK:Pi.NOT_RENDERED)<<12,A|=(t&F?255:0)<<16,rl[0]=A,this._state.flagsBuf.setData(rl,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(ul[0]=t[0],ul[1]=t[1],ul[2]=t[2],this._state.offsetsBuf.setData(ul,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,Pi.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,Pi.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,Pi.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Pi.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Pi.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,Pi.COLOR_OPAQUE)}drawShadow(e,t){}drawPickMesh(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,Pi.PICK)}drawPickDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,Pi.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 pl{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 Al{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const dl={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}};class fl{constructor(e,t,s){this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=s}itemStart(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}itemEnd(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}itemError(e){void 0!==this.onError&&this.onError(e)}resolveURL(e){return this.urlModifier?this.urlModifier(e):e}setURLModifier(e){return this.urlModifier=e,this}addHandler(e,t){return this.handlers.push(e,t),this}removeHandler(e){const t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}getHandler(e){for(let t=0,s=this.handlers.length;t{t&&t(i),this.manager.itemEnd(e)}),0),i;if(void 0!==ml[e])return void ml[e].push({onLoad:t,onProgress:s,onError:n});ml[e]=[],ml[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=ml[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=>{dl.add(e,t);const s=ml[e];delete ml[e];for(let e=0,n=s.length;e{const s=ml[e];if(void 0===s)throw this.manager.itemError(e),t;delete ml[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 wl{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 gl=0;class Tl{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 wl,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 vl;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new vl;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=Tl.BasisWorker.toString(),n=["/* constants */","let _EngineFormat = "+JSON.stringify(Tl.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(Tl.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(Tl.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}))})),gl>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),gl++}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(),gl--}}Tl.BasisFormat={ETC1S:0,UASTC_4x4:1},Tl.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},Tl.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},Tl.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 El[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 1d305d59c..2a70866c4 100644 --- a/dist/xeokit-sdk.min.es.js +++ b/dist/xeokit-sdk.min.es.js @@ -7,7 +7,7 @@ class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){ * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT */ -function is(e,t){t.length;const s=e.length,n=[],i=[],a=e=>{for(let s=0,n=e.meshIds.length;s{const s=t[e];let n,i;if(s.positionsCompressed){const e=bt.getPositionsBounds(s.positionsCompressed);n=bt.decompressPosition(e.min,s.positionsDecodeMatrix,[]),i=bt.decompressPosition(e.max,s.positionsDecodeMatrix,[])}else{const e=bt.getPositionsBounds(s.positions);n=e.min,i=e.max}n[0]+=s.origin[0],n[1]+=s.origin[1],n[2]+=s.origin[2],i[0]+=s.origin[0],i[1]+=s.origin[1],i[2]+=s.origin[2],p.expandAABB3Point3(l,n),p.expandAABB3Point3(l,i),o+=s.numPrimitives})),n[r]={aabb:l,numPrimitives:o,entityId:s.id}}let r,l=[],o={};if(Object.keys(n).length>0){r=function(e){const t=[];for(let s=0,n=e.length;s{s=Math.max(s,e.entity.id)}));const n=new Array(s+1);t.forEach((t=>{n[t.entity.id]=e.objects[t.entity.xeokitId]})),this._internalNodesList=n,this._lastVisibleFrameOfNodes=new Array(n.length),this._lastVisibleFrameOfNodes.fill(0)}_searchVisibleNodesWithFrustumCulling(){return this._aabbTree.searchCustom(((e,t)=>this._aabbIntersectsCameraFrustum(e,t)),(e=>this._aabbContainedInCameraFrustum(e)))}_markVisibleFrameOfVisibleNodes(e,t){const s=this._lastVisibleFrameOfNodes;for(let n=0,i=e.length;nthis._frustumProps.CAM_FACTOR_1?(s|=r<0?64:128,s&=-17):s&=-33;const l=os(p.dotVec3(i,this._frustumProps.up),a);Math.abs(l)>this._frustumProps.CAM_FACTOR_2?(s|=l<0?1024:2048,s&=-257):s&=-513}return 4&s&&8&s&&(s|=4096),64&s&&128&s&&(s|=8192),1024&s&&2048&s&&(s|=16384),e._check=s,s}}class us{constructor(e,t){this.sceneModel=t,this.entities=[],this.meshes=[],this.finalized=!1}addEntity(e){if(this.finalized)throw"Already finalized";this.entities.push(e)}addMesh(e){if(this.finalized)throw"Already finalized";this.meshes.push(e)}finalize(e){if(this.finalized)throw"Already finalized";this.finalized=!0,this.VFCState=new cs,this.VFCState.initializeVFCState(this.entities,this.meshes),this.VFCState.finalize(this.sceneModel,e),this._onSceneRendering=this.sceneModel.scene.on("rendering",(()=>this.applyViewFrustumCulling.call(this)))}applyViewFrustumCulling(){this.finalized&&this.VFCState.applyViewFrustumCulling(this.sceneModel)}destroy(){this.finalized&&this.sceneModel.off(this._onSceneRendering)}}class hs extends _{constructor(e,t={}){super(e,t),this._scene=e,this._vfcManagers={},this._vfcManagerList=[],this.enabled=t.enabled,this._init()}_init(){this._scene.on("rendering",(()=>{for(let e=0,t=this._vfcManagerList.length;e{this.glRedraw()})),this.canvas.on("webglContextFailed",(()=>{alert("xeokit failed to find WebGL!")})),this._renderer=new je(this,{transparent:n,alphaDepthMask:i}),this._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1;let e=null;this.getHash=function(){if(e)return e;const t=this.sectionPlanes;if(0===t.length)return this.hash=";";const s=[];for(let e=0,n=t.length;e0&&e.push("/lm"),this.reflectionMaps.length>0&&e.push("/rm"),e.push(";"),s=e.join(""),s},this.addLight=function(e){this.lights.push(e),n=null,s=null},this.removeLight=function(e){for(let t=0,i=this.lights.length;t{this._renderer.imageDirty()})),this.lod=new $t(this,{enabled:t.lodEnabled}),this.vfc=new hs(this,{enabled:t.vfcEnabled})}_initDefaults(){}_addComponent(e){if(e.id&&this.components[e.id]&&(this.error("Component "+m.inQuotes(e.id)+" already exists in Scene - ignoring ID, will randomly-generate instead"),e.id=null),!e.id)for(void 0===window.nextID&&(window.nextID=0),e.id="__"+window.nextID++;this.components[e.id];)e.id=p.createUUID();this.components[e.id]=e;const t=e.type;let s=this.types[e.type];s||(s=this.types[t]={}),s[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}_removeComponent(e){var t=e.id,s=e.type;delete this.components[t];const n=this.types[s];n&&(delete n[t],m.isEmptyObject(n)&&delete this.types[s]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}_sectionPlaneCreated(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}_bitmapCreated(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}_lineSetCreated(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}_lightCreated(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}_lightMapCreated(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}_reflectionMapCreated(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}_sectionPlaneDestroyed(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}_bitmapDestroyed(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}_lineSetDestroyed(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}_lightDestroyed(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}_lightMapDestroyed(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}_reflectionMapDestroyed(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}_registerModel(e){this.models[e.id]=e,this._modelIds=null}_deregisterModel(e){const t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}_registerObject(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}_deregisterObject(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}_objectVisibilityUpdated(e,t=!0){e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}_objectXRayedUpdated(e,t=!0){e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}_objectHighlightedUpdated(e,t=!0){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null,t&&this.fire("objectHighlighted",e,!0)}_objectSelectedUpdated(e,t=!0){e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}_objectColorizeUpdated(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}_objectOpacityUpdated(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}_objectOffsetUpdated(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}_webglContextLost(){this.canvas.spinner.processes++;for(const e in this.components)if(this.components.hasOwnProperty(e)){const t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}_webglContextRestored(){const e=this.canvas.gl;for(const t in this.components)if(this.components.hasOwnProperty(t)){const s=this.components[t];s._webglContextRestored&&s._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}get capabilities(){return this._renderer.capabilities}get entityOffsetsEnabled(){return this._entityOffsetsEnabled}get pickSurfacePrecisionEnabled(){return!1}get logarithmicDepthBufferEnabled(){return this._logarithmicDepthBufferEnabled}set pbrEnabled(e){this._pbrEnabled=!!e,this.glRedraw()}get pbrEnabled(){return this._pbrEnabled}set dtxEnabled(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}get dtxEnabled(){return this._dtxEnabled}set colorTextureEnabled(e){this._colorTextureEnabled=!!e,this.glRedraw()}get colorTextureEnabled(){return this._colorTextureEnabled}doOcclusionTest(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}render(e){e&&R.runTasks();const t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),!e&&!this._renderer.needsRender())return;t.sceneId=this.id;const s=this._passes,n=this._clearEachPass;let i,a;for(i=0;ii&&(i=e[3]),e[4]>a&&(a=e[4]),e[5]>r&&(r=e[5]),c=!0}c||(t=-100,s=-100,n=-100,i=100,a=100,r=100),this._aabb[0]=t,this._aabb[1]=s,this._aabb[2]=n,this._aabb[3]=i,this._aabb[4]=a,this._aabb[5]=r,this._aabbDirty=!1}return this._aabb}_setAABBDirty(){this._aabbDirty=!0,this.fire("boundary")}pick(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");const s=e.includeEntities||e.include;s&&(e.includeEntityIds=ps(this,s));const n=e.excludeEntities||e.exclude;return n&&(e.excludeEntityIds=ps(this,n)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=this._renderer.pick(e,t))?(t.entity&&t.entity.fire&&t.entity.fire("picked",t),t):void 0}snapPick(e){return this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapMode||"vertex")}clear(){var e;for(const t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}clearLights(){const e=Object.keys(this.lights);for(let t=0,s=e.length;t{if(e.collidable){const o=e.aabb;o[0]a&&(a=o[3]),o[4]>r&&(r=o[4]),o[5]>l&&(l=o[5]),t=!0}})),t){const e=p.AABB3();return e[0]=s,e[1]=n,e[2]=i,e[3]=a,e[4]=r,e[5]=l,e}return this.aabb}setObjectsVisible(e,t){return this.withObjects(e,(e=>{const s=e.visible!==t;return e.visible=t,s}))}setObjectsCollidable(e,t){return this.withObjects(e,(e=>{const s=e.collidable!==t;return e.collidable=t,s}))}setObjectsCulled(e,t){return this.withObjects(e,(e=>{const s=e.culled!==t;return e.culled=t,s}))}setObjectsSelected(e,t){return this.withObjects(e,(e=>{const s=e.selected!==t;return e.selected=t,s}))}setObjectsHighlighted(e,t){return this.withObjects(e,(e=>{const s=e.highlighted!==t;return e.highlighted=t,s}))}setObjectsXRayed(e,t){return this.withObjects(e,(e=>{const s=e.xrayed!==t;return e.xrayed=t,s}))}setObjectsEdges(e,t){return this.withObjects(e,(e=>{const s=e.edges!==t;return e.edges=t,s}))}setObjectsColorized(e,t){return this.withObjects(e,(e=>{e.colorize=t}))}setObjectsOpacity(e,t){return this.withObjects(e,(e=>{const s=e.opacity!==t;return e.opacity=t,s}))}setObjectsPickable(e,t){return this.withObjects(e,(e=>{const s=e.pickable!==t;return e.pickable=t,s}))}setObjectsOffset(e,t){this.withObjects(e,(e=>{e.offset=t}))}withObjects(e,t){m.isString(e)&&(e=[e]);let s=!1;for(let n=0,i=e.length;n0,o=!!i.compressGeometry,c=[];c.push("#version 300 es"),c.push("// Lambertian drawing vertex shader"),c.push("in vec3 position;"),c.push("uniform mat4 modelMatrix;"),c.push("uniform mat4 viewMatrix;"),c.push("uniform mat4 projMatrix;"),c.push("uniform vec4 colorize;"),c.push("uniform vec3 offset;"),o&&c.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(c.push("uniform float logDepthBufFC;"),c.push("out float vFragDepth;"),c.push("bool isPerspectiveMatrix(mat4 m) {"),c.push(" return (m[2][3] == - 1.0);"),c.push("}"),c.push("out float isPerspective;"));l&&c.push("out vec4 vWorldPosition;");if(c.push("uniform vec4 lightAmbient;"),c.push("uniform vec4 materialColor;"),c.push("uniform vec3 materialEmissive;"),i.normalsBuf){c.push("in vec3 normal;"),c.push("uniform mat4 modelNormalMatrix;"),c.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=n.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),c.push(" }"),c.push(" return normalize(v);"),c.push("}"))}c.push("out vec4 vColor;"),"points"===i.primitiveName&&c.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(c.push("void billboard(inout mat4 mat) {"),c.push(" mat[0][0] = 1.0;"),c.push(" mat[0][1] = 0.0;"),c.push(" mat[0][2] = 0.0;"),"spherical"===a&&(c.push(" mat[1][0] = 0.0;"),c.push(" mat[1][1] = 1.0;"),c.push(" mat[1][2] = 0.0;")),c.push(" mat[2][0] = 0.0;"),c.push(" mat[2][1] = 0.0;"),c.push(" mat[2][2] =1.0;"),c.push("}"));c.push("void main(void) {"),c.push("vec4 localPosition = vec4(position, 1.0); "),c.push("vec4 worldPosition;"),o&&c.push("localPosition = positionsDecodeMatrix * localPosition;");i.normalsBuf&&(o?c.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):c.push("vec4 localNormal = vec4(normal, 0.0); "),c.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),c.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));c.push("mat4 viewMatrix2 = viewMatrix;"),c.push("mat4 modelMatrix2 = modelMatrix;"),r&&c.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===a||"cylindrical"===a?(c.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),c.push("billboard(modelMatrix2);"),c.push("billboard(viewMatrix2);"),c.push("billboard(modelViewMatrix);"),i.normalsBuf&&(c.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),c.push("billboard(modelNormalMatrix2);"),c.push("billboard(viewNormalMatrix2);"),c.push("billboard(modelViewNormalMatrix);")),c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i.normalsBuf&&c.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(c.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),c.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),c.push("float lambertian = 1.0;"),i.normalsBuf)for(let e=0,t=n.lights.length;e0,a=t.gammaOutput,r=[];r.push("#version 300 es"),r.push("// Lambertian drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(i){r.push("in vec4 vWorldPosition;"),r.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),r.push("}")}"points"===n.primitiveName&&(r.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),r.push("float r = dot(cxy, cxy);"),r.push("if (r > 1.0) {"),r.push(" discard;"),r.push("}"));t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");a?r.push("outColor = linearToGamma(vColor, gammaFactor);"):r.push("outColor = vColor;");return r.push("}"),r}(e)):(this.vertex=function(e){const t=e.scene;e._material;const s=e._state,n=t._sectionPlanesState,i=e._geometry._state,a=t._lightsState;let r;const l=s.billboard,o=s.background,c=s.stationary,u=function(e){if(!e._geometry._state.uvBuf)return!1;const t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),h=Sn(e),p=n.sectionPlanes.length>0,A=On(e),d=!!i.compressGeometry,f=[];f.push("#version 300 es"),f.push("// Drawing vertex shader"),f.push("in vec3 position;"),d&&f.push("uniform mat4 positionsDecodeMatrix;");f.push("uniform mat4 modelMatrix;"),f.push("uniform mat4 viewMatrix;"),f.push("uniform mat4 projMatrix;"),f.push("out vec3 vViewPosition;"),f.push("uniform vec3 offset;"),p&&f.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(f.push("uniform float logDepthBufFC;"),f.push("out float vFragDepth;"),f.push("bool isPerspectiveMatrix(mat4 m) {"),f.push(" return (m[2][3] == - 1.0);"),f.push("}"),f.push("out float isPerspective;"));a.lightMaps.length>0&&f.push("out vec3 vWorldNormal;");if(h){f.push("in vec3 normal;"),f.push("uniform mat4 modelNormalMatrix;"),f.push("uniform mat4 viewNormalMatrix;"),f.push("out vec3 vViewNormal;");for(let e=0,t=a.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),f.push(" }"),f.push(" return normalize(v);"),f.push("}"))}u&&(f.push("in vec2 uv;"),f.push("out vec2 vUV;"),d&&f.push("uniform mat3 uvDecodeMatrix;"));i.colors&&(f.push("in vec4 color;"),f.push("out vec4 vColor;"));"points"===i.primitiveName&&f.push("uniform float pointSize;");"spherical"!==l&&"cylindrical"!==l||(f.push("void billboard(inout mat4 mat) {"),f.push(" mat[0][0] = 1.0;"),f.push(" mat[0][1] = 0.0;"),f.push(" mat[0][2] = 0.0;"),"spherical"===l&&(f.push(" mat[1][0] = 0.0;"),f.push(" mat[1][1] = 1.0;"),f.push(" mat[1][2] = 0.0;")),f.push(" mat[2][0] = 0.0;"),f.push(" mat[2][1] = 0.0;"),f.push(" mat[2][2] =1.0;"),f.push("}"));if(A){f.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(let e=0,t=a.lights.length;e0&&f.push("vWorldNormal = worldNormal;"),f.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),f.push("vec3 tmpVec3;"),f.push("float lightDist;");for(let e=0,t=a.lights.length;e0,o=Sn(e),c=n.uvBuf,u="PhongMaterial"===r.type,h="MetallicMaterial"===r.type,p="SpecularMaterial"===r.type,A=On(e);t.gammaInput;const d=t.gammaOutput,f=[];f.push("#version 300 es"),f.push("// Drawing fragment shader"),f.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),f.push("precision highp float;"),f.push("precision highp int;"),f.push("#else"),f.push("precision mediump float;"),f.push("precision mediump int;"),f.push("#endif"),t.logarithmicDepthBufferEnabled&&(f.push("in float isPerspective;"),f.push("uniform float logDepthBufFC;"),f.push("in float vFragDepth;"));A&&(f.push("float unpackDepth (vec4 color) {"),f.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),f.push(" return dot(color, bitShift);"),f.push("}"));f.push("uniform float gammaFactor;"),f.push("vec4 linearToLinear( in vec4 value ) {"),f.push(" return value;"),f.push("}"),f.push("vec4 sRGBToLinear( in vec4 value ) {"),f.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),f.push("}"),f.push("vec4 gammaToLinear( in vec4 value) {"),f.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),f.push("}"),d&&(f.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),f.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),f.push("}"));if(l){f.push("in vec4 vWorldPosition;"),f.push("uniform bool clippable;");for(var I=0;I0&&(f.push("uniform samplerCube lightMap;"),f.push("uniform mat4 viewNormalMatrix;")),a.reflectionMaps.length>0&&f.push("uniform samplerCube reflectionMap;"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("uniform mat4 viewMatrix;"),f.push("#define PI 3.14159265359"),f.push("#define RECIPROCAL_PI 0.31830988618"),f.push("#define RECIPROCAL_PI2 0.15915494"),f.push("#define EPSILON 1e-6"),f.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),f.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),f.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),f.push("}"),f.push("struct IncidentLight {"),f.push(" vec3 color;"),f.push(" vec3 direction;"),f.push("};"),f.push("struct ReflectedLight {"),f.push(" vec3 diffuse;"),f.push(" vec3 specular;"),f.push("};"),f.push("struct Geometry {"),f.push(" vec3 position;"),f.push(" vec3 viewNormal;"),f.push(" vec3 worldNormal;"),f.push(" vec3 viewEyeDir;"),f.push("};"),f.push("struct Material {"),f.push(" vec3 diffuseColor;"),f.push(" float specularRoughness;"),f.push(" vec3 specularColor;"),f.push(" float shine;"),f.push("};"),u&&((a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = "+Bn[a.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),f.push(" radiance *= PI;"),f.push(" reflectedLight.specular += radiance;")),f.push("}")),f.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),f.push(" vec3 irradiance = dotNL * directLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),f.push("}")),(h||p)&&(f.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),f.push(" float r = ggxRoughness + 0.0001;"),f.push(" return (2.0 / (r * r) - 2.0);"),f.push("}"),f.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),f.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),f.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),f.push("}"),a.reflectionMaps.length>0&&(f.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),f.push(" vec3 envMapColor = "+Bn[a.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),f.push(" return envMapColor;"),f.push("}")),f.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),f.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),f.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),f.push("}"),f.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" return 1.0 / ( gl * gv );"),f.push("}"),f.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" return 0.5 / max( gv + gl, EPSILON );"),f.push("}"),f.push("float D_GGX(const in float alpha, const in float dotNH) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),f.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float alpha = ( roughness * roughness );"),f.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),f.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),f.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),f.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),f.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),f.push(" vec3 F = F_Schlick( specularColor, dotLH );"),f.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),f.push(" float D = D_GGX( alpha, dotNH );"),f.push(" return F * (G * D);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),f.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),f.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),f.push(" vec4 r = roughness * c0 + c1;"),f.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),f.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),f.push(" return specularColor * AB.x + AB.y;"),f.push("}"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),f.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),f.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),f.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),f.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),f.push("}")),f.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),f.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),f.push("}")));f.push("in vec3 vViewPosition;"),n.colors&&f.push("in vec4 vColor;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._occlusionMap||s._alphaMap)&&f.push("in vec2 vUV;");o&&(a.lightMaps.length>0&&f.push("in vec3 vWorldNormal;"),f.push("in vec3 vViewNormal;"));r.ambient&&f.push("uniform vec3 materialAmbient;");r.baseColor&&f.push("uniform vec3 materialBaseColor;");void 0!==r.alpha&&null!==r.alpha&&f.push("uniform vec4 materialAlphaModeCutoff;");r.emissive&&f.push("uniform vec3 materialEmissive;");r.diffuse&&f.push("uniform vec3 materialDiffuse;");void 0!==r.glossiness&&null!==r.glossiness&&f.push("uniform float materialGlossiness;");void 0!==r.shininess&&null!==r.shininess&&f.push("uniform float materialShininess;");r.specular&&f.push("uniform vec3 materialSpecular;");void 0!==r.metallic&&null!==r.metallic&&f.push("uniform float materialMetallic;");void 0!==r.roughness&&null!==r.roughness&&f.push("uniform float materialRoughness;");void 0!==r.specularF0&&null!==r.specularF0&&f.push("uniform float materialSpecularF0;");c&&s._ambientMap&&(f.push("uniform sampler2D ambientMap;"),s._ambientMap._state.matrix&&f.push("uniform mat4 ambientMapMatrix;"));c&&s._baseColorMap&&(f.push("uniform sampler2D baseColorMap;"),s._baseColorMap._state.matrix&&f.push("uniform mat4 baseColorMapMatrix;"));c&&s._diffuseMap&&(f.push("uniform sampler2D diffuseMap;"),s._diffuseMap._state.matrix&&f.push("uniform mat4 diffuseMapMatrix;"));c&&s._emissiveMap&&(f.push("uniform sampler2D emissiveMap;"),s._emissiveMap._state.matrix&&f.push("uniform mat4 emissiveMapMatrix;"));o&&c&&s._metallicMap&&(f.push("uniform sampler2D metallicMap;"),s._metallicMap._state.matrix&&f.push("uniform mat4 metallicMapMatrix;"));o&&c&&s._roughnessMap&&(f.push("uniform sampler2D roughnessMap;"),s._roughnessMap._state.matrix&&f.push("uniform mat4 roughnessMapMatrix;"));o&&c&&s._metallicRoughnessMap&&(f.push("uniform sampler2D metallicRoughnessMap;"),s._metallicRoughnessMap._state.matrix&&f.push("uniform mat4 metallicRoughnessMapMatrix;"));o&&s._normalMap&&(f.push("uniform sampler2D normalMap;"),s._normalMap._state.matrix&&f.push("uniform mat4 normalMapMatrix;"),f.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),f.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),f.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),f.push(" vec2 st0 = dFdx( uv.st );"),f.push(" vec2 st1 = dFdy( uv.st );"),f.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),f.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),f.push(" vec3 N = normalize( surf_norm );"),f.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),f.push(" mat3 tsn = mat3( S, T, N );"),f.push(" return normalize( tsn * mapN );"),f.push("}"));c&&s._occlusionMap&&(f.push("uniform sampler2D occlusionMap;"),s._occlusionMap._state.matrix&&f.push("uniform mat4 occlusionMapMatrix;"));c&&s._alphaMap&&(f.push("uniform sampler2D alphaMap;"),s._alphaMap._state.matrix&&f.push("uniform mat4 alphaMapMatrix;"));o&&c&&s._specularMap&&(f.push("uniform sampler2D specularMap;"),s._specularMap._state.matrix&&f.push("uniform mat4 specularMapMatrix;"));o&&c&&s._glossinessMap&&(f.push("uniform sampler2D glossinessMap;"),s._glossinessMap._state.matrix&&f.push("uniform mat4 glossinessMapMatrix;"));o&&c&&s._specularGlossinessMap&&(f.push("uniform sampler2D materialSpecularGlossinessMap;"),s._specularGlossinessMap._state.matrix&&f.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));o&&(s._diffuseFresnel||s._specularFresnel||s._alphaFresnel||s._emissiveFresnel||s._reflectivityFresnel)&&(f.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),f.push(" float fr = abs(dot(eyeDir, normal));"),f.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),f.push(" return pow(finalFr, power);"),f.push("}"),s._diffuseFresnel&&(f.push("uniform float diffuseFresnelCenterBias;"),f.push("uniform float diffuseFresnelEdgeBias;"),f.push("uniform float diffuseFresnelPower;"),f.push("uniform vec3 diffuseFresnelCenterColor;"),f.push("uniform vec3 diffuseFresnelEdgeColor;")),s._specularFresnel&&(f.push("uniform float specularFresnelCenterBias;"),f.push("uniform float specularFresnelEdgeBias;"),f.push("uniform float specularFresnelPower;"),f.push("uniform vec3 specularFresnelCenterColor;"),f.push("uniform vec3 specularFresnelEdgeColor;")),s._alphaFresnel&&(f.push("uniform float alphaFresnelCenterBias;"),f.push("uniform float alphaFresnelEdgeBias;"),f.push("uniform float alphaFresnelPower;"),f.push("uniform vec3 alphaFresnelCenterColor;"),f.push("uniform vec3 alphaFresnelEdgeColor;")),s._reflectivityFresnel&&(f.push("uniform float materialSpecularF0FresnelCenterBias;"),f.push("uniform float materialSpecularF0FresnelEdgeBias;"),f.push("uniform float materialSpecularF0FresnelPower;"),f.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),f.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),s._emissiveFresnel&&(f.push("uniform float emissiveFresnelCenterBias;"),f.push("uniform float emissiveFresnelEdgeBias;"),f.push("uniform float emissiveFresnelPower;"),f.push("uniform vec3 emissiveFresnelCenterColor;"),f.push("uniform vec3 emissiveFresnelEdgeColor;")));if(f.push("uniform vec4 lightAmbient;"),o)for(let e=0,t=a.lights.length;e 0.0) { discard; }"),f.push("}")}"points"===n.primitiveName&&(f.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),f.push("float r = dot(cxy, cxy);"),f.push("if (r > 1.0) {"),f.push(" discard;"),f.push("}"));f.push("float occlusion = 1.0;"),r.ambient?f.push("vec3 ambientColor = materialAmbient;"):f.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");r.diffuse?f.push("vec3 diffuseColor = materialDiffuse;"):r.baseColor?f.push("vec3 diffuseColor = materialBaseColor;"):f.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");n.colors&&f.push("diffuseColor *= vColor.rgb;");r.emissive?f.push("vec3 emissiveColor = materialEmissive;"):f.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");r.specular?f.push("vec3 specular = materialSpecular;"):f.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==r.alpha?f.push("float alpha = materialAlphaModeCutoff[0];"):f.push("float alpha = 1.0;");n.colors&&f.push("alpha *= vColor.a;");void 0!==r.glossiness?f.push("float glossiness = materialGlossiness;"):f.push("float glossiness = 1.0;");void 0!==r.metallic?f.push("float metallic = materialMetallic;"):f.push("float metallic = 1.0;");void 0!==r.roughness?f.push("float roughness = materialRoughness;"):f.push("float roughness = 1.0;");void 0!==r.specularF0?f.push("float specularF0 = materialSpecularF0;"):f.push("float specularF0 = 1.0;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._occlusionMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._alphaMap)&&(f.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),f.push("vec2 textureCoord;"));c&&s._ambientMap&&(s._ambientMap._state.matrix?f.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),f.push("ambientTexel = "+Bn[s._ambientMap._state.encoding]+"(ambientTexel);"),f.push("ambientColor *= ambientTexel.rgb;"));c&&s._diffuseMap&&(s._diffuseMap._state.matrix?f.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),f.push("diffuseTexel = "+Bn[s._diffuseMap._state.encoding]+"(diffuseTexel);"),f.push("diffuseColor *= diffuseTexel.rgb;"),f.push("alpha *= diffuseTexel.a;"));c&&s._baseColorMap&&(s._baseColorMap._state.matrix?f.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),f.push("baseColorTexel = "+Bn[s._baseColorMap._state.encoding]+"(baseColorTexel);"),f.push("diffuseColor *= baseColorTexel.rgb;"),f.push("alpha *= baseColorTexel.a;"));c&&s._emissiveMap&&(s._emissiveMap._state.matrix?f.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),f.push("emissiveTexel = "+Bn[s._emissiveMap._state.encoding]+"(emissiveTexel);"),f.push("emissiveColor = emissiveTexel.rgb;"));c&&s._alphaMap&&(s._alphaMap._state.matrix?f.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("alpha *= texture(alphaMap, textureCoord).r;"));c&&s._occlusionMap&&(s._occlusionMap._state.matrix?f.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(o&&(a.lights.length>0||a.lightMaps.length>0||a.reflectionMaps.length>0)){c&&s._normalMap?(s._normalMap._state.matrix?f.push("textureCoord = (normalMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):f.push("vec3 viewNormal = normalize(vViewNormal);"),c&&s._specularMap&&(s._specularMap._state.matrix?f.push("textureCoord = (specularMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("specular *= texture(specularMap, textureCoord).rgb;")),c&&s._glossinessMap&&(s._glossinessMap._state.matrix?f.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("glossiness *= texture(glossinessMap, textureCoord).r;")),c&&s._specularGlossinessMap&&(s._specularGlossinessMap._state.matrix?f.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),f.push("specular *= specGlossRGB.rgb;"),f.push("glossiness *= specGlossRGB.a;")),c&&s._metallicMap&&(s._metallicMap._state.matrix?f.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("metallic *= texture(metallicMap, textureCoord).r;")),c&&s._roughnessMap&&(s._roughnessMap._state.matrix?f.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("roughness *= texture(roughnessMap, textureCoord).r;")),c&&s._metallicRoughnessMap&&(s._metallicRoughnessMap._state.matrix?f.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),f.push("metallic *= metalRoughRGB.b;"),f.push("roughness *= metalRoughRGB.g;")),f.push("vec3 viewEyeDir = normalize(-vViewPosition);"),s._diffuseFresnel&&(f.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),f.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),s._specularFresnel&&(f.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),f.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),s._alphaFresnel&&(f.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),f.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),s._emissiveFresnel&&(f.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),f.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),f.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),f.push(" discard;"),f.push("}"),f.push("IncidentLight light;"),f.push("Material material;"),f.push("Geometry geometry;"),f.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),f.push("vec3 viewLightDir;"),u&&(f.push("material.diffuseColor = diffuseColor;"),f.push("material.specularColor = specular;"),f.push("material.shine = materialShininess;")),p&&(f.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),f.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),f.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),f.push("material.specularColor = specular;")),h&&(f.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),f.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),f.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),f.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),f.push("geometry.position = vViewPosition;"),a.lightMaps.length>0&&f.push("geometry.worldNormal = normalize(vWorldNormal);"),f.push("geometry.viewNormal = viewNormal;"),f.push("geometry.viewEyeDir = viewEyeDir;"),u&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePhongLightMapping(geometry, material, reflectedLight);"),(p||h)&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePBRLightMapping(geometry, material, reflectedLight);"),f.push("float shadow = 1.0;"),f.push("float shadowAcneRemover = 0.007;"),f.push("vec3 fragmentDepth;"),f.push("float texelSize = 1.0 / 1024.0;"),f.push("float amountInLight = 0.0;"),f.push("vec3 shadowCoord;"),f.push("vec4 rgbaDepth;"),f.push("float depth;");for(let e=0,t=a.lights.length;e0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(u=0,h=a.sectionPlanes.length;u0&&i.lightMaps[0].texture&&this._uLightMap&&(l.bindTexture(this._uLightMap,i.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),i.reflectionMaps.length>0&&i.reflectionMaps[0].texture&&this._uReflectionMap&&(l.bindTexture(this._uReflectionMap,i.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),this._uGammaFactor&&n.uniform1f(this._uGammaFactor,s.gammaFactor),this._baseTextureUnit=e.textureUnit};class Fn{constructor(e){this.vertex=function(e){const t=e.scene,s=t._lightsState,n=function(e){const t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),i=t._sectionPlanesState.sectionPlanes.length>0,a=!!e._geometry._state.compressGeometry,r=e._state.billboard,l=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// EmphasisFillShaderSource vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("uniform vec4 colorize;"),o.push("uniform vec3 offset;"),a&&o.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));i&&o.push("out vec4 vWorldPosition;");if(o.push("uniform vec4 lightAmbient;"),o.push("uniform vec4 fillColor;"),n){o.push("in vec3 normal;"),o.push("uniform mat4 modelNormalMatrix;"),o.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),o.push(" }"),o.push(" return normalize(v);"),o.push("}"))}o.push("out vec4 vColor;"),("spherical"===r||"cylindrical"===r)&&(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),o.push("vec4 worldPosition;"),a&&o.push("localPosition = positionsDecodeMatrix * localPosition;");n&&(a?o.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):o.push("vec4 localNormal = vec4(normal, 0.0); "),o.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),o.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),l&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===r||"cylindrical"===r?(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"),o.push("billboard(modelViewMatrix);"),n&&(o.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),o.push("billboard(modelNormalMatrix2);"),o.push("billboard(viewNormalMatrix2);"),o.push("billboard(modelViewNormalMatrix);")),o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));n&&o.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),n)for(let e=0,t=s.lights.length;e0,a=[];a.push("#version 300 es"),a.push("// Lambertian drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}"points"===e._geometry._state.primitiveName&&(a.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),a.push("float r = dot(cxy, cxy);"),a.push("if (r > 1.0) {"),a.push(" discard;"),a.push("}"));t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const Hn=new e({}),Un=p.vec3(),Gn=function(e,t){this.id=Hn.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Fn(t),this._allocate(t)},Vn={};Gn.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=Vn[t];return s||(s=new Gn(t,e),Vn[t]=s,d.memory.programs++),s._useCount++,s},Gn.prototype.put=function(){0==--this._useCount&&(Hn.removeItem(this.id),this._program&&this._program.destroy(),delete Vn[this._hash],d.memory.programs--)},Gn.prototype.webglContextRestored=function(){this._program=null},Gn.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl,r=0===s?t._xrayMaterial._state:1===s?t._highlightMaterial._state:t._selectedMaterial._state,l=t._state,o=t._geometry._state,c=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,c?e.getRTCViewMatrix(l.originHash,c):i.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.viewNormalMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Edges drawing vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec4 edgeColor;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));s&&r.push("out vec4 vWorldPosition;");r.push("out vec4 vColor;"),("spherical"===i||"cylindrical"===i)&&(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r.push("vColor = edgeColor;"),s&&r.push("vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=e.scene._sectionPlanesState,n=e.scene.gammaOutput,i=s.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Edges drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const kn=new e({}),Qn=p.vec3(),Wn=function(e,t){this.id=kn.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new jn(t),this._allocate(t)},zn={};Wn.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=zn[t];return s||(s=new Wn(t,e),zn[t]=s,d.memory.programs++),s._useCount++,s},Wn.prototype.put=function(){0==--this._useCount&&(kn.removeItem(this.id),this._program&&this._program.destroy(),delete zn[this._hash],d.memory.programs--)},Wn.prototype.webglContextRestored=function(){this._program=null},Wn.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl;let r;const l=t._state,o=t._geometry,c=o._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(l.originHash,u):i.viewMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh picking vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("out vec4 vViewPosition;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==i&&"cylindrical"!==i||(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"));r.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(i.push("uniform vec4 pickColor;"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = pickColor; "),i.push("}"),i}(e)}}const Yn=p.vec3(),Xn=function(e,t){this._hash=e,this._shaderSource=new Kn(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},qn={};Xn.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let s=qn[t];if(!s){if(s=new Xn(t,e),s.errors)return console.log(s.errors.join("\n")),null;qn[t]=s,d.memory.programs++}return s._useCount++,s},Xn.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete qn[this._hash],d.memory.programs--)},Xn.prototype.webglContextRestored=function(){this._program=null},Xn.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(i.originHash,l):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t>24&255,u=o>>16&255,h=o>>8&255,p=255&o;n.uniform4f(this._uPickColor,p/255,h/255,u/255,c/255),r.indicesBuf?(n.drawElements(r.primitive,r.indicesBuf.numItems,r.indicesBuf.itemType,0),e.drawElements++):r.positions&&n.drawArrays(n.TRIANGLES,0,r.positions.numItems)},Xn.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new be(s,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0,n=!!e._geometry._state.compressGeometry;e._state.billboard,e._state.stationary;const i=[];i.push("#version 300 es"),i.push("// Surface picking vertex shader"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform vec3 offset;"),s&&(i.push("uniform bool clippable;"),i.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"));i.push("out vec4 vColor;"),n&&i.push("uniform mat4 positionsDecodeMatrix;");i.push("void main(void) {"),i.push("vec4 localPosition = vec4(position, 1.0); "),n&&i.push("localPosition = positionsDecodeMatrix * localPosition;");i.push(" vec4 worldPosition = modelMatrix * localPosition; "),i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),s&&i.push(" vWorldPosition = worldPosition;");i.push(" vColor = color;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return i.push("gl_Position = clipPos;"),i.push("}"),i}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Surface picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = vColor;"),i.push("}"),i}(e)}}const Zn=p.vec3(),$n=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Jn(t),this._allocate(t)},ei={};$n.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=ei[t];if(!s){if(s=new $n(t,e),s.errors)return console.log(s.errors.join("\n")),null;ei[t]=s,d.memory.programs++}return s._useCount++,s},$n.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete ei[this._hash],d.memory.programs--)},$n.prototype.webglContextRestored=function(){this._program=null},$n.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry,l=t._geometry._state,o=t.origin,c=a.backfaces,u=a.frontface,h=s.camera.project,p=r._getPickTrianglePositions(),A=r._getPickTriangleColors();if(this._program.bind(),e.useProgram++,s.logarithmicDepthBufferEnabled){const e=2/(Math.log(h.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,e)}if(n.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCPickViewMatrix(i.originHash,o):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh occlusion vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push("}"),i}(e)}}const si=p.vec3(),ni=function(e,t){this._hash=e,this._shaderSource=new ti(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},ii={};ni.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";");let s=ii[t];if(!s){if(s=new ni(t,e),s.errors)return console.log(s.errors.join("\n")),null;ii[t]=s,d.memory.programs++}return s._useCount++,s},ni.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete ii[this._hash],d.memory.programs--)},ni.prototype.webglContextRestored=function(){this._program=null},ni.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._material._state,a=t._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),i.id!==this._lastMaterialId){const t=i.backfaces;e.backfaces!==t&&(t?n.disable(n.CULL_FACE):n.enable(n.CULL_FACE),e.backfaces=t);const s=i.frontface;e.frontface!==s&&(s?n.frontFace(n.CCW):n.frontFace(n.CW),e.frontface=s),this._lastMaterialId=i.id}const o=s.camera;if(n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCViewMatrix(a.originHash,l):o.viewMatrix),a.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,s=!!e._geometry._state.compressGeometry,n=[];n.push("// Mesh shadow vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),n.push("uniform vec3 offset;"),s&&n.push("uniform mat4 positionsDecodeMatrix;");t&&n.push("out vec4 vWorldPosition;");n.push("void main(void) {"),n.push("vec4 localPosition = vec4(position, 1.0); "),n.push("vec4 worldPosition;"),s&&n.push("localPosition = positionsDecodeMatrix * localPosition;");n.push("worldPosition = modelMatrix * localPosition;"),n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&n.push("vWorldPosition = worldPosition;");return n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n}(e),this.fragment=function(e){const t=e.scene;t.canvas.gl;const s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("// Mesh shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}return i.push("outColor = encodeFloat(gl_FragCoord.z);"),i.push("}"),i}(e)}}const ri=function(e,t){this._hash=e,this._shaderSource=new ai(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},li={};ri.get=function(e){const t=e.scene,s=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let n=li[s];if(!n){if(n=new ri(s,e),n.errors)return console.log(n.errors.join("\n")),null;li[s]=n,d.memory.programs++}return n._useCount++,n},ri.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete li[this._hash],d.memory.programs--)},ri.prototype.webglContextRestored=function(){this._program=null},ri.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene.canvas.gl,n=t._material._state,i=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.id!==this._lastMaterialId){const t=n.backfaces;e.backfaces!==t&&(t?s.disable(s.CULL_FACE):s.enable(s.CULL_FACE),e.backfaces=t);const i=n.frontface;e.frontface!==i&&(i?s.frontFace(s.CCW):s.frontFace(s.CW),e.frontface=i),e.lineWidth!==n.lineWidth&&(s.lineWidth(n.lineWidth),e.lineWidth=n.lineWidth),this._uPointSize&&s.uniform1i(this._uPointSize,n.pointSize),this._lastMaterialId=n.id}if(s.uniformMatrix4fv(this._uModelMatrix,s.FALSE,t.worldMatrix),i.combineGeometry){const n=t.vertexBufs;n.id!==this._lastVertexBufsId&&(n.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(n.positionsBuf,n.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),this._lastVertexBufsId=n.id)}this._uClippable&&s.uniform1i(this._uClippable,t._state.clippable),s.uniform3fv(this._uOffset,t._state.offset),i.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,i.positionsDecodeMatrix),i.combineGeometry?i.indicesBufCombined&&(i.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(i.positionsBuf,i.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),i.indicesBuf&&(i.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=i.id),i.combineGeometry?i.indicesBufCombined&&(s.drawElements(i.primitive,i.indicesBufCombined.numItems,i.indicesBufCombined.itemType,0),e.drawElements++):i.indicesBuf?(s.drawElements(i.primitive,i.indicesBuf.numItems,i.indicesBuf.itemType,0),e.drawElements++):i.positions&&(s.drawArrays(s.TRIANGLES,0,i.positions.numItems),e.drawArrays++)},ri.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new be(s,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uShadowViewMatrix=n.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=n.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0){let e,t,i,a,r;for(let l=0,o=this._uSectionPlanes.length;l0)for(let s=0;s0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}const wi=function(){const e=p.vec3(),t=p.vec3(),s=p.vec3(),n=p.vec3(),i=p.vec3(),a=p.vec3(),r=p.vec4(),l=p.vec3(),o=p.vec3(),c=p.vec3(),u=p.vec3(),h=p.vec3(),A=p.vec3(),d=p.vec3(),f=p.vec3(),I=p.vec3(),y=p.vec4(),m=p.vec4(),v=p.vec4(),w=p.vec3(),g=p.vec3(),T=p.vec3(),E=p.vec3(),b=p.vec3(),D=p.vec3(),P=p.vec3(),R=p.vec3(),C=p.vec3(),_=p.vec3(),B=p.vec3();return function(S,N,x,L){var M=L.primIndex;if(null!=M&&M>-1){const G=S.geometry._state,V=S.scene,j=V.camera,k=V.canvas;if("triangles"===G.primitiveName){L.primitive="triangle";const V=M,Q=G.indices,W=G.positions;let z,K,Y;if(Q){var F=Q[V+0],H=Q[V+1],U=Q[V+2];a[0]=F,a[1]=H,a[2]=U,L.indices=a,z=3*F,K=3*H,Y=3*U}else z=3*V,K=z+3,Y=K+3;if(s[0]=W[z+0],s[1]=W[z+1],s[2]=W[z+2],n[0]=W[K+0],n[1]=W[K+1],n[2]=W[K+2],i[0]=W[Y+0],i[1]=W[Y+1],i[2]=W[Y+2],G.compressGeometry){const e=G.positionsDecodeMatrix;e&&(bt.decompressPosition(s,e,s),bt.decompressPosition(n,e,n),bt.decompressPosition(i,e,i))}L.canvasPos?p.canvasPosToLocalRay(k.canvas,S.origin?O(N,S.origin):N,x,S.worldMatrix,L.canvasPos,e,t):L.origin&&L.direction&&p.worldRayToLocalRay(S.worldMatrix,L.origin,L.direction,e,t),p.normalizeVec3(t),p.rayPlaneIntersect(e,t,s,n,i,r),L.localPos=r,L.position=r,y[0]=r[0],y[1]=r[1],y[2]=r[2],y[3]=1,p.transformVec4(S.worldMatrix,y,m),l[0]=m[0],l[1]=m[1],l[2]=m[2],L.canvasPos&&S.origin&&(l[0]+=S.origin[0],l[1]+=S.origin[1],l[2]+=S.origin[2]),L.worldPos=l,p.transformVec4(j.matrix,m,v),o[0]=v[0],o[1]=v[1],o[2]=v[2],L.viewPos=o,p.cartesianToBarycentric(r,s,n,i,c),L.bary=c;const X=G.normals;if(X){if(G.compressGeometry){const e=3*F,t=3*H,s=3*U;bt.decompressNormal(X.subarray(e,e+2),u),bt.decompressNormal(X.subarray(t,t+2),h),bt.decompressNormal(X.subarray(s,s+2),A)}else u[0]=X[z],u[1]=X[z+1],u[2]=X[z+2],h[0]=X[K],h[1]=X[K+1],h[2]=X[K+2],A[0]=X[Y],A[1]=X[Y+1],A[2]=X[Y+2];const e=p.addVec3(p.addVec3(p.mulVec3Scalar(u,c[0],w),p.mulVec3Scalar(h,c[1],g),T),p.mulVec3Scalar(A,c[2],E),b);L.worldNormal=p.normalizeVec3(p.transformVec3(S.worldNormalMatrix,e,D))}const q=G.uv;if(q){if(d[0]=q[2*F],d[1]=q[2*F+1],f[0]=q[2*H],f[1]=q[2*H+1],I[0]=q[2*U],I[1]=q[2*U+1],G.compressGeometry){const e=G.uvDecodeMatrix;e&&(bt.decompressUV(d,e,d),bt.decompressUV(f,e,f),bt.decompressUV(I,e,I))}L.uv=p.addVec3(p.addVec3(p.mulVec2Scalar(d,c[0],P),p.mulVec2Scalar(f,c[1],R),C),p.mulVec2Scalar(I,c[2],_),B)}}}}}();function gi(e={}){let t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);let s=e.radiusBottom||1;s<0&&(console.error("negative radiusBottom not allowed - will invert"),s*=-1);let n=e.height||1;n<0&&(console.error("negative height not allowed - will invert"),n*=-1);let i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);let a=e.heightSegments||1;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),a<1&&(a=1);const r=!!e.openEnded;let l=e.center;const o=l?l[0]:0,c=l?l[1]:0,u=l?l[2]:0,h=n/2,p=n/a,A=2*Math.PI/i,d=1/i,f=(t-s)/a,I=[],y=[],v=[],w=[];let g,T,E,b,D,P,R,C,_,B,O;const S=(90-180*Math.atan(n/(s-t))/Math.PI)/90;for(g=0;g<=a;g++)for(D=t-g*f,P=h-g*p,T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),y.push(D*E),y.push(S),y.push(D*b),v.push(T*d),v.push(1*g/a),I.push(D*E+o),I.push(P+c),I.push(D*b+u);for(g=0;g0){for(_=I.length/3,y.push(0),y.push(1),y.push(0),v.push(.5),v.push(.5),I.push(0+o),I.push(h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,y.push(t*E),y.push(1),y.push(t*b),v.push(B),v.push(O),I.push(t*E+o),I.push(h+c),I.push(t*b+u);for(T=0;T0){for(_=I.length/3,y.push(0),y.push(-1),y.push(0),v.push(.5),v.push(.5),I.push(0+o),I.push(0-h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,y.push(s*E),y.push(-1),y.push(s*b),v.push(B),v.push(O),I.push(s*E+o),I.push(0-h+c),I.push(s*b+u);for(T=0;T":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function bi(e={}){var t=e.origin||[0,0,0],s=t[0],n=t[1],i=t[2],a=e.size||1,r=[],l=[],o=e.text;m.isNumeric(o)&&(o=""+o);for(var c,u,h,p,A,d,f,I,y,v=(o||"").split("\n"),w=0,g=0,T=.04,E=0;E0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length){const e=this._children.splice();let t;for(let s=0,n=e.length;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=Qi(s,this.wrapS);a&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,a);const r=Qi(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=Qi(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,Yi(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Yi(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Qi(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Qi(s,this.magFilter)));const l=Qi(s,this.format,this.encoding),o=Qi(s,this.type),c=Ki(s,this.internalFormat,l,o,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,n,c,e[0].width,e[0].height);for(let t=0,n=e.length;t>t;return e+1}class Zi extends _{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new We({texture:new zi({gl:this.scene.canvas.gl}),matrix:p.identityMat4(),hasMatrix:t.translate&&(0!==t.translate[0]||0!==t.translate[1])||!!t.rotate||t.scale&&(0!==t.scale[0]||0!==t.scale[1]),minFilter:this._checkMinFilter(t.minFilter),magFilter:this._checkMagFilter(t.magFilter),wrapS:this._checkWrapS(t.wrapS),wrapT:this._checkWrapT(t.wrapT),flipY:this._checkFlipY(t.flipY),encoding:this._checkEncoding(t.encoding)}),this._src=null,this._image=null,this._translate=p.vec2([0,0]),this._scale=p.vec2([1,1]),this._rotate=p.vec2([0,0]),this._matrixDirty=!1,this.translate=t.translate,this.scale=t.scale,this.rotate=t.rotate,t.src?this.src=t.src:t.image&&(this.image=t.image),d.memory.textures++}_checkMinFilter(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}_checkMagFilter(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}_checkWrapS(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkWrapT(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this._state.texture=new zi({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}_update(){const e=this._state;if(this._matrixDirty){let t,s;0===this._translate[0]&&0===this._translate[1]||(t=p.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(s=p.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?p.mulMat4(t,s):s),0!==this._rotate&&(s=p.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?p.mulMat4(t,s):s),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=Xi(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}get image(){return this._image}set src(e){this.scene.loading++,this.scene.canvas.spinner.processes++;const t=this;let s=new Image;s.onload=function(){s=Xi(s),t._state.texture.setImage(s,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},s.src=e,this._src=e,this._image=null}get src(){return this._src}set translate(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}get translate(){return this._translate}set scale(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}get scale(){return this._scale}set rotate(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}get rotate(){return this._rotate}get minFilter(){return this._state.minFilter}get magFilter(){return this._state.magFilter}get wrapS(){return this._state.wrapS}get wrapT(){return this._state.wrapT}get flipY(){return this._state.flipY}get encoding(){return this._state.encoding}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),d.memory.textures--}}class $i extends _{get type(){return"Fresnel"}constructor(e,t={}){super(e,t),this._state=new We({edgeColor:p.vec3([0,0,0]),centerColor:p.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),this.edgeColor=t.edgeColor,this.centerColor=t.centerColor,this.edgeBias=t.edgeBias,this.centerBias=t.centerBias,this.power=t.power}set edgeColor(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set centerColor(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}get centerColor(){return this._state.centerColor}set edgeBias(e){this._state.edgeBias=e||0,this.glRedraw()}get edgeBias(){return this._state.edgeBias}set centerBias(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}get centerBias(){return this._state.centerBias}set power(e){this._state.power=null!=e?e:1,this.glRedraw()}get power(){return this._state.power}destroy(){super.destroy(),this._state.destroy()}}const ea=d.memory,ta=p.AABB3();class sa extends It{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new We({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._aabb=null,this._obb=p.OBB3();const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(t.indices){var i;if(t.positionsDecodeMatrix);else{const e=bt.getPositionsBounds(t.positions),a=bt.compressPositions(t.positions,e.min,e.max);i=a.quantized,s.positionsDecodeMatrix=a.decodeMatrix,s.positionsBuf=new De(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),ea.positions+=s.positionsBuf.numItems,p.positions3ToAABB3(t.positions,this._aabb),p.positions3ToAABB3(i,ta,s.positionsDecodeMatrix),p.AABB3ToOBB3(ta,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);s.colorsBuf=new De(n,n.ARRAY_BUFFER,e,e.length,4,n.STATIC_DRAW),ea.colors+=s.colorsBuf.numItems}if(t.uv){const e=bt.getUVBounds(t.uv),i=bt.compressUVs(t.uv,e.min,e.max),a=i.quantized;s.uvDecodeMatrix=i.decodeMatrix,s.uvBuf=new De(n,n.ARRAY_BUFFER,a,a.length,2,n.STATIC_DRAW),ea.uvs+=s.uvBuf.numItems}if(t.normals){const e=bt.compressNormals(t.normals);let i=s.compressGeometry;s.normalsBuf=new De(n,n.ARRAY_BUFFER,e,e.length,3,n.STATIC_DRAW,i),ea.normals+=s.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);s.indicesBuf=new De(n,n.ELEMENT_ARRAY_BUFFER,e,e.length,1,n.STATIC_DRAW),ea.indices+=s.indicesBuf.numItems;const a=yt(i,e,s.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new De(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),ea.meshes++}else this.error("Config expected: indices");else this.error("Config expected: positions")}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf}get primitive(){return this._state.primitiveName}get aabb(){return this._aabb}get obb(){return this._obb}get numTriangles(){return this._numTriangles}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),ea.meshes--}}var na={};function ia(e,t={}){return new Promise((function(s,n){t.src||(console.error("load3DSGeometry: Parameter expected: src"),n());var i=e.canvas.spinner;i.processes++,m.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),i.processes--,n());var a=na.parse.from3DS(e).edit.objects[0].mesh,r=a.vertices,l=a.uvt,o=a.indices;i.processes--,s(m.apply(t,{primitive:"triangles",positions:r,normals:null,uv:l,indices:o}))}),(function(e){console.error("load3DSGeometry: "+e),i.processes--,n()}))}))}function aa(e,t={}){return new Promise((function(s,n){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),n());var i=e.canvas.spinner;i.processes++,m.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),i.processes--,n());for(var a=na.parse.fromOBJ(e),r=na.edit.unwrap(a.i_verts,a.c_verts,3),l=na.edit.unwrap(a.i_norms,a.c_norms,3),o=na.edit.unwrap(a.i_uvt,a.c_uvt,2),c=new Int32Array(a.i_verts.length),u=0;u0?l:null,autoNormals:0===l.length,uv:o,indices:c}))}),(function(e){console.error("loadOBJGeometry: "+e),i.processes--,n()}))}))}function ra(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);const i=e.center,a=i?i[0]:0,r=i?i[1]:0,l=i?i[2]:0,o=-t+a,c=-s+r,u=-n+l,h=t+a,p=s+r,A=n+l;return m.apply(e,{primitive:"lines",positions:[o,c,u,o,c,A,o,p,u,o,p,A,h,c,u,h,c,A,h,p,u,h,p,A],indices:[0,1,1,3,3,2,2,0,4,5,5,7,7,6,6,4,0,4,1,5,2,6,3,7]})}function la(e={}){let t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);let s=e.divisions||1;s<0&&(console.error("negative divisions not allowed - will invert"),s*=-1),s<1&&(s=1),t=t||10,s=s||10;const n=t/s,i=t/2,a=[],r=[];let l=0;for(let e=0,t=-i;e<=s;e++,t+=n)a.push(-i),a.push(0),a.push(t),a.push(i),a.push(0),a.push(t),a.push(t),a.push(0),a.push(-i),a.push(t),a.push(0),a.push(i),r.push(l++),r.push(l++),r.push(l++),r.push(l++);return m.apply(e,{primitive:"lines",positions:a,indices:r})}function oa(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);let n=e.xSegments||1;n<0&&(console.error("negative xSegments not allowed - will invert"),n*=-1),n<1&&(n=1);let i=e.xSegments||1;i<0&&(console.error("negative zSegments not allowed - will invert"),i*=-1),i<1&&(i=1);const a=e.center,r=a?a[0]:0,l=a?a[1]:0,o=a?a[2]:0,c=t/2,u=s/2,h=Math.floor(n)||1,p=Math.floor(i)||1,A=h+1,d=p+1,f=t/h,I=s/p,y=new Float32Array(A*d*3),v=new Float32Array(A*d*3),w=new Float32Array(A*d*2);let g,T,E,b,D,P,R,C=0,_=0;for(g=0;g65535?Uint32Array:Uint16Array)(h*p*6);for(g=0;g360&&(a=360);const r=e.center;let l=r?r[0]:0,o=r?r[1]:0;const c=r?r[2]:0,u=[],h=[],A=[],d=[];let f,I,y,v,w,g,T,E,b,D,P,R;for(E=0;E<=i;E++)for(T=0;T<=n;T++)f=T/n*a,I=.785398+E/i*Math.PI*2,l=t*Math.cos(f),o=t*Math.sin(f),y=(t+s*Math.cos(I))*Math.cos(f),v=(t+s*Math.cos(I))*Math.sin(f),w=s*Math.sin(I),u.push(y+l),u.push(v+o),u.push(w+c),A.push(1-T/n),A.push(E/i),g=p.normalizeVec3(p.subVec3([y,v,w],[l,o,c],[]),[]),h.push(g[0]),h.push(g[1]),h.push(g[2]);for(E=1;E<=i;E++)for(T=1;T<=n;T++)b=(n+1)*E+T-1,D=(n+1)*(E-1)+T-1,P=(n+1)*(E-1)+T,R=(n+1)*E+T,d.push(b),d.push(D),d.push(P),d.push(P),d.push(R),d.push(b);return m.apply(e,{positions:u,normals:h,uv:A,indices:d})}na.load=function(e,t){var s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="arraybuffer",s.onload=function(e){t(e.target.response)},s.send()},na.save=function(e,t){var s="data:application/octet-stream;base64,"+btoa(na.parse._buffToStr(e));window.location.href=s},na.clone=function(e){return JSON.parse(JSON.stringify(e))},na.bin={},na.bin.f=new Float32Array(1),na.bin.fb=new Uint8Array(na.bin.f.buffer),na.bin.rf=function(e,t){for(var s=na.bin.f,n=na.bin.fb,i=0;i<4;i++)n[i]=e[t+i];return s[0]},na.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},na.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},na.bin.rASCII0=function(e,t){for(var s="";0!=e[t];)s+=String.fromCharCode(e[t++]);return s},na.bin.wf=function(e,t,s){new Float32Array(e.buffer,t,1)[0]=s},na.bin.wsl=function(e,t,s){e[t]=s,e[t+1]=s>>8},na.bin.wil=function(e,t,s){e[t]=s,e[t+1]=s>>8,e[t+2]=s>>16,e[t+3]},na.parse={},na.parse._buffToStr=function(e){for(var t=new Uint8Array(e),s="",n=0;ni&&(i=o),ca&&(a=c),ur&&(r=u)}return{min:{x:t,y:s,z:n},max:{x:i,y:a,z:r}}};class ua extends _{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=p.vec3(t.pos||[0,0,0]),this._up=p.vec3(t.up||[0,1,0]),this._normal=p.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=p.vec3(),this._rtcPos=p.vec3(),this._imageSize=p.vec2(),this._texture=new Zi(this),this._image=new Image,"jpg"!==this._type&&"png"!==this._type&&(this.error('Unsupported type - defaulting to "jpg"'),this._type="jpg"),this._node=new Mi(this,{matrix:p.inverseMat4(p.lookAtMat4v(this._pos,p.subVec3(this._pos,this._normal,p.mat4()),this._up,p.mat4())),children:[this._bitmapMesh=new vi(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new Rt(this,oa({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new St(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0})})]}),t.image?this.image=t.image:t.src?this.src=t.src:t.imageData&&(this.imageData=t.imageData),this.scene._bitmapCreated(this)}set visible(e){this._bitmapMesh.visible=e}get visible(){return this._bitmapMesh.visible}set image(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}get image(){return this._image}set src(e){if(e){this._image.onload=()=>{this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale()},this._image.src=e;switch(e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}}get src(){return this._image.src}set imageData(e){this._image.onload=()=>{this._texture.image=image,this._imageSize[0]=image.width,this._imageSize[1]=image.height,this._updateBitmapMeshScale()},this._image.src=e}get imageData(){const e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")}set type(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}get type(){return this._type}get pos(){return this._pos}get normal(){return this._normal}get up(){return this._up}set height(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}get height(){return this._height}set collidable(e){this._bitmapMesh.collidable=!1!==e}get collidable(){return this._bitmapMesh.collidable}set clippable(e){this._bitmapMesh.clippable=!1!==e}get clippable(){return this._bitmapMesh.clippable}set pickable(e){this._bitmapMesh.pickable=!1!==e}get pickable(){return this._bitmapMesh.pickable}set opacity(e){this._bitmapMesh.opacity=e}get opacity(){return this._bitmapMesh.opacity}destroy(){super.destroy(),this.scene._bitmapDestroyed(this)}_updateBitmapMeshScale(){const e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height*e,1,this._height]}}class ha extends _{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],this._origin=p.vec3(t.origin||[0,0,0]),t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;ed.has(e.id)||I.has(e.id)||f.has(e.id))).reduce(((e,s)=>{let n,i=function(e){let t="";return t+=Math.round(255*e[0]).toString(16).padStart(2,"0"),t+=Math.round(255*e[1]).toString(16).padStart(2,"0"),t+=Math.round(255*e[2]).toString(16).padStart(2,"0"),t}(s.colorize);s.xrayed?(n=0===t.xrayMaterial.fillAlpha&&0!==t.xrayMaterial.edgeAlpha?.1:t.xrayMaterial.fillAlpha,n=Math.round(255*n).toString(16).padStart(2,"0"),i=n+i):d.has(s.id)&&(n=Math.round(255*s.opacity).toString(16).padStart(2,"0"),i=n+i),e[i]||(e[i]=[]);const a=s.id,r=s.originalSystemId,l={ifc_guid:r,originating_system:this.originatingSystem};return r!==a&&(l.authoring_tool_id=a),e[i].push(l),e}),{}),m=Object.entries(y).map((([e,t])=>({color:e,components:t})));a.components.coloring=m;const v=t.objectIds,w=t.visibleObjects,g=t.visibleObjectIds,T=v.filter((e=>!w[e])),E=t.selectedObjectIds;return e.defaultInvisible||g.length{e.start_point&&e.end_point&&(t.push(e.start_point.x),t.push(e.start_point.y),t.push(e.start_point.z),t.push(e.end_point.x),t.push(e.end_point.y),t.push(e.end_point.z),s.push(i++),s.push(i++))})),new ha(n,{positions:t,indices:s,clippable:!1,collidable:!0})}if(n.clearBitmaps(),e.bitmaps&&e.bitmaps.forEach((function(e){const t=e.bitmap_type||"jpg",s=e.bitmap_data;let a=ma(e.location,Aa),r=ma(e.normal,da),l=ma(e.up,fa),o=e.height||1;t&&s&&a&&r&&l&&(i.yUp&&(a=wa(a),r=wa(r),l=wa(l)),new ua(n,{src:s,type:t,pos:a,normal:r,up:l,clippable:!1,collidable:!0,height:o}))})),l&&(n.setObjectsXRayed(n.xrayedObjectIds,!1),n.setObjectsHighlighted(n.highlightedObjectIds,!1),n.setObjectsSelected(n.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(n.setObjectsVisible(n.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!1))))):(n.setObjectsVisible(n.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!0)))));const i=e.components.visibility.view_setup_hints;i&&(!1===i.spaces_visible&&n.setObjectsVisible(s.metaScene.getObjectIDsByType("IfcSpace"),!1),!1===i.openings_visible&&n.setObjectsVisible(s.metaScene.getObjectIDsByType("IfcOpening"),!1),i.space_boundaries_visible)}e.components.selection&&(n.setObjectsSelected(n.selectedObjectIds,!1),e.components.selection.forEach((e=>this._withBCFComponent(t,e,(e=>e.selected=!0))))),e.components.coloring&&e.components.coloring.forEach((e=>{let s=e.color,n=0,i=!1;8===s.length&&(n=parseInt(s.substring(0,2),16)/256,n<=1&&n>=.95&&(n=1),s=s.substring(2),i=!0);const a=[parseInt(s.substring(0,2),16)/256,parseInt(s.substring(2,4),16)/256,parseInt(s.substring(4,6),16)/256];e.components.map((e=>this._withBCFComponent(t,e,(e=>{e.colorize=a,i&&(e.opacity=n)}))))}))}if(e.perspective_camera||e.orthogonal_camera){let l,c,u,h;if(e.perspective_camera?(l=ma(e.perspective_camera.camera_view_point,pa),c=ma(e.perspective_camera.camera_direction,pa),u=ma(e.perspective_camera.camera_up_vector,pa),i.perspective.fov=e.perspective_camera.field_of_view,h="perspective"):(l=ma(e.orthogonal_camera.camera_view_point,pa),c=ma(e.orthogonal_camera.camera_direction,pa),u=ma(e.orthogonal_camera.camera_up_vector,pa),i.ortho.scale=e.orthogonal_camera.view_to_world_scale,h="ortho"),p.subVec3(l,o),i.yUp&&(l=wa(l),c=wa(c),u=wa(u)),a){const e=n.pick({pickSurface:!0,origin:l,direction:c});c=e?e.worldPos:p.addVec3(l,c,pa)}else c=p.addVec3(l,c,pa);r?(i.eye=l,i.look=c,i.up=u,i.projection=h):s.cameraFlight.flyTo({eye:l,look:c,up:u,duration:t.duration,projection:h})}}_withBCFComponent(e,t,s){const n=this.viewer,i=n.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){const a=t.authoring_tool_id,r=i.objects[a];if(r)return void s(r);if(e.updateCompositeObjects){if(n.metaScene.metaObjects[a])return void i.withObjects(n.metaScene.getObjectIDsInSubtree(a),s)}}if(t.ifc_guid){const a=t.ifc_guid,r=i.objects[a];if(r)return void s(r);if(e.updateCompositeObjects){if(n.metaScene.metaObjects[a])return void i.withObjects(n.metaScene.getObjectIDsInSubtree(a),s)}Object.keys(i.models).forEach((t=>{const r=p.globalizeObjectId(t,a),l=i.objects[r];if(l)s(l);else if(e.updateCompositeObjects){n.metaScene.metaObjects[r]&&i.withObjects(n.metaScene.getObjectIDsInSubtree(r),s)}}))}}destroy(){super.destroy()}}function ya(e){return{x:e[0],y:e[1],z:e[2]}}function ma(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function va(e){return new Float64Array([e[0],-e[2],e[1]])}function wa(e){return new Float64Array([e[0],e[2],-e[1]])}var ga=p.vec3();const Ta=(e,t,s,n)=>{var i=e-s,a=t-n;return Math.sqrt(i*i+a*a)};class Ea extends _{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._eventSubs={};var s=this.plugin.viewer.scene;this._originMarker=new q(s,t.origin),this._targetMarker=new q(s,t.target),this._originWorld=p.vec3(),this._targetWorld=p.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;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._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._lengthWire=new J(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._xAxisWire=new J(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._yAxisWire=new J(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._zAxisWire=new J(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._lengthLabel=new $(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._xAxisLabel=new $(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._yAxisLabel=new $(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._zAxisLabel=new $(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,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._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._onMetricsUnits=s.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=s.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=s.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;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._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=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._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0);const t=this._originMarker.viewPos[2],s=this._targetMarker.viewPos[2];if(t>-.3||s>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){p.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var n=this._pp,i=this._cp,a=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var r=a.top-t.top,l=a.left-t.left,o=e.canvas.boundary,c=o[2],u=o[3],h=0;const s=this.plugin.viewer.scene.metrics,f=s.scale,I=s.units,y=s.unitsInfo[I].abbrev;for(var A=0,d=n.length;A1?i.other:i.one,i?(i=Pa(i,[t]),s&&(i=Pa(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const a=this._events[t];return void 0!==a&&s(a),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function Da(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var s=e-t,n=e+t;s<0&&(s=0),n>1&&(n=1);var i=this.getPoint(s),a=this.getPoint(n),r=p.subVec3(a,i,[]);return p.normalizeVec3(r,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,s,n=[],i=this.getPoint(0),a=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),a+=p.lenVec3(p.subVec3(t,i,[])),n.push(a),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,a=n.length;s=t||e*n[a-1];for(var r,l=0,o=a-1;l<=o;)if((r=n[i=Math.floor(l+(o-l)/2)]-s)<0)l=i+1;else{if(!(r>0)){o=i;break}o=i-1}if(n[i=o]===s)return i/(a-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(a-1)}}class Ca extends Ra{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var s=(t.length-1)*e,n=Math.floor(s),i=s-n,a=t[0===n?n:n-1],r=t[n],l=t[n>t.length-2?t.length-1:n+1],o=t[n>t.length-3?t.length-1:n+2],c=p.vec3();return c[0]=p.catmullRomInterpolate(a[0],r[0],l[0],o[0],i),c[1]=p.catmullRomInterpolate(a[1],r[1],l[1],o[1],i),c[2]=p.catmullRomInterpolate(a[2],r[2],l[2],o[2],i),c}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const _a=p.vec3();class Ba extends _{get type(){return"CameraPath"}constructor(e,t={}){super(e,t),this._frames=[],this._eyeCurve=new Ca(this),this._lookCurve=new Ca(this),this._upCurve=new Ca(this),t.frames&&(this.addFrames(t.frames),this.smoothFrameTimes(1))}get frames(){return this._frames}get eyeCurve(){return this._eyeCurve}get lookCurve(){return this._lookCurve}get upCurve(){return this._upCurve}saveFrame(e){const t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}addFrame(e,t,s,n){const i={t:e,eye:t.slice(0),look:s.slice(0),up:n.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}addFrames(e){let t;for(let s=0,n=e.length;s1?1:e,t.eye=this._eyeCurve.getPoint(e,_a),t.look=this._lookCurve.getPoint(e,_a),t.up=this._upCurve.getPoint(e,_a)}sampleFrame(e,t,s,n){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,s),this._upCurve.getPoint(e,n)}smoothFrameTimes(e){if(0===this._frames.length)return;const t=p.vec3();var s=0;this._frames[0].t=0;const n=[];for(let e=1,a=this._frames.length;e=1;e>1&&(e=1);const s=this.easing?Ma._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(p.subVec3(n.eye,n.look,La),n.eye=p.lerpVec3(s,0,1,this._eye1,this._eye2,Na),n.look=p.subVec3(Na,La,Sa)):this._flyingLook&&(n.look=p.lerpVec3(s,0,1,this._look1,this._look2,Sa),n.up=p.lerpVec3(s,0,1,this._up1,this._up2,xa)):this._flyingEyeLookUp&&(n.eye=p.lerpVec3(s,0,1,this._eye1,this._eye2,Na),n.look=p.lerpVec3(s,0,1,this._look1,this._look2,Sa),n.up=p.lerpVec3(s,0,1,this._up1,this._up2,xa)),this._projection2){const t="ortho"===this._projection2?Ma._easeOutExpo(e,0,1,1):Ma._easeInCubic(e,0,1,1);n.customProjection.matrix=p.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();R.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class Fa extends _{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new Ma(this),this._t=0,this.state=Fa.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case Fa.SCRUBBING:return;case Fa.PLAYING:if(this._t+=this._playingRate*i,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=Fa.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case Fa.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=Fa.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=Fa.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=Fa.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=Fa.SCRUBBING,this._cameraFlightAnimation.flyTo(n,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=Fa.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=Fa.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=Fa.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}Fa.STOPPED=0,Fa.SCRUBBING=1,Fa.PLAYING=2,Fa.PLAYING_TO=3;const Ha=p.vec3(),Ua=p.vec3();p.vec3();const Ga=p.vec3([0,-1,0]),Va=p.vec4([0,0,0,1]);class ja extends _{constructor(e,t={}){super(e,t),this._src=null,this._image=null,this._pos=p.vec3(),this._origin=p.vec3(),this._rtcPos=p.vec3(),this._dir=p.vec3(),this._size=1,this._imageSize=p.vec2(),this._texture=new Zi(this),this._plane=new vi(this,{geometry:new Rt(this,oa({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new St(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0}),clippable:t.clippable}),this._grid=new vi(this,{geometry:new Rt(this,la({size:1,divisions:10})),material:new St(this,{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:t.clippable}),this._node=new Mi(this,{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[this._plane,this._grid]}),this._gridVisible=!1,this.visible=!0,this.gridVisible=t.gridVisible,this.position=t.position,this.rotation=t.rotation,this.dir=t.dir,this.size=t.size,this.collidable=t.collidable,this.clippable=t.clippable,this.pickable=t.pickable,this.opacity=t.opacity,t.image?this.image=t.image:this.src=t.src}set visible(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}get visible(){return this._plane.visible}set gridVisible(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}get gridVisible(){return this._gridVisible}set image(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}get image(){return this._image}set src(e){if(this._src=e,this._src){this._image=null;const e=new Image;e.onload=()=>{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set position(e){this._pos.set(e||[0,0,0]),S(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}get position(){return this._pos}set rotation(e){this._node.rotation=e}get rotation(){return this._node.rotation}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set dir(e){if(this._dir.set(e||[0,0,-1]),e){const t=this.scene.center,s=[-this._dir[0],-this._dir[1],-this._dir[2]];p.subVec3(t,this.position,Ha);const n=-p.dotVec3(s,Ha);p.normalizeVec3(s),p.mulVec3Scalar(s,n,Ua),p.vec3PairToQuaternion(Ga,e,Va),this._node.quaternion=Va}}get dir(){return this._dir}set collidable(e){this._node.collidable=!1!==e}get collidable(){return this._node.collidable}set clippable(e){this._node.clippable=!1!==e}get clippable(){return this._node.clippable}set pickable(e){this._node.pickable=!1!==e}get pickable(){return this._node.pickable}set opacity(e){this._node.opacity=e}get opacity(){return this._node.opacity}destroy(){super.destroy()}_updatePlaneSizeFromImage(){const e=this._size,t=this._imageSize[0],s=this._imageSize[1];if(t>s){const n=s/t;this._node.scale=[e,1,e*n]}else{const n=t/s;this._node.scale=[e*n,1,e]}}}class ka extends At{get type(){return"PointLight"}constructor(e,t={}){super(e,t);const s=this;this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const n=this.scene.camera,i=this.scene.canvas;this._onCameraViewMatrix=n.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=n.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=i.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new We({type:"point",pos:p.vec3([1,1,1]),color:p.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(s._shadowViewMatrixDirty){s._shadowViewMatrix||(s._shadowViewMatrix=p.identityMat4());const e=s._state.pos,t=n.look,i=n.up;p.lookAtMat4v(e,t,i,s._shadowViewMatrix),s._shadowViewMatrixDirty=!1}return s._shadowViewMatrix},getShadowProjMatrix:()=>{if(s._shadowProjMatrixDirty){s._shadowProjMatrix||(s._shadowProjMatrix=p.identityMat4());const e=s.scene.canvas.canvas;p.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,s._shadowProjMatrix),s._shadowProjMatrixDirty=!1}return s._shadowProjMatrix},getShadowRenderBuf:()=>(s._shadowRenderBuf||(s._shadowRenderBuf=new Ue(s.scene.canvas.canvas,s.scene.canvas.gl,{size:[1024,1024]})),s._shadowRenderBuf)}),this.pos=t.pos,this.color=t.color,this.intensity=t.intensity,this.constantAttenuation=t.constantAttenuation,this.linearAttenuation=t.linearAttenuation,this.quadraticAttenuation=t.quadraticAttenuation,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set pos(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get pos(){return this._state.pos}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set constantAttenuation(e){this._state.attenuation[0]=e||0,this.glRedraw()}get constantAttenuation(){return this._state.attenuation[0]}set linearAttenuation(e){this._state.attenuation[1]=e||0,this.glRedraw()}get linearAttenuation(){return this._state.attenuation[1]}set quadraticAttenuation(e){this._state.attenuation[2]=e||0,this.glRedraw()}get quadraticAttenuation(){return this._state.attenuation[2]}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}function Qa(e){if(!Wa(e.width)||!Wa(e.height)){const t=document.createElement("canvas");t.width=za(e.width),t.height=za(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Wa(e){return 0==(e&e-1)}function za(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Ka extends _{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new We({texture:new zi({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),d.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let a=0;a{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set collidable(e){this._mesh.collidable=!1!==e}get collidable(){return this._mesh.collidable}set clippable(e){this._mesh.clippable=!1!==e}get clippable(){return this._mesh.clippable}set pickable(e){this._mesh.pickable=!1!==e}get pickable(){return this._mesh.pickable}set opacity(e){this._mesh.opacity=e}get opacity(){return this._mesh.opacity}_updatePlaneSizeFromImage(){const e=.5*this._size,t=this._imageSize[0],s=this._imageSize[1],n=s/t;this._geometry.positions=t>s?[e,e*n,0,-e,e*n,0,-e,-e*n,0,e,-e*n,0]:[e/n,e,0,-e/n,e,0,-e/n,-e,0,e/n,-e,0]}}class Ja{constructor(e){this._eye=p.vec3(),this._look=p.vec3(),this._up=p.vec3(),this._projection={},e&&this.saveCamera(e)}saveCamera(e){const t=e.camera,s=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:s.fov,fovAxis:s.fovAxis,near:s.near,far:s.far};break;case"ortho":this._projection={projection:"ortho",scale:s.scale,near:s.near,far:s.far};break;case"frustum":this._projection={projection:"frustum",left:s.left,right:s.right,top:s.top,bottom:s.bottom,near:s.near,far:s.far};break;case"custom":this._projection={projection:"custom",matrix:s.matrix.slice()}}}restoreCamera(e,t){const s=e.camera,n=this._projection;function i(){switch(n.type){case"perspective":s.perspective.fov=n.fov,s.perspective.fovAxis=n.fovAxis,s.perspective.near=n.near,s.perspective.far=n.far;break;case"ortho":s.ortho.scale=n.scale,s.ortho.near=n.near,s.ortho.far=n.far;break;case"frustum":s.frustum.left=n.left,s.frustum.right=n.right,s.frustum.top=n.top,s.frustum.bottom=n.bottom,s.frustum.near=n.near,s.frustum.far=n.far;break;case"custom":s.customProjection.matrix=n.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:n.scale,projection:n.projection},(()=>{i(),t()})):(s.eye=this._eye,s.look=this._look,s.up=this._up,i(),s.projection=n.projection)}}const Za=p.vec3();class $a{constructor(e){if(this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,e){const t=e.metaScene.scene;this.saveObjects(t,e)}}saveObjects(e,t,s){const n=t.rootMetaObject;if(!n)return;const i=n.getObjectIDsInSubtree();this.numObjects=0,this._mask=s?m.apply(s,{}):null;const a=e.objects,r=!s||s.visible,l=!s||s.edges,o=!s||s.xrayed,c=!s||s.highlighted,u=!s||s.selected,h=!s||s.clippable,p=!s||s.pickable,A=!s||s.colorize,d=!s||s.opacity;for(var f=0,I=i.length;f1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=p.vec3();return t[0]=p.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=p.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=p.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}class nr extends Ra{constructor(e,t={}){super(e,t),this._cachedLengths=[],this._dirty=!0,this._curves=[],this._t=0,this._dirtySubs=[],this._destroyedSubs=[],this.curves=t.curves||[],this.t=t.t}addCurve(e){this._curves.push(e),this._dirty=!0}set curves(e){var t,s,n;for(e=e||[],s=0,n=this._curves.length;s1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}get length(){var e=this._getCurveLengths();return e[e.length-1]}getPoint(e){for(var t,s=e*this.length,n=this._getCurveLengths(),i=0;i=s){var a=1-(n[i]-s)/(t=this._curves[i]).length;return t.getPointAt(a)}i++}return null}_getCurveLengths(){if(!this._dirty)return this._cachedLengths;var e,t=[],s=0,n=this._curves.length;for(e=0;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=p.vec3();return t[0]=p.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=p.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=p.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}class ar{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 rr=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 lr=0;const or={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},cr=new Float32Array([1,1,1,1]),ur=new Float32Array([0,0,0,1]),hr=p.vec4(),pr=p.vec3();class Ar{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;hr[0]=s,hr[1]=n,hr[2]=t.blendCutoff,hr[3]=t.blendFactor,l.uniform4fv(this._uSAOParams,hr),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===or[(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===or[(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===or[(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?ur:cr)}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 dr extends Ar{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 fr extends dr{constructor(e,t){super(e,t,{instancing:!1,edges:!0})}}class Ir extends Ar{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 yr extends Ir{constructor(e,t){super(e,t,{instancing:!0,edges:!0})}}class mr extends Ar{_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 vr extends Ar{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 wr extends Ar{_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 gr extends Ar{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 Tr extends dr{_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 Er extends dr{_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 Dr extends fr{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 Pr extends fr{_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 Rr extends dr{_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 Cr extends dr{_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 _r extends dr{_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 Br extends dr{_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 Or extends dr{_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 Sr extends dr{_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 Nr extends dr{_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 xr extends dr{_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 Mr extends dr{_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 Gr=p.mat4(),Vr=p.mat4();function jr(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 Wr(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 zr=p.vec3();class Kr{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.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[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.snapPickCoordinateScale[0]=p.safeInv(h[0]),e.snapPickCoordinateScale[1]=p.safeInv(h[1]),e.snapPickCoordinateScale[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.snapPickLayerNumber),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 Yr=p.vec3();class Xr{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.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[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.snapPickCoordinateScale[0]=p.safeInv(u[0]),e.snapPickCoordinateScale[1]=p.safeInv(u[1]),e.snapPickCoordinateScale[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.snapPickLayerNumber),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("gl_PointSize = 1.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("// 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 qr{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 Kr(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Xr(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const Jr={};const Zr=p.mat4(),$r=p.mat4(),el=p.vec4([0,0,0,1]),tl=p.vec4([0,0,0,1]),sl=p.vec4([0,0,0,1]),nl=p.OBB3(),il=p.vec3(),al=p.vec3(),rl=p.vec3(),ll=p.vec3(),ol=p.vec3(),cl=p.vec3(),ul=p.vec3();class hl{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=Hr[t];return s||(s=new Fr(e),Hr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Hr[t],s._destroy()}))),s}(e.model.scene),this._snapBatchingRenderers=function(e){const t=e.id;let s=Jr[t];return s||(s=new qr(e),Jr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Jr[t],s._destroy()}))),s}(e.model.scene),this._buffer=new Ur(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new We({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=Zr;I?p.inverseMat4(p.transposeMat4(I,$r),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=Qr(d,"floor","ceil"),l=Wr(r),c=a(d,l),c>u&&(o=r,u=c),r=Qr(d,"ceil","ceil"),l=Wr(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):jr(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=bt.getUVBounds(s.uv),i=bt.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 pl extends Ir{_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 Al extends Ir{_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 fl extends yr{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 Il extends yr{_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 yl extends Ir{_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 ml extends Ir{_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 vl extends Ir{_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 wl extends Ir{_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 gl extends Ir{_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 Tl extends Ir{_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 El extends Ir{_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 bl={3e3:"linearToLinear",3001:"sRGBToLinear"};class Dl extends Ir{_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 = "+bl[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 = "+bl[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 Rl extends Ir{_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*I,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),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 Sl=p.vec3();class Nl{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.canvas.gl,r=t._state,l=t._state.origin;e.snapPickOrigin[0]=l[0],e.snapPickOrigin[1]=l[1],e.snapPickOrigin[2]=l[2];const o=t.aabb,c=[p.safeInv(o[3]-o[0])*p.MAX_INT,p.safeInv(o[4]-o[1])*p.MAX_INT,p.safeInv(o[5]-o[2])*p.MAX_INT];if(e.snapPickCoordinateScale[0]=p.safeInv(c[0]),e.snapPickCoordinateScale[1]=p.safeInv(c[1]),e.snapPickCoordinateScale[2]=p.safeInv(c[2]),!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const u=i.camera;let h=u.eye;e.pickViewMatrix&&(h=e.pickOrigin||h);const A=[h[0]-l[0],h[1]-l[1],h[2]-l[2]];a.uniform3fv(this._uCameraEyeRtc,A),a.uniform2fv(this.uVectorA,e.snapVectorA),a.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),a.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),a.uniform3fv(this._uCoordinateScaler,c),a.uniform1i(this._uRenderPass,s),a.uniform1i(this._uPickInvisible,e.pickInvisible);const d=e.pickViewMatrix||u.viewMatrix,f=l?O(d,l):d;if(a.uniformMatrix4fv(this._uViewMatrix,!1,f),a.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),a.uniformMatrix4fv(this._uProjMatrix,!1,u.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);a.uniform1f(this._uLogDepthBufFC,t)}const I=i._sectionPlanesState.sectionPlanes.length;if(I>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*I,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),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("gl_PointSize = 1.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("// SnapInstancingDepthRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),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}}class xl{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 Ol(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Nl(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const Ll={};const Ml=new Uint8Array(4),Fl=new Float32Array(1),Hl=p.vec4([0,0,0,1]),Ul=p.vec4([0,0,0,1]),Gl=p.vec4([0,0,0,1]),Vl=new Float32Array(3),jl=p.vec3(),kl=p.vec3(),Ql=p.vec3(),Wl=p.vec3(),zl=p.vec3(),Kl=p.vec3(),Yl=p.vec3();class Xl{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=_l[t];return s||(s=new Cl(e),_l[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete _l[t],s._destroy()}))),s}(e.model.scene),this._snapInstancingRenderers=function(e){const t=e.id;let s=Ll[t];return s||(s=new xl(e),Ll[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Ll[t],s._destroy()}))),s}(e.model.scene),this._aabb=p.collapseAABB3(),this._state=new We({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";Ml[0]=t[0],Ml[1]=t[1],Ml[2]=t[2],Ml[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(Ml,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?or.NOT_RENDERED:s?or.COLOR_TRANSPARENT:or.COLOR_OPAQUE,h=!n||c?or.NOT_RENDERED:r?or.SILHOUETTE_SELECTED:a?or.SILHOUETTE_HIGHLIGHTED:i?or.SILHOUETTE_XRAYED:or.NOT_RENDERED;let p=0;p=!n||c?or.NOT_RENDERED:r?or.EDGES_SELECTED:a?or.EDGES_HIGHLIGHTED:i?or.EDGES_XRAYED:l?s?or.EDGES_COLOR_TRANSPARENT:or.EDGES_COLOR_OPAQUE:or.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?or.PICK:or.NOT_RENDERED)<<12,A|=(t&U?1:0)<<16,Fl[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(Fl,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Vl[0]=t[0],Vl[1]=t[1],Vl[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Vl,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=Hl,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 ql extends wr{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 Jl extends wr{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 Zl{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 ql(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Jl(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const $l={};class eo{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]}}const to=p.vec4([0,0,0,1]),so=p.vec4([0,0,0,1]),no=p.vec4([0,0,0,1]),io=p.OBB3();class ao{constructor(e){this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=$l[t];return s||(s=new Zl(e),$l[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete $l[t],s._destroy()}))),s}(e.model.scene),this.model=e.model,this._buffer=new eo(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new We({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=jr(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 lo extends gr{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 oo{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 ro(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new lo(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const co={};const uo=new Uint8Array(4),ho=new Float32Array(1),po=p.vec4([0,0,0,1]),Ao=p.vec4([0,0,0,1]),fo=p.vec4([0,0,0,1]),Io=new Float32Array(3);class yo{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=co[t];return s||(s=new oo(e),co[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete co[t],s._destroy()}))),s}(e.model.scene),this._aabb=p.collapseAABB3(),this._state=new We({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";uo[0]=t[0],uo[1]=t[1],uo[2]=t[2],uo[3]=t[3],this._state.colorsBuf.setData(uo,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?or.NOT_RENDERED:s?or.COLOR_TRANSPARENT:or.COLOR_OPAQUE,h=!n||c?or.NOT_RENDERED:r?or.SILHOUETTE_SELECTED:a?or.SILHOUETTE_HIGHLIGHTED:i?or.SILHOUETTE_XRAYED:or.NOT_RENDERED;let p=0;p=!n||c?or.NOT_RENDERED:r?or.EDGES_SELECTED:a?or.EDGES_HIGHLIGHTED:i?or.EDGES_XRAYED:l?s?or.EDGES_COLOR_TRANSPARENT:or.EDGES_COLOR_OPAQUE:or.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?or.PICK:or.NOT_RENDERED)<<12,A|=(t&U?255:0)<<16,ho[0]=A,this._state.flagsBuf.setData(ho,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Io[0]=t[0],Io[1]=t[1],Io[2]=t[2],this._state.offsetsBuf.setData(Io,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,or.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,or.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,or.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,or.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,or.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 mo extends mr{_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 vo extends mr{_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 wo extends mr{_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 go extends mr{_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 To extends mr{_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 Eo{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 mo(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new vo(this._scene)),this._silhouetteRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new wo(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new go(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new To(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 bo={};class Do{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 Po=p.vec4(),Ro=p.vec4(),Co=p.vec4([0,0,0,1]),_o=p.vec4([0,0,0,1]),Bo=p.vec4([0,0,0,1]),Oo=p.OBB3();class So{constructor(e){this.model=e.model,this.sortId="PointsBatchingLayer",this.layerIndex=e.layerIndex,this._pointsBatchingRenderers=function(e){const t=e.id;let s=bo[t];return s||(s=new Eo(e),bo[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete bo[t],s._destroy()}))),s}(e.model.scene),this._buffer=new Do(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new We({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=jr(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 xo extends vr{_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 Lo extends vr{_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 Mo extends vr{_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 Fo extends vr{_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 Ho extends vr{_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 Uo extends vr{_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 Go{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 No(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new xo(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new Ho(this._scene)),this._depthRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Lo(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Mo(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new Fo(this._scene)),this._occlusionRenderer}get shadowRenderer(){return this._shadowRenderer||(this._shadowRenderer=new Uo(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 Vo={};const jo=new Uint8Array(4),ko=new Float32Array(1),Qo=p.vec4([0,0,0,1]),Wo=p.vec4([0,0,0,1]),zo=p.vec4([0,0,0,1]),Ko=new Float32Array(3);class Yo{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=Vo[t];return s||(s=new Go(e),Vo[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Vo[t],s._destroy()}))),s}(e.model.scene),this._aabb=p.collapseAABB3(),this._state=new We({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";jo[0]=t[0],jo[1]=t[1],jo[2]=t[2],this._state.colorsBuf.setData(jo,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?or.NOT_RENDERED:s?or.COLOR_TRANSPARENT:or.COLOR_OPAQUE,h=!n||c?or.NOT_RENDERED:r?or.SILHOUETTE_SELECTED:a?or.SILHOUETTE_HIGHLIGHTED:i?or.SILHOUETTE_XRAYED:or.NOT_RENDERED;let p=0;p=!n||c?or.NOT_RENDERED:r?or.EDGES_SELECTED:a?or.EDGES_HIGHLIGHTED:i?or.EDGES_XRAYED:l?s?or.EDGES_COLOR_TRANSPARENT:or.EDGES_COLOR_OPAQUE:or.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?or.PICK:or.NOT_RENDERED)<<12,A|=(t&U?255:0)<<16,ko[0]=A,this._state.flagsBuf.setData(ko,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Ko[0]=t[0],Ko[1]=t[1],Ko[2]=t[2],this._state.offsetsBuf.setData(Ko,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,or.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,or.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,or.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,or.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,or.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,or.COLOR_OPAQUE)}drawShadow(e,t){}drawPickMesh(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,or.PICK)}drawPickDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,or.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 Xo{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 qo{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const Jo={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}};class Zo{constructor(e,t,s){this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=s}itemStart(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}itemEnd(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}itemError(e){void 0!==this.onError&&this.onError(e)}resolveURL(e){return this.urlModifier?this.urlModifier(e):e}setURLModifier(e){return this.urlModifier=e,this}addHandler(e,t){return this.handlers.push(e,t),this}removeHandler(e){const t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}getHandler(e){for(let t=0,s=this.handlers.length;t{t&&t(i),this.manager.itemEnd(e)}),0),i;if(void 0!==tc[e])return void tc[e].push({onLoad:t,onProgress:s,onError:n});tc[e]=[],tc[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=tc[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=>{Jo.add(e,t);const s=tc[e];delete tc[e];for(let e=0,n=s.length;e{const s=tc[e];if(void 0===s)throw this.manager.itemError(e),t;delete tc[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 nc{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 ic=0;class ac{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 nc,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 sc;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new sc;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=ac.BasisWorker.toString(),n=["/* constants */","let _EngineFormat = "+JSON.stringify(ac.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(ac.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(ac.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}))})),ic>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),ic++}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(),ic--}}ac.BasisFormat={ETC1S:0,UASTC_4x4:1},ac.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},ac.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},ac.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 rc[t],s.destroy()}))),s} +function is(e,t){t.length;const s=e.length,n=[],i=[],a=e=>{for(let s=0,n=e.meshIds.length;s{const s=t[e];let n,i;if(s.positionsCompressed){const e=bt.getPositionsBounds(s.positionsCompressed);n=bt.decompressPosition(e.min,s.positionsDecodeMatrix,[]),i=bt.decompressPosition(e.max,s.positionsDecodeMatrix,[])}else{const e=bt.getPositionsBounds(s.positions);n=e.min,i=e.max}n[0]+=s.origin[0],n[1]+=s.origin[1],n[2]+=s.origin[2],i[0]+=s.origin[0],i[1]+=s.origin[1],i[2]+=s.origin[2],p.expandAABB3Point3(l,n),p.expandAABB3Point3(l,i),o+=s.numPrimitives})),n[r]={aabb:l,numPrimitives:o,entityId:s.id}}let r,l=[],o={};if(Object.keys(n).length>0){r=function(e){const t=[];for(let s=0,n=e.length;s{s=Math.max(s,e.entity.id)}));const n=new Array(s+1);t.forEach((t=>{n[t.entity.id]=e.objects[t.entity.xeokitId]})),this._internalNodesList=n,this._lastVisibleFrameOfNodes=new Array(n.length),this._lastVisibleFrameOfNodes.fill(0)}_searchVisibleNodesWithFrustumCulling(){return this._aabbTree.searchCustom(((e,t)=>this._aabbIntersectsCameraFrustum(e,t)),(e=>this._aabbContainedInCameraFrustum(e)))}_markVisibleFrameOfVisibleNodes(e,t){const s=this._lastVisibleFrameOfNodes;for(let n=0,i=e.length;nthis._frustumProps.CAM_FACTOR_1?(s|=r<0?64:128,s&=-17):s&=-33;const l=os(p.dotVec3(i,this._frustumProps.up),a);Math.abs(l)>this._frustumProps.CAM_FACTOR_2?(s|=l<0?1024:2048,s&=-257):s&=-513}return 4&s&&8&s&&(s|=4096),64&s&&128&s&&(s|=8192),1024&s&&2048&s&&(s|=16384),e._check=s,s}}class us{constructor(e,t){this.sceneModel=t,this.entities=[],this.meshes=[],this.finalized=!1}addEntity(e){if(this.finalized)throw"Already finalized";this.entities.push(e)}addMesh(e){if(this.finalized)throw"Already finalized";this.meshes.push(e)}finalize(e){if(this.finalized)throw"Already finalized";this.finalized=!0,this.VFCState=new cs,this.VFCState.initializeVFCState(this.entities,this.meshes),this.VFCState.finalize(this.sceneModel,e),this._onSceneRendering=this.sceneModel.scene.on("rendering",(()=>this.applyViewFrustumCulling.call(this)))}applyViewFrustumCulling(){this.finalized&&this.VFCState.applyViewFrustumCulling(this.sceneModel)}destroy(){this.finalized&&this.sceneModel.off(this._onSceneRendering)}}class hs extends _{constructor(e,t={}){super(e,t),this._scene=e,this._vfcManagers={},this._vfcManagerList=[],this.enabled=t.enabled,this._init()}_init(){this._scene.on("rendering",(()=>{for(let e=0,t=this._vfcManagerList.length;e{this.glRedraw()})),this.canvas.on("webglContextFailed",(()=>{alert("xeokit failed to find WebGL!")})),this._renderer=new je(this,{transparent:n,alphaDepthMask:i}),this._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1;let e=null;this.getHash=function(){if(e)return e;const t=this.sectionPlanes;if(0===t.length)return this.hash=";";const s=[];for(let e=0,n=t.length;e0&&e.push("/lm"),this.reflectionMaps.length>0&&e.push("/rm"),e.push(";"),s=e.join(""),s},this.addLight=function(e){this.lights.push(e),n=null,s=null},this.removeLight=function(e){for(let t=0,i=this.lights.length;t{this._renderer.imageDirty()})),this.lod=new $t(this,{enabled:t.lodEnabled}),this.vfc=new hs(this,{enabled:t.vfcEnabled})}_initDefaults(){}_addComponent(e){if(e.id&&this.components[e.id]&&(this.error("Component "+m.inQuotes(e.id)+" already exists in Scene - ignoring ID, will randomly-generate instead"),e.id=null),!e.id)for(void 0===window.nextID&&(window.nextID=0),e.id="__"+window.nextID++;this.components[e.id];)e.id=p.createUUID();this.components[e.id]=e;const t=e.type;let s=this.types[e.type];s||(s=this.types[t]={}),s[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}_removeComponent(e){var t=e.id,s=e.type;delete this.components[t];const n=this.types[s];n&&(delete n[t],m.isEmptyObject(n)&&delete this.types[s]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}_sectionPlaneCreated(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}_bitmapCreated(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}_lineSetCreated(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}_lightCreated(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}_lightMapCreated(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}_reflectionMapCreated(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}_sectionPlaneDestroyed(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}_bitmapDestroyed(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}_lineSetDestroyed(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}_lightDestroyed(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}_lightMapDestroyed(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}_reflectionMapDestroyed(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}_registerModel(e){this.models[e.id]=e,this._modelIds=null}_deregisterModel(e){const t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}_registerObject(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}_deregisterObject(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}_objectVisibilityUpdated(e,t=!0){e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}_objectXRayedUpdated(e,t=!0){e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}_objectHighlightedUpdated(e,t=!0){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null,t&&this.fire("objectHighlighted",e,!0)}_objectSelectedUpdated(e,t=!0){e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}_objectColorizeUpdated(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}_objectOpacityUpdated(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}_objectOffsetUpdated(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}_webglContextLost(){this.canvas.spinner.processes++;for(const e in this.components)if(this.components.hasOwnProperty(e)){const t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}_webglContextRestored(){const e=this.canvas.gl;for(const t in this.components)if(this.components.hasOwnProperty(t)){const s=this.components[t];s._webglContextRestored&&s._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}get capabilities(){return this._renderer.capabilities}get entityOffsetsEnabled(){return this._entityOffsetsEnabled}get pickSurfacePrecisionEnabled(){return!1}get logarithmicDepthBufferEnabled(){return this._logarithmicDepthBufferEnabled}set pbrEnabled(e){this._pbrEnabled=!!e,this.glRedraw()}get pbrEnabled(){return this._pbrEnabled}set dtxEnabled(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}get dtxEnabled(){return this._dtxEnabled}set colorTextureEnabled(e){this._colorTextureEnabled=!!e,this.glRedraw()}get colorTextureEnabled(){return this._colorTextureEnabled}doOcclusionTest(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}render(e){e&&R.runTasks();const t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),!e&&!this._renderer.needsRender())return;t.sceneId=this.id;const s=this._passes,n=this._clearEachPass;let i,a;for(i=0;ii&&(i=e[3]),e[4]>a&&(a=e[4]),e[5]>r&&(r=e[5]),c=!0}c||(t=-100,s=-100,n=-100,i=100,a=100,r=100),this._aabb[0]=t,this._aabb[1]=s,this._aabb[2]=n,this._aabb[3]=i,this._aabb[4]=a,this._aabb[5]=r,this._aabbDirty=!1}return this._aabb}_setAABBDirty(){this._aabbDirty=!0,this.fire("boundary")}pick(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");const s=e.includeEntities||e.include;s&&(e.includeEntityIds=ps(this,s));const n=e.excludeEntities||e.exclude;return n&&(e.excludeEntityIds=ps(this,n)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=this._renderer.pick(e,t))?(t.entity&&t.entity.fire&&t.entity.fire("picked",t),t):void 0}snapPick(e){return this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapMode||"vertex")}clear(){var e;for(const t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}clearLights(){const e=Object.keys(this.lights);for(let t=0,s=e.length;t{if(e.collidable){const o=e.aabb;o[0]a&&(a=o[3]),o[4]>r&&(r=o[4]),o[5]>l&&(l=o[5]),t=!0}})),t){const e=p.AABB3();return e[0]=s,e[1]=n,e[2]=i,e[3]=a,e[4]=r,e[5]=l,e}return this.aabb}setObjectsVisible(e,t){return this.withObjects(e,(e=>{const s=e.visible!==t;return e.visible=t,s}))}setObjectsCollidable(e,t){return this.withObjects(e,(e=>{const s=e.collidable!==t;return e.collidable=t,s}))}setObjectsCulled(e,t){return this.withObjects(e,(e=>{const s=e.culled!==t;return e.culled=t,s}))}setObjectsSelected(e,t){return this.withObjects(e,(e=>{const s=e.selected!==t;return e.selected=t,s}))}setObjectsHighlighted(e,t){return this.withObjects(e,(e=>{const s=e.highlighted!==t;return e.highlighted=t,s}))}setObjectsXRayed(e,t){return this.withObjects(e,(e=>{const s=e.xrayed!==t;return e.xrayed=t,s}))}setObjectsEdges(e,t){return this.withObjects(e,(e=>{const s=e.edges!==t;return e.edges=t,s}))}setObjectsColorized(e,t){return this.withObjects(e,(e=>{e.colorize=t}))}setObjectsOpacity(e,t){return this.withObjects(e,(e=>{const s=e.opacity!==t;return e.opacity=t,s}))}setObjectsPickable(e,t){return this.withObjects(e,(e=>{const s=e.pickable!==t;return e.pickable=t,s}))}setObjectsOffset(e,t){this.withObjects(e,(e=>{e.offset=t}))}withObjects(e,t){m.isString(e)&&(e=[e]);let s=!1;for(let n=0,i=e.length;n0,o=!!i.compressGeometry,c=[];c.push("#version 300 es"),c.push("// Lambertian drawing vertex shader"),c.push("in vec3 position;"),c.push("uniform mat4 modelMatrix;"),c.push("uniform mat4 viewMatrix;"),c.push("uniform mat4 projMatrix;"),c.push("uniform vec4 colorize;"),c.push("uniform vec3 offset;"),o&&c.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(c.push("uniform float logDepthBufFC;"),c.push("out float vFragDepth;"),c.push("bool isPerspectiveMatrix(mat4 m) {"),c.push(" return (m[2][3] == - 1.0);"),c.push("}"),c.push("out float isPerspective;"));l&&c.push("out vec4 vWorldPosition;");if(c.push("uniform vec4 lightAmbient;"),c.push("uniform vec4 materialColor;"),c.push("uniform vec3 materialEmissive;"),i.normalsBuf){c.push("in vec3 normal;"),c.push("uniform mat4 modelNormalMatrix;"),c.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=n.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),c.push(" }"),c.push(" return normalize(v);"),c.push("}"))}c.push("out vec4 vColor;"),"points"===i.primitiveName&&c.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(c.push("void billboard(inout mat4 mat) {"),c.push(" mat[0][0] = 1.0;"),c.push(" mat[0][1] = 0.0;"),c.push(" mat[0][2] = 0.0;"),"spherical"===a&&(c.push(" mat[1][0] = 0.0;"),c.push(" mat[1][1] = 1.0;"),c.push(" mat[1][2] = 0.0;")),c.push(" mat[2][0] = 0.0;"),c.push(" mat[2][1] = 0.0;"),c.push(" mat[2][2] =1.0;"),c.push("}"));c.push("void main(void) {"),c.push("vec4 localPosition = vec4(position, 1.0); "),c.push("vec4 worldPosition;"),o&&c.push("localPosition = positionsDecodeMatrix * localPosition;");i.normalsBuf&&(o?c.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):c.push("vec4 localNormal = vec4(normal, 0.0); "),c.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),c.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));c.push("mat4 viewMatrix2 = viewMatrix;"),c.push("mat4 modelMatrix2 = modelMatrix;"),r&&c.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===a||"cylindrical"===a?(c.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),c.push("billboard(modelMatrix2);"),c.push("billboard(viewMatrix2);"),c.push("billboard(modelViewMatrix);"),i.normalsBuf&&(c.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),c.push("billboard(modelNormalMatrix2);"),c.push("billboard(viewNormalMatrix2);"),c.push("billboard(modelViewNormalMatrix);")),c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i.normalsBuf&&c.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(c.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),c.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),c.push("float lambertian = 1.0;"),i.normalsBuf)for(let e=0,t=n.lights.length;e0,a=t.gammaOutput,r=[];r.push("#version 300 es"),r.push("// Lambertian drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(i){r.push("in vec4 vWorldPosition;"),r.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),r.push("}")}"points"===n.primitiveName&&(r.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),r.push("float r = dot(cxy, cxy);"),r.push("if (r > 1.0) {"),r.push(" discard;"),r.push("}"));t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");a?r.push("outColor = linearToGamma(vColor, gammaFactor);"):r.push("outColor = vColor;");return r.push("}"),r}(e)):(this.vertex=function(e){const t=e.scene;e._material;const s=e._state,n=t._sectionPlanesState,i=e._geometry._state,a=t._lightsState;let r;const l=s.billboard,o=s.background,c=s.stationary,u=function(e){if(!e._geometry._state.uvBuf)return!1;const t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),h=Sn(e),p=n.sectionPlanes.length>0,A=On(e),d=!!i.compressGeometry,f=[];f.push("#version 300 es"),f.push("// Drawing vertex shader"),f.push("in vec3 position;"),d&&f.push("uniform mat4 positionsDecodeMatrix;");f.push("uniform mat4 modelMatrix;"),f.push("uniform mat4 viewMatrix;"),f.push("uniform mat4 projMatrix;"),f.push("out vec3 vViewPosition;"),f.push("uniform vec3 offset;"),p&&f.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(f.push("uniform float logDepthBufFC;"),f.push("out float vFragDepth;"),f.push("bool isPerspectiveMatrix(mat4 m) {"),f.push(" return (m[2][3] == - 1.0);"),f.push("}"),f.push("out float isPerspective;"));a.lightMaps.length>0&&f.push("out vec3 vWorldNormal;");if(h){f.push("in vec3 normal;"),f.push("uniform mat4 modelNormalMatrix;"),f.push("uniform mat4 viewNormalMatrix;"),f.push("out vec3 vViewNormal;");for(let e=0,t=a.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),f.push(" }"),f.push(" return normalize(v);"),f.push("}"))}u&&(f.push("in vec2 uv;"),f.push("out vec2 vUV;"),d&&f.push("uniform mat3 uvDecodeMatrix;"));i.colors&&(f.push("in vec4 color;"),f.push("out vec4 vColor;"));"points"===i.primitiveName&&f.push("uniform float pointSize;");"spherical"!==l&&"cylindrical"!==l||(f.push("void billboard(inout mat4 mat) {"),f.push(" mat[0][0] = 1.0;"),f.push(" mat[0][1] = 0.0;"),f.push(" mat[0][2] = 0.0;"),"spherical"===l&&(f.push(" mat[1][0] = 0.0;"),f.push(" mat[1][1] = 1.0;"),f.push(" mat[1][2] = 0.0;")),f.push(" mat[2][0] = 0.0;"),f.push(" mat[2][1] = 0.0;"),f.push(" mat[2][2] =1.0;"),f.push("}"));if(A){f.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(let e=0,t=a.lights.length;e0&&f.push("vWorldNormal = worldNormal;"),f.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),f.push("vec3 tmpVec3;"),f.push("float lightDist;");for(let e=0,t=a.lights.length;e0,o=Sn(e),c=n.uvBuf,u="PhongMaterial"===r.type,h="MetallicMaterial"===r.type,p="SpecularMaterial"===r.type,A=On(e);t.gammaInput;const d=t.gammaOutput,f=[];f.push("#version 300 es"),f.push("// Drawing fragment shader"),f.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),f.push("precision highp float;"),f.push("precision highp int;"),f.push("#else"),f.push("precision mediump float;"),f.push("precision mediump int;"),f.push("#endif"),t.logarithmicDepthBufferEnabled&&(f.push("in float isPerspective;"),f.push("uniform float logDepthBufFC;"),f.push("in float vFragDepth;"));A&&(f.push("float unpackDepth (vec4 color) {"),f.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),f.push(" return dot(color, bitShift);"),f.push("}"));f.push("uniform float gammaFactor;"),f.push("vec4 linearToLinear( in vec4 value ) {"),f.push(" return value;"),f.push("}"),f.push("vec4 sRGBToLinear( in vec4 value ) {"),f.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),f.push("}"),f.push("vec4 gammaToLinear( in vec4 value) {"),f.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),f.push("}"),d&&(f.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),f.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),f.push("}"));if(l){f.push("in vec4 vWorldPosition;"),f.push("uniform bool clippable;");for(var I=0;I0&&(f.push("uniform samplerCube lightMap;"),f.push("uniform mat4 viewNormalMatrix;")),a.reflectionMaps.length>0&&f.push("uniform samplerCube reflectionMap;"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("uniform mat4 viewMatrix;"),f.push("#define PI 3.14159265359"),f.push("#define RECIPROCAL_PI 0.31830988618"),f.push("#define RECIPROCAL_PI2 0.15915494"),f.push("#define EPSILON 1e-6"),f.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),f.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),f.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),f.push("}"),f.push("struct IncidentLight {"),f.push(" vec3 color;"),f.push(" vec3 direction;"),f.push("};"),f.push("struct ReflectedLight {"),f.push(" vec3 diffuse;"),f.push(" vec3 specular;"),f.push("};"),f.push("struct Geometry {"),f.push(" vec3 position;"),f.push(" vec3 viewNormal;"),f.push(" vec3 worldNormal;"),f.push(" vec3 viewEyeDir;"),f.push("};"),f.push("struct Material {"),f.push(" vec3 diffuseColor;"),f.push(" float specularRoughness;"),f.push(" vec3 specularColor;"),f.push(" float shine;"),f.push("};"),u&&((a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = "+Bn[a.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),f.push(" radiance *= PI;"),f.push(" reflectedLight.specular += radiance;")),f.push("}")),f.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),f.push(" vec3 irradiance = dotNL * directLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),f.push("}")),(h||p)&&(f.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),f.push(" float r = ggxRoughness + 0.0001;"),f.push(" return (2.0 / (r * r) - 2.0);"),f.push("}"),f.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),f.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),f.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),f.push("}"),a.reflectionMaps.length>0&&(f.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),f.push(" vec3 envMapColor = "+Bn[a.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),f.push(" return envMapColor;"),f.push("}")),f.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),f.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),f.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),f.push("}"),f.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" return 1.0 / ( gl * gv );"),f.push("}"),f.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" return 0.5 / max( gv + gl, EPSILON );"),f.push("}"),f.push("float D_GGX(const in float alpha, const in float dotNH) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),f.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float alpha = ( roughness * roughness );"),f.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),f.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),f.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),f.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),f.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),f.push(" vec3 F = F_Schlick( specularColor, dotLH );"),f.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),f.push(" float D = D_GGX( alpha, dotNH );"),f.push(" return F * (G * D);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),f.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),f.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),f.push(" vec4 r = roughness * c0 + c1;"),f.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),f.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),f.push(" return specularColor * AB.x + AB.y;"),f.push("}"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),f.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),f.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),f.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),f.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),f.push("}")),f.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),f.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),f.push("}")));f.push("in vec3 vViewPosition;"),n.colors&&f.push("in vec4 vColor;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._occlusionMap||s._alphaMap)&&f.push("in vec2 vUV;");o&&(a.lightMaps.length>0&&f.push("in vec3 vWorldNormal;"),f.push("in vec3 vViewNormal;"));r.ambient&&f.push("uniform vec3 materialAmbient;");r.baseColor&&f.push("uniform vec3 materialBaseColor;");void 0!==r.alpha&&null!==r.alpha&&f.push("uniform vec4 materialAlphaModeCutoff;");r.emissive&&f.push("uniform vec3 materialEmissive;");r.diffuse&&f.push("uniform vec3 materialDiffuse;");void 0!==r.glossiness&&null!==r.glossiness&&f.push("uniform float materialGlossiness;");void 0!==r.shininess&&null!==r.shininess&&f.push("uniform float materialShininess;");r.specular&&f.push("uniform vec3 materialSpecular;");void 0!==r.metallic&&null!==r.metallic&&f.push("uniform float materialMetallic;");void 0!==r.roughness&&null!==r.roughness&&f.push("uniform float materialRoughness;");void 0!==r.specularF0&&null!==r.specularF0&&f.push("uniform float materialSpecularF0;");c&&s._ambientMap&&(f.push("uniform sampler2D ambientMap;"),s._ambientMap._state.matrix&&f.push("uniform mat4 ambientMapMatrix;"));c&&s._baseColorMap&&(f.push("uniform sampler2D baseColorMap;"),s._baseColorMap._state.matrix&&f.push("uniform mat4 baseColorMapMatrix;"));c&&s._diffuseMap&&(f.push("uniform sampler2D diffuseMap;"),s._diffuseMap._state.matrix&&f.push("uniform mat4 diffuseMapMatrix;"));c&&s._emissiveMap&&(f.push("uniform sampler2D emissiveMap;"),s._emissiveMap._state.matrix&&f.push("uniform mat4 emissiveMapMatrix;"));o&&c&&s._metallicMap&&(f.push("uniform sampler2D metallicMap;"),s._metallicMap._state.matrix&&f.push("uniform mat4 metallicMapMatrix;"));o&&c&&s._roughnessMap&&(f.push("uniform sampler2D roughnessMap;"),s._roughnessMap._state.matrix&&f.push("uniform mat4 roughnessMapMatrix;"));o&&c&&s._metallicRoughnessMap&&(f.push("uniform sampler2D metallicRoughnessMap;"),s._metallicRoughnessMap._state.matrix&&f.push("uniform mat4 metallicRoughnessMapMatrix;"));o&&s._normalMap&&(f.push("uniform sampler2D normalMap;"),s._normalMap._state.matrix&&f.push("uniform mat4 normalMapMatrix;"),f.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),f.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),f.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),f.push(" vec2 st0 = dFdx( uv.st );"),f.push(" vec2 st1 = dFdy( uv.st );"),f.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),f.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),f.push(" vec3 N = normalize( surf_norm );"),f.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),f.push(" mat3 tsn = mat3( S, T, N );"),f.push(" return normalize( tsn * mapN );"),f.push("}"));c&&s._occlusionMap&&(f.push("uniform sampler2D occlusionMap;"),s._occlusionMap._state.matrix&&f.push("uniform mat4 occlusionMapMatrix;"));c&&s._alphaMap&&(f.push("uniform sampler2D alphaMap;"),s._alphaMap._state.matrix&&f.push("uniform mat4 alphaMapMatrix;"));o&&c&&s._specularMap&&(f.push("uniform sampler2D specularMap;"),s._specularMap._state.matrix&&f.push("uniform mat4 specularMapMatrix;"));o&&c&&s._glossinessMap&&(f.push("uniform sampler2D glossinessMap;"),s._glossinessMap._state.matrix&&f.push("uniform mat4 glossinessMapMatrix;"));o&&c&&s._specularGlossinessMap&&(f.push("uniform sampler2D materialSpecularGlossinessMap;"),s._specularGlossinessMap._state.matrix&&f.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));o&&(s._diffuseFresnel||s._specularFresnel||s._alphaFresnel||s._emissiveFresnel||s._reflectivityFresnel)&&(f.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),f.push(" float fr = abs(dot(eyeDir, normal));"),f.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),f.push(" return pow(finalFr, power);"),f.push("}"),s._diffuseFresnel&&(f.push("uniform float diffuseFresnelCenterBias;"),f.push("uniform float diffuseFresnelEdgeBias;"),f.push("uniform float diffuseFresnelPower;"),f.push("uniform vec3 diffuseFresnelCenterColor;"),f.push("uniform vec3 diffuseFresnelEdgeColor;")),s._specularFresnel&&(f.push("uniform float specularFresnelCenterBias;"),f.push("uniform float specularFresnelEdgeBias;"),f.push("uniform float specularFresnelPower;"),f.push("uniform vec3 specularFresnelCenterColor;"),f.push("uniform vec3 specularFresnelEdgeColor;")),s._alphaFresnel&&(f.push("uniform float alphaFresnelCenterBias;"),f.push("uniform float alphaFresnelEdgeBias;"),f.push("uniform float alphaFresnelPower;"),f.push("uniform vec3 alphaFresnelCenterColor;"),f.push("uniform vec3 alphaFresnelEdgeColor;")),s._reflectivityFresnel&&(f.push("uniform float materialSpecularF0FresnelCenterBias;"),f.push("uniform float materialSpecularF0FresnelEdgeBias;"),f.push("uniform float materialSpecularF0FresnelPower;"),f.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),f.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),s._emissiveFresnel&&(f.push("uniform float emissiveFresnelCenterBias;"),f.push("uniform float emissiveFresnelEdgeBias;"),f.push("uniform float emissiveFresnelPower;"),f.push("uniform vec3 emissiveFresnelCenterColor;"),f.push("uniform vec3 emissiveFresnelEdgeColor;")));if(f.push("uniform vec4 lightAmbient;"),o)for(let e=0,t=a.lights.length;e 0.0) { discard; }"),f.push("}")}"points"===n.primitiveName&&(f.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),f.push("float r = dot(cxy, cxy);"),f.push("if (r > 1.0) {"),f.push(" discard;"),f.push("}"));f.push("float occlusion = 1.0;"),r.ambient?f.push("vec3 ambientColor = materialAmbient;"):f.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");r.diffuse?f.push("vec3 diffuseColor = materialDiffuse;"):r.baseColor?f.push("vec3 diffuseColor = materialBaseColor;"):f.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");n.colors&&f.push("diffuseColor *= vColor.rgb;");r.emissive?f.push("vec3 emissiveColor = materialEmissive;"):f.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");r.specular?f.push("vec3 specular = materialSpecular;"):f.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==r.alpha?f.push("float alpha = materialAlphaModeCutoff[0];"):f.push("float alpha = 1.0;");n.colors&&f.push("alpha *= vColor.a;");void 0!==r.glossiness?f.push("float glossiness = materialGlossiness;"):f.push("float glossiness = 1.0;");void 0!==r.metallic?f.push("float metallic = materialMetallic;"):f.push("float metallic = 1.0;");void 0!==r.roughness?f.push("float roughness = materialRoughness;"):f.push("float roughness = 1.0;");void 0!==r.specularF0?f.push("float specularF0 = materialSpecularF0;"):f.push("float specularF0 = 1.0;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._occlusionMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._alphaMap)&&(f.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),f.push("vec2 textureCoord;"));c&&s._ambientMap&&(s._ambientMap._state.matrix?f.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),f.push("ambientTexel = "+Bn[s._ambientMap._state.encoding]+"(ambientTexel);"),f.push("ambientColor *= ambientTexel.rgb;"));c&&s._diffuseMap&&(s._diffuseMap._state.matrix?f.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),f.push("diffuseTexel = "+Bn[s._diffuseMap._state.encoding]+"(diffuseTexel);"),f.push("diffuseColor *= diffuseTexel.rgb;"),f.push("alpha *= diffuseTexel.a;"));c&&s._baseColorMap&&(s._baseColorMap._state.matrix?f.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),f.push("baseColorTexel = "+Bn[s._baseColorMap._state.encoding]+"(baseColorTexel);"),f.push("diffuseColor *= baseColorTexel.rgb;"),f.push("alpha *= baseColorTexel.a;"));c&&s._emissiveMap&&(s._emissiveMap._state.matrix?f.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),f.push("emissiveTexel = "+Bn[s._emissiveMap._state.encoding]+"(emissiveTexel);"),f.push("emissiveColor = emissiveTexel.rgb;"));c&&s._alphaMap&&(s._alphaMap._state.matrix?f.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("alpha *= texture(alphaMap, textureCoord).r;"));c&&s._occlusionMap&&(s._occlusionMap._state.matrix?f.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(o&&(a.lights.length>0||a.lightMaps.length>0||a.reflectionMaps.length>0)){c&&s._normalMap?(s._normalMap._state.matrix?f.push("textureCoord = (normalMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):f.push("vec3 viewNormal = normalize(vViewNormal);"),c&&s._specularMap&&(s._specularMap._state.matrix?f.push("textureCoord = (specularMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("specular *= texture(specularMap, textureCoord).rgb;")),c&&s._glossinessMap&&(s._glossinessMap._state.matrix?f.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("glossiness *= texture(glossinessMap, textureCoord).r;")),c&&s._specularGlossinessMap&&(s._specularGlossinessMap._state.matrix?f.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),f.push("specular *= specGlossRGB.rgb;"),f.push("glossiness *= specGlossRGB.a;")),c&&s._metallicMap&&(s._metallicMap._state.matrix?f.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("metallic *= texture(metallicMap, textureCoord).r;")),c&&s._roughnessMap&&(s._roughnessMap._state.matrix?f.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("roughness *= texture(roughnessMap, textureCoord).r;")),c&&s._metallicRoughnessMap&&(s._metallicRoughnessMap._state.matrix?f.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),f.push("metallic *= metalRoughRGB.b;"),f.push("roughness *= metalRoughRGB.g;")),f.push("vec3 viewEyeDir = normalize(-vViewPosition);"),s._diffuseFresnel&&(f.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),f.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),s._specularFresnel&&(f.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),f.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),s._alphaFresnel&&(f.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),f.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),s._emissiveFresnel&&(f.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),f.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),f.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),f.push(" discard;"),f.push("}"),f.push("IncidentLight light;"),f.push("Material material;"),f.push("Geometry geometry;"),f.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),f.push("vec3 viewLightDir;"),u&&(f.push("material.diffuseColor = diffuseColor;"),f.push("material.specularColor = specular;"),f.push("material.shine = materialShininess;")),p&&(f.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),f.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),f.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),f.push("material.specularColor = specular;")),h&&(f.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),f.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),f.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),f.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),f.push("geometry.position = vViewPosition;"),a.lightMaps.length>0&&f.push("geometry.worldNormal = normalize(vWorldNormal);"),f.push("geometry.viewNormal = viewNormal;"),f.push("geometry.viewEyeDir = viewEyeDir;"),u&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePhongLightMapping(geometry, material, reflectedLight);"),(p||h)&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePBRLightMapping(geometry, material, reflectedLight);"),f.push("float shadow = 1.0;"),f.push("float shadowAcneRemover = 0.007;"),f.push("vec3 fragmentDepth;"),f.push("float texelSize = 1.0 / 1024.0;"),f.push("float amountInLight = 0.0;"),f.push("vec3 shadowCoord;"),f.push("vec4 rgbaDepth;"),f.push("float depth;");for(let e=0,t=a.lights.length;e0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(u=0,h=a.sectionPlanes.length;u0&&i.lightMaps[0].texture&&this._uLightMap&&(l.bindTexture(this._uLightMap,i.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),i.reflectionMaps.length>0&&i.reflectionMaps[0].texture&&this._uReflectionMap&&(l.bindTexture(this._uReflectionMap,i.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),this._uGammaFactor&&n.uniform1f(this._uGammaFactor,s.gammaFactor),this._baseTextureUnit=e.textureUnit};class Fn{constructor(e){this.vertex=function(e){const t=e.scene,s=t._lightsState,n=function(e){const t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),i=t._sectionPlanesState.sectionPlanes.length>0,a=!!e._geometry._state.compressGeometry,r=e._state.billboard,l=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// EmphasisFillShaderSource vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("uniform vec4 colorize;"),o.push("uniform vec3 offset;"),a&&o.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));i&&o.push("out vec4 vWorldPosition;");if(o.push("uniform vec4 lightAmbient;"),o.push("uniform vec4 fillColor;"),n){o.push("in vec3 normal;"),o.push("uniform mat4 modelNormalMatrix;"),o.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),o.push(" }"),o.push(" return normalize(v);"),o.push("}"))}o.push("out vec4 vColor;"),("spherical"===r||"cylindrical"===r)&&(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),o.push("vec4 worldPosition;"),a&&o.push("localPosition = positionsDecodeMatrix * localPosition;");n&&(a?o.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):o.push("vec4 localNormal = vec4(normal, 0.0); "),o.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),o.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),l&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===r||"cylindrical"===r?(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"),o.push("billboard(modelViewMatrix);"),n&&(o.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),o.push("billboard(modelNormalMatrix2);"),o.push("billboard(viewNormalMatrix2);"),o.push("billboard(modelViewNormalMatrix);")),o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));n&&o.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),n)for(let e=0,t=s.lights.length;e0,a=[];a.push("#version 300 es"),a.push("// Lambertian drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}"points"===e._geometry._state.primitiveName&&(a.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),a.push("float r = dot(cxy, cxy);"),a.push("if (r > 1.0) {"),a.push(" discard;"),a.push("}"));t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const Hn=new e({}),Un=p.vec3(),Gn=function(e,t){this.id=Hn.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Fn(t),this._allocate(t)},Vn={};Gn.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=Vn[t];return s||(s=new Gn(t,e),Vn[t]=s,d.memory.programs++),s._useCount++,s},Gn.prototype.put=function(){0==--this._useCount&&(Hn.removeItem(this.id),this._program&&this._program.destroy(),delete Vn[this._hash],d.memory.programs--)},Gn.prototype.webglContextRestored=function(){this._program=null},Gn.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl,r=0===s?t._xrayMaterial._state:1===s?t._highlightMaterial._state:t._selectedMaterial._state,l=t._state,o=t._geometry._state,c=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,c?e.getRTCViewMatrix(l.originHash,c):i.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.viewNormalMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Edges drawing vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec4 edgeColor;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));s&&r.push("out vec4 vWorldPosition;");r.push("out vec4 vColor;"),("spherical"===i||"cylindrical"===i)&&(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r.push("vColor = edgeColor;"),s&&r.push("vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=e.scene._sectionPlanesState,n=e.scene.gammaOutput,i=s.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Edges drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const kn=new e({}),Qn=p.vec3(),Wn=function(e,t){this.id=kn.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new jn(t),this._allocate(t)},zn={};Wn.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=zn[t];return s||(s=new Wn(t,e),zn[t]=s,d.memory.programs++),s._useCount++,s},Wn.prototype.put=function(){0==--this._useCount&&(kn.removeItem(this.id),this._program&&this._program.destroy(),delete zn[this._hash],d.memory.programs--)},Wn.prototype.webglContextRestored=function(){this._program=null},Wn.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl;let r;const l=t._state,o=t._geometry,c=o._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(l.originHash,u):i.viewMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh picking vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("out vec4 vViewPosition;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==i&&"cylindrical"!==i||(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"));r.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(i.push("uniform vec4 pickColor;"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = pickColor; "),i.push("}"),i}(e)}}const Yn=p.vec3(),Xn=function(e,t){this._hash=e,this._shaderSource=new Kn(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},qn={};Xn.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let s=qn[t];if(!s){if(s=new Xn(t,e),s.errors)return console.log(s.errors.join("\n")),null;qn[t]=s,d.memory.programs++}return s._useCount++,s},Xn.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete qn[this._hash],d.memory.programs--)},Xn.prototype.webglContextRestored=function(){this._program=null},Xn.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(i.originHash,l):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t>24&255,u=o>>16&255,h=o>>8&255,p=255&o;n.uniform4f(this._uPickColor,p/255,h/255,u/255,c/255),r.indicesBuf?(n.drawElements(r.primitive,r.indicesBuf.numItems,r.indicesBuf.itemType,0),e.drawElements++):r.positions&&n.drawArrays(n.TRIANGLES,0,r.positions.numItems)},Xn.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new be(s,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0,n=!!e._geometry._state.compressGeometry;e._state.billboard,e._state.stationary;const i=[];i.push("#version 300 es"),i.push("// Surface picking vertex shader"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform vec3 offset;"),s&&(i.push("uniform bool clippable;"),i.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"));i.push("out vec4 vColor;"),n&&i.push("uniform mat4 positionsDecodeMatrix;");i.push("void main(void) {"),i.push("vec4 localPosition = vec4(position, 1.0); "),n&&i.push("localPosition = positionsDecodeMatrix * localPosition;");i.push(" vec4 worldPosition = modelMatrix * localPosition; "),i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),s&&i.push(" vWorldPosition = worldPosition;");i.push(" vColor = color;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return i.push("gl_Position = clipPos;"),i.push("}"),i}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Surface picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = vColor;"),i.push("}"),i}(e)}}const Zn=p.vec3(),$n=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Jn(t),this._allocate(t)},ei={};$n.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=ei[t];if(!s){if(s=new $n(t,e),s.errors)return console.log(s.errors.join("\n")),null;ei[t]=s,d.memory.programs++}return s._useCount++,s},$n.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete ei[this._hash],d.memory.programs--)},$n.prototype.webglContextRestored=function(){this._program=null},$n.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry,l=t._geometry._state,o=t.origin,c=a.backfaces,u=a.frontface,h=s.camera.project,p=r._getPickTrianglePositions(),A=r._getPickTriangleColors();if(this._program.bind(),e.useProgram++,s.logarithmicDepthBufferEnabled){const e=2/(Math.log(h.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,e)}if(n.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCPickViewMatrix(i.originHash,o):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh occlusion vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push("}"),i}(e)}}const si=p.vec3(),ni=function(e,t){this._hash=e,this._shaderSource=new ti(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},ii={};ni.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";");let s=ii[t];if(!s){if(s=new ni(t,e),s.errors)return console.log(s.errors.join("\n")),null;ii[t]=s,d.memory.programs++}return s._useCount++,s},ni.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete ii[this._hash],d.memory.programs--)},ni.prototype.webglContextRestored=function(){this._program=null},ni.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._material._state,a=t._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),i.id!==this._lastMaterialId){const t=i.backfaces;e.backfaces!==t&&(t?n.disable(n.CULL_FACE):n.enable(n.CULL_FACE),e.backfaces=t);const s=i.frontface;e.frontface!==s&&(s?n.frontFace(n.CCW):n.frontFace(n.CW),e.frontface=s),this._lastMaterialId=i.id}const o=s.camera;if(n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCViewMatrix(a.originHash,l):o.viewMatrix),a.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,s=!!e._geometry._state.compressGeometry,n=[];n.push("// Mesh shadow vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),n.push("uniform vec3 offset;"),s&&n.push("uniform mat4 positionsDecodeMatrix;");t&&n.push("out vec4 vWorldPosition;");n.push("void main(void) {"),n.push("vec4 localPosition = vec4(position, 1.0); "),n.push("vec4 worldPosition;"),s&&n.push("localPosition = positionsDecodeMatrix * localPosition;");n.push("worldPosition = modelMatrix * localPosition;"),n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&n.push("vWorldPosition = worldPosition;");return n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n}(e),this.fragment=function(e){const t=e.scene;t.canvas.gl;const s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("// Mesh shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}return i.push("outColor = encodeFloat(gl_FragCoord.z);"),i.push("}"),i}(e)}}const ri=function(e,t){this._hash=e,this._shaderSource=new ai(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},li={};ri.get=function(e){const t=e.scene,s=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let n=li[s];if(!n){if(n=new ri(s,e),n.errors)return console.log(n.errors.join("\n")),null;li[s]=n,d.memory.programs++}return n._useCount++,n},ri.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete li[this._hash],d.memory.programs--)},ri.prototype.webglContextRestored=function(){this._program=null},ri.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene.canvas.gl,n=t._material._state,i=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.id!==this._lastMaterialId){const t=n.backfaces;e.backfaces!==t&&(t?s.disable(s.CULL_FACE):s.enable(s.CULL_FACE),e.backfaces=t);const i=n.frontface;e.frontface!==i&&(i?s.frontFace(s.CCW):s.frontFace(s.CW),e.frontface=i),e.lineWidth!==n.lineWidth&&(s.lineWidth(n.lineWidth),e.lineWidth=n.lineWidth),this._uPointSize&&s.uniform1i(this._uPointSize,n.pointSize),this._lastMaterialId=n.id}if(s.uniformMatrix4fv(this._uModelMatrix,s.FALSE,t.worldMatrix),i.combineGeometry){const n=t.vertexBufs;n.id!==this._lastVertexBufsId&&(n.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(n.positionsBuf,n.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),this._lastVertexBufsId=n.id)}this._uClippable&&s.uniform1i(this._uClippable,t._state.clippable),s.uniform3fv(this._uOffset,t._state.offset),i.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,i.positionsDecodeMatrix),i.combineGeometry?i.indicesBufCombined&&(i.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(i.positionsBuf,i.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),i.indicesBuf&&(i.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=i.id),i.combineGeometry?i.indicesBufCombined&&(s.drawElements(i.primitive,i.indicesBufCombined.numItems,i.indicesBufCombined.itemType,0),e.drawElements++):i.indicesBuf?(s.drawElements(i.primitive,i.indicesBuf.numItems,i.indicesBuf.itemType,0),e.drawElements++):i.positions&&(s.drawArrays(s.TRIANGLES,0,i.positions.numItems),e.drawArrays++)},ri.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new be(s,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uShadowViewMatrix=n.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=n.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0){let e,t,i,a,r;for(let l=0,o=this._uSectionPlanes.length;l0)for(let s=0;s0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}const wi=function(){const e=p.vec3(),t=p.vec3(),s=p.vec3(),n=p.vec3(),i=p.vec3(),a=p.vec3(),r=p.vec4(),l=p.vec3(),o=p.vec3(),c=p.vec3(),u=p.vec3(),h=p.vec3(),A=p.vec3(),d=p.vec3(),f=p.vec3(),I=p.vec3(),y=p.vec4(),m=p.vec4(),v=p.vec4(),w=p.vec3(),g=p.vec3(),T=p.vec3(),E=p.vec3(),b=p.vec3(),D=p.vec3(),P=p.vec3(),R=p.vec3(),C=p.vec3(),_=p.vec3(),B=p.vec3();return function(S,N,x,L){var M=L.primIndex;if(null!=M&&M>-1){const G=S.geometry._state,V=S.scene,j=V.camera,k=V.canvas;if("triangles"===G.primitiveName){L.primitive="triangle";const V=M,Q=G.indices,W=G.positions;let z,K,Y;if(Q){var F=Q[V+0],H=Q[V+1],U=Q[V+2];a[0]=F,a[1]=H,a[2]=U,L.indices=a,z=3*F,K=3*H,Y=3*U}else z=3*V,K=z+3,Y=K+3;if(s[0]=W[z+0],s[1]=W[z+1],s[2]=W[z+2],n[0]=W[K+0],n[1]=W[K+1],n[2]=W[K+2],i[0]=W[Y+0],i[1]=W[Y+1],i[2]=W[Y+2],G.compressGeometry){const e=G.positionsDecodeMatrix;e&&(bt.decompressPosition(s,e,s),bt.decompressPosition(n,e,n),bt.decompressPosition(i,e,i))}L.canvasPos?p.canvasPosToLocalRay(k.canvas,S.origin?O(N,S.origin):N,x,S.worldMatrix,L.canvasPos,e,t):L.origin&&L.direction&&p.worldRayToLocalRay(S.worldMatrix,L.origin,L.direction,e,t),p.normalizeVec3(t),p.rayPlaneIntersect(e,t,s,n,i,r),L.localPos=r,L.position=r,y[0]=r[0],y[1]=r[1],y[2]=r[2],y[3]=1,p.transformVec4(S.worldMatrix,y,m),l[0]=m[0],l[1]=m[1],l[2]=m[2],L.canvasPos&&S.origin&&(l[0]+=S.origin[0],l[1]+=S.origin[1],l[2]+=S.origin[2]),L.worldPos=l,p.transformVec4(j.matrix,m,v),o[0]=v[0],o[1]=v[1],o[2]=v[2],L.viewPos=o,p.cartesianToBarycentric(r,s,n,i,c),L.bary=c;const X=G.normals;if(X){if(G.compressGeometry){const e=3*F,t=3*H,s=3*U;bt.decompressNormal(X.subarray(e,e+2),u),bt.decompressNormal(X.subarray(t,t+2),h),bt.decompressNormal(X.subarray(s,s+2),A)}else u[0]=X[z],u[1]=X[z+1],u[2]=X[z+2],h[0]=X[K],h[1]=X[K+1],h[2]=X[K+2],A[0]=X[Y],A[1]=X[Y+1],A[2]=X[Y+2];const e=p.addVec3(p.addVec3(p.mulVec3Scalar(u,c[0],w),p.mulVec3Scalar(h,c[1],g),T),p.mulVec3Scalar(A,c[2],E),b);L.worldNormal=p.normalizeVec3(p.transformVec3(S.worldNormalMatrix,e,D))}const q=G.uv;if(q){if(d[0]=q[2*F],d[1]=q[2*F+1],f[0]=q[2*H],f[1]=q[2*H+1],I[0]=q[2*U],I[1]=q[2*U+1],G.compressGeometry){const e=G.uvDecodeMatrix;e&&(bt.decompressUV(d,e,d),bt.decompressUV(f,e,f),bt.decompressUV(I,e,I))}L.uv=p.addVec3(p.addVec3(p.mulVec2Scalar(d,c[0],P),p.mulVec2Scalar(f,c[1],R),C),p.mulVec2Scalar(I,c[2],_),B)}}}}}();function gi(e={}){let t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);let s=e.radiusBottom||1;s<0&&(console.error("negative radiusBottom not allowed - will invert"),s*=-1);let n=e.height||1;n<0&&(console.error("negative height not allowed - will invert"),n*=-1);let i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);let a=e.heightSegments||1;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),a<1&&(a=1);const r=!!e.openEnded;let l=e.center;const o=l?l[0]:0,c=l?l[1]:0,u=l?l[2]:0,h=n/2,p=n/a,A=2*Math.PI/i,d=1/i,f=(t-s)/a,I=[],y=[],v=[],w=[];let g,T,E,b,D,P,R,C,_,B,O;const S=(90-180*Math.atan(n/(s-t))/Math.PI)/90;for(g=0;g<=a;g++)for(D=t-g*f,P=h-g*p,T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),y.push(D*E),y.push(S),y.push(D*b),v.push(T*d),v.push(1*g/a),I.push(D*E+o),I.push(P+c),I.push(D*b+u);for(g=0;g0){for(_=I.length/3,y.push(0),y.push(1),y.push(0),v.push(.5),v.push(.5),I.push(0+o),I.push(h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,y.push(t*E),y.push(1),y.push(t*b),v.push(B),v.push(O),I.push(t*E+o),I.push(h+c),I.push(t*b+u);for(T=0;T0){for(_=I.length/3,y.push(0),y.push(-1),y.push(0),v.push(.5),v.push(.5),I.push(0+o),I.push(0-h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,y.push(s*E),y.push(-1),y.push(s*b),v.push(B),v.push(O),I.push(s*E+o),I.push(0-h+c),I.push(s*b+u);for(T=0;T":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function bi(e={}){var t=e.origin||[0,0,0],s=t[0],n=t[1],i=t[2],a=e.size||1,r=[],l=[],o=e.text;m.isNumeric(o)&&(o=""+o);for(var c,u,h,p,A,d,f,I,y,v=(o||"").split("\n"),w=0,g=0,T=.04,E=0;E0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length){const e=this._children.splice();let t;for(let s=0,n=e.length;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=Qi(s,this.wrapS);a&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,a);const r=Qi(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=Qi(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,Yi(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Yi(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Qi(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Qi(s,this.magFilter)));const l=Qi(s,this.format,this.encoding),o=Qi(s,this.type),c=Ki(s,this.internalFormat,l,o,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,n,c,e[0].width,e[0].height);for(let t=0,n=e.length;t>t;return e+1}class Zi extends _{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new We({texture:new zi({gl:this.scene.canvas.gl}),matrix:p.identityMat4(),hasMatrix:t.translate&&(0!==t.translate[0]||0!==t.translate[1])||!!t.rotate||t.scale&&(0!==t.scale[0]||0!==t.scale[1]),minFilter:this._checkMinFilter(t.minFilter),magFilter:this._checkMagFilter(t.magFilter),wrapS:this._checkWrapS(t.wrapS),wrapT:this._checkWrapT(t.wrapT),flipY:this._checkFlipY(t.flipY),encoding:this._checkEncoding(t.encoding)}),this._src=null,this._image=null,this._translate=p.vec2([0,0]),this._scale=p.vec2([1,1]),this._rotate=p.vec2([0,0]),this._matrixDirty=!1,this.translate=t.translate,this.scale=t.scale,this.rotate=t.rotate,t.src?this.src=t.src:t.image&&(this.image=t.image),d.memory.textures++}_checkMinFilter(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}_checkMagFilter(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}_checkWrapS(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkWrapT(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this._state.texture=new zi({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}_update(){const e=this._state;if(this._matrixDirty){let t,s;0===this._translate[0]&&0===this._translate[1]||(t=p.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(s=p.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?p.mulMat4(t,s):s),0!==this._rotate&&(s=p.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?p.mulMat4(t,s):s),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=Xi(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}get image(){return this._image}set src(e){this.scene.loading++,this.scene.canvas.spinner.processes++;const t=this;let s=new Image;s.onload=function(){s=Xi(s),t._state.texture.setImage(s,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},s.src=e,this._src=e,this._image=null}get src(){return this._src}set translate(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}get translate(){return this._translate}set scale(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}get scale(){return this._scale}set rotate(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}get rotate(){return this._rotate}get minFilter(){return this._state.minFilter}get magFilter(){return this._state.magFilter}get wrapS(){return this._state.wrapS}get wrapT(){return this._state.wrapT}get flipY(){return this._state.flipY}get encoding(){return this._state.encoding}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),d.memory.textures--}}class $i extends _{get type(){return"Fresnel"}constructor(e,t={}){super(e,t),this._state=new We({edgeColor:p.vec3([0,0,0]),centerColor:p.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),this.edgeColor=t.edgeColor,this.centerColor=t.centerColor,this.edgeBias=t.edgeBias,this.centerBias=t.centerBias,this.power=t.power}set edgeColor(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set centerColor(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}get centerColor(){return this._state.centerColor}set edgeBias(e){this._state.edgeBias=e||0,this.glRedraw()}get edgeBias(){return this._state.edgeBias}set centerBias(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}get centerBias(){return this._state.centerBias}set power(e){this._state.power=null!=e?e:1,this.glRedraw()}get power(){return this._state.power}destroy(){super.destroy(),this._state.destroy()}}const ea=d.memory,ta=p.AABB3();class sa extends It{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new We({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._aabb=null,this._obb=p.OBB3();const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(t.indices){var i;if(t.positionsDecodeMatrix);else{const e=bt.getPositionsBounds(t.positions),a=bt.compressPositions(t.positions,e.min,e.max);i=a.quantized,s.positionsDecodeMatrix=a.decodeMatrix,s.positionsBuf=new De(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),ea.positions+=s.positionsBuf.numItems,p.positions3ToAABB3(t.positions,this._aabb),p.positions3ToAABB3(i,ta,s.positionsDecodeMatrix),p.AABB3ToOBB3(ta,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);s.colorsBuf=new De(n,n.ARRAY_BUFFER,e,e.length,4,n.STATIC_DRAW),ea.colors+=s.colorsBuf.numItems}if(t.uv){const e=bt.getUVBounds(t.uv),i=bt.compressUVs(t.uv,e.min,e.max),a=i.quantized;s.uvDecodeMatrix=i.decodeMatrix,s.uvBuf=new De(n,n.ARRAY_BUFFER,a,a.length,2,n.STATIC_DRAW),ea.uvs+=s.uvBuf.numItems}if(t.normals){const e=bt.compressNormals(t.normals);let i=s.compressGeometry;s.normalsBuf=new De(n,n.ARRAY_BUFFER,e,e.length,3,n.STATIC_DRAW,i),ea.normals+=s.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);s.indicesBuf=new De(n,n.ELEMENT_ARRAY_BUFFER,e,e.length,1,n.STATIC_DRAW),ea.indices+=s.indicesBuf.numItems;const a=yt(i,e,s.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new De(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),ea.meshes++}else this.error("Config expected: indices");else this.error("Config expected: positions")}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf}get primitive(){return this._state.primitiveName}get aabb(){return this._aabb}get obb(){return this._obb}get numTriangles(){return this._numTriangles}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),ea.meshes--}}var na={};function ia(e,t={}){return new Promise((function(s,n){t.src||(console.error("load3DSGeometry: Parameter expected: src"),n());var i=e.canvas.spinner;i.processes++,m.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),i.processes--,n());var a=na.parse.from3DS(e).edit.objects[0].mesh,r=a.vertices,l=a.uvt,o=a.indices;i.processes--,s(m.apply(t,{primitive:"triangles",positions:r,normals:null,uv:l,indices:o}))}),(function(e){console.error("load3DSGeometry: "+e),i.processes--,n()}))}))}function aa(e,t={}){return new Promise((function(s,n){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),n());var i=e.canvas.spinner;i.processes++,m.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),i.processes--,n());for(var a=na.parse.fromOBJ(e),r=na.edit.unwrap(a.i_verts,a.c_verts,3),l=na.edit.unwrap(a.i_norms,a.c_norms,3),o=na.edit.unwrap(a.i_uvt,a.c_uvt,2),c=new Int32Array(a.i_verts.length),u=0;u0?l:null,autoNormals:0===l.length,uv:o,indices:c}))}),(function(e){console.error("loadOBJGeometry: "+e),i.processes--,n()}))}))}function ra(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);const i=e.center,a=i?i[0]:0,r=i?i[1]:0,l=i?i[2]:0,o=-t+a,c=-s+r,u=-n+l,h=t+a,p=s+r,A=n+l;return m.apply(e,{primitive:"lines",positions:[o,c,u,o,c,A,o,p,u,o,p,A,h,c,u,h,c,A,h,p,u,h,p,A],indices:[0,1,1,3,3,2,2,0,4,5,5,7,7,6,6,4,0,4,1,5,2,6,3,7]})}function la(e={}){let t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);let s=e.divisions||1;s<0&&(console.error("negative divisions not allowed - will invert"),s*=-1),s<1&&(s=1),t=t||10,s=s||10;const n=t/s,i=t/2,a=[],r=[];let l=0;for(let e=0,t=-i;e<=s;e++,t+=n)a.push(-i),a.push(0),a.push(t),a.push(i),a.push(0),a.push(t),a.push(t),a.push(0),a.push(-i),a.push(t),a.push(0),a.push(i),r.push(l++),r.push(l++),r.push(l++),r.push(l++);return m.apply(e,{primitive:"lines",positions:a,indices:r})}function oa(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);let n=e.xSegments||1;n<0&&(console.error("negative xSegments not allowed - will invert"),n*=-1),n<1&&(n=1);let i=e.xSegments||1;i<0&&(console.error("negative zSegments not allowed - will invert"),i*=-1),i<1&&(i=1);const a=e.center,r=a?a[0]:0,l=a?a[1]:0,o=a?a[2]:0,c=t/2,u=s/2,h=Math.floor(n)||1,p=Math.floor(i)||1,A=h+1,d=p+1,f=t/h,I=s/p,y=new Float32Array(A*d*3),v=new Float32Array(A*d*3),w=new Float32Array(A*d*2);let g,T,E,b,D,P,R,C=0,_=0;for(g=0;g65535?Uint32Array:Uint16Array)(h*p*6);for(g=0;g360&&(a=360);const r=e.center;let l=r?r[0]:0,o=r?r[1]:0;const c=r?r[2]:0,u=[],h=[],A=[],d=[];let f,I,y,v,w,g,T,E,b,D,P,R;for(E=0;E<=i;E++)for(T=0;T<=n;T++)f=T/n*a,I=.785398+E/i*Math.PI*2,l=t*Math.cos(f),o=t*Math.sin(f),y=(t+s*Math.cos(I))*Math.cos(f),v=(t+s*Math.cos(I))*Math.sin(f),w=s*Math.sin(I),u.push(y+l),u.push(v+o),u.push(w+c),A.push(1-T/n),A.push(E/i),g=p.normalizeVec3(p.subVec3([y,v,w],[l,o,c],[]),[]),h.push(g[0]),h.push(g[1]),h.push(g[2]);for(E=1;E<=i;E++)for(T=1;T<=n;T++)b=(n+1)*E+T-1,D=(n+1)*(E-1)+T-1,P=(n+1)*(E-1)+T,R=(n+1)*E+T,d.push(b),d.push(D),d.push(P),d.push(P),d.push(R),d.push(b);return m.apply(e,{positions:u,normals:h,uv:A,indices:d})}na.load=function(e,t){var s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="arraybuffer",s.onload=function(e){t(e.target.response)},s.send()},na.save=function(e,t){var s="data:application/octet-stream;base64,"+btoa(na.parse._buffToStr(e));window.location.href=s},na.clone=function(e){return JSON.parse(JSON.stringify(e))},na.bin={},na.bin.f=new Float32Array(1),na.bin.fb=new Uint8Array(na.bin.f.buffer),na.bin.rf=function(e,t){for(var s=na.bin.f,n=na.bin.fb,i=0;i<4;i++)n[i]=e[t+i];return s[0]},na.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},na.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},na.bin.rASCII0=function(e,t){for(var s="";0!=e[t];)s+=String.fromCharCode(e[t++]);return s},na.bin.wf=function(e,t,s){new Float32Array(e.buffer,t,1)[0]=s},na.bin.wsl=function(e,t,s){e[t]=s,e[t+1]=s>>8},na.bin.wil=function(e,t,s){e[t]=s,e[t+1]=s>>8,e[t+2]=s>>16,e[t+3]},na.parse={},na.parse._buffToStr=function(e){for(var t=new Uint8Array(e),s="",n=0;ni&&(i=o),ca&&(a=c),ur&&(r=u)}return{min:{x:t,y:s,z:n},max:{x:i,y:a,z:r}}};class ua extends _{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=p.vec3(t.pos||[0,0,0]),this._up=p.vec3(t.up||[0,1,0]),this._normal=p.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=p.vec3(),this._rtcPos=p.vec3(),this._imageSize=p.vec2(),this._texture=new Zi(this),this._image=new Image,"jpg"!==this._type&&"png"!==this._type&&(this.error('Unsupported type - defaulting to "jpg"'),this._type="jpg"),this._node=new Mi(this,{matrix:p.inverseMat4(p.lookAtMat4v(this._pos,p.subVec3(this._pos,this._normal,p.mat4()),this._up,p.mat4())),children:[this._bitmapMesh=new vi(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new Rt(this,oa({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new St(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0})})]}),t.image?this.image=t.image:t.src?this.src=t.src:t.imageData&&(this.imageData=t.imageData),this.scene._bitmapCreated(this)}set visible(e){this._bitmapMesh.visible=e}get visible(){return this._bitmapMesh.visible}set image(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}get image(){return this._image}set src(e){if(e){this._image.onload=()=>{this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale()},this._image.src=e;switch(e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}}get src(){return this._image.src}set imageData(e){this._image.onload=()=>{this._texture.image=image,this._imageSize[0]=image.width,this._imageSize[1]=image.height,this._updateBitmapMeshScale()},this._image.src=e}get imageData(){const e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")}set type(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}get type(){return this._type}get pos(){return this._pos}get normal(){return this._normal}get up(){return this._up}set height(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}get height(){return this._height}set collidable(e){this._bitmapMesh.collidable=!1!==e}get collidable(){return this._bitmapMesh.collidable}set clippable(e){this._bitmapMesh.clippable=!1!==e}get clippable(){return this._bitmapMesh.clippable}set pickable(e){this._bitmapMesh.pickable=!1!==e}get pickable(){return this._bitmapMesh.pickable}set opacity(e){this._bitmapMesh.opacity=e}get opacity(){return this._bitmapMesh.opacity}destroy(){super.destroy(),this.scene._bitmapDestroyed(this)}_updateBitmapMeshScale(){const e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height*e,1,this._height]}}class ha extends _{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],this._origin=p.vec3(t.origin||[0,0,0]),t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;ed.has(e.id)||I.has(e.id)||f.has(e.id))).reduce(((e,s)=>{let n,i=function(e){let t="";return t+=Math.round(255*e[0]).toString(16).padStart(2,"0"),t+=Math.round(255*e[1]).toString(16).padStart(2,"0"),t+=Math.round(255*e[2]).toString(16).padStart(2,"0"),t}(s.colorize);s.xrayed?(n=0===t.xrayMaterial.fillAlpha&&0!==t.xrayMaterial.edgeAlpha?.1:t.xrayMaterial.fillAlpha,n=Math.round(255*n).toString(16).padStart(2,"0"),i=n+i):d.has(s.id)&&(n=Math.round(255*s.opacity).toString(16).padStart(2,"0"),i=n+i),e[i]||(e[i]=[]);const a=s.id,r=s.originalSystemId,l={ifc_guid:r,originating_system:this.originatingSystem};return r!==a&&(l.authoring_tool_id=a),e[i].push(l),e}),{}),m=Object.entries(y).map((([e,t])=>({color:e,components:t})));a.components.coloring=m;const v=t.objectIds,w=t.visibleObjects,g=t.visibleObjectIds,T=v.filter((e=>!w[e])),E=t.selectedObjectIds;return e.defaultInvisible||g.length{e.start_point&&e.end_point&&(t.push(e.start_point.x),t.push(e.start_point.y),t.push(e.start_point.z),t.push(e.end_point.x),t.push(e.end_point.y),t.push(e.end_point.z),s.push(i++),s.push(i++))})),new ha(n,{positions:t,indices:s,clippable:!1,collidable:!0})}if(n.clearBitmaps(),e.bitmaps&&e.bitmaps.forEach((function(e){const t=e.bitmap_type||"jpg",s=e.bitmap_data;let a=ma(e.location,Aa),r=ma(e.normal,da),l=ma(e.up,fa),o=e.height||1;t&&s&&a&&r&&l&&(i.yUp&&(a=wa(a),r=wa(r),l=wa(l)),new ua(n,{src:s,type:t,pos:a,normal:r,up:l,clippable:!1,collidable:!0,height:o}))})),l&&(n.setObjectsXRayed(n.xrayedObjectIds,!1),n.setObjectsHighlighted(n.highlightedObjectIds,!1),n.setObjectsSelected(n.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(n.setObjectsVisible(n.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!1))))):(n.setObjectsVisible(n.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((e=>this._withBCFComponent(t,e,(e=>e.visible=!0)))));const i=e.components.visibility.view_setup_hints;i&&(!1===i.spaces_visible&&n.setObjectsVisible(s.metaScene.getObjectIDsByType("IfcSpace"),!1),!1===i.openings_visible&&n.setObjectsVisible(s.metaScene.getObjectIDsByType("IfcOpening"),!1),i.space_boundaries_visible)}e.components.selection&&(n.setObjectsSelected(n.selectedObjectIds,!1),e.components.selection.forEach((e=>this._withBCFComponent(t,e,(e=>e.selected=!0))))),e.components.coloring&&e.components.coloring.forEach((e=>{let s=e.color,n=0,i=!1;8===s.length&&(n=parseInt(s.substring(0,2),16)/256,n<=1&&n>=.95&&(n=1),s=s.substring(2),i=!0);const a=[parseInt(s.substring(0,2),16)/256,parseInt(s.substring(2,4),16)/256,parseInt(s.substring(4,6),16)/256];e.components.map((e=>this._withBCFComponent(t,e,(e=>{e.colorize=a,i&&(e.opacity=n)}))))}))}if(e.perspective_camera||e.orthogonal_camera){let l,c,u,h;if(e.perspective_camera?(l=ma(e.perspective_camera.camera_view_point,pa),c=ma(e.perspective_camera.camera_direction,pa),u=ma(e.perspective_camera.camera_up_vector,pa),i.perspective.fov=e.perspective_camera.field_of_view,h="perspective"):(l=ma(e.orthogonal_camera.camera_view_point,pa),c=ma(e.orthogonal_camera.camera_direction,pa),u=ma(e.orthogonal_camera.camera_up_vector,pa),i.ortho.scale=e.orthogonal_camera.view_to_world_scale,h="ortho"),p.subVec3(l,o),i.yUp&&(l=wa(l),c=wa(c),u=wa(u)),a){const e=n.pick({pickSurface:!0,origin:l,direction:c});c=e?e.worldPos:p.addVec3(l,c,pa)}else c=p.addVec3(l,c,pa);r?(i.eye=l,i.look=c,i.up=u,i.projection=h):s.cameraFlight.flyTo({eye:l,look:c,up:u,duration:t.duration,projection:h})}}_withBCFComponent(e,t,s){const n=this.viewer,i=n.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){const a=t.authoring_tool_id,r=i.objects[a];if(r)return void s(r);if(e.updateCompositeObjects){if(n.metaScene.metaObjects[a])return void i.withObjects(n.metaScene.getObjectIDsInSubtree(a),s)}}if(t.ifc_guid){const a=t.ifc_guid,r=i.objects[a];if(r)return void s(r);if(e.updateCompositeObjects){if(n.metaScene.metaObjects[a])return void i.withObjects(n.metaScene.getObjectIDsInSubtree(a),s)}Object.keys(i.models).forEach((t=>{const r=p.globalizeObjectId(t,a),l=i.objects[r];if(l)s(l);else if(e.updateCompositeObjects){n.metaScene.metaObjects[r]&&i.withObjects(n.metaScene.getObjectIDsInSubtree(r),s)}}))}}destroy(){super.destroy()}}function ya(e){return{x:e[0],y:e[1],z:e[2]}}function ma(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function va(e){return new Float64Array([e[0],-e[2],e[1]])}function wa(e){return new Float64Array([e[0],e[2],-e[1]])}var ga=p.vec3();const Ta=(e,t,s,n)=>{var i=e-s,a=t-n;return Math.sqrt(i*i+a*a)};class Ea extends _{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._eventSubs={};var s=this.plugin.viewer.scene;this._originMarker=new q(s,t.origin),this._targetMarker=new q(s,t.target),this._originWorld=p.vec3(),this._targetWorld=p.vec3(),this._wp=new Float64Array(24),this._vp=new Float64Array(24),this._pp=new Float64Array(24),this._cp=new Float64Array(8),this._xAxisLabelCulled=!1,this._yAxisLabelCulled=!1,this._zAxisLabelCulled=!1,this._color=t.color||this.plugin.defaultColor;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._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._lengthWire=new J(this._container,{color:this._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._xAxisWire=new J(this._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._yAxisWire=new J(this._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._zAxisWire=new J(this._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._lengthLabel=new $(this._container,{fillColor:this._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._xAxisLabel=new $(this._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._yAxisLabel=new $(this._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._zAxisLabel=new $(this._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._targetVisible=!1,this._wireVisible=!1,this._axisVisible=!1,this._xAxisVisible=!1,this._yAxisVisible=!1,this._zAxisVisible=!1,this._axisEnabled=!0,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._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._onMetricsUnits=s.metrics.on("units",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsScale=s.metrics.on("scale",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onMetricsOrigin=s.metrics.on("origin",(()=>{this._cpDirty=!0,this._needUpdate()})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.targetVisible=t.targetVisible,this.wireVisible=t.wireVisible,this.axisVisible=t.axisVisible,this.xAxisVisible=t.xAxisVisible,this.yAxisVisible=t.yAxisVisible,this.zAxisVisible=t.zAxisVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;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._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=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._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0);const t=this._originMarker.viewPos[2],s=this._targetMarker.viewPos[2];if(t>-.3||s>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){p.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var n=this._pp,i=this._cp,a=e.canvas.canvas.getBoundingClientRect();const t=this._container.getBoundingClientRect();var r=a.top-t.top,l=a.left-t.left,o=e.canvas.boundary,c=o[2],u=o[3],h=0;const s=this.plugin.viewer.scene.metrics,f=s.scale,I=s.units,y=s.unitsInfo[I].abbrev;for(var A=0,d=n.length;A1?i.other:i.one,i?(i=Pa(i,[t]),s&&(i=Pa(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const a=this._events[t];return void 0!==a&&s(a),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function Da(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var s=e-t,n=e+t;s<0&&(s=0),n>1&&(n=1);var i=this.getPoint(s),a=this.getPoint(n),r=p.subVec3(a,i,[]);return p.normalizeVec3(r,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,s,n=[],i=this.getPoint(0),a=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),a+=p.lenVec3(p.subVec3(t,i,[])),n.push(a),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,a=n.length;s=t||e*n[a-1];for(var r,l=0,o=a-1;l<=o;)if((r=n[i=Math.floor(l+(o-l)/2)]-s)<0)l=i+1;else{if(!(r>0)){o=i;break}o=i-1}if(n[i=o]===s)return i/(a-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(a-1)}}class Ca extends Ra{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var s=(t.length-1)*e,n=Math.floor(s),i=s-n,a=t[0===n?n:n-1],r=t[n],l=t[n>t.length-2?t.length-1:n+1],o=t[n>t.length-3?t.length-1:n+2],c=p.vec3();return c[0]=p.catmullRomInterpolate(a[0],r[0],l[0],o[0],i),c[1]=p.catmullRomInterpolate(a[1],r[1],l[1],o[1],i),c[2]=p.catmullRomInterpolate(a[2],r[2],l[2],o[2],i),c}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const _a=p.vec3();class Ba extends _{get type(){return"CameraPath"}constructor(e,t={}){super(e,t),this._frames=[],this._eyeCurve=new Ca(this),this._lookCurve=new Ca(this),this._upCurve=new Ca(this),t.frames&&(this.addFrames(t.frames),this.smoothFrameTimes(1))}get frames(){return this._frames}get eyeCurve(){return this._eyeCurve}get lookCurve(){return this._lookCurve}get upCurve(){return this._upCurve}saveFrame(e){const t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}addFrame(e,t,s,n){const i={t:e,eye:t.slice(0),look:s.slice(0),up:n.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}addFrames(e){let t;for(let s=0,n=e.length;s1?1:e,t.eye=this._eyeCurve.getPoint(e,_a),t.look=this._lookCurve.getPoint(e,_a),t.up=this._upCurve.getPoint(e,_a)}sampleFrame(e,t,s,n){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,s),this._upCurve.getPoint(e,n)}smoothFrameTimes(e){if(0===this._frames.length)return;const t=p.vec3();var s=0;this._frames[0].t=0;const n=[];for(let e=1,a=this._frames.length;e=1;e>1&&(e=1);const s=this.easing?Ma._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(p.subVec3(n.eye,n.look,La),n.eye=p.lerpVec3(s,0,1,this._eye1,this._eye2,Na),n.look=p.subVec3(Na,La,Sa)):this._flyingLook&&(n.look=p.lerpVec3(s,0,1,this._look1,this._look2,Sa),n.up=p.lerpVec3(s,0,1,this._up1,this._up2,xa)):this._flyingEyeLookUp&&(n.eye=p.lerpVec3(s,0,1,this._eye1,this._eye2,Na),n.look=p.lerpVec3(s,0,1,this._look1,this._look2,Sa),n.up=p.lerpVec3(s,0,1,this._up1,this._up2,xa)),this._projection2){const t="ortho"===this._projection2?Ma._easeOutExpo(e,0,1,1):Ma._easeInCubic(e,0,1,1);n.customProjection.matrix=p.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();R.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class Fa extends _{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new Ma(this),this._t=0,this.state=Fa.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case Fa.SCRUBBING:return;case Fa.PLAYING:if(this._t+=this._playingRate*i,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=Fa.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case Fa.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=Fa.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=Fa.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=Fa.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=Fa.SCRUBBING,this._cameraFlightAnimation.flyTo(n,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=Fa.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=Fa.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=Fa.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}Fa.STOPPED=0,Fa.SCRUBBING=1,Fa.PLAYING=2,Fa.PLAYING_TO=3;const Ha=p.vec3(),Ua=p.vec3();p.vec3();const Ga=p.vec3([0,-1,0]),Va=p.vec4([0,0,0,1]);class ja extends _{constructor(e,t={}){super(e,t),this._src=null,this._image=null,this._pos=p.vec3(),this._origin=p.vec3(),this._rtcPos=p.vec3(),this._dir=p.vec3(),this._size=1,this._imageSize=p.vec2(),this._texture=new Zi(this),this._plane=new vi(this,{geometry:new Rt(this,oa({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new St(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0}),clippable:t.clippable}),this._grid=new vi(this,{geometry:new Rt(this,la({size:1,divisions:10})),material:new St(this,{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:t.clippable}),this._node=new Mi(this,{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[this._plane,this._grid]}),this._gridVisible=!1,this.visible=!0,this.gridVisible=t.gridVisible,this.position=t.position,this.rotation=t.rotation,this.dir=t.dir,this.size=t.size,this.collidable=t.collidable,this.clippable=t.clippable,this.pickable=t.pickable,this.opacity=t.opacity,t.image?this.image=t.image:this.src=t.src}set visible(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}get visible(){return this._plane.visible}set gridVisible(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}get gridVisible(){return this._gridVisible}set image(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}get image(){return this._image}set src(e){if(this._src=e,this._src){this._image=null;const e=new Image;e.onload=()=>{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set position(e){this._pos.set(e||[0,0,0]),S(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}get position(){return this._pos}set rotation(e){this._node.rotation=e}get rotation(){return this._node.rotation}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set dir(e){if(this._dir.set(e||[0,0,-1]),e){const t=this.scene.center,s=[-this._dir[0],-this._dir[1],-this._dir[2]];p.subVec3(t,this.position,Ha);const n=-p.dotVec3(s,Ha);p.normalizeVec3(s),p.mulVec3Scalar(s,n,Ua),p.vec3PairToQuaternion(Ga,e,Va),this._node.quaternion=Va}}get dir(){return this._dir}set collidable(e){this._node.collidable=!1!==e}get collidable(){return this._node.collidable}set clippable(e){this._node.clippable=!1!==e}get clippable(){return this._node.clippable}set pickable(e){this._node.pickable=!1!==e}get pickable(){return this._node.pickable}set opacity(e){this._node.opacity=e}get opacity(){return this._node.opacity}destroy(){super.destroy()}_updatePlaneSizeFromImage(){const e=this._size,t=this._imageSize[0],s=this._imageSize[1];if(t>s){const n=s/t;this._node.scale=[e,1,e*n]}else{const n=t/s;this._node.scale=[e*n,1,e]}}}class ka extends At{get type(){return"PointLight"}constructor(e,t={}){super(e,t);const s=this;this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const n=this.scene.camera,i=this.scene.canvas;this._onCameraViewMatrix=n.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=n.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=i.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new We({type:"point",pos:p.vec3([1,1,1]),color:p.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(s._shadowViewMatrixDirty){s._shadowViewMatrix||(s._shadowViewMatrix=p.identityMat4());const e=s._state.pos,t=n.look,i=n.up;p.lookAtMat4v(e,t,i,s._shadowViewMatrix),s._shadowViewMatrixDirty=!1}return s._shadowViewMatrix},getShadowProjMatrix:()=>{if(s._shadowProjMatrixDirty){s._shadowProjMatrix||(s._shadowProjMatrix=p.identityMat4());const e=s.scene.canvas.canvas;p.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,s._shadowProjMatrix),s._shadowProjMatrixDirty=!1}return s._shadowProjMatrix},getShadowRenderBuf:()=>(s._shadowRenderBuf||(s._shadowRenderBuf=new Ue(s.scene.canvas.canvas,s.scene.canvas.gl,{size:[1024,1024]})),s._shadowRenderBuf)}),this.pos=t.pos,this.color=t.color,this.intensity=t.intensity,this.constantAttenuation=t.constantAttenuation,this.linearAttenuation=t.linearAttenuation,this.quadraticAttenuation=t.quadraticAttenuation,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set pos(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get pos(){return this._state.pos}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set constantAttenuation(e){this._state.attenuation[0]=e||0,this.glRedraw()}get constantAttenuation(){return this._state.attenuation[0]}set linearAttenuation(e){this._state.attenuation[1]=e||0,this.glRedraw()}get linearAttenuation(){return this._state.attenuation[1]}set quadraticAttenuation(e){this._state.attenuation[2]=e||0,this.glRedraw()}get quadraticAttenuation(){return this._state.attenuation[2]}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}function Qa(e){if(!Wa(e.width)||!Wa(e.height)){const t=document.createElement("canvas");t.width=za(e.width),t.height=za(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Wa(e){return 0==(e&e-1)}function za(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Ka extends _{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new We({texture:new zi({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),d.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let a=0;a{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set collidable(e){this._mesh.collidable=!1!==e}get collidable(){return this._mesh.collidable}set clippable(e){this._mesh.clippable=!1!==e}get clippable(){return this._mesh.clippable}set pickable(e){this._mesh.pickable=!1!==e}get pickable(){return this._mesh.pickable}set opacity(e){this._mesh.opacity=e}get opacity(){return this._mesh.opacity}_updatePlaneSizeFromImage(){const e=.5*this._size,t=this._imageSize[0],s=this._imageSize[1],n=s/t;this._geometry.positions=t>s?[e,e*n,0,-e,e*n,0,-e,-e*n,0,e,-e*n,0]:[e/n,e,0,-e/n,e,0,-e/n,-e,0,e/n,-e,0]}}class Ja{constructor(e){this._eye=p.vec3(),this._look=p.vec3(),this._up=p.vec3(),this._projection={},e&&this.saveCamera(e)}saveCamera(e){const t=e.camera,s=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:s.fov,fovAxis:s.fovAxis,near:s.near,far:s.far};break;case"ortho":this._projection={projection:"ortho",scale:s.scale,near:s.near,far:s.far};break;case"frustum":this._projection={projection:"frustum",left:s.left,right:s.right,top:s.top,bottom:s.bottom,near:s.near,far:s.far};break;case"custom":this._projection={projection:"custom",matrix:s.matrix.slice()}}}restoreCamera(e,t){const s=e.camera,n=this._projection;function i(){switch(n.type){case"perspective":s.perspective.fov=n.fov,s.perspective.fovAxis=n.fovAxis,s.perspective.near=n.near,s.perspective.far=n.far;break;case"ortho":s.ortho.scale=n.scale,s.ortho.near=n.near,s.ortho.far=n.far;break;case"frustum":s.frustum.left=n.left,s.frustum.right=n.right,s.frustum.top=n.top,s.frustum.bottom=n.bottom,s.frustum.near=n.near,s.frustum.far=n.far;break;case"custom":s.customProjection.matrix=n.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:n.scale,projection:n.projection},(()=>{i(),t()})):(s.eye=this._eye,s.look=this._look,s.up=this._up,i(),s.projection=n.projection)}}const Za=p.vec3();class $a{constructor(e){if(this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,e){const t=e.metaScene.scene;this.saveObjects(t,e)}}saveObjects(e,t,s){const n=t.rootMetaObject;if(!n)return;const i=n.getObjectIDsInSubtree();this.numObjects=0,this._mask=s?m.apply(s,{}):null;const a=e.objects,r=!s||s.visible,l=!s||s.edges,o=!s||s.xrayed,c=!s||s.highlighted,u=!s||s.selected,h=!s||s.clippable,p=!s||s.pickable,A=!s||s.colorize,d=!s||s.opacity;for(var f=0,I=i.length;f1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=p.vec3();return t[0]=p.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=p.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=p.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}class nr extends Ra{constructor(e,t={}){super(e,t),this._cachedLengths=[],this._dirty=!0,this._curves=[],this._t=0,this._dirtySubs=[],this._destroyedSubs=[],this.curves=t.curves||[],this.t=t.t}addCurve(e){this._curves.push(e),this._dirty=!0}set curves(e){var t,s,n;for(e=e||[],s=0,n=this._curves.length;s1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}get length(){var e=this._getCurveLengths();return e[e.length-1]}getPoint(e){for(var t,s=e*this.length,n=this._getCurveLengths(),i=0;i=s){var a=1-(n[i]-s)/(t=this._curves[i]).length;return t.getPointAt(a)}i++}return null}_getCurveLengths(){if(!this._dirty)return this._cachedLengths;var e,t=[],s=0,n=this._curves.length;for(e=0;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=p.vec3();return t[0]=p.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=p.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=p.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}class ar{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 rr=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 lr=0;const or={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},cr=new Float32Array([1,1,1,1]),ur=new Float32Array([0,0,0,1]),hr=p.vec4(),pr=p.vec3();class Ar{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;hr[0]=s,hr[1]=n,hr[2]=t.blendCutoff,hr[3]=t.blendFactor,l.uniform4fv(this._uSAOParams,hr),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===or[(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===or[(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===or[(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?ur:cr)}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 dr extends Ar{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 fr extends dr{constructor(e,t){super(e,t,{instancing:!1,edges:!0})}}class Ir extends Ar{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 yr extends Ir{constructor(e,t){super(e,t,{instancing:!0,edges:!0})}}class mr extends Ar{_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 vr extends Ar{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 wr extends Ar{_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 gr extends Ar{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 Tr extends dr{_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 Er extends dr{_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 Dr extends fr{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 Pr extends fr{_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 Rr extends dr{_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 Cr extends dr{_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 _r extends dr{_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 Br extends dr{_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 Or extends dr{_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 Sr extends dr{_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 Nr extends dr{_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 xr extends dr{_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 Mr extends dr{_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 Gr=p.mat4(),Vr=p.mat4();function jr(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 Wr(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 zr=p.vec3();class Kr{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.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[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.snapPickCoordinateScale[0]=p.safeInv(h[0]),e.snapPickCoordinateScale[1]=p.safeInv(h[1]),e.snapPickCoordinateScale[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.snapPickLayerNumber),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 Yr=p.vec3();class Xr{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.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[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.snapPickCoordinateScale[0]=p.safeInv(u[0]),e.snapPickCoordinateScale[1]=p.safeInv(u[1]),e.snapPickCoordinateScale[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.snapPickLayerNumber),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("gl_PointSize = 1.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("// 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 qr{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 Kr(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Xr(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const Jr={};const Zr=p.mat4(),$r=p.mat4(),el=p.vec4([0,0,0,1]),tl=p.vec4([0,0,0,1]),sl=p.vec4([0,0,0,1]),nl=p.OBB3(),il=p.vec3(),al=p.vec3(),rl=p.vec3(),ll=p.vec3(),ol=p.vec3(),cl=p.vec3(),ul=p.vec3();class hl{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=Hr[t];return s||(s=new Fr(e),Hr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Hr[t],s._destroy()}))),s}(e.model.scene),this._snapBatchingRenderers=function(e){const t=e.id;let s=Jr[t];return s||(s=new qr(e),Jr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Jr[t],s._destroy()}))),s}(e.model.scene),this._buffer=new Ur(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new We({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=Zr;I?p.inverseMat4(p.transposeMat4(I,$r),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=Qr(d,"floor","ceil"),l=Wr(r),c=a(d,l),c>u&&(o=r,u=c),r=Qr(d,"ceil","ceil"),l=Wr(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):jr(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=bt.getUVBounds(s.uv),i=bt.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 pl extends Ir{_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 Al extends Ir{_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 fl extends yr{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 Il extends yr{_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 yl extends Ir{_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 ml extends Ir{_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 vl extends Ir{_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 wl extends Ir{_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("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 = 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 gl extends Ir{_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 Tl extends Ir{_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 El extends Ir{_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 bl={3e3:"linearToLinear",3001:"sRGBToLinear"};class Dl extends Ir{_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 = "+bl[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 = "+bl[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 Rl extends Ir{_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*I,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),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 Sl=p.vec3();class Nl{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.canvas.gl,r=t._state,l=t._state.origin;e.snapPickOrigin[0]=l[0],e.snapPickOrigin[1]=l[1],e.snapPickOrigin[2]=l[2];const o=t.aabb,c=[p.safeInv(o[3]-o[0])*p.MAX_INT,p.safeInv(o[4]-o[1])*p.MAX_INT,p.safeInv(o[5]-o[2])*p.MAX_INT];if(e.snapPickCoordinateScale[0]=p.safeInv(c[0]),e.snapPickCoordinateScale[1]=p.safeInv(c[1]),e.snapPickCoordinateScale[2]=p.safeInv(c[2]),!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const u=i.camera;let h=u.eye;e.pickViewMatrix&&(h=e.pickOrigin||h);const A=[h[0]-l[0],h[1]-l[1],h[2]-l[2]];a.uniform3fv(this._uCameraEyeRtc,A),a.uniform2fv(this.uVectorA,e.snapVectorA),a.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),a.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),a.uniform3fv(this._uCoordinateScaler,c),a.uniform1i(this._uRenderPass,s),a.uniform1i(this._uPickInvisible,e.pickInvisible);const d=e.pickViewMatrix||u.viewMatrix,f=l?O(d,l):d;if(a.uniformMatrix4fv(this._uViewMatrix,!1,f),a.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),a.uniformMatrix4fv(this._uProjMatrix,!1,u.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);a.uniform1f(this._uLogDepthBufFC,t)}const I=i._sectionPlanesState.sectionPlanes.length;if(I>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*I,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),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("gl_PointSize = 1.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("// SnapInstancingDepthRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),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}}class xl{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 Ol(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Nl(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const Ll={};const Ml=new Uint8Array(4),Fl=new Float32Array(1),Hl=p.vec4([0,0,0,1]),Ul=p.vec4([0,0,0,1]),Gl=p.vec4([0,0,0,1]),Vl=new Float32Array(3),jl=p.vec3(),kl=p.vec3(),Ql=p.vec3(),Wl=p.vec3(),zl=p.vec3(),Kl=p.vec3(),Yl=p.vec3();class Xl{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=_l[t];return s||(s=new Cl(e),_l[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete _l[t],s._destroy()}))),s}(e.model.scene),this._snapInstancingRenderers=function(e){const t=e.id;let s=Ll[t];return s||(s=new xl(e),Ll[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Ll[t],s._destroy()}))),s}(e.model.scene),this._aabb=p.collapseAABB3(),this._state=new We({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";Ml[0]=t[0],Ml[1]=t[1],Ml[2]=t[2],Ml[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(Ml,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?or.NOT_RENDERED:s?or.COLOR_TRANSPARENT:or.COLOR_OPAQUE,h=!n||c?or.NOT_RENDERED:r?or.SILHOUETTE_SELECTED:a?or.SILHOUETTE_HIGHLIGHTED:i?or.SILHOUETTE_XRAYED:or.NOT_RENDERED;let p=0;p=!n||c?or.NOT_RENDERED:r?or.EDGES_SELECTED:a?or.EDGES_HIGHLIGHTED:i?or.EDGES_XRAYED:l?s?or.EDGES_COLOR_TRANSPARENT:or.EDGES_COLOR_OPAQUE:or.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?or.PICK:or.NOT_RENDERED)<<12,A|=(t&U?1:0)<<16,Fl[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(Fl,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Vl[0]=t[0],Vl[1]=t[1],Vl[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Vl,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=Hl,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 ql extends wr{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 Jl extends wr{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 Zl{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 ql(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Jl(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const $l={};class eo{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]}}const to=p.vec4([0,0,0,1]),so=p.vec4([0,0,0,1]),no=p.vec4([0,0,0,1]),io=p.OBB3();class ao{constructor(e){this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=$l[t];return s||(s=new Zl(e),$l[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete $l[t],s._destroy()}))),s}(e.model.scene),this.model=e.model,this._buffer=new eo(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new We({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=jr(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 lo extends gr{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 oo{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 ro(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new lo(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const co={};const uo=new Uint8Array(4),ho=new Float32Array(1),po=p.vec4([0,0,0,1]),Ao=p.vec4([0,0,0,1]),fo=p.vec4([0,0,0,1]),Io=new Float32Array(3);class yo{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=co[t];return s||(s=new oo(e),co[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete co[t],s._destroy()}))),s}(e.model.scene),this._aabb=p.collapseAABB3(),this._state=new We({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";uo[0]=t[0],uo[1]=t[1],uo[2]=t[2],uo[3]=t[3],this._state.colorsBuf.setData(uo,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?or.NOT_RENDERED:s?or.COLOR_TRANSPARENT:or.COLOR_OPAQUE,h=!n||c?or.NOT_RENDERED:r?or.SILHOUETTE_SELECTED:a?or.SILHOUETTE_HIGHLIGHTED:i?or.SILHOUETTE_XRAYED:or.NOT_RENDERED;let p=0;p=!n||c?or.NOT_RENDERED:r?or.EDGES_SELECTED:a?or.EDGES_HIGHLIGHTED:i?or.EDGES_XRAYED:l?s?or.EDGES_COLOR_TRANSPARENT:or.EDGES_COLOR_OPAQUE:or.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?or.PICK:or.NOT_RENDERED)<<12,A|=(t&U?255:0)<<16,ho[0]=A,this._state.flagsBuf.setData(ho,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Io[0]=t[0],Io[1]=t[1],Io[2]=t[2],this._state.offsetsBuf.setData(Io,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,or.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,or.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,or.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,or.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,or.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 mo extends mr{_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 vo extends mr{_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 wo extends mr{_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 go extends mr{_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 To extends mr{_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 Eo{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 mo(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new vo(this._scene)),this._silhouetteRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new wo(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new go(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new To(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 bo={};class Do{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 Po=p.vec4(),Ro=p.vec4(),Co=p.vec4([0,0,0,1]),_o=p.vec4([0,0,0,1]),Bo=p.vec4([0,0,0,1]),Oo=p.OBB3();class So{constructor(e){this.model=e.model,this.sortId="PointsBatchingLayer",this.layerIndex=e.layerIndex,this._pointsBatchingRenderers=function(e){const t=e.id;let s=bo[t];return s||(s=new Eo(e),bo[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete bo[t],s._destroy()}))),s}(e.model.scene),this._buffer=new Do(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new We({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=jr(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 xo extends vr{_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 Lo extends vr{_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 Mo extends vr{_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 Fo extends vr{_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 Ho extends vr{_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 Uo extends vr{_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 Go{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 No(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new xo(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new Ho(this._scene)),this._depthRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Lo(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Mo(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new Fo(this._scene)),this._occlusionRenderer}get shadowRenderer(){return this._shadowRenderer||(this._shadowRenderer=new Uo(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 Vo={};const jo=new Uint8Array(4),ko=new Float32Array(1),Qo=p.vec4([0,0,0,1]),Wo=p.vec4([0,0,0,1]),zo=p.vec4([0,0,0,1]),Ko=new Float32Array(3);class Yo{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=Vo[t];return s||(s=new Go(e),Vo[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Vo[t],s._destroy()}))),s}(e.model.scene),this._aabb=p.collapseAABB3(),this._state=new We({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";jo[0]=t[0],jo[1]=t[1],jo[2]=t[2],this._state.colorsBuf.setData(jo,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?or.NOT_RENDERED:s?or.COLOR_TRANSPARENT:or.COLOR_OPAQUE,h=!n||c?or.NOT_RENDERED:r?or.SILHOUETTE_SELECTED:a?or.SILHOUETTE_HIGHLIGHTED:i?or.SILHOUETTE_XRAYED:or.NOT_RENDERED;let p=0;p=!n||c?or.NOT_RENDERED:r?or.EDGES_SELECTED:a?or.EDGES_HIGHLIGHTED:i?or.EDGES_XRAYED:l?s?or.EDGES_COLOR_TRANSPARENT:or.EDGES_COLOR_OPAQUE:or.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?or.PICK:or.NOT_RENDERED)<<12,A|=(t&U?255:0)<<16,ko[0]=A,this._state.flagsBuf.setData(ko,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Ko[0]=t[0],Ko[1]=t[1],Ko[2]=t[2],this._state.offsetsBuf.setData(Ko,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,or.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,or.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,or.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,or.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,or.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,or.COLOR_OPAQUE)}drawShadow(e,t){}drawPickMesh(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,or.PICK)}drawPickDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,or.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 Xo{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 qo{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const Jo={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}};class Zo{constructor(e,t,s){this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=s}itemStart(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}itemEnd(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}itemError(e){void 0!==this.onError&&this.onError(e)}resolveURL(e){return this.urlModifier?this.urlModifier(e):e}setURLModifier(e){return this.urlModifier=e,this}addHandler(e,t){return this.handlers.push(e,t),this}removeHandler(e){const t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}getHandler(e){for(let t=0,s=this.handlers.length;t{t&&t(i),this.manager.itemEnd(e)}),0),i;if(void 0!==tc[e])return void tc[e].push({onLoad:t,onProgress:s,onError:n});tc[e]=[],tc[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=tc[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=>{Jo.add(e,t);const s=tc[e];delete tc[e];for(let e=0,n=s.length;e{const s=tc[e];if(void 0===s)throw this.manager.itemError(e),t;delete tc[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 nc{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 ic=0;class ac{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 nc,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 sc;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new sc;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=ac.BasisWorker.toString(),n=["/* constants */","let _EngineFormat = "+JSON.stringify(ac.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(ac.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(ac.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}))})),ic>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),ic++}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(),ic--}}ac.BasisFormat={ETC1S:0,UASTC_4x4:1},ac.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},ac.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},ac.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 rc[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 8b96dcef1..c9b0e9a25 100644 --- a/dist/xeokit-sdk.min.es5.js +++ b/dist/xeokit-sdk.min.es5.js @@ -7,7 +7,7 @@ var e,t=l().mark(eT),n=l().mark(tT),r=l().mark(pD);function i(e){return function * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT */ -function zn(e,t){t.length;for(var n=e.length,r=[],i=[],a=function(n){var a=e[n];if(function(e){for(var n=0,r=e.meshIds.length;n0){o=function(e){for(var t=[],n=0,r=e.length;nthis._frustumProps.CAM_FACTOR_1?(n|=l<0?64:128,n&=-17):n&=-33;var u=er(Z.dotVec3(s,this._frustumProps.up),o);Math.abs(u)>this._frustumProps.CAM_FACTOR_2?(n|=u<0?1024:2048,n&=-257):n&=-513}return 4&n&&8&n&&(n|=4096),64&n&&128&n&&(n|=8192),1024&n&&2048&n&&(n|=16384),e._check=n,n}}]),e}(),nr=function(){function e(t,n){b(this,e),this.sceneModel=n,this.entities=[],this.meshes=[],this.finalized=!1}return P(e,[{key:"addEntity",value:function(e){if(this.finalized)throw"Already finalized";this.entities.push(e)}},{key:"addMesh",value:function(e){if(this.finalized)throw"Already finalized";this.meshes.push(e)}},{key:"finalize",value:function(e){var t=this;if(this.finalized)throw"Already finalized";this.finalized=!0,this.VFCState=new tr,this.VFCState.initializeVFCState(this.entities,this.meshes),this.VFCState.finalize(this.sceneModel,e),this._onSceneRendering=this.sceneModel.scene.on("rendering",(function(){return t.applyViewFrustumCulling.call(t)}))}},{key:"applyViewFrustumCulling",value:function(){this.finalized&&this.VFCState.applyViewFrustumCulling(this.sceneModel)}},{key:"destroy",value:function(){this.finalized&&this.sceneModel.off(this._onSceneRendering)}}]),e}(),rr=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._scene=e,r._vfcManagers={},r._vfcManagerList=[],r.enabled=i.enabled,r._init(),r}return P(n,[{key:"_init",value:function(){var e=this;this._scene.on("rendering",(function(){for(var t=0,n=e._vfcManagerList.length;t1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),r=t.call(this,null,i);var a=i.canvasElement||document.getElementById(i.canvasId);if(!(a instanceof HTMLCanvasElement))throw"Mandatory config expected: valid canvasId or canvasElement";var s=!!i.transparent,o=!!i.alphaDepthMask;return r._aabbDirty=!0,r.viewer=e,r.occlusionTestCountdown=0,r.loading=0,r.startTime=(new Date).getTime(),r.models={},r.objects={},r._numObjects=0,r.visibleObjects={},r._numVisibleObjects=0,r.xrayedObjects={},r._numXRayedObjects=0,r.highlightedObjects={},r._numHighlightedObjects=0,r.selectedObjects={},r._numSelectedObjects=0,r.colorizedObjects={},r._numColorizedObjects=0,r.opacityObjects={},r._numOpacityObjects=0,r.offsetObjects={},r._numOffsetObjects=0,r._modelIds=null,r._objectIds=null,r._visibleObjectIds=null,r._xrayedObjectIds=null,r._highlightedObjectIds=null,r._selectedObjectIds=null,r._colorizedObjectIds=null,r._opacityObjectIds=null,r._offsetObjectIds=null,r._collidables={},r._compilables={},r._needRecompile=!1,r.types={},r.components={},r.sectionPlanes={},r.lights={},r.lightMaps={},r.reflectionMaps={},r.bitmaps={},r.lineSets={},r.realWorldOffset=i.realWorldOffset||new Float64Array([0,0,0]),r.canvas=new nt(g(r),{dontClear:!0,canvas:a,spinnerElementId:i.spinnerElementId,transparent:s,webgl2:!1!==i.webgl2,contextAttr:i.contextAttr||{},backgroundColor:i.backgroundColor,backgroundColorFromAmbientLight:i.backgroundColorFromAmbientLight,premultipliedAlpha:i.premultipliedAlpha}),r.canvas.on("boundary",(function(){r.glRedraw()})),r.canvas.on("webglContextFailed",(function(){alert("xeokit failed to find WebGL!")})),r._renderer=new _t(g(r),{transparent:s,alphaDepthMask:o}),r._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1;var e=null;this.getHash=function(){if(e)return e;var t=this.sectionPlanes;if(0===t.length)return this.hash=";";for(var n=[],r=0,i=t.length;r0&&t.push("/lm"),this.reflectionMaps.length>0&&t.push("/rm"),t.push(";"),n=t.join("")},this.addLight=function(e){this.lights.push(e),r=null,n=null},this.removeLight=function(e){for(var t=0,i=this.lights.length;t1&&void 0!==arguments[1])||arguments[1];e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}},{key:"_objectXRayedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}},{key:"_objectHighlightedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null,t&&this.fire("objectHighlighted",e,!0)}},{key:"_objectSelectedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}},{key:"_objectColorizeUpdated",value:function(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}},{key:"_objectOpacityUpdated",value:function(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}},{key:"_objectOffsetUpdated",value:function(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}},{key:"_webglContextLost",value:function(){for(var e in this.canvas.spinner.processes++,this.components)if(this.components.hasOwnProperty(e)){var t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}},{key:"_webglContextRestored",value:function(){var e=this.canvas.gl;for(var t in this.components)if(this.components.hasOwnProperty(t)){var n=this.components[t];n._webglContextRestored&&n._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}},{key:"capabilities",get:function(){return this._renderer.capabilities}},{key:"entityOffsetsEnabled",get:function(){return this._entityOffsetsEnabled}},{key:"pickSurfacePrecisionEnabled",get:function(){return!1}},{key:"logarithmicDepthBufferEnabled",get:function(){return this._logarithmicDepthBufferEnabled}},{key:"pbrEnabled",get:function(){return this._pbrEnabled},set:function(e){this._pbrEnabled=!!e,this.glRedraw()}},{key:"dtxEnabled",get:function(){return this._dtxEnabled},set:function(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled},set:function(e){this._colorTextureEnabled=!!e,this.glRedraw()}},{key:"doOcclusionTest",value:function(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}},{key:"render",value:function(e){e&&Ae.runTasks();var t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),e||this._renderer.needsRender()){t.sceneId=this.id;var n,r,i=this._passes,a=this._clearEachPass;for(n=0;na&&(a=e[3]),e[4]>s&&(s=e[4]),e[5]>o&&(o=e[5]),u=!0}u||(n=-100,r=-100,i=-100,a=100,s=100,o=100),this._aabb[0]=n,this._aabb[1]=r,this._aabb[2]=i,this._aabb[3]=a,this._aabb[4]=s,this._aabb[5]=o,this._aabbDirty=!1}return this._aabb}},{key:"_setAABBDirty",value:function(){this._aabbDirty=!0,this.fire("boundary")}},{key:"pick",value:function(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");var n=e.includeEntities||e.include;n&&(e.includeEntityIds=ir(this,n));var r=e.excludeEntities||e.exclude;return r&&(e.excludeEntityIds=ir(this,r)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=this._renderer.pick(e,t))?(t.entity&&t.entity.fire&&t.entity.fire("picked",t),t):void 0}},{key:"snapPick",value:function(e){return this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapMode||"vertex")}},{key:"clear",value:function(){var e;for(var t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}},{key:"clearLights",value:function(){for(var e=Object.keys(this.lights),t=0,n=e.length;ts&&(s=t[3]),t[4]>o&&(o=t[4]),t[5]>l&&(l=t[5]),n=!0}})),n){var u=Z.AABB3();return u[0]=r,u[1]=i,u[2]=a,u[3]=s,u[4]=o,u[5]=l,u}return this.aabb}},{key:"setObjectsVisible",value:function(e,t){return this.withObjects(e,(function(e){var n=e.visible!==t;return e.visible=t,n}))}},{key:"setObjectsCollidable",value:function(e,t){return this.withObjects(e,(function(e){var n=e.collidable!==t;return e.collidable=t,n}))}},{key:"setObjectsCulled",value:function(e,t){return this.withObjects(e,(function(e){var n=e.culled!==t;return e.culled=t,n}))}},{key:"setObjectsSelected",value:function(e,t){return this.withObjects(e,(function(e){var n=e.selected!==t;return e.selected=t,n}))}},{key:"setObjectsHighlighted",value:function(e,t){return this.withObjects(e,(function(e){var n=e.highlighted!==t;return e.highlighted=t,n}))}},{key:"setObjectsXRayed",value:function(e,t){return this.withObjects(e,(function(e){var n=e.xrayed!==t;return e.xrayed=t,n}))}},{key:"setObjectsEdges",value:function(e,t){return this.withObjects(e,(function(e){var n=e.edges!==t;return e.edges=t,n}))}},{key:"setObjectsColorized",value:function(e,t){return this.withObjects(e,(function(e){e.colorize=t}))}},{key:"setObjectsOpacity",value:function(e,t){return this.withObjects(e,(function(e){var n=e.opacity!==t;return e.opacity=t,n}))}},{key:"setObjectsPickable",value:function(e,t){return this.withObjects(e,(function(e){var n=e.pickable!==t;return e.pickable=t,n}))}},{key:"setObjectsOffset",value:function(e,t){this.withObjects(e,(function(e){e.offset=t}))}},{key:"withObjects",value:function(e,t){ae.isString(e)&&(e=[e]);for(var n=!1,r=0,i=e.length;r0,l=!!i.compressGeometry,u=[];u.push("#version 300 es"),u.push("// Lambertian drawing vertex shader"),u.push("in vec3 position;"),u.push("uniform mat4 modelMatrix;"),u.push("uniform mat4 viewMatrix;"),u.push("uniform mat4 projMatrix;"),u.push("uniform vec4 colorize;"),u.push("uniform vec3 offset;"),l&&u.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(u.push("uniform float logDepthBufFC;"),u.push("out float vFragDepth;"),u.push("bool isPerspectiveMatrix(mat4 m) {"),u.push(" return (m[2][3] == - 1.0);"),u.push("}"),u.push("out float isPerspective;"));o&&u.push("out vec4 vWorldPosition;");if(u.push("uniform vec4 lightAmbient;"),u.push("uniform vec4 materialColor;"),u.push("uniform vec3 materialEmissive;"),i.normalsBuf){u.push("in vec3 normal;"),u.push("uniform mat4 modelNormalMatrix;"),u.push("uniform mat4 viewNormalMatrix;");for(var c=0,f=r.lights.length;c= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),u.push(" }"),u.push(" return normalize(v);"),u.push("}"))}u.push("out vec4 vColor;"),"points"===i.primitiveName&&u.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(u.push("void billboard(inout mat4 mat) {"),u.push(" mat[0][0] = 1.0;"),u.push(" mat[0][1] = 0.0;"),u.push(" mat[0][2] = 0.0;"),"spherical"===a&&(u.push(" mat[1][0] = 0.0;"),u.push(" mat[1][1] = 1.0;"),u.push(" mat[1][2] = 0.0;")),u.push(" mat[2][0] = 0.0;"),u.push(" mat[2][1] = 0.0;"),u.push(" mat[2][2] =1.0;"),u.push("}"));u.push("void main(void) {"),u.push("vec4 localPosition = vec4(position, 1.0); "),u.push("vec4 worldPosition;"),l&&u.push("localPosition = positionsDecodeMatrix * localPosition;");i.normalsBuf&&(l?u.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):u.push("vec4 localNormal = vec4(normal, 0.0); "),u.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),u.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));u.push("mat4 viewMatrix2 = viewMatrix;"),u.push("mat4 modelMatrix2 = modelMatrix;"),s&&u.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===a||"cylindrical"===a?(u.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),u.push("billboard(modelMatrix2);"),u.push("billboard(viewMatrix2);"),u.push("billboard(modelViewMatrix);"),i.normalsBuf&&(u.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),u.push("billboard(modelNormalMatrix2);"),u.push("billboard(viewNormalMatrix2);"),u.push("billboard(modelViewNormalMatrix);")),u.push("worldPosition = modelMatrix2 * localPosition;"),u.push("worldPosition.xyz = worldPosition.xyz + offset;"),u.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(u.push("worldPosition = modelMatrix2 * localPosition;"),u.push("worldPosition.xyz = worldPosition.xyz + offset;"),u.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i.normalsBuf&&u.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(u.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),u.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),u.push("float lambertian = 1.0;"),i.normalsBuf)for(var A=0,d=r.lights.length;A0,a=t.gammaOutput,s=[];s.push("#version 300 es"),s.push("// Lambertian drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"));if(i){s.push("in vec4 vWorldPosition;"),s.push("uniform bool clippable;");for(var o=0,l=n.sectionPlanes.length;o 0.0) { discard; }"),s.push("}")}"points"===r.primitiveName&&(s.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),s.push("float r = dot(cxy, cxy);"),s.push("if (r > 1.0) {"),s.push(" discard;"),s.push("}"));t.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");a?s.push("outColor = linearToGamma(vColor, gammaFactor);"):s.push("outColor = vColor;");return s.push("}"),s}(e)):(this.vertex=function(e){var t=e.scene;e._material;var n,r=e._state,i=t._sectionPlanesState,a=e._geometry._state,s=t._lightsState,o=r.billboard,l=r.background,u=r.stationary,c=function(e){if(!e._geometry._state.uvBuf)return!1;var t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),f=Ei(e),p=i.sectionPlanes.length>0,A=Ti(e),d=!!a.compressGeometry,v=[];v.push("#version 300 es"),v.push("// Drawing vertex shader"),v.push("in vec3 position;"),d&&v.push("uniform mat4 positionsDecodeMatrix;");v.push("uniform mat4 modelMatrix;"),v.push("uniform mat4 viewMatrix;"),v.push("uniform mat4 projMatrix;"),v.push("out vec3 vViewPosition;"),v.push("uniform vec3 offset;"),p&&v.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(v.push("uniform float logDepthBufFC;"),v.push("out float vFragDepth;"),v.push("bool isPerspectiveMatrix(mat4 m) {"),v.push(" return (m[2][3] == - 1.0);"),v.push("}"),v.push("out float isPerspective;"));s.lightMaps.length>0&&v.push("out vec3 vWorldNormal;");if(f){v.push("in vec3 normal;"),v.push("uniform mat4 modelNormalMatrix;"),v.push("uniform mat4 viewNormalMatrix;"),v.push("out vec3 vViewNormal;");for(var h=0,I=s.lights.length;h= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),v.push(" }"),v.push(" return normalize(v);"),v.push("}"))}c&&(v.push("in vec2 uv;"),v.push("out vec2 vUV;"),d&&v.push("uniform mat3 uvDecodeMatrix;"));a.colors&&(v.push("in vec4 color;"),v.push("out vec4 vColor;"));"points"===a.primitiveName&&v.push("uniform float pointSize;");"spherical"!==o&&"cylindrical"!==o||(v.push("void billboard(inout mat4 mat) {"),v.push(" mat[0][0] = 1.0;"),v.push(" mat[0][1] = 0.0;"),v.push(" mat[0][2] = 0.0;"),"spherical"===o&&(v.push(" mat[1][0] = 0.0;"),v.push(" mat[1][1] = 1.0;"),v.push(" mat[1][2] = 0.0;")),v.push(" mat[2][0] = 0.0;"),v.push(" mat[2][1] = 0.0;"),v.push(" mat[2][2] =1.0;"),v.push("}"));if(A){v.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(var y=0,m=s.lights.length;y0&&v.push("vWorldNormal = worldNormal;"),v.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),v.push("vec3 tmpVec3;"),v.push("float lightDist;");for(var w=0,g=s.lights.length;w0,l=Ei(e),u=r.uvBuf,c="PhongMaterial"===s.type,f="MetallicMaterial"===s.type,p="SpecularMaterial"===s.type,A=Ti(e);t.gammaInput;var d=t.gammaOutput,v=[];v.push("#version 300 es"),v.push("// Drawing fragment shader"),v.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),v.push("precision highp float;"),v.push("precision highp int;"),v.push("#else"),v.push("precision mediump float;"),v.push("precision mediump int;"),v.push("#endif"),t.logarithmicDepthBufferEnabled&&(v.push("in float isPerspective;"),v.push("uniform float logDepthBufFC;"),v.push("in float vFragDepth;"));A&&(v.push("float unpackDepth (vec4 color) {"),v.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),v.push(" return dot(color, bitShift);"),v.push("}"));v.push("uniform float gammaFactor;"),v.push("vec4 linearToLinear( in vec4 value ) {"),v.push(" return value;"),v.push("}"),v.push("vec4 sRGBToLinear( in vec4 value ) {"),v.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),v.push("}"),v.push("vec4 gammaToLinear( in vec4 value) {"),v.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),v.push("}"),d&&(v.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),v.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),v.push("}"));if(o){v.push("in vec4 vWorldPosition;"),v.push("uniform bool clippable;");for(var h=0;h0&&(v.push("uniform samplerCube lightMap;"),v.push("uniform mat4 viewNormalMatrix;")),a.reflectionMaps.length>0&&v.push("uniform samplerCube reflectionMap;"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&v.push("uniform mat4 viewMatrix;"),v.push("#define PI 3.14159265359"),v.push("#define RECIPROCAL_PI 0.31830988618"),v.push("#define RECIPROCAL_PI2 0.15915494"),v.push("#define EPSILON 1e-6"),v.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),v.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),v.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),v.push("}"),v.push("struct IncidentLight {"),v.push(" vec3 color;"),v.push(" vec3 direction;"),v.push("};"),v.push("struct ReflectedLight {"),v.push(" vec3 diffuse;"),v.push(" vec3 specular;"),v.push("};"),v.push("struct Geometry {"),v.push(" vec3 position;"),v.push(" vec3 viewNormal;"),v.push(" vec3 worldNormal;"),v.push(" vec3 viewEyeDir;"),v.push("};"),v.push("struct Material {"),v.push(" vec3 diffuseColor;"),v.push(" float specularRoughness;"),v.push(" vec3 specularColor;"),v.push(" float shine;"),v.push("};"),c&&((a.lightMaps.length>0||a.reflectionMaps.length>0)&&(v.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(v.push(" vec3 irradiance = "+gi[a.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),v.push(" irradiance *= PI;"),v.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(v.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),v.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),v.push(" radiance *= PI;"),v.push(" reflectedLight.specular += radiance;")),v.push("}")),v.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),v.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),v.push(" vec3 irradiance = dotNL * directLight.color * PI;"),v.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),v.push("}")),(f||p)&&(v.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),v.push(" float r = ggxRoughness + 0.0001;"),v.push(" return (2.0 / (r * r) - 2.0);"),v.push("}"),v.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),v.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),v.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),v.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),v.push("}"),a.reflectionMaps.length>0&&(v.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),v.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),v.push(" vec3 envMapColor = "+gi[a.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),v.push(" return envMapColor;"),v.push("}")),v.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),v.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),v.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),v.push("}"),v.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),v.push(" float a2 = ( alpha * alpha );"),v.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),v.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),v.push(" return 1.0 / ( gl * gv );"),v.push("}"),v.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),v.push(" float a2 = ( alpha * alpha );"),v.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),v.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),v.push(" return 0.5 / max( gv + gl, EPSILON );"),v.push("}"),v.push("float D_GGX(const in float alpha, const in float dotNH) {"),v.push(" float a2 = ( alpha * alpha );"),v.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),v.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),v.push("}"),v.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),v.push(" float alpha = ( roughness * roughness );"),v.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),v.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),v.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),v.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),v.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),v.push(" vec3 F = F_Schlick( specularColor, dotLH );"),v.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),v.push(" float D = D_GGX( alpha, dotNH );"),v.push(" return F * (G * D);"),v.push("}"),v.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),v.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),v.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),v.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),v.push(" vec4 r = roughness * c0 + c1;"),v.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),v.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),v.push(" return specularColor * AB.x + AB.y;"),v.push("}"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&(v.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(v.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),v.push(" irradiance *= PI;"),v.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(v.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),v.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),v.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),v.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),v.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),v.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),v.push("}")),v.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),v.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),v.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),v.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),v.push("}")));v.push("in vec3 vViewPosition;"),r.colors&&v.push("in vec4 vColor;");u&&(l&&n._normalMap||n._ambientMap||n._baseColorMap||n._diffuseMap||n._emissiveMap||n._metallicMap||n._roughnessMap||n._metallicRoughnessMap||n._specularMap||n._glossinessMap||n._specularGlossinessMap||n._occlusionMap||n._alphaMap)&&v.push("in vec2 vUV;");l&&(a.lightMaps.length>0&&v.push("in vec3 vWorldNormal;"),v.push("in vec3 vViewNormal;"));s.ambient&&v.push("uniform vec3 materialAmbient;");s.baseColor&&v.push("uniform vec3 materialBaseColor;");void 0!==s.alpha&&null!==s.alpha&&v.push("uniform vec4 materialAlphaModeCutoff;");s.emissive&&v.push("uniform vec3 materialEmissive;");s.diffuse&&v.push("uniform vec3 materialDiffuse;");void 0!==s.glossiness&&null!==s.glossiness&&v.push("uniform float materialGlossiness;");void 0!==s.shininess&&null!==s.shininess&&v.push("uniform float materialShininess;");s.specular&&v.push("uniform vec3 materialSpecular;");void 0!==s.metallic&&null!==s.metallic&&v.push("uniform float materialMetallic;");void 0!==s.roughness&&null!==s.roughness&&v.push("uniform float materialRoughness;");void 0!==s.specularF0&&null!==s.specularF0&&v.push("uniform float materialSpecularF0;");u&&n._ambientMap&&(v.push("uniform sampler2D ambientMap;"),n._ambientMap._state.matrix&&v.push("uniform mat4 ambientMapMatrix;"));u&&n._baseColorMap&&(v.push("uniform sampler2D baseColorMap;"),n._baseColorMap._state.matrix&&v.push("uniform mat4 baseColorMapMatrix;"));u&&n._diffuseMap&&(v.push("uniform sampler2D diffuseMap;"),n._diffuseMap._state.matrix&&v.push("uniform mat4 diffuseMapMatrix;"));u&&n._emissiveMap&&(v.push("uniform sampler2D emissiveMap;"),n._emissiveMap._state.matrix&&v.push("uniform mat4 emissiveMapMatrix;"));l&&u&&n._metallicMap&&(v.push("uniform sampler2D metallicMap;"),n._metallicMap._state.matrix&&v.push("uniform mat4 metallicMapMatrix;"));l&&u&&n._roughnessMap&&(v.push("uniform sampler2D roughnessMap;"),n._roughnessMap._state.matrix&&v.push("uniform mat4 roughnessMapMatrix;"));l&&u&&n._metallicRoughnessMap&&(v.push("uniform sampler2D metallicRoughnessMap;"),n._metallicRoughnessMap._state.matrix&&v.push("uniform mat4 metallicRoughnessMapMatrix;"));l&&n._normalMap&&(v.push("uniform sampler2D normalMap;"),n._normalMap._state.matrix&&v.push("uniform mat4 normalMapMatrix;"),v.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),v.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),v.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),v.push(" vec2 st0 = dFdx( uv.st );"),v.push(" vec2 st1 = dFdy( uv.st );"),v.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),v.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),v.push(" vec3 N = normalize( surf_norm );"),v.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),v.push(" mat3 tsn = mat3( S, T, N );"),v.push(" return normalize( tsn * mapN );"),v.push("}"));u&&n._occlusionMap&&(v.push("uniform sampler2D occlusionMap;"),n._occlusionMap._state.matrix&&v.push("uniform mat4 occlusionMapMatrix;"));u&&n._alphaMap&&(v.push("uniform sampler2D alphaMap;"),n._alphaMap._state.matrix&&v.push("uniform mat4 alphaMapMatrix;"));l&&u&&n._specularMap&&(v.push("uniform sampler2D specularMap;"),n._specularMap._state.matrix&&v.push("uniform mat4 specularMapMatrix;"));l&&u&&n._glossinessMap&&(v.push("uniform sampler2D glossinessMap;"),n._glossinessMap._state.matrix&&v.push("uniform mat4 glossinessMapMatrix;"));l&&u&&n._specularGlossinessMap&&(v.push("uniform sampler2D materialSpecularGlossinessMap;"),n._specularGlossinessMap._state.matrix&&v.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));l&&(n._diffuseFresnel||n._specularFresnel||n._alphaFresnel||n._emissiveFresnel||n._reflectivityFresnel)&&(v.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),v.push(" float fr = abs(dot(eyeDir, normal));"),v.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),v.push(" return pow(finalFr, power);"),v.push("}"),n._diffuseFresnel&&(v.push("uniform float diffuseFresnelCenterBias;"),v.push("uniform float diffuseFresnelEdgeBias;"),v.push("uniform float diffuseFresnelPower;"),v.push("uniform vec3 diffuseFresnelCenterColor;"),v.push("uniform vec3 diffuseFresnelEdgeColor;")),n._specularFresnel&&(v.push("uniform float specularFresnelCenterBias;"),v.push("uniform float specularFresnelEdgeBias;"),v.push("uniform float specularFresnelPower;"),v.push("uniform vec3 specularFresnelCenterColor;"),v.push("uniform vec3 specularFresnelEdgeColor;")),n._alphaFresnel&&(v.push("uniform float alphaFresnelCenterBias;"),v.push("uniform float alphaFresnelEdgeBias;"),v.push("uniform float alphaFresnelPower;"),v.push("uniform vec3 alphaFresnelCenterColor;"),v.push("uniform vec3 alphaFresnelEdgeColor;")),n._reflectivityFresnel&&(v.push("uniform float materialSpecularF0FresnelCenterBias;"),v.push("uniform float materialSpecularF0FresnelEdgeBias;"),v.push("uniform float materialSpecularF0FresnelPower;"),v.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),v.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),n._emissiveFresnel&&(v.push("uniform float emissiveFresnelCenterBias;"),v.push("uniform float emissiveFresnelEdgeBias;"),v.push("uniform float emissiveFresnelPower;"),v.push("uniform vec3 emissiveFresnelCenterColor;"),v.push("uniform vec3 emissiveFresnelEdgeColor;")));if(v.push("uniform vec4 lightAmbient;"),l)for(var I=0,y=a.lights.length;I 0.0) { discard; }"),v.push("}")}"points"===r.primitiveName&&(v.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),v.push("float r = dot(cxy, cxy);"),v.push("if (r > 1.0) {"),v.push(" discard;"),v.push("}"));v.push("float occlusion = 1.0;"),s.ambient?v.push("vec3 ambientColor = materialAmbient;"):v.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");s.diffuse?v.push("vec3 diffuseColor = materialDiffuse;"):s.baseColor?v.push("vec3 diffuseColor = materialBaseColor;"):v.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");r.colors&&v.push("diffuseColor *= vColor.rgb;");s.emissive?v.push("vec3 emissiveColor = materialEmissive;"):v.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");s.specular?v.push("vec3 specular = materialSpecular;"):v.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==s.alpha?v.push("float alpha = materialAlphaModeCutoff[0];"):v.push("float alpha = 1.0;");r.colors&&v.push("alpha *= vColor.a;");void 0!==s.glossiness?v.push("float glossiness = materialGlossiness;"):v.push("float glossiness = 1.0;");void 0!==s.metallic?v.push("float metallic = materialMetallic;"):v.push("float metallic = 1.0;");void 0!==s.roughness?v.push("float roughness = materialRoughness;"):v.push("float roughness = 1.0;");void 0!==s.specularF0?v.push("float specularF0 = materialSpecularF0;"):v.push("float specularF0 = 1.0;");u&&(l&&n._normalMap||n._ambientMap||n._baseColorMap||n._diffuseMap||n._occlusionMap||n._emissiveMap||n._metallicMap||n._roughnessMap||n._metallicRoughnessMap||n._specularMap||n._glossinessMap||n._specularGlossinessMap||n._alphaMap)&&(v.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),v.push("vec2 textureCoord;"));u&&n._ambientMap&&(n._ambientMap._state.matrix?v.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),v.push("ambientTexel = "+gi[n._ambientMap._state.encoding]+"(ambientTexel);"),v.push("ambientColor *= ambientTexel.rgb;"));u&&n._diffuseMap&&(n._diffuseMap._state.matrix?v.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),v.push("diffuseTexel = "+gi[n._diffuseMap._state.encoding]+"(diffuseTexel);"),v.push("diffuseColor *= diffuseTexel.rgb;"),v.push("alpha *= diffuseTexel.a;"));u&&n._baseColorMap&&(n._baseColorMap._state.matrix?v.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),v.push("baseColorTexel = "+gi[n._baseColorMap._state.encoding]+"(baseColorTexel);"),v.push("diffuseColor *= baseColorTexel.rgb;"),v.push("alpha *= baseColorTexel.a;"));u&&n._emissiveMap&&(n._emissiveMap._state.matrix?v.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),v.push("emissiveTexel = "+gi[n._emissiveMap._state.encoding]+"(emissiveTexel);"),v.push("emissiveColor = emissiveTexel.rgb;"));u&&n._alphaMap&&(n._alphaMap._state.matrix?v.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("alpha *= texture(alphaMap, textureCoord).r;"));u&&n._occlusionMap&&(n._occlusionMap._state.matrix?v.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(l&&(a.lights.length>0||a.lightMaps.length>0||a.reflectionMaps.length>0)){u&&n._normalMap?(n._normalMap._state.matrix?v.push("textureCoord = (normalMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):v.push("vec3 viewNormal = normalize(vViewNormal);"),u&&n._specularMap&&(n._specularMap._state.matrix?v.push("textureCoord = (specularMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("specular *= texture(specularMap, textureCoord).rgb;")),u&&n._glossinessMap&&(n._glossinessMap._state.matrix?v.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("glossiness *= texture(glossinessMap, textureCoord).r;")),u&&n._specularGlossinessMap&&(n._specularGlossinessMap._state.matrix?v.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),v.push("specular *= specGlossRGB.rgb;"),v.push("glossiness *= specGlossRGB.a;")),u&&n._metallicMap&&(n._metallicMap._state.matrix?v.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("metallic *= texture(metallicMap, textureCoord).r;")),u&&n._roughnessMap&&(n._roughnessMap._state.matrix?v.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("roughness *= texture(roughnessMap, textureCoord).r;")),u&&n._metallicRoughnessMap&&(n._metallicRoughnessMap._state.matrix?v.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),v.push("metallic *= metalRoughRGB.b;"),v.push("roughness *= metalRoughRGB.g;")),v.push("vec3 viewEyeDir = normalize(-vViewPosition);"),n._diffuseFresnel&&(v.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),v.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),n._specularFresnel&&(v.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),v.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),n._alphaFresnel&&(v.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),v.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),n._emissiveFresnel&&(v.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),v.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),v.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),v.push(" discard;"),v.push("}"),v.push("IncidentLight light;"),v.push("Material material;"),v.push("Geometry geometry;"),v.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),v.push("vec3 viewLightDir;"),c&&(v.push("material.diffuseColor = diffuseColor;"),v.push("material.specularColor = specular;"),v.push("material.shine = materialShininess;")),p&&(v.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),v.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),v.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),v.push("material.specularColor = specular;")),f&&(v.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),v.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),v.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),v.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),v.push("geometry.position = vViewPosition;"),a.lightMaps.length>0&&v.push("geometry.worldNormal = normalize(vWorldNormal);"),v.push("geometry.viewNormal = viewNormal;"),v.push("geometry.viewEyeDir = viewEyeDir;"),c&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&v.push("computePhongLightMapping(geometry, material, reflectedLight);"),(p||f)&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&v.push("computePBRLightMapping(geometry, material, reflectedLight);"),v.push("float shadow = 1.0;"),v.push("float shadowAcneRemover = 0.007;"),v.push("vec3 fragmentDepth;"),v.push("float texelSize = 1.0 / 1024.0;"),v.push("float amountInLight = 0.0;"),v.push("vec3 shadowCoord;"),v.push("vec4 rgbaDepth;"),v.push("float depth;");for(var T=0,E=a.lights.length;T0)for(var d=r._sectionPlanesState.sectionPlanes,v=t.renderFlags,h=0;h0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(c=0,f=a.sectionPlanes.length;c0&&a.lightMaps[0].texture&&this._uLightMap&&(o.bindTexture(this._uLightMap,a.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++),a.reflectionMaps.length>0&&a.reflectionMaps[0].texture&&this._uReflectionMap&&(o.bindTexture(this._uReflectionMap,a.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++),this._uGammaFactor&&i.uniform1f(this._uGammaFactor,r.gammaFactor),this._baseTextureUnit=e.textureUnit};var Ci=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene,n=t._lightsState,r=function(e){var t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),i=t._sectionPlanesState.sectionPlanes.length>0,a=!!e._geometry._state.compressGeometry,s=e._state.billboard,o=e._state.stationary,l=[];l.push("#version 300 es"),l.push("// EmphasisFillShaderSource vertex shader"),l.push("in vec3 position;"),l.push("uniform mat4 modelMatrix;"),l.push("uniform mat4 viewMatrix;"),l.push("uniform mat4 projMatrix;"),l.push("uniform vec4 colorize;"),l.push("uniform vec3 offset;"),a&&l.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;"));i&&l.push("out vec4 vWorldPosition;");if(l.push("uniform vec4 lightAmbient;"),l.push("uniform vec4 fillColor;"),r){l.push("in vec3 normal;"),l.push("uniform mat4 modelNormalMatrix;"),l.push("uniform mat4 viewNormalMatrix;");for(var u=0,c=n.lights.length;u= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"))}l.push("out vec4 vColor;"),("spherical"===s||"cylindrical"===s)&&(l.push("void billboard(inout mat4 mat) {"),l.push(" mat[0][0] = 1.0;"),l.push(" mat[0][1] = 0.0;"),l.push(" mat[0][2] = 0.0;"),"spherical"===s&&(l.push(" mat[1][0] = 0.0;"),l.push(" mat[1][1] = 1.0;"),l.push(" mat[1][2] = 0.0;")),l.push(" mat[2][0] = 0.0;"),l.push(" mat[2][1] = 0.0;"),l.push(" mat[2][2] =1.0;"),l.push("}"));l.push("void main(void) {"),l.push("vec4 localPosition = vec4(position, 1.0); "),l.push("vec4 worldPosition;"),a&&l.push("localPosition = positionsDecodeMatrix * localPosition;");r&&(a?l.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):l.push("vec4 localNormal = vec4(normal, 0.0); "),l.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),l.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));l.push("mat4 viewMatrix2 = viewMatrix;"),l.push("mat4 modelMatrix2 = modelMatrix;"),o&&l.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===s||"cylindrical"===s?(l.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),l.push("billboard(modelMatrix2);"),l.push("billboard(viewMatrix2);"),l.push("billboard(modelViewMatrix);"),r&&(l.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),l.push("billboard(modelNormalMatrix2);"),l.push("billboard(viewNormalMatrix2);"),l.push("billboard(modelViewNormalMatrix);")),l.push("worldPosition = modelMatrix2 * localPosition;"),l.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(l.push("worldPosition = modelMatrix2 * localPosition;"),l.push("worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r&&l.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),r)for(var p=0,A=n.lights.length;p0,a=[];a.push("#version 300 es"),a.push("// Lambertian drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));r&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(var s=0,o=n.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}"points"===e._geometry._state.primitiveName&&(a.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),a.push("float r = dot(cxy, cxy);"),a.push("if (r > 1.0) {"),a.push(" discard;"),a.push("}"));t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");r?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(t)}));var _i=new G({}),Bi=Z.vec3(),Oi=function(e,t){this.id=_i.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Ci(t),this._allocate(t)},Si={};Oi.get=function(e){var t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),n=Si[t];return n||(n=new Oi(t,e),Si[t]=n,ee.memory.programs++),n._useCount++,n},Oi.prototype.put=function(){0==--this._useCount&&(_i.removeItem(this.id),this._program&&this._program.destroy(),delete Si[this._hash],ee.memory.programs--)},Oi.prototype.webglContextRestored=function(){this._program=null},Oi.prototype.drawMesh=function(e,t,n){this._program||this._allocate(t);var r=this._scene,i=r.camera,a=r.canvas.gl,s=0===n?t._xrayMaterial._state:1===n?t._highlightMaterial._state:t._selectedMaterial._state,o=t._state,l=t._geometry._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(o.originHash,u):i.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.viewNormalMatrix),o.clippable){var c=r._sectionPlanesState.sectionPlanes.length;if(c>0)for(var f=r._sectionPlanesState.sectionPlanes,p=t.renderFlags,A=0;A0,r=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,s=[];s.push("#version 300 es"),s.push("// Edges drawing vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform vec4 edgeColor;"),s.push("uniform vec3 offset;"),r&&s.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"));n&&s.push("out vec4 vWorldPosition;");s.push("out vec4 vColor;"),("spherical"===i||"cylindrical"===i)&&(s.push("void billboard(inout mat4 mat) {"),s.push(" mat[0][0] = 1.0;"),s.push(" mat[0][1] = 0.0;"),s.push(" mat[0][2] = 0.0;"),"spherical"===i&&(s.push(" mat[1][0] = 0.0;"),s.push(" mat[1][1] = 1.0;"),s.push(" mat[1][2] = 0.0;")),s.push(" mat[2][0] = 0.0;"),s.push(" mat[2][1] = 0.0;"),s.push(" mat[2][2] =1.0;"),s.push("}"));s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),s.push("vec4 worldPosition;"),r&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("mat4 viewMatrix2 = viewMatrix;"),s.push("mat4 modelMatrix2 = modelMatrix;"),a&&s.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(s.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),s.push("billboard(modelMatrix2);"),s.push("billboard(viewMatrix2);"),s.push("billboard(modelViewMatrix);"),s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s.push("vColor = edgeColor;"),n&&s.push("vWorldPosition = worldPosition;");s.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return s.push("gl_Position = clipPos;"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene,n=e.scene._sectionPlanesState,r=e.scene.gammaOutput,i=n.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Edges drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));r&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(var s=0,o=n.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");r?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(t)}));var Li=new G({}),xi=Z.vec3(),Mi=function(e,t){this.id=Li.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Ni(t),this._allocate(t)},Fi={};Mi.get=function(e){var t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),n=Fi[t];return n||(n=new Mi(t,e),Fi[t]=n,ee.memory.programs++),n._useCount++,n},Mi.prototype.put=function(){0==--this._useCount&&(Li.removeItem(this.id),this._program&&this._program.destroy(),delete Fi[this._hash],ee.memory.programs--)},Mi.prototype.webglContextRestored=function(){this._program=null},Mi.prototype.drawMesh=function(e,t,n){this._program||this._allocate(t);var r,i,a=this._scene,s=a.camera,o=a.canvas.gl,l=t._state,u=t._geometry,c=u._state,f=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),o.uniformMatrix4fv(this._uViewMatrix,!1,f?e.getRTCViewMatrix(l.originHash,f):s.viewMatrix),l.clippable){var p=a._sectionPlanesState.sectionPlanes.length;if(p>0)for(var A=a._sectionPlanesState.sectionPlanes,d=t.renderFlags,v=0;v0,r=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,s=[];s.push("#version 300 es"),s.push("// Mesh picking vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("out vec4 vViewPosition;"),s.push("uniform vec3 offset;"),r&&s.push("uniform mat4 positionsDecodeMatrix;");n&&s.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(s.push("void billboard(inout mat4 mat) {"),s.push(" mat[0][0] = 1.0;"),s.push(" mat[0][1] = 0.0;"),s.push(" mat[0][2] = 0.0;"),"spherical"===i&&(s.push(" mat[1][0] = 0.0;"),s.push(" mat[1][1] = 1.0;"),s.push(" mat[1][2] = 0.0;")),s.push(" mat[2][0] = 0.0;"),s.push(" mat[2][1] = 0.0;"),s.push(" mat[2][2] =1.0;"),s.push("}"));s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),r&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("mat4 viewMatrix2 = viewMatrix;"),s.push("mat4 modelMatrix2 = modelMatrix;"),a&&s.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==i&&"cylindrical"!==i||(s.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),s.push("billboard(modelMatrix2);"),s.push("billboard(viewMatrix2);"));s.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),n&&s.push(" vWorldPosition = worldPosition;");s.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return s.push("gl_Position = clipPos;"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(i.push("uniform vec4 pickColor;"),r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = pickColor; "),i.push("}"),i}(t)}));var Ui=Z.vec3(),Gi=function(e,t){this._hash=e,this._shaderSource=new Hi(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},ki={};Gi.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";"),n=ki[t];if(!n){if((n=new Gi(t,e)).errors)return console.log(n.errors.join("\n")),null;ki[t]=n,ee.memory.programs++}return n._useCount++,n},Gi.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete ki[this._hash],ee.memory.programs--)},Gi.prototype.webglContextRestored=function(){this._program=null},Gi.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene,r=n.canvas.gl,i=t._state,a=t._material._state,s=t._geometry._state,o=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),r.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCPickViewMatrix(i.originHash,o):e.pickViewMatrix),i.clippable){var l=n._sectionPlanesState.sectionPlanes.length;if(l>0)for(var u=n._sectionPlanesState.sectionPlanes,c=t.renderFlags,f=0;f>24&255,m=I>>16&255,w=I>>8&255,g=255&I;r.uniform4f(this._uPickColor,g/255,w/255,m/255,y/255),s.indicesBuf?(r.drawElements(s.primitive,s.indicesBuf.numItems,s.indicesBuf.itemType,0),e.drawElements++):s.positions&&r.drawArrays(r.TRIANGLES,0,s.positions.numItems)},Gi.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl;if(this._program=new ft(n,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uPositionsDecodeMatrix=r.getLocation("positionsDecodeMatrix"),this._uModelMatrix=r.getLocation("modelMatrix"),this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var i=0,a=t._sectionPlanesState.sectionPlanes.length;i0,r=!!e._geometry._state.compressGeometry;e._state.billboard,e._state.stationary;var i=[];i.push("#version 300 es"),i.push("// Surface picking vertex shader"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform vec3 offset;"),n&&(i.push("uniform bool clippable;"),i.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"));i.push("out vec4 vColor;"),r&&i.push("uniform mat4 positionsDecodeMatrix;");i.push("void main(void) {"),i.push("vec4 localPosition = vec4(position, 1.0); "),r&&i.push("localPosition = positionsDecodeMatrix * localPosition;");i.push(" vec4 worldPosition = modelMatrix * localPosition; "),i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),n&&i.push(" vWorldPosition = worldPosition;");i.push(" vColor = color;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return i.push("gl_Position = clipPos;"),i.push("}"),i}(t),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Surface picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = vColor;"),i.push("}"),i}(t)}));var ji=Z.vec3(),Qi=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Vi(t),this._allocate(t)},Wi={};Qi.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),n=Wi[t];if(!n){if((n=new Qi(t,e)).errors)return console.log(n.errors.join("\n")),null;Wi[t]=n,ee.memory.programs++}return n._useCount++,n},Qi.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Wi[this._hash],ee.memory.programs--)},Qi.prototype.webglContextRestored=function(){this._program=null},Qi.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene,r=n.canvas.gl,i=t._state,a=t._material._state,s=t._geometry,o=t._geometry._state,l=t.origin,u=a.backfaces,c=a.frontface,f=n.camera.project,p=s._getPickTrianglePositions(),A=s._getPickTriangleColors();if(this._program.bind(),e.useProgram++,n.logarithmicDepthBufferEnabled){var d=2/(Math.log(f.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,d)}if(r.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(i.originHash,l):e.pickViewMatrix),i.clippable){var v=n._sectionPlanesState.sectionPlanes.length;if(v>0)for(var h=n._sectionPlanesState.sectionPlanes,I=t.renderFlags,y=0;y0,r=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,s=[];s.push("#version 300 es"),s.push("// Mesh occlusion vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform vec3 offset;"),r&&s.push("uniform mat4 positionsDecodeMatrix;");n&&s.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(s.push("void billboard(inout mat4 mat) {"),s.push(" mat[0][0] = 1.0;"),s.push(" mat[0][1] = 0.0;"),s.push(" mat[0][2] = 0.0;"),"spherical"===i&&(s.push(" mat[1][0] = 0.0;"),s.push(" mat[1][1] = 1.0;"),s.push(" mat[1][2] = 0.0;")),s.push(" mat[2][0] = 0.0;"),s.push(" mat[2][1] = 0.0;"),s.push(" mat[2][2] =1.0;"),s.push("}"));s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),s.push("vec4 worldPosition;"),r&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("mat4 viewMatrix2 = viewMatrix;"),s.push("mat4 modelMatrix2 = modelMatrix;"),a&&s.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(s.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),s.push("billboard(modelMatrix2);"),s.push("billboard(viewMatrix2);"),s.push("billboard(modelViewMatrix);"),s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));n&&s.push(" vWorldPosition = worldPosition;");s.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return s.push("gl_Position = clipPos;"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push("}"),i}(t)}));var Ki=Z.vec3(),Yi=function(e,t){this._hash=e,this._shaderSource=new zi(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Xi={};Yi.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";"),n=Xi[t];if(!n){if((n=new Yi(t,e)).errors)return console.log(n.errors.join("\n")),null;Xi[t]=n,ee.memory.programs++}return n._useCount++,n},Yi.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Xi[this._hash],ee.memory.programs--)},Yi.prototype.webglContextRestored=function(){this._program=null},Yi.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene,r=n.canvas.gl,i=t._material._state,a=t._state,s=t._geometry._state,o=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),i.id!==this._lastMaterialId){var l=i.backfaces;e.backfaces!==l&&(l?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),e.backfaces=l);var u=i.frontface;e.frontface!==u&&(u?r.frontFace(r.CCW):r.frontFace(r.CW),e.frontface=u),this._lastMaterialId=i.id}var c=n.camera;if(r.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCViewMatrix(a.originHash,o):c.viewMatrix),a.clippable){var f=n._sectionPlanesState.sectionPlanes.length;if(f>0)for(var p=n._sectionPlanesState.sectionPlanes,A=t.renderFlags,d=0;d0,n=!!e._geometry._state.compressGeometry,r=[];r.push("// Mesh shadow vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 shadowViewMatrix;"),r.push("uniform mat4 shadowProjMatrix;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");t&&r.push("out vec4 vWorldPosition;");r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("worldPosition = modelMatrix * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&r.push("vWorldPosition = worldPosition;");return r.push(" gl_Position = shadowProjMatrix * viewPosition;"),r.push("}"),r}(t),this.fragment=function(e){var t=e.scene;t.canvas.gl;var n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];if(i.push("// Mesh shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}return i.push("outColor = encodeFloat(gl_FragCoord.z);"),i.push("}"),i}(t)}));var Ji=function(e,t){this._hash=e,this._shaderSource=new qi(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Zi={};Ji.get=function(e){var t=e.scene,n=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";"),r=Zi[n];if(!r){if((r=new Ji(n,e)).errors)return console.log(r.errors.join("\n")),null;Zi[n]=r,ee.memory.programs++}return r._useCount++,r},Ji.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Zi[this._hash],ee.memory.programs--)},Ji.prototype.webglContextRestored=function(){this._program=null},Ji.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene.canvas.gl,r=t._material._state,i=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),r.id!==this._lastMaterialId){var a=r.backfaces;e.backfaces!==a&&(a?n.disable(n.CULL_FACE):n.enable(n.CULL_FACE),e.backfaces=a);var s=r.frontface;e.frontface!==s&&(s?n.frontFace(n.CCW):n.frontFace(n.CW),e.frontface=s),e.lineWidth!==r.lineWidth&&(n.lineWidth(r.lineWidth),e.lineWidth=r.lineWidth),this._uPointSize&&n.uniform1i(this._uPointSize,r.pointSize),this._lastMaterialId=r.id}if(n.uniformMatrix4fv(this._uModelMatrix,n.FALSE,t.worldMatrix),i.combineGeometry){var o=t.vertexBufs;o.id!==this._lastVertexBufsId&&(o.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(o.positionsBuf,o.compressGeometry?n.UNSIGNED_SHORT:n.FLOAT),e.bindArray++),this._lastVertexBufsId=o.id)}this._uClippable&&n.uniform1i(this._uClippable,t._state.clippable),n.uniform3fv(this._uOffset,t._state.offset),i.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&n.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,i.positionsDecodeMatrix),i.combineGeometry?i.indicesBufCombined&&(i.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(i.positionsBuf,i.compressGeometry?n.UNSIGNED_SHORT:n.FLOAT),e.bindArray++),i.indicesBuf&&(i.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=i.id),i.combineGeometry?i.indicesBufCombined&&(n.drawElements(i.primitive,i.indicesBufCombined.numItems,i.indicesBufCombined.itemType,0),e.drawElements++):i.indicesBuf?(n.drawElements(i.primitive,i.indicesBuf.numItems,i.indicesBuf.itemType,0),e.drawElements++):i.positions&&(n.drawArrays(n.TRIANGLES,0,i.positions.numItems),e.drawArrays++)},Ji.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl;if(this._program=new ft(n,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uPositionsDecodeMatrix=r.getLocation("positionsDecodeMatrix"),this._uModelMatrix=r.getLocation("modelMatrix"),this._uShadowViewMatrix=r.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=r.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(var i=0,a=t._sectionPlanesState.sectionPlanes.length;i0)for(var i,a,s,o=0,l=this._uSectionPlanes.length;o1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i)).originalSystemId=i.originalSystemId||r.id,r.renderFlags=new $i,r._state=new St({visible:!0,culled:!1,pickable:null,clippable:null,collidable:null,occluder:!1!==i.occluder,castsShadow:null,receivesShadow:null,xrayed:!1,highlighted:!1,selected:!1,edges:!1,stationary:!!i.stationary,background:!!i.background,billboard:r._checkBillboard(i.billboard),layer:null,colorize:null,pickID:r.scene._renderer.getPickID(g(r)),drawHash:"",pickHash:"",offset:Z.vec3(),origin:null,originHash:null}),r._drawRenderer=null,r._shadowRenderer=null,r._emphasisFillRenderer=null,r._emphasisEdgesRenderer=null,r._pickMeshRenderer=null,r._pickTriangleRenderer=null,r._occlusionRenderer=null,r._geometry=i.geometry?r._checkComponent2(["ReadableGeometry","VBOGeometry"],i.geometry):r.scene.geometry,r._material=i.material?r._checkComponent2(["PhongMaterial","MetallicMaterial","SpecularMaterial","LambertMaterial"],i.material):r.scene.material,r._xrayMaterial=i.xrayMaterial?r._checkComponent("EmphasisMaterial",i.xrayMaterial):r.scene.xrayMaterial,r._highlightMaterial=i.highlightMaterial?r._checkComponent("EmphasisMaterial",i.highlightMaterial):r.scene.highlightMaterial,r._selectedMaterial=i.selectedMaterial?r._checkComponent("EmphasisMaterial",i.selectedMaterial):r.scene.selectedMaterial,r._edgeMaterial=i.edgeMaterial?r._checkComponent("EdgeMaterial",i.edgeMaterial):r.scene.edgeMaterial,r._parentNode=null,r._aabb=null,r._aabbDirty=!0,r._numTriangles=r._geometry?r._geometry.numTriangles:0,r.scene._aabbDirty=!0,r._scale=Z.vec3(),r._quaternion=Z.identityQuaternion(),r._rotation=Z.vec3(),r._position=Z.vec3(),r._worldMatrix=Z.identityMat4(),r._worldNormalMatrix=Z.identityMat4(),r._localMatrixDirty=!0,r._worldMatrixDirty=!0,r._worldNormalMatrixDirty=!0;var a=i.origin||i.rtcCenter;if(a&&(r._state.origin=Z.vec3(a),r._state.originHash=a.join()),i.matrix?r.matrix=i.matrix:(r.scale=i.scale,r.position=i.position,i.quaternion||(r.rotation=i.rotation)),r._isObject=i.isObject,r._isObject&&r.scene._registerObject(g(r)),r._isModel=i.isModel,r._isModel&&r.scene._registerModel(g(r)),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.layer=i.layer,r.colorize=i.colorize,r.opacity=i.opacity,r.offset=i.offset,i.parentId){var s=r.scene.components[i.parentId];s?s.isNode?s.addChild(g(r)):r.error("Parent is not a Node: '"+i.parentId+"'"):r.error("Parent not found: '"+i.parentId+"'"),r._parentNode=s}else i.parent&&(i.parent.isNode||r.error("Parent is not a Node"),i.parent.addChild(g(r)),r._parentNode=i.parent);return r.compile(),r}return P(n,[{key:"type",get:function(){return"Mesh"}},{key:"isMesh",get:function(){return!0}},{key:"parent",get:function(){return this._parentNode}},{key:"geometry",get:function(){return this._geometry}},{key:"material",get:function(){return this._material}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),Z.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),Z.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"matrix",get:function(){return this._localMatrixDirty&&(this.__localMatrix||(this.__localMatrix=Z.identityMat4()),Z.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix},set:function(e){this.__localMatrix||(this.__localMatrix=Z.identityMat4()),this.__localMatrix.set(e||ua),Z.decomposeMat4(this.__localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrixDirty&&this._buildWorldNormalMatrix(),this._worldNormalMatrix}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return this._isObject}},{key:"aabb",get:function(){return this._aabbDirty&&this._updateAABB(),this._aabb}},{key:"origin",get:function(){return this._state.origin},set:function(e){e?(this._state.origin||(this._state.origin=Z.vec3()),this._state.origin.set(e),this._state.originHash=e.join(),this._setAABBDirty(),this.scene._aabbDirty=!0):this._state.origin&&(this._state.origin=null,this._state.originHash=null,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"rtcCenter",get:function(){return this.origin},set:function(e){this.origin=e}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"visible",get:function(){return this._state.visible},set:function(e){e=!1!==e,this._state.visible=e,this._isObject&&this.scene._objectVisibilityUpdated(this,e),this.glRedraw()}},{key:"xrayed",get:function(){return this._state.xrayed},set:function(e){e=!!e,this._state.xrayed!==e&&(this._state.xrayed=e,this._isObject&&this.scene._objectXRayedUpdated(this,e),this.glRedraw())}},{key:"highlighted",get:function(){return this._state.highlighted},set:function(e){(e=!!e)!==this._state.highlighted&&(this._state.highlighted=e,this._isObject&&this.scene._objectHighlightedUpdated(this,e),this.glRedraw())}},{key:"selected",get:function(){return this._state.selected},set:function(e){(e=!!e)!==this._state.selected&&(this._state.selected=e,this._isObject&&this.scene._objectSelectedUpdated(this,e),this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){(e=!!e)!==this._state.edges&&(this._state.edges=e,this.glRedraw())}},{key:"culled",get:function(){return this._state.culled},set:function(e){this._state.culled=!!e,this.glRedraw()}},{key:"clippable",get:function(){return this._state.clippable},set:function(e){e=!1!==e,this._state.clippable!==e&&(this._state.clippable=e,this.glRedraw())}},{key:"collidable",get:function(){return this._state.collidable},set:function(e){(e=!1!==e)!==this._state.collidable&&(this._state.collidable=e,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"pickable",get:function(){return this._state.pickable},set:function(e){e=!1!==e,this._state.pickable!==e&&(this._state.pickable=e)}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){(e=!1!==e)!==this._state.castsShadow&&(this._state.castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._state.receivesShadow},set:function(e){(e=!1!==e)!==this._state.receivesShadow&&(this._state.receivesShadow=e,this._state.hash=e?"/mod/rs;":"/mod;",this.fire("dirty",this))}},{key:"saoEnabled",get:function(){return!1}},{key:"colorize",get:function(){return this._state.colorize},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);var n=!!e;this.scene._objectColorizeUpdated(this,n),this.glRedraw()}},{key:"opacity",get:function(){return this._state.colorize[3]},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[0]=1,t[1]=1,t[2]=1);var n=null!=e;t[3]=n?e:1,this.scene._objectOpacityUpdated(this,n),this.glRedraw()}},{key:"transparent",get:function(){return 2===this._material.alphaMode||this._state.colorize[3]<1}},{key:"layer",get:function(){return this._state.layer},set:function(e){e=e||0,(e=Math.round(e))!==this._state.layer&&(this._state.layer=e,this._renderer.needStateSort())}},{key:"stationary",get:function(){return this._state.stationary}},{key:"billboard",get:function(){return this._state.billboard}},{key:"offset",get:function(){return this._state.offset},set:function(e){this._state.offset.set(e||[0,0,0]),this._setAABBDirty(),this.glRedraw()}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!0}},{key:"xrayMaterial",get:function(){return this._xrayMaterial}},{key:"highlightMaterial",get:function(){return this._highlightMaterial}},{key:"selectedMaterial",get:function(){return this._selectedMaterial}},{key:"edgeMaterial",get:function(){return this._edgeMaterial}},{key:"_checkBillboard",value:function(e){return"spherical"!==(e=e||"none")&&"cylindrical"!==e&&"none"!==e&&(this.error("Unsupported value for 'billboard': "+e+" - accepted values are 'spherical', 'cylindrical' and 'none' - defaulting to 'none'."),e="none"),e}},{key:"compile",value:function(){var e=this._makeDrawHash();this._state.drawHash!==e&&(this._state.drawHash=e,this._putDrawRenderers(),this._drawRenderer=Pi.get(this),this._emphasisFillRenderer=Oi.get(this),this._emphasisEdgesRenderer=Mi.get(this));var t=this._makePickHash();if(this._state.pickHash!==t&&(this._state.pickHash=t,this._putPickRenderers(),this._pickMeshRenderer=Gi.get(this)),this._state.occluder){var n=this._makeOcclusionHash();this._state.occlusionHash!==n&&(this._state.occlusionHash=n,this._putOcclusionRenderer(),this._occlusionRenderer=Yi.get(this))}}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}},{key:"_setWorldMatrixDirty",value:function(){this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentNode)Z.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(var t=0,n=e.length;t0)for(var n=0;n-1){var x=B.geometry._state,M=B.scene,F=M.camera,H=M.canvas;if("triangles"===x.primitiveName){N.primitive="triangle";var U,G,k,V=L,j=x.indices,Q=x.positions;if(j){var W=j[V+0],z=j[V+1],K=j[V+2];a[0]=W,a[1]=z,a[2]=K,N.indices=a,U=3*W,G=3*z,k=3*K}else k=(G=(U=3*V)+3)+3;if(n[0]=Q[U+0],n[1]=Q[U+1],n[2]=Q[U+2],r[0]=Q[G+0],r[1]=Q[G+1],r[2]=Q[G+2],i[0]=Q[k+0],i[1]=Q[k+1],i[2]=Q[k+2],x.compressGeometry){var Y=x.positionsDecodeMatrix;Y&&(pn.decompressPosition(n,Y,n),pn.decompressPosition(r,Y,r),pn.decompressPosition(i,Y,i))}N.canvasPos?Z.canvasPosToLocalRay(H.canvas,B.origin?Ie(O,B.origin):O,S,B.worldMatrix,N.canvasPos,e,t):N.origin&&N.direction&&Z.worldRayToLocalRay(B.worldMatrix,N.origin,N.direction,e,t),Z.normalizeVec3(t),Z.rayPlaneIntersect(e,t,n,r,i,s),N.localPos=s,N.position=s,h[0]=s[0],h[1]=s[1],h[2]=s[2],h[3]=1,Z.transformVec4(B.worldMatrix,h,I),o[0]=I[0],o[1]=I[1],o[2]=I[2],N.canvasPos&&B.origin&&(o[0]+=B.origin[0],o[1]+=B.origin[1],o[2]+=B.origin[2]),N.worldPos=o,Z.transformVec4(F.matrix,I,y),l[0]=y[0],l[1]=y[1],l[2]=y[2],N.viewPos=l,Z.cartesianToBarycentric(s,n,r,i,u),N.bary=u;var X=x.normals;if(X){if(x.compressGeometry){var q=3*W,J=3*z,$=3*K;pn.decompressNormal(X.subarray(q,q+2),c),pn.decompressNormal(X.subarray(J,J+2),f),pn.decompressNormal(X.subarray($,$+2),p)}else c[0]=X[U],c[1]=X[U+1],c[2]=X[U+2],f[0]=X[G],f[1]=X[G+1],f[2]=X[G+2],p[0]=X[k],p[1]=X[k+1],p[2]=X[k+2];var ee=Z.addVec3(Z.addVec3(Z.mulVec3Scalar(c,u[0],m),Z.mulVec3Scalar(f,u[1],w),g),Z.mulVec3Scalar(p,u[2],T),E);N.worldNormal=Z.normalizeVec3(Z.transformVec3(B.worldNormalMatrix,ee,b))}var te=x.uv;if(te){if(A[0]=te[2*W],A[1]=te[2*W+1],d[0]=te[2*z],d[1]=te[2*z+1],v[0]=te[2*K],v[1]=te[2*K+1],x.compressGeometry){var ne=x.uvDecodeMatrix;ne&&(pn.decompressUV(A,ne,A),pn.decompressUV(d,ne,d),pn.decompressUV(v,ne,v))}N.uv=Z.addVec3(Z.addVec3(Z.mulVec2Scalar(A,u[0],D),Z.mulVec2Scalar(d,u[1],P),R),Z.mulVec2Scalar(v,u[2],C),_)}}}}}();function pa(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);var n=e.radiusBottom||1;n<0&&(console.error("negative radiusBottom not allowed - will invert"),n*=-1);var r=e.height||1;r<0&&(console.error("negative height not allowed - will invert"),r*=-1);var i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);var a=e.heightSegments||1;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),a<1&&(a=1);var s,o,l,u,c,f,p,A,d,v,h,I=!!e.openEnded,y=e.center,m=y?y[0]:0,w=y?y[1]:0,g=y?y[2]:0,T=r/2,E=r/a,b=2*Math.PI/i,D=1/i,P=(t-n)/a,R=[],C=[],_=[],B=[],O=(90-180*Math.atan(r/(n-t))/Math.PI)/90;for(s=0;s<=a;s++)for(c=t-s*P,f=T-s*E,o=0;o<=i;o++)l=Math.sin(o*b),u=Math.cos(o*b),C.push(c*l),C.push(O),C.push(c*u),_.push(o*D),_.push(1*s/a),R.push(c*l+m),R.push(f+w),R.push(c*u+g);for(s=0;s0){for(d=R.length/3,C.push(0),C.push(1),C.push(0),_.push(.5),_.push(.5),R.push(0+m),R.push(T+w),R.push(0+g),o=0;o<=i;o++)l=Math.sin(o*b),u=Math.cos(o*b),v=.5*Math.sin(o*b)+.5,h=.5*Math.cos(o*b)+.5,C.push(t*l),C.push(1),C.push(t*u),_.push(v),_.push(h),R.push(t*l+m),R.push(T+w),R.push(t*u+g);for(o=0;o0){for(d=R.length/3,C.push(0),C.push(-1),C.push(0),_.push(.5),_.push(.5),R.push(0+m),R.push(0-T+w),R.push(0+g),o=0;o<=i;o++)l=Math.sin(o*b),u=Math.cos(o*b),v=.5*Math.sin(o*b)+.5,h=.5*Math.cos(o*b)+.5,C.push(n*l),C.push(-1),C.push(n*u),_.push(v),_.push(h),R.push(n*l+m),R.push(0-T+w),R.push(n*u+g);for(o=0;o0&&void 0!==arguments[0]?arguments[0]:{},t=e.lod||1,n=e.center?e.center[0]:0,r=e.center?e.center[1]:0,i=e.center?e.center[2]:0,a=e.radius||1;a<0&&(console.error("negative radius not allowed - will invert"),a*=-1);var s=e.heightSegments||18;s<0&&(console.error("negative heightSegments not allowed - will invert"),s*=-1),(s=Math.floor(t*s))<18&&(s=18);var o=e.widthSegments||18;o<0&&(console.error("negative widthSegments not allowed - will invert"),o*=-1),(o=Math.floor(t*o))<18&&(o=18);var l,u,c,f,p,A,d,v,h,I,y,m,w,g,T=[],E=[],b=[],D=[];for(l=0;l<=s;l++)for(c=l*Math.PI/s,f=Math.sin(c),p=Math.cos(c),u=0;u<=o;u++)A=2*u*Math.PI/o,d=Math.sin(A),v=Math.cos(A)*f,h=p,I=d*f,y=1-u/o,m=l/s,E.push(v),E.push(h),E.push(I),b.push(y),b.push(m),T.push(n+a*v),T.push(r+a*h),T.push(i+a*I);for(l=0;l":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function va(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.origin||[0,0,0],n=t[0],r=t[1],i=t[2],a=e.size||1,s=[],o=[],l=e.text;ae.isNumeric(l)&&(l=""+l);for(var u,c,f,p,A,d,v,h,I,y=(l||"").split("\n"),m=0,w=0,g=.04,T=0;T1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({active:!0,pos:Z.vec3(),dir:Z.vec3(),dist:0}),r.active=i.active,r.pos=i.pos,r.dir=i.dir,r.scene._sectionPlaneCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"SectionPlane"}},{key:"active",get:function(){return this._state.active},set:function(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active)}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-Z.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos)}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||[0,0,-1]),this._state.dist=-Z.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir)}},{key:"dist",get:function(){return this._state.dist}},{key:"flipDir",value:function(){var e=this._state.dir;e[0]*=-1,e[1]*=-1,e[2]*=-1,this._state.dist=-Z.dotVec3(this._state.pos,this._state.dir),this.fire("dir",this._state.dir),this.glRedraw()}},{key:"destroy",value:function(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),ya=Z.vec4(4),ma=Z.vec4(),wa=Z.vec4(),ga=Z.vec3([1,0,0]),Ta=Z.vec3([0,1,0]),Ea=Z.vec3([0,0,1]),ba=Z.vec3(3),Da=Z.vec3(3),Pa=Z.identityMat4(),Ra=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,i))._parentNode=null,r._children=[],r._aabb=null,r._aabbDirty=!0,r.scene._aabbDirty=!0,r._numTriangles=0,r._scale=Z.vec3(),r._quaternion=Z.identityQuaternion(),r._rotation=Z.vec3(),r._position=Z.vec3(),r._offset=Z.vec3(),r._localMatrix=Z.identityMat4(),r._worldMatrix=Z.identityMat4(),r._localMatrixDirty=!0,r._worldMatrixDirty=!0,i.matrix?r.matrix=i.matrix:(r.scale=i.scale,r.position=i.position,i.quaternion||(r.rotation=i.rotation)),r._isModel=i.isModel,r._isModel&&r.scene._registerModel(g(r)),r._isObject=i.isObject,r._isObject&&r.scene._registerObject(g(r)),r.origin=i.origin,r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.offset=i.offset,i.children)for(var a=i.children,s=0,o=a.length;s1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"LambertMaterial",ambient:Z.vec3([1,1,1]),color:Z.vec3([1,1,1]),emissive:Z.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),r.ambient=i.ambient,r.color=i.color,r.emissive=i.emissive,r.alpha=i.alpha,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r.backfaces=i.backfaces,r.frontface=i.frontface,r}return P(n,[{key:"type",get:function(){return"LambertMaterial"}},{key:"ambient",get:function(){return this._state.ambient},set:function(e){var t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){var t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this._state.alphaMode=e<1?2:0,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),_a={opaque:0,mask:1,blend:2},Ba=["opaque","mask","blend"],Oa=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"MetallicMaterial",baseColor:Z.vec4([1,1,1]),emissive:Z.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.baseColor=i.baseColor,r.metallic=i.metallic,r.roughness=i.roughness,r.specularF0=i.specularF0,r.emissive=i.emissive,r.alpha=i.alpha,i.baseColorMap&&(r._baseColorMap=r._checkComponent("Texture",i.baseColorMap)),i.metallicMap&&(r._metallicMap=r._checkComponent("Texture",i.metallicMap)),i.roughnessMap&&(r._roughnessMap=r._checkComponent("Texture",i.roughnessMap)),i.metallicRoughnessMap&&(r._metallicRoughnessMap=r._checkComponent("Texture",i.metallicRoughnessMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r._makeHash(),r}return P(n,[{key:"type",get:function(){return"MetallicMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"baseColor",get:function(){return this._state.baseColor},set:function(e){var t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"baseColorMap",get:function(){return this._baseColorMap}},{key:"metallic",get:function(){return this._state.metallic},set:function(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}},{key:"metallicMap",get:function(){return this._attached.metallicMap}},{key:"roughness",get:function(){return this._state.roughness},set:function(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}},{key:"roughnessMap",get:function(){return this._attached.roughnessMap}},{key:"metallicRoughnessMap",get:function(){return this._attached.metallicRoughnessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"emissiveMap",get:function(){return this._attached.emissiveMap}},{key:"occlusionMap",get:function(){return this._attached.occlusionMap}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"alphaMap",get:function(){return this._attached.alphaMap}},{key:"normalMap",get:function(){return this._attached.normalMap}},{key:"alphaMode",get:function(){return Ba[this._state.alphaMode]},set:function(e){var t=_a[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Sa={opaque:0,mask:1,blend:2},Na=["opaque","mask","blend"],La=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"SpecularMaterial",diffuse:Z.vec3([1,1,1]),emissive:Z.vec3([0,0,0]),specular:Z.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.diffuse=i.diffuse,r.specular=i.specular,r.glossiness=i.glossiness,r.specularF0=i.specularF0,r.emissive=i.emissive,r.alpha=i.alpha,i.diffuseMap&&(r._diffuseMap=r._checkComponent("Texture",i.diffuseMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.specularMap&&(r._specularMap=r._checkComponent("Texture",i.specularMap)),i.glossinessMap&&(r._glossinessMap=r._checkComponent("Texture",i.glossinessMap)),i.specularGlossinessMap&&(r._specularGlossinessMap=r._checkComponent("Texture",i.specularGlossinessMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r._makeHash(),r}return P(n,[{key:"type",get:function(){return"SpecularMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"diffuse",get:function(){return this._state.diffuse},set:function(e){var t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"diffuseMap",get:function(){return this._diffuseMap}},{key:"specular",get:function(){return this._state.specular},set:function(e){var t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"specularMap",get:function(){return this._specularMap}},{key:"specularGlossinessMap",get:function(){return this._specularGlossinessMap}},{key:"glossiness",get:function(){return this._state.glossiness},set:function(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}},{key:"glossinessMap",get:function(){return this._glossinessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"emissiveMap",get:function(){return this._emissiveMap}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"alphaMap",get:function(){return this._alphaMap}},{key:"normalMap",get:function(){return this._normalMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"alphaMode",get:function(){return Na[this._state.alphaMode]},set:function(e){var t=Sa[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}();function xa(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 Ma=new Uint8Array([0,0,0,1]),Fa=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?(Ma[0]=Math.floor(255*e[0]),Ma[1]=Math.floor(255*e[1]),Ma[2]=Math.floor(255*e[2]),Ma[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(Ma[0]=0,Ma[1]=0,Ma[2]=0,Ma[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=xa(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=xa(n,this.magFilter);u&&n.texParameteri(this.target,n.TEXTURE_MAG_FILTER,u);var c=xa(n,this.wrapS);c&&n.texParameteri(this.target,n.TEXTURE_WRAP_S,c);var f=xa(n,this.wrapT);f&&n.texParameteri(this.target,n.TEXTURE_WRAP_T,f);var p=xa(n,this.format,this.encoding),A=xa(n,this.type),d=Ha(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=xa(i,this.wrapS);o&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,o);var l=xa(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=xa(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,Ua(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Ua(i,this.magFilter))):(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,xa(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,xa(i,this.magFilter)));var c=xa(i,this.format,this.encoding),f=xa(i,this.type),p=Ha(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 Ua(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function Ga(e){if(!ka(e.width)||!ka(e.height)){var t=document.createElement("canvas");t.width=Va(e.width),t.height=Va(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function ka(e){return 0==(e&e-1)}function Va(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var ja=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({texture:new Fa({gl:r.scene.canvas.gl}),matrix:Z.identityMat4(),hasMatrix:i.translate&&(0!==i.translate[0]||0!==i.translate[1])||!!i.rotate||i.scale&&(0!==i.scale[0]||0!==i.scale[1]),minFilter:r._checkMinFilter(i.minFilter),magFilter:r._checkMagFilter(i.magFilter),wrapS:r._checkWrapS(i.wrapS),wrapT:r._checkWrapT(i.wrapT),flipY:r._checkFlipY(i.flipY),encoding:r._checkEncoding(i.encoding)}),r._src=null,r._image=null,r._translate=Z.vec2([0,0]),r._scale=Z.vec2([1,1]),r._rotate=Z.vec2([0,0]),r._matrixDirty=!1,r.translate=i.translate,r.scale=i.scale,r.rotate=i.rotate,i.src?r.src=i.src:i.image&&(r.image=i.image),ee.memory.textures++,r}return P(n,[{key:"type",get:function(){return"Texture"}},{key:"_checkMinFilter",value:function(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}},{key:"_checkMagFilter",value:function(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}},{key:"_checkWrapS",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkWrapT",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this._state.texture=new Fa({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}},{key:"_update",value:function(){var e,t,n=this._state;this._matrixDirty&&(0===this._translate[0]&&0===this._translate[1]||(e=Z.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(t=Z.scalingMat4v([this._scale[0],this._scale[1],1]),e=e?Z.mulMat4(e,t):t),0!==this._rotate&&(t=Z.rotationMat4v(.0174532925*this._rotate,[0,0,1]),e=e?Z.mulMat4(e,t):t),e&&(n.matrix=e),this._matrixDirty=!1);this.glRedraw()}},{key:"image",get:function(){return this._image},set:function(e){this._image=Ga(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}},{key:"src",get:function(){return this._src},set:function(e){this.scene.loading++,this.scene.canvas.spinner.processes++;var t=this,n=new Image;n.onload=function(){n=Ga(n),t._state.texture.setImage(n,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},n.src=e,this._src=e,this._image=null}},{key:"translate",get:function(){return this._translate},set:function(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}},{key:"rotate",get:function(){return this._rotate},set:function(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}},{key:"minFilter",get:function(){return this._state.minFilter}},{key:"magFilter",get:function(){return this._state.magFilter}},{key:"wrapS",get:function(){return this._state.wrapS}},{key:"wrapT",get:function(){return this._state.wrapT}},{key:"flipY",get:function(){return this._state.flipY}},{key:"encoding",get:function(){return this._state.encoding}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),ee.memory.textures--}}]),n}(),Qa=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({edgeColor:Z.vec3([0,0,0]),centerColor:Z.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),r.edgeColor=i.edgeColor,r.centerColor=i.centerColor,r.edgeBias=i.edgeBias,r.centerBias=i.centerBias,r.power=i.power,r}return P(n,[{key:"type",get:function(){return"Fresnel"}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}},{key:"centerColor",get:function(){return this._state.centerColor},set:function(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}},{key:"edgeBias",get:function(){return this._state.edgeBias},set:function(e){this._state.edgeBias=e||0,this.glRedraw()}},{key:"centerBias",get:function(){return this._state.centerBias},set:function(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}},{key:"power",get:function(){return this._state.power},set:function(e){this._state.power=null!=e?e:1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Wa=ee.memory,za=Z.AABB3(),Ka=function(e){I(n,rn);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._state=new St({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),r._numTriangles=0,r._edgeThreshold=i.edgeThreshold||10,r._aabb=null,r._obb=Z.OBB3();var a,s=r._state,o=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":s.primitive=o.POINTS,s.primitiveName=i.primitive;break;case"lines":s.primitive=o.LINES,s.primitiveName=i.primitive;break;case"line-loop":s.primitive=o.LINE_LOOP,s.primitiveName=i.primitive;break;case"line-strip":s.primitive=o.LINE_STRIP,s.primitiveName=i.primitive;break;case"triangles":s.primitive=o.TRIANGLES,s.primitiveName=i.primitive;break;case"triangle-strip":s.primitive=o.TRIANGLE_STRIP,s.primitiveName=i.primitive;break;case"triangle-fan":s.primitive=o.TRIANGLE_FAN,s.primitiveName=i.primitive;break;default:r.error("Unsupported value for 'primitive': '"+i.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=o.TRIANGLES,s.primitiveName=i.primitive}if(!i.positions)return r.error("Config expected: positions"),w(r);if(!i.indices)return r.error("Config expected: indices"),w(r);var l=i.positionsDecodeMatrix;if(l);else{var u=pn.getPositionsBounds(i.positions),c=pn.compressPositions(i.positions,u.min,u.max);a=c.quantized,s.positionsDecodeMatrix=c.decodeMatrix,s.positionsBuf=new pt(o,o.ARRAY_BUFFER,a,a.length,3,o.STATIC_DRAW),Wa.positions+=s.positionsBuf.numItems,Z.positions3ToAABB3(i.positions,r._aabb),Z.positions3ToAABB3(a,za,s.positionsDecodeMatrix),Z.AABB3ToOBB3(za,r._obb)}if(i.colors){var f=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors);s.colorsBuf=new pt(o,o.ARRAY_BUFFER,f,f.length,4,o.STATIC_DRAW),Wa.colors+=s.colorsBuf.numItems}if(i.uv){var p=pn.getUVBounds(i.uv),A=pn.compressUVs(i.uv,p.min,p.max),d=A.quantized;s.uvDecodeMatrix=A.decodeMatrix,s.uvBuf=new pt(o,o.ARRAY_BUFFER,d,d.length,2,o.STATIC_DRAW),Wa.uvs+=s.uvBuf.numItems}if(i.normals){var v=pn.compressNormals(i.normals),h=s.compressGeometry;s.normalsBuf=new pt(o,o.ARRAY_BUFFER,v,v.length,3,o.STATIC_DRAW,h),Wa.normals+=s.normalsBuf.numItems}var I=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices);s.indicesBuf=new pt(o,o.ELEMENT_ARRAY_BUFFER,I,I.length,1,o.STATIC_DRAW),Wa.indices+=s.indicesBuf.numItems;var y=an(a,I,s.positionsDecodeMatrix,r._edgeThreshold);return r._edgeIndicesBuf=new pt(o,o.ELEMENT_ARRAY_BUFFER,y,y.length,1,o.STATIC_DRAW),"triangles"===r._state.primitiveName&&(r._numTriangles=i.indices.length/3),r._buildHash(),Wa.meshes++,r}return P(n,[{key:"type",get:function(){return"VBOGeometry"}},{key:"isVBOGeometry",get:function(){return!0}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"aabb",get:function(){return this._aabb}},{key:"obb",get:function(){return this._obb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this);var e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),Wa.meshes--}}]),n}(),Ya={};function Xa(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(n,r){t.src||(console.error("load3DSGeometry: Parameter expected: src"),r());var i=e.canvas.spinner;i.processes++,ae.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),i.processes--,r());var a=Ya.parse.from3DS(e).edit.objects[0].mesh,s=a.vertices,o=a.uvt,l=a.indices;i.processes--,n(ae.apply(t,{primitive:"triangles",positions:s,normals:null,uv:o,indices:l}))}),(function(e){console.error("load3DSGeometry: "+e),i.processes--,r()}))}))}function qa(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(n,r){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),r());var i=e.canvas.spinner;i.processes++,ae.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),i.processes--,r());for(var a=Ya.parse.fromOBJ(e),s=Ya.edit.unwrap(a.i_verts,a.c_verts,3),o=Ya.edit.unwrap(a.i_norms,a.c_norms,3),l=Ya.edit.unwrap(a.i_uvt,a.c_uvt,2),u=new Int32Array(a.i_verts.length),c=0;c0?o:null,autoNormals:0===o.length,uv:l,indices:u}))}),(function(e){console.error("loadOBJGeometry: "+e),i.processes--,r()}))}))}function Ja(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.ySize||1;n<0&&(console.error("negative ySize not allowed - will invert"),n*=-1);var r=e.zSize||1;r<0&&(console.error("negative zSize not allowed - will invert"),r*=-1);var i=e.center,a=i?i[0]:0,s=i?i[1]:0,o=i?i[2]:0,l=-t+a,u=-n+s,c=-r+o,f=t+a,p=n+s,A=r+o;return ae.apply(e,{primitive:"lines",positions:[l,u,c,l,u,A,l,p,c,l,p,A,f,u,c,f,u,A,f,p,c,f,p,A],indices:[0,1,1,3,3,2,2,0,4,5,5,7,7,6,6,4,0,4,1,5,2,6,3,7]})}function Za(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);var n=e.divisions||1;n<0&&(console.error("negative divisions not allowed - will invert"),n*=-1),n<1&&(n=1);for(var r=(t=t||10)/(n=n||10),i=t/2,a=[],s=[],o=0,l=0,u=-i;l<=n;l++,u+=r)a.push(-i),a.push(0),a.push(u),a.push(i),a.push(0),a.push(u),a.push(u),a.push(0),a.push(-i),a.push(u),a.push(0),a.push(i),s.push(o++),s.push(o++),s.push(o++),s.push(o++);return ae.apply(e,{primitive:"lines",positions:a,indices:s})}function $a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);var r=e.xSegments||1;r<0&&(console.error("negative xSegments not allowed - will invert"),r*=-1),r<1&&(r=1);var i=e.xSegments||1;i<0&&(console.error("negative zSegments not allowed - will invert"),i*=-1),i<1&&(i=1);var a,s,o,l,u,c,f,p=e.center,A=p?p[0]:0,d=p?p[1]:0,v=p?p[2]:0,h=t/2,I=n/2,y=Math.floor(r)||1,m=Math.floor(i)||1,w=y+1,g=m+1,T=t/y,E=n/m,b=new Float32Array(w*g*3),D=new Float32Array(w*g*3),P=new Float32Array(w*g*2),R=0,C=0;for(a=0;a65535?Uint32Array:Uint16Array)(y*m*6);for(a=0;a0&&void 0!==arguments[0]?arguments[0]:{},t=e.radius||1;t<0&&(console.error("negative radius not allowed - will invert"),t*=-1),t*=.5;var n=e.tube||.3;n<0&&(console.error("negative tube not allowed - will invert"),n*=-1);var r=e.radialSegments||32;r<0&&(console.error("negative radialSegments not allowed - will invert"),r*=-1),r<4&&(r=4);var i=e.tubeSegments||24;i<0&&(console.error("negative tubeSegments not allowed - will invert"),i*=-1),i<4&&(i=4);var a=e.arc||2*Math.PI;a<0&&(console.warn("negative arc not allowed - will invert"),a*=-1),a>360&&(a=360);var s,o,l,u,c,f,p,A,d,v,h,I,y=e.center,m=y?y[0]:0,w=y?y[1]:0,g=y?y[2]:0,T=[],E=[],b=[],D=[];for(A=0;A<=i;A++)for(p=0;p<=r;p++)s=p/r*a,o=.785398+A/i*Math.PI*2,m=t*Math.cos(s),w=t*Math.sin(s),l=(t+n*Math.cos(o))*Math.cos(s),u=(t+n*Math.cos(o))*Math.sin(s),c=n*Math.sin(o),T.push(l+m),T.push(u+w),T.push(c+g),b.push(1-p/r),b.push(A/i),f=Z.normalizeVec3(Z.subVec3([l,u,c],[m,w,g],[]),[]),E.push(f[0]),E.push(f[1]),E.push(f[2]);for(A=1;A<=i;A++)for(p=1;p<=r;p++)d=(r+1)*A+p-1,v=(r+1)*(A-1)+p-1,h=(r+1)*(A-1)+p,I=(r+1)*A+p,D.push(d),D.push(v),D.push(h),D.push(h),D.push(I),D.push(d);return ae.apply(e,{positions:T,normals:E,uv:b,indices:D})}Ya.load=function(e,t){var n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=function(e){t(e.target.response)},n.send()},Ya.save=function(e,t){var n="data:application/octet-stream;base64,"+btoa(Ya.parse._buffToStr(e));window.location.href=n},Ya.clone=function(e){return JSON.parse(JSON.stringify(e))},Ya.bin={},Ya.bin.f=new Float32Array(1),Ya.bin.fb=new Uint8Array(Ya.bin.f.buffer),Ya.bin.rf=function(e,t){for(var n=Ya.bin.f,r=Ya.bin.fb,i=0;i<4;i++)r[i]=e[t+i];return n[0]},Ya.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Ya.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Ya.bin.rASCII0=function(e,t){for(var n="";0!=e[t];)n+=String.fromCharCode(e[t++]);return n},Ya.bin.wf=function(e,t,n){new Float32Array(e.buffer,t,1)[0]=n},Ya.bin.wsl=function(e,t,n){e[t]=n,e[t+1]=n>>8},Ya.bin.wil=function(e,t,n){e[t]=n,e[t+1]=n>>8,e[t+2]=n>>16,e[t+3]},Ya.parse={},Ya.parse._buffToStr=function(e){for(var t=new Uint8Array(e),n="",r=0;ri&&(i=l),ua&&(a=u),cs&&(s=c)}return{min:{x:t,y:n,z:r},max:{x:i,y:a,z:s}}};var ts=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._type=i.type||(i.src?i.src.split(".").pop():null)||"jpg",r._pos=Z.vec3(i.pos||[0,0,0]),r._up=Z.vec3(i.up||[0,1,0]),r._normal=Z.vec3(i.normal||[0,0,1]),r._height=i.height||1,r._origin=Z.vec3(),r._rtcPos=Z.vec3(),r._imageSize=Z.vec2(),r._texture=new ja(g(r)),r._image=new Image,"jpg"!==r._type&&"png"!==r._type&&(r.error('Unsupported type - defaulting to "jpg"'),r._type="jpg"),r._node=new Ra(g(r),{matrix:Z.inverseMat4(Z.lookAtMat4v(r._pos,Z.subVec3(r._pos,r._normal,Z.mat4()),r._up,Z.mat4())),children:[r._bitmapMesh=new ca(g(r),{scale:[1,1,1],rotation:[-90,0,0],collidable:i.collidable,pickable:i.pickable,opacity:i.opacity,clippable:i.clippable,geometry:new vn(g(r),$a({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new wn(g(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0})})]}),i.image?r.image=i.image:i.src?r.src=i.src:i.imageData&&(r.imageData=i.imageData),r.scene._bitmapCreated(g(r)),r}return P(n,[{key:"visible",get:function(){return this._bitmapMesh.visible},set:function(e){this._bitmapMesh.visible=e}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}},{key:"src",get:function(){return this._image.src},set:function(e){var t=this;if(e)switch(this._image.onload=function(){t._texture.image=t._image,t._imageSize[0]=t._image.width,t._imageSize[1]=t._image.height,t._updateBitmapMeshScale()},this._image.src=e,e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}},{key:"imageData",get:function(){var e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")},set:function(e){var t=this;this._image.onload=function(){t._texture.image=image,t._imageSize[0]=image.width,t._imageSize[1]=image.height,t._updateBitmapMeshScale()},this._image.src=e}},{key:"type",get:function(){return this._type},set:function(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}},{key:"pos",get:function(){return this._pos}},{key:"normal",get:function(){return this._normal}},{key:"up",get:function(){return this._up}},{key:"height",get:function(){return this._height},set:function(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}},{key:"collidable",get:function(){return this._bitmapMesh.collidable},set:function(e){this._bitmapMesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._bitmapMesh.clippable},set:function(e){this._bitmapMesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._bitmapMesh.pickable},set:function(e){this._bitmapMesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._bitmapMesh.opacity},set:function(e){this._bitmapMesh.opacity=e}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._bitmapDestroyed(this)}},{key:"_updateBitmapMeshScale",value:function(){var e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height*e,1,this._height]}}]),n}(),ns=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,i))._positions=i.positions||[],r._origin=Z.vec3(i.origin||[0,0,0]),i.indices)r._indices=i.indices;else{r._indices=[];for(var a=0,s=r._positions.length/3-1;a1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"BCFViewpoints",e,i)).originatingSystem=i.originatingSystem||"xeokit.io",r.authoringTool=i.authoringTool||"xeokit.io",r}return P(n,[{key:"getViewpoint",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=this.viewer.scene,r=n.camera,i=n.realWorldOffset,a=!0===t.reverseClippingPlanes,s={},o=Z.normalizeVec3(Z.subVec3(r.look,r.eye,Z.vec3())),l=r.eye,u=r.up;r.yUp&&(o=cs(o),l=cs(l),u=cs(u));var c=ls(Z.addVec3(l,i));"ortho"===r.projection?s.orthogonal_camera={camera_view_point:c,camera_direction:ls(o),camera_up_vector:ls(u),view_to_world_scale:r.ortho.scale}:s.perspective_camera={camera_view_point:c,camera_direction:ls(o),camera_up_vector:ls(u),field_of_view:r.perspective.fov};var f=n.sectionPlanes;for(var A in f)if(f.hasOwnProperty(A)){var d=f[A];if(!d.active)continue;var v=d.pos,h=void 0;h=a?Z.negateVec3(d.dir,Z.vec3()):d.dir,r.yUp&&(v=cs(v),h=cs(h)),Z.addVec3(v,i),v=ls(v),h=ls(h),s.clipping_planes||(s.clipping_planes=[]),s.clipping_planes.push({location:v,direction:h})}var I=n.lineSets;for(var y in I)if(I.hasOwnProperty(y)){var m=I[y];s.lines||(s.lines=[]);for(var w=m.positions,g=m.indices,T=0,E=g.length/2;T1&&void 0!==arguments[1]?arguments[1]:{};if(e){var r=this.viewer,i=r.scene,a=i.camera,s=!1!==n.rayCast,o=!1!==n.immediate,l=!1!==n.reset,u=i.realWorldOffset,c=!0===n.reverseClippingPlanes;if(i.clearSectionPlanes(),e.clipping_planes&&e.clipping_planes.forEach((function(e){var t=us(e.location,rs),n=us(e.direction,rs);c&&Z.negateVec3(n),Z.subVec3(t,u),a.yUp&&(t=fs(t),n=fs(n)),new Ia(i,{pos:t,dir:n})})),i.clearLines(),e.lines){var f=[],p=[],A=0;e.lines.forEach((function(e){e.start_point&&e.end_point&&(f.push(e.start_point.x),f.push(e.start_point.y),f.push(e.start_point.z),f.push(e.end_point.x),f.push(e.end_point.y),f.push(e.end_point.z),p.push(A++),p.push(A++))})),new ns(i,{positions:f,indices:p,clippable:!1,collidable:!0})}if(i.clearBitmaps(),e.bitmaps&&e.bitmaps.forEach((function(e){var t=e.bitmap_type||"jpg",n=e.bitmap_data,r=us(e.location,is),s=us(e.normal,as),o=us(e.up,ss),l=e.height||1;t&&n&&r&&s&&o&&(a.yUp&&(r=fs(r),s=fs(s),o=fs(o)),new ts(i,{src:n,type:t,pos:r,normal:s,up:o,clippable:!1,collidable:!0,height:l}))})),l&&(i.setObjectsXRayed(i.xrayedObjectIds,!1),i.setObjectsHighlighted(i.highlightedObjectIds,!1),i.setObjectsSelected(i.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(i.setObjectsVisible(i.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.visible=!1}))}))):(i.setObjectsVisible(i.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.visible=!0}))})));var d=e.components.visibility.view_setup_hints;d&&(!1===d.spaces_visible&&i.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcSpace"),!1),!1===d.openings_visible&&i.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcOpening"),!1),d.space_boundaries_visible)}e.components.selection&&(i.setObjectsSelected(i.selectedObjectIds,!1),e.components.selection.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.selected=!0}))}))),e.components.coloring&&e.components.coloring.forEach((function(e){var r=e.color,i=0,a=!1;8===r.length&&((i=parseInt(r.substring(0,2),16)/256)<=1&&i>=.95&&(i=1),r=r.substring(2),a=!0);var s=[parseInt(r.substring(0,2),16)/256,parseInt(r.substring(2,4),16)/256,parseInt(r.substring(4,6),16)/256];e.components.map((function(e){return t._withBCFComponent(n,e,(function(e){e.colorize=s,a&&(e.opacity=i)}))}))}))}if(e.perspective_camera||e.orthogonal_camera){var v,h,I,y;if(e.perspective_camera?(v=us(e.perspective_camera.camera_view_point,rs),h=us(e.perspective_camera.camera_direction,rs),I=us(e.perspective_camera.camera_up_vector,rs),a.perspective.fov=e.perspective_camera.field_of_view,y="perspective"):(v=us(e.orthogonal_camera.camera_view_point,rs),h=us(e.orthogonal_camera.camera_direction,rs),I=us(e.orthogonal_camera.camera_up_vector,rs),a.ortho.scale=e.orthogonal_camera.view_to_world_scale,y="ortho"),Z.subVec3(v,u),a.yUp&&(v=fs(v),h=fs(h),I=fs(I)),s){var m=i.pick({pickSurface:!0,origin:v,direction:h});h=m?m.worldPos:Z.addVec3(v,h,rs)}else h=Z.addVec3(v,h,rs);o?(a.eye=v,a.look=h,a.up=I,a.projection=y):r.cameraFlight.flyTo({eye:v,look:h,up:I,duration:n.duration,projection:y})}}}},{key:"_withBCFComponent",value:function(e,t,n){var r=this.viewer,i=r.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){var a=t.authoring_tool_id,s=i.objects[a];if(s)return void n(s);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[a])return void i.withObjects(r.metaScene.getObjectIDsInSubtree(a),n)}if(t.ifc_guid){var o=t.ifc_guid,l=i.objects[o];if(l)return void n(l);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[o])return void i.withObjects(r.metaScene.getObjectIDsInSubtree(o),n);Object.keys(i.models).forEach((function(t){var a=Z.globalizeObjectId(t,o),s=i.objects[a];s?n(s):e.updateCompositeObjects&&r.metaScene.metaObjects[a]&&i.withObjects(r.metaScene.getObjectIDsInSubtree(a),n)}))}}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this)}}]),n}();function ls(e){return{x:e[0],y:e[1],z:e[2]}}function us(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function cs(e){return new Float64Array([e[0],-e[2],e[1]])}function fs(e){return new Float64Array([e[0],e[2],-e[1]])}function ps(e){var t="";return t+=Math.round(255*e[0]).toString(16).padStart(2,"0"),t+=Math.round(255*e[1]).toString(16).padStart(2,"0"),t+=Math.round(255*e[2]).toString(16).padStart(2,"0")}var As=Z.vec3(),ds=function(e,t,n,r){var i=e-n,a=t-r;return Math.sqrt(i*i+a*a)},vs=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._eventSubs={};var a=r.plugin.viewer.scene;r._originMarker=new Me(a,i.origin),r._targetMarker=new Me(a,i.target),r._originWorld=Z.vec3(),r._targetWorld=Z.vec3(),r._wp=new Float64Array(24),r._vp=new Float64Array(24),r._pp=new Float64Array(24),r._cp=new Float64Array(8),r._xAxisLabelCulled=!1,r._yAxisLabelCulled=!1,r._zAxisLabelCulled=!1,r._color=i.color||r.plugin.defaultColor;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._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._lengthWire=new Fe(r._container,{color:r._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._xAxisWire=new Fe(r._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._yAxisWire=new Fe(r._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._zAxisWire=new Fe(r._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._lengthLabel=new Ue(r._container,{fillColor:r._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._xAxisLabel=new Ue(r._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._yAxisLabel=new Ue(r._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._zAxisLabel=new Ue(r._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._wpDirty=!1,r._vpDirty=!1,r._cpDirty=!1,r._visible=!1,r._originVisible=!1,r._targetVisible=!1,r._wireVisible=!1,r._axisVisible=!1,r._xAxisVisible=!1,r._yAxisVisible=!1,r._zAxisVisible=!1,r._axisEnabled=!0,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._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._onMetricsUnits=a.metrics.on("units",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsScale=a.metrics.on("scale",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsOrigin=a.metrics.on("origin",(function(){r._cpDirty=!0,r._needUpdate()})),r.approximate=i.approximate,r.visible=i.visible,r.originVisible=i.originVisible,r.targetVisible=i.targetVisible,r.wireVisible=i.wireVisible,r.axisVisible=i.axisVisible,r.xAxisVisible=i.xAxisVisible,r.yAxisVisible=i.yAxisVisible,r.zAxisVisible=i.zAxisVisible,r.labelsVisible=i.labelsVisible,r}return P(n,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;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._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=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._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0);var t=this._originMarker.viewPos[2],n=this._targetMarker.viewPos[2];if(t>-.3||n>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){Z.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var r=this._pp,i=this._cp,a=e.canvas.canvas.getBoundingClientRect(),s=this._container.getBoundingClientRect(),o=a.top-s.top,l=a.left-s.left,u=e.canvas.boundary,c=u[2],f=u[3],p=0,A=this.plugin.viewer.scene.metrics,d=A.scale,v=A.units,h=A.unitsInfo[v].abbrev,I=0,y=r.length;I0&&void 0!==arguments[0]?arguments[0]:{};b(this,e),this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=t.messages,this.locale=t.locale}return P(e,[{key:"messages",set:function(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}},{key:"loadMessages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var t in e)this._messages[t]=e[t];this.messages=this._messages}},{key:"clearMessages",value:function(){this.messages={}}},{key:"locales",get:function(){return this._locales}},{key:"locale",get:function(){return this._locale},set:function(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}},{key:"translate",value:function(e,t){var n=this._messages[this._locale];if(!n)return null;var r=Is(e,n);return r?t?ys(r,t):r:null}},{key:"translatePlurals",value:function(e,t,n){var r=this._messages[this._locale];if(!r)return null;var i=Is(e,r);return(i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one)?(i=ys(i,[t]),n&&(i=ys(i,n)),i):null}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==n&&(this._events[e]=t||!0);var r=this._eventSubs[e];if(r)for(var i in r){if(r.hasOwnProperty(i))r[i].callback(t)}}},{key:"on",value:function(e,t){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new G),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});var n=this._eventSubs[e];n||(n={},this._eventSubs[e]=n);var r=this._eventSubIDMap.addItem();n[r]={callback:t},this._eventSubEvents[r]=e;var i=this._events[e];return void 0!==i&&t(i),r}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var n=this._eventSubs[t];n&&delete n[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function Is(e,t){if(t[e])return t[e];for(var n=e.split("."),r=t,i=0,a=n.length;r&&i1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,n){return"{{"===e?"{":"}}"===e?"}":t[n]}))}var ms=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).t=i.t,r}return P(n,[{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"tangent",get:function(){return this.getTangent(this._t)}},{key:"length",get:function(){var e=this._getLengths();return e[e.length-1]}},{key:"getTangent",value:function(e){var t=1e-4;void 0===e&&(e=this._t);var n=e-t,r=e+t;n<0&&(n=0),r>1&&(r=1);var i=this.getPoint(n),a=this.getPoint(r),s=Z.subVec3(a,i,[]);return Z.normalizeVec3(s,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,n=[];for(t=0;t<=e;t++)n.push(this.getPoint(t/e));return n}},{key:"_getLengths",value:function(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,n,r=[],i=this.getPoint(0),a=0;for(r.push(0),n=1;n<=e;n++)t=this.getPoint(n/e),a+=Z.lenVec3(Z.subVec3(t,i,[])),r.push(a),i=t;return this.cacheArcLengths=r,r}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var n,r=this._getLengths(),i=0,a=r.length;n=t||e*r[a-1];for(var s,o=0,l=a-1;o<=l;)if((s=r[i=Math.floor(o+(l-o)/2)]-n)<0)o=i+1;else{if(!(s>0)){l=i;break}l=i-1}if(r[i=l]===n)return i/(a-1);var u=r[i];return(i+(n-u)/(r[i+1]-u))/(a-1)}}]),n}(),ws=function(e){I(n,ms);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).points=i.points,r.t=i.t,r}return P(n,[{key:"points",get:function(){return this._points},set:function(e){this._points=e||[]}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=this.points;if(!(t.length<3)){var n=(t.length-1)*e,r=Math.floor(n),i=n-r,a=t[0===r?r:r-1],s=t[r],o=t[r>t.length-2?t.length-1:r+1],l=t[r>t.length-3?t.length-1:r+2],u=Z.vec3();return u[0]=Z.catmullRomInterpolate(a[0],s[0],o[0],l[0],i),u[1]=Z.catmullRomInterpolate(a[1],s[1],o[1],l[1],i),u[2]=Z.catmullRomInterpolate(a[2],s[2],o[2],l[2],i),u}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}},{key:"getJSON",value:function(){return{points:points,t:this._t}}}]),n}(),gs=Z.vec3(),Ts=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._frames=[],r._eyeCurve=new ws(g(r)),r._lookCurve=new ws(g(r)),r._upCurve=new ws(g(r)),i.frames&&(r.addFrames(i.frames),r.smoothFrameTimes(1)),r}return P(n,[{key:"type",get:function(){return"CameraPath"}},{key:"frames",get:function(){return this._frames}},{key:"eyeCurve",get:function(){return this._eyeCurve}},{key:"lookCurve",get:function(){return this._lookCurve}},{key:"upCurve",get:function(){return this._upCurve}},{key:"saveFrame",value:function(e){var t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}},{key:"addFrame",value:function(e,t,n,r){var i={t:e,eye:t.slice(0),look:n.slice(0),up:r.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}},{key:"addFrames",value:function(e){for(var t,n=0,r=e.length;n1?1:e,t.eye=this._eyeCurve.getPoint(e,gs),t.look=this._lookCurve.getPoint(e,gs),t.up=this._upCurve.getPoint(e,gs)}},{key:"sampleFrame",value:function(e,t,n,r){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,n),this._upCurve.getPoint(e,r)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=Z.vec3(),n=0;this._frames[0].t=0;for(var r=[],i=1,a=this._frames.length;i1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._look1=Z.vec3(),r._eye1=Z.vec3(),r._up1=Z.vec3(),r._look2=Z.vec3(),r._eye2=Z.vec3(),r._up2=Z.vec3(),r._orthoScale1=1,r._orthoScale2=1,r._flying=!1,r._flyEyeLookUp=!1,r._flyingEye=!1,r._flyingLook=!1,r._callback=null,r._callbackScope=null,r._time1=null,r._time2=null,r.easing=!1!==i.easing,r.duration=i.duration,r.fit=i.fit,r.fitFOV=i.fitFOV,r.trail=i.trail,r}return P(n,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,n){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=n;var r,i,a,s,o,l=this.scene.camera,u=!!e.projection&&e.projection!==l.projection;if(this._eye1[0]=l.eye[0],this._eye1[1]=l.eye[1],this._eye1[2]=l.eye[2],this._look1[0]=l.look[0],this._look1[1]=l.look[1],this._look1[2]=l.look[2],this._up1[0]=l.up[0],this._up1[1]=l.up[1],this._up1[2]=l.up[2],this._orthoScale1=l.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)i=e.eye,a=e.look,s=e.up;else if(e.eye)i=e.eye;else if(e.look)a=e.look;else{var c=e;if((ae.isNumeric(c)||ae.isString(c))&&(o=c,!(c=this.scene.components[o])))return this.error("Component not found: "+ae.inQuotes(o)),void(t&&(n?t.call(n):t()));u||(r=c.aabb||this.scene.aabb)}var f=e.poi;if(r){if(r[3]=1;e>1&&(e=1);var r=this.easing?n._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(Z.subVec3(i.eye,i.look,Rs),i.eye=Z.lerpVec3(r,0,1,this._eye1,this._eye2,Ds),i.look=Z.subVec3(Ds,Rs,bs)):this._flyingLook&&(i.look=Z.lerpVec3(r,0,1,this._look1,this._look2,bs),i.up=Z.lerpVec3(r,0,1,this._up1,this._up2,Ps)):this._flyingEyeLookUp&&(i.eye=Z.lerpVec3(r,0,1,this._eye1,this._eye2,Ds),i.look=Z.lerpVec3(r,0,1,this._look1,this._look2,bs),i.up=Z.lerpVec3(r,0,1,this._up1,this._up2,Ps)),this._projection2){var a="ortho"===this._projection2?n._easeOutExpo(e,0,1,1):n._easeInCubic(e,0,1,1);i.customProjection.matrix=Z.lerpMat4(a,0,1,this._projMatrix1,this._projMatrix2)}else i.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return i.ortho.scale=this._orthoScale2,void this.stop();Ae.scheduleTask(this._update,this)}}},{key:"stop",value:function(){if(this._flying){this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);var e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}}},{key:"cancel",value:function(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}},{key:"duration",get:function(){return this._duration/1e3},set:function(e){this._duration=e?1e3*e:500,this.stop()}},{key:"fit",get:function(){return this._fit},set:function(e){this._fit=!1!==e}},{key:"fitFOV",get:function(){return this._fitFOV},set:function(e){this._fitFOV=e||45}},{key:"trail",get:function(){return this._trail},set:function(e){this._trail=!!e}},{key:"destroy",value:function(){this.stop(),v(T(n.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,n,r){return n*(e/=r)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,n,r){return n*(1-Math.pow(2,-10*e/r))+t}}]),n}(),_s=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cameraFlightAnimation=new Cs(g(r)),r._t=0,r.state=n.SCRUBBING,r._playingFromT=0,r._playingToT=0,r._playingRate=i.playingRate||1,r._playingDir=1,r._lastTime=null,r.cameraPath=i.cameraPath,r._tick=r.scene.on("tick",r._updateT,g(r)),r}return P(n,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,r,i=performance.now(),a=this._lastTime?.001*(i-this._lastTime):0;if(this._lastTime=i,0!==a)switch(this.state){case n.SCRUBBING:return;case n.PLAYING:if(this._t+=this._playingRate*a,0===(t=this._cameraPath.frames.length)||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=n.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case n.PLAYING_TO:r=this._t+this._playingRate*a*this._playingDir,(this._playingDir<0&&r<=this._playingToT||this._playingDir>0&&r>=this._playingToT)&&(r=this._playingToT,this.state=n.SCRUBBING,this.fire("stopped")),this._t=r,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"cameraPath",get:function(){return this._cameraPath},set:function(e){this._cameraPath=e}},{key:"rate",get:function(){return this._playingRate},set:function(e){this._playingRate=e}},{key:"play",value:function(){this._cameraPath&&(this._lastTime=null,this.state=n.PLAYING)}},{key:"playToT",value:function(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=n.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var n=t.frames[e];n?this.playToT(n.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var r=this._cameraPath;if(r){var i=r.frames[e];i?(this.state=n.SCRUBBING,this._cameraFlightAnimation.flyTo(i,t)):this.error("flyToFrame - frame index out of range: "+e)}}},{key:"scrubToT",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=n.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=n.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=n.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),n}();_s.STOPPED=0,_s.SCRUBBING=1,_s.PLAYING=2,_s.PLAYING_TO=3;var Bs=Z.vec3(),Os=Z.vec3();Z.vec3();var Ss=Z.vec3([0,-1,0]),Ns=Z.vec4([0,0,0,1]),Ls=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._src=null,r._image=null,r._pos=Z.vec3(),r._origin=Z.vec3(),r._rtcPos=Z.vec3(),r._dir=Z.vec3(),r._size=1,r._imageSize=Z.vec2(),r._texture=new ja(g(r)),r._plane=new ca(g(r),{geometry:new vn(g(r),$a({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new wn(g(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0}),clippable:i.clippable}),r._grid=new ca(g(r),{geometry:new vn(g(r),Za({size:1,divisions:10})),material:new wn(g(r),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:i.clippable}),r._node=new Ra(g(r),{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[r._plane,r._grid]}),r._gridVisible=!1,r.visible=!0,r.gridVisible=i.gridVisible,r.position=i.position,r.rotation=i.rotation,r.dir=i.dir,r.size=i.size,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"visible",get:function(){return this._plane.visible},set:function(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}},{key:"gridVisible",get:function(){return this._gridVisible},set:function(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),ye(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}},{key:"rotation",get:function(){return this._node.rotation},set:function(e){this._node.rotation=e}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"dir",get:function(){return this._dir},set:function(e){if(this._dir.set(e||[0,0,-1]),e){var t=this.scene.center,n=[-this._dir[0],-this._dir[1],-this._dir[2]];Z.subVec3(t,this.position,Bs);var r=-Z.dotVec3(n,Bs);Z.normalizeVec3(n),Z.mulVec3Scalar(n,r,Os),Z.vec3PairToQuaternion(Ss,e,Ns),this._node.quaternion=Ns}}},{key:"collidable",get:function(){return this._node.collidable},set:function(e){this._node.collidable=!1!==e}},{key:"clippable",get:function(){return this._node.clippable},set:function(e){this._node.clippable=!1!==e}},{key:"pickable",get:function(){return this._node.pickable},set:function(e){this._node.pickable=!1!==e}},{key:"opacity",get:function(){return this._node.opacity},set:function(e){this._node.opacity=e}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],n=this._imageSize[1];if(t>n){var r=n/t;this._node.scale=[e,1,e*r]}else{var i=t/n;this._node.scale=[e*i,1,e]}}}]),n}(),xs=function(e){I(n,en);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=g(r=t.call(this,e,i));r._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var s=r.scene.camera,o=r.scene.canvas;return r._onCameraViewMatrix=s.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=s.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=o.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new St({type:"point",pos:Z.vec3([1,1,1]),color:Z.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(a._shadowViewMatrixDirty){a._shadowViewMatrix||(a._shadowViewMatrix=Z.identityMat4());var e=a._state.pos,t=s.look,n=s.up;Z.lookAtMat4v(e,t,n,a._shadowViewMatrix),a._shadowViewMatrixDirty=!1}return a._shadowViewMatrix},getShadowProjMatrix:function(){if(a._shadowProjMatrixDirty){a._shadowProjMatrix||(a._shadowProjMatrix=Z.identityMat4());var e=a.scene.canvas.canvas;Z.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,a._shadowProjMatrix),a._shadowProjMatrixDirty=!1}return a._shadowProjMatrix},getShadowRenderBuf:function(){return a._shadowRenderBuf||(a._shadowRenderBuf=new Pt(a.scene.canvas.canvas,a.scene.canvas.gl,{size:[1024,1024]})),a._shadowRenderBuf}}),r.pos=i.pos,r.color=i.color,r.intensity=i.intensity,r.constantAttenuation=i.constantAttenuation,r.linearAttenuation=i.linearAttenuation,r.quadraticAttenuation=i.quadraticAttenuation,r.castsShadow=i.castsShadow,r.scene._lightCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"PointLight"}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"constantAttenuation",get:function(){return this._state.attenuation[0]},set:function(e){this._state.attenuation[0]=e||0,this.glRedraw()}},{key:"linearAttenuation",get:function(){return this._state.attenuation[1]},set:function(e){this._state.attenuation[1]=e||0,this.glRedraw()}},{key:"quadraticAttenuation",get:function(){return this._state.attenuation[2]},set:function(e){this._state.attenuation[2]=e||0,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}();function Ms(e){return 0==(e&e-1)}function Fs(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var Hs=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);var a=(r=t.call(this,e,i)).scene.canvas.gl;return r._state=new St({texture:new Fa({gl:a,target:a.TEXTURE_CUBE_MAP}),flipY:r._checkFlipY(i.minFilter),encoding:r._checkEncoding(i.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),r._src=i.src,r._images=[],r._loadSrc(i.src),ee.memory.textures++,r}return P(n,[{key:"type",get:function(){return"CubeTexture"}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}},{key:"_loadSrc",value:function(e){var t=this,n=this.scene.canvas.gl;this._images=[];for(var r=!1,i=0,a=function(a){var s=new Image;s.onload=function(){var e=s,o=a;return function(){if(!r&&(e=function(e){if(!Ms(e.width)||!Ms(e.height)){var t=document.createElement("canvas");t.width=Fs(e.width),t.height=Fs(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(e),t._images[o]=e,6===++i)){var a=t._state.texture;a||(a=new Fa({gl:n,target:n.TEXTURE_CUBE_MAP}),t._state.texture=a),a.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}}(),s.onerror=function(){r=!0},s.src=e[a]},s=0;s1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightsState.addReflectionMap(r._state),r.scene._reflectionMapCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),n}(),Gs=function(e){I(n,Hs);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightMapCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),n}(),ks=function(e){I(n,Me);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,{entity:i.entity,occludable:i.occludable,worldPos:i.worldPos}))._occluded=!1,r._visible=!0,r._src=null,r._image=null,r._pos=Z.vec3(),r._origin=Z.vec3(),r._rtcPos=Z.vec3(),r._dir=Z.vec3(),r._size=1,r._imageSize=Z.vec2(),r._texture=new ja(g(r),{src:i.src}),r._geometry=new vn(g(r),{primitive:"triangles",positions:[3,3,0,-3,3,0,-3,-3,0,3,-3,0],normals:[-1,0,0,-1,0,0,-1,0,0,-1,0,0],uv:[1,-1,0,-1,0,0,1,0],indices:[0,1,2,0,2,3]}),r._mesh=new ca(g(r),{geometry:r._geometry,material:new wn(g(r),{ambient:[.9,.3,.9],shininess:30,diffuseMap:r._texture,backfaces:!0}),scale:[1,1,1],position:i.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),r.visible=!0,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,r.size=i.size,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,v(T(n.prototype),"_setVisible",this).call(this,e)}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"collidable",get:function(){return this._mesh.collidable},set:function(e){this._mesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._mesh.clippable},set:function(e){this._mesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._mesh.pickable},set:function(e){this._mesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._mesh.opacity},set:function(e){this._mesh.opacity=e}},{key:"_updatePlaneSizeFromImage",value:function(){var e=.5*this._size,t=this._imageSize[0],n=this._imageSize[1],r=n/t;this._geometry.positions=t>n?[e,e*r,0,-e,e*r,0,-e,-e*r,0,e,-e*r,0]:[e/r,e,0,-e/r,e,0,-e/r,-e,0,e/r,-e,0]}}]),n}(),Vs=function(){function e(t){b(this,e),this._eye=Z.vec3(),this._look=Z.vec3(),this._up=Z.vec3(),this._projection={},t&&this.saveCamera(t)}return P(e,[{key:"saveCamera",value:function(e){var t=e.camera,n=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:n.fov,fovAxis:n.fovAxis,near:n.near,far:n.far};break;case"ortho":this._projection={projection:"ortho",scale:n.scale,near:n.near,far:n.far};break;case"frustum":this._projection={projection:"frustum",left:n.left,right:n.right,top:n.top,bottom:n.bottom,near:n.near,far:n.far};break;case"custom":this._projection={projection:"custom",matrix:n.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var n=e.camera,r=this._projection;function i(){switch(r.type){case"perspective":n.perspective.fov=r.fov,n.perspective.fovAxis=r.fovAxis,n.perspective.near=r.near,n.perspective.far=r.far;break;case"ortho":n.ortho.scale=r.scale,n.ortho.near=r.near,n.ortho.far=r.far;break;case"frustum":n.frustum.left=r.left,n.frustum.right=r.right,n.frustum.top=r.top,n.frustum.bottom=r.bottom,n.frustum.near=r.near,n.frustum.far=r.far;break;case"custom":n.customProjection.matrix=r.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:r.scale,projection:r.projection},(function(){i(),t()})):(n.eye=this._eye,n.look=this._look,n.up=this._up,i(),n.projection=r.projection)}}]),e}(),js=Z.vec3(),Qs=function(){function e(t){if(b(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,t){var n=t.metaScene.scene;this.saveObjects(n,t)}}return P(e,[{key:"saveObjects",value:function(e,t,n){var r=t.rootMetaObject;if(r){var i=r.getObjectIDsInSubtree();this.numObjects=0,this._mask=n?ae.apply(n,{}):null;for(var a=e.objects,s=!n||n.visible,o=!n||n.edges,l=!n||n.xrayed,u=!n||n.highlighted,c=!n||n.selected,f=!n||n.clippable,p=!n||n.pickable,A=!n||n.colorize,d=!n||n.opacity,v=0,h=i.length;v1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.v3=i.v3,r.t=i.t,r}return P(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||Z.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||Z.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||Z.vec3([0,0,0])}},{key:"v3",get:function(){return this._v3},set:function(e){this.fire("v3",this._v3=e||Z.vec3([0,0,0]))}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=Z.vec3();return t[0]=Z.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=Z.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=Z.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}]),n}(),Ys=function(e){I(n,ms);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cachedLengths=[],r._dirty=!0,r._curves=[],r._t=0,r._dirtySubs=[],r._destroyedSubs=[],r.curves=i.curves||[],r.t=i.t,r}return P(n,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,n,r;for(e=e||[],n=0,r=this._curves.length;n1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"length",get:function(){var e=this._getCurveLengths();return e[e.length-1]}},{key:"getPoint",value:function(e){for(var t,n=e*this.length,r=this._getCurveLengths(),i=0;i=n){var a=1-(r[i]-n)/(t=this._curves[i]).length;return t.getPointAt(a)}i++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],n=0,r=this._curves.length;for(e=0;e1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.t=i.t,r}return P(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||Z.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||Z.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||Z.vec3([0,0,0])}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=Z.vec3();return t[0]=Z.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=Z.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=Z.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}]),n}(),qs=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}(),Js=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}()),Zs=0;function $s(){return Zs++,Js}var eo={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},to=new Float32Array([1,1,1,1]),no=new Float32Array([0,0,0,1]),ro=Z.vec4(),io=Z.vec3(),ao=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;ro[0]=x,ro[1]=M,ro[2]=N.blendCutoff,ro[3]=N.blendFactor,c.uniform4fv(this._uSAOParams,ro),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===eo["".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===eo["".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===eo["".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?no:to)}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}(),so=function(e){I(n,ao);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}(),oo=function(e){I(n,so);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!1,edges:!0})}return P(n)}(),lo=function(e){I(n,ao);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}(),uo=function(e){I(n,lo);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0,edges:!0})}return P(n)}(),co=function(e){I(n,ao);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}(),fo=function(e){I(n,ao);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}(),po=function(e){I(n,ao);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}(),Ao=function(e){I(n,ao);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}(),vo=function(e){I(n,so);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}(),ho=function(e){I(n,so);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}(),yo=function(e){I(n,oo);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}(),mo=function(e){I(n,oo);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}(),wo=function(e){I(n,so);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}(),go=function(e){I(n,so);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}(),To=function(e){I(n,so);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}(),Eo=function(e){I(n,so);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}(),bo=function(e){I(n,so);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}(),Do=function(e){I(n,so);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}(),Po=function(e){I(n,so);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}(),Ro=function(e){I(n,so);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}(),_o=function(e){I(n,so);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=[]})),No=Z.mat4(),Lo=Z.mat4();function xo(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 Ho(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 Uo=Z.vec3(),Go=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.snapPickOrigin[0]=l[0],e.snapPickOrigin[1]=l[1],e.snapPickOrigin[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.snapPickCoordinateScale[0]=Z.safeInv(f[0]),e.snapPickCoordinateScale[1]=Z.safeInv(f[1]),e.snapPickCoordinateScale[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.snapPickLayerNumber),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}(),ko=Z.vec3(),Vo=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.snapPickOrigin[0]=l[0],e.snapPickOrigin[1]=l[1],e.snapPickOrigin[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.snapPickCoordinateScale[0]=Z.safeInv(c[0]),e.snapPickCoordinateScale[1]=Z.safeInv(c[1]),e.snapPickCoordinateScale[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.snapPickLayerNumber),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("gl_PointSize = 1.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("// 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}(),jo=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 Go(this._scene,!1)),this._snapDepthBufInitRenderer}},{key:"snapDepthRenderer",get:function(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Vo(this._scene)),this._snapDepthRenderer}},{key:"_destroy",value:function(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}]),e}(),Qo={};var Wo=Z.mat4(),zo=Z.mat4(),Ko=Z.vec4([0,0,0,1]),Yo=Z.vec4([0,0,0,1]),Xo=Z.vec4([0,0,0,1]),qo=Z.OBB3(),Jo=Z.vec3(),Zo=Z.vec3(),$o=Z.vec3(),el=Z.vec3(),tl=Z.vec3(),nl=Z.vec3(),rl=Z.vec3(),il=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=Oo[r])||(i=new Bo(n),Oo[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Oo[r],i._destroy()}))),i),this._snapBatchingRenderers=function(e){var t=e.id,n=Qo[t];return n||(n=new jo(e),Qo[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete Qo[t],n._destroy()}))),n}(t.model.scene),this._buffer=new So(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new St({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=Wo;h?Z.inverseMat4(Z.transposeMat4(h,zo),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,Ho(s=Fo(p,"floor","ceil"))))>u&&(o=s,u=l),(l=a(p,Ho(s=Fo(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):xo(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=pn.getUVBounds(n.uv),p=pn.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?eo.NOT_RENDERED:n?eo.COLOR_TRANSPARENT:eo.COLOR_OPAQUE,a=!p||y?eo.NOT_RENDERED:v?eo.SILHOUETTE_SELECTED:d?eo.SILHOUETTE_HIGHLIGHTED:A?eo.SILHOUETTE_XRAYED:eo.NOT_RENDERED;var m=0;m=!p||y?eo.NOT_RENDERED:v?eo.EDGES_SELECTED:d?eo.EDGES_HIGHLIGHTED:A?eo.EDGES_XRAYED:h?n?eo.EDGES_COLOR_TRANSPARENT:eo.EDGES_COLOR_OPAQUE:eo.NOT_RENDERED;var w=p&&!y&&I?eo.PICK:eo.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}(),al=function(e){I(n,lo);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}(),sl=function(e){I(n,lo);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}(),ll=function(e){I(n,uo);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}(),ul=function(e){I(n,uo);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}(),cl=function(e){I(n,lo);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}(),fl=function(e){I(n,lo);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}(),pl=function(e){I(n,lo);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}(),Al=function(e){I(n,lo);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}(),dl=function(e){I(n,lo);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}(),vl=function(e){I(n,lo);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}(),hl=function(e){I(n,lo);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}(),Il={3e3:"linearToLinear",3001:"sRGBToLinear"},yl=function(e){I(n,lo);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 = "+Il[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 = "+Il[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}(),wl=function(e){I(n,lo);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 I=i._sectionPlanesState.sectionPlanes,y=t.layerIndex*h,m=r.renderFlags,w=0;w0,n=[];return n.push("#version 300 es"),n.push("// SnapInstancingDepthBufInitRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),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}(),Dl=Z.vec3(),Pl=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;e.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[2]=o[2];var l=t.aabb,u=[Z.safeInv(l[3]-l[0])*Z.MAX_INT,Z.safeInv(l[4]-l[1])*Z.MAX_INT,Z.safeInv(l[5]-l[2])*Z.MAX_INT];if(e.snapPickCoordinateScale[0]=Z.safeInv(u[0]),e.snapPickCoordinateScale[1]=Z.safeInv(u[1]),e.snapPickCoordinateScale[2]=Z.safeInv(u[2]),this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var c=i.camera,f=c.eye;e.pickViewMatrix&&(f=e.pickOrigin||f);var p=[f[0]-o[0],f[1]-o[1],f[2]-o[2]];a.uniform3fv(this._uCameraEyeRtc,p),a.uniform2fv(this.uVectorA,e.snapVectorA),a.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),a.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),a.uniform3fv(this._uCoordinateScaler,u),a.uniform1i(this._uRenderPass,n),a.uniform1i(this._uPickInvisible,e.pickInvisible);var A=e.pickViewMatrix||c.viewMatrix,d=o?Ie(A,o):A;if(a.uniformMatrix4fv(this._uViewMatrix,!1,d),a.uniformMatrix4fv(this._uWorldMatrix,!1,r.worldMatrix),a.uniformMatrix4fv(this._uProjMatrix,!1,c.projMatrix),i.logarithmicDepthBufferEnabled){var v=2/(Math.log(e.pickZFar+1)/Math.LN2);a.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("// SnapInstancingDepthRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),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("gl_PointSize = 1.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("// SnapInstancingDepthRenderer 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}(),Rl=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 bl(this._scene,!1)),this._snapDepthBufInitRenderer}},{key:"snapDepthRenderer",get:function(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Pl(this._scene)),this._snapDepthRenderer}},{key:"_destroy",value:function(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}]),e}(),Cl={};var _l=new Uint8Array(4),Bl=new Float32Array(1),Ol=Z.vec4([0,0,0,1]),Sl=Z.vec4([0,0,0,1]),Nl=Z.vec4([0,0,0,1]),Ll=new Float32Array(3),xl=Z.vec3(),Ml=Z.vec3(),Fl=Z.vec3(),Hl=Z.vec3(),Ul=Z.vec3(),Gl=Z.vec3(),kl=Z.vec3(),Vl=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=Tl[r])||(i=new gl(n),Tl[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Tl[r],i._destroy()}))),i),this._snapInstancingRenderers=function(e){var t=e.id,n=Cl[t];return n||(n=new Rl(e),Cl[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete Cl[t],n._destroy()}))),n}(t.model.scene),this._aabb=Z.collapseAABB3(),this._state=new St({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";_l[0]=t[0],_l[1]=t[1],_l[2]=t[2],_l[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(_l,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?eo.NOT_RENDERED:n?eo.COLOR_TRANSPARENT:eo.COLOR_OPAQUE,c|=(!r||u?eo.NOT_RENDERED:s?eo.SILHOUETTE_SELECTED:a?eo.SILHOUETTE_HIGHLIGHTED:i?eo.SILHOUETTE_XRAYED:eo.NOT_RENDERED)<<4,c|=(!r||u?eo.NOT_RENDERED:s?eo.EDGES_SELECTED:a?eo.EDGES_HIGHLIGHTED:i?eo.EDGES_XRAYED:o?n?eo.EDGES_COLOR_TRANSPARENT:eo.EDGES_COLOR_OPAQUE:eo.NOT_RENDERED)<<8,c|=(r&&!u&&l?eo.PICK:eo.NOT_RENDERED)<<12,c|=(t&De?1:0)<<16,Bl[0]=c,this._state.flagsBuf&&this._state.flagsBuf.setData(Bl,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Ll[0]=t[0],Ll[1]=t[1],Ll[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Ll,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=Ol,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}(),jl=function(e){I(n,po);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}(),Ql=function(e){I(n,po);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}(),Wl=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 jl(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Ql(this._scene)),this._silhouetteRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}]),e}(),zl={};var Kl=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=[]})),Yl=Z.vec4([0,0,0,1]),Xl=Z.vec4([0,0,0,1]),ql=Z.vec4([0,0,0,1]),Jl=Z.OBB3(),Zl=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=zl[r])||(i=new Wl(n),zl[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete zl[r],i._destroy()}))),i),this.model=t.model,this._buffer=new Kl(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new St({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=xo(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?eo.NOT_RENDERED:n?eo.COLOR_TRANSPARENT:eo.COLOR_OPAQUE,a=!f||h?eo.NOT_RENDERED:d?eo.SILHOUETTE_SELECTED:A?eo.SILHOUETTE_HIGHLIGHTED:p?eo.SILHOUETTE_XRAYED:eo.NOT_RENDERED;var I=f&&!h&&v?eo.PICK:eo.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}(),eu=function(e){I(n,Ao);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}(),tu=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 $l(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new eu(this._scene)),this._silhouetteRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}]),e}(),nu={};var ru=new Uint8Array(4),iu=new Float32Array(1),au=Z.vec4([0,0,0,1]),su=Z.vec4([0,0,0,1]),ou=Z.vec4([0,0,0,1]),lu=new Float32Array(3),uu=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=nu[r])||(i=new tu(n),nu[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete nu[r],i._destroy()}))),i),this._aabb=Z.collapseAABB3(),this._state=new St({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";ru[0]=t[0],ru[1]=t[1],ru[2]=t[2],ru[3]=t[3],this._state.colorsBuf.setData(ru,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?eo.NOT_RENDERED:n?eo.COLOR_TRANSPARENT:eo.COLOR_OPAQUE,c|=(!r||u?eo.NOT_RENDERED:s?eo.SILHOUETTE_SELECTED:a?eo.SILHOUETTE_HIGHLIGHTED:i?eo.SILHOUETTE_XRAYED:eo.NOT_RENDERED)<<4,c|=(!r||u?eo.NOT_RENDERED:s?eo.EDGES_SELECTED:a?eo.EDGES_HIGHLIGHTED:i?eo.EDGES_XRAYED:o?n?eo.EDGES_COLOR_TRANSPARENT:eo.EDGES_COLOR_OPAQUE:eo.NOT_RENDERED)<<8,c|=(r&&!u&&l?eo.PICK:eo.NOT_RENDERED)<<12,c|=(t&De?255:0)<<16,iu[0]=c,this._state.flagsBuf.setData(iu,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(lu[0]=t[0],lu[1]=t[1],lu[2]=t[2],this._state.offsetsBuf.setData(lu,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,eo.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,eo.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,eo.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,eo.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,eo.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}(),cu=function(e){I(n,co);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}(),fu=function(e){I(n,co);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}(),pu=function(e){I(n,co);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}(),Au=function(e){I(n,co);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}(),du=function(e){I(n,co);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}(),vu=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 cu(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new fu(this._scene)),this._silhouetteRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new pu(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Au(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new du(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}(),hu={};var Iu=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=[]})),yu=Z.vec4(),mu=Z.vec4(),wu=Z.vec4([0,0,0,1]),gu=Z.vec4([0,0,0,1]),Tu=Z.vec4([0,0,0,1]),Eu=Z.OBB3(),bu=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=hu[t];return n||(n=new vu(e),hu[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete hu[t],n._destroy()}))),n}(t.model.scene),this._buffer=new Iu(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new St({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=xo(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}(),Pu=function(e){I(n,fo);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}(),Ru=function(e){I(n,fo);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}(),Cu=function(e){I(n,fo);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}(),_u=function(e){I(n,fo);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}(),Bu=function(e){I(n,fo);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}(),Ou=function(e){I(n,fo);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}(),Su=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 Du(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Pu(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new Bu(this._scene)),this._depthRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Ru(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Cu(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new _u(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new Ou(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}(),Nu={};var Lu=new Uint8Array(4),xu=new Float32Array(1),Mu=Z.vec4([0,0,0,1]),Fu=Z.vec4([0,0,0,1]),Hu=Z.vec4([0,0,0,1]),Uu=new Float32Array(3),Gu=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=Nu[r])||(i=new Su(n),Nu[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Nu[r],i._destroy()}))),i),this._aabb=Z.collapseAABB3(),this._state=new St({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";Lu[0]=t[0],Lu[1]=t[1],Lu[2]=t[2],this._state.colorsBuf.setData(Lu,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?eo.NOT_RENDERED:n?eo.COLOR_TRANSPARENT:eo.COLOR_OPAQUE,c|=(!r||u?eo.NOT_RENDERED:s?eo.SILHOUETTE_SELECTED:a?eo.SILHOUETTE_HIGHLIGHTED:i?eo.SILHOUETTE_XRAYED:eo.NOT_RENDERED)<<4,c|=(!r||u?eo.NOT_RENDERED:s?eo.EDGES_SELECTED:a?eo.EDGES_HIGHLIGHTED:i?eo.EDGES_XRAYED:o?n?eo.EDGES_COLOR_TRANSPARENT:eo.EDGES_COLOR_OPAQUE:eo.NOT_RENDERED)<<8,c|=(r&&!u&&l?eo.PICK:eo.NOT_RENDERED)<<12,c|=(t&De?255:0)<<16,xu[0]=c,this._state.flagsBuf.setData(xu,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Uu[0]=t[0],Uu[1]=t[1],Uu[2]=t[2],this._state.offsetsBuf.setData(Uu,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,eo.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,eo.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,eo.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,eo.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,eo.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,eo.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,eo.PICK)}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,eo.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}(),ku=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}(),Vu=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}(),ju={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={}}},Qu=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."),qu++}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(),qu--}}]),e}();Ju.BasisFormat={ETC1S:0,UASTC_4x4:1},Ju.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},Ju.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},Ju.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;d0){o=function(e){for(var t=[],n=0,r=e.length;nthis._frustumProps.CAM_FACTOR_1?(n|=l<0?64:128,n&=-17):n&=-33;var u=er(Z.dotVec3(s,this._frustumProps.up),o);Math.abs(u)>this._frustumProps.CAM_FACTOR_2?(n|=u<0?1024:2048,n&=-257):n&=-513}return 4&n&&8&n&&(n|=4096),64&n&&128&n&&(n|=8192),1024&n&&2048&n&&(n|=16384),e._check=n,n}}]),e}(),nr=function(){function e(t,n){b(this,e),this.sceneModel=n,this.entities=[],this.meshes=[],this.finalized=!1}return P(e,[{key:"addEntity",value:function(e){if(this.finalized)throw"Already finalized";this.entities.push(e)}},{key:"addMesh",value:function(e){if(this.finalized)throw"Already finalized";this.meshes.push(e)}},{key:"finalize",value:function(e){var t=this;if(this.finalized)throw"Already finalized";this.finalized=!0,this.VFCState=new tr,this.VFCState.initializeVFCState(this.entities,this.meshes),this.VFCState.finalize(this.sceneModel,e),this._onSceneRendering=this.sceneModel.scene.on("rendering",(function(){return t.applyViewFrustumCulling.call(t)}))}},{key:"applyViewFrustumCulling",value:function(){this.finalized&&this.VFCState.applyViewFrustumCulling(this.sceneModel)}},{key:"destroy",value:function(){this.finalized&&this.sceneModel.off(this._onSceneRendering)}}]),e}(),rr=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._scene=e,r._vfcManagers={},r._vfcManagerList=[],r.enabled=i.enabled,r._init(),r}return P(n,[{key:"_init",value:function(){var e=this;this._scene.on("rendering",(function(){for(var t=0,n=e._vfcManagerList.length;t1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),r=t.call(this,null,i);var a=i.canvasElement||document.getElementById(i.canvasId);if(!(a instanceof HTMLCanvasElement))throw"Mandatory config expected: valid canvasId or canvasElement";var s=!!i.transparent,o=!!i.alphaDepthMask;return r._aabbDirty=!0,r.viewer=e,r.occlusionTestCountdown=0,r.loading=0,r.startTime=(new Date).getTime(),r.models={},r.objects={},r._numObjects=0,r.visibleObjects={},r._numVisibleObjects=0,r.xrayedObjects={},r._numXRayedObjects=0,r.highlightedObjects={},r._numHighlightedObjects=0,r.selectedObjects={},r._numSelectedObjects=0,r.colorizedObjects={},r._numColorizedObjects=0,r.opacityObjects={},r._numOpacityObjects=0,r.offsetObjects={},r._numOffsetObjects=0,r._modelIds=null,r._objectIds=null,r._visibleObjectIds=null,r._xrayedObjectIds=null,r._highlightedObjectIds=null,r._selectedObjectIds=null,r._colorizedObjectIds=null,r._opacityObjectIds=null,r._offsetObjectIds=null,r._collidables={},r._compilables={},r._needRecompile=!1,r.types={},r.components={},r.sectionPlanes={},r.lights={},r.lightMaps={},r.reflectionMaps={},r.bitmaps={},r.lineSets={},r.realWorldOffset=i.realWorldOffset||new Float64Array([0,0,0]),r.canvas=new nt(g(r),{dontClear:!0,canvas:a,spinnerElementId:i.spinnerElementId,transparent:s,webgl2:!1!==i.webgl2,contextAttr:i.contextAttr||{},backgroundColor:i.backgroundColor,backgroundColorFromAmbientLight:i.backgroundColorFromAmbientLight,premultipliedAlpha:i.premultipliedAlpha}),r.canvas.on("boundary",(function(){r.glRedraw()})),r.canvas.on("webglContextFailed",(function(){alert("xeokit failed to find WebGL!")})),r._renderer=new _t(g(r),{transparent:s,alphaDepthMask:o}),r._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1;var e=null;this.getHash=function(){if(e)return e;var t=this.sectionPlanes;if(0===t.length)return this.hash=";";for(var n=[],r=0,i=t.length;r0&&t.push("/lm"),this.reflectionMaps.length>0&&t.push("/rm"),t.push(";"),n=t.join("")},this.addLight=function(e){this.lights.push(e),r=null,n=null},this.removeLight=function(e){for(var t=0,i=this.lights.length;t1&&void 0!==arguments[1])||arguments[1];e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}},{key:"_objectXRayedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}},{key:"_objectHighlightedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null,t&&this.fire("objectHighlighted",e,!0)}},{key:"_objectSelectedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}},{key:"_objectColorizeUpdated",value:function(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}},{key:"_objectOpacityUpdated",value:function(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}},{key:"_objectOffsetUpdated",value:function(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}},{key:"_webglContextLost",value:function(){for(var e in this.canvas.spinner.processes++,this.components)if(this.components.hasOwnProperty(e)){var t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}},{key:"_webglContextRestored",value:function(){var e=this.canvas.gl;for(var t in this.components)if(this.components.hasOwnProperty(t)){var n=this.components[t];n._webglContextRestored&&n._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}},{key:"capabilities",get:function(){return this._renderer.capabilities}},{key:"entityOffsetsEnabled",get:function(){return this._entityOffsetsEnabled}},{key:"pickSurfacePrecisionEnabled",get:function(){return!1}},{key:"logarithmicDepthBufferEnabled",get:function(){return this._logarithmicDepthBufferEnabled}},{key:"pbrEnabled",get:function(){return this._pbrEnabled},set:function(e){this._pbrEnabled=!!e,this.glRedraw()}},{key:"dtxEnabled",get:function(){return this._dtxEnabled},set:function(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled},set:function(e){this._colorTextureEnabled=!!e,this.glRedraw()}},{key:"doOcclusionTest",value:function(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}},{key:"render",value:function(e){e&&Ae.runTasks();var t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),e||this._renderer.needsRender()){t.sceneId=this.id;var n,r,i=this._passes,a=this._clearEachPass;for(n=0;na&&(a=e[3]),e[4]>s&&(s=e[4]),e[5]>o&&(o=e[5]),u=!0}u||(n=-100,r=-100,i=-100,a=100,s=100,o=100),this._aabb[0]=n,this._aabb[1]=r,this._aabb[2]=i,this._aabb[3]=a,this._aabb[4]=s,this._aabb[5]=o,this._aabbDirty=!1}return this._aabb}},{key:"_setAABBDirty",value:function(){this._aabbDirty=!0,this.fire("boundary")}},{key:"pick",value:function(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");var n=e.includeEntities||e.include;n&&(e.includeEntityIds=ir(this,n));var r=e.excludeEntities||e.exclude;return r&&(e.excludeEntityIds=ir(this,r)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=this._renderer.pick(e,t))?(t.entity&&t.entity.fire&&t.entity.fire("picked",t),t):void 0}},{key:"snapPick",value:function(e){return this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapMode||"vertex")}},{key:"clear",value:function(){var e;for(var t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}},{key:"clearLights",value:function(){for(var e=Object.keys(this.lights),t=0,n=e.length;ts&&(s=t[3]),t[4]>o&&(o=t[4]),t[5]>l&&(l=t[5]),n=!0}})),n){var u=Z.AABB3();return u[0]=r,u[1]=i,u[2]=a,u[3]=s,u[4]=o,u[5]=l,u}return this.aabb}},{key:"setObjectsVisible",value:function(e,t){return this.withObjects(e,(function(e){var n=e.visible!==t;return e.visible=t,n}))}},{key:"setObjectsCollidable",value:function(e,t){return this.withObjects(e,(function(e){var n=e.collidable!==t;return e.collidable=t,n}))}},{key:"setObjectsCulled",value:function(e,t){return this.withObjects(e,(function(e){var n=e.culled!==t;return e.culled=t,n}))}},{key:"setObjectsSelected",value:function(e,t){return this.withObjects(e,(function(e){var n=e.selected!==t;return e.selected=t,n}))}},{key:"setObjectsHighlighted",value:function(e,t){return this.withObjects(e,(function(e){var n=e.highlighted!==t;return e.highlighted=t,n}))}},{key:"setObjectsXRayed",value:function(e,t){return this.withObjects(e,(function(e){var n=e.xrayed!==t;return e.xrayed=t,n}))}},{key:"setObjectsEdges",value:function(e,t){return this.withObjects(e,(function(e){var n=e.edges!==t;return e.edges=t,n}))}},{key:"setObjectsColorized",value:function(e,t){return this.withObjects(e,(function(e){e.colorize=t}))}},{key:"setObjectsOpacity",value:function(e,t){return this.withObjects(e,(function(e){var n=e.opacity!==t;return e.opacity=t,n}))}},{key:"setObjectsPickable",value:function(e,t){return this.withObjects(e,(function(e){var n=e.pickable!==t;return e.pickable=t,n}))}},{key:"setObjectsOffset",value:function(e,t){this.withObjects(e,(function(e){e.offset=t}))}},{key:"withObjects",value:function(e,t){ae.isString(e)&&(e=[e]);for(var n=!1,r=0,i=e.length;r0,l=!!i.compressGeometry,u=[];u.push("#version 300 es"),u.push("// Lambertian drawing vertex shader"),u.push("in vec3 position;"),u.push("uniform mat4 modelMatrix;"),u.push("uniform mat4 viewMatrix;"),u.push("uniform mat4 projMatrix;"),u.push("uniform vec4 colorize;"),u.push("uniform vec3 offset;"),l&&u.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(u.push("uniform float logDepthBufFC;"),u.push("out float vFragDepth;"),u.push("bool isPerspectiveMatrix(mat4 m) {"),u.push(" return (m[2][3] == - 1.0);"),u.push("}"),u.push("out float isPerspective;"));o&&u.push("out vec4 vWorldPosition;");if(u.push("uniform vec4 lightAmbient;"),u.push("uniform vec4 materialColor;"),u.push("uniform vec3 materialEmissive;"),i.normalsBuf){u.push("in vec3 normal;"),u.push("uniform mat4 modelNormalMatrix;"),u.push("uniform mat4 viewNormalMatrix;");for(var c=0,f=r.lights.length;c= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),u.push(" }"),u.push(" return normalize(v);"),u.push("}"))}u.push("out vec4 vColor;"),"points"===i.primitiveName&&u.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(u.push("void billboard(inout mat4 mat) {"),u.push(" mat[0][0] = 1.0;"),u.push(" mat[0][1] = 0.0;"),u.push(" mat[0][2] = 0.0;"),"spherical"===a&&(u.push(" mat[1][0] = 0.0;"),u.push(" mat[1][1] = 1.0;"),u.push(" mat[1][2] = 0.0;")),u.push(" mat[2][0] = 0.0;"),u.push(" mat[2][1] = 0.0;"),u.push(" mat[2][2] =1.0;"),u.push("}"));u.push("void main(void) {"),u.push("vec4 localPosition = vec4(position, 1.0); "),u.push("vec4 worldPosition;"),l&&u.push("localPosition = positionsDecodeMatrix * localPosition;");i.normalsBuf&&(l?u.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):u.push("vec4 localNormal = vec4(normal, 0.0); "),u.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),u.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));u.push("mat4 viewMatrix2 = viewMatrix;"),u.push("mat4 modelMatrix2 = modelMatrix;"),s&&u.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===a||"cylindrical"===a?(u.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),u.push("billboard(modelMatrix2);"),u.push("billboard(viewMatrix2);"),u.push("billboard(modelViewMatrix);"),i.normalsBuf&&(u.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),u.push("billboard(modelNormalMatrix2);"),u.push("billboard(viewNormalMatrix2);"),u.push("billboard(modelViewNormalMatrix);")),u.push("worldPosition = modelMatrix2 * localPosition;"),u.push("worldPosition.xyz = worldPosition.xyz + offset;"),u.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(u.push("worldPosition = modelMatrix2 * localPosition;"),u.push("worldPosition.xyz = worldPosition.xyz + offset;"),u.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i.normalsBuf&&u.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(u.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),u.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),u.push("float lambertian = 1.0;"),i.normalsBuf)for(var A=0,d=r.lights.length;A0,a=t.gammaOutput,s=[];s.push("#version 300 es"),s.push("// Lambertian drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"));if(i){s.push("in vec4 vWorldPosition;"),s.push("uniform bool clippable;");for(var o=0,l=n.sectionPlanes.length;o 0.0) { discard; }"),s.push("}")}"points"===r.primitiveName&&(s.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),s.push("float r = dot(cxy, cxy);"),s.push("if (r > 1.0) {"),s.push(" discard;"),s.push("}"));t.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");a?s.push("outColor = linearToGamma(vColor, gammaFactor);"):s.push("outColor = vColor;");return s.push("}"),s}(e)):(this.vertex=function(e){var t=e.scene;e._material;var n,r=e._state,i=t._sectionPlanesState,a=e._geometry._state,s=t._lightsState,o=r.billboard,l=r.background,u=r.stationary,c=function(e){if(!e._geometry._state.uvBuf)return!1;var t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),f=Ei(e),p=i.sectionPlanes.length>0,A=Ti(e),d=!!a.compressGeometry,v=[];v.push("#version 300 es"),v.push("// Drawing vertex shader"),v.push("in vec3 position;"),d&&v.push("uniform mat4 positionsDecodeMatrix;");v.push("uniform mat4 modelMatrix;"),v.push("uniform mat4 viewMatrix;"),v.push("uniform mat4 projMatrix;"),v.push("out vec3 vViewPosition;"),v.push("uniform vec3 offset;"),p&&v.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(v.push("uniform float logDepthBufFC;"),v.push("out float vFragDepth;"),v.push("bool isPerspectiveMatrix(mat4 m) {"),v.push(" return (m[2][3] == - 1.0);"),v.push("}"),v.push("out float isPerspective;"));s.lightMaps.length>0&&v.push("out vec3 vWorldNormal;");if(f){v.push("in vec3 normal;"),v.push("uniform mat4 modelNormalMatrix;"),v.push("uniform mat4 viewNormalMatrix;"),v.push("out vec3 vViewNormal;");for(var h=0,I=s.lights.length;h= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),v.push(" }"),v.push(" return normalize(v);"),v.push("}"))}c&&(v.push("in vec2 uv;"),v.push("out vec2 vUV;"),d&&v.push("uniform mat3 uvDecodeMatrix;"));a.colors&&(v.push("in vec4 color;"),v.push("out vec4 vColor;"));"points"===a.primitiveName&&v.push("uniform float pointSize;");"spherical"!==o&&"cylindrical"!==o||(v.push("void billboard(inout mat4 mat) {"),v.push(" mat[0][0] = 1.0;"),v.push(" mat[0][1] = 0.0;"),v.push(" mat[0][2] = 0.0;"),"spherical"===o&&(v.push(" mat[1][0] = 0.0;"),v.push(" mat[1][1] = 1.0;"),v.push(" mat[1][2] = 0.0;")),v.push(" mat[2][0] = 0.0;"),v.push(" mat[2][1] = 0.0;"),v.push(" mat[2][2] =1.0;"),v.push("}"));if(A){v.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(var y=0,m=s.lights.length;y0&&v.push("vWorldNormal = worldNormal;"),v.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),v.push("vec3 tmpVec3;"),v.push("float lightDist;");for(var w=0,g=s.lights.length;w0,l=Ei(e),u=r.uvBuf,c="PhongMaterial"===s.type,f="MetallicMaterial"===s.type,p="SpecularMaterial"===s.type,A=Ti(e);t.gammaInput;var d=t.gammaOutput,v=[];v.push("#version 300 es"),v.push("// Drawing fragment shader"),v.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),v.push("precision highp float;"),v.push("precision highp int;"),v.push("#else"),v.push("precision mediump float;"),v.push("precision mediump int;"),v.push("#endif"),t.logarithmicDepthBufferEnabled&&(v.push("in float isPerspective;"),v.push("uniform float logDepthBufFC;"),v.push("in float vFragDepth;"));A&&(v.push("float unpackDepth (vec4 color) {"),v.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),v.push(" return dot(color, bitShift);"),v.push("}"));v.push("uniform float gammaFactor;"),v.push("vec4 linearToLinear( in vec4 value ) {"),v.push(" return value;"),v.push("}"),v.push("vec4 sRGBToLinear( in vec4 value ) {"),v.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),v.push("}"),v.push("vec4 gammaToLinear( in vec4 value) {"),v.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),v.push("}"),d&&(v.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),v.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),v.push("}"));if(o){v.push("in vec4 vWorldPosition;"),v.push("uniform bool clippable;");for(var h=0;h0&&(v.push("uniform samplerCube lightMap;"),v.push("uniform mat4 viewNormalMatrix;")),a.reflectionMaps.length>0&&v.push("uniform samplerCube reflectionMap;"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&v.push("uniform mat4 viewMatrix;"),v.push("#define PI 3.14159265359"),v.push("#define RECIPROCAL_PI 0.31830988618"),v.push("#define RECIPROCAL_PI2 0.15915494"),v.push("#define EPSILON 1e-6"),v.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),v.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),v.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),v.push("}"),v.push("struct IncidentLight {"),v.push(" vec3 color;"),v.push(" vec3 direction;"),v.push("};"),v.push("struct ReflectedLight {"),v.push(" vec3 diffuse;"),v.push(" vec3 specular;"),v.push("};"),v.push("struct Geometry {"),v.push(" vec3 position;"),v.push(" vec3 viewNormal;"),v.push(" vec3 worldNormal;"),v.push(" vec3 viewEyeDir;"),v.push("};"),v.push("struct Material {"),v.push(" vec3 diffuseColor;"),v.push(" float specularRoughness;"),v.push(" vec3 specularColor;"),v.push(" float shine;"),v.push("};"),c&&((a.lightMaps.length>0||a.reflectionMaps.length>0)&&(v.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(v.push(" vec3 irradiance = "+gi[a.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),v.push(" irradiance *= PI;"),v.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(v.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),v.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),v.push(" radiance *= PI;"),v.push(" reflectedLight.specular += radiance;")),v.push("}")),v.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),v.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),v.push(" vec3 irradiance = dotNL * directLight.color * PI;"),v.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),v.push("}")),(f||p)&&(v.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),v.push(" float r = ggxRoughness + 0.0001;"),v.push(" return (2.0 / (r * r) - 2.0);"),v.push("}"),v.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),v.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),v.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),v.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),v.push("}"),a.reflectionMaps.length>0&&(v.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),v.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),v.push(" vec3 envMapColor = "+gi[a.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),v.push(" return envMapColor;"),v.push("}")),v.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),v.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),v.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),v.push("}"),v.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),v.push(" float a2 = ( alpha * alpha );"),v.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),v.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),v.push(" return 1.0 / ( gl * gv );"),v.push("}"),v.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),v.push(" float a2 = ( alpha * alpha );"),v.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),v.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),v.push(" return 0.5 / max( gv + gl, EPSILON );"),v.push("}"),v.push("float D_GGX(const in float alpha, const in float dotNH) {"),v.push(" float a2 = ( alpha * alpha );"),v.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),v.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),v.push("}"),v.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),v.push(" float alpha = ( roughness * roughness );"),v.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),v.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),v.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),v.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),v.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),v.push(" vec3 F = F_Schlick( specularColor, dotLH );"),v.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),v.push(" float D = D_GGX( alpha, dotNH );"),v.push(" return F * (G * D);"),v.push("}"),v.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),v.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),v.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),v.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),v.push(" vec4 r = roughness * c0 + c1;"),v.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),v.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),v.push(" return specularColor * AB.x + AB.y;"),v.push("}"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&(v.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(v.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),v.push(" irradiance *= PI;"),v.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(v.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),v.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),v.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),v.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),v.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),v.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),v.push("}")),v.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),v.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),v.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),v.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),v.push("}")));v.push("in vec3 vViewPosition;"),r.colors&&v.push("in vec4 vColor;");u&&(l&&n._normalMap||n._ambientMap||n._baseColorMap||n._diffuseMap||n._emissiveMap||n._metallicMap||n._roughnessMap||n._metallicRoughnessMap||n._specularMap||n._glossinessMap||n._specularGlossinessMap||n._occlusionMap||n._alphaMap)&&v.push("in vec2 vUV;");l&&(a.lightMaps.length>0&&v.push("in vec3 vWorldNormal;"),v.push("in vec3 vViewNormal;"));s.ambient&&v.push("uniform vec3 materialAmbient;");s.baseColor&&v.push("uniform vec3 materialBaseColor;");void 0!==s.alpha&&null!==s.alpha&&v.push("uniform vec4 materialAlphaModeCutoff;");s.emissive&&v.push("uniform vec3 materialEmissive;");s.diffuse&&v.push("uniform vec3 materialDiffuse;");void 0!==s.glossiness&&null!==s.glossiness&&v.push("uniform float materialGlossiness;");void 0!==s.shininess&&null!==s.shininess&&v.push("uniform float materialShininess;");s.specular&&v.push("uniform vec3 materialSpecular;");void 0!==s.metallic&&null!==s.metallic&&v.push("uniform float materialMetallic;");void 0!==s.roughness&&null!==s.roughness&&v.push("uniform float materialRoughness;");void 0!==s.specularF0&&null!==s.specularF0&&v.push("uniform float materialSpecularF0;");u&&n._ambientMap&&(v.push("uniform sampler2D ambientMap;"),n._ambientMap._state.matrix&&v.push("uniform mat4 ambientMapMatrix;"));u&&n._baseColorMap&&(v.push("uniform sampler2D baseColorMap;"),n._baseColorMap._state.matrix&&v.push("uniform mat4 baseColorMapMatrix;"));u&&n._diffuseMap&&(v.push("uniform sampler2D diffuseMap;"),n._diffuseMap._state.matrix&&v.push("uniform mat4 diffuseMapMatrix;"));u&&n._emissiveMap&&(v.push("uniform sampler2D emissiveMap;"),n._emissiveMap._state.matrix&&v.push("uniform mat4 emissiveMapMatrix;"));l&&u&&n._metallicMap&&(v.push("uniform sampler2D metallicMap;"),n._metallicMap._state.matrix&&v.push("uniform mat4 metallicMapMatrix;"));l&&u&&n._roughnessMap&&(v.push("uniform sampler2D roughnessMap;"),n._roughnessMap._state.matrix&&v.push("uniform mat4 roughnessMapMatrix;"));l&&u&&n._metallicRoughnessMap&&(v.push("uniform sampler2D metallicRoughnessMap;"),n._metallicRoughnessMap._state.matrix&&v.push("uniform mat4 metallicRoughnessMapMatrix;"));l&&n._normalMap&&(v.push("uniform sampler2D normalMap;"),n._normalMap._state.matrix&&v.push("uniform mat4 normalMapMatrix;"),v.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),v.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),v.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),v.push(" vec2 st0 = dFdx( uv.st );"),v.push(" vec2 st1 = dFdy( uv.st );"),v.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),v.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),v.push(" vec3 N = normalize( surf_norm );"),v.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),v.push(" mat3 tsn = mat3( S, T, N );"),v.push(" return normalize( tsn * mapN );"),v.push("}"));u&&n._occlusionMap&&(v.push("uniform sampler2D occlusionMap;"),n._occlusionMap._state.matrix&&v.push("uniform mat4 occlusionMapMatrix;"));u&&n._alphaMap&&(v.push("uniform sampler2D alphaMap;"),n._alphaMap._state.matrix&&v.push("uniform mat4 alphaMapMatrix;"));l&&u&&n._specularMap&&(v.push("uniform sampler2D specularMap;"),n._specularMap._state.matrix&&v.push("uniform mat4 specularMapMatrix;"));l&&u&&n._glossinessMap&&(v.push("uniform sampler2D glossinessMap;"),n._glossinessMap._state.matrix&&v.push("uniform mat4 glossinessMapMatrix;"));l&&u&&n._specularGlossinessMap&&(v.push("uniform sampler2D materialSpecularGlossinessMap;"),n._specularGlossinessMap._state.matrix&&v.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));l&&(n._diffuseFresnel||n._specularFresnel||n._alphaFresnel||n._emissiveFresnel||n._reflectivityFresnel)&&(v.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),v.push(" float fr = abs(dot(eyeDir, normal));"),v.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),v.push(" return pow(finalFr, power);"),v.push("}"),n._diffuseFresnel&&(v.push("uniform float diffuseFresnelCenterBias;"),v.push("uniform float diffuseFresnelEdgeBias;"),v.push("uniform float diffuseFresnelPower;"),v.push("uniform vec3 diffuseFresnelCenterColor;"),v.push("uniform vec3 diffuseFresnelEdgeColor;")),n._specularFresnel&&(v.push("uniform float specularFresnelCenterBias;"),v.push("uniform float specularFresnelEdgeBias;"),v.push("uniform float specularFresnelPower;"),v.push("uniform vec3 specularFresnelCenterColor;"),v.push("uniform vec3 specularFresnelEdgeColor;")),n._alphaFresnel&&(v.push("uniform float alphaFresnelCenterBias;"),v.push("uniform float alphaFresnelEdgeBias;"),v.push("uniform float alphaFresnelPower;"),v.push("uniform vec3 alphaFresnelCenterColor;"),v.push("uniform vec3 alphaFresnelEdgeColor;")),n._reflectivityFresnel&&(v.push("uniform float materialSpecularF0FresnelCenterBias;"),v.push("uniform float materialSpecularF0FresnelEdgeBias;"),v.push("uniform float materialSpecularF0FresnelPower;"),v.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),v.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),n._emissiveFresnel&&(v.push("uniform float emissiveFresnelCenterBias;"),v.push("uniform float emissiveFresnelEdgeBias;"),v.push("uniform float emissiveFresnelPower;"),v.push("uniform vec3 emissiveFresnelCenterColor;"),v.push("uniform vec3 emissiveFresnelEdgeColor;")));if(v.push("uniform vec4 lightAmbient;"),l)for(var I=0,y=a.lights.length;I 0.0) { discard; }"),v.push("}")}"points"===r.primitiveName&&(v.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),v.push("float r = dot(cxy, cxy);"),v.push("if (r > 1.0) {"),v.push(" discard;"),v.push("}"));v.push("float occlusion = 1.0;"),s.ambient?v.push("vec3 ambientColor = materialAmbient;"):v.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");s.diffuse?v.push("vec3 diffuseColor = materialDiffuse;"):s.baseColor?v.push("vec3 diffuseColor = materialBaseColor;"):v.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");r.colors&&v.push("diffuseColor *= vColor.rgb;");s.emissive?v.push("vec3 emissiveColor = materialEmissive;"):v.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");s.specular?v.push("vec3 specular = materialSpecular;"):v.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==s.alpha?v.push("float alpha = materialAlphaModeCutoff[0];"):v.push("float alpha = 1.0;");r.colors&&v.push("alpha *= vColor.a;");void 0!==s.glossiness?v.push("float glossiness = materialGlossiness;"):v.push("float glossiness = 1.0;");void 0!==s.metallic?v.push("float metallic = materialMetallic;"):v.push("float metallic = 1.0;");void 0!==s.roughness?v.push("float roughness = materialRoughness;"):v.push("float roughness = 1.0;");void 0!==s.specularF0?v.push("float specularF0 = materialSpecularF0;"):v.push("float specularF0 = 1.0;");u&&(l&&n._normalMap||n._ambientMap||n._baseColorMap||n._diffuseMap||n._occlusionMap||n._emissiveMap||n._metallicMap||n._roughnessMap||n._metallicRoughnessMap||n._specularMap||n._glossinessMap||n._specularGlossinessMap||n._alphaMap)&&(v.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),v.push("vec2 textureCoord;"));u&&n._ambientMap&&(n._ambientMap._state.matrix?v.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),v.push("ambientTexel = "+gi[n._ambientMap._state.encoding]+"(ambientTexel);"),v.push("ambientColor *= ambientTexel.rgb;"));u&&n._diffuseMap&&(n._diffuseMap._state.matrix?v.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),v.push("diffuseTexel = "+gi[n._diffuseMap._state.encoding]+"(diffuseTexel);"),v.push("diffuseColor *= diffuseTexel.rgb;"),v.push("alpha *= diffuseTexel.a;"));u&&n._baseColorMap&&(n._baseColorMap._state.matrix?v.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),v.push("baseColorTexel = "+gi[n._baseColorMap._state.encoding]+"(baseColorTexel);"),v.push("diffuseColor *= baseColorTexel.rgb;"),v.push("alpha *= baseColorTexel.a;"));u&&n._emissiveMap&&(n._emissiveMap._state.matrix?v.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),v.push("emissiveTexel = "+gi[n._emissiveMap._state.encoding]+"(emissiveTexel);"),v.push("emissiveColor = emissiveTexel.rgb;"));u&&n._alphaMap&&(n._alphaMap._state.matrix?v.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("alpha *= texture(alphaMap, textureCoord).r;"));u&&n._occlusionMap&&(n._occlusionMap._state.matrix?v.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(l&&(a.lights.length>0||a.lightMaps.length>0||a.reflectionMaps.length>0)){u&&n._normalMap?(n._normalMap._state.matrix?v.push("textureCoord = (normalMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):v.push("vec3 viewNormal = normalize(vViewNormal);"),u&&n._specularMap&&(n._specularMap._state.matrix?v.push("textureCoord = (specularMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("specular *= texture(specularMap, textureCoord).rgb;")),u&&n._glossinessMap&&(n._glossinessMap._state.matrix?v.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("glossiness *= texture(glossinessMap, textureCoord).r;")),u&&n._specularGlossinessMap&&(n._specularGlossinessMap._state.matrix?v.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),v.push("specular *= specGlossRGB.rgb;"),v.push("glossiness *= specGlossRGB.a;")),u&&n._metallicMap&&(n._metallicMap._state.matrix?v.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("metallic *= texture(metallicMap, textureCoord).r;")),u&&n._roughnessMap&&(n._roughnessMap._state.matrix?v.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("roughness *= texture(roughnessMap, textureCoord).r;")),u&&n._metallicRoughnessMap&&(n._metallicRoughnessMap._state.matrix?v.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),v.push("metallic *= metalRoughRGB.b;"),v.push("roughness *= metalRoughRGB.g;")),v.push("vec3 viewEyeDir = normalize(-vViewPosition);"),n._diffuseFresnel&&(v.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),v.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),n._specularFresnel&&(v.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),v.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),n._alphaFresnel&&(v.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),v.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),n._emissiveFresnel&&(v.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),v.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),v.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),v.push(" discard;"),v.push("}"),v.push("IncidentLight light;"),v.push("Material material;"),v.push("Geometry geometry;"),v.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),v.push("vec3 viewLightDir;"),c&&(v.push("material.diffuseColor = diffuseColor;"),v.push("material.specularColor = specular;"),v.push("material.shine = materialShininess;")),p&&(v.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),v.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),v.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),v.push("material.specularColor = specular;")),f&&(v.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),v.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),v.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),v.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),v.push("geometry.position = vViewPosition;"),a.lightMaps.length>0&&v.push("geometry.worldNormal = normalize(vWorldNormal);"),v.push("geometry.viewNormal = viewNormal;"),v.push("geometry.viewEyeDir = viewEyeDir;"),c&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&v.push("computePhongLightMapping(geometry, material, reflectedLight);"),(p||f)&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&v.push("computePBRLightMapping(geometry, material, reflectedLight);"),v.push("float shadow = 1.0;"),v.push("float shadowAcneRemover = 0.007;"),v.push("vec3 fragmentDepth;"),v.push("float texelSize = 1.0 / 1024.0;"),v.push("float amountInLight = 0.0;"),v.push("vec3 shadowCoord;"),v.push("vec4 rgbaDepth;"),v.push("float depth;");for(var T=0,E=a.lights.length;T0)for(var d=r._sectionPlanesState.sectionPlanes,v=t.renderFlags,h=0;h0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(c=0,f=a.sectionPlanes.length;c0&&a.lightMaps[0].texture&&this._uLightMap&&(o.bindTexture(this._uLightMap,a.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++),a.reflectionMaps.length>0&&a.reflectionMaps[0].texture&&this._uReflectionMap&&(o.bindTexture(this._uReflectionMap,a.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++),this._uGammaFactor&&i.uniform1f(this._uGammaFactor,r.gammaFactor),this._baseTextureUnit=e.textureUnit};var Ci=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene,n=t._lightsState,r=function(e){var t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),i=t._sectionPlanesState.sectionPlanes.length>0,a=!!e._geometry._state.compressGeometry,s=e._state.billboard,o=e._state.stationary,l=[];l.push("#version 300 es"),l.push("// EmphasisFillShaderSource vertex shader"),l.push("in vec3 position;"),l.push("uniform mat4 modelMatrix;"),l.push("uniform mat4 viewMatrix;"),l.push("uniform mat4 projMatrix;"),l.push("uniform vec4 colorize;"),l.push("uniform vec3 offset;"),a&&l.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;"));i&&l.push("out vec4 vWorldPosition;");if(l.push("uniform vec4 lightAmbient;"),l.push("uniform vec4 fillColor;"),r){l.push("in vec3 normal;"),l.push("uniform mat4 modelNormalMatrix;"),l.push("uniform mat4 viewNormalMatrix;");for(var u=0,c=n.lights.length;u= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"))}l.push("out vec4 vColor;"),("spherical"===s||"cylindrical"===s)&&(l.push("void billboard(inout mat4 mat) {"),l.push(" mat[0][0] = 1.0;"),l.push(" mat[0][1] = 0.0;"),l.push(" mat[0][2] = 0.0;"),"spherical"===s&&(l.push(" mat[1][0] = 0.0;"),l.push(" mat[1][1] = 1.0;"),l.push(" mat[1][2] = 0.0;")),l.push(" mat[2][0] = 0.0;"),l.push(" mat[2][1] = 0.0;"),l.push(" mat[2][2] =1.0;"),l.push("}"));l.push("void main(void) {"),l.push("vec4 localPosition = vec4(position, 1.0); "),l.push("vec4 worldPosition;"),a&&l.push("localPosition = positionsDecodeMatrix * localPosition;");r&&(a?l.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):l.push("vec4 localNormal = vec4(normal, 0.0); "),l.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),l.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));l.push("mat4 viewMatrix2 = viewMatrix;"),l.push("mat4 modelMatrix2 = modelMatrix;"),o&&l.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===s||"cylindrical"===s?(l.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),l.push("billboard(modelMatrix2);"),l.push("billboard(viewMatrix2);"),l.push("billboard(modelViewMatrix);"),r&&(l.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),l.push("billboard(modelNormalMatrix2);"),l.push("billboard(viewNormalMatrix2);"),l.push("billboard(modelViewNormalMatrix);")),l.push("worldPosition = modelMatrix2 * localPosition;"),l.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(l.push("worldPosition = modelMatrix2 * localPosition;"),l.push("worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r&&l.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),r)for(var p=0,A=n.lights.length;p0,a=[];a.push("#version 300 es"),a.push("// Lambertian drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));r&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(var s=0,o=n.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}"points"===e._geometry._state.primitiveName&&(a.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),a.push("float r = dot(cxy, cxy);"),a.push("if (r > 1.0) {"),a.push(" discard;"),a.push("}"));t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");r?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(t)}));var _i=new G({}),Bi=Z.vec3(),Oi=function(e,t){this.id=_i.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Ci(t),this._allocate(t)},Si={};Oi.get=function(e){var t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),n=Si[t];return n||(n=new Oi(t,e),Si[t]=n,ee.memory.programs++),n._useCount++,n},Oi.prototype.put=function(){0==--this._useCount&&(_i.removeItem(this.id),this._program&&this._program.destroy(),delete Si[this._hash],ee.memory.programs--)},Oi.prototype.webglContextRestored=function(){this._program=null},Oi.prototype.drawMesh=function(e,t,n){this._program||this._allocate(t);var r=this._scene,i=r.camera,a=r.canvas.gl,s=0===n?t._xrayMaterial._state:1===n?t._highlightMaterial._state:t._selectedMaterial._state,o=t._state,l=t._geometry._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(o.originHash,u):i.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.viewNormalMatrix),o.clippable){var c=r._sectionPlanesState.sectionPlanes.length;if(c>0)for(var f=r._sectionPlanesState.sectionPlanes,p=t.renderFlags,A=0;A0,r=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,s=[];s.push("#version 300 es"),s.push("// Edges drawing vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform vec4 edgeColor;"),s.push("uniform vec3 offset;"),r&&s.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"));n&&s.push("out vec4 vWorldPosition;");s.push("out vec4 vColor;"),("spherical"===i||"cylindrical"===i)&&(s.push("void billboard(inout mat4 mat) {"),s.push(" mat[0][0] = 1.0;"),s.push(" mat[0][1] = 0.0;"),s.push(" mat[0][2] = 0.0;"),"spherical"===i&&(s.push(" mat[1][0] = 0.0;"),s.push(" mat[1][1] = 1.0;"),s.push(" mat[1][2] = 0.0;")),s.push(" mat[2][0] = 0.0;"),s.push(" mat[2][1] = 0.0;"),s.push(" mat[2][2] =1.0;"),s.push("}"));s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),s.push("vec4 worldPosition;"),r&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("mat4 viewMatrix2 = viewMatrix;"),s.push("mat4 modelMatrix2 = modelMatrix;"),a&&s.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(s.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),s.push("billboard(modelMatrix2);"),s.push("billboard(viewMatrix2);"),s.push("billboard(modelViewMatrix);"),s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s.push("vColor = edgeColor;"),n&&s.push("vWorldPosition = worldPosition;");s.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return s.push("gl_Position = clipPos;"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene,n=e.scene._sectionPlanesState,r=e.scene.gammaOutput,i=n.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Edges drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));r&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(var s=0,o=n.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");r?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(t)}));var Li=new G({}),xi=Z.vec3(),Mi=function(e,t){this.id=Li.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Ni(t),this._allocate(t)},Fi={};Mi.get=function(e){var t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),n=Fi[t];return n||(n=new Mi(t,e),Fi[t]=n,ee.memory.programs++),n._useCount++,n},Mi.prototype.put=function(){0==--this._useCount&&(Li.removeItem(this.id),this._program&&this._program.destroy(),delete Fi[this._hash],ee.memory.programs--)},Mi.prototype.webglContextRestored=function(){this._program=null},Mi.prototype.drawMesh=function(e,t,n){this._program||this._allocate(t);var r,i,a=this._scene,s=a.camera,o=a.canvas.gl,l=t._state,u=t._geometry,c=u._state,f=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),o.uniformMatrix4fv(this._uViewMatrix,!1,f?e.getRTCViewMatrix(l.originHash,f):s.viewMatrix),l.clippable){var p=a._sectionPlanesState.sectionPlanes.length;if(p>0)for(var A=a._sectionPlanesState.sectionPlanes,d=t.renderFlags,v=0;v0,r=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,s=[];s.push("#version 300 es"),s.push("// Mesh picking vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("out vec4 vViewPosition;"),s.push("uniform vec3 offset;"),r&&s.push("uniform mat4 positionsDecodeMatrix;");n&&s.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(s.push("void billboard(inout mat4 mat) {"),s.push(" mat[0][0] = 1.0;"),s.push(" mat[0][1] = 0.0;"),s.push(" mat[0][2] = 0.0;"),"spherical"===i&&(s.push(" mat[1][0] = 0.0;"),s.push(" mat[1][1] = 1.0;"),s.push(" mat[1][2] = 0.0;")),s.push(" mat[2][0] = 0.0;"),s.push(" mat[2][1] = 0.0;"),s.push(" mat[2][2] =1.0;"),s.push("}"));s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),r&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("mat4 viewMatrix2 = viewMatrix;"),s.push("mat4 modelMatrix2 = modelMatrix;"),a&&s.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==i&&"cylindrical"!==i||(s.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),s.push("billboard(modelMatrix2);"),s.push("billboard(viewMatrix2);"));s.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),n&&s.push(" vWorldPosition = worldPosition;");s.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return s.push("gl_Position = clipPos;"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(i.push("uniform vec4 pickColor;"),r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = pickColor; "),i.push("}"),i}(t)}));var Ui=Z.vec3(),Gi=function(e,t){this._hash=e,this._shaderSource=new Hi(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},ki={};Gi.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";"),n=ki[t];if(!n){if((n=new Gi(t,e)).errors)return console.log(n.errors.join("\n")),null;ki[t]=n,ee.memory.programs++}return n._useCount++,n},Gi.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete ki[this._hash],ee.memory.programs--)},Gi.prototype.webglContextRestored=function(){this._program=null},Gi.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene,r=n.canvas.gl,i=t._state,a=t._material._state,s=t._geometry._state,o=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),r.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCPickViewMatrix(i.originHash,o):e.pickViewMatrix),i.clippable){var l=n._sectionPlanesState.sectionPlanes.length;if(l>0)for(var u=n._sectionPlanesState.sectionPlanes,c=t.renderFlags,f=0;f>24&255,m=I>>16&255,w=I>>8&255,g=255&I;r.uniform4f(this._uPickColor,g/255,w/255,m/255,y/255),s.indicesBuf?(r.drawElements(s.primitive,s.indicesBuf.numItems,s.indicesBuf.itemType,0),e.drawElements++):s.positions&&r.drawArrays(r.TRIANGLES,0,s.positions.numItems)},Gi.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl;if(this._program=new ft(n,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uPositionsDecodeMatrix=r.getLocation("positionsDecodeMatrix"),this._uModelMatrix=r.getLocation("modelMatrix"),this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var i=0,a=t._sectionPlanesState.sectionPlanes.length;i0,r=!!e._geometry._state.compressGeometry;e._state.billboard,e._state.stationary;var i=[];i.push("#version 300 es"),i.push("// Surface picking vertex shader"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform vec3 offset;"),n&&(i.push("uniform bool clippable;"),i.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"));i.push("out vec4 vColor;"),r&&i.push("uniform mat4 positionsDecodeMatrix;");i.push("void main(void) {"),i.push("vec4 localPosition = vec4(position, 1.0); "),r&&i.push("localPosition = positionsDecodeMatrix * localPosition;");i.push(" vec4 worldPosition = modelMatrix * localPosition; "),i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),n&&i.push(" vWorldPosition = worldPosition;");i.push(" vColor = color;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return i.push("gl_Position = clipPos;"),i.push("}"),i}(t),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Surface picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = vColor;"),i.push("}"),i}(t)}));var ji=Z.vec3(),Qi=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Vi(t),this._allocate(t)},Wi={};Qi.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),n=Wi[t];if(!n){if((n=new Qi(t,e)).errors)return console.log(n.errors.join("\n")),null;Wi[t]=n,ee.memory.programs++}return n._useCount++,n},Qi.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Wi[this._hash],ee.memory.programs--)},Qi.prototype.webglContextRestored=function(){this._program=null},Qi.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene,r=n.canvas.gl,i=t._state,a=t._material._state,s=t._geometry,o=t._geometry._state,l=t.origin,u=a.backfaces,c=a.frontface,f=n.camera.project,p=s._getPickTrianglePositions(),A=s._getPickTriangleColors();if(this._program.bind(),e.useProgram++,n.logarithmicDepthBufferEnabled){var d=2/(Math.log(f.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,d)}if(r.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(i.originHash,l):e.pickViewMatrix),i.clippable){var v=n._sectionPlanesState.sectionPlanes.length;if(v>0)for(var h=n._sectionPlanesState.sectionPlanes,I=t.renderFlags,y=0;y0,r=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,s=[];s.push("#version 300 es"),s.push("// Mesh occlusion vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform vec3 offset;"),r&&s.push("uniform mat4 positionsDecodeMatrix;");n&&s.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(s.push("void billboard(inout mat4 mat) {"),s.push(" mat[0][0] = 1.0;"),s.push(" mat[0][1] = 0.0;"),s.push(" mat[0][2] = 0.0;"),"spherical"===i&&(s.push(" mat[1][0] = 0.0;"),s.push(" mat[1][1] = 1.0;"),s.push(" mat[1][2] = 0.0;")),s.push(" mat[2][0] = 0.0;"),s.push(" mat[2][1] = 0.0;"),s.push(" mat[2][2] =1.0;"),s.push("}"));s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),s.push("vec4 worldPosition;"),r&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("mat4 viewMatrix2 = viewMatrix;"),s.push("mat4 modelMatrix2 = modelMatrix;"),a&&s.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(s.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),s.push("billboard(modelMatrix2);"),s.push("billboard(viewMatrix2);"),s.push("billboard(modelViewMatrix);"),s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));n&&s.push(" vWorldPosition = worldPosition;");s.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return s.push("gl_Position = clipPos;"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push("}"),i}(t)}));var Ki=Z.vec3(),Yi=function(e,t){this._hash=e,this._shaderSource=new zi(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Xi={};Yi.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";"),n=Xi[t];if(!n){if((n=new Yi(t,e)).errors)return console.log(n.errors.join("\n")),null;Xi[t]=n,ee.memory.programs++}return n._useCount++,n},Yi.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Xi[this._hash],ee.memory.programs--)},Yi.prototype.webglContextRestored=function(){this._program=null},Yi.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene,r=n.canvas.gl,i=t._material._state,a=t._state,s=t._geometry._state,o=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),i.id!==this._lastMaterialId){var l=i.backfaces;e.backfaces!==l&&(l?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),e.backfaces=l);var u=i.frontface;e.frontface!==u&&(u?r.frontFace(r.CCW):r.frontFace(r.CW),e.frontface=u),this._lastMaterialId=i.id}var c=n.camera;if(r.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCViewMatrix(a.originHash,o):c.viewMatrix),a.clippable){var f=n._sectionPlanesState.sectionPlanes.length;if(f>0)for(var p=n._sectionPlanesState.sectionPlanes,A=t.renderFlags,d=0;d0,n=!!e._geometry._state.compressGeometry,r=[];r.push("// Mesh shadow vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 shadowViewMatrix;"),r.push("uniform mat4 shadowProjMatrix;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");t&&r.push("out vec4 vWorldPosition;");r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("worldPosition = modelMatrix * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&r.push("vWorldPosition = worldPosition;");return r.push(" gl_Position = shadowProjMatrix * viewPosition;"),r.push("}"),r}(t),this.fragment=function(e){var t=e.scene;t.canvas.gl;var n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];if(i.push("// Mesh shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}return i.push("outColor = encodeFloat(gl_FragCoord.z);"),i.push("}"),i}(t)}));var Ji=function(e,t){this._hash=e,this._shaderSource=new qi(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Zi={};Ji.get=function(e){var t=e.scene,n=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";"),r=Zi[n];if(!r){if((r=new Ji(n,e)).errors)return console.log(r.errors.join("\n")),null;Zi[n]=r,ee.memory.programs++}return r._useCount++,r},Ji.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Zi[this._hash],ee.memory.programs--)},Ji.prototype.webglContextRestored=function(){this._program=null},Ji.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene.canvas.gl,r=t._material._state,i=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),r.id!==this._lastMaterialId){var a=r.backfaces;e.backfaces!==a&&(a?n.disable(n.CULL_FACE):n.enable(n.CULL_FACE),e.backfaces=a);var s=r.frontface;e.frontface!==s&&(s?n.frontFace(n.CCW):n.frontFace(n.CW),e.frontface=s),e.lineWidth!==r.lineWidth&&(n.lineWidth(r.lineWidth),e.lineWidth=r.lineWidth),this._uPointSize&&n.uniform1i(this._uPointSize,r.pointSize),this._lastMaterialId=r.id}if(n.uniformMatrix4fv(this._uModelMatrix,n.FALSE,t.worldMatrix),i.combineGeometry){var o=t.vertexBufs;o.id!==this._lastVertexBufsId&&(o.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(o.positionsBuf,o.compressGeometry?n.UNSIGNED_SHORT:n.FLOAT),e.bindArray++),this._lastVertexBufsId=o.id)}this._uClippable&&n.uniform1i(this._uClippable,t._state.clippable),n.uniform3fv(this._uOffset,t._state.offset),i.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&n.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,i.positionsDecodeMatrix),i.combineGeometry?i.indicesBufCombined&&(i.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(i.positionsBuf,i.compressGeometry?n.UNSIGNED_SHORT:n.FLOAT),e.bindArray++),i.indicesBuf&&(i.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=i.id),i.combineGeometry?i.indicesBufCombined&&(n.drawElements(i.primitive,i.indicesBufCombined.numItems,i.indicesBufCombined.itemType,0),e.drawElements++):i.indicesBuf?(n.drawElements(i.primitive,i.indicesBuf.numItems,i.indicesBuf.itemType,0),e.drawElements++):i.positions&&(n.drawArrays(n.TRIANGLES,0,i.positions.numItems),e.drawArrays++)},Ji.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl;if(this._program=new ft(n,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uPositionsDecodeMatrix=r.getLocation("positionsDecodeMatrix"),this._uModelMatrix=r.getLocation("modelMatrix"),this._uShadowViewMatrix=r.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=r.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(var i=0,a=t._sectionPlanesState.sectionPlanes.length;i0)for(var i,a,s,o=0,l=this._uSectionPlanes.length;o1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i)).originalSystemId=i.originalSystemId||r.id,r.renderFlags=new $i,r._state=new St({visible:!0,culled:!1,pickable:null,clippable:null,collidable:null,occluder:!1!==i.occluder,castsShadow:null,receivesShadow:null,xrayed:!1,highlighted:!1,selected:!1,edges:!1,stationary:!!i.stationary,background:!!i.background,billboard:r._checkBillboard(i.billboard),layer:null,colorize:null,pickID:r.scene._renderer.getPickID(g(r)),drawHash:"",pickHash:"",offset:Z.vec3(),origin:null,originHash:null}),r._drawRenderer=null,r._shadowRenderer=null,r._emphasisFillRenderer=null,r._emphasisEdgesRenderer=null,r._pickMeshRenderer=null,r._pickTriangleRenderer=null,r._occlusionRenderer=null,r._geometry=i.geometry?r._checkComponent2(["ReadableGeometry","VBOGeometry"],i.geometry):r.scene.geometry,r._material=i.material?r._checkComponent2(["PhongMaterial","MetallicMaterial","SpecularMaterial","LambertMaterial"],i.material):r.scene.material,r._xrayMaterial=i.xrayMaterial?r._checkComponent("EmphasisMaterial",i.xrayMaterial):r.scene.xrayMaterial,r._highlightMaterial=i.highlightMaterial?r._checkComponent("EmphasisMaterial",i.highlightMaterial):r.scene.highlightMaterial,r._selectedMaterial=i.selectedMaterial?r._checkComponent("EmphasisMaterial",i.selectedMaterial):r.scene.selectedMaterial,r._edgeMaterial=i.edgeMaterial?r._checkComponent("EdgeMaterial",i.edgeMaterial):r.scene.edgeMaterial,r._parentNode=null,r._aabb=null,r._aabbDirty=!0,r._numTriangles=r._geometry?r._geometry.numTriangles:0,r.scene._aabbDirty=!0,r._scale=Z.vec3(),r._quaternion=Z.identityQuaternion(),r._rotation=Z.vec3(),r._position=Z.vec3(),r._worldMatrix=Z.identityMat4(),r._worldNormalMatrix=Z.identityMat4(),r._localMatrixDirty=!0,r._worldMatrixDirty=!0,r._worldNormalMatrixDirty=!0;var a=i.origin||i.rtcCenter;if(a&&(r._state.origin=Z.vec3(a),r._state.originHash=a.join()),i.matrix?r.matrix=i.matrix:(r.scale=i.scale,r.position=i.position,i.quaternion||(r.rotation=i.rotation)),r._isObject=i.isObject,r._isObject&&r.scene._registerObject(g(r)),r._isModel=i.isModel,r._isModel&&r.scene._registerModel(g(r)),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.layer=i.layer,r.colorize=i.colorize,r.opacity=i.opacity,r.offset=i.offset,i.parentId){var s=r.scene.components[i.parentId];s?s.isNode?s.addChild(g(r)):r.error("Parent is not a Node: '"+i.parentId+"'"):r.error("Parent not found: '"+i.parentId+"'"),r._parentNode=s}else i.parent&&(i.parent.isNode||r.error("Parent is not a Node"),i.parent.addChild(g(r)),r._parentNode=i.parent);return r.compile(),r}return P(n,[{key:"type",get:function(){return"Mesh"}},{key:"isMesh",get:function(){return!0}},{key:"parent",get:function(){return this._parentNode}},{key:"geometry",get:function(){return this._geometry}},{key:"material",get:function(){return this._material}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),Z.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),Z.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"matrix",get:function(){return this._localMatrixDirty&&(this.__localMatrix||(this.__localMatrix=Z.identityMat4()),Z.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix},set:function(e){this.__localMatrix||(this.__localMatrix=Z.identityMat4()),this.__localMatrix.set(e||ua),Z.decomposeMat4(this.__localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrixDirty&&this._buildWorldNormalMatrix(),this._worldNormalMatrix}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return this._isObject}},{key:"aabb",get:function(){return this._aabbDirty&&this._updateAABB(),this._aabb}},{key:"origin",get:function(){return this._state.origin},set:function(e){e?(this._state.origin||(this._state.origin=Z.vec3()),this._state.origin.set(e),this._state.originHash=e.join(),this._setAABBDirty(),this.scene._aabbDirty=!0):this._state.origin&&(this._state.origin=null,this._state.originHash=null,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"rtcCenter",get:function(){return this.origin},set:function(e){this.origin=e}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"visible",get:function(){return this._state.visible},set:function(e){e=!1!==e,this._state.visible=e,this._isObject&&this.scene._objectVisibilityUpdated(this,e),this.glRedraw()}},{key:"xrayed",get:function(){return this._state.xrayed},set:function(e){e=!!e,this._state.xrayed!==e&&(this._state.xrayed=e,this._isObject&&this.scene._objectXRayedUpdated(this,e),this.glRedraw())}},{key:"highlighted",get:function(){return this._state.highlighted},set:function(e){(e=!!e)!==this._state.highlighted&&(this._state.highlighted=e,this._isObject&&this.scene._objectHighlightedUpdated(this,e),this.glRedraw())}},{key:"selected",get:function(){return this._state.selected},set:function(e){(e=!!e)!==this._state.selected&&(this._state.selected=e,this._isObject&&this.scene._objectSelectedUpdated(this,e),this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){(e=!!e)!==this._state.edges&&(this._state.edges=e,this.glRedraw())}},{key:"culled",get:function(){return this._state.culled},set:function(e){this._state.culled=!!e,this.glRedraw()}},{key:"clippable",get:function(){return this._state.clippable},set:function(e){e=!1!==e,this._state.clippable!==e&&(this._state.clippable=e,this.glRedraw())}},{key:"collidable",get:function(){return this._state.collidable},set:function(e){(e=!1!==e)!==this._state.collidable&&(this._state.collidable=e,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"pickable",get:function(){return this._state.pickable},set:function(e){e=!1!==e,this._state.pickable!==e&&(this._state.pickable=e)}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){(e=!1!==e)!==this._state.castsShadow&&(this._state.castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._state.receivesShadow},set:function(e){(e=!1!==e)!==this._state.receivesShadow&&(this._state.receivesShadow=e,this._state.hash=e?"/mod/rs;":"/mod;",this.fire("dirty",this))}},{key:"saoEnabled",get:function(){return!1}},{key:"colorize",get:function(){return this._state.colorize},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);var n=!!e;this.scene._objectColorizeUpdated(this,n),this.glRedraw()}},{key:"opacity",get:function(){return this._state.colorize[3]},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[0]=1,t[1]=1,t[2]=1);var n=null!=e;t[3]=n?e:1,this.scene._objectOpacityUpdated(this,n),this.glRedraw()}},{key:"transparent",get:function(){return 2===this._material.alphaMode||this._state.colorize[3]<1}},{key:"layer",get:function(){return this._state.layer},set:function(e){e=e||0,(e=Math.round(e))!==this._state.layer&&(this._state.layer=e,this._renderer.needStateSort())}},{key:"stationary",get:function(){return this._state.stationary}},{key:"billboard",get:function(){return this._state.billboard}},{key:"offset",get:function(){return this._state.offset},set:function(e){this._state.offset.set(e||[0,0,0]),this._setAABBDirty(),this.glRedraw()}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!0}},{key:"xrayMaterial",get:function(){return this._xrayMaterial}},{key:"highlightMaterial",get:function(){return this._highlightMaterial}},{key:"selectedMaterial",get:function(){return this._selectedMaterial}},{key:"edgeMaterial",get:function(){return this._edgeMaterial}},{key:"_checkBillboard",value:function(e){return"spherical"!==(e=e||"none")&&"cylindrical"!==e&&"none"!==e&&(this.error("Unsupported value for 'billboard': "+e+" - accepted values are 'spherical', 'cylindrical' and 'none' - defaulting to 'none'."),e="none"),e}},{key:"compile",value:function(){var e=this._makeDrawHash();this._state.drawHash!==e&&(this._state.drawHash=e,this._putDrawRenderers(),this._drawRenderer=Pi.get(this),this._emphasisFillRenderer=Oi.get(this),this._emphasisEdgesRenderer=Mi.get(this));var t=this._makePickHash();if(this._state.pickHash!==t&&(this._state.pickHash=t,this._putPickRenderers(),this._pickMeshRenderer=Gi.get(this)),this._state.occluder){var n=this._makeOcclusionHash();this._state.occlusionHash!==n&&(this._state.occlusionHash=n,this._putOcclusionRenderer(),this._occlusionRenderer=Yi.get(this))}}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}},{key:"_setWorldMatrixDirty",value:function(){this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentNode)Z.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(var t=0,n=e.length;t0)for(var n=0;n-1){var x=B.geometry._state,M=B.scene,F=M.camera,H=M.canvas;if("triangles"===x.primitiveName){N.primitive="triangle";var U,G,k,V=L,j=x.indices,Q=x.positions;if(j){var W=j[V+0],z=j[V+1],K=j[V+2];a[0]=W,a[1]=z,a[2]=K,N.indices=a,U=3*W,G=3*z,k=3*K}else k=(G=(U=3*V)+3)+3;if(n[0]=Q[U+0],n[1]=Q[U+1],n[2]=Q[U+2],r[0]=Q[G+0],r[1]=Q[G+1],r[2]=Q[G+2],i[0]=Q[k+0],i[1]=Q[k+1],i[2]=Q[k+2],x.compressGeometry){var Y=x.positionsDecodeMatrix;Y&&(pn.decompressPosition(n,Y,n),pn.decompressPosition(r,Y,r),pn.decompressPosition(i,Y,i))}N.canvasPos?Z.canvasPosToLocalRay(H.canvas,B.origin?Ie(O,B.origin):O,S,B.worldMatrix,N.canvasPos,e,t):N.origin&&N.direction&&Z.worldRayToLocalRay(B.worldMatrix,N.origin,N.direction,e,t),Z.normalizeVec3(t),Z.rayPlaneIntersect(e,t,n,r,i,s),N.localPos=s,N.position=s,h[0]=s[0],h[1]=s[1],h[2]=s[2],h[3]=1,Z.transformVec4(B.worldMatrix,h,I),o[0]=I[0],o[1]=I[1],o[2]=I[2],N.canvasPos&&B.origin&&(o[0]+=B.origin[0],o[1]+=B.origin[1],o[2]+=B.origin[2]),N.worldPos=o,Z.transformVec4(F.matrix,I,y),l[0]=y[0],l[1]=y[1],l[2]=y[2],N.viewPos=l,Z.cartesianToBarycentric(s,n,r,i,u),N.bary=u;var X=x.normals;if(X){if(x.compressGeometry){var q=3*W,J=3*z,$=3*K;pn.decompressNormal(X.subarray(q,q+2),c),pn.decompressNormal(X.subarray(J,J+2),f),pn.decompressNormal(X.subarray($,$+2),p)}else c[0]=X[U],c[1]=X[U+1],c[2]=X[U+2],f[0]=X[G],f[1]=X[G+1],f[2]=X[G+2],p[0]=X[k],p[1]=X[k+1],p[2]=X[k+2];var ee=Z.addVec3(Z.addVec3(Z.mulVec3Scalar(c,u[0],m),Z.mulVec3Scalar(f,u[1],w),g),Z.mulVec3Scalar(p,u[2],T),E);N.worldNormal=Z.normalizeVec3(Z.transformVec3(B.worldNormalMatrix,ee,b))}var te=x.uv;if(te){if(A[0]=te[2*W],A[1]=te[2*W+1],d[0]=te[2*z],d[1]=te[2*z+1],v[0]=te[2*K],v[1]=te[2*K+1],x.compressGeometry){var ne=x.uvDecodeMatrix;ne&&(pn.decompressUV(A,ne,A),pn.decompressUV(d,ne,d),pn.decompressUV(v,ne,v))}N.uv=Z.addVec3(Z.addVec3(Z.mulVec2Scalar(A,u[0],D),Z.mulVec2Scalar(d,u[1],P),R),Z.mulVec2Scalar(v,u[2],C),_)}}}}}();function pa(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);var n=e.radiusBottom||1;n<0&&(console.error("negative radiusBottom not allowed - will invert"),n*=-1);var r=e.height||1;r<0&&(console.error("negative height not allowed - will invert"),r*=-1);var i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);var a=e.heightSegments||1;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),a<1&&(a=1);var s,o,l,u,c,f,p,A,d,v,h,I=!!e.openEnded,y=e.center,m=y?y[0]:0,w=y?y[1]:0,g=y?y[2]:0,T=r/2,E=r/a,b=2*Math.PI/i,D=1/i,P=(t-n)/a,R=[],C=[],_=[],B=[],O=(90-180*Math.atan(r/(n-t))/Math.PI)/90;for(s=0;s<=a;s++)for(c=t-s*P,f=T-s*E,o=0;o<=i;o++)l=Math.sin(o*b),u=Math.cos(o*b),C.push(c*l),C.push(O),C.push(c*u),_.push(o*D),_.push(1*s/a),R.push(c*l+m),R.push(f+w),R.push(c*u+g);for(s=0;s0){for(d=R.length/3,C.push(0),C.push(1),C.push(0),_.push(.5),_.push(.5),R.push(0+m),R.push(T+w),R.push(0+g),o=0;o<=i;o++)l=Math.sin(o*b),u=Math.cos(o*b),v=.5*Math.sin(o*b)+.5,h=.5*Math.cos(o*b)+.5,C.push(t*l),C.push(1),C.push(t*u),_.push(v),_.push(h),R.push(t*l+m),R.push(T+w),R.push(t*u+g);for(o=0;o0){for(d=R.length/3,C.push(0),C.push(-1),C.push(0),_.push(.5),_.push(.5),R.push(0+m),R.push(0-T+w),R.push(0+g),o=0;o<=i;o++)l=Math.sin(o*b),u=Math.cos(o*b),v=.5*Math.sin(o*b)+.5,h=.5*Math.cos(o*b)+.5,C.push(n*l),C.push(-1),C.push(n*u),_.push(v),_.push(h),R.push(n*l+m),R.push(0-T+w),R.push(n*u+g);for(o=0;o0&&void 0!==arguments[0]?arguments[0]:{},t=e.lod||1,n=e.center?e.center[0]:0,r=e.center?e.center[1]:0,i=e.center?e.center[2]:0,a=e.radius||1;a<0&&(console.error("negative radius not allowed - will invert"),a*=-1);var s=e.heightSegments||18;s<0&&(console.error("negative heightSegments not allowed - will invert"),s*=-1),(s=Math.floor(t*s))<18&&(s=18);var o=e.widthSegments||18;o<0&&(console.error("negative widthSegments not allowed - will invert"),o*=-1),(o=Math.floor(t*o))<18&&(o=18);var l,u,c,f,p,A,d,v,h,I,y,m,w,g,T=[],E=[],b=[],D=[];for(l=0;l<=s;l++)for(c=l*Math.PI/s,f=Math.sin(c),p=Math.cos(c),u=0;u<=o;u++)A=2*u*Math.PI/o,d=Math.sin(A),v=Math.cos(A)*f,h=p,I=d*f,y=1-u/o,m=l/s,E.push(v),E.push(h),E.push(I),b.push(y),b.push(m),T.push(n+a*v),T.push(r+a*h),T.push(i+a*I);for(l=0;l":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function va(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.origin||[0,0,0],n=t[0],r=t[1],i=t[2],a=e.size||1,s=[],o=[],l=e.text;ae.isNumeric(l)&&(l=""+l);for(var u,c,f,p,A,d,v,h,I,y=(l||"").split("\n"),m=0,w=0,g=.04,T=0;T1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({active:!0,pos:Z.vec3(),dir:Z.vec3(),dist:0}),r.active=i.active,r.pos=i.pos,r.dir=i.dir,r.scene._sectionPlaneCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"SectionPlane"}},{key:"active",get:function(){return this._state.active},set:function(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active)}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-Z.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos)}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||[0,0,-1]),this._state.dist=-Z.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir)}},{key:"dist",get:function(){return this._state.dist}},{key:"flipDir",value:function(){var e=this._state.dir;e[0]*=-1,e[1]*=-1,e[2]*=-1,this._state.dist=-Z.dotVec3(this._state.pos,this._state.dir),this.fire("dir",this._state.dir),this.glRedraw()}},{key:"destroy",value:function(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),ya=Z.vec4(4),ma=Z.vec4(),wa=Z.vec4(),ga=Z.vec3([1,0,0]),Ta=Z.vec3([0,1,0]),Ea=Z.vec3([0,0,1]),ba=Z.vec3(3),Da=Z.vec3(3),Pa=Z.identityMat4(),Ra=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,i))._parentNode=null,r._children=[],r._aabb=null,r._aabbDirty=!0,r.scene._aabbDirty=!0,r._numTriangles=0,r._scale=Z.vec3(),r._quaternion=Z.identityQuaternion(),r._rotation=Z.vec3(),r._position=Z.vec3(),r._offset=Z.vec3(),r._localMatrix=Z.identityMat4(),r._worldMatrix=Z.identityMat4(),r._localMatrixDirty=!0,r._worldMatrixDirty=!0,i.matrix?r.matrix=i.matrix:(r.scale=i.scale,r.position=i.position,i.quaternion||(r.rotation=i.rotation)),r._isModel=i.isModel,r._isModel&&r.scene._registerModel(g(r)),r._isObject=i.isObject,r._isObject&&r.scene._registerObject(g(r)),r.origin=i.origin,r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.offset=i.offset,i.children)for(var a=i.children,s=0,o=a.length;s1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"LambertMaterial",ambient:Z.vec3([1,1,1]),color:Z.vec3([1,1,1]),emissive:Z.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),r.ambient=i.ambient,r.color=i.color,r.emissive=i.emissive,r.alpha=i.alpha,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r.backfaces=i.backfaces,r.frontface=i.frontface,r}return P(n,[{key:"type",get:function(){return"LambertMaterial"}},{key:"ambient",get:function(){return this._state.ambient},set:function(e){var t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){var t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this._state.alphaMode=e<1?2:0,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),_a={opaque:0,mask:1,blend:2},Ba=["opaque","mask","blend"],Oa=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"MetallicMaterial",baseColor:Z.vec4([1,1,1]),emissive:Z.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.baseColor=i.baseColor,r.metallic=i.metallic,r.roughness=i.roughness,r.specularF0=i.specularF0,r.emissive=i.emissive,r.alpha=i.alpha,i.baseColorMap&&(r._baseColorMap=r._checkComponent("Texture",i.baseColorMap)),i.metallicMap&&(r._metallicMap=r._checkComponent("Texture",i.metallicMap)),i.roughnessMap&&(r._roughnessMap=r._checkComponent("Texture",i.roughnessMap)),i.metallicRoughnessMap&&(r._metallicRoughnessMap=r._checkComponent("Texture",i.metallicRoughnessMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r._makeHash(),r}return P(n,[{key:"type",get:function(){return"MetallicMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"baseColor",get:function(){return this._state.baseColor},set:function(e){var t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"baseColorMap",get:function(){return this._baseColorMap}},{key:"metallic",get:function(){return this._state.metallic},set:function(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}},{key:"metallicMap",get:function(){return this._attached.metallicMap}},{key:"roughness",get:function(){return this._state.roughness},set:function(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}},{key:"roughnessMap",get:function(){return this._attached.roughnessMap}},{key:"metallicRoughnessMap",get:function(){return this._attached.metallicRoughnessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"emissiveMap",get:function(){return this._attached.emissiveMap}},{key:"occlusionMap",get:function(){return this._attached.occlusionMap}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"alphaMap",get:function(){return this._attached.alphaMap}},{key:"normalMap",get:function(){return this._attached.normalMap}},{key:"alphaMode",get:function(){return Ba[this._state.alphaMode]},set:function(e){var t=_a[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Sa={opaque:0,mask:1,blend:2},Na=["opaque","mask","blend"],La=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"SpecularMaterial",diffuse:Z.vec3([1,1,1]),emissive:Z.vec3([0,0,0]),specular:Z.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.diffuse=i.diffuse,r.specular=i.specular,r.glossiness=i.glossiness,r.specularF0=i.specularF0,r.emissive=i.emissive,r.alpha=i.alpha,i.diffuseMap&&(r._diffuseMap=r._checkComponent("Texture",i.diffuseMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.specularMap&&(r._specularMap=r._checkComponent("Texture",i.specularMap)),i.glossinessMap&&(r._glossinessMap=r._checkComponent("Texture",i.glossinessMap)),i.specularGlossinessMap&&(r._specularGlossinessMap=r._checkComponent("Texture",i.specularGlossinessMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r._makeHash(),r}return P(n,[{key:"type",get:function(){return"SpecularMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"diffuse",get:function(){return this._state.diffuse},set:function(e){var t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"diffuseMap",get:function(){return this._diffuseMap}},{key:"specular",get:function(){return this._state.specular},set:function(e){var t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"specularMap",get:function(){return this._specularMap}},{key:"specularGlossinessMap",get:function(){return this._specularGlossinessMap}},{key:"glossiness",get:function(){return this._state.glossiness},set:function(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}},{key:"glossinessMap",get:function(){return this._glossinessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"emissiveMap",get:function(){return this._emissiveMap}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"alphaMap",get:function(){return this._alphaMap}},{key:"normalMap",get:function(){return this._normalMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"alphaMode",get:function(){return Na[this._state.alphaMode]},set:function(e){var t=Sa[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}();function xa(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 Ma=new Uint8Array([0,0,0,1]),Fa=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?(Ma[0]=Math.floor(255*e[0]),Ma[1]=Math.floor(255*e[1]),Ma[2]=Math.floor(255*e[2]),Ma[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(Ma[0]=0,Ma[1]=0,Ma[2]=0,Ma[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=xa(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=xa(n,this.magFilter);u&&n.texParameteri(this.target,n.TEXTURE_MAG_FILTER,u);var c=xa(n,this.wrapS);c&&n.texParameteri(this.target,n.TEXTURE_WRAP_S,c);var f=xa(n,this.wrapT);f&&n.texParameteri(this.target,n.TEXTURE_WRAP_T,f);var p=xa(n,this.format,this.encoding),A=xa(n,this.type),d=Ha(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=xa(i,this.wrapS);o&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,o);var l=xa(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=xa(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,Ua(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Ua(i,this.magFilter))):(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,xa(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,xa(i,this.magFilter)));var c=xa(i,this.format,this.encoding),f=xa(i,this.type),p=Ha(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 Ua(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function Ga(e){if(!ka(e.width)||!ka(e.height)){var t=document.createElement("canvas");t.width=Va(e.width),t.height=Va(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function ka(e){return 0==(e&e-1)}function Va(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var ja=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({texture:new Fa({gl:r.scene.canvas.gl}),matrix:Z.identityMat4(),hasMatrix:i.translate&&(0!==i.translate[0]||0!==i.translate[1])||!!i.rotate||i.scale&&(0!==i.scale[0]||0!==i.scale[1]),minFilter:r._checkMinFilter(i.minFilter),magFilter:r._checkMagFilter(i.magFilter),wrapS:r._checkWrapS(i.wrapS),wrapT:r._checkWrapT(i.wrapT),flipY:r._checkFlipY(i.flipY),encoding:r._checkEncoding(i.encoding)}),r._src=null,r._image=null,r._translate=Z.vec2([0,0]),r._scale=Z.vec2([1,1]),r._rotate=Z.vec2([0,0]),r._matrixDirty=!1,r.translate=i.translate,r.scale=i.scale,r.rotate=i.rotate,i.src?r.src=i.src:i.image&&(r.image=i.image),ee.memory.textures++,r}return P(n,[{key:"type",get:function(){return"Texture"}},{key:"_checkMinFilter",value:function(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}},{key:"_checkMagFilter",value:function(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}},{key:"_checkWrapS",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkWrapT",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this._state.texture=new Fa({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}},{key:"_update",value:function(){var e,t,n=this._state;this._matrixDirty&&(0===this._translate[0]&&0===this._translate[1]||(e=Z.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(t=Z.scalingMat4v([this._scale[0],this._scale[1],1]),e=e?Z.mulMat4(e,t):t),0!==this._rotate&&(t=Z.rotationMat4v(.0174532925*this._rotate,[0,0,1]),e=e?Z.mulMat4(e,t):t),e&&(n.matrix=e),this._matrixDirty=!1);this.glRedraw()}},{key:"image",get:function(){return this._image},set:function(e){this._image=Ga(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}},{key:"src",get:function(){return this._src},set:function(e){this.scene.loading++,this.scene.canvas.spinner.processes++;var t=this,n=new Image;n.onload=function(){n=Ga(n),t._state.texture.setImage(n,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},n.src=e,this._src=e,this._image=null}},{key:"translate",get:function(){return this._translate},set:function(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}},{key:"rotate",get:function(){return this._rotate},set:function(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}},{key:"minFilter",get:function(){return this._state.minFilter}},{key:"magFilter",get:function(){return this._state.magFilter}},{key:"wrapS",get:function(){return this._state.wrapS}},{key:"wrapT",get:function(){return this._state.wrapT}},{key:"flipY",get:function(){return this._state.flipY}},{key:"encoding",get:function(){return this._state.encoding}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),ee.memory.textures--}}]),n}(),Qa=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({edgeColor:Z.vec3([0,0,0]),centerColor:Z.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),r.edgeColor=i.edgeColor,r.centerColor=i.centerColor,r.edgeBias=i.edgeBias,r.centerBias=i.centerBias,r.power=i.power,r}return P(n,[{key:"type",get:function(){return"Fresnel"}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}},{key:"centerColor",get:function(){return this._state.centerColor},set:function(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}},{key:"edgeBias",get:function(){return this._state.edgeBias},set:function(e){this._state.edgeBias=e||0,this.glRedraw()}},{key:"centerBias",get:function(){return this._state.centerBias},set:function(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}},{key:"power",get:function(){return this._state.power},set:function(e){this._state.power=null!=e?e:1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Wa=ee.memory,za=Z.AABB3(),Ka=function(e){I(n,rn);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._state=new St({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),r._numTriangles=0,r._edgeThreshold=i.edgeThreshold||10,r._aabb=null,r._obb=Z.OBB3();var a,s=r._state,o=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":s.primitive=o.POINTS,s.primitiveName=i.primitive;break;case"lines":s.primitive=o.LINES,s.primitiveName=i.primitive;break;case"line-loop":s.primitive=o.LINE_LOOP,s.primitiveName=i.primitive;break;case"line-strip":s.primitive=o.LINE_STRIP,s.primitiveName=i.primitive;break;case"triangles":s.primitive=o.TRIANGLES,s.primitiveName=i.primitive;break;case"triangle-strip":s.primitive=o.TRIANGLE_STRIP,s.primitiveName=i.primitive;break;case"triangle-fan":s.primitive=o.TRIANGLE_FAN,s.primitiveName=i.primitive;break;default:r.error("Unsupported value for 'primitive': '"+i.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=o.TRIANGLES,s.primitiveName=i.primitive}if(!i.positions)return r.error("Config expected: positions"),w(r);if(!i.indices)return r.error("Config expected: indices"),w(r);var l=i.positionsDecodeMatrix;if(l);else{var u=pn.getPositionsBounds(i.positions),c=pn.compressPositions(i.positions,u.min,u.max);a=c.quantized,s.positionsDecodeMatrix=c.decodeMatrix,s.positionsBuf=new pt(o,o.ARRAY_BUFFER,a,a.length,3,o.STATIC_DRAW),Wa.positions+=s.positionsBuf.numItems,Z.positions3ToAABB3(i.positions,r._aabb),Z.positions3ToAABB3(a,za,s.positionsDecodeMatrix),Z.AABB3ToOBB3(za,r._obb)}if(i.colors){var f=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors);s.colorsBuf=new pt(o,o.ARRAY_BUFFER,f,f.length,4,o.STATIC_DRAW),Wa.colors+=s.colorsBuf.numItems}if(i.uv){var p=pn.getUVBounds(i.uv),A=pn.compressUVs(i.uv,p.min,p.max),d=A.quantized;s.uvDecodeMatrix=A.decodeMatrix,s.uvBuf=new pt(o,o.ARRAY_BUFFER,d,d.length,2,o.STATIC_DRAW),Wa.uvs+=s.uvBuf.numItems}if(i.normals){var v=pn.compressNormals(i.normals),h=s.compressGeometry;s.normalsBuf=new pt(o,o.ARRAY_BUFFER,v,v.length,3,o.STATIC_DRAW,h),Wa.normals+=s.normalsBuf.numItems}var I=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices);s.indicesBuf=new pt(o,o.ELEMENT_ARRAY_BUFFER,I,I.length,1,o.STATIC_DRAW),Wa.indices+=s.indicesBuf.numItems;var y=an(a,I,s.positionsDecodeMatrix,r._edgeThreshold);return r._edgeIndicesBuf=new pt(o,o.ELEMENT_ARRAY_BUFFER,y,y.length,1,o.STATIC_DRAW),"triangles"===r._state.primitiveName&&(r._numTriangles=i.indices.length/3),r._buildHash(),Wa.meshes++,r}return P(n,[{key:"type",get:function(){return"VBOGeometry"}},{key:"isVBOGeometry",get:function(){return!0}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"aabb",get:function(){return this._aabb}},{key:"obb",get:function(){return this._obb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this);var e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),Wa.meshes--}}]),n}(),Ya={};function Xa(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(n,r){t.src||(console.error("load3DSGeometry: Parameter expected: src"),r());var i=e.canvas.spinner;i.processes++,ae.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),i.processes--,r());var a=Ya.parse.from3DS(e).edit.objects[0].mesh,s=a.vertices,o=a.uvt,l=a.indices;i.processes--,n(ae.apply(t,{primitive:"triangles",positions:s,normals:null,uv:o,indices:l}))}),(function(e){console.error("load3DSGeometry: "+e),i.processes--,r()}))}))}function qa(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(n,r){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),r());var i=e.canvas.spinner;i.processes++,ae.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),i.processes--,r());for(var a=Ya.parse.fromOBJ(e),s=Ya.edit.unwrap(a.i_verts,a.c_verts,3),o=Ya.edit.unwrap(a.i_norms,a.c_norms,3),l=Ya.edit.unwrap(a.i_uvt,a.c_uvt,2),u=new Int32Array(a.i_verts.length),c=0;c0?o:null,autoNormals:0===o.length,uv:l,indices:u}))}),(function(e){console.error("loadOBJGeometry: "+e),i.processes--,r()}))}))}function Ja(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.ySize||1;n<0&&(console.error("negative ySize not allowed - will invert"),n*=-1);var r=e.zSize||1;r<0&&(console.error("negative zSize not allowed - will invert"),r*=-1);var i=e.center,a=i?i[0]:0,s=i?i[1]:0,o=i?i[2]:0,l=-t+a,u=-n+s,c=-r+o,f=t+a,p=n+s,A=r+o;return ae.apply(e,{primitive:"lines",positions:[l,u,c,l,u,A,l,p,c,l,p,A,f,u,c,f,u,A,f,p,c,f,p,A],indices:[0,1,1,3,3,2,2,0,4,5,5,7,7,6,6,4,0,4,1,5,2,6,3,7]})}function Za(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);var n=e.divisions||1;n<0&&(console.error("negative divisions not allowed - will invert"),n*=-1),n<1&&(n=1);for(var r=(t=t||10)/(n=n||10),i=t/2,a=[],s=[],o=0,l=0,u=-i;l<=n;l++,u+=r)a.push(-i),a.push(0),a.push(u),a.push(i),a.push(0),a.push(u),a.push(u),a.push(0),a.push(-i),a.push(u),a.push(0),a.push(i),s.push(o++),s.push(o++),s.push(o++),s.push(o++);return ae.apply(e,{primitive:"lines",positions:a,indices:s})}function $a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);var r=e.xSegments||1;r<0&&(console.error("negative xSegments not allowed - will invert"),r*=-1),r<1&&(r=1);var i=e.xSegments||1;i<0&&(console.error("negative zSegments not allowed - will invert"),i*=-1),i<1&&(i=1);var a,s,o,l,u,c,f,p=e.center,A=p?p[0]:0,d=p?p[1]:0,v=p?p[2]:0,h=t/2,I=n/2,y=Math.floor(r)||1,m=Math.floor(i)||1,w=y+1,g=m+1,T=t/y,E=n/m,b=new Float32Array(w*g*3),D=new Float32Array(w*g*3),P=new Float32Array(w*g*2),R=0,C=0;for(a=0;a65535?Uint32Array:Uint16Array)(y*m*6);for(a=0;a0&&void 0!==arguments[0]?arguments[0]:{},t=e.radius||1;t<0&&(console.error("negative radius not allowed - will invert"),t*=-1),t*=.5;var n=e.tube||.3;n<0&&(console.error("negative tube not allowed - will invert"),n*=-1);var r=e.radialSegments||32;r<0&&(console.error("negative radialSegments not allowed - will invert"),r*=-1),r<4&&(r=4);var i=e.tubeSegments||24;i<0&&(console.error("negative tubeSegments not allowed - will invert"),i*=-1),i<4&&(i=4);var a=e.arc||2*Math.PI;a<0&&(console.warn("negative arc not allowed - will invert"),a*=-1),a>360&&(a=360);var s,o,l,u,c,f,p,A,d,v,h,I,y=e.center,m=y?y[0]:0,w=y?y[1]:0,g=y?y[2]:0,T=[],E=[],b=[],D=[];for(A=0;A<=i;A++)for(p=0;p<=r;p++)s=p/r*a,o=.785398+A/i*Math.PI*2,m=t*Math.cos(s),w=t*Math.sin(s),l=(t+n*Math.cos(o))*Math.cos(s),u=(t+n*Math.cos(o))*Math.sin(s),c=n*Math.sin(o),T.push(l+m),T.push(u+w),T.push(c+g),b.push(1-p/r),b.push(A/i),f=Z.normalizeVec3(Z.subVec3([l,u,c],[m,w,g],[]),[]),E.push(f[0]),E.push(f[1]),E.push(f[2]);for(A=1;A<=i;A++)for(p=1;p<=r;p++)d=(r+1)*A+p-1,v=(r+1)*(A-1)+p-1,h=(r+1)*(A-1)+p,I=(r+1)*A+p,D.push(d),D.push(v),D.push(h),D.push(h),D.push(I),D.push(d);return ae.apply(e,{positions:T,normals:E,uv:b,indices:D})}Ya.load=function(e,t){var n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=function(e){t(e.target.response)},n.send()},Ya.save=function(e,t){var n="data:application/octet-stream;base64,"+btoa(Ya.parse._buffToStr(e));window.location.href=n},Ya.clone=function(e){return JSON.parse(JSON.stringify(e))},Ya.bin={},Ya.bin.f=new Float32Array(1),Ya.bin.fb=new Uint8Array(Ya.bin.f.buffer),Ya.bin.rf=function(e,t){for(var n=Ya.bin.f,r=Ya.bin.fb,i=0;i<4;i++)r[i]=e[t+i];return n[0]},Ya.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Ya.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Ya.bin.rASCII0=function(e,t){for(var n="";0!=e[t];)n+=String.fromCharCode(e[t++]);return n},Ya.bin.wf=function(e,t,n){new Float32Array(e.buffer,t,1)[0]=n},Ya.bin.wsl=function(e,t,n){e[t]=n,e[t+1]=n>>8},Ya.bin.wil=function(e,t,n){e[t]=n,e[t+1]=n>>8,e[t+2]=n>>16,e[t+3]},Ya.parse={},Ya.parse._buffToStr=function(e){for(var t=new Uint8Array(e),n="",r=0;ri&&(i=l),ua&&(a=u),cs&&(s=c)}return{min:{x:t,y:n,z:r},max:{x:i,y:a,z:s}}};var ts=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._type=i.type||(i.src?i.src.split(".").pop():null)||"jpg",r._pos=Z.vec3(i.pos||[0,0,0]),r._up=Z.vec3(i.up||[0,1,0]),r._normal=Z.vec3(i.normal||[0,0,1]),r._height=i.height||1,r._origin=Z.vec3(),r._rtcPos=Z.vec3(),r._imageSize=Z.vec2(),r._texture=new ja(g(r)),r._image=new Image,"jpg"!==r._type&&"png"!==r._type&&(r.error('Unsupported type - defaulting to "jpg"'),r._type="jpg"),r._node=new Ra(g(r),{matrix:Z.inverseMat4(Z.lookAtMat4v(r._pos,Z.subVec3(r._pos,r._normal,Z.mat4()),r._up,Z.mat4())),children:[r._bitmapMesh=new ca(g(r),{scale:[1,1,1],rotation:[-90,0,0],collidable:i.collidable,pickable:i.pickable,opacity:i.opacity,clippable:i.clippable,geometry:new vn(g(r),$a({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new wn(g(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0})})]}),i.image?r.image=i.image:i.src?r.src=i.src:i.imageData&&(r.imageData=i.imageData),r.scene._bitmapCreated(g(r)),r}return P(n,[{key:"visible",get:function(){return this._bitmapMesh.visible},set:function(e){this._bitmapMesh.visible=e}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}},{key:"src",get:function(){return this._image.src},set:function(e){var t=this;if(e)switch(this._image.onload=function(){t._texture.image=t._image,t._imageSize[0]=t._image.width,t._imageSize[1]=t._image.height,t._updateBitmapMeshScale()},this._image.src=e,e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}},{key:"imageData",get:function(){var e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")},set:function(e){var t=this;this._image.onload=function(){t._texture.image=image,t._imageSize[0]=image.width,t._imageSize[1]=image.height,t._updateBitmapMeshScale()},this._image.src=e}},{key:"type",get:function(){return this._type},set:function(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}},{key:"pos",get:function(){return this._pos}},{key:"normal",get:function(){return this._normal}},{key:"up",get:function(){return this._up}},{key:"height",get:function(){return this._height},set:function(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}},{key:"collidable",get:function(){return this._bitmapMesh.collidable},set:function(e){this._bitmapMesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._bitmapMesh.clippable},set:function(e){this._bitmapMesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._bitmapMesh.pickable},set:function(e){this._bitmapMesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._bitmapMesh.opacity},set:function(e){this._bitmapMesh.opacity=e}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._bitmapDestroyed(this)}},{key:"_updateBitmapMeshScale",value:function(){var e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height*e,1,this._height]}}]),n}(),ns=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,i))._positions=i.positions||[],r._origin=Z.vec3(i.origin||[0,0,0]),i.indices)r._indices=i.indices;else{r._indices=[];for(var a=0,s=r._positions.length/3-1;a1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"BCFViewpoints",e,i)).originatingSystem=i.originatingSystem||"xeokit.io",r.authoringTool=i.authoringTool||"xeokit.io",r}return P(n,[{key:"getViewpoint",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=this.viewer.scene,r=n.camera,i=n.realWorldOffset,a=!0===t.reverseClippingPlanes,s={},o=Z.normalizeVec3(Z.subVec3(r.look,r.eye,Z.vec3())),l=r.eye,u=r.up;r.yUp&&(o=cs(o),l=cs(l),u=cs(u));var c=ls(Z.addVec3(l,i));"ortho"===r.projection?s.orthogonal_camera={camera_view_point:c,camera_direction:ls(o),camera_up_vector:ls(u),view_to_world_scale:r.ortho.scale}:s.perspective_camera={camera_view_point:c,camera_direction:ls(o),camera_up_vector:ls(u),field_of_view:r.perspective.fov};var f=n.sectionPlanes;for(var A in f)if(f.hasOwnProperty(A)){var d=f[A];if(!d.active)continue;var v=d.pos,h=void 0;h=a?Z.negateVec3(d.dir,Z.vec3()):d.dir,r.yUp&&(v=cs(v),h=cs(h)),Z.addVec3(v,i),v=ls(v),h=ls(h),s.clipping_planes||(s.clipping_planes=[]),s.clipping_planes.push({location:v,direction:h})}var I=n.lineSets;for(var y in I)if(I.hasOwnProperty(y)){var m=I[y];s.lines||(s.lines=[]);for(var w=m.positions,g=m.indices,T=0,E=g.length/2;T1&&void 0!==arguments[1]?arguments[1]:{};if(e){var r=this.viewer,i=r.scene,a=i.camera,s=!1!==n.rayCast,o=!1!==n.immediate,l=!1!==n.reset,u=i.realWorldOffset,c=!0===n.reverseClippingPlanes;if(i.clearSectionPlanes(),e.clipping_planes&&e.clipping_planes.forEach((function(e){var t=us(e.location,rs),n=us(e.direction,rs);c&&Z.negateVec3(n),Z.subVec3(t,u),a.yUp&&(t=fs(t),n=fs(n)),new Ia(i,{pos:t,dir:n})})),i.clearLines(),e.lines){var f=[],p=[],A=0;e.lines.forEach((function(e){e.start_point&&e.end_point&&(f.push(e.start_point.x),f.push(e.start_point.y),f.push(e.start_point.z),f.push(e.end_point.x),f.push(e.end_point.y),f.push(e.end_point.z),p.push(A++),p.push(A++))})),new ns(i,{positions:f,indices:p,clippable:!1,collidable:!0})}if(i.clearBitmaps(),e.bitmaps&&e.bitmaps.forEach((function(e){var t=e.bitmap_type||"jpg",n=e.bitmap_data,r=us(e.location,is),s=us(e.normal,as),o=us(e.up,ss),l=e.height||1;t&&n&&r&&s&&o&&(a.yUp&&(r=fs(r),s=fs(s),o=fs(o)),new ts(i,{src:n,type:t,pos:r,normal:s,up:o,clippable:!1,collidable:!0,height:l}))})),l&&(i.setObjectsXRayed(i.xrayedObjectIds,!1),i.setObjectsHighlighted(i.highlightedObjectIds,!1),i.setObjectsSelected(i.selectedObjectIds,!1)),e.components){if(e.components.visibility){e.components.visibility.default_visibility?(i.setObjectsVisible(i.objectIds,!0),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.visible=!1}))}))):(i.setObjectsVisible(i.objectIds,!1),e.components.visibility.exceptions&&e.components.visibility.exceptions.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.visible=!0}))})));var d=e.components.visibility.view_setup_hints;d&&(!1===d.spaces_visible&&i.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcSpace"),!1),!1===d.openings_visible&&i.setObjectsVisible(r.metaScene.getObjectIDsByType("IfcOpening"),!1),d.space_boundaries_visible)}e.components.selection&&(i.setObjectsSelected(i.selectedObjectIds,!1),e.components.selection.forEach((function(e){return t._withBCFComponent(n,e,(function(e){return e.selected=!0}))}))),e.components.coloring&&e.components.coloring.forEach((function(e){var r=e.color,i=0,a=!1;8===r.length&&((i=parseInt(r.substring(0,2),16)/256)<=1&&i>=.95&&(i=1),r=r.substring(2),a=!0);var s=[parseInt(r.substring(0,2),16)/256,parseInt(r.substring(2,4),16)/256,parseInt(r.substring(4,6),16)/256];e.components.map((function(e){return t._withBCFComponent(n,e,(function(e){e.colorize=s,a&&(e.opacity=i)}))}))}))}if(e.perspective_camera||e.orthogonal_camera){var v,h,I,y;if(e.perspective_camera?(v=us(e.perspective_camera.camera_view_point,rs),h=us(e.perspective_camera.camera_direction,rs),I=us(e.perspective_camera.camera_up_vector,rs),a.perspective.fov=e.perspective_camera.field_of_view,y="perspective"):(v=us(e.orthogonal_camera.camera_view_point,rs),h=us(e.orthogonal_camera.camera_direction,rs),I=us(e.orthogonal_camera.camera_up_vector,rs),a.ortho.scale=e.orthogonal_camera.view_to_world_scale,y="ortho"),Z.subVec3(v,u),a.yUp&&(v=fs(v),h=fs(h),I=fs(I)),s){var m=i.pick({pickSurface:!0,origin:v,direction:h});h=m?m.worldPos:Z.addVec3(v,h,rs)}else h=Z.addVec3(v,h,rs);o?(a.eye=v,a.look=h,a.up=I,a.projection=y):r.cameraFlight.flyTo({eye:v,look:h,up:I,duration:n.duration,projection:y})}}}},{key:"_withBCFComponent",value:function(e,t,n){var r=this.viewer,i=r.scene;if(t.authoring_tool_id&&t.originating_system===this.originatingSystem){var a=t.authoring_tool_id,s=i.objects[a];if(s)return void n(s);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[a])return void i.withObjects(r.metaScene.getObjectIDsInSubtree(a),n)}if(t.ifc_guid){var o=t.ifc_guid,l=i.objects[o];if(l)return void n(l);if(e.updateCompositeObjects)if(r.metaScene.metaObjects[o])return void i.withObjects(r.metaScene.getObjectIDsInSubtree(o),n);Object.keys(i.models).forEach((function(t){var a=Z.globalizeObjectId(t,o),s=i.objects[a];s?n(s):e.updateCompositeObjects&&r.metaScene.metaObjects[a]&&i.withObjects(r.metaScene.getObjectIDsInSubtree(a),n)}))}}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this)}}]),n}();function ls(e){return{x:e[0],y:e[1],z:e[2]}}function us(e,t){return(t=new Float64Array(3))[0]=e.x,t[1]=e.y,t[2]=e.z,t}function cs(e){return new Float64Array([e[0],-e[2],e[1]])}function fs(e){return new Float64Array([e[0],e[2],-e[1]])}function ps(e){var t="";return t+=Math.round(255*e[0]).toString(16).padStart(2,"0"),t+=Math.round(255*e[1]).toString(16).padStart(2,"0"),t+=Math.round(255*e[2]).toString(16).padStart(2,"0")}var As=Z.vec3(),ds=function(e,t,n,r){var i=e-n,a=t-r;return Math.sqrt(i*i+a*a)},vs=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._eventSubs={};var a=r.plugin.viewer.scene;r._originMarker=new Me(a,i.origin),r._targetMarker=new Me(a,i.target),r._originWorld=Z.vec3(),r._targetWorld=Z.vec3(),r._wp=new Float64Array(24),r._vp=new Float64Array(24),r._pp=new Float64Array(24),r._cp=new Float64Array(8),r._xAxisLabelCulled=!1,r._yAxisLabelCulled=!1,r._zAxisLabelCulled=!1,r._color=i.color||r.plugin.defaultColor;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._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._lengthWire=new Fe(r._container,{color:r._color,thickness:2,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._xAxisWire=new Fe(r._container,{color:"#FF0000",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._yAxisWire=new Fe(r._container,{color:"green",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._zAxisWire=new Fe(r._container,{color:"blue",thickness:1,thicknessClickable:6,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._lengthLabel=new Ue(r._container,{fillColor:r._color,prefix:"",text:"",zIndex:void 0!==e.zIndex?e.zIndex+4:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._xAxisLabel=new Ue(r._container,{fillColor:"red",prefix:"X",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._yAxisLabel=new Ue(r._container,{fillColor:"green",prefix:"Y",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._zAxisLabel=new Ue(r._container,{fillColor:"blue",prefix:"Z",text:"",zIndex:void 0!==e.zIndex?e.zIndex+3:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._wpDirty=!1,r._vpDirty=!1,r._cpDirty=!1,r._visible=!1,r._originVisible=!1,r._targetVisible=!1,r._wireVisible=!1,r._axisVisible=!1,r._xAxisVisible=!1,r._yAxisVisible=!1,r._zAxisVisible=!1,r._axisEnabled=!0,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._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._onMetricsUnits=a.metrics.on("units",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsScale=a.metrics.on("scale",(function(){r._cpDirty=!0,r._needUpdate()})),r._onMetricsOrigin=a.metrics.on("origin",(function(){r._cpDirty=!0,r._needUpdate()})),r.approximate=i.approximate,r.visible=i.visible,r.originVisible=i.originVisible,r.targetVisible=i.targetVisible,r.wireVisible=i.wireVisible,r.axisVisible=i.axisVisible,r.xAxisVisible=i.xAxisVisible,r.yAxisVisible=i.yAxisVisible,r.zAxisVisible=i.zAxisVisible,r.labelsVisible=i.labelsVisible,r}return P(n,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;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._targetWorld[0],this._wp[5]=this._originWorld[1],this._wp[6]=this._originWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._originWorld[2],this._wp[11]=1,this._wp[12]=this._targetWorld[0],this._wp[13]=this._targetWorld[1],this._wp[14]=this._targetWorld[2],this._wp[15]=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._vp[15]=1,this._vpDirty=!1,this._cpDirty=!0);var t=this._originMarker.viewPos[2],n=this._targetMarker.viewPos[2];if(t>-.3||n>-.3)return this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0),this._lengthLabel.setCulled(!0),this._xAxisWire.setVisible(!1),this._yAxisWire.setVisible(!1),this._zAxisWire.setVisible(!1),this._lengthWire.setVisible(!1),this._originDot.setVisible(!1),void this._targetDot.setVisible(!1);if(this._cpDirty){Z.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var r=this._pp,i=this._cp,a=e.canvas.canvas.getBoundingClientRect(),s=this._container.getBoundingClientRect(),o=a.top-s.top,l=a.left-s.left,u=e.canvas.boundary,c=u[2],f=u[3],p=0,A=this.plugin.viewer.scene.metrics,d=A.scale,v=A.units,h=A.unitsInfo[v].abbrev,I=0,y=r.length;I0&&void 0!==arguments[0]?arguments[0]:{};b(this,e),this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=t.messages,this.locale=t.locale}return P(e,[{key:"messages",set:function(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}},{key:"loadMessages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var t in e)this._messages[t]=e[t];this.messages=this._messages}},{key:"clearMessages",value:function(){this.messages={}}},{key:"locales",get:function(){return this._locales}},{key:"locale",get:function(){return this._locale},set:function(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}},{key:"translate",value:function(e,t){var n=this._messages[this._locale];if(!n)return null;var r=Is(e,n);return r?t?ys(r,t):r:null}},{key:"translatePlurals",value:function(e,t,n){var r=this._messages[this._locale];if(!r)return null;var i=Is(e,r);return(i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one)?(i=ys(i,[t]),n&&(i=ys(i,n)),i):null}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==n&&(this._events[e]=t||!0);var r=this._eventSubs[e];if(r)for(var i in r){if(r.hasOwnProperty(i))r[i].callback(t)}}},{key:"on",value:function(e,t){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new G),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});var n=this._eventSubs[e];n||(n={},this._eventSubs[e]=n);var r=this._eventSubIDMap.addItem();n[r]={callback:t},this._eventSubEvents[r]=e;var i=this._events[e];return void 0!==i&&t(i),r}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var n=this._eventSubs[t];n&&delete n[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function Is(e,t){if(t[e])return t[e];for(var n=e.split("."),r=t,i=0,a=n.length;r&&i1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,n){return"{{"===e?"{":"}}"===e?"}":t[n]}))}var ms=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).t=i.t,r}return P(n,[{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"tangent",get:function(){return this.getTangent(this._t)}},{key:"length",get:function(){var e=this._getLengths();return e[e.length-1]}},{key:"getTangent",value:function(e){var t=1e-4;void 0===e&&(e=this._t);var n=e-t,r=e+t;n<0&&(n=0),r>1&&(r=1);var i=this.getPoint(n),a=this.getPoint(r),s=Z.subVec3(a,i,[]);return Z.normalizeVec3(s,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,n=[];for(t=0;t<=e;t++)n.push(this.getPoint(t/e));return n}},{key:"_getLengths",value:function(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,n,r=[],i=this.getPoint(0),a=0;for(r.push(0),n=1;n<=e;n++)t=this.getPoint(n/e),a+=Z.lenVec3(Z.subVec3(t,i,[])),r.push(a),i=t;return this.cacheArcLengths=r,r}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var n,r=this._getLengths(),i=0,a=r.length;n=t||e*r[a-1];for(var s,o=0,l=a-1;o<=l;)if((s=r[i=Math.floor(o+(l-o)/2)]-n)<0)o=i+1;else{if(!(s>0)){l=i;break}l=i-1}if(r[i=l]===n)return i/(a-1);var u=r[i];return(i+(n-u)/(r[i+1]-u))/(a-1)}}]),n}(),ws=function(e){I(n,ms);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).points=i.points,r.t=i.t,r}return P(n,[{key:"points",get:function(){return this._points},set:function(e){this._points=e||[]}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=this.points;if(!(t.length<3)){var n=(t.length-1)*e,r=Math.floor(n),i=n-r,a=t[0===r?r:r-1],s=t[r],o=t[r>t.length-2?t.length-1:r+1],l=t[r>t.length-3?t.length-1:r+2],u=Z.vec3();return u[0]=Z.catmullRomInterpolate(a[0],s[0],o[0],l[0],i),u[1]=Z.catmullRomInterpolate(a[1],s[1],o[1],l[1],i),u[2]=Z.catmullRomInterpolate(a[2],s[2],o[2],l[2],i),u}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}},{key:"getJSON",value:function(){return{points:points,t:this._t}}}]),n}(),gs=Z.vec3(),Ts=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._frames=[],r._eyeCurve=new ws(g(r)),r._lookCurve=new ws(g(r)),r._upCurve=new ws(g(r)),i.frames&&(r.addFrames(i.frames),r.smoothFrameTimes(1)),r}return P(n,[{key:"type",get:function(){return"CameraPath"}},{key:"frames",get:function(){return this._frames}},{key:"eyeCurve",get:function(){return this._eyeCurve}},{key:"lookCurve",get:function(){return this._lookCurve}},{key:"upCurve",get:function(){return this._upCurve}},{key:"saveFrame",value:function(e){var t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}},{key:"addFrame",value:function(e,t,n,r){var i={t:e,eye:t.slice(0),look:n.slice(0),up:r.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}},{key:"addFrames",value:function(e){for(var t,n=0,r=e.length;n1?1:e,t.eye=this._eyeCurve.getPoint(e,gs),t.look=this._lookCurve.getPoint(e,gs),t.up=this._upCurve.getPoint(e,gs)}},{key:"sampleFrame",value:function(e,t,n,r){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,n),this._upCurve.getPoint(e,r)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=Z.vec3(),n=0;this._frames[0].t=0;for(var r=[],i=1,a=this._frames.length;i1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._look1=Z.vec3(),r._eye1=Z.vec3(),r._up1=Z.vec3(),r._look2=Z.vec3(),r._eye2=Z.vec3(),r._up2=Z.vec3(),r._orthoScale1=1,r._orthoScale2=1,r._flying=!1,r._flyEyeLookUp=!1,r._flyingEye=!1,r._flyingLook=!1,r._callback=null,r._callbackScope=null,r._time1=null,r._time2=null,r.easing=!1!==i.easing,r.duration=i.duration,r.fit=i.fit,r.fitFOV=i.fitFOV,r.trail=i.trail,r}return P(n,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,n){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=n;var r,i,a,s,o,l=this.scene.camera,u=!!e.projection&&e.projection!==l.projection;if(this._eye1[0]=l.eye[0],this._eye1[1]=l.eye[1],this._eye1[2]=l.eye[2],this._look1[0]=l.look[0],this._look1[1]=l.look[1],this._look1[2]=l.look[2],this._up1[0]=l.up[0],this._up1[1]=l.up[1],this._up1[2]=l.up[2],this._orthoScale1=l.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)i=e.eye,a=e.look,s=e.up;else if(e.eye)i=e.eye;else if(e.look)a=e.look;else{var c=e;if((ae.isNumeric(c)||ae.isString(c))&&(o=c,!(c=this.scene.components[o])))return this.error("Component not found: "+ae.inQuotes(o)),void(t&&(n?t.call(n):t()));u||(r=c.aabb||this.scene.aabb)}var f=e.poi;if(r){if(r[3]=1;e>1&&(e=1);var r=this.easing?n._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(Z.subVec3(i.eye,i.look,Rs),i.eye=Z.lerpVec3(r,0,1,this._eye1,this._eye2,Ds),i.look=Z.subVec3(Ds,Rs,bs)):this._flyingLook&&(i.look=Z.lerpVec3(r,0,1,this._look1,this._look2,bs),i.up=Z.lerpVec3(r,0,1,this._up1,this._up2,Ps)):this._flyingEyeLookUp&&(i.eye=Z.lerpVec3(r,0,1,this._eye1,this._eye2,Ds),i.look=Z.lerpVec3(r,0,1,this._look1,this._look2,bs),i.up=Z.lerpVec3(r,0,1,this._up1,this._up2,Ps)),this._projection2){var a="ortho"===this._projection2?n._easeOutExpo(e,0,1,1):n._easeInCubic(e,0,1,1);i.customProjection.matrix=Z.lerpMat4(a,0,1,this._projMatrix1,this._projMatrix2)}else i.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return i.ortho.scale=this._orthoScale2,void this.stop();Ae.scheduleTask(this._update,this)}}},{key:"stop",value:function(){if(this._flying){this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);var e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}}},{key:"cancel",value:function(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}},{key:"duration",get:function(){return this._duration/1e3},set:function(e){this._duration=e?1e3*e:500,this.stop()}},{key:"fit",get:function(){return this._fit},set:function(e){this._fit=!1!==e}},{key:"fitFOV",get:function(){return this._fitFOV},set:function(e){this._fitFOV=e||45}},{key:"trail",get:function(){return this._trail},set:function(e){this._trail=!!e}},{key:"destroy",value:function(){this.stop(),v(T(n.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,n,r){return n*(e/=r)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,n,r){return n*(1-Math.pow(2,-10*e/r))+t}}]),n}(),_s=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cameraFlightAnimation=new Cs(g(r)),r._t=0,r.state=n.SCRUBBING,r._playingFromT=0,r._playingToT=0,r._playingRate=i.playingRate||1,r._playingDir=1,r._lastTime=null,r.cameraPath=i.cameraPath,r._tick=r.scene.on("tick",r._updateT,g(r)),r}return P(n,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,r,i=performance.now(),a=this._lastTime?.001*(i-this._lastTime):0;if(this._lastTime=i,0!==a)switch(this.state){case n.SCRUBBING:return;case n.PLAYING:if(this._t+=this._playingRate*a,0===(t=this._cameraPath.frames.length)||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=n.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case n.PLAYING_TO:r=this._t+this._playingRate*a*this._playingDir,(this._playingDir<0&&r<=this._playingToT||this._playingDir>0&&r>=this._playingToT)&&(r=this._playingToT,this.state=n.SCRUBBING,this.fire("stopped")),this._t=r,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"cameraPath",get:function(){return this._cameraPath},set:function(e){this._cameraPath=e}},{key:"rate",get:function(){return this._playingRate},set:function(e){this._playingRate=e}},{key:"play",value:function(){this._cameraPath&&(this._lastTime=null,this.state=n.PLAYING)}},{key:"playToT",value:function(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=n.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var n=t.frames[e];n?this.playToT(n.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var r=this._cameraPath;if(r){var i=r.frames[e];i?(this.state=n.SCRUBBING,this._cameraFlightAnimation.flyTo(i,t)):this.error("flyToFrame - frame index out of range: "+e)}}},{key:"scrubToT",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=n.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=n.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=n.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),n}();_s.STOPPED=0,_s.SCRUBBING=1,_s.PLAYING=2,_s.PLAYING_TO=3;var Bs=Z.vec3(),Os=Z.vec3();Z.vec3();var Ss=Z.vec3([0,-1,0]),Ns=Z.vec4([0,0,0,1]),Ls=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._src=null,r._image=null,r._pos=Z.vec3(),r._origin=Z.vec3(),r._rtcPos=Z.vec3(),r._dir=Z.vec3(),r._size=1,r._imageSize=Z.vec2(),r._texture=new ja(g(r)),r._plane=new ca(g(r),{geometry:new vn(g(r),$a({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new wn(g(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0}),clippable:i.clippable}),r._grid=new ca(g(r),{geometry:new vn(g(r),Za({size:1,divisions:10})),material:new wn(g(r),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:i.clippable}),r._node=new Ra(g(r),{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[r._plane,r._grid]}),r._gridVisible=!1,r.visible=!0,r.gridVisible=i.gridVisible,r.position=i.position,r.rotation=i.rotation,r.dir=i.dir,r.size=i.size,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"visible",get:function(){return this._plane.visible},set:function(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}},{key:"gridVisible",get:function(){return this._gridVisible},set:function(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),ye(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}},{key:"rotation",get:function(){return this._node.rotation},set:function(e){this._node.rotation=e}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"dir",get:function(){return this._dir},set:function(e){if(this._dir.set(e||[0,0,-1]),e){var t=this.scene.center,n=[-this._dir[0],-this._dir[1],-this._dir[2]];Z.subVec3(t,this.position,Bs);var r=-Z.dotVec3(n,Bs);Z.normalizeVec3(n),Z.mulVec3Scalar(n,r,Os),Z.vec3PairToQuaternion(Ss,e,Ns),this._node.quaternion=Ns}}},{key:"collidable",get:function(){return this._node.collidable},set:function(e){this._node.collidable=!1!==e}},{key:"clippable",get:function(){return this._node.clippable},set:function(e){this._node.clippable=!1!==e}},{key:"pickable",get:function(){return this._node.pickable},set:function(e){this._node.pickable=!1!==e}},{key:"opacity",get:function(){return this._node.opacity},set:function(e){this._node.opacity=e}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],n=this._imageSize[1];if(t>n){var r=n/t;this._node.scale=[e,1,e*r]}else{var i=t/n;this._node.scale=[e*i,1,e]}}}]),n}(),xs=function(e){I(n,en);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=g(r=t.call(this,e,i));r._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var s=r.scene.camera,o=r.scene.canvas;return r._onCameraViewMatrix=s.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=s.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=o.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new St({type:"point",pos:Z.vec3([1,1,1]),color:Z.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(a._shadowViewMatrixDirty){a._shadowViewMatrix||(a._shadowViewMatrix=Z.identityMat4());var e=a._state.pos,t=s.look,n=s.up;Z.lookAtMat4v(e,t,n,a._shadowViewMatrix),a._shadowViewMatrixDirty=!1}return a._shadowViewMatrix},getShadowProjMatrix:function(){if(a._shadowProjMatrixDirty){a._shadowProjMatrix||(a._shadowProjMatrix=Z.identityMat4());var e=a.scene.canvas.canvas;Z.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,a._shadowProjMatrix),a._shadowProjMatrixDirty=!1}return a._shadowProjMatrix},getShadowRenderBuf:function(){return a._shadowRenderBuf||(a._shadowRenderBuf=new Pt(a.scene.canvas.canvas,a.scene.canvas.gl,{size:[1024,1024]})),a._shadowRenderBuf}}),r.pos=i.pos,r.color=i.color,r.intensity=i.intensity,r.constantAttenuation=i.constantAttenuation,r.linearAttenuation=i.linearAttenuation,r.quadraticAttenuation=i.quadraticAttenuation,r.castsShadow=i.castsShadow,r.scene._lightCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"PointLight"}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"constantAttenuation",get:function(){return this._state.attenuation[0]},set:function(e){this._state.attenuation[0]=e||0,this.glRedraw()}},{key:"linearAttenuation",get:function(){return this._state.attenuation[1]},set:function(e){this._state.attenuation[1]=e||0,this.glRedraw()}},{key:"quadraticAttenuation",get:function(){return this._state.attenuation[2]},set:function(e){this._state.attenuation[2]=e||0,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}();function Ms(e){return 0==(e&e-1)}function Fs(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var Hs=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);var a=(r=t.call(this,e,i)).scene.canvas.gl;return r._state=new St({texture:new Fa({gl:a,target:a.TEXTURE_CUBE_MAP}),flipY:r._checkFlipY(i.minFilter),encoding:r._checkEncoding(i.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),r._src=i.src,r._images=[],r._loadSrc(i.src),ee.memory.textures++,r}return P(n,[{key:"type",get:function(){return"CubeTexture"}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}},{key:"_loadSrc",value:function(e){var t=this,n=this.scene.canvas.gl;this._images=[];for(var r=!1,i=0,a=function(a){var s=new Image;s.onload=function(){var e=s,o=a;return function(){if(!r&&(e=function(e){if(!Ms(e.width)||!Ms(e.height)){var t=document.createElement("canvas");t.width=Fs(e.width),t.height=Fs(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(e),t._images[o]=e,6===++i)){var a=t._state.texture;a||(a=new Fa({gl:n,target:n.TEXTURE_CUBE_MAP}),t._state.texture=a),a.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}}(),s.onerror=function(){r=!0},s.src=e[a]},s=0;s1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightsState.addReflectionMap(r._state),r.scene._reflectionMapCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),n}(),Gs=function(e){I(n,Hs);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightMapCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),n}(),ks=function(e){I(n,Me);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,{entity:i.entity,occludable:i.occludable,worldPos:i.worldPos}))._occluded=!1,r._visible=!0,r._src=null,r._image=null,r._pos=Z.vec3(),r._origin=Z.vec3(),r._rtcPos=Z.vec3(),r._dir=Z.vec3(),r._size=1,r._imageSize=Z.vec2(),r._texture=new ja(g(r),{src:i.src}),r._geometry=new vn(g(r),{primitive:"triangles",positions:[3,3,0,-3,3,0,-3,-3,0,3,-3,0],normals:[-1,0,0,-1,0,0,-1,0,0,-1,0,0],uv:[1,-1,0,-1,0,0,1,0],indices:[0,1,2,0,2,3]}),r._mesh=new ca(g(r),{geometry:r._geometry,material:new wn(g(r),{ambient:[.9,.3,.9],shininess:30,diffuseMap:r._texture,backfaces:!0}),scale:[1,1,1],position:i.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),r.visible=!0,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,r.size=i.size,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,v(T(n.prototype),"_setVisible",this).call(this,e)}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"collidable",get:function(){return this._mesh.collidable},set:function(e){this._mesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._mesh.clippable},set:function(e){this._mesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._mesh.pickable},set:function(e){this._mesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._mesh.opacity},set:function(e){this._mesh.opacity=e}},{key:"_updatePlaneSizeFromImage",value:function(){var e=.5*this._size,t=this._imageSize[0],n=this._imageSize[1],r=n/t;this._geometry.positions=t>n?[e,e*r,0,-e,e*r,0,-e,-e*r,0,e,-e*r,0]:[e/r,e,0,-e/r,e,0,-e/r,-e,0,e/r,-e,0]}}]),n}(),Vs=function(){function e(t){b(this,e),this._eye=Z.vec3(),this._look=Z.vec3(),this._up=Z.vec3(),this._projection={},t&&this.saveCamera(t)}return P(e,[{key:"saveCamera",value:function(e){var t=e.camera,n=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:n.fov,fovAxis:n.fovAxis,near:n.near,far:n.far};break;case"ortho":this._projection={projection:"ortho",scale:n.scale,near:n.near,far:n.far};break;case"frustum":this._projection={projection:"frustum",left:n.left,right:n.right,top:n.top,bottom:n.bottom,near:n.near,far:n.far};break;case"custom":this._projection={projection:"custom",matrix:n.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var n=e.camera,r=this._projection;function i(){switch(r.type){case"perspective":n.perspective.fov=r.fov,n.perspective.fovAxis=r.fovAxis,n.perspective.near=r.near,n.perspective.far=r.far;break;case"ortho":n.ortho.scale=r.scale,n.ortho.near=r.near,n.ortho.far=r.far;break;case"frustum":n.frustum.left=r.left,n.frustum.right=r.right,n.frustum.top=r.top,n.frustum.bottom=r.bottom,n.frustum.near=r.near,n.frustum.far=r.far;break;case"custom":n.customProjection.matrix=r.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:r.scale,projection:r.projection},(function(){i(),t()})):(n.eye=this._eye,n.look=this._look,n.up=this._up,i(),n.projection=r.projection)}}]),e}(),js=Z.vec3(),Qs=function(){function e(t){if(b(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,t){var n=t.metaScene.scene;this.saveObjects(n,t)}}return P(e,[{key:"saveObjects",value:function(e,t,n){var r=t.rootMetaObject;if(r){var i=r.getObjectIDsInSubtree();this.numObjects=0,this._mask=n?ae.apply(n,{}):null;for(var a=e.objects,s=!n||n.visible,o=!n||n.edges,l=!n||n.xrayed,u=!n||n.highlighted,c=!n||n.selected,f=!n||n.clippable,p=!n||n.pickable,A=!n||n.colorize,d=!n||n.opacity,v=0,h=i.length;v1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.v3=i.v3,r.t=i.t,r}return P(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||Z.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||Z.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||Z.vec3([0,0,0])}},{key:"v3",get:function(){return this._v3},set:function(e){this.fire("v3",this._v3=e||Z.vec3([0,0,0]))}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=Z.vec3();return t[0]=Z.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=Z.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=Z.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}]),n}(),Ys=function(e){I(n,ms);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cachedLengths=[],r._dirty=!0,r._curves=[],r._t=0,r._dirtySubs=[],r._destroyedSubs=[],r.curves=i.curves||[],r.t=i.t,r}return P(n,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,n,r;for(e=e||[],n=0,r=this._curves.length;n1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"length",get:function(){var e=this._getCurveLengths();return e[e.length-1]}},{key:"getPoint",value:function(e){for(var t,n=e*this.length,r=this._getCurveLengths(),i=0;i=n){var a=1-(r[i]-n)/(t=this._curves[i]).length;return t.getPointAt(a)}i++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],n=0,r=this._curves.length;for(e=0;e1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.t=i.t,r}return P(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||Z.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||Z.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||Z.vec3([0,0,0])}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=Z.vec3();return t[0]=Z.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=Z.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=Z.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}]),n}(),qs=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}(),Js=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}()),Zs=0;function $s(){return Zs++,Js}var eo={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},to=new Float32Array([1,1,1,1]),no=new Float32Array([0,0,0,1]),ro=Z.vec4(),io=Z.vec3(),ao=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;ro[0]=x,ro[1]=M,ro[2]=N.blendCutoff,ro[3]=N.blendFactor,c.uniform4fv(this._uSAOParams,ro),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===eo["".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===eo["".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===eo["".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?no:to)}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}(),so=function(e){I(n,ao);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}(),oo=function(e){I(n,so);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!1,edges:!0})}return P(n)}(),lo=function(e){I(n,ao);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}(),uo=function(e){I(n,lo);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0,edges:!0})}return P(n)}(),co=function(e){I(n,ao);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}(),fo=function(e){I(n,ao);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}(),po=function(e){I(n,ao);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}(),Ao=function(e){I(n,ao);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}(),vo=function(e){I(n,so);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}(),ho=function(e){I(n,so);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}(),yo=function(e){I(n,oo);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}(),mo=function(e){I(n,oo);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}(),wo=function(e){I(n,so);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}(),go=function(e){I(n,so);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}(),To=function(e){I(n,so);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}(),Eo=function(e){I(n,so);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}(),bo=function(e){I(n,so);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}(),Do=function(e){I(n,so);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}(),Po=function(e){I(n,so);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}(),Ro=function(e){I(n,so);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}(),_o=function(e){I(n,so);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=[]})),No=Z.mat4(),Lo=Z.mat4();function xo(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 Ho(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 Uo=Z.vec3(),Go=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.snapPickOrigin[0]=l[0],e.snapPickOrigin[1]=l[1],e.snapPickOrigin[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.snapPickCoordinateScale[0]=Z.safeInv(f[0]),e.snapPickCoordinateScale[1]=Z.safeInv(f[1]),e.snapPickCoordinateScale[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.snapPickLayerNumber),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}(),ko=Z.vec3(),Vo=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.snapPickOrigin[0]=l[0],e.snapPickOrigin[1]=l[1],e.snapPickOrigin[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.snapPickCoordinateScale[0]=Z.safeInv(c[0]),e.snapPickCoordinateScale[1]=Z.safeInv(c[1]),e.snapPickCoordinateScale[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.snapPickLayerNumber),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("gl_PointSize = 1.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("// 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}(),jo=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 Go(this._scene,!1)),this._snapDepthBufInitRenderer}},{key:"snapDepthRenderer",get:function(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Vo(this._scene)),this._snapDepthRenderer}},{key:"_destroy",value:function(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}]),e}(),Qo={};var Wo=Z.mat4(),zo=Z.mat4(),Ko=Z.vec4([0,0,0,1]),Yo=Z.vec4([0,0,0,1]),Xo=Z.vec4([0,0,0,1]),qo=Z.OBB3(),Jo=Z.vec3(),Zo=Z.vec3(),$o=Z.vec3(),el=Z.vec3(),tl=Z.vec3(),nl=Z.vec3(),rl=Z.vec3(),il=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=Oo[r])||(i=new Bo(n),Oo[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Oo[r],i._destroy()}))),i),this._snapBatchingRenderers=function(e){var t=e.id,n=Qo[t];return n||(n=new jo(e),Qo[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete Qo[t],n._destroy()}))),n}(t.model.scene),this._buffer=new So(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new St({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=Wo;h?Z.inverseMat4(Z.transposeMat4(h,zo),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,Ho(s=Fo(p,"floor","ceil"))))>u&&(o=s,u=l),(l=a(p,Ho(s=Fo(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):xo(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=pn.getUVBounds(n.uv),p=pn.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?eo.NOT_RENDERED:n?eo.COLOR_TRANSPARENT:eo.COLOR_OPAQUE,a=!p||y?eo.NOT_RENDERED:v?eo.SILHOUETTE_SELECTED:d?eo.SILHOUETTE_HIGHLIGHTED:A?eo.SILHOUETTE_XRAYED:eo.NOT_RENDERED;var m=0;m=!p||y?eo.NOT_RENDERED:v?eo.EDGES_SELECTED:d?eo.EDGES_HIGHLIGHTED:A?eo.EDGES_XRAYED:h?n?eo.EDGES_COLOR_TRANSPARENT:eo.EDGES_COLOR_OPAQUE:eo.NOT_RENDERED;var w=p&&!y&&I?eo.PICK:eo.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}(),al=function(e){I(n,lo);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}(),sl=function(e){I(n,lo);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}(),ll=function(e){I(n,uo);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}(),ul=function(e){I(n,uo);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}(),cl=function(e){I(n,lo);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}(),fl=function(e){I(n,lo);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}(),pl=function(e){I(n,lo);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}(),Al=function(e){I(n,lo);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("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 = 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}(),dl=function(e){I(n,lo);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}(),vl=function(e){I(n,lo);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}(),hl=function(e){I(n,lo);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}(),Il={3e3:"linearToLinear",3001:"sRGBToLinear"},yl=function(e){I(n,lo);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 = "+Il[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 = "+Il[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}(),wl=function(e){I(n,lo);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 I=i._sectionPlanesState.sectionPlanes,y=t.layerIndex*h,m=r.renderFlags,w=0;w0,n=[];return n.push("#version 300 es"),n.push("// SnapInstancingDepthBufInitRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),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}(),Dl=Z.vec3(),Pl=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;e.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[2]=o[2];var l=t.aabb,u=[Z.safeInv(l[3]-l[0])*Z.MAX_INT,Z.safeInv(l[4]-l[1])*Z.MAX_INT,Z.safeInv(l[5]-l[2])*Z.MAX_INT];if(e.snapPickCoordinateScale[0]=Z.safeInv(u[0]),e.snapPickCoordinateScale[1]=Z.safeInv(u[1]),e.snapPickCoordinateScale[2]=Z.safeInv(u[2]),this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var c=i.camera,f=c.eye;e.pickViewMatrix&&(f=e.pickOrigin||f);var p=[f[0]-o[0],f[1]-o[1],f[2]-o[2]];a.uniform3fv(this._uCameraEyeRtc,p),a.uniform2fv(this.uVectorA,e.snapVectorA),a.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),a.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),a.uniform3fv(this._uCoordinateScaler,u),a.uniform1i(this._uRenderPass,n),a.uniform1i(this._uPickInvisible,e.pickInvisible);var A=e.pickViewMatrix||c.viewMatrix,d=o?Ie(A,o):A;if(a.uniformMatrix4fv(this._uViewMatrix,!1,d),a.uniformMatrix4fv(this._uWorldMatrix,!1,r.worldMatrix),a.uniformMatrix4fv(this._uProjMatrix,!1,c.projMatrix),i.logarithmicDepthBufferEnabled){var v=2/(Math.log(e.pickZFar+1)/Math.LN2);a.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("// SnapInstancingDepthRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),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("gl_PointSize = 1.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("// SnapInstancingDepthRenderer 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}(),Rl=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 bl(this._scene,!1)),this._snapDepthBufInitRenderer}},{key:"snapDepthRenderer",get:function(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Pl(this._scene)),this._snapDepthRenderer}},{key:"_destroy",value:function(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}]),e}(),Cl={};var _l=new Uint8Array(4),Bl=new Float32Array(1),Ol=Z.vec4([0,0,0,1]),Sl=Z.vec4([0,0,0,1]),Nl=Z.vec4([0,0,0,1]),Ll=new Float32Array(3),xl=Z.vec3(),Ml=Z.vec3(),Fl=Z.vec3(),Hl=Z.vec3(),Ul=Z.vec3(),Gl=Z.vec3(),kl=Z.vec3(),Vl=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=Tl[r])||(i=new gl(n),Tl[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Tl[r],i._destroy()}))),i),this._snapInstancingRenderers=function(e){var t=e.id,n=Cl[t];return n||(n=new Rl(e),Cl[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete Cl[t],n._destroy()}))),n}(t.model.scene),this._aabb=Z.collapseAABB3(),this._state=new St({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";_l[0]=t[0],_l[1]=t[1],_l[2]=t[2],_l[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(_l,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?eo.NOT_RENDERED:n?eo.COLOR_TRANSPARENT:eo.COLOR_OPAQUE,c|=(!r||u?eo.NOT_RENDERED:s?eo.SILHOUETTE_SELECTED:a?eo.SILHOUETTE_HIGHLIGHTED:i?eo.SILHOUETTE_XRAYED:eo.NOT_RENDERED)<<4,c|=(!r||u?eo.NOT_RENDERED:s?eo.EDGES_SELECTED:a?eo.EDGES_HIGHLIGHTED:i?eo.EDGES_XRAYED:o?n?eo.EDGES_COLOR_TRANSPARENT:eo.EDGES_COLOR_OPAQUE:eo.NOT_RENDERED)<<8,c|=(r&&!u&&l?eo.PICK:eo.NOT_RENDERED)<<12,c|=(t&De?1:0)<<16,Bl[0]=c,this._state.flagsBuf&&this._state.flagsBuf.setData(Bl,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Ll[0]=t[0],Ll[1]=t[1],Ll[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Ll,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=Ol,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}(),jl=function(e){I(n,po);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}(),Ql=function(e){I(n,po);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}(),Wl=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 jl(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Ql(this._scene)),this._silhouetteRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}]),e}(),zl={};var Kl=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=[]})),Yl=Z.vec4([0,0,0,1]),Xl=Z.vec4([0,0,0,1]),ql=Z.vec4([0,0,0,1]),Jl=Z.OBB3(),Zl=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=zl[r])||(i=new Wl(n),zl[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete zl[r],i._destroy()}))),i),this.model=t.model,this._buffer=new Kl(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new St({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=xo(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?eo.NOT_RENDERED:n?eo.COLOR_TRANSPARENT:eo.COLOR_OPAQUE,a=!f||h?eo.NOT_RENDERED:d?eo.SILHOUETTE_SELECTED:A?eo.SILHOUETTE_HIGHLIGHTED:p?eo.SILHOUETTE_XRAYED:eo.NOT_RENDERED;var I=f&&!h&&v?eo.PICK:eo.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}(),eu=function(e){I(n,Ao);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}(),tu=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 $l(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new eu(this._scene)),this._silhouetteRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}]),e}(),nu={};var ru=new Uint8Array(4),iu=new Float32Array(1),au=Z.vec4([0,0,0,1]),su=Z.vec4([0,0,0,1]),ou=Z.vec4([0,0,0,1]),lu=new Float32Array(3),uu=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=nu[r])||(i=new tu(n),nu[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete nu[r],i._destroy()}))),i),this._aabb=Z.collapseAABB3(),this._state=new St({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";ru[0]=t[0],ru[1]=t[1],ru[2]=t[2],ru[3]=t[3],this._state.colorsBuf.setData(ru,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?eo.NOT_RENDERED:n?eo.COLOR_TRANSPARENT:eo.COLOR_OPAQUE,c|=(!r||u?eo.NOT_RENDERED:s?eo.SILHOUETTE_SELECTED:a?eo.SILHOUETTE_HIGHLIGHTED:i?eo.SILHOUETTE_XRAYED:eo.NOT_RENDERED)<<4,c|=(!r||u?eo.NOT_RENDERED:s?eo.EDGES_SELECTED:a?eo.EDGES_HIGHLIGHTED:i?eo.EDGES_XRAYED:o?n?eo.EDGES_COLOR_TRANSPARENT:eo.EDGES_COLOR_OPAQUE:eo.NOT_RENDERED)<<8,c|=(r&&!u&&l?eo.PICK:eo.NOT_RENDERED)<<12,c|=(t&De?255:0)<<16,iu[0]=c,this._state.flagsBuf.setData(iu,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(lu[0]=t[0],lu[1]=t[1],lu[2]=t[2],this._state.offsetsBuf.setData(lu,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,eo.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,eo.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,eo.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,eo.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,eo.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}(),cu=function(e){I(n,co);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}(),fu=function(e){I(n,co);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}(),pu=function(e){I(n,co);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}(),Au=function(e){I(n,co);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}(),du=function(e){I(n,co);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}(),vu=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 cu(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new fu(this._scene)),this._silhouetteRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new pu(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Au(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new du(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}(),hu={};var Iu=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=[]})),yu=Z.vec4(),mu=Z.vec4(),wu=Z.vec4([0,0,0,1]),gu=Z.vec4([0,0,0,1]),Tu=Z.vec4([0,0,0,1]),Eu=Z.OBB3(),bu=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=hu[t];return n||(n=new vu(e),hu[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete hu[t],n._destroy()}))),n}(t.model.scene),this._buffer=new Iu(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new St({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=xo(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}(),Pu=function(e){I(n,fo);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}(),Ru=function(e){I(n,fo);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}(),Cu=function(e){I(n,fo);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}(),_u=function(e){I(n,fo);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}(),Bu=function(e){I(n,fo);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}(),Ou=function(e){I(n,fo);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}(),Su=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 Du(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Pu(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new Bu(this._scene)),this._depthRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Ru(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Cu(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new _u(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new Ou(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}(),Nu={};var Lu=new Uint8Array(4),xu=new Float32Array(1),Mu=Z.vec4([0,0,0,1]),Fu=Z.vec4([0,0,0,1]),Hu=Z.vec4([0,0,0,1]),Uu=new Float32Array(3),Gu=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=Nu[r])||(i=new Su(n),Nu[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Nu[r],i._destroy()}))),i),this._aabb=Z.collapseAABB3(),this._state=new St({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";Lu[0]=t[0],Lu[1]=t[1],Lu[2]=t[2],this._state.colorsBuf.setData(Lu,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?eo.NOT_RENDERED:n?eo.COLOR_TRANSPARENT:eo.COLOR_OPAQUE,c|=(!r||u?eo.NOT_RENDERED:s?eo.SILHOUETTE_SELECTED:a?eo.SILHOUETTE_HIGHLIGHTED:i?eo.SILHOUETTE_XRAYED:eo.NOT_RENDERED)<<4,c|=(!r||u?eo.NOT_RENDERED:s?eo.EDGES_SELECTED:a?eo.EDGES_HIGHLIGHTED:i?eo.EDGES_XRAYED:o?n?eo.EDGES_COLOR_TRANSPARENT:eo.EDGES_COLOR_OPAQUE:eo.NOT_RENDERED)<<8,c|=(r&&!u&&l?eo.PICK:eo.NOT_RENDERED)<<12,c|=(t&De?255:0)<<16,xu[0]=c,this._state.flagsBuf.setData(xu,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Uu[0]=t[0],Uu[1]=t[1],Uu[2]=t[2],this._state.offsetsBuf.setData(Uu,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,eo.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,eo.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,eo.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,eo.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,eo.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,eo.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,eo.PICK)}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,eo.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}(),ku=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}(),Vu=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}(),ju={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={}}},Qu=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."),qu++}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(),qu--}}]),e}();Ju.BasisFormat={ETC1S:0,UASTC_4x4:1},Ju.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},Ju.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},Ju.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