@xeokit/xeokit-sdk 2.4.0-alpha-71 → 2.4.0-alpha-72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ var e,t=l().mark(eT),n=l().mark(tT),r=l().mark(pD);function i(e){return function
7
7
  * @author https://github.com/tmarti, with support from https://tribia.com/
8
8
  * @license MIT
9
9
  */
10
- 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;n<r;n++)if(t[e.meshIds[n]].geometryId)return!0;return!1}(a))return i.push(n),"continue";var s=Z.collapseAABB3(),o=0;a.meshIds.forEach((function(e){var n,r,i=t[e];if(i.positionsCompressed){var a=pn.getPositionsBounds(i.positionsCompressed);n=pn.decompressPosition(a.min,i.positionsDecodeMatrix,[]),r=pn.decompressPosition(a.max,i.positionsDecodeMatrix,[])}else{var l=pn.getPositionsBounds(i.positions);n=l.min,r=l.max}n[0]+=i.origin[0],n[1]+=i.origin[1],n[2]+=i.origin[2],r[0]+=i.origin[0],r[1]+=i.origin[1],r[2]+=i.origin[2],Z.expandAABB3Point3(s,n),Z.expandAABB3Point3(s,r),o+=i.numPrimitives})),r[n]={aabb:s,numPrimitives:o,entityId:a.id}},s=0;s<n;s++)a(s);var o,l=[],u={};if(Object.keys(r).length>0){o=function(e){for(var t=[],n=0,r=e.length;n<r;n++){var i=e[n];i&&t.push({minX:i.aabb[0],minY:i.aabb[1],minZ:i.aabb[2],maxX:i.aabb[3],maxY:i.aabb[4],maxZ:i.aabb[5],entity:{id:n,xeokitId:i.entityId,meshes:[{numPrimitives:i.numPrimitives}]},numPrimitives:i.numPrimitives})}var a=new Qn(4);return a.load(t),a}(r);var c=Wn({aabbTree:o});l=c.orderedEntityIds,u=c.clusteringResult.entityIdToClusterIdMapping}return{orderedClusteredIndexes:l,entityIdToClusterIdMapping:u,instancedIndexes:i,rTreeBasedAabbTree:o}}for(var Kn=Z.vec3(),Yn=180/Math.PI,Xn=new Float32Array(262144),qn=-256;qn<256;qn++)for(var Jn=-256;Jn<256;Jn++){var Zn=(qn+256<<9)+(Jn+256),$n=Math.max(Math.abs(qn),Math.abs(Jn));Xn[Zn]=Math.atan2(qn/$n,Jn/$n)}function er(e,t){var n=256/Math.max(Math.abs(e),Math.abs(t)),r=Math.round(e*n)+255,i=Math.round(t*n)+255;return Xn[(r<<9)+i]}var tr=function(){function e(){b(this,e),this._aabbTree=null,this._orderedMeshList=[],this._orderedEntityList=[],this._frustumProps={dirty:!0,wMultiply:1,hMultiply:1},this._cullFrame=0,this.finalized=!1}return P(e,[{key:"initializeVFCState",value:function(e,t){if(this.finalized)throw"Already finalized";var n=zn(e,t);this._aabbTree=n.rTreeBasedAabbTree;for(var r=0,i=n.orderedClusteredIndexes.length;r<i;r++){for(var a=n.orderedClusteredIndexes[r],s=n.entityIdToClusterIdMapping[a],o=e[a],l=[],u=0,c=o.meshIds.length;u<c;u++){var f=o.meshIds[u];t[f].id=this._orderedMeshList.length,l.push(this._orderedMeshList.length),this._orderedMeshList.push({clusterNumber:s,mesh:t[f]})}o.meshIds=l,this._orderedEntityList.push(o)}for(var p=0,A=n.instancedIndexes.length;p<A;p++){for(var d=e[n.instancedIndexes[p]],v=[],h=0,I=d.meshIds.length;h<I;h++){var y=d.meshIds[h];t[y].id=this._orderedMeshList.length,v.push(this._orderedMeshList.length),this._orderedMeshList.push({clusterNumber:99999,mesh:t[y]})}d.meshIds=v,this._orderedEntityList.push(d)}}},{key:"finalize",value:function(e,t){if(this.finalized)throw"Already finalized";for(var n=-1,r=0,i=this._orderedMeshList.length;r<i;r++){var a=this._orderedMeshList[r],s=a.clusterNumber,o=a.mesh;-1!==n&&n!==s&&t.call(e),e._createMesh(o),n=s}for(var l=0,u=this._orderedEntityList.length;l<u;l++)e._createEntity(this._orderedEntityList[l]);this._orderedMeshList=[],this._orderedEntityList=[],this.finalized=!0}},{key:"applyViewFrustumCulling",value:function(e){if(!this.finalized)throw"Not finalized";if(this._aabbTree){this._canvasElement||(this._canvasElement=e.scene.canvas.canvas),this._camera||(this._camera=e.scene.camera),this._ensureFrustumPropsUpdated(e),this._initializeCullingDataIfNeeded(e);var t=this._searchVisibleNodesWithFrustumCulling();this._cullFrame++,this._markVisibleFrameOfVisibleNodes(t,this._cullFrame),this._cullNonVisibleNodes(e,this._cullFrame)}}},{key:"_initializeCullingDataIfNeeded",value:function(e){if(!this._internalNodesList&&this._aabbTree){var t=this._aabbTree.all(),n=0;t.forEach((function(e){n=Math.max(n,e.entity.id)}));var r=new Array(n+1);t.forEach((function(t){r[t.entity.id]=e.objects[t.entity.xeokitId]})),this._internalNodesList=r,this._lastVisibleFrameOfNodes=new Array(r.length),this._lastVisibleFrameOfNodes.fill(0)}}},{key:"_searchVisibleNodesWithFrustumCulling",value:function(){var e=this;return this._aabbTree.searchCustom((function(t,n){return e._aabbIntersectsCameraFrustum(t,n)}),(function(t){return e._aabbContainedInCameraFrustum(t)}))}},{key:"_markVisibleFrameOfVisibleNodes",value:function(e,t){for(var n=this._lastVisibleFrameOfNodes,r=0,i=e.length;r<i;r++)n[e[r].entity.id]=t}},{key:"_cullNonVisibleNodes",value:function(e,t){for(var n=this._internalNodesList,r=this._lastVisibleFrameOfNodes,i=0,a=n.length;i<a;i++)n[i]&&(n[i].culledVFC=r[i]!==t)}},{key:"_getPointsForBBox",value:function(e){for(var t=[],n=0;n<8;n++)t.push(new Float32Array([1&n?e.maxX:e.minX,2&n?e.maxY:e.minY,4&n?e.maxZ:e.minZ]));return t}},{key:"_aabbIntersectsCameraFrustum",value:function(e,t){if(t)return!0;if("ortho"===this._camera.projection)return this._frustumProps.dirty=!1,!0;var n=this._aabbIntersectsCameraFrustum_internal(e);return!!((4096&n||!(1&n||2&n)||1&n)&&(8192&n||!(16&n||32&n)||16&n)&&(16384&n||!(256&n||512&n)||256&n))}},{key:"_aabbContainedInCameraFrustum",value:function(e){if("ortho"===this._camera.projection)return this._frustumProps.dirty=!1,!0;var t=e._check;return 1&t&&16&t&&256&t}},{key:"_ensureFrustumPropsUpdated",value:function(e){var t=Math.min(this._canvasElement.width,this._canvasElement.height);this._frustumProps.wMultiply=this._canvasElement.width/t,this._frustumProps.hMultiply=this._canvasElement.height/t;var n=this._canvasElement.width/this._canvasElement.height,r=this._camera.perspective.fov;n<1&&(r/=n),r=Math.min(r,120),this._frustumProps.fov=r;var i=Z.inverseMat4(e.worldMatrix,Z.mat4()),a=Z.transformVec3(i,this._camera.eye,[0,0,0]),s=Z.transformVec3(i,this._camera.look,[0,0,0]);this._frustumProps.forward=Z.normalizeVec3(Z.subVec3(s,a,[0,0,0]),[0,0,0]),this._frustumProps.up=Z.normalizeVec3(this._camera.up,[0,0,0]),this._frustumProps.right=Z.normalizeVec3(Z.cross3Vec3(this._frustumProps.forward,this._frustumProps.up,[0,0,0]),[0,0,0]),this._frustumProps.eye=a.slice(),this._frustumProps.CAM_FACTOR_1=this._frustumProps.fov/2*this._frustumProps.wMultiply/Yn,this._frustumProps.CAM_FACTOR_2=this._frustumProps.fov/2*this._frustumProps.hMultiply/Yn}},{key:"_aabbIntersectsCameraFrustum_internal",value:function(e){var t=e._points||this._getPointsForBBox(e);e._points=t;for(var n=819,r=0,i=t.length;r<i;r++){var a=t[r],s=Kn;s[0]=a[0]-this._frustumProps.eye[0],s[1]=a[1]-this._frustumProps.eye[1],s[2]=a[2]-this._frustumProps.eye[2];var o=Z.dotVec3(s,this._frustumProps.forward);o<0?(n|=4,n&=-2):(n|=8,n&=-3);var l=er(Z.dotVec3(s,this._frustumProps.right),o);Math.abs(l)>this._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;t<n;t++)e._vfcManagerList[t].applyViewFrustumCulling()}))}},{key:"enabled",get:function(){return this._enabled},set:function(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}},{key:"getVFCManager",value:function(e){var t=new nr(this.scene,e);return this._vfcManagers[t.id]=t,this._vfcManagerList=Object.values(this._vfcManagers),t}},{key:"putVFCManager",value:function(e){delete this._vfcManagers[e.id],this._vfcManagerList=Object.values(this._vfcManagers)}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this)}}]),n}();function ir(e,t){for(var n,r,i={},a=0,s=t.length;a<s;a++)n=t[a],(r=e.component[n])?r.isEntity?i[n]=!0:e.warn("pick(): Component is not an Entity: "+n):e.warn("pick(): Component not found: "+n);return i}var ar=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),r=t.call(this,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;r<i;r++)n.push("cp");return n.push(";"),e=n.join("")},this.addSectionPlane=function(t){this.sectionPlanes.push(t),e=null},this.removeSectionPlane=function(t){for(var n=0,r=this.sectionPlanes.length;n<r;n++)if(this.sectionPlanes[n].id===t.id)return this.sectionPlanes.splice(n,1),void(e=null)}},r._lightsState=new function(){var e=Z.vec4([0,0,0,0]),t=Z.vec4();this.lights=[],this.reflectionMaps=[],this.lightMaps=[];var n=null,r=null;this.getHash=function(){if(n)return n;for(var e,t=[],r=this.lights,i=0,a=r.length;i<a;i++)e=r[i],t.push("/"),t.push(e.type),t.push("world"===e.space?"w":"v"),e.castsShadow&&t.push("sh");return this.lightMaps.length>0&&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;t<i;t++){if(this.lights[t].id===e.id)return this.lights.splice(t,1),r&&r.id===e.id&&(r=null),void(n=null)}},this.addReflectionMap=function(e){this.reflectionMaps.push(e),n=null},this.removeReflectionMap=function(e){for(var t=0,r=this.reflectionMaps.length;t<r;t++)if(this.reflectionMaps[t].id===e.id)return this.reflectionMaps.splice(t,1),void(n=null)},this.addLightMap=function(e){this.lightMaps.push(e),n=null},this.removeLightMap=function(e){for(var t=0,r=this.lightMaps.length;t<r;t++)if(this.lightMaps[t].id===e.id)return this.lightMaps.splice(t,1),void(n=null)},this.getAmbientColorAndIntensity=function(){if(!r)for(var n=0,i=this.lights.length;n<i;n++){var a=this.lights[n];if("ambient"===a.type){r=a;break}}if(r){var s=r.color,o=r.intensity;return t[0]=s[0],t[1]=s[1],t[2]=s[2],t[3]=o,t}return e}},r.input=new Bt(g(r),{dontClear:!0,element:r.canvas.canvas,keyboardEventsElement:i.keyboardEventsElement}),r.metrics=new Pn(g(r),{units:i.units,scale:i.scale,origin:i.origin}),r.sao=new Rn(g(r),{enabled:i.saoEnabled}),r.ticksPerRender=i.ticksPerRender,r.ticksPerOcclusionTest=i.ticksPerOcclusionTest,r.passes=i.passes,r.clearEachPass=i.clearEachPass,r.gammaInput=i.gammaInput,r.gammaOutput=i.gammaOutput,r.gammaFactor=i.gammaFactor,r._entityOffsetsEnabled=!!i.entityOffsetsEnabled,r._logarithmicDepthBufferEnabled=!!i.logarithmicDepthBufferEnabled,r._dtxEnabled=!1!==i.dtxEnabled,r._pbrEnabled=!!i.pbrEnabled,r._colorTextureEnabled=!1!==i.colorTextureEnabled,r._dtxEnabled=!!i.dtxEnabled,Ae._addScene(g(r)),r._initDefaults(),r._viewport=new Nt(g(r),{id:"default.viewport",autoBoundary:!0,dontClear:!0}),r._camera=new $t(g(r),{id:"default.camera",dontClear:!0}),new nn(g(r),{color:[1,1,1],intensity:.7}),new tn(g(r),{dir:[.8,-.5,-.5],color:[.67,.67,1],intensity:.7,space:"world"}),new tn(g(r),{dir:[-.8,-1,.5],color:[1,1,.9],intensity:.9,space:"world"}),r._camera.on("dirty",(function(){r._renderer.imageDirty()})),r.lod=new kn(g(r),{enabled:i.lodEnabled}),r.vfc=new rr(g(r),{enabled:i.vfcEnabled}),r}return P(n,[{key:"type",get:function(){return"Scene"}},{key:"_initDefaults",value:function(){}},{key:"_addComponent",value:function(e){if(e.id&&this.components[e.id]&&(this.error("Component "+ae.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=Z.createUUID();this.components[e.id]=e;var t=e.type,n=this.types[e.type];n||(n=this.types[t]={}),n[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}},{key:"_removeComponent",value:function(e){var t=e.id,n=e.type;delete this.components[t];var r=this.types[n];r&&(delete r[t],ae.isEmptyObject(r)&&delete this.types[n]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}},{key:"_sectionPlaneCreated",value:function(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}},{key:"_bitmapCreated",value:function(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}},{key:"_lineSetCreated",value:function(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}},{key:"_lightCreated",value:function(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}},{key:"_lightMapCreated",value:function(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}},{key:"_reflectionMapCreated",value:function(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}},{key:"_sectionPlaneDestroyed",value:function(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}},{key:"_bitmapDestroyed",value:function(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}},{key:"_lineSetDestroyed",value:function(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}},{key:"_lightDestroyed",value:function(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}},{key:"_lightMapDestroyed",value:function(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}},{key:"_reflectionMapDestroyed",value:function(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}},{key:"_registerModel",value:function(e){this.models[e.id]=e,this._modelIds=null}},{key:"_deregisterModel",value:function(e){var t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}},{key:"_registerObject",value:function(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}},{key:"_deregisterObject",value:function(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}},{key:"_objectVisibilityUpdated",value:function(e){var t=!(arguments.length>1&&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;n<i;n++)t.pass=n,this.fire("rendering",t,!0),r=a||0===n,this._renderer.render({pass:n,clear:r,force:e}),this.fire("rendered",t,!0);this._saveAmbientColor()}}},{key:"_recompile",value:function(){for(var e in this._compilables)this._compilables.hasOwnProperty(e)&&this._compilables[e].compile();this._renderer.shadowsDirty(),this.fire("compile",this,!0)}},{key:"_saveAmbientColor",value:function(){var e=this.canvas;if(e.transparent||e.backgroundImage||e.backgroundColor)this._lastAmbientColor=null;else{var t=this._lightsState.getAmbientColorAndIntensity();this._lastAmbientColor&&this._lastAmbientColor[0]===t[0]&&this._lastAmbientColor[1]===t[1]&&this._lastAmbientColor[2]===t[2]&&this._lastAmbientColor[3]===t[3]||(e.backgroundColor=t,this._lastAmbientColor||(this._lastAmbientColor=Z.vec4([0,0,0,1])),this._lastAmbientColor.set(t))}}},{key:"modelIds",get:function(){return this._modelIds||(this._modelIds=Object.keys(this.models)),this._modelIds}},{key:"numObjects",get:function(){return this._numObjects}},{key:"objectIds",get:function(){return this._objectIds||(this._objectIds=Object.keys(this.objects)),this._objectIds}},{key:"numVisibleObjects",get:function(){return this._numVisibleObjects}},{key:"visibleObjectIds",get:function(){return this._visibleObjectIds||(this._visibleObjectIds=Object.keys(this.visibleObjects)),this._visibleObjectIds}},{key:"numXRayedObjects",get:function(){return this._numXRayedObjects}},{key:"xrayedObjectIds",get:function(){return this._xrayedObjectIds||(this._xrayedObjectIds=Object.keys(this.xrayedObjects)),this._xrayedObjectIds}},{key:"numHighlightedObjects",get:function(){return this._numHighlightedObjects}},{key:"highlightedObjectIds",get:function(){return this._highlightedObjectIds||(this._highlightedObjectIds=Object.keys(this.highlightedObjects)),this._highlightedObjectIds}},{key:"numSelectedObjects",get:function(){return this._numSelectedObjects}},{key:"selectedObjectIds",get:function(){return this._selectedObjectIds||(this._selectedObjectIds=Object.keys(this.selectedObjects)),this._selectedObjectIds}},{key:"numColorizedObjects",get:function(){return this._numColorizedObjects}},{key:"colorizedObjectIds",get:function(){return this._colorizedObjectIds||(this._colorizedObjectIds=Object.keys(this.colorizedObjects)),this._colorizedObjectIds}},{key:"opacityObjectIds",get:function(){return this._opacityObjectIds||(this._opacityObjectIds=Object.keys(this.opacityObjects)),this._opacityObjectIds}},{key:"offsetObjectIds",get:function(){return this._offsetObjectIds||(this._offsetObjectIds=Object.keys(this.offsetObjects)),this._offsetObjectIds}},{key:"ticksPerRender",get:function(){return this._ticksPerRender},set:function(e){null==e?e=1:(!ae.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'ticksPerRender': '"+e+"' - should be an integer greater than zero."),e=1),e!==this._ticksPerRender&&(this._ticksPerRender=e)}},{key:"ticksPerOcclusionTest",get:function(){return this._ticksPerOcclusionTest},set:function(e){null==e?e=20:(!ae.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'ticksPerOcclusionTest': '"+e+"' - should be an integer greater than zero."),e=20),e!==this._ticksPerOcclusionTest&&(this._ticksPerOcclusionTest=e)}},{key:"passes",get:function(){return this._passes},set:function(e){null==e?e=1:(!ae.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'passes': '"+e+"' - should be an integer greater than zero."),e=1),e!==this._passes&&(this._passes=e,this.glRedraw())}},{key:"clearEachPass",get:function(){return this._clearEachPass},set:function(e){(e=!!e)!==this._clearEachPass&&(this._clearEachPass=e,this.glRedraw())}},{key:"gammaInput",get:function(){return this._renderer.gammaInput},set:function(e){(e=!1!==e)!==this._renderer.gammaInput&&(this._renderer.gammaInput=e,this._needRecompile=!0,this.glRedraw())}},{key:"gammaOutput",get:function(){return this._renderer.gammaOutput},set:function(e){(e=!!e)!==this._renderer.gammaOutput&&(this._renderer.gammaOutput=e,this._needRecompile=!0,this.glRedraw())}},{key:"gammaFactor",get:function(){return this._renderer.gammaFactor},set:function(e){(e=null==e?2.2:e)!==this._renderer.gammaFactor&&(this._renderer.gammaFactor=e,this.glRedraw())}},{key:"geometry",get:function(){return this.components["default.geometry"]||hn(vn)}},{key:"material",get:function(){return this.components["default.material"]||new wn(this,{id:"default.material",emissive:[.4,.4,.4],dontClear:!0})}},{key:"xrayMaterial",get:function(){return this.components["default.xrayMaterial"]||new Tn(this,{id:"default.xrayMaterial",preset:"sepia",dontClear:!0})}},{key:"highlightMaterial",get:function(){return this.components["default.highlightMaterial"]||new Tn(this,{id:"default.highlightMaterial",preset:"yellowHighlight",dontClear:!0})}},{key:"selectedMaterial",get:function(){return this.components["default.selectedMaterial"]||new Tn(this,{id:"default.selectedMaterial",preset:"greenSelected",dontClear:!0})}},{key:"edgeMaterial",get:function(){return this.components["default.edgeMaterial"]||new bn(this,{id:"default.edgeMaterial",preset:"default",edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1,dontClear:!0})}},{key:"pointsMaterial",get:function(){return this.components["default.pointsMaterial"]||new _n(this,{id:"default.pointsMaterial",preset:"default",dontClear:!0})}},{key:"linesMaterial",get:function(){return this.components["default.linesMaterial"]||new On(this,{id:"default.linesMaterial",preset:"default",dontClear:!0})}},{key:"viewport",get:function(){return this._viewport}},{key:"camera",get:function(){return this._camera}},{key:"center",get:function(){if(this._aabbDirty||!this._center){this._center&&this._center||(this._center=Z.vec3());var e=this.aabb;this._center[0]=(e[0]+e[3])/2,this._center[1]=(e[1]+e[4])/2,this._center[2]=(e[2]+e[5])/2}return this._center}},{key:"aabb",get:function(){if(this._aabbDirty){this._aabb||(this._aabb=Z.AABB3());var e,t,n=Z.MAX_DOUBLE,r=Z.MAX_DOUBLE,i=Z.MAX_DOUBLE,a=Z.MIN_DOUBLE,s=Z.MIN_DOUBLE,o=Z.MIN_DOUBLE,l=this._collidables,u=!1;for(var c in l)if(l.hasOwnProperty(c)){if(!1===(t=l[c]).collidable)continue;(e=t.aabb)[0]<n&&(n=e[0]),e[1]<r&&(r=e[1]),e[2]<i&&(i=e[2]),e[3]>a&&(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;t<n;t++)this.lights[e[t]].destroy()}},{key:"clearSectionPlanes",value:function(){for(var e=Object.keys(this.sectionPlanes),t=0,n=e.length;t<n;t++)this.sectionPlanes[e[t]].destroy()}},{key:"clearBitmaps",value:function(){for(var e=Object.keys(this.bitmaps),t=0,n=e.length;t<n;t++)this.bitmaps[e[t]].destroy()}},{key:"clearLines",value:function(){for(var e=Object.keys(this.lineSets),t=0,n=e.length;t<n;t++)this.lineSets[e[t]].destroy()}},{key:"getAABB",value:function(e){if(void 0===e)return this.aabb;if(ae.isString(e)){var t=this.objects[e];if(t&&t.aabb)return t.aabb;e=[e]}if(0===e.length)return this.aabb;var n,r=Z.MAX_DOUBLE,i=Z.MAX_DOUBLE,a=Z.MAX_DOUBLE,s=Z.MIN_DOUBLE,o=Z.MIN_DOUBLE,l=Z.MIN_DOUBLE;if(this.withObjects(e,(function(e){if(e.collidable){var t=e.aabb;t[0]<r&&(r=t[0]),t[1]<i&&(i=t[1]),t[2]<a&&(a=t[2]),t[3]>s&&(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;r<i;r++){var a=e[r],s=this.objects[a];if(s)n=t(s)||n;else for(var o=this.modelIds,l=0,u=o.length;l<u;l++){var c=o[l],f=Z.globalizeObjectId(c,a);(s=this.objects[f])&&(n=t(s)||n)}}return n}},{key:"destroy",value:function(){for(var e in v(T(n.prototype),"destroy",this).call(this),this.components)this.components.hasOwnProperty(e)&&this.components[e].destroy();this.canvas.gl=null,this.components=null,this.models=null,this.objects=null,this.visibleObjects=null,this.xrayedObjects=null,this.highlightedObjects=null,this.selectedObjects=null,this.colorizedObjects=null,this.opacityObjects=null,this.sectionPlanes=null,this.lights=null,this.lightMaps=null,this.reflectionMaps=null,this._objectIds=null,this._visibleObjectIds=null,this._xrayedObjectIds=null,this._highlightedObjectIds=null,this._selectedObjectIds=null,this._colorizedObjectIds=null,this.types=null,this.components=null,this.canvas=null,this._renderer=null,this.input=null,this._viewport=null,this._camera=null}}]),n}(),sr=1e3,or=1001,lr=1002,ur=1003,cr=1004,fr=1004,pr=1005,Ar=1005,dr=1006,vr=1007,hr=1007,Ir=1008,yr=1008,mr=1009,wr=1010,gr=1011,Tr=1012,Er=1013,br=1014,Dr=1015,Pr=1016,Rr=1017,Cr=1018,_r=1020,Br=1021,Or=1022,Sr=1023,Nr=1024,Lr=1025,xr=1026,Mr=1027,Fr=1028,Hr=1029,Ur=1030,Gr=1031,kr=1033,Vr=33776,jr=33777,Qr=33778,Wr=33779,zr=35840,Kr=35841,Yr=35842,Xr=35843,qr=36196,Jr=37492,Zr=37496,$r=37808,ei=37809,ti=37810,ni=37811,ri=37812,ii=37813,ai=37814,si=37815,oi=37816,li=37817,ui=37818,ci=37819,fi=37820,pi=37821,Ai=36492,di=3e3,vi=3001,hi=1e4,Ii=10001,yi=10002,mi=10003,wi=function(e){"LambertMaterial"===e._material._state.type?(this.vertex=function(e){var t=e.scene,n=e.scene._sectionPlanesState,r=e.scene._lightsState,i=e._geometry._state,a=e._state.billboard,s=e._state.stationary,o=n.sectionPlanes.length>0,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<f;c++){var p=r.lights[c];"ambient"!==p.type&&(u.push("uniform vec4 lightColor"+c+";"),"dir"===p.type&&u.push("uniform vec3 lightDir"+c+";"),"point"===p.type&&u.push("uniform vec3 lightPos"+c+";"),"spot"===p.type&&(u.push("uniform vec3 lightPos"+c+";"),u.push("uniform vec3 lightDir"+c+";")))}l&&(u.push("vec3 octDecode(vec2 oct) {"),u.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),u.push(" if (v.z < 0.0) {"),u.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);"),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;A<d;A++){var v=r.lights[A];if("ambient"!==v.type){if("dir"===v.type)"view"===v.space?u.push("viewLightDir = normalize(lightDir"+A+");"):u.push("viewLightDir = normalize((viewMatrix2 * vec4(lightDir"+A+", 0.0)).xyz);");else if("point"===v.type)"view"===v.space?u.push("viewLightDir = -normalize(lightPos"+A+" - viewPosition.xyz);"):u.push("viewLightDir = -normalize((viewMatrix2 * vec4(lightPos"+A+", 0.0)).xyz);");else{if("spot"!==v.type)continue;"view"===v.space?u.push("viewLightDir = normalize(lightDir"+A+");"):u.push("viewLightDir = normalize((viewMatrix2 * vec4(lightDir"+A+", 0.0)).xyz);")}u.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),u.push("reflectedColor += lambertian * (lightColor"+A+".rgb * lightColor"+A+".a);")}}u.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * materialColor.rgb) + materialEmissive.rgb + (reflectedColor * materialColor.rgb), materialColor.a) * colorize;"),o&&u.push("vWorldPosition = worldPosition;");"points"===i.primitiveName&&u.push("gl_PointSize = pointSize;");u.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(u.push("vFragDepth = 1.0 + clipPos.w;"),u.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return u.push("gl_Position = clipPos;"),u.push("}"),u}(e),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState;e._material._state;var r=e._geometry._state,i=n.sectionPlanes.length>0,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<l;o++)s.push("uniform bool sectionPlaneActive"+o+";"),s.push("uniform vec3 sectionPlanePos"+o+";"),s.push("uniform vec3 sectionPlaneDir"+o+";")}s.push("in vec4 vColor;"),a&&(s.push("uniform float gammaFactor;"),s.push(" vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),s.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),s.push("}"));if(s.push("out vec4 outColor;"),s.push("void main(void) {"),i){s.push("if (clippable) {"),s.push(" float dist = 0.0;");for(var u=0,c=n.sectionPlanes.length;u<c;u++)s.push("if (sectionPlaneActive"+u+") {"),s.push(" dist += clamp(dot(-sectionPlaneDir"+u+".xyz, vWorldPosition.xyz - sectionPlanePos"+u+".xyz), 0.0, 1000.0);"),s.push("}");s.push(" if (dist > 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<I;h++)"ambient"!==(n=s.lights[h]).type&&("dir"===n.type&&v.push("uniform vec3 lightDir"+h+";"),"point"===n.type&&v.push("uniform vec3 lightPos"+h+";"),"spot"===n.type&&(v.push("uniform vec3 lightPos"+h+";"),v.push("uniform vec3 lightDir"+h+";")),"dir"===n.type&&"view"===n.space||v.push("out vec4 vViewLightReverseDirAndDist"+h+";"));d&&(v.push("vec3 octDecode(vec2 oct) {"),v.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),v.push(" if (v.z < 0.0) {"),v.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);"),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;y<m;y++)s.lights[y].castsShadow&&(v.push("uniform mat4 shadowViewMatrix"+y+";"),v.push("uniform mat4 shadowProjMatrix"+y+";"),v.push("out vec4 vShadowPosFromLight"+y+";"))}v.push("void main(void) {"),v.push("vec4 localPosition = vec4(position, 1.0); "),v.push("vec4 worldPosition;"),d&&v.push("localPosition = positionsDecodeMatrix * localPosition;");f&&(d?v.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):v.push("vec4 localNormal = vec4(normal, 0.0); "),v.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),v.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));v.push("mat4 viewMatrix2 = viewMatrix;"),v.push("mat4 modelMatrix2 = modelMatrix;"),u?v.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;"):l&&v.push("viewMatrix2[3] = vec4(0.0, 0.0, 0.0 ,1.0);");"spherical"===o||"cylindrical"===o?(v.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),v.push("billboard(modelMatrix2);"),v.push("billboard(viewMatrix2);"),v.push("billboard(modelViewMatrix);"),f&&(v.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),v.push("billboard(modelNormalMatrix2);"),v.push("billboard(viewNormalMatrix2);"),v.push("billboard(modelViewNormalMatrix);")),v.push("worldPosition = modelMatrix2 * localPosition;"),v.push("worldPosition.xyz = worldPosition.xyz + offset;"),v.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(v.push("worldPosition = modelMatrix2 * localPosition;"),v.push("worldPosition.xyz = worldPosition.xyz + offset;"),v.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));if(f){v.push("vec3 worldNormal = (modelNormalMatrix2 * localNormal).xyz; "),s.lightMaps.length>0&&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;w<g;w++)"ambient"!==(n=s.lights[w]).type&&("dir"===n.type&&"world"===n.space&&(v.push("tmpVec3 = vec3(viewMatrix2 * vec4(lightDir"+w+", 0.0) ).xyz;"),v.push("vViewLightReverseDirAndDist"+w+" = vec4(-tmpVec3, 0.0);")),"point"===n.type&&("world"===n.space?(v.push("tmpVec3 = (viewMatrix2 * vec4(lightPos"+w+", 1.0)).xyz - viewPosition.xyz;"),v.push("lightDist = abs(length(tmpVec3));")):(v.push("tmpVec3 = lightPos"+w+".xyz - viewPosition.xyz;"),v.push("lightDist = abs(length(tmpVec3));")),v.push("vViewLightReverseDirAndDist"+w+" = vec4(tmpVec3, lightDist);")))}c&&(d?v.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"):v.push("vUV = uv;"));a.colors&&v.push("vColor = color;");"points"===a.primitiveName&&v.push("gl_PointSize = pointSize;");p&&v.push("vWorldPosition = worldPosition;");v.push(" vViewPosition = viewPosition.xyz;"),v.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(v.push("vFragDepth = 1.0 + clipPos.w;"),v.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));l&&v.push("clipPos.z = clipPos.w;");if(v.push("gl_Position = clipPos;"),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);"),v.push("vec4 tempx; ");for(var T=0,E=s.lights.length;T<E;T++)s.lights[T].castsShadow&&v.push("vShadowPosFromLight"+T+" = texUnitConverter * shadowProjMatrix"+T+" * (shadowViewMatrix"+T+" * worldPosition); ")}return v.push("}"),v}(e),this.fragment=function(e){var t=e.scene;t.canvas.gl;var n=e._material,r=e._geometry._state,i=e.scene._sectionPlanesState,a=e.scene._lightsState,s=e._material._state,o=i.sectionPlanes.length>0,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;h<i.sectionPlanes.length;h++)v.push("uniform bool sectionPlaneActive"+h+";"),v.push("uniform vec3 sectionPlanePos"+h+";"),v.push("uniform vec3 sectionPlaneDir"+h+";")}l&&(a.lightMaps.length>0&&(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<y;I++){var m=a.lights[I];"ambient"!==m.type&&(v.push("uniform vec4 lightColor"+I+";"),"point"===m.type&&v.push("uniform vec3 lightAttenuation"+I+";"),"dir"===m.type&&"view"===m.space&&v.push("uniform vec3 lightDir"+I+";"),"point"===m.type&&"view"===m.space?v.push("uniform vec3 lightPos"+I+";"):v.push("in vec4 vViewLightReverseDirAndDist"+I+";"))}if(A)for(var w=0,g=a.lights.length;w<g;w++)a.lights[w].castsShadow&&(v.push("in vec4 vShadowPosFromLight"+w+";"),v.push("uniform sampler2D shadowMap"+w+";"));if(v.push("uniform vec4 colorize;"),v.push("out vec4 outColor;"),v.push("void main(void) {"),o){v.push("if (clippable) {"),v.push(" float dist = 0.0;");for(h=0;h<i.sectionPlanes.length;h++)v.push("if (sectionPlaneActive"+h+") {"),v.push(" dist += clamp(dot(-sectionPlaneDir"+h+".xyz, vWorldPosition.xyz - sectionPlanePos"+h+".xyz), 0.0, 1000.0);"),v.push("}");v.push(" if (dist > 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;T<E;T++){var b=a.lights[T];"ambient"!==b.type&&("dir"===b.type&&"view"===b.space?v.push("viewLightDir = -normalize(lightDir"+T+");"):"point"===b.type&&"view"===b.space?v.push("viewLightDir = normalize(lightPos"+T+" - vViewPosition);"):v.push("viewLightDir = normalize(vViewLightReverseDirAndDist"+T+".xyz);"),A&&b.castsShadow?(v.push("shadow = 0.0;"),v.push("fragmentDepth = vShadowPosFromLight"+T+".xyz;"),v.push("fragmentDepth.z -= shadowAcneRemover;"),v.push("for (int x = -3; x <= 3; x++) {"),v.push(" for (int y = -3; y <= 3; y++) {"),v.push(" float texelDepth = unpackDepth(texture(shadowMap"+T+", fragmentDepth.xy + vec2(x, y) * texelSize));"),v.push(" if (fragmentDepth.z < texelDepth) {"),v.push(" shadow += 1.0;"),v.push(" }"),v.push(" }"),v.push("}"),v.push("shadow = shadow / 9.0;"),v.push("light.color = lightColor"+T+".rgb * (lightColor"+T+".a * shadow);")):v.push("light.color = lightColor"+T+".rgb * (lightColor"+T+".a );"),v.push("light.direction = viewLightDir;"),c&&v.push("computePhongLighting(light, geometry, material, reflectedLight);"),(p||f)&&v.push("computePBRLighting(light, geometry, material, reflectedLight);"))}c?v.push("vec3 outgoingLight = (lightAmbient.rgb * lightAmbient.a * diffuseColor) + ((occlusion * (( reflectedLight.diffuse + reflectedLight.specular)))) + emissiveColor;"):v.push("vec3 outgoingLight = (occlusion * (reflectedLight.diffuse)) + (occlusion * reflectedLight.specular) + emissiveColor;")}else v.push("ambientColor *= (lightAmbient.rgb * lightAmbient.a);"),v.push("vec3 outgoingLight = emissiveColor + ambientColor;");v.push("vec4 fragColor = vec4(outgoingLight, alpha) * colorize;"),d&&v.push("fragColor = linearToGamma(fragColor, gammaFactor);");v.push("outColor = fragColor;"),t.logarithmicDepthBufferEnabled&&v.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return v.push("}"),v}(e))},gi={};function Ti(e){if(!e.receivesShadow)return!1;var t=e.scene._lightsState.lights;if(!t||0===t.length)return!1;for(var n=0,r=t.length;n<r;n++)if(t[n].castsShadow)return!0;return!1}function Ei(e){var t=e._geometry._state.primitiveName;return!(!e._geometry._state.autoVertexNormals&&!e._geometry._state.normalsBuf||"triangles"!==t&&"triangle-strip"!==t&&"triangle-fan"!==t)}gi[3e3]="linearToLinear",gi[3001]="sRGBToLinear";var bi=Z.vec3(),Di=new G({}),Pi=function(e,t){this.id=Di.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new wi(t),this._allocate(t)},Ri={};Pi.get=function(e){var t=e.scene,n=[t.canvas.canvas.id,(t.gammaInput?"gi;":";")+(t.gammaOutput?"go":""),t._lightsState.getHash(),t._sectionPlanesState.getHash(),e._geometry._state.hash,e._material._state.hash,e._state.drawHash].join(";"),r=Ri[n];if(!r){if((r=new Pi(n,e)).errors)return console.log(r.errors.join("\n")),null;Ri[n]=r,ee.memory.programs++}return r._useCount++,r},Pi.prototype.put=function(){0==--this._useCount&&(Di.removeItem(this.id),this._program&&this._program.destroy(),delete Ri[this._hash],ee.memory.programs--)},Pi.prototype.webglContextRestored=function(){this._program=null},Pi.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=Ze.MAX_TEXTURE_UNITS,r=t.scene,i=t._material,a=r.canvas.gl,s=this._program,o=t._state,l=t._material._state,u=t._geometry._state,c=r.camera,f=t.origin,p=o.background;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,p&&a.depthFunc(a.LEQUAL),this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,f?e.getRTCViewMatrix(o.originHash,f):c.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,c.viewNormalMatrix),o.clippable){var A=r._sectionPlanesState.sectionPlanes.length;if(A>0)for(var d=r._sectionPlanesState.sectionPlanes,v=t.renderFlags,h=0;h<A;h++){var I=this._uSectionPlanes[h];if(I){var y=v.sectionPlanesActivePerLayer[h];if(a.uniform1i(I.active,y?1:0),y){var m=d[h];a.uniform3fv(I.pos,f?ge(m.dist,m.dir,f,bi):m.pos),a.uniform3fv(I.dir,m.dir)}}}}if(l.id!==this._lastMaterialId){e.textureUnit=this._baseTextureUnit;var w=l.backfaces;e.backfaces!==w&&(w?a.disable(a.CULL_FACE):a.enable(a.CULL_FACE),e.backfaces=w);var g=l.frontface;switch(e.frontface!==g&&(g?a.frontFace(a.CCW):a.frontFace(a.CW),e.frontface=g),e.lineWidth!==l.lineWidth&&(a.lineWidth(l.lineWidth),e.lineWidth=l.lineWidth),this._uPointSize&&a.uniform1f(this._uPointSize,l.pointSize),l.type){case"LambertMaterial":this._uMaterialAmbient&&a.uniform3fv(this._uMaterialAmbient,l.ambient),this._uMaterialColor&&a.uniform4f(this._uMaterialColor,l.color[0],l.color[1],l.color[2],l.alpha),this._uMaterialEmissive&&a.uniform3fv(this._uMaterialEmissive,l.emissive);break;case"PhongMaterial":this._uMaterialShininess&&a.uniform1f(this._uMaterialShininess,l.shininess),this._uMaterialAmbient&&a.uniform3fv(this._uMaterialAmbient,l.ambient),this._uMaterialDiffuse&&a.uniform3fv(this._uMaterialDiffuse,l.diffuse),this._uMaterialSpecular&&a.uniform3fv(this._uMaterialSpecular,l.specular),this._uMaterialEmissive&&a.uniform3fv(this._uMaterialEmissive,l.emissive),this._uAlphaModeCutoff&&a.uniform4f(this._uAlphaModeCutoff,1*l.alpha,1===l.alphaMode?1:0,l.alphaCutoff,0),i._ambientMap&&i._ambientMap._state.texture&&this._uMaterialAmbientMap&&(s.bindTexture(this._uMaterialAmbientMap,i._ambientMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uMaterialAmbientMapMatrix&&a.uniformMatrix4fv(this._uMaterialAmbientMapMatrix,!1,i._ambientMap._state.matrix)),i._diffuseMap&&i._diffuseMap._state.texture&&this._uDiffuseMap&&(s.bindTexture(this._uDiffuseMap,i._diffuseMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uDiffuseMapMatrix&&a.uniformMatrix4fv(this._uDiffuseMapMatrix,!1,i._diffuseMap._state.matrix)),i._specularMap&&i._specularMap._state.texture&&this._uSpecularMap&&(s.bindTexture(this._uSpecularMap,i._specularMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uSpecularMapMatrix&&a.uniformMatrix4fv(this._uSpecularMapMatrix,!1,i._specularMap._state.matrix)),i._emissiveMap&&i._emissiveMap._state.texture&&this._uEmissiveMap&&(s.bindTexture(this._uEmissiveMap,i._emissiveMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uEmissiveMapMatrix&&a.uniformMatrix4fv(this._uEmissiveMapMatrix,!1,i._emissiveMap._state.matrix)),i._alphaMap&&i._alphaMap._state.texture&&this._uAlphaMap&&(s.bindTexture(this._uAlphaMap,i._alphaMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uAlphaMapMatrix&&a.uniformMatrix4fv(this._uAlphaMapMatrix,!1,i._alphaMap._state.matrix)),i._reflectivityMap&&i._reflectivityMap._state.texture&&this._uReflectivityMap&&(s.bindTexture(this._uReflectivityMap,i._reflectivityMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,this._uReflectivityMapMatrix&&a.uniformMatrix4fv(this._uReflectivityMapMatrix,!1,i._reflectivityMap._state.matrix)),i._normalMap&&i._normalMap._state.texture&&this._uNormalMap&&(s.bindTexture(this._uNormalMap,i._normalMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uNormalMapMatrix&&a.uniformMatrix4fv(this._uNormalMapMatrix,!1,i._normalMap._state.matrix)),i._occlusionMap&&i._occlusionMap._state.texture&&this._uOcclusionMap&&(s.bindTexture(this._uOcclusionMap,i._occlusionMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uOcclusionMapMatrix&&a.uniformMatrix4fv(this._uOcclusionMapMatrix,!1,i._occlusionMap._state.matrix)),i._diffuseFresnel&&(this._uDiffuseFresnelEdgeBias&&a.uniform1f(this._uDiffuseFresnelEdgeBias,i._diffuseFresnel.edgeBias),this._uDiffuseFresnelCenterBias&&a.uniform1f(this._uDiffuseFresnelCenterBias,i._diffuseFresnel.centerBias),this._uDiffuseFresnelEdgeColor&&a.uniform3fv(this._uDiffuseFresnelEdgeColor,i._diffuseFresnel.edgeColor),this._uDiffuseFresnelCenterColor&&a.uniform3fv(this._uDiffuseFresnelCenterColor,i._diffuseFresnel.centerColor),this._uDiffuseFresnelPower&&a.uniform1f(this._uDiffuseFresnelPower,i._diffuseFresnel.power)),i._specularFresnel&&(this._uSpecularFresnelEdgeBias&&a.uniform1f(this._uSpecularFresnelEdgeBias,i._specularFresnel.edgeBias),this._uSpecularFresnelCenterBias&&a.uniform1f(this._uSpecularFresnelCenterBias,i._specularFresnel.centerBias),this._uSpecularFresnelEdgeColor&&a.uniform3fv(this._uSpecularFresnelEdgeColor,i._specularFresnel.edgeColor),this._uSpecularFresnelCenterColor&&a.uniform3fv(this._uSpecularFresnelCenterColor,i._specularFresnel.centerColor),this._uSpecularFresnelPower&&a.uniform1f(this._uSpecularFresnelPower,i._specularFresnel.power)),i._alphaFresnel&&(this._uAlphaFresnelEdgeBias&&a.uniform1f(this._uAlphaFresnelEdgeBias,i._alphaFresnel.edgeBias),this._uAlphaFresnelCenterBias&&a.uniform1f(this._uAlphaFresnelCenterBias,i._alphaFresnel.centerBias),this._uAlphaFresnelEdgeColor&&a.uniform3fv(this._uAlphaFresnelEdgeColor,i._alphaFresnel.edgeColor),this._uAlphaFresnelCenterColor&&a.uniform3fv(this._uAlphaFresnelCenterColor,i._alphaFresnel.centerColor),this._uAlphaFresnelPower&&a.uniform1f(this._uAlphaFresnelPower,i._alphaFresnel.power)),i._reflectivityFresnel&&(this._uReflectivityFresnelEdgeBias&&a.uniform1f(this._uReflectivityFresnelEdgeBias,i._reflectivityFresnel.edgeBias),this._uReflectivityFresnelCenterBias&&a.uniform1f(this._uReflectivityFresnelCenterBias,i._reflectivityFresnel.centerBias),this._uReflectivityFresnelEdgeColor&&a.uniform3fv(this._uReflectivityFresnelEdgeColor,i._reflectivityFresnel.edgeColor),this._uReflectivityFresnelCenterColor&&a.uniform3fv(this._uReflectivityFresnelCenterColor,i._reflectivityFresnel.centerColor),this._uReflectivityFresnelPower&&a.uniform1f(this._uReflectivityFresnelPower,i._reflectivityFresnel.power)),i._emissiveFresnel&&(this._uEmissiveFresnelEdgeBias&&a.uniform1f(this._uEmissiveFresnelEdgeBias,i._emissiveFresnel.edgeBias),this._uEmissiveFresnelCenterBias&&a.uniform1f(this._uEmissiveFresnelCenterBias,i._emissiveFresnel.centerBias),this._uEmissiveFresnelEdgeColor&&a.uniform3fv(this._uEmissiveFresnelEdgeColor,i._emissiveFresnel.edgeColor),this._uEmissiveFresnelCenterColor&&a.uniform3fv(this._uEmissiveFresnelCenterColor,i._emissiveFresnel.centerColor),this._uEmissiveFresnelPower&&a.uniform1f(this._uEmissiveFresnelPower,i._emissiveFresnel.power));break;case"MetallicMaterial":this._uBaseColor&&a.uniform3fv(this._uBaseColor,l.baseColor),this._uMaterialMetallic&&a.uniform1f(this._uMaterialMetallic,l.metallic),this._uMaterialRoughness&&a.uniform1f(this._uMaterialRoughness,l.roughness),this._uMaterialSpecularF0&&a.uniform1f(this._uMaterialSpecularF0,l.specularF0),this._uMaterialEmissive&&a.uniform3fv(this._uMaterialEmissive,l.emissive),this._uAlphaModeCutoff&&a.uniform4f(this._uAlphaModeCutoff,1*l.alpha,1===l.alphaMode?1:0,l.alphaCutoff,0);var T=i._baseColorMap;T&&T._state.texture&&this._uBaseColorMap&&(s.bindTexture(this._uBaseColorMap,T._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uBaseColorMapMatrix&&a.uniformMatrix4fv(this._uBaseColorMapMatrix,!1,T._state.matrix));var E=i._metallicMap;E&&E._state.texture&&this._uMetallicMap&&(s.bindTexture(this._uMetallicMap,E._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uMetallicMapMatrix&&a.uniformMatrix4fv(this._uMetallicMapMatrix,!1,E._state.matrix));var b=i._roughnessMap;b&&b._state.texture&&this._uRoughnessMap&&(s.bindTexture(this._uRoughnessMap,b._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uRoughnessMapMatrix&&a.uniformMatrix4fv(this._uRoughnessMapMatrix,!1,b._state.matrix));var D=i._metallicRoughnessMap;D&&D._state.texture&&this._uMetallicRoughnessMap&&(s.bindTexture(this._uMetallicRoughnessMap,D._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uMetallicRoughnessMapMatrix&&a.uniformMatrix4fv(this._uMetallicRoughnessMapMatrix,!1,D._state.matrix)),(_=i._emissiveMap)&&_._state.texture&&this._uEmissiveMap&&(s.bindTexture(this._uEmissiveMap,_._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uEmissiveMapMatrix&&a.uniformMatrix4fv(this._uEmissiveMapMatrix,!1,_._state.matrix)),(B=i._occlusionMap)&&i._occlusionMap._state.texture&&this._uOcclusionMap&&(s.bindTexture(this._uOcclusionMap,B._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uOcclusionMapMatrix&&a.uniformMatrix4fv(this._uOcclusionMapMatrix,!1,B._state.matrix)),(O=i._alphaMap)&&O._state.texture&&this._uAlphaMap&&(s.bindTexture(this._uAlphaMap,O._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uAlphaMapMatrix&&a.uniformMatrix4fv(this._uAlphaMapMatrix,!1,O._state.matrix)),(S=i._normalMap)&&S._state.texture&&this._uNormalMap&&(s.bindTexture(this._uNormalMap,S._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uNormalMapMatrix&&a.uniformMatrix4fv(this._uNormalMapMatrix,!1,S._state.matrix));break;case"SpecularMaterial":this._uMaterialDiffuse&&a.uniform3fv(this._uMaterialDiffuse,l.diffuse),this._uMaterialSpecular&&a.uniform3fv(this._uMaterialSpecular,l.specular),this._uMaterialGlossiness&&a.uniform1f(this._uMaterialGlossiness,l.glossiness),this._uMaterialReflectivity&&a.uniform1f(this._uMaterialReflectivity,l.reflectivity),this._uMaterialEmissive&&a.uniform3fv(this._uMaterialEmissive,l.emissive),this._uAlphaModeCutoff&&a.uniform4f(this._uAlphaModeCutoff,1*l.alpha,1===l.alphaMode?1:0,l.alphaCutoff,0);var P=i._diffuseMap;P&&P._state.texture&&this._uDiffuseMap&&(s.bindTexture(this._uDiffuseMap,P._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uDiffuseMapMatrix&&a.uniformMatrix4fv(this._uDiffuseMapMatrix,!1,P._state.matrix));var R=i._specularMap;R&&R._state.texture&&this._uSpecularMap&&(s.bindTexture(this._uSpecularMap,R._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uSpecularMapMatrix&&a.uniformMatrix4fv(this._uSpecularMapMatrix,!1,R._state.matrix));var C=i._glossinessMap;C&&C._state.texture&&this._uGlossinessMap&&(s.bindTexture(this._uGlossinessMap,C._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uGlossinessMapMatrix&&a.uniformMatrix4fv(this._uGlossinessMapMatrix,!1,C._state.matrix));var _,B,O,S,N=i._specularGlossinessMap;N&&N._state.texture&&this._uSpecularGlossinessMap&&(s.bindTexture(this._uSpecularGlossinessMap,N._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uSpecularGlossinessMapMatrix&&a.uniformMatrix4fv(this._uSpecularGlossinessMapMatrix,!1,N._state.matrix)),(_=i._emissiveMap)&&_._state.texture&&this._uEmissiveMap&&(s.bindTexture(this._uEmissiveMap,_._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uEmissiveMapMatrix&&a.uniformMatrix4fv(this._uEmissiveMapMatrix,!1,_._state.matrix)),(B=i._occlusionMap)&&B._state.texture&&this._uOcclusionMap&&(s.bindTexture(this._uOcclusionMap,B._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uOcclusionMapMatrix&&a.uniformMatrix4fv(this._uOcclusionMapMatrix,!1,B._state.matrix)),(O=i._alphaMap)&&O._state.texture&&this._uAlphaMap&&(s.bindTexture(this._uAlphaMap,O._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uAlphaMapMatrix&&a.uniformMatrix4fv(this._uAlphaMapMatrix,!1,O._state.matrix)),(S=i._normalMap)&&S._state.texture&&this._uNormalMap&&(s.bindTexture(this._uNormalMap,S._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uNormalMapMatrix&&a.uniformMatrix4fv(this._uNormalMapMatrix,!1,S._state.matrix))}this._lastMaterialId=l.id}if(a.uniformMatrix4fv(this._uModelMatrix,a.FALSE,t.worldMatrix),this._uModelNormalMatrix&&a.uniformMatrix4fv(this._uModelNormalMatrix,a.FALSE,t.worldNormalMatrix),this._uClippable&&a.uniform1i(this._uClippable,o.clippable),this._uColorize){var L=o.colorize,x=this._lastColorize;x[0]===L[0]&&x[1]===L[1]&&x[2]===L[2]&&x[3]===L[3]||(a.uniform4fv(this._uColorize,L),x[0]=L[0],x[1]=L[1],x[2]=L[2],x[3]=L[3])}a.uniform3fv(this._uOffset,o.offset),u.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&a.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,u.positionsDecodeMatrix),this._uUVDecodeMatrix&&a.uniformMatrix3fv(this._uUVDecodeMatrix,!1,u.uvDecodeMatrix),this._aPosition&&(this._aPosition.bindArrayBuffer(u.positionsBuf),e.bindArray++),this._aNormal&&(this._aNormal.bindArrayBuffer(u.normalsBuf),e.bindArray++),this._aUV&&(this._aUV.bindArrayBuffer(u.uvBuf),e.bindArray++),this._aColor&&(this._aColor.bindArrayBuffer(u.colorsBuf),e.bindArray++),this._aFlags&&(this._aFlags.bindArrayBuffer(u.flagsBuf),e.bindArray++),u.indicesBuf&&(u.indicesBuf.bind(),e.bindArray++),this._lastGeometryId=u.id),u.indicesBuf?(a.drawElements(u.primitive,u.indicesBuf.numItems,u.indicesBuf.itemType,0),e.drawElements++):u.positions&&(a.drawArrays(a.TRIANGLES,0,u.positions.numItems),e.drawArrays++),p&&a.depthFunc(a.LESS)},Pi.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl,r=e._material,i=t._lightsState,a=t._sectionPlanesState,s=e._material._state;if(this._program=new ft(n,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var o=this._program;this._uPositionsDecodeMatrix=o.getLocation("positionsDecodeMatrix"),this._uUVDecodeMatrix=o.getLocation("uvDecodeMatrix"),this._uModelMatrix=o.getLocation("modelMatrix"),this._uModelNormalMatrix=o.getLocation("modelNormalMatrix"),this._uViewMatrix=o.getLocation("viewMatrix"),this._uViewNormalMatrix=o.getLocation("viewNormalMatrix"),this._uProjMatrix=o.getLocation("projMatrix"),this._uGammaFactor=o.getLocation("gammaFactor"),this._uLightAmbient=[],this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[],this._uShadowViewMatrix=[],this._uShadowProjMatrix=[],t.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=o.getLocation("logDepthBufFC"));for(var l,u=i.lights,c=0,f=u.length;c<f;c++){switch((l=u[c]).type){case"ambient":this._uLightAmbient[c]=o.getLocation("lightAmbient");break;case"dir":this._uLightColor[c]=o.getLocation("lightColor"+c),this._uLightPos[c]=null,this._uLightDir[c]=o.getLocation("lightDir"+c);break;case"point":this._uLightColor[c]=o.getLocation("lightColor"+c),this._uLightPos[c]=o.getLocation("lightPos"+c),this._uLightDir[c]=null,this._uLightAttenuation[c]=o.getLocation("lightAttenuation"+c);break;case"spot":this._uLightColor[c]=o.getLocation("lightColor"+c),this._uLightPos[c]=o.getLocation("lightPos"+c),this._uLightDir[c]=o.getLocation("lightDir"+c),this._uLightAttenuation[c]=o.getLocation("lightAttenuation"+c)}l.castsShadow&&(this._uShadowViewMatrix[c]=o.getLocation("shadowViewMatrix"+c),this._uShadowProjMatrix[c]=o.getLocation("shadowProjMatrix"+c))}i.lightMaps.length>0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(c=0,f=a.sectionPlanes.length;c<f;c++)this._uSectionPlanes.push({active:o.getLocation("sectionPlaneActive"+c),pos:o.getLocation("sectionPlanePos"+c),dir:o.getLocation("sectionPlaneDir"+c)});switch(this._uPointSize=o.getLocation("pointSize"),s.type){case"LambertMaterial":this._uMaterialColor=o.getLocation("materialColor"),this._uMaterialEmissive=o.getLocation("materialEmissive"),this._uAlphaModeCutoff=o.getLocation("materialAlphaModeCutoff");break;case"PhongMaterial":this._uMaterialAmbient=o.getLocation("materialAmbient"),this._uMaterialDiffuse=o.getLocation("materialDiffuse"),this._uMaterialSpecular=o.getLocation("materialSpecular"),this._uMaterialEmissive=o.getLocation("materialEmissive"),this._uAlphaModeCutoff=o.getLocation("materialAlphaModeCutoff"),this._uMaterialShininess=o.getLocation("materialShininess"),r._ambientMap&&(this._uMaterialAmbientMap="ambientMap",this._uMaterialAmbientMapMatrix=o.getLocation("ambientMapMatrix")),r._diffuseMap&&(this._uDiffuseMap="diffuseMap",this._uDiffuseMapMatrix=o.getLocation("diffuseMapMatrix")),r._specularMap&&(this._uSpecularMap="specularMap",this._uSpecularMapMatrix=o.getLocation("specularMapMatrix")),r._emissiveMap&&(this._uEmissiveMap="emissiveMap",this._uEmissiveMapMatrix=o.getLocation("emissiveMapMatrix")),r._alphaMap&&(this._uAlphaMap="alphaMap",this._uAlphaMapMatrix=o.getLocation("alphaMapMatrix")),r._reflectivityMap&&(this._uReflectivityMap="reflectivityMap",this._uReflectivityMapMatrix=o.getLocation("reflectivityMapMatrix")),r._normalMap&&(this._uNormalMap="normalMap",this._uNormalMapMatrix=o.getLocation("normalMapMatrix")),r._occlusionMap&&(this._uOcclusionMap="occlusionMap",this._uOcclusionMapMatrix=o.getLocation("occlusionMapMatrix")),r._diffuseFresnel&&(this._uDiffuseFresnelEdgeBias=o.getLocation("diffuseFresnelEdgeBias"),this._uDiffuseFresnelCenterBias=o.getLocation("diffuseFresnelCenterBias"),this._uDiffuseFresnelEdgeColor=o.getLocation("diffuseFresnelEdgeColor"),this._uDiffuseFresnelCenterColor=o.getLocation("diffuseFresnelCenterColor"),this._uDiffuseFresnelPower=o.getLocation("diffuseFresnelPower")),r._specularFresnel&&(this._uSpecularFresnelEdgeBias=o.getLocation("specularFresnelEdgeBias"),this._uSpecularFresnelCenterBias=o.getLocation("specularFresnelCenterBias"),this._uSpecularFresnelEdgeColor=o.getLocation("specularFresnelEdgeColor"),this._uSpecularFresnelCenterColor=o.getLocation("specularFresnelCenterColor"),this._uSpecularFresnelPower=o.getLocation("specularFresnelPower")),r._alphaFresnel&&(this._uAlphaFresnelEdgeBias=o.getLocation("alphaFresnelEdgeBias"),this._uAlphaFresnelCenterBias=o.getLocation("alphaFresnelCenterBias"),this._uAlphaFresnelEdgeColor=o.getLocation("alphaFresnelEdgeColor"),this._uAlphaFresnelCenterColor=o.getLocation("alphaFresnelCenterColor"),this._uAlphaFresnelPower=o.getLocation("alphaFresnelPower")),r._reflectivityFresnel&&(this._uReflectivityFresnelEdgeBias=o.getLocation("reflectivityFresnelEdgeBias"),this._uReflectivityFresnelCenterBias=o.getLocation("reflectivityFresnelCenterBias"),this._uReflectivityFresnelEdgeColor=o.getLocation("reflectivityFresnelEdgeColor"),this._uReflectivityFresnelCenterColor=o.getLocation("reflectivityFresnelCenterColor"),this._uReflectivityFresnelPower=o.getLocation("reflectivityFresnelPower")),r._emissiveFresnel&&(this._uEmissiveFresnelEdgeBias=o.getLocation("emissiveFresnelEdgeBias"),this._uEmissiveFresnelCenterBias=o.getLocation("emissiveFresnelCenterBias"),this._uEmissiveFresnelEdgeColor=o.getLocation("emissiveFresnelEdgeColor"),this._uEmissiveFresnelCenterColor=o.getLocation("emissiveFresnelCenterColor"),this._uEmissiveFresnelPower=o.getLocation("emissiveFresnelPower"));break;case"MetallicMaterial":this._uBaseColor=o.getLocation("materialBaseColor"),this._uMaterialMetallic=o.getLocation("materialMetallic"),this._uMaterialRoughness=o.getLocation("materialRoughness"),this._uMaterialSpecularF0=o.getLocation("materialSpecularF0"),this._uMaterialEmissive=o.getLocation("materialEmissive"),this._uAlphaModeCutoff=o.getLocation("materialAlphaModeCutoff"),r._baseColorMap&&(this._uBaseColorMap="baseColorMap",this._uBaseColorMapMatrix=o.getLocation("baseColorMapMatrix")),r._metallicMap&&(this._uMetallicMap="metallicMap",this._uMetallicMapMatrix=o.getLocation("metallicMapMatrix")),r._roughnessMap&&(this._uRoughnessMap="roughnessMap",this._uRoughnessMapMatrix=o.getLocation("roughnessMapMatrix")),r._metallicRoughnessMap&&(this._uMetallicRoughnessMap="metallicRoughnessMap",this._uMetallicRoughnessMapMatrix=o.getLocation("metallicRoughnessMapMatrix")),r._emissiveMap&&(this._uEmissiveMap="emissiveMap",this._uEmissiveMapMatrix=o.getLocation("emissiveMapMatrix")),r._occlusionMap&&(this._uOcclusionMap="occlusionMap",this._uOcclusionMapMatrix=o.getLocation("occlusionMapMatrix")),r._alphaMap&&(this._uAlphaMap="alphaMap",this._uAlphaMapMatrix=o.getLocation("alphaMapMatrix")),r._normalMap&&(this._uNormalMap="normalMap",this._uNormalMapMatrix=o.getLocation("normalMapMatrix"));break;case"SpecularMaterial":this._uMaterialDiffuse=o.getLocation("materialDiffuse"),this._uMaterialSpecular=o.getLocation("materialSpecular"),this._uMaterialGlossiness=o.getLocation("materialGlossiness"),this._uMaterialReflectivity=o.getLocation("reflectivityFresnel"),this._uMaterialEmissive=o.getLocation("materialEmissive"),this._uAlphaModeCutoff=o.getLocation("materialAlphaModeCutoff"),r._diffuseMap&&(this._uDiffuseMap="diffuseMap",this._uDiffuseMapMatrix=o.getLocation("diffuseMapMatrix")),r._specularMap&&(this._uSpecularMap="specularMap",this._uSpecularMapMatrix=o.getLocation("specularMapMatrix")),r._glossinessMap&&(this._uGlossinessMap="glossinessMap",this._uGlossinessMapMatrix=o.getLocation("glossinessMapMatrix")),r._specularGlossinessMap&&(this._uSpecularGlossinessMap="materialSpecularGlossinessMap",this._uSpecularGlossinessMapMatrix=o.getLocation("materialSpecularGlossinessMapMatrix")),r._emissiveMap&&(this._uEmissiveMap="emissiveMap",this._uEmissiveMapMatrix=o.getLocation("emissiveMapMatrix")),r._occlusionMap&&(this._uOcclusionMap="occlusionMap",this._uOcclusionMapMatrix=o.getLocation("occlusionMapMatrix")),r._alphaMap&&(this._uAlphaMap="alphaMap",this._uAlphaMapMatrix=o.getLocation("alphaMapMatrix")),r._normalMap&&(this._uNormalMap="normalMap",this._uNormalMapMatrix=o.getLocation("normalMapMatrix"))}this._aPosition=o.getAttribute("position"),this._aNormal=o.getAttribute("normal"),this._aUV=o.getAttribute("uv"),this._aColor=o.getAttribute("color"),this._aFlags=o.getAttribute("flags"),this._uClippable=o.getLocation("clippable"),this._uColorize=o.getLocation("colorize"),this._uOffset=o.getLocation("offset"),this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null,this._lastColorize=new Float32Array(4),this._baseTextureUnit=0}},Pi.prototype._bindProgram=function(e){var t,n=Ze.MAX_TEXTURE_UNITS,r=this._scene,i=r.canvas.gl,a=r._lightsState,s=r.camera.project,o=this._program;if(o.bind(),e.useProgram++,e.textureUnit=0,this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null,this._lastColorize[0]=-1,this._lastColorize[1]=-1,this._lastColorize[2]=-1,this._lastColorize[3]=-1,i.uniformMatrix4fv(this._uProjMatrix,!1,s.matrix),r.logarithmicDepthBufferEnabled){var l=2/(Math.log(s.far+1)/Math.LN2);i.uniform1f(this._uLogDepthBufFC,l)}for(var u=0,c=a.lights.length;u<c;u++)if(t=a.lights[u],this._uLightAmbient[u])i.uniform4f(this._uLightAmbient[u],t.color[0],t.color[1],t.color[2],t.intensity);else if(this._uLightColor[u]&&i.uniform4f(this._uLightColor[u],t.color[0],t.color[1],t.color[2],t.intensity),this._uLightPos[u]&&(i.uniform3fv(this._uLightPos[u],t.pos),this._uLightAttenuation[u]&&i.uniform1f(this._uLightAttenuation[u],t.attenuation)),this._uLightDir[u]&&i.uniform3fv(this._uLightDir[u],t.dir),t.castsShadow){this._uShadowViewMatrix[u]&&i.uniformMatrix4fv(this._uShadowViewMatrix[u],!1,t.getShadowViewMatrix()),this._uShadowProjMatrix[u]&&i.uniformMatrix4fv(this._uShadowProjMatrix[u],!1,t.getShadowProjMatrix());var f=t.getShadowRenderBuf();f&&(o.bindTexture("shadowMap"+u,f.getTexture(),e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++)}a.lightMaps.length>0&&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<c;u++){var f=n.lights[u];"ambient"!==f.type&&(l.push("uniform vec4 lightColor"+u+";"),"dir"===f.type&&l.push("uniform vec3 lightDir"+u+";"),"point"===f.type&&l.push("uniform vec3 lightPos"+u+";"),"spot"===f.type&&l.push("uniform vec3 lightPos"+u+";"))}a&&(l.push("vec3 octDecode(vec2 oct) {"),l.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),l.push(" if (v.z < 0.0) {"),l.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);"),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;p<A;p++){var d=n.lights[p];if("ambient"!==d.type){if("dir"===d.type)"view"===d.space?l.push("viewLightDir = normalize(lightDir"+p+");"):l.push("viewLightDir = normalize((viewMatrix2 * vec4(lightDir"+p+", 0.0)).xyz);");else{if("point"!==d.type)continue;"view"===d.space?l.push("viewLightDir = normalize(lightPos"+p+" - viewPosition.xyz);"):l.push("viewLightDir = normalize((viewMatrix2 * vec4(lightPos"+p+", 0.0)).xyz);")}l.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),l.push("reflectedColor += lambertian * (lightColor"+p+".rgb * lightColor"+p+".a);")}}l.push("vColor = vec4(reflectedColor * fillColor.rgb, fillColor.a);"),i&&l.push("vWorldPosition = worldPosition;");"points"===e._geometry._state.primitiveName&&l.push("gl_PointSize = pointSize;");l.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(l.push("vFragDepth = 1.0 + clipPos.w;"),l.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return l.push("gl_Position = clipPos;"),l.push("}"),l}(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("// 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<o;s++)a.push("uniform bool sectionPlaneActive"+s+";"),a.push("uniform vec3 sectionPlanePos"+s+";"),a.push("uniform vec3 sectionPlaneDir"+s+";")}if(a.push("in vec4 vColor;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),i){a.push("if (clippable) {"),a.push(" float dist = 0.0;");for(var l=0,u=n.sectionPlanes.length;l<u;l++)a.push("if (sectionPlaneActive"+l+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+l+".xyz, vWorldPosition.xyz - sectionPlanePos"+l+".xyz), 0.0, 1000.0);"),a.push("}");a.push(" if (dist > 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;A<c;A++){var d=this._uSectionPlanes[A];if(d){var v=p.sectionPlanesActivePerLayer[A];if(a.uniform1i(d.active,v?1:0),v){var h=f[A];a.uniform3fv(d.pos,u?ge(h.dist,h.dir,u,Bi):h.pos),a.uniform3fv(d.dir,h.dir)}}}}if(s.id!==this._lastMaterialId){var I=s.fillColor,y=s.backfaces;e.backfaces!==y&&(y?a.disable(a.CULL_FACE):a.enable(a.CULL_FACE),e.backfaces=y),a.uniform4f(this._uFillColor,I[0],I[1],I[2],s.fillAlpha),this._lastMaterialId=s.id}a.uniformMatrix4fv(this._uModelMatrix,a.FALSE,t.worldMatrix),this._uModelNormalMatrix&&a.uniformMatrix4fv(this._uModelNormalMatrix,a.FALSE,t.worldNormalMatrix),this._uClippable&&a.uniform1i(this._uClippable,o.clippable),a.uniform3fv(this._uOffset,o.offset),l.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&a.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,l.positionsDecodeMatrix),this._uUVDecodeMatrix&&a.uniformMatrix3fv(this._uUVDecodeMatrix,!1,l.uvDecodeMatrix),this._aPosition&&(this._aPosition.bindArrayBuffer(l.positionsBuf),e.bindArray++),this._aNormal&&(this._aNormal.bindArrayBuffer(l.normalsBuf),e.bindArray++),l.indicesBuf?(l.indicesBuf.bind(),e.bindArray++):l.positionsBuf,this._lastGeometryId=l.id),l.indicesBuf?(a.drawElements(l.primitive,l.indicesBuf.numItems,l.indicesBuf.itemType,0),e.drawElements++):l.positionsBuf&&(a.drawArrays(a.TRIANGLES,0,l.positionsBuf.numItems),e.drawArrays++)},Oi.prototype._allocate=function(e){var t=e.scene,n=t._lightsState,r=t._sectionPlanesState,i=t.canvas.gl;if(this._program=new ft(i,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var a=this._program;this._uPositionsDecodeMatrix=a.getLocation("positionsDecodeMatrix"),this._uModelMatrix=a.getLocation("modelMatrix"),this._uModelNormalMatrix=a.getLocation("modelNormalMatrix"),this._uViewMatrix=a.getLocation("viewMatrix"),this._uViewNormalMatrix=a.getLocation("viewNormalMatrix"),this._uProjMatrix=a.getLocation("projMatrix"),this._uLightAmbient=[],this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];for(var s=0,o=n.lights.length;s<o;s++){switch(n.lights[s].type){case"ambient":this._uLightAmbient[s]=a.getLocation("lightAmbient");break;case"dir":this._uLightColor[s]=a.getLocation("lightColor"+s),this._uLightPos[s]=null,this._uLightDir[s]=a.getLocation("lightDir"+s);break;case"point":this._uLightColor[s]=a.getLocation("lightColor"+s),this._uLightPos[s]=a.getLocation("lightPos"+s),this._uLightDir[s]=null,this._uLightAttenuation[s]=a.getLocation("lightAttenuation"+s)}}this._uSectionPlanes=[];for(var l=0,u=r.sectionPlanes.length;l<u;l++)this._uSectionPlanes.push({active:a.getLocation("sectionPlaneActive"+l),pos:a.getLocation("sectionPlanePos"+l),dir:a.getLocation("sectionPlaneDir"+l)});this._uFillColor=a.getLocation("fillColor"),this._aPosition=a.getAttribute("position"),this._aNormal=a.getAttribute("normal"),this._uClippable=a.getLocation("clippable"),this._uGammaFactor=a.getLocation("gammaFactor"),this._uOffset=a.getLocation("offset"),t.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=a.getLocation("logDepthBufFC")),this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null}},Oi.prototype._bindProgram=function(e){var t=this._scene,n=t.canvas.gl,r=t._lightsState,i=t.camera,a=i.project;if(this._program.bind(),e.useProgram++,e.textureUnit=0,this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null,this._lastIndicesBufId=null,n.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.normalMatrix),n.uniformMatrix4fv(this._uProjMatrix,!1,a.matrix),t.logarithmicDepthBufferEnabled){var s=2/(Math.log(a.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,s)}for(var o=0,l=r.lights.length;o<l;o++){var u=r.lights[o];this._uLightAmbient[o]?n.uniform4f(this._uLightAmbient[o],u.color[0],u.color[1],u.color[2],u.intensity):(this._uLightColor[o]&&n.uniform4f(this._uLightColor[o],u.color[0],u.color[1],u.color[2],u.intensity),this._uLightPos[o]&&(n.uniform3fv(this._uLightPos[o],u.pos),this._uLightAttenuation[o]&&n.uniform1f(this._uLightAttenuation[o],u.attenuation)),this._uLightDir[o]&&n.uniform3fv(this._uLightDir[o],u.dir))}this._uGammaFactor&&n.uniform1f(this._uGammaFactor,t.gammaFactor)};var Ni=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene,n=t._sectionPlanesState.sectionPlanes.length>0,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<o;s++)a.push("uniform bool sectionPlaneActive"+s+";"),a.push("uniform vec3 sectionPlanePos"+s+";"),a.push("uniform vec3 sectionPlaneDir"+s+";")}if(a.push("in vec4 vColor;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),i){a.push("if (clippable) {"),a.push(" float dist = 0.0;");for(var l=0,u=n.sectionPlanes.length;l<u;l++)a.push("if (sectionPlaneActive"+l+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+l+".xyz, vWorldPosition.xyz - sectionPlanePos"+l+".xyz), 0.0, 1000.0);"),a.push("}");a.push(" if (dist > 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;v<p;v++){var h=this._uSectionPlanes[v];if(h){var I=d.sectionPlanesActivePerLayer[v];if(o.uniform1i(h.active,I?1:0),I){var y=A[v];o.uniform3fv(h.pos,f?ge(y.dist,y.dir,f,xi):y.pos),o.uniform3fv(h.dir,y.dir)}}}}switch(n){case 0:r=t._xrayMaterial._state;break;case 1:r=t._highlightMaterial._state;break;case 2:r=t._selectedMaterial._state;break;default:r=t._edgeMaterial._state}if(r.id!==this._lastMaterialId){var m=r.backfaces;if(e.backfaces!==m&&(m?o.disable(o.CULL_FACE):o.enable(o.CULL_FACE),e.backfaces=m),e.lineWidth!==r.edgeWidth&&(o.lineWidth(r.edgeWidth),e.lineWidth=r.edgeWidth),this._uEdgeColor){var w=r.edgeColor,g=r.edgeAlpha;o.uniform4f(this._uEdgeColor,w[0],w[1],w[2],g)}this._lastMaterialId=r.id}o.uniformMatrix4fv(this._uModelMatrix,o.FALSE,t.worldMatrix),this._uClippable&&o.uniform1i(this._uClippable,l.clippable),o.uniform3fv(this._uOffset,l.offset),c.primitive===o.TRIANGLES?i=u._getEdgeIndices():c.primitive===o.LINES&&(i=c.indicesBuf),i&&(c.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&o.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,c.positionsDecodeMatrix),this._aPosition&&(this._aPosition.bindArrayBuffer(c.positionsBuf,c.compressGeometry?o.UNSIGNED_SHORT:o.FLOAT),e.bindArray++),i.bind(),e.bindArray++,this._lastGeometryId=c.id),o.drawElements(o.LINES,i.numItems,i.itemType,0),e.drawElements++)},Mi.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl,r=t._sectionPlanesState;if(this._program=new ft(n,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uPositionsDecodeMatrix=i.getLocation("positionsDecodeMatrix"),this._uModelMatrix=i.getLocation("modelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var a=0,s=r.sectionPlanes.length;a<s;a++)this._uSectionPlanes.push({active:i.getLocation("sectionPlaneActive"+a),pos:i.getLocation("sectionPlanePos"+a),dir:i.getLocation("sectionPlaneDir"+a)});this._uEdgeColor=i.getLocation("edgeColor"),this._aPosition=i.getAttribute("position"),this._uClippable=i.getLocation("clippable"),this._uGammaFactor=i.getLocation("gammaFactor"),this._uOffset=i.getLocation("offset"),t.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=i.getLocation("logDepthBufFC")),this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null}},Mi.prototype._bindProgram=function(e){var t=this._program,n=this._scene,r=n.canvas.gl,i=n.camera.project;if(t.bind(),e.useProgram++,this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null,r.uniformMatrix4fv(this._uProjMatrix,!1,i.matrix),n.logarithmicDepthBufferEnabled){var a=2/(Math.log(i.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,a)}this._uGammaFactor&&r.uniform1f(this._uGammaFactor,n.gammaFactor)};var Hi=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene,n=t._sectionPlanesState.sectionPlanes.length>0,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<n.sectionPlanes.length;a++)i.push("uniform bool sectionPlaneActive"+a+";"),i.push("uniform vec3 sectionPlanePos"+a+";"),i.push("uniform vec3 sectionPlaneDir"+a+";")}if(i.push("out vec4 outColor;"),i.push("void main(void) {"),r){i.push("if (clippable) {"),i.push(" float dist = 0.0;");for(a=0;a<n.sectionPlanes.length;a++)i.push("if (sectionPlaneActive"+a+") {"),i.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),i.push("}");i.push(" if (dist > 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<l;f++){var p=this._uSectionPlanes[f];if(p){var A=c.sectionPlanesActivePerLayer[f];if(r.uniform1i(p.active,A?1:0),A){var d=u[f];r.uniform3fv(p.pos,o?ge(d.dist,d.dir,o,Ui):d.pos),r.uniform3fv(p.dir,d.dir)}}}}if(a.id!==this._lastMaterialId){var v=a.backfaces;e.backfaces!==v&&(v?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),e.backfaces=v);var h=a.frontface;e.frontface!==h&&(h?r.frontFace(r.CCW):r.frontFace(r.CW),e.frontface=h),this._lastMaterialId=a.id}r.uniformMatrix4fv(this._uProjMatrix,!1,e.pickProjMatrix),r.uniformMatrix4fv(this._uModelMatrix,!1,t.worldMatrix),this._uClippable&&r.uniform1i(this._uClippable,t._state.clippable),r.uniform3fv(this._uOffset,t._state.offset),s.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&r.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,s.positionsDecodeMatrix),this._aPosition&&(this._aPosition.bindArrayBuffer(s.positionsBuf,s.compressGeometry?r.UNSIGNED_SHORT:r.FLOAT),e.bindArray++),s.indicesBuf&&(s.indicesBuf.bind(),e.bindArray++),this._lastGeometryId=s.id);var I=t._state.pickID,y=I>>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;i<a;i++)this._uSectionPlanes.push({active:r.getLocation("sectionPlaneActive"+i),pos:r.getLocation("sectionPlanePos"+i),dir:r.getLocation("sectionPlaneDir"+i)});this._aPosition=r.getAttribute("position"),this._uClippable=r.getLocation("clippable"),this._uPickColor=r.getLocation("pickColor"),this._uOffset=r.getLocation("offset"),t.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=r.getLocation("logDepthBufFC")),this._lastMaterialId=null,this._lastGeometryId=null}},Gi.prototype._bindProgram=function(e){var t=this._scene,n=t.canvas.gl,r=t.camera.project;if(this._program.bind(),e.useProgram++,t.logarithmicDepthBufferEnabled){var i=2/(Math.log(r.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,i)}this._lastMaterialId=null,this._lastGeometryId=null};var Vi=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene,n=t._sectionPlanesState.sectionPlanes.length>0,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<n.sectionPlanes.length;a++)i.push("uniform bool sectionPlaneActive"+a+";"),i.push("uniform vec3 sectionPlanePos"+a+";"),i.push("uniform vec3 sectionPlaneDir"+a+";")}if(i.push("out vec4 outColor;"),i.push("void main(void) {"),r){i.push("if (clippable) {"),i.push(" float dist = 0.0;");for(var s=0;s<n.sectionPlanes.length;s++)i.push("if (sectionPlaneActive"+s+") {"),i.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),i.push("}");i.push(" if (dist > 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;y<v;y++){var m=this._uSectionPlanes[y];if(m){var w=I.sectionPlanesActivePerLayer[y];if(r.uniform1i(m.active,w?1:0),w){var g=h[y];r.uniform3fv(m.pos,l?ge(g.dist,g.dir,l,ji):g.pos),r.uniform3fv(m.dir,g.dir)}}}}r.uniformMatrix4fv(this._uProjMatrix,!1,e.pickProjMatrix),n.logarithmicDepthBufferEnabled&&r.uniform1f(this._uZFar,n.camera.project.far),e.backfaces!==u&&(u?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),e.backfaces=u),e.frontface!==c&&(c?r.frontFace(r.CCW):r.frontFace(r.CW),e.frontface=c),r.uniformMatrix4fv(this._uModelMatrix,!1,t.worldMatrix),this._uClippable&&r.uniform1i(this._uClippable,t._state.clippable),r.uniform3fv(this._uOffset,t._state.offset),this._uPositionsDecodeMatrix?(r.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,o.positionsDecodeMatrix),this._aPosition.bindArrayBuffer(p,o.compressGeometry?r.UNSIGNED_SHORT:r.FLOAT)):this._aPosition.bindArrayBuffer(p),A.bind(),r.enableVertexAttribArray(this._aColor.location),r.vertexAttribPointer(this._aColor.location,A.itemSize,A.itemType,!0,0,0),r.drawArrays(o.primitive,0,p.numItems/3)},Qi.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl;if(this._program=new ft(n,this._shaderSource),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._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var i=0,a=t._sectionPlanesState.sectionPlanes.length;i<a;i++)this._uSectionPlanes.push({active:r.getLocation("sectionPlaneActive"+i),pos:r.getLocation("sectionPlanePos"+i),dir:r.getLocation("sectionPlaneDir"+i)});this._aPosition=r.getAttribute("position"),this._aColor=r.getAttribute("color"),this._uClippable=r.getLocation("clippable"),this._uOffset=r.getLocation("offset"),t.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=r.getLocation("logDepthBufFC"))}};var zi=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene,n=t._sectionPlanesState.sectionPlanes.length>0,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<n.sectionPlanes.length;a++)i.push("uniform bool sectionPlaneActive"+a+";"),i.push("uniform vec3 sectionPlanePos"+a+";"),i.push("uniform vec3 sectionPlaneDir"+a+";")}if(i.push("out vec4 outColor;"),i.push("void main(void) {"),r){i.push("if (clippable) {"),i.push(" float dist = 0.0;");for(a=0;a<n.sectionPlanes.length;a++)i.push("if (sectionPlaneActive"+a+") {"),i.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),i.push("}");i.push(" if (dist > 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;d<f;d++){var v=this._uSectionPlanes[d];if(v){var h=A.sectionPlanesActivePerLayer[d];if(r.uniform1i(v.active,h?1:0),h){var I=p[d];r.uniform3fv(v.pos,o?ge(I.dist,I.dir,o,Ki):I.pos),r.uniform3fv(v.dir,I.dir)}}}}r.uniformMatrix4fv(this._uProjMatrix,!1,c._project._state.matrix),r.uniformMatrix4fv(this._uModelMatrix,r.FALSE,t.worldMatrix),this._uClippable&&r.uniform1i(this._uClippable,t._state.clippable),r.uniform3fv(this._uOffset,t._state.offset),s.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&r.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,s.positionsDecodeMatrix),this._aPosition&&(this._aPosition.bindArrayBuffer(s.positionsBuf,s.compressGeometry?r.UNSIGNED_SHORT:r.FLOAT),e.bindArray++),s.indicesBuf&&(s.indicesBuf.bind(),e.bindArray++),this._lastGeometryId=s.id),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)},Yi.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;i<a;i++)this._uSectionPlanes.push({active:r.getLocation("sectionPlaneActive"+i),pos:r.getLocation("sectionPlanePos"+i),dir:r.getLocation("sectionPlaneDir"+i)});this._aPosition=r.getAttribute("position"),this._uClippable=r.getLocation("clippable"),this._uOffset=r.getLocation("offset"),t.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=r.getLocation("logDepthBufFC")),this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null}},Yi.prototype._bindProgram=function(e){var t=this._scene,n=t.camera.project,r=t.canvas.gl;if(this._program.bind(),e.useProgram++,r.uniformMatrix4fv(this._uProjMatrix,!1,n.matrix),t.logarithmicDepthBufferEnabled){var i=2/(Math.log(n.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,i)}this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null};var qi=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene._sectionPlanesState.sectionPlanes.length>0,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<n.sectionPlanes.length;a++)i.push("uniform bool sectionPlaneActive"+a+";"),i.push("uniform vec3 sectionPlanePos"+a+";"),i.push("uniform vec3 sectionPlaneDir"+a+";")}if(i.push("vec4 encodeFloat( const in float depth ) {"),i.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"),i.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"),i.push(" vec4 comp = fract(depth * bitShift);"),i.push(" comp -= comp.xxyz * bitMask;"),i.push(" return comp;"),i.push("}"),i.push("out vec4 outColor;"),i.push("void main(void) {"),r){i.push("if (clippable) {"),i.push(" float dist = 0.0;");for(a=0;a<n.sectionPlanes.length;a++)i.push("if (sectionPlaneActive"+a+") {"),i.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),i.push("}");i.push(" if (dist > 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;i<a;i++)this._uSectionPlanes.push({active:r.getLocation("sectionPlaneActive"+i),pos:r.getLocation("sectionPlanePos"+i),dir:r.getLocation("sectionPlaneDir"+i)});this._aPosition=r.getAttribute("position"),this._uClippable=r.getLocation("clippable"),this._uOffset=r.getLocation("offset"),this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null}},Ji.prototype._bindProgram=function(e){this._program||this._allocate(mesh);var t=this._scene,n=t.canvas.gl,r=t._sectionPlanesState;if(this._program.bind(),e.useProgram++,n.uniformMatrix4fv(this._uShadowViewMatrix,!1,e.shadowViewMatrix),n.uniformMatrix4fv(this._uShadowProjMatrix,!1,e.shadowProjMatrix),this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null,r.sectionPlanes.length>0)for(var i,a,s,o=0,l=this._uSectionPlanes.length;o<l;o++)a=(i=this._uSectionPlanes[o]).active,s=r.sectionPlanes[o],a&&n.uniform1i(a,s.active),i.pos&&n.uniform3fv(i.pos,s.pos),i.dir&&n.uniform3fv(i.dir,s.dir)};var $i=function(){function e(){b(this,e),this.visibleLayers=[],this.sectionPlanesActivePerLayer=[],this.reset()}return P(e,[{key:"reset",value:function(){this.culled=!1,this.sectioned=!1,this.numLayers=0,this.numVisibleLayers=0,this.colorOpaque=!1,this.colorTransparent=!1,this.edgesOpaque=!1,this.edgesTransparent=!1,this.xrayedSilhouetteOpaque=!1,this.xrayedEdgesOpaque=!1,this.xrayedSilhouetteTransparent=!1,this.xrayedEdgesTransparent=!1,this.highlightedSilhouetteOpaque=!1,this.highlightedEdgesOpaque=!1,this.highlightedSilhouetteTransparent=!1,this.highlightedEdgesTransparent=!1,this.selectedSilhouetteOpaque=!1,this.selectedEdgesOpaque=!1,this.selectedSilhouetteTransparent=!1,this.selectedEdgesTransparent=!1}}]),e}(),ea=Z.OBB3(),ta=Z.vec4(),na=Z.vec4(),ra=Z.vec4(),ia=Z.vec3([1,0,0]),aa=Z.vec3([0,1,0]),sa=Z.vec3([0,0,1]),oa=Z.vec3(3),la=Z.vec3(3),ua=Z.identityMat4(),ca=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i)).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;t<n;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}},{key:"_buildWorldNormalMatrix",value:function(){this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldNormalMatrix||(this._worldNormalMatrix=Z.mat4()),Z.transposeMat4(this._worldMatrix,this._worldNormalMatrix),Z.inverseMat4(this._worldNormalMatrix),this._worldNormalMatrixDirty=!1}},{key:"_setAABBDirty",value:function(){if(this.collidable)for(var e=this;e;e=e._parentNode)e._aabbDirty=!0}},{key:"_updateAABB",value:function(){this.scene._aabbDirty=!0,this._aabb||(this._aabb=Z.AABB3()),this._buildAABB(this.worldMatrix,this._aabb),this._aabbDirty=!1}},{key:"_webglContextRestored",value:function(){this._drawRenderer&&this._drawRenderer.webglContextRestored(),this._shadowRenderer&&this._shadowRenderer.webglContextRestored(),this._emphasisFillRenderer&&this._emphasisFillRenderer.webglContextRestored(),this._emphasisEdgesRenderer&&this._emphasisEdgesRenderer.webglContextRestored(),this._pickMeshRenderer&&this._pickMeshRenderer.webglContextRestored(),this._pickTriangleRenderer&&this._pickMeshRenderer.webglContextRestored(),this._occlusionRenderer&&this._occlusionRenderer.webglContextRestored()}},{key:"_makeDrawHash",value:function(){var e=this.scene,t=[e.canvas.canvas.id,(e.gammaInput?"gi;":";")+(e.gammaOutput?"go":""),e._lightsState.getHash(),e._sectionPlanesState.getHash()],n=this._state;return n.stationary&&t.push("/s"),"none"===n.billboard?t.push("/n"):"spherical"===n.billboard?t.push("/s"):"cylindrical"===n.billboard&&t.push("/c"),n.receivesShadow&&t.push("/rs"),t.push(";"),t.join("")}},{key:"_makePickHash",value:function(){var e=this.scene,t=[e.canvas.canvas.id,e._sectionPlanesState.getHash()],n=this._state;return n.stationary&&t.push("/s"),"none"===n.billboard?t.push("/n"):"spherical"===n.billboard?t.push("/s"):"cylindrical"===n.billboard&&t.push("/c"),t.push(";"),t.join("")}},{key:"_makeOcclusionHash",value:function(){var e=this.scene,t=[e.canvas.canvas.id,e._sectionPlanesState.getHash()],n=this._state;return n.stationary&&t.push("/s"),"none"===n.billboard?t.push("/n"):"spherical"===n.billboard?t.push("/s"):"cylindrical"===n.billboard&&t.push("/c"),t.push(";"),t.join("")}},{key:"_buildAABB",value:function(e,t){Z.transformOBB3(e,this._geometry.obb,ea),Z.OBB3ToAABB3(ea,t);var n=this._state.offset;if(t[0]+=n[0],t[1]+=n[1],t[2]+=n[2],t[3]+=n[0],t[4]+=n[1],t[5]+=n[2],this._state.origin){var r=this._state.origin;t[0]+=r[0],t[1]+=r[1],t[2]+=r[2],t[3]+=r[0],t[4]+=r[1],t[5]+=r[2]}}},{key:"rotate",value:function(e,t){return ta[0]=e[0],ta[1]=e[1],ta[2]=e[2],ta[3]=t*Z.DEGTORAD,Z.angleAxisToQuaternion(ta,na),Z.mulQuaternions(this.quaternion,na,ra),this.quaternion=ra,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return ta[0]=e[0],ta[1]=e[1],ta[2]=e[2],ta[3]=t*Z.DEGTORAD,Z.angleAxisToQuaternion(ta,na),Z.mulQuaternions(na,this.quaternion,na),this}},{key:"rotateX",value:function(e){return this.rotate(ia,e)}},{key:"rotateY",value:function(e){return this.rotate(aa,e)}},{key:"rotateZ",value:function(e){return this.rotate(sa,e)}},{key:"translate",value:function(e,t){return Z.vec3ApplyQuaternion(this.quaternion,e,oa),Z.mulVec3Scalar(oa,t,la),Z.addVec3(this.position,la,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"translateX",value:function(e){return this.translate(ia,e)}},{key:"translateY",value:function(e){return this.translate(aa,e)}},{key:"translateZ",value:function(e){return this.translate(sa,e)}},{key:"_putDrawRenderers",value:function(){this._drawRenderer&&(this._drawRenderer.put(),this._drawRenderer=null),this._shadowRenderer&&(this._shadowRenderer.put(),this._shadowRenderer=null),this._emphasisFillRenderer&&(this._emphasisFillRenderer.put(),this._emphasisFillRenderer=null),this._emphasisEdgesRenderer&&(this._emphasisEdgesRenderer.put(),this._emphasisEdgesRenderer=null)}},{key:"_putPickRenderers",value:function(){this._pickMeshRenderer&&(this._pickMeshRenderer.put(),this._pickMeshRenderer=null),this._pickTriangleRenderer&&(this._pickTriangleRenderer.put(),this._pickTriangleRenderer=null)}},{key:"_putOcclusionRenderer",value:function(){this._occlusionRenderer&&(this._occlusionRenderer.put(),this._occlusionRenderer=null)}},{key:"stateSortCompare",value:function(e,t){return e._state.layer-t._state.layer||e._drawRenderer.id-t._drawRenderer.id||e._material._state.id-t._material._state.id||e._geometry._state.id-t._geometry._state.id}},{key:"rebuildRenderFlags",value:function(){this.renderFlags.reset(),this._getActiveSectionPlanes()?(this.renderFlags.numLayers=1,this.renderFlags.numVisibleLayers=1,this.renderFlags.visibleLayers[0]=0,this._updateRenderFlags()):this.renderFlags.culled=!0}},{key:"_updateRenderFlags",value:function(){var e=this.renderFlags,t=this._state;if(t.xrayed){var n=this._xrayMaterial._state;n.fill&&(n.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),n.edges&&(n.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}else{if(this._material._state.alpha<1||t.colorize[3]<1?e.colorTransparent=!0:e.colorOpaque=!0,t.edges)this._edgeMaterial._state.alpha<1?e.edgesTransparent=!0:e.edgesOpaque=!0;if(t.selected){var r=this._selectedMaterial._state;r.fill&&(r.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),r.edges&&(r.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}else if(t.highlighted){var i=this._highlightMaterial._state;i.fill&&(i.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),i.edges&&(i.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"_getActiveSectionPlanes",value:function(){if(this._state.clippable){var e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(var n=0;n<t;n++){var r=e[n],i=this.renderFlags;if(r.active)if(this._state.origin){var a=Z.planeAABB3Intersect(r.dir,r.dist,this.aabb);if(-1===a)return!1;var s=0===a;i.sectionPlanesActivePerLayer[n]=s}else i.sectionPlanesActivePerLayer[n]=!0;else i.sectionPlanesActivePerLayer[n]=!1}}return!0}},{key:"drawColorOpaque",value:function(e){(this._drawRenderer||(this._drawRenderer=Pi.get(this)))&&this._drawRenderer.drawMesh(e,this)}},{key:"drawColorTransparent",value:function(e){(this._drawRenderer||(this._drawRenderer=Pi.get(this)))&&this._drawRenderer.drawMesh(e,this)}},{key:"drawSilhouetteXRayed",value:function(e){(this._emphasisFillRenderer||(this._emphasisFillRenderer=Oi.get(this)))&&this._emphasisFillRenderer.drawMesh(e,this,0)}},{key:"drawSilhouetteHighlighted",value:function(e){(this._emphasisFillRenderer||(this._emphasisFillRenderer=Oi.get(this)))&&this._emphasisFillRenderer.drawMesh(e,this,1)}},{key:"drawSilhouetteSelected",value:function(e){(this._emphasisFillRenderer||(this._emphasisFillRenderer=Oi.get(this)))&&this._emphasisFillRenderer.drawMesh(e,this,2)}},{key:"drawEdgesColorOpaque",value:function(e){(this._emphasisEdgesRenderer||(this._emphasisEdgesRenderer=Mi.get(this)))&&this._emphasisEdgesRenderer.drawMesh(e,this,3)}},{key:"drawEdgesColorTransparent",value:function(e){(this._emphasisEdgesRenderer||(this._emphasisEdgesRenderer=Mi.get(this)))&&this._emphasisEdgesRenderer.drawMesh(e,this,3)}},{key:"drawEdgesXRayed",value:function(e){(this._emphasisEdgesRenderer||(this._emphasisEdgesRenderer=Mi.get(this)))&&this._emphasisEdgesRenderer.drawMesh(e,this,0)}},{key:"drawEdgesHighlighted",value:function(e){(this._emphasisEdgesRenderer||(this._emphasisEdgesRenderer=Mi.get(this)))&&this._emphasisEdgesRenderer.drawMesh(e,this,1)}},{key:"drawEdgesSelected",value:function(e){(this._emphasisEdgesRenderer||(this._emphasisEdgesRenderer=Mi.get(this)))&&this._emphasisEdgesRenderer.drawMesh(e,this,2)}},{key:"drawOcclusion",value:function(e){(this._state.occluder&&this._occlusionRenderer||(this._occlusionRenderer=Yi.get(this)))&&this._occlusionRenderer.drawMesh(e,this)}},{key:"drawShadow",value:function(e){(this._shadowRenderer||(this._shadowRenderer=Ji.get(this)))&&this._shadowRenderer.drawMesh(e,this)}},{key:"drawPickMesh",value:function(e){(this._pickMeshRenderer||(this._pickMeshRenderer=Gi.get(this)))&&this._pickMeshRenderer.drawMesh(e,this)}},{key:"canPickTriangle",value:function(){return this._geometry.isReadableGeometry}},{key:"drawPickTriangles",value:function(e){(this._pickTriangleRenderer||(this._pickTriangleRenderer=Qi.get(this)))&&this._pickTriangleRenderer.drawMesh(e,this)}},{key:"pickTriangleSurface",value:function(e,t,n){fa(this,e,t,n)}},{key:"drawPickVertices",value:function(e){}},{key:"delegatePickedEntity",value:function(){return this}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._putDrawRenderers(),this._putPickRenderers(),this._putOcclusionRenderer(),this.scene._renderer.putPickID(this._state.pickID),this._isObject&&(this.scene._deregisterObject(this),this._visible&&this.scene._objectVisibilityUpdated(this,!1,!1),this._xrayed&&this.scene._objectXRayedUpdated(this,!1,!1),this._selected&&this.scene._objectSelectedUpdated(this,!1,!1),this._highlighted&&this.scene._objectHighlightedUpdated(this,!1,!1),this.scene._objectColorizeUpdated(this,!1),this.scene._objectOpacityUpdated(this,!1),this.offset.some((function(e){return 0!==e}))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}]),n}(),fa=function(){var e=Z.vec3(),t=Z.vec3(),n=Z.vec3(),r=Z.vec3(),i=Z.vec3(),a=Z.vec3(),s=Z.vec4(),o=Z.vec3(),l=Z.vec3(),u=Z.vec3(),c=Z.vec3(),f=Z.vec3(),p=Z.vec3(),A=Z.vec3(),d=Z.vec3(),v=Z.vec3(),h=Z.vec4(),I=Z.vec4(),y=Z.vec4(),m=Z.vec3(),w=Z.vec3(),g=Z.vec3(),T=Z.vec3(),E=Z.vec3(),b=Z.vec3(),D=Z.vec3(),P=Z.vec3(),R=Z.vec3(),C=Z.vec3(),_=Z.vec3();return function(B,O,S,N){var L=N.primIndex;if(null!=L&&L>-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;s<a;s++)for(o=0;o<=i;o++)A=(p=s*(i+1)+o)+i,B.push(p),B.push(A),B.push(A+1),B.push(p),B.push(A+1),B.push(p+1);if(!I&&t>0){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;o<i;o++)y=d,p=d+1+o,B.push(p),B.push(p+1),B.push(y)}if(!I&&n>0){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;o<i;o++)y=d,p=d+1+o,B.push(y),B.push(p+1),B.push(p)}return ae.apply(e,{positions:R,normals:C,uv:_,indices:B})}function Aa(){var e=arguments.length>0&&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<s;l++)for(u=0;u<o;u++)g=(w=l*(o+1)+u)+o+1,D.push(w+1),D.push(g+1),D.push(g),D.push(w+1),D.push(g),D.push(w);return ae.apply(e,{positions:T,normals:E,uv:b,indices:D})}var da={" ":{width:16,points:[]},"!":{width:10,points:[[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},'"':{width:16,points:[[4,21],[4,14],[-1,-1],[12,21],[12,14]]},"#":{width:21,points:[[11,25],[4,-7],[-1,-1],[17,25],[10,-7],[-1,-1],[4,12],[18,12],[-1,-1],[3,6],[17,6]]},$:{width:20,points:[[8,25],[8,-4],[-1,-1],[12,25],[12,-4],[-1,-1],[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},"%":{width:24,points:[[21,21],[3,0],[-1,-1],[8,21],[10,19],[10,17],[9,15],[7,14],[5,14],[3,16],[3,18],[4,20],[6,21],[8,21],[10,20],[13,19],[16,19],[19,20],[21,21],[-1,-1],[17,7],[15,6],[14,4],[14,2],[16,0],[18,0],[20,1],[21,3],[21,5],[19,7],[17,7]]},"&":{width:26,points:[[23,12],[23,13],[22,14],[21,14],[20,13],[19,11],[17,6],[15,3],[13,1],[11,0],[7,0],[5,1],[4,2],[3,4],[3,6],[4,8],[5,9],[12,13],[13,14],[14,16],[14,18],[13,20],[11,21],[9,20],[8,18],[8,16],[9,13],[11,10],[16,3],[18,1],[20,0],[22,0],[23,1],[23,2]]},"'":{width:10,points:[[5,19],[4,20],[5,21],[6,20],[6,18],[5,16],[4,15]]},"(":{width:14,points:[[11,25],[9,23],[7,20],[5,16],[4,11],[4,7],[5,2],[7,-2],[9,-5],[11,-7]]},")":{width:14,points:[[3,25],[5,23],[7,20],[9,16],[10,11],[10,7],[9,2],[7,-2],[5,-5],[3,-7]]},"*":{width:16,points:[[8,21],[8,9],[-1,-1],[3,18],[13,12],[-1,-1],[13,18],[3,12]]},"+":{width:26,points:[[13,18],[13,0],[-1,-1],[4,9],[22,9]]},",":{width:10,points:[[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"-":{width:26,points:[[4,9],[22,9]]},".":{width:10,points:[[5,2],[4,1],[5,0],[6,1],[5,2]]},"/":{width:22,points:[[20,25],[2,-7]]},0:{width:20,points:[[9,21],[6,20],[4,17],[3,12],[3,9],[4,4],[6,1],[9,0],[11,0],[14,1],[16,4],[17,9],[17,12],[16,17],[14,20],[11,21],[9,21]]},1:{width:20,points:[[6,17],[8,18],[11,21],[11,0]]},2:{width:20,points:[[4,16],[4,17],[5,19],[6,20],[8,21],[12,21],[14,20],[15,19],[16,17],[16,15],[15,13],[13,10],[3,0],[17,0]]},3:{width:20,points:[[5,21],[16,21],[10,13],[13,13],[15,12],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},4:{width:20,points:[[13,21],[3,7],[18,7],[-1,-1],[13,21],[13,0]]},5:{width:20,points:[[15,21],[5,21],[4,12],[5,13],[8,14],[11,14],[14,13],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},6:{width:20,points:[[16,18],[15,20],[12,21],[10,21],[7,20],[5,17],[4,12],[4,7],[5,3],[7,1],[10,0],[11,0],[14,1],[16,3],[17,6],[17,7],[16,10],[14,12],[11,13],[10,13],[7,12],[5,10],[4,7]]},7:{width:20,points:[[17,21],[7,0],[-1,-1],[3,21],[17,21]]},8:{width:20,points:[[8,21],[5,20],[4,18],[4,16],[5,14],[7,13],[11,12],[14,11],[16,9],[17,7],[17,4],[16,2],[15,1],[12,0],[8,0],[5,1],[4,2],[3,4],[3,7],[4,9],[6,11],[9,12],[13,13],[15,14],[16,16],[16,18],[15,20],[12,21],[8,21]]},9:{width:20,points:[[16,14],[15,11],[13,9],[10,8],[9,8],[6,9],[4,11],[3,14],[3,15],[4,18],[6,20],[9,21],[10,21],[13,20],[15,18],[16,14],[16,9],[15,4],[13,1],[10,0],[8,0],[5,1],[4,3]]},":":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},";":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"<":{width:24,points:[[20,18],[4,9],[20,0]]},"=":{width:26,points:[[4,12],[22,12],[-1,-1],[4,6],[22,6]]},">":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function 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;T<y.length;T++){u=0,f=(c=y[T]).length;for(var E=0;E<f;E++)if(p=da[c.charAt(E)]){A=1,d=-1,v=-1,h=p.points.length;for(var b=0;b<h;b++)-1!==(I=p.points[b])[0]||-1!==I[1]?(s.push(u+I[0]*a*g+n),s.push(w+I[1]*a*g+r),s.push(0+i),-1===d?d=m:(-1===v||(d=v),v=m),m++,A?A=!1:(o.push(d),o.push(v))):A=1;u+=p.width*g*a}w-=35*g*a}return ae.apply(e,{primitive:"lines",positions:s,indices:o})}var ha=function(e){I(n,z);var t=m(n);function n(e,r){var i;b(this,n),r=r||{},i=t.call(this,"AxisGizmo",e,r);var a=e.scene.camera;r.canvasId||r.canvasElement||i.error("Config expected: either 'canvasId' or 'canvasElement'");try{i._axisGizmoScene=new ar(e,{canvasId:r.canvasId,canvasElement:r.canvasElement,transparent:!0})}catch(e){return i.error(e),w(i)}var s=i._axisGizmoScene;s.clearLights(),new nn(s,{color:[.45,.45,.5],intensity:.9}),new tn(s,{dir:[-.5,.5,-.6],color:[.8,.8,.7],intensity:1,space:"view"}),new tn(s,{dir:[.5,-.5,-.6],color:[.8,.8,.8],intensity:1,space:"view"});var o=s.camera;a.on("matrix",(function(){var e=a.eye,t=a.look,n=a.up,r=Z.mulVec3Scalar(Z.normalizeVec3(Z.subVec3(e,t,[])),22);o.look=[0,0,0],o.eye=r,o.up=n}));var l=new vn(s,pa({radiusTop:.01,radiusBottom:.6,height:1.7,radialSegments:20,heightSegments:1,openEnded:!1})),u=new vn(s,pa({radiusTop:.2,radiusBottom:.2,height:4.5,radialSegments:20,heightSegments:1,openEnded:!1})),c=new wn(s,{diffuse:[1,.3,.3],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),f=new wn(s,{emissive:[1,.3,.3],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),p=new wn(s,{diffuse:[.3,1,.3],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),A=new wn(s,{emissive:[.3,1,.3],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),d=new wn(s,{diffuse:[.3,.3,1],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),v=new wn(s,{emissive:[.3,.3,1],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),h=new wn(s,{diffuse:[.5,.5,.5],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2});return i._meshes=[new ca(s,{geometry:new vn(s,Aa({radius:9,heightSegments:60,widthSegments:60})),material:new wn(s,{diffuse:[0,0,0],emissive:[.1,.1,.1],ambient:[.1,.1,.2],specular:[0,0,0],alpha:.4,alphaMode:"blend",frontface:"cw"}),pickable:!1,collidable:!1,visible:!1!==r.visible}),new ca(s,{geometry:new vn(s,Aa({radius:1})),material:h,pickable:!1,collidable:!1,visible:!1!==r.visible}),new ca(s,{geometry:l,material:c,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[5,0,0],rotation:[0,0,-90]}),new ca(s,{geometry:u,material:c,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[2,0,0],rotation:[0,0,90]}),new ca(s,{geometry:new vn(s,va({text:"X",size:1.5})),material:f,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[7,0,0],billboard:"spherical"}),new ca(s,{geometry:l,material:p,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[0,5,0]}),new ca(s,{geometry:u,material:p,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[0,2,0]}),new ca(s,{geometry:new vn(s,va({text:"Y",size:1.5})),material:A,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[0,7,0],billboard:"spherical"}),new ca(s,{geometry:l,material:d,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[0,0,5],rotation:[90,0,0]}),new ca(s,{geometry:u,material:d,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[0,0,2],rotation:[90,0,0]}),new ca(s,{geometry:new vn(s,va({text:"Z",size:1.5})),material:v,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[0,0,7],billboard:"spherical"})],i}return P(n,[{key:"setVisible",value:function(e){for(var t=0;t<this._meshes.length;t++)this._meshes[t].visible=e}},{key:"destroy",value:function(){this._axisGizmoCanvas=null,this._axisGizmoScene.destroy(),this._axisGizmoScene=null,v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Ia=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({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;s<o;s++)r.addChild(a[s],i.inheritStates);if(i.parentId){var l=r.scene.components[i.parentId];l?l.isNode?l.addChild(g(r)):r.error("Parent is not a Node: '"+i.parentId+"'"):r.error("Parent not found: '"+i.parentId+"'")}else i.parent&&(i.parent.isNode||r.error("Parent is not a Node"),i.parent.addChild(g(r)));return r}return P(n,[{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._origin},set:function(e){e?(this._origin||(this._origin=Z.vec3()),this._origin.set(e)):this._origin&&(this._origin=null);for(var t=0,n=this._children.length;t<n;t++)this._children[t].origin=e;this.glRedraw()}},{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._visible},set:function(e){e=!1!==e,this._visible=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].visible=e;this._isObject&&this.scene._objectVisibilityUpdated(this,e)}},{key:"xrayed",get:function(){return this._xrayed},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].xrayed=e;this._isObject&&this.scene._objectXRayedUpdated(this,e)}},{key:"highlighted",get:function(){return this._highlighted},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].highlighted=e;this._isObject&&this.scene._objectHighlightedUpdated(this,e)}},{key:"selected",get:function(){return this._selected},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].selected=e;this._isObject&&this.scene._objectSelectedUpdated(this,e)}},{key:"edges",get:function(){return this._edges},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].edges=e}},{key:"culled",get:function(){return this._culled},set:function(e){e=!!e,this._culled=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].culled=e}},{key:"clippable",get:function(){return this._clippable},set:function(e){e=!1!==e,this._clippable=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].clippable=e}},{key:"collidable",get:function(){return this._collidable},set:function(e){e=!1!==e,this._collidable=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].collidable=e}},{key:"pickable",get:function(){return this._pickable},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].pickable=e}},{key:"colorize",get:function(){return this._colorize.slice(0,3)},set:function(e){var t=this._colorize;t||((t=this._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);for(var n=0,r=this._children.length;n<r;n++)this._children[n].colorize=t;if(this._isObject){var i=!!e;this.scene._objectColorizeUpdated(this,i)}}},{key:"opacity",get:function(){return this._colorize[3]},set:function(e){var t=this._colorize;t||((t=this._colorize=new Float32Array(4))[0]=1,t[1]=1,t[2]=1),t[3]=null!=e?e:1;for(var n=0,r=this._children.length;n<r;n++)this._children[n].opacity=e;if(this._isObject){var i=null!=e;this.scene._objectOpacityUpdated(this,i)}}},{key:"castsShadow",get:function(){return this._castsShadow},set:function(e){e=!!e,this._castsShadow=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].castsShadow=e}},{key:"receivesShadow",get:function(){return this._receivesShadow},set:function(e){e=!!e,this._receivesShadow=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].receivesShadow=e}},{key:"saoEnabled",get:function(){return!1}},{key:"offset",get:function(){return this._offset},set:function(e){e?(this._offset[0]=e[0],this._offset[1]=e[1],this._offset[2]=e[2]):(this._offset[0]=0,this._offset[1]=0,this._offset[2]=0);for(var t=0,n=this._children.length;t<n;t++)this._children[t].offset=this._offset;this._isObject&&this.scene._objectOffsetUpdated(this,e)}},{key:"isNode",get:function(){return!0}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}},{key:"_setWorldMatrixDirty",value:function(){this._worldMatrixDirty=!0;for(var e=0,t=this._children.length;e<t;e++)this._children[e]._setWorldMatrixDirty()}},{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;t<n;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}},{key:"_setSubtreeAABBsDirty",value:function(e){if(e._aabbDirty=!0,e._children)for(var t=0,n=e._children.length;t<n;t++)this._setSubtreeAABBsDirty(e._children[t])}},{key:"_setAABBDirty",value:function(){if(this._setSubtreeAABBsDirty(this),this.collidable)for(var e=this;e;e=e._parentNode)e._aabbDirty=!0}},{key:"_updateAABB",value:function(){if(this.scene._aabbDirty=!0,this._aabb||(this._aabb=Z.AABB3()),this._buildAABB)this._buildAABB(this.worldMatrix,this._aabb);else{var e;Z.collapseAABB3(this._aabb);for(var t=0,n=this._children.length;t<n;t++)(e=this._children[t]).collidable&&Z.expandAABB3(this._aabb,e.aabb)}this._aabbDirty=!1}},{key:"addChild",value:function(e,t){if(ae.isNumeric(e)||ae.isString(e)){var n=e;if(!(e=this.scene.component[n]))return void this.warn("Component not found: "+ae.inQuotes(n));if(!e.isNode&&!e.isMesh)return void this.error("Not a Node or Mesh: "+n)}else{if(!e.isNode&&!e.isMesh)return void this.error("Not a Node or Mesh: "+e.id);if(e._parentNode){if(e._parentNode.id===this.id)return void this.warn("Already a child: "+e.id);e._parentNode.removeChild(e)}}if(e.id,e.scene.id===this.scene.id)return this._children.push(e),e._parentNode=this,t&&(e.visible=this.visible,e.culled=this.culled,e.xrayed=this.xrayed,e.highlited=this.highlighted,e.selected=this.selected,e.edges=this.edges,e.clippable=this.clippable,e.pickable=this.pickable,e.collidable=this.collidable,e.castsShadow=this.castsShadow,e.receivesShadow=this.receivesShadow,e.colorize=this.colorize,e.opacity=this.opacity,e.offset=this.offset),e._setWorldMatrixDirty(),e._setAABBDirty(),this._numTriangles+=e.numTriangles,e;this.error("Child not in same Scene: "+e.id)}},{key:"removeChild",value:function(e){for(var t=0,n=this._children.length;t<n;t++)if(this._children[t].id===e.id)return e._parentNode=null,this._children=this._children.splice(t,1),e._setWorldMatrixDirty(),e._setAABBDirty(),this._setAABBDirty(),void(this._numTriangles-=e.numTriangles)}},{key:"removeChildren",value:function(){for(var e,t=0,n=this._children.length;t<n;t++)(e=this._children[t])._parentNode=null,e._setWorldMatrixDirty(),e._setAABBDirty(),this._numTriangles-=e.numTriangles;this._children=[],this._setAABBDirty()}},{key:"numChildren",get:function(){return this._children.length}},{key:"children",get:function(){return this._children}},{key:"parent",get:function(){return this._parentNode},set:function(e){if(ae.isNumeric(e)||ae.isString(e)){var t=e;if(!(e=this.scene.components[t]))return void this.warn("Node not found: "+ae.inQuotes(t));if(!e.isNode)return void this.error("Not a Node: "+e.id)}e.scene.id===this.scene.id?this._parentNode&&this._parentNode.id===e.id?this.warn("Already a child of Node: "+e.id):e.addChild(this):this.error("Node not in same Scene: "+e.id)}},{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||Pa),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:"rotate",value:function(e,t){return ya[0]=e[0],ya[1]=e[1],ya[2]=e[2],ya[3]=t*Z.DEGTORAD,Z.angleAxisToQuaternion(ya,ma),Z.mulQuaternions(this.quaternion,ma,wa),this.quaternion=wa,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return ya[0]=e[0],ya[1]=e[1],ya[2]=e[2],ya[3]=t*Z.DEGTORAD,Z.angleAxisToQuaternion(ya,ma),Z.mulQuaternions(ma,this.quaternion,ma),this}},{key:"rotateX",value:function(e){return this.rotate(ga,e)}},{key:"rotateY",value:function(e){return this.rotate(Ta,e)}},{key:"rotateZ",value:function(e){return this.rotate(Ea,e)}},{key:"translate",value:function(e,t){return Z.vec3ApplyQuaternion(this.quaternion,e,ba),Z.mulVec3Scalar(ba,t,Da),Z.addVec3(this.position,Da,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"translateX",value:function(e){return this.translate(ga,e)}},{key:"translateY",value:function(e){return this.translate(Ta,e)}},{key:"translateZ",value:function(e){return this.translate(Ea,e)}},{key:"type",get:function(){return"Node"}},{key:"destroy",value:function(){if(v(T(n.prototype),"destroy",this).call(this),this._parentNode&&this._parentNode.removeChild(this),this._isObject&&(this.scene._deregisterObject(this),this._visible&&this.scene._objectVisibilityUpdated(this,!1,!1),this._xrayed&&this.scene._objectXRayedUpdated(this,!1,!1),this._selected&&this.scene._objectSelectedUpdated(this,!1,!1),this._highlighted&&this.scene._objectHighlightedUpdated(this,!1,!1),this.scene._objectColorizeUpdated(this,!1),this.scene._objectOpacityUpdated(this,!1),this.offset.some((function(e){return 0!==e}))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length)for(var e=this._children.splice(),t=0,r=e.length;t<r;t++)e[t].destroy();this._children=[],this._setAABBDirty(),this.scene._aabbDirty=!0}}]),n}(),Ca=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:"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;r<i;r++)t.texImage2D(n[r],0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,Ma);else t.texImage2D(this.target,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,Ma);t.bindTexture(this.target,null)}},{key:"setTarget",value:function(e){this.target=e||this.gl.TEXTURE_2D}},{key:"setImage",value:function(e){var t=arguments.length>1&&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;I<y;I++)n.texImage2D(h[I],0,d,p,A,v[I])}else n.texImage2D(n.TEXTURE_2D,0,d,p,A,e);r&&n.generateMipmap(this.target),n.bindTexture(this.target,null),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,i),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a),n.pixelStorei(n.UNPACK_ALIGNMENT,s),n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,o)}},{key:"setCompressedData",value:function(e){var t=e.mipmaps,n=e.props,r=void 0===n?{}:n,i=this.gl,a=t.length;void 0!==r.format&&(this.format=r.format),void 0!==r.internalFormat&&(this.internalFormat=r.internalFormat),void 0!==r.encoding&&(this.encoding=r.encoding),void 0!==r.type&&(this.type=r.type),void 0!==r.flipY&&(this.flipY=r.flipY),void 0!==r.premultiplyAlpha&&(this.premultiplyAlpha=r.premultiplyAlpha),void 0!==r.unpackAlignment&&(this.unpackAlignment=r.unpackAlignment),void 0!==r.minFilter&&(this.minFilter=r.minFilter),void 0!==r.magFilter&&(this.magFilter=r.magFilter),void 0!==r.wrapS&&(this.wrapS=r.wrapS),void 0!==r.wrapT&&(this.wrapT=r.wrapT),void 0!==r.wrapR&&(this.wrapR=r.wrapR),i.activeTexture(i.TEXTURE0+0),i.bindTexture(this.target,this.texture);var s=t.length>1;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;A<d;A++){var v=t[A];1023!==this.format?null!==c?i.compressedTexSubImage2D(i.TEXTURE_2D,A,0,0,v.width,v.height,c,v.data):console.warn("Attempt to load unsupported compressed texture format in .setCompressedData()"):i.texSubImage2D(i.TEXTURE_2D,A,0,0,v.width,v.height,c,f,v.data)}i.bindTexture(this.target,null)}},{key:"setProps",value:function(e){var t=this.gl;t.bindTexture(this.target,this.texture),this._uploadProps(e),t.bindTexture(this.target,null)}},{key:"_uploadProps",value:function(e){var t=this.gl;if(void 0!==e.format&&(this.format=e.format),void 0!==e.internalFormat&&(this.internalFormat=e.internalFormat),void 0!==e.encoding&&(this.encoding=e.encoding),void 0!==e.type&&(this.type=e.type),void 0!==e.minFilter){var n=xa(t,e.minFilter);n&&(this.minFilter=e.minFilter,t.texParameteri(this.target,t.TEXTURE_MIN_FILTER,n),n!==t.NEAREST_MIPMAP_NEAREST&&n!==t.LINEAR_MIPMAP_NEAREST&&n!==t.NEAREST_MIPMAP_LINEAR&&n!==t.LINEAR_MIPMAP_LINEAR||t.generateMipmap(this.target))}if(void 0!==e.magFilter){var r=xa(t,e.magFilter);r&&(this.magFilter=e.magFilter,t.texParameteri(this.target,t.TEXTURE_MAG_FILTER,r))}if(void 0!==e.wrapS){var i=xa(t,e.wrapS);i&&(this.wrapS=e.wrapS,t.texParameteri(this.target,t.TEXTURE_WRAP_S,i))}if(void 0!==e.wrapT){var a=xa(t,e.wrapT);a&&(this.wrapT=e.wrapT,t.texParameteri(this.target,t.TEXTURE_WRAP_T,a))}}},{key:"bind",value:function(e){if(this.allocated){if(this.texture){var t=this.gl;return t.activeTexture(t["TEXTURE"+e]),t.bindTexture(this.target,this.texture),!0}return!1}}},{key:"unbind",value:function(e){if(this.allocated&&this.texture){var t=this.gl;t.activeTexture(t["TEXTURE"+e]),t.bindTexture(this.target,null)}}},{key:"destroy",value:function(){this.allocated&&this.texture&&(this.gl.deleteTexture(this.texture),this.texture=null)}}]),e}();function Ha(e,t,n,r,i){var a=arguments.length>5&&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;c<a.i_verts.length;c++)u[c]=c;i.processes--,n(ae.apply(t,{primitive:"triangles",positions:s,normals:o.length>0?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;a<g;a++){var _=a*E-I;for(s=0;s<w;s++)o=s*T-h,b[R]=o+A,b[R+1]=d,b[R+2]=-_+v,D[R+2]=-1,P[C]=s/y,P[C+1]=(m-a)/m,R+=3,C+=2}R=0;var B=new(b.length/3>65535?Uint32Array:Uint16Array)(y*m*6);for(a=0;a<m;a++)for(s=0;s<y;s++)l=s+w*a,u=s+w*(a+1),c=s+1+w*(a+1),f=s+1+w*a,B[R]=f,B[R+1]=u,B[R+2]=l,B[R+3]=f,B[R+4]=c,B[R+5]=u,R+=6;return ae.apply(e,{positions:b,normals:D,uv:P,indices:B})}function es(){var e=arguments.length>0&&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;r<t.length;r++)n=n.concat(String.fromCharCode(t[r]));return n},Ya.parse._strToBuff=function(e){for(var t=new ArrayBuffer(e.length),n=new Uint8Array(t),r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return t},Ya.parse._readLine=function(e,t){for(var n="";10!=e[t];)n+=String.fromCharCode(e[t++]);return n},Ya.parse.fromJSON=function(e){return JSON.parse(Ya.parse._buffToStr(e))},Ya.parse.toJSON=function(e){var t=JSON.stringify(e);return Ya.parse._strToBuff(t)},Ya.parse.fromOBJ=function(e){for(var t={groups:{},c_verts:[],c_uvt:[],c_norms:[],i_verts:[],i_uvt:[],i_norms:[]},n={from:0,to:0},r=0,i=new Uint8Array(e);r<i.length;){var a=Ya.parse._readLine(i,r);r+=a.length+1;var s=(a=(a=a.replace(/ +(?= )/g,"")).replace(/(^\s+|\s+$)/g,"")).split(" ");if("g"==s[0]&&(n.to=t.i_verts.length,null==t.groups[s[1]]&&(t.groups[s[1]]={from:t.i_verts.length,to:0}),n=t.groups[s[1]]),"v"==s[0]){var o=parseFloat(s[1]),l=parseFloat(s[2]),u=parseFloat(s[3]);t.c_verts.push(o,l,u)}if("vt"==s[0]){o=parseFloat(s[1]),l=1-parseFloat(s[2]);t.c_uvt.push(o,l)}if("vn"==s[0]){o=parseFloat(s[1]),l=parseFloat(s[2]),u=parseFloat(s[3]);t.c_norms.push(o,l,u)}if("f"==s[0]){var c=s[1].split("/"),f=s[2].split("/"),p=s[3].split("/"),A=parseInt(c[0])-1,d=parseInt(f[0])-1,v=parseInt(p[0])-1,h=parseInt(c[1])-1,I=parseInt(f[1])-1,y=parseInt(p[1])-1,m=parseInt(c[2])-1,w=parseInt(f[2])-1,g=parseInt(p[2])-1,T=t.c_verts.length/3,E=t.c_uvt.length/2,b=t.c_norms.length/3;if(A<0&&(A=T+A+1),d<0&&(d=T+d+1),v<0&&(v=T+v+1),h<0&&(h=E+h+1),I<0&&(I=E+I+1),y<0&&(y=E+y+1),m<0&&(m=b+m+1),w<0&&(w=b+w+1),g<0&&(g=b+g+1),t.i_verts.push(A,d,v),t.i_uvt.push(h,I,y),t.i_norms.push(m,w,g),5==s.length){var D=s[4].split("/"),P=parseInt(D[0])-1,R=parseInt(D[1])-1,C=parseInt(D[2])-1;P<0&&(P=T+P+1),R<0&&(R=E+R+1),C<0&&(C=b+C+1),t.i_verts.push(A,v,P),t.i_uvt.push(h,y,R),t.i_norms.push(m,g,C)}}}return n.to=t.i_verts.length,t},Ya.parse.fromMD2=function(e){e=new Uint8Array(e);var t={},n={};n.ident=Ya.bin.ril(e,0),n.version=Ya.bin.ril(e,4),n.skinwidth=Ya.bin.ril(e,8),n.skinheight=Ya.bin.ril(e,12),n.framesize=Ya.bin.ril(e,16),n.num_skins=Ya.bin.ril(e,20),n.num_vertices=Ya.bin.ril(e,24),n.num_st=Ya.bin.ril(e,28),n.num_tris=Ya.bin.ril(e,32),n.num_glcmds=Ya.bin.ril(e,36),n.num_frames=Ya.bin.ril(e,40),n.offset_skins=Ya.bin.ril(e,44),n.offset_st=Ya.bin.ril(e,48),n.offset_tris=Ya.bin.ril(e,52),n.offset_frames=Ya.bin.ril(e,56),n.offset_glcmds=Ya.bin.ril(e,60),n.offset_end=Ya.bin.ril(e,64);var r=n.offset_st;t.c_uvt=[];for(var i=0;i<n.num_st;i++){var a=Ya.bin.rsl(e,r)/n.skinwidth,s=Ya.bin.rsl(e,r+2)/n.skinheight;t.c_uvt.push(a,s),r+=4}r=n.offset_tris;var o=[],l=[];t.i_verts=o,t.i_uvt=l;for(i=0;i<n.num_tris;i++)o.push(Ya.bin.rsl(e,r),Ya.bin.rsl(e,r+2),Ya.bin.rsl(e,r+4)),l.push(Ya.bin.rsl(e,r+6),Ya.bin.rsl(e,r+8),Ya.bin.rsl(e,r+10)),r+=12;r=n.offset_skins;t.skins=[];for(i=0;i<n.num_skins;i++)t.skins.push(Ya.bin.rASCII0(e,r)),r+=64;r=n.offset_frames;t.frames=[];var u=Ya.parse.fromMD2._normals;for(i=0;i<n.num_frames;i++){var c={},f=Ya.bin.rf(e,r),p=Ya.bin.rf(e,r+4),A=Ya.bin.rf(e,r+8);r+=12;var d=Ya.bin.rf(e,r),v=Ya.bin.rf(e,r+4),h=Ya.bin.rf(e,r+8);r+=12,c.name=Ya.bin.rASCII0(e,r),r+=16,c.verts=[],c.norms=[];for(var I=0;I<n.num_vertices;I++)c.verts.push(e[r]*f+d,e[r+1]*p+v,e[r+2]*A+h),c.norms.push(u[3*e[r+3]],u[3*e[r+3]+1],u[3*e[r+3]+2]),r+=4;t.frames.push(c)}return t},Ya.parse.fromMD2._normals=[-.525731,0,.850651,-.442863,.238856,.864188,-.295242,0,.955423,-.309017,.5,.809017,-.16246,.262866,.951056,0,0,1,0,.850651,.525731,-.147621,.716567,.681718,.147621,.716567,.681718,0,.525731,.850651,.309017,.5,.809017,.525731,0,.850651,.295242,0,.955423,.442863,.238856,.864188,.16246,.262866,.951056,-.681718,.147621,.716567,-.809017,.309017,.5,-.587785,.425325,.688191,-.850651,.525731,0,-.864188,.442863,.238856,-.716567,.681718,.147621,-.688191,.587785,.425325,-.5,.809017,.309017,-.238856,.864188,.442863,-.425325,.688191,.587785,-.716567,.681718,-.147621,-.5,.809017,-.309017,-.525731,.850651,0,0,.850651,-.525731,-.238856,.864188,-.442863,0,.955423,-.295242,-.262866,.951056,-.16246,0,1,0,0,.955423,.295242,-.262866,.951056,.16246,.238856,.864188,.442863,.262866,.951056,.16246,.5,.809017,.309017,.238856,.864188,-.442863,.262866,.951056,-.16246,.5,.809017,-.309017,.850651,.525731,0,.716567,.681718,.147621,.716567,.681718,-.147621,.525731,.850651,0,.425325,.688191,.587785,.864188,.442863,.238856,.688191,.587785,.425325,.809017,.309017,.5,.681718,.147621,.716567,.587785,.425325,.688191,.955423,.295242,0,1,0,0,.951056,.16246,.262866,.850651,-.525731,0,.955423,-.295242,0,.864188,-.442863,.238856,.951056,-.16246,.262866,.809017,-.309017,.5,.681718,-.147621,.716567,.850651,0,.525731,.864188,.442863,-.238856,.809017,.309017,-.5,.951056,.16246,-.262866,.525731,0,-.850651,.681718,.147621,-.716567,.681718,-.147621,-.716567,.850651,0,-.525731,.809017,-.309017,-.5,.864188,-.442863,-.238856,.951056,-.16246,-.262866,.147621,.716567,-.681718,.309017,.5,-.809017,.425325,.688191,-.587785,.442863,.238856,-.864188,.587785,.425325,-.688191,.688191,.587785,-.425325,-.147621,.716567,-.681718,-.309017,.5,-.809017,0,.525731,-.850651,-.525731,0,-.850651,-.442863,.238856,-.864188,-.295242,0,-.955423,-.16246,.262866,-.951056,0,0,-1,.295242,0,-.955423,.16246,.262866,-.951056,-.442863,-.238856,-.864188,-.309017,-.5,-.809017,-.16246,-.262866,-.951056,0,-.850651,-.525731,-.147621,-.716567,-.681718,.147621,-.716567,-.681718,0,-.525731,-.850651,.309017,-.5,-.809017,.442863,-.238856,-.864188,.16246,-.262866,-.951056,.238856,-.864188,-.442863,.5,-.809017,-.309017,.425325,-.688191,-.587785,.716567,-.681718,-.147621,.688191,-.587785,-.425325,.587785,-.425325,-.688191,0,-.955423,-.295242,0,-1,0,.262866,-.951056,-.16246,0,-.850651,.525731,0,-.955423,.295242,.238856,-.864188,.442863,.262866,-.951056,.16246,.5,-.809017,.309017,.716567,-.681718,.147621,.525731,-.850651,0,-.238856,-.864188,-.442863,-.5,-.809017,-.309017,-.262866,-.951056,-.16246,-.850651,-.525731,0,-.716567,-.681718,-.147621,-.716567,-.681718,.147621,-.525731,-.850651,0,-.5,-.809017,.309017,-.238856,-.864188,.442863,-.262866,-.951056,.16246,-.864188,-.442863,.238856,-.809017,-.309017,.5,-.688191,-.587785,.425325,-.681718,-.147621,.716567,-.442863,-.238856,.864188,-.587785,-.425325,.688191,-.309017,-.5,.809017,-.147621,-.716567,.681718,-.425325,-.688191,.587785,-.16246,-.262866,.951056,.442863,-.238856,.864188,.16246,-.262866,.951056,.309017,-.5,.809017,.147621,-.716567,.681718,0,-.525731,.850651,.425325,-.688191,.587785,.587785,-.425325,.688191,.688191,-.587785,.425325,-.955423,.295242,0,-.951056,.16246,.262866,-1,0,0,-.850651,0,.525731,-.955423,-.295242,0,-.951056,-.16246,.262866,-.864188,.442863,-.238856,-.951056,.16246,-.262866,-.809017,.309017,-.5,-.864188,-.442863,-.238856,-.951056,-.16246,-.262866,-.809017,-.309017,-.5,-.681718,.147621,-.716567,-.681718,-.147621,-.716567,-.850651,0,-.525731,-.688191,.587785,-.425325,-.587785,.425325,-.688191,-.425325,.688191,-.587785,-.425325,-.688191,-.587785,-.587785,-.425325,-.688191,-.688191,-.587785,-.425325],Ya.parse.fromCollada=function(e){var t=Ya.parse._buffToStr(e),n=(new DOMParser).parseFromString(t,"text/xml"),r={},i=(n=n.childNodes[0]).getElementsByTagName("asset")[0],a=n.getElementsByTagName("library_geometries")[0],s=n.getElementsByTagName("library_images")[0],o=n.getElementsByTagName("library_materials")[0],l=n.getElementsByTagName("library_effects")[0];return i&&(r.asset=Ya.parse.fromCollada._asset(i)),a&&(r.geometries=Ya.parse.fromCollada._libGeometries(a)),s&&(r.images=Ya.parse.fromCollada._libImages(s)),o&&(r.materials=Ya.parse.fromCollada._libMaterials(o)),l&&(r.effects=Ya.parse.fromCollada._libEffects(l)),r},Ya.parse.fromCollada._asset=function(e){return{created:e.getElementsByTagName("created")[0].textContent,modified:e.getElementsByTagName("modified")[0].textContent,up_axis:e.getElementsByTagName("up_axis")[0].textContent}},Ya.parse.fromCollada._libGeometries=function(e){e=e.getElementsByTagName("geometry");for(var t=[],n=0;n<e.length;n++){var r=e[n],i=Ya.parse.fromCollada._getMesh(r.getElementsByTagName("mesh")[0]);t.push(i)}return t},Ya.parse.fromCollada._getMesh=function(e){for(var t={},n=e.getElementsByTagName("source"),r=t.sources={},i=0;i<n.length;i++){for(var a=n[i].getElementsByTagName("float_array")[0].textContent.split(" "),s=a.length-(""==a[a.length-1]?1:0),o=new Array(s),l=0;l<s;l++)o[l]=parseFloat(a[l]);r[n[i].getAttribute("id")]=o}t.triangles=[];var u=e.getElementsByTagName("triangles");if(null==u)return t;for(i=0;i<u.length;i++){var c={},f=u[i];c.material=f.getAttribute("material");var p=f.getElementsByTagName("input"),A=[];for(l=0;l<p.length;l++){var d=p[l];o=[];A[parseInt(d.getAttribute("offset"))]=o;var v=d.getAttribute("semantic");c["s_"+v]="VERTEX"==v?e.getElementsByTagName("vertices")[0].getElementsByTagName("input")[0].getAttribute("source").substring(1):d.getAttribute("source").substring(1),c["i_"+v]=o,r[c["s_"+v]]}var h=f.getElementsByTagName("p")[0].textContent.split(" "),I=3*Math.floor(h.length/3);for(l=0;l<I;l++)A[l%p.length].push(parseInt(h[l]));t.triangles.push(c)}return t},Ya.parse.fromCollada._libImages=function(e){e=e.getElementsByTagName("image");for(var t={},n=0;n<e.length;n++)t[e[n].getAttribute("id")]=e[n].getElementsByTagName("init_from")[0].textContent;return t},Ya.parse.fromCollada._libMaterials=function(e){e=e.getElementsByTagName("material");for(var t={},n=0;n<e.length;n++)t[e[n].getAttribute("name")]=e[n].getElementsByTagName("instance_effect")[0].getAttribute("url").substring(1);return t},Ya.parse.fromCollada._libEffects=function(e){e=e.getElementsByTagName("effect");for(var t={},n=0;n<e.length;n++){for(var r={},i=e[n].getElementsByTagName("newparam"),a=0;a<i.length;a++){var s=i[a].getElementsByTagName("surface")[0];s&&(r.surface=s.getElementsByTagName("init_from")[0].textContent)}t[e[n].getAttribute("id")]=r}return t},Ya.parse.from3DS=function(e){e=new Uint8Array(e);var t={};if(19789!=Ya.bin.rsl(e,0))return null;for(var n=Ya.bin.ril(e,2),r=6;r<n;){var i=Ya.bin.rsl(e,r),a=Ya.bin.ril(e,r+2);15677==i&&(t.edit=Ya.parse.from3DS._edit3ds(e,r,a)),45056==i&&(t.keyf=Ya.parse.from3DS._keyf3ds(e,r,a)),r+=a}return t},Ya.parse.from3DS._edit3ds=function(e,t,n){for(var r={},i=t+6;i<t+n;){var a=Ya.bin.rsl(e,i),s=Ya.bin.ril(e,i+2);16384==a&&(null==r.objects&&(r.objects=[]),r.objects.push(Ya.parse.from3DS._edit_object(e,i,s))),i+=s}return r},Ya.parse.from3DS._keyf3ds=function(e,t,n){for(var r={},i=t+6;i<t+n;){var a=Ya.bin.rsl(e,i),s=Ya.bin.ril(e,i+2);45058==a&&(null==r.desc&&(r.desc=[]),r.desc.push(Ya.parse.from3DS._keyf_objdes(e,i,s))),i+=s}return r},Ya.parse.from3DS._keyf_objdes=function(e,t,n){for(var r={},i=t+6;i<t+n;){var a=Ya.bin.rsl(e,i),s=Ya.bin.ril(e,i+2);45072==a&&(r.hierarchy=Ya.parse.from3DS._keyf_objhierarch(e,i,s)),45073==a&&(r.dummy_name=Ya.bin.rASCII0(e,i+6)),i+=s}return r},Ya.parse.from3DS._keyf_objhierarch=function(e,t,n){var r={},i=t+6;return r.name=Ya.bin.rASCII0(e,i),i+=r.name.length+1,r.hierarchy=Ya.bin.rsl(e,i+4),r},Ya.parse.from3DS._edit_object=function(e,t,n){var r={},i=t+6;for(r.name=Ya.bin.rASCII0(e,i),i+=r.name.length+1;i<t+n;){var a=Ya.bin.rsl(e,i),s=Ya.bin.ril(e,i+2);16640==a&&(r.mesh=Ya.parse.from3DS._obj_trimesh(e,i,s)),i+=s}return r},Ya.parse.from3DS._obj_trimesh=function(e,t,n){for(var r={},i=t+6;i<t+n;){var a=Ya.bin.rsl(e,i),s=Ya.bin.ril(e,i+2);16656==a&&(r.vertices=Ya.parse.from3DS._tri_vertexl(e,i,s)),16672==a&&(r.indices=Ya.parse.from3DS._tri_facel1(e,i,s)),16704==a&&(r.uvt=Ya.parse.from3DS._tri_mappingcoors(e,i,s)),16736==a&&(r.local=Ya.parse.from3DS._tri_local(e,i,s)),i+=s}return r},Ya.parse.from3DS._tri_vertexl=function(e,t,n){var r=[],i=t+6,a=Ya.bin.rsl(e,i);i+=2;for(var s=0;s<a;s++)r.push(Ya.bin.rf(e,i)),r.push(Ya.bin.rf(e,i+4)),r.push(Ya.bin.rf(e,i+8)),i+=12;return r},Ya.parse.from3DS._tri_facel1=function(e,t,n){var r=[],i=t+6,a=Ya.bin.rsl(e,i);i+=2;for(var s=0;s<a;s++)r.push(Ya.bin.rsl(e,i)),r.push(Ya.bin.rsl(e,i+2)),r.push(Ya.bin.rsl(e,i+4)),i+=8;return r},Ya.parse.from3DS._tri_mappingcoors=function(e,t,n){var r=[],i=t+6,a=Ya.bin.rsl(e,i);i+=2;for(var s=0;s<a;s++)r.push(Ya.bin.rf(e,i)),r.push(1-Ya.bin.rf(e,i+4)),i+=8;return r},Ya.parse.from3DS._tri_local=function(e,t,n){var r={},i=t+6;return r.X=[Ya.bin.rf(e,i),Ya.bin.rf(e,i+4),Ya.bin.rf(e,i+8)],i+=12,r.Y=[Ya.bin.rf(e,i),Ya.bin.rf(e,i+4),Ya.bin.rf(e,i+8)],i+=12,r.Z=[Ya.bin.rf(e,i),Ya.bin.rf(e,i+4),Ya.bin.rf(e,i+8)],i+=12,r.C=[Ya.bin.rf(e,i),Ya.bin.rf(e,i+4),Ya.bin.rf(e,i+8)],i+=12,r},Ya.parse.fromBIV=function(e){e=new Uint8Array(e);var t={},n={};return n.id=Ya.bin.ril(e,0),n.verS=Ya.bin.ril(e,4),n.texS=Ya.bin.ril(e,8),n.indS=Ya.bin.ril(e,12),n.verO=Ya.bin.ril(e,16),n.verL=Ya.bin.ril(e,20),n.texO=Ya.bin.ril(e,24),n.texL=Ya.bin.ril(e,28),n.indO=Ya.bin.ril(e,32),n.indL=Ya.bin.ril(e,36),0!=n.verO&&(t.vertices=Ya.parse.fromBIV._readFloats(e,n.verO,n.verL)),0!=n.texO&&(t.uvt=Ya.parse.fromBIV._readFloats(e,n.texO,n.texL)),0!=n.indO&&(t.indices=Ya.parse.fromBIV._readInts(e,n.indO,n.indL,n.indS)),t},Ya.parse.toBIV=function(e){for(var t=0,n=0;n<e.indices.length;n++)t=Math.max(t,e.indices[n]);var r=32;t<=65535&&(r=16);var i=40;e.vertices&&(i+=4*e.vertices.length),e.uvt&&(i+=4*e.uvt.length),e.indices&&(i+=e.indices.length*r/8);var a=new Uint8Array(i);Ya.bin.wil(a,0,1769365870),Ya.bin.wil(a,4,32),Ya.bin.wil(a,8,32),Ya.bin.wil(a,12,r);var s=40;return e.vertices&&(Ya.bin.wil(a,16,s),Ya.bin.wil(a,20,4*e.vertices.length),Ya.parse.fromBIV._writeFloats(a,s,e.vertices),s+=4*e.vertices.length),e.uvt&&(Ya.bin.wil(a,24,s),Ya.bin.wil(a,28,4*e.uvt.length),Ya.parse.fromBIV._writeFloats(a,s,e.uvt),s+=4*e.uvt.length),e.indices&&(Ya.bin.wil(a,32,s),Ya.bin.wil(a,36,4*e.indices.length),Ya.parse.fromBIV._writeInts(a,s,e.indices,r)),a.buffer},Ya.parse.fromBIV._readFloats=function(e,t,n){for(var r=[],i=0;i<n/4;i++)r.push(Ya.bin.rf(e,t+4*i));return r},Ya.parse.fromBIV._writeFloats=function(e,t,n){for(var r=0;r<n.length;r++)Ya.bin.wf(e,t+4*r,n[r])},Ya.parse.fromBIV._readInts=function(e,t,n,r){for(var i=[],a=0;a<n/4;a++)16==r&&i.push(Ya.bin.rsl(e,t+2*a)),32==r&&i.push(Ya.bin.ril(e,t+4*a));return i},Ya.parse.fromBIV._writeInts=function(e,t,n,r){for(var i=0;i<n.length;i++)16==r&&Ya.bin.wsl(e,t+2*i,n[i]),32==r&&Ya.bin.wil(e,t+4*i,n[i])},Ya.gen={},Ya.gen.Plane=function(e,t,n,r){n||(n=1),r||(r=1);for(var i={verts:[],inds:[],uvt:[]},a=e+1,s=t+1,o=0;o<s;o++)for(var l=0;l<a;l++){var u=l*(2/e)-1,c=o*(2/t)-1;i.verts.push(u,c,0),i.uvt.push(n*l/e,r*o/t),o<t&&l<e&&i.inds.push(o*a+l,o*a+l+1,(o+1)*a+l,o*a+l+1,(o+1)*a+l,(o+1)*a+l+1)}return i},Ya.gen.Cube=function(){return{verts:[-1,1,-1,1,1,-1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,1,-1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,1,-1,1,-1,1,1,-1,-1,-1,1,-1,1,1,-1,-1,1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,1,-1,1],inds:[0,1,2,1,2,3,4,5,6,5,6,7,8,9,10,9,10,11,12,13,14,13,14,15,16,17,18,17,18,19,20,21,22,21,22,23],uvt:[1/4,1/4,.5,1/4,1/4,.5,.5,.5,1,1/4,3/4,1/4,1,.5,3/4,.5,0,1/4,1/4,1/4,0,.5,1/4,.5,3/4,1/4,.5,1/4,3/4,.5,.5,.5,1/4,1/4,.5,1/4,1/4,0,.5,0,1/4,.5,.5,.5,1/4,3/4,.5,3/4]}},Ya.gen.Sphere=function(e,t){for(var n={verts:[],inds:[],uvt:[]},r=e+1,i=t+1,a=0;a<i;a++)for(var s=0;s<r;s++){var o=-Math.PI/2+a*Math.PI/t,l=2*s*Math.PI/e,u=Math.cos(o)*Math.cos(l),c=Math.sin(o),f=Math.cos(o)*Math.sin(l);n.verts.push(u,c,f),n.uvt.push(s/e,a/t),a<t&&s<e&&n.inds.push(r*a+s,r*a+s+1,r*(a+1)+s,r*a+s+1,r*(a+1)+s,r*(a+1)+s+1)}return n},Ya.mat={},Ya.mat.scale=function(e,t,n){return[e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1]},Ya.mat.translate=function(e,t,n){return[1,0,0,0,0,1,0,0,0,0,1,0,e,t,n,1]},Ya.mat.rotateDeg=function(e,t,n){var r=Math.PI/180;return Ya.mat.rotate(e*r,t*r,n*r)},Ya.mat.rotate=function(e,t,n){var r=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],i=e,a=t,s=n,o=Math.cos(i),l=Math.cos(a),u=Math.cos(s),c=Math.sin(i),f=Math.sin(a),p=Math.sin(s);return r[0]=l*u,r[1]=-l*p,r[2]=f,r[4]=o*p+c*f*u,r[5]=o*u-c*f*p,r[6]=-c*l,r[8]=c*p-o*f*u,r[9]=c*u+o*f*p,r[10]=o*l,r},Ya.edit={},Ya.edit.interpolate=function(e,t,n,r){for(var i=0;i<e.length;i++)n[i]=e[i]+r*(t[i]-e[i])},Ya.edit.transform=function(e,t){for(var n=0;n<e.length;n+=3){var r=e[n],i=e[n+1],a=e[n+2];e[n+0]=t[0]*r+t[4]*i+t[8]*a+t[12],e[n+1]=t[1]*r+t[5]*i+t[9]*a+t[13],e[n+2]=t[2]*r+t[6]*i+t[10]*a+t[14]}},Ya.edit.unwrap=function(e,t,n){for(var r=new Array(Math.floor(e.length/3)*n),i=0;i<e.length;i++)for(var a=0;a<n;a++)r[i*n+a]=t[e[i]*n+a];return r},Ya.edit.remap=function(e,t,n,r){for(var i=new Array(n.length),a=0;a<e.length;a++)for(var s=0;s<r;s++)i[t[a]*r+s]=n[e[a]*r+s];return i},Ya.utils={},Ya.utils.getAABB=function(e){var t,n,r,i,a,s;i=a=s=-(t=n=r=999999999);for(var o=0;o<e.length;o+=3){var l=e[o+0],u=e[o+1],c=e[o+2];l<t&&(t=l),l>i&&(i=l),u<n&&(n=u),u>a&&(a=u),c<r&&(r=c),u>s&&(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;a<s;a+=2)r._indices.push(a),r._indices.push(a+1)}return r._mesh=new ca(g(r),{visible:i.visible,clippable:i.clippable,collidable:i.collidable,geometry:new Ka(g(r),{primitive:"lines",positions:r._positions,indices:r._indices,origin:i.origin}),material:new wn(g(r),{diffuse:i.color||[0,0,0],emissive:i.color||[0,0,0]})}),r.scene._lineSetCreated(g(r)),r}return P(n,[{key:"visible",get:function(){return this._mesh.visible},set:function(e){this._mesh.visible=e}},{key:"positions",get:function(){return this._positions}},{key:"indices",get:function(){return this._indices}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._lineSetDestroyed(this)}}]),n}(),rs=Z.vec3(),is=Z.vec3(),as=Z.vec3(),ss=Z.vec3(),os=function(e){I(n,z);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,"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;T<E;T++){var b=g[2*T],D=g[2*T+1];s.lines.push({start_point:{x:w[3*b+0],y:w[3*b+1],z:w[3*b+2]},end_point:{x:w[3*D+0],y:w[3*D+1],z:w[3*D+2]}})}}var P=n.bitmaps;for(var R in P)if(P.hasOwnProperty(R)){var C=P[R],_=C.pos,B=C.normal,O=C.up;r.yUp&&(_=cs(_),B=cs(B),O=cs(O)),Z.addVec3(_,i),s.bitmaps||(s.bitmaps=[]),s.bitmaps.push({bitmap_type:C.type,bitmap_data:C.imageData,location:ls(_),normal:ls(B),up:ls(O),height:C.height})}s.components={visibility:{view_setup_hints:{spaces_visible:!!t.spacesVisible,space_boundaries_visible:!!t.spaceBoundariesVisible,openings_visible:!!t.openingsVisible}}};var S=new Set(n.opacityObjectIds),N=new Set(n.xrayedObjectIds),L=new Set(n.colorizedObjectIds),x=Object.values(n.objects).filter((function(e){return S.has(e.id)||L.has(e.id)||N.has(e.id)})).reduce((function(t,r){var i,a=ps(r.colorize);r.xrayed?(i=0===n.xrayMaterial.fillAlpha&&0!==n.xrayMaterial.edgeAlpha?.1:n.xrayMaterial.fillAlpha,a=(i=Math.round(255*i).toString(16).padStart(2,"0"))+a):S.has(r.id)&&(a=(i=Math.round(255*r.opacity).toString(16).padStart(2,"0"))+a),t[a]||(t[a]=[]);var s=r.id,o=r.originalSystemId,l={ifc_guid:o,originating_system:e.originatingSystem};return o!==s&&(l.authoring_tool_id=s),t[a].push(l),t}),{}),M=Object.entries(x).map((function(e){var t=p(e,2);return{color:t[0],components:t[1]}}));s.components.coloring=M;var F=n.objectIds,H=n.visibleObjects,U=n.visibleObjectIds,G=F.filter((function(e){return!H[e]})),k=n.selectedObjectIds;return t.defaultInvisible||U.length<G.length?(s.components.visibility.exceptions=this._createBCFComponents(U),s.components.visibility.default_visibility=!1):(s.components.visibility.exceptions=this._createBCFComponents(G),s.components.visibility.default_visibility=!0),s.components.selection=this._createBCFComponents(k),!1!==t.snapshot&&(s.snapshot={snapshot_type:"png",snapshot_data:this.viewer.getSnapshot({format:"png"})}),s}},{key:"_createBCFComponents",value:function(e){for(var t=this.viewer.scene,n=[],r=0,i=e.length;r<i;r++){var a=e[r],s=t.objects[a];if(s){var o={ifc_guid:s.originalSystemId,originating_system:this.originatingSystem};s.originalSystemId!==a&&(o.authoring_tool_id=a),n.push(o)}}return n}},{key:"setViewpoint",value:function(e){var t=this,n=arguments.length>1&&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;I<y;I+=4)i[p]=l+Math.floor((1+r[I+0]/r[I+3])*c/2),i[p+1]=o+Math.floor((1-r[I+1]/r[I+3])*f/2),p+=2;if(this._originDot.setPos(i[0],i[1]),this._targetDot.setPos(i[6],i[7]),this._lengthWire.setStartAndEnd(i[0],i[1],i[6],i[7]),this._xAxisWire.setStartAndEnd(i[0],i[1],i[2],i[3]),this._yAxisWire.setStartAndEnd(i[2],i[3],i[4],i[5]),this._zAxisWire.setStartAndEnd(i[4],i[5],i[6],i[7]),this.labelsVisible){this._lengthLabel.setPosOnWire(i[0],i[1],i[6],i[7]),this._xAxisLabel.setPosOnWire(i[0],i[1],i[2],i[3]),this._yAxisLabel.setPosOnWire(i[2],i[3],i[4],i[5]),this._zAxisLabel.setPosOnWire(i[4],i[5],i[6],i[7]);var m=this._approximate?" ~ ":" = ";this._length=Math.abs(Z.lenVec3(Z.subVec3(this._targetWorld,this._originWorld,As))),this._lengthLabel.setText(m+(this._length*d).toFixed(2)+h);var w=Math.abs(ds(i[0],i[1],i[2],i[3])),g=Math.abs(ds(i[2],i[3],i[4],i[5])),T=Math.abs(ds(i[4],i[5],i[6],i[7])),E=this.plugin.labelMinAxisLength;this._xAxisLabelCulled=w<E,this._yAxisLabelCulled=g<E,this._zAxisLabelCulled=T<E,this._xAxisLabelCulled?this._xAxisLabel.setCulled(!0):(this._xAxisLabel.setText(m+Math.abs((this._targetWorld[0]-this._originWorld[0])*d).toFixed(2)+h),this._xAxisLabel.setCulled(!this.axisVisible)),this._yAxisLabelCulled?this._yAxisLabel.setCulled(!0):(this._yAxisLabel.setText(m+Math.abs((this._targetWorld[1]-this._originWorld[1])*d).toFixed(2)+h),this._yAxisLabel.setCulled(!this.axisVisible)),this._zAxisLabelCulled?this._zAxisLabel.setCulled(!0):(this._zAxisLabel.setText(m+Math.abs((this._targetWorld[2]-this._originWorld[2])*d).toFixed(2)+h),this._zAxisLabel.setCulled(!this.axisVisible))}else this._lengthLabel.setCulled(!0),this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0);this._originDot.setVisible(this._visible&&this._originVisible),this._targetDot.setVisible(this._visible&&this._targetVisible),this._xAxisWire.setVisible(this.axisVisible&&this.xAxisVisible),this._yAxisWire.setVisible(this.axisVisible&&this.yAxisVisible),this._zAxisWire.setVisible(this.axisVisible&&this.zAxisVisible),this._lengthWire.setVisible(this.wireVisible),this._lengthLabel.setCulled(!this.wireVisible),this._cpDirty=!1}}}},{key:"approximate",get:function(){return this._approximate},set:function(e){e=!1!==e,this._approximate!==e&&(this._approximate=e,this._cpDirty=!0,this._needUpdate(0))}},{key:"origin",get:function(){return this._originMarker}},{key:"target",get:function(){return this._targetMarker}},{key:"length",get:function(){this._update();var e=this.plugin.viewer.scene.metrics.scale;return this._length*e}},{key:"color",get:function(){return this._color},set:function(e){this._color=e,this._originDot.setFillColor(e),this._targetDot.setFillColor(e),this._lengthWire.setColor(e),this._lengthLabel.setFillColor(e)}},{key:"visible",get:function(){return this._visible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultVisible,this._visible=e,this._originDot.setVisible(this._visible&&this._originVisible),this._targetDot.setVisible(this._visible&&this._targetVisible),this._lengthWire.setVisible(this._visible&&this._wireVisible),this._lengthLabel.setVisible(this._visible&&this._wireVisible);var t=this._visible&&this._axisVisible&&this._xAxisVisible,n=this._visible&&this._axisVisible&&this._yAxisVisible,r=this._visible&&this._axisVisible&&this._zAxisVisible;this._xAxisWire.setVisible(t),this._yAxisWire.setVisible(n),this._zAxisWire.setVisible(r),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled),this._yAxisLabel.setVisible(n&&!this._yAxisLabelCulled),this._zAxisLabel.setVisible(r&&!this._zAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"originVisible",get:function(){return this._originVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultOriginVisible,this._originVisible=e,this._originDot.setVisible(this._visible&&this._originVisible)}},{key:"targetVisible",get:function(){return this._targetVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultTargetVisible,this._targetVisible=e,this._targetDot.setVisible(this._visible&&this._targetVisible)}},{key:"axisEnabled",get:function(){return this._axisEnabled},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._axisEnabled=e;var t=this._visible&&this._axisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t&&this._xAxisVisible),this._yAxisWire.setVisible(t&&this._yAxisVisible),this._zAxisWire.setVisible(t&&this._zAxisVisible),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled&&this._xAxisVisible),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled&&this._xAxisVisible),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled&&this._xAxisVisible),this._cpDirty=!0,this._needUpdate()}},{key:"axisVisible",get:function(){return this._axisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._axisVisible=e;var t=this._visible&&this._axisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t&&this._xAxisVisible),this._yAxisWire.setVisible(t&&this._yAxisVisible),this._zAxisWire.setVisible(t&&this._zAxisVisible),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled&&this._xAxisVisible),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled&&this._yAxisVisible),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled&&this._zAxisVisible),this._cpDirty=!0,this._needUpdate()}},{key:"xAxisVisible",get:function(){return this._xAxisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._xAxisVisible=e;var t=this._visible&&this._axisVisible&&this._xAxisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"yAxisVisible",get:function(){return this._yAxisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._yAxisVisible=e;var t=this._visible&&this._axisVisible&&this._yAxisVisible&&this._axisEnabled;this._yAxisWire.setVisible(t),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"zAxisVisible",get:function(){return this._zAxisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._zAxisVisible=e;var t=this._visible&&this._axisVisible&&this._zAxisVisible&&this._axisEnabled;this._zAxisWire.setVisible(t),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"wireVisible",get:function(){return this._wireVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultWireVisible,this._wireVisible=e;var t=this._visible&&this._wireVisible;this._lengthLabel.setVisible(t),this._lengthWire.setVisible(t)}},{key:"labelsVisible",get:function(){return this._labelsVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultLabelsVisible,this._labelsVisible=e;var t=this._visible&&this._labelsVisible;this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled&&this._clickable&&this._axisEnabled),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled&&this._clickable&&this._axisEnabled),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled&&this._clickable&&this._axisEnabled),this._lengthLabel.setVisible(t),this._cpDirty=!0,this._needUpdate()}},{key:"setHighlighted",value:function(e){this._originDot.setHighlighted(e),this._targetDot.setHighlighted(e),this._xAxisWire.setHighlighted(e),this._yAxisWire.setHighlighted(e),this._zAxisWire.setHighlighted(e),this._xAxisLabel.setHighlighted(e),this._yAxisLabel.setHighlighted(e),this._zAxisLabel.setHighlighted(e),this._lengthWire.setHighlighted(e),this._lengthLabel.setHighlighted(e)}},{key:"clickable",get:function(){return this._clickable},set:function(e){e=!!e,this._clickable=e,this._originDot.setClickable(this._clickable),this._targetDot.setClickable(this._clickable),this._xAxisWire.setClickable(this._clickable),this._yAxisWire.setClickable(this._clickable),this._zAxisWire.setClickable(this._clickable),this._lengthWire.setClickable(this._clickable),this._xAxisLabel.setClickable(this._clickable),this._yAxisLabel.setClickable(this._clickable),this._zAxisLabel.setClickable(this._clickable),this._lengthLabel.setClickable(this._clickable)}},{key:"destroy",value:function(){var e=this.plugin.viewer.scene,t=e.metrics;this._onViewMatrix&&e.camera.off(this._onViewMatrix),this._onProjMatrix&&e.camera.off(this._onProjMatrix),this._onCanvasBoundary&&e.canvas.off(this._onCanvasBoundary),this._onMetricsUnits&&t.off(this._onMetricsUnits),this._onMetricsScale&&t.off(this._onMetricsScale),this._onMetricsOrigin&&t.off(this._onMetricsOrigin),this._originDot.destroy(),this._targetDot.destroy(),this._xAxisWire.destroy(),this._yAxisWire.destroy(),this._zAxisWire.destroy(),this._lengthLabel.destroy(),this._xAxisLabel.destroy(),this._yAxisLabel.destroy(),this._zAxisLabel.destroy(),this._lengthWire.destroy(),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),hs=function(){function e(){var t=arguments.length>0&&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&&i<a;i++){r=r[n[i]]}return r}function ys(e){var t=arguments.length>1&&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;n<r;n++)t=e[n],this.addFrame(t.t||0,t.eye,t.look,t.up)}},{key:"loadFrame",value:function(e){var t=this.scene.camera;e=(e/=this._frames[this._frames.length-1].t-this._frames[0].t)<0?0:e>1?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;i<a;i++){var s=Z.lenVec3(Z.subVec3(this._frames[i].eye,this._frames[i-1].eye,t));r[i]=s,n+=s}for(var o=1,l=this._frames.length;o<l;o++){var u=r[o]/n*e;this._frames[o].t=this._frames[o-1].t+u}}}},{key:"clearFrames",value:function(){this._frames=[],this._eyeCurve.points=[],this._lookCurve.points=[],this._upCurve.points=[]}}]),n}(),Es=Z.vec3(),bs=Z.vec3(),Ds=Z.vec3(),Ps=Z.vec3(),Rs=Z.vec3(),Cs=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))._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]<r[0]||r[4]<r[1]||r[5]<r[2])return;if(r[3]===r[0]&&r[4]===r[1]&&r[5]===r[2])return;r=r.slice();var p=Z.getAABB3Center(r);this._look2=f||p;var A=Z.subVec3(this._eye1,this._look1,Es),d=Z.normalizeVec3(A),v=f?Z.getAABB3DiagPoint(r,f):Z.getAABB3Diag(r),h=e.fitFOV||this._fitFOV,I=Math.abs(v/Math.tan(h*Z.DEGTORAD));this._orthoScale2=1.1*v,this._eye2[0]=this._look2[0]+d[0]*I,this._eye2[1]=this._look2[1]+d[1]*I,this._eye2[2]=this._look2[2]+d[2]*I,this._up2[0]=this._up1[0],this._up2[1]=this._up1[1],this._up2[2]=this._up1[2],this._flyingEyeLookUp=!0}else(i||a||s)&&(this._flyingEyeLookUp=!!i&&!!a&&!!s,this._flyingEye=!!i&&!a,this._flyingLook=!!a&&!i,i&&(this._eye2[0]=i[0],this._eye2[1]=i[1],this._eye2[2]=i[2]),a&&(this._look2[0]=a[0],this._look2[1]=a[1],this._look2[2]=a[2]),s&&(this._up2[0]=s[0],this._up2[1]=s[1],this._up2[2]=s[2]));u?("ortho"===e.projection&&"ortho"!==l.projection&&(this._projection2="ortho",this._projMatrix1=l.projMatrix.slice(),this._projMatrix2=l.ortho.matrix.slice(),l.projection="customProjection"),"perspective"===e.projection&&"perspective"!==l.projection&&(this._projection2="perspective",this._projMatrix1=l.projMatrix.slice(),this._projMatrix2=l.perspective.matrix.slice(),l.projection="customProjection")):this._projection2=null,this.fire("started",e,!0),this._time1=Date.now(),this._time2=this._time1+(e.duration?1e3*e.duration:this._duration),this._flying=!0,Ae.scheduleTask(this._update,this)}},{key:"jumpTo",value:function(e){this._jumpTo(e)}},{key:"_jumpTo",value:function(e){this._flying&&this.stop();var t,n,r,i,a,s=this.scene.camera;if(e.aabb)t=e.aabb;else if(6===e.length)t=e;else if(e.eye||e.look||e.up)r=e.eye,i=e.look,a=e.up;else{var o=e;if((ae.isNumeric(o)||ae.isString(o))&&(n=o,!(o=this.scene.components[n])))return void this.error("Component not found: "+ae.inQuotes(n));t=o.aabb||this.scene.aabb}var l=e.poi;if(t){if(t[3]<=t[0]||t[4]<=t[1]||t[5]<=t[2])return;var u,c=l?Z.getAABB3DiagPoint(t,l):Z.getAABB3Diag(t);i=l||Z.getAABB3Center(t,i),this._trail?Z.subVec3(s.look,i,Rs):Z.subVec3(s.eye,s.look,Rs),Z.normalizeVec3(Rs),u=(void 0!==e.fit?e.fit:this._fit)?Math.abs(c/Math.tan((e.fitFOV||this._fitFOV)*Z.DEGTORAD)):Z.lenVec3(Z.subVec3(s.eye,s.look,Es)),Z.mulVec3Scalar(Rs,u),s.eye=Z.addVec3(i,Rs,Es),s.look=i,this.scene.camera.ortho.scale=1.1*c}else(r||i||a)&&(r&&(s.eye=r),i&&(s.look=i),a&&(s.up=a));e.projection&&(s.projection=e.projection)}},{key:"_update",value:function(){if(this._flying){var e=(Date.now()-this._time1)/(this._time2-this._time1),t=e>=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;s<e.length;s++)a(s)}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),ee.memory.textures--,this._state.destroy()}}]),n}(),Us=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._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;v<h;v++){var I=a[i[v]];if(I){if(s&&(this.objectsVisible[v]=I.visible),o&&(this.objectsEdges[v]=I.edges),l&&(this.objectsXrayed[v]=I.xrayed),u&&(this.objectsHighlighted[v]=I.highlighted),c&&(this.objectsSelected[v]=I.selected),f&&(this.objectsClippable[v]=I.clippable),p&&(this.objectsPickable[v]=I.pickable),A){var y=I.colorize;this.objectsColorize[3*v+0]=y[0],this.objectsColorize[3*v+1]=y[1],this.objectsColorize[3*v+2]=y[2]}d&&(this.objectsOpacity[v]=I.opacity),this.numObjects++}}}}},{key:"restoreObjects",value:function(e,t){var n=t.rootMetaObject;if(n)for(var r=n.getObjectIDsInSubtree(),i=this._mask,a=!i||i.visible,s=!i||i.edges,o=!i||i.xrayed,l=!i||i.highlighted,u=!i||i.selected,c=!i||i.clippable,f=!i||i.pickable,p=!i||i.colorize,A=!i||i.opacity,d=e.objects,v=0,h=r.length;v<h;v++){var I=d[r[v]];I&&(a&&(I.visible=this.objectsVisible[v]),s&&(I.edges=this.objectsEdges[v]),o&&(I.xrayed=this.objectsXrayed[v]),l&&(I.highlighted=this.objectsHighlighted[v]),u&&(I.selected=this.objectsSelected[v]),c&&(I.clippable=this.objectsClippable[v]),f&&(I.pickable=this.objectsPickable[v]),p&&(js[0]=this.objectsColorize[3*v+0],js[1]=this.objectsColorize[3*v+1],js[2]=this.objectsColorize[3*v+2],I.colorize=js),A&&(I.opacity=this.objectsOpacity[v]))}}}]),e}(),Ws=Z.vec3(),zs=function(){function e(){b(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}return P(e,[{key:"saveObjects",value:function(e,t){this.numObjects=0,this._mask=t?ae.apply(t,{}):null;var n=e.objects,r=!t||t.visible,i=!t||t.edges,a=!t||t.xrayed,s=!t||t.highlighted,o=!t||t.selected,l=!t||t.clippable,u=!t||t.pickable,c=!t||t.colorize,f=!t||t.opacity;for(var p in n)if(n.hasOwnProperty(p)){var A=n[p],d=this.numObjects;if(r&&(this.objectsVisible[d]=A.visible),i&&(this.objectsEdges[d]=A.edges),a&&(this.objectsXrayed[d]=A.xrayed),s&&(this.objectsHighlighted[d]=A.highlighted),o&&(this.objectsSelected[d]=A.selected),l&&(this.objectsClippable[d]=A.clippable),u&&(this.objectsPickable[d]=A.pickable),c){var v=A.colorize;v?(this.objectsColorize[3*d+0]=v[0],this.objectsColorize[3*d+1]=v[1],this.objectsColorize[3*d+2]=v[2],this.objectsHasColorize[d]=!0):this.objectsHasColorize[d]=!1}f&&(this.objectsOpacity[d]=A.opacity),this.numObjects++}}},{key:"restoreObjects",value:function(e){var t=this._mask,n=!t||t.visible,r=!t||t.edges,i=!t||t.xrayed,a=!t||t.highlighted,s=!t||t.selected,o=!t||t.clippable,l=!t||t.pickable,u=!t||t.colorize,c=!t||t.opacity,f=0,p=e.objects;for(var A in p)if(p.hasOwnProperty(A)){var d=p[A];n&&(d.visible=this.objectsVisible[f]),r&&(d.edges=this.objectsEdges[f]),i&&(d.xrayed=this.objectsXrayed[f]),a&&(d.highlighted=this.objectsHighlighted[f]),s&&(d.selected=this.objectsSelected[f]),o&&(d.clippable=this.objectsClippable[f]),l&&(d.pickable=this.objectsPickable[f]),u&&(this.objectsHasColorize[f]?(Ws[0]=this.objectsColorize[3*f+0],Ws[1]=this.objectsColorize[3*f+1],Ws[2]=this.objectsColorize[3*f+2],d.colorize=Ws):d.colorize=null),c&&(d.opacity=this.objectsOpacity[f]),f++}}}]),e}(),Ks=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)).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;n<r;n++)(t=this._curves[n]).off(this._dirtySubs[n]),t.off(this._destroyedSubs[n]);this._curves=[],this._dirtySubs=[],this._destroyedSubs=[];var i=this;function a(){i._dirty=!0}function s(){var e=this.id;for(n=0,r=i._curves.length;n<r;n++)if(i._curves[n].id===e)return i._curves=i._curves.slice(n,n+1),i._dirtySubs=i._dirtySubs.slice(n,n+1),i._destroyedSubs=i._destroyedSubs.slice(n,n+1),void(i._dirty=!0)}for(n=0,r=e.length;n<r;n++){if(t=e[n],ae.isNumeric(t)||ae.isString(t)){var o=t;if(!(t=this.scene.components[o])){this.error("Component not found: "+_inQuotes(o));continue}}var l=t.type;"xeokit.SplineCurve"===l||"xeokit.Path"===l||"xeokit.CubicBezierCurve"===l||"xeokit.QuadraticBezierCurve"===l?(this._curves.push(t),this._dirtySubs.push(t.on("dirty",a)),this._destroyedSubs.push(t.once("destroyed",s))):this.error("Component "+_inQuotes(t.id)+" is not a xeokit.SplineCurve, xeokit.Path or xeokit.QuadraticBezierCurve")}this._dirty=!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:"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<r.length;){if(r[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;e<r;e++)n+=this._curves[e].length,t.push(n);return this._cachedLengths=t,this._dirty=!1,t}},{key:"_getJSON",value:function(){for(var e=[],t=0,n=this._curves.length;t<n;t++)e.push(this._curves[t].id);return{curves:e,t:this._t}}},{key:"destroy",value:function(){var e,t,r;for(v(T(n.prototype),"destroy",this).call(this),e=0,t=this._curves.length;e<t;e++)(r=this._curves[e]).off(this._dirtySubs[e]),r.off(this._destroyedSubs[e])}}]),n}(),Xs=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)).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;u<a;u++){var c=this._uSectionPlanes[u];if(c){var f=l.sectionPlanesActivePerLayer[o+u];if(n.uniform1i(c.active,f?1:0),f){var p=s[u],A=e._state.origin;if(A){var d=ge(p.dist,p.dir,A,io);n.uniform3fv(c.pos,d)}else n.uniform3fv(c.pos,p.pos);n.uniform3fv(c.dir,p.dir)}}}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl,n=e._lightsState;if(this._program=new ft(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uRenderPass=r.getLocation("renderPass"),this._uColor=r.getLocation("color"),this._uColor||(this._uColor=r.getLocation("silhouetteColor")),this._uUVDecodeMatrix=r.getLocation("uvDecodeMatrix"),this._uPickInvisible=r.getLocation("pickInvisible"),this._uGammaFactor=r.getLocation("gammaFactor"),t.uniformBlockBinding(r.handle,t.getUniformBlockIndex(r.handle,"Matrices"),this._matricesUniformBlockBufferBindingPoint),this._uShadowViewMatrix=r.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=r.getLocation("shadowProjMatrix"),e.logarithmicDepthBufferEnabled&&(this._uZFar=r.getLocation("zFar")),this._uLightAmbient=r.getLocation("lightAmbient"),this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];for(var i=n.lights,a=0,s=i.length;a<s;a++)switch(i[a].type){case"dir":this._uLightColor[a]=r.getLocation("lightColor"+a),this._uLightPos[a]=null,this._uLightDir[a]=r.getLocation("lightDir"+a);break;case"point":this._uLightColor[a]=r.getLocation("lightColor"+a),this._uLightPos[a]=r.getLocation("lightPos"+a),this._uLightDir[a]=null,this._uLightAttenuation[a]=r.getLocation("lightAttenuation"+a);break;case"spot":this._uLightColor[a]=r.getLocation("lightColor"+a),this._uLightPos[a]=r.getLocation("lightPos"+a),this._uLightDir[a]=r.getLocation("lightDir"+a),this._uLightAttenuation[a]=r.getLocation("lightAttenuation"+a)}n.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),n.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(var o=0,l=e._sectionPlanesState.sectionPlanes.length;o<l;o++)this._uSectionPlanes.push({active:r.getLocation("sectionPlaneActive"+o),pos:r.getLocation("sectionPlanePos"+o),dir:r.getLocation("sectionPlaneDir"+o)});this._aPosition=r.getAttribute("position"),this._aOffset=r.getAttribute("offset"),this._aNormal=r.getAttribute("normal"),this._aUV=r.getAttribute("uv"),this._aColor=r.getAttribute("color"),this._aMetallicRoughness=r.getAttribute("metallicRoughness"),this._aFlags=r.getAttribute("flags"),this._aPickColor=r.getAttribute("pickColor"),this._uPickZNear=r.getLocation("pickZNear"),this._uPickZFar=r.getLocation("pickZFar"),this._uColorMap="uColorMap",this._uMetallicRoughMap="uMetallicRoughMap",this._uEmissiveMap="uEmissiveMap",this._uNormalMap="uNormalMap",this._uAOMap="uAOMap",this._instancing&&(this._aModelMatrixCol0=r.getAttribute("modelMatrixCol0"),this._aModelMatrixCol1=r.getAttribute("modelMatrixCol1"),this._aModelMatrixCol2=r.getAttribute("modelMatrixCol2"),this._aModelNormalMatrixCol0=r.getAttribute("modelNormalMatrixCol0"),this._aModelNormalMatrixCol1=r.getAttribute("modelNormalMatrixCol1"),this._aModelNormalMatrixCol2=r.getAttribute("modelNormalMatrixCol2")),this._withSAO&&(this._uOcclusionTexture="uOcclusionTexture",this._uSAOParams=r.getLocation("uSAOParams")),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=r.getLocation("logDepthBufFC")),e.pointsMaterial._state.filterIntensity&&(this._uIntensityRange=r.getLocation("intensityRange")),this._uPointSize=r.getLocation("pointSize"),this._uNearPlaneHeight=r.getLocation("nearPlaneHeight")}}},{key:"_bindProgram",value:function(e){var t=this._scene,n=t.canvas.gl,r=this._program,i=t._lightsState,a=i.lights,s=t.camera.project;r.bind(),e.textureUnit=0,this._uLightAmbient&&n.uniform4fv(this._uLightAmbient,i.getAmbientColorAndIntensity());for(var o=0,l=a.length;o<l;o++){var u=a[o];this._uLightColor[o]&&n.uniform4f(this._uLightColor[o],u.color[0],u.color[1],u.color[2],u.intensity),this._uLightPos[o]&&(n.uniform3fv(this._uLightPos[o],u.pos),this._uLightAttenuation[o]&&n.uniform1f(this._uLightAttenuation[o],u.attenuation)),this._uLightDir[o]&&n.uniform3fv(this._uLightDir[o],u.dir)}if(this._withSAO){var c=t.sao;if(c.possible){var f=n.drawingBufferWidth,p=n.drawingBufferHeight;ro[0]=f,ro[1]=p,ro[2]=c.blendCutoff,ro[3]=c.blendFactor,n.uniform4fv(this._uSAOParams,ro),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,0)}}if(t.logarithmicDepthBufferEnabled){var A=2/(Math.log(s.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,A)}this._uGammaFactor&&n.uniform1f(this._uGammaFactor,t.gammaFactor),this._uPickInvisible&&n.uniform1i(this._uPickInvisible,e.pickInvisible),this._uShadowViewMatrix&&n.uniformMatrix4fv(this._uShadowViewMatrix,!1,e.shadowViewMatrix),this._uShadowProjMatrix&&n.uniformMatrix4fv(this._uShadowProjMatrix,!1,e.shadowProjMatrix)}},{key:"_makeVAO",value:function(e){var t=this._scene.canvas.gl,n=t.createVertexArray();return t.bindVertexArray(n),this._instancing&&(this._aModelMatrixCol0.bindArrayBuffer(e.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(e.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(e.modelMatrixCol2Buf),t.vertexAttribDivisor(this._aModelMatrixCol0.location,1),t.vertexAttribDivisor(this._aModelMatrixCol1.location,1),t.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aModelNormalMatrixCol0&&(this._aModelNormalMatrixCol0.bindArrayBuffer(e.modelNormalMatrixCol0Buf),t.vertexAttribDivisor(this._aModelNormalMatrixCol0.location,1)),this._aModelNormalMatrixCol1&&(this._aModelNormalMatrixCol1.bindArrayBuffer(e.modelNormalMatrixCol1Buf),t.vertexAttribDivisor(this._aModelNormalMatrixCol1.location,1)),this._aModelNormalMatrixCol2&&(this._aModelNormalMatrixCol2.bindArrayBuffer(e.modelNormalMatrixCol2Buf),t.vertexAttribDivisor(this._aModelNormalMatrixCol2.location,1))),this._aPosition.bindArrayBuffer((this._instancing,e.positionsBuf)),this._aUV&&this._aUV.bindArrayBuffer((this._instancing,e.uvBuf)),this._aNormal&&this._aNormal.bindArrayBuffer((this._instancing,e.normalsBuf)),this._aMetallicRoughness&&(this._aMetallicRoughness.bindArrayBuffer(e.metallicRoughnessBuf),this._instancing&&t.vertexAttribDivisor(this._aMetallicRoughness.location,1)),this._aColor&&(this._aColor.bindArrayBuffer((e.colorsBuf,e.colorsBuf)),this._instancing&&e.colorsBuf&&t.vertexAttribDivisor(this._aColor.location,1)),this._aFlags&&(this._aFlags.bindArrayBuffer(e.flagsBuf),this._instancing&&t.vertexAttribDivisor(this._aFlags.location,1)),this._aOffset&&(this._aOffset.bindArrayBuffer(e.offsetsBuf),this._instancing&&t.vertexAttribDivisor(this._aOffset.location,1)),this._aPickColor&&(this._aPickColor.bindArrayBuffer(e.pickColorsBuf),this._instancing&&t.vertexAttribDivisor(this._aPickColor.location,1)),this._instancing,this._edges?e.edgeIndicesBuf.bind():e.indicesBuf&&e.indicesBuf.bind(),n}},{key:"drawLayer",value:function(e,t,n){var r=arguments.length>3&&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<o;s++)"ambient"!==(e=r.lights[s]).type&&(a.push("uniform vec4 lightColor"+s+";"),"dir"===e.type&&a.push("uniform vec3 lightDir"+s+";"),"point"===e.type&&a.push("uniform vec3 lightPos"+s+";"),"spot"===e.type&&(a.push("uniform vec3 lightPos"+s+";"),a.push("uniform vec3 lightDir"+s+";")));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("}"),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;l<u;l++)if("ambient"!==(e=r.lights[l]).type){if("dir"===e.type)"view"===e.space?a.push("viewLightDir = normalize(lightDir"+l+");"):a.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+l+", 0.0)).xyz);");else if("point"===e.type)"view"===e.space?a.push("viewLightDir = -normalize(lightPos"+l+" - viewPosition.xyz);"):a.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+l+", 0.0)).xyz);");else{if("spot"!==e.type)continue;"view"===e.space?a.push("viewLightDir = normalize(lightDir"+l+");"):a.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+l+", 0.0)).xyz);")}a.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),a.push("reflectedColor += lambertian * (lightColor"+l+".rgb * lightColor"+l+".a);")}return a.push("vec3 rgb = (vec3(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0));"),a.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedColor * rgb), float(color.a) / 255.0);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;")),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}}]),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<s;a++)i.push("uniform bool sectionPlaneActive"+a+";"),i.push("uniform vec3 sectionPlanePos"+a+";"),i.push("uniform vec3 sectionPlaneDir"+a+";")}this._addMatricesUniformBlockLines(i),i.push("uniform vec4 lightAmbient;");for(var o=0,l=t.lights.length;o<l;o++){var u=t.lights[o];"ambient"!==u.type&&(i.push("uniform vec4 lightColor"+o+";"),"dir"===u.type&&i.push("uniform vec3 lightDir"+o+";"),"point"===u.type&&i.push("uniform vec3 lightPos"+o+";"),"spot"===u.type&&(i.push("uniform vec3 lightPos"+o+";"),i.push("uniform vec3 lightDir"+o+";")))}if(i.push("in vec4 vViewPosition;"),i.push("in vec4 vColor;"),i.push("out vec4 outColor;"),i.push("void main(void) {"),r){i.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var c=0,f=n.sectionPlanes.length;c<f;c++)i.push("if (sectionPlaneActive"+c+") {"),i.push(" dist += clamp(dot(-sectionPlaneDir"+c+".xyz, vWorldPosition.xyz - sectionPlanePos"+c+".xyz), 0.0, 1000.0);"),i.push("}");i.push(" if (dist > 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;p<A;p++){var d=t.lights[p];if("ambient"!==d.type){if("dir"===d.type)"view"===d.space?i.push("viewLightDir = normalize(lightDir"+p+");"):i.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+p+", 0.0)).xyz);");else if("point"===d.type)"view"===d.space?i.push("viewLightDir = -normalize(lightPos"+p+" - viewPosition.xyz);"):i.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+p+", 0.0)).xyz);");else{if("spot"!==d.type)continue;"view"===d.space?i.push("viewLightDir = normalize(lightDir"+p+");"):i.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+p+", 0.0)).xyz);")}i.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),i.push("reflectedColor += lambertian * (lightColor"+p+".rgb * lightColor"+p+".a);")}}return i.push("vec4 fragColor = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);"),this._withSAO?(i.push(" float viewportWidth = uSAOParams[0];"),i.push(" float viewportHeight = uSAOParams[1];"),i.push(" float blendCutoff = uSAOParams[2];"),i.push(" float blendFactor = uSAOParams[3];"),i.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),i.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),i.push(" outColor = vec4(fragColor.rgb * ambient, 1.0);")):i.push(" outColor = fragColor;"),e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("}"),i}}]),n}(),Io=function(e){I(n,so);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 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<t;e++)a.push("uniform bool sectionPlaneActive"+e+";"),a.push("uniform vec3 sectionPlanePos"+e+";"),a.push("uniform vec3 sectionPlaneDir"+e+";");if(a.push("in vec4 vColor;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),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<t;e++)a.push("if (sectionPlaneActive"+e+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+e+".xyz, vWorldPosition.xyz - sectionPlanePos"+e+".xyz), 0.0, 1000.0);"),a.push("}");a.push(" if (dist > 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vPickColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vViewPosition;"),r.push("vec4 packDepth(const in float depth) {"),r.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),r.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),r.push(" vec4 res = fract(depth * bitShift);"),r.push(" res -= res.xxyz * bitMask;"),r.push(" return res;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vWorldNormal;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("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("const float shiftRight8 = 1.0 / 256.;"),r.push("vec4 packDepthToRGBA( const in float v ) {"),r.push(" vec4 r = vec4( fract( v * packFactors ), v );"),r.push(" r.yzw -= r.xyz * shiftRight8;"),r.push(" return r * packUpScale;"),r.push("}"),r.push("in vec2 vHighPrecisionZW;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vViewNormal;"),r.push("vec3 packNormalToRGB( const in vec3 normal ) {"),r.push(" return normalize( normal ) * 0.5 + 0.5;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<e.sectionPlanes.length;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in vec4 vViewPosition;"),n.push("vec4 encodeFloat( const in float v ) {"),n.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"),n.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"),n.push(" vec4 comp = fract(v * bitShift);"),n.push(" comp -= comp.xxyz * bitMask;"),n.push(" return comp;"),n.push("}"),n.push("out vec4 outColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i<e.sectionPlanes.length;i++)n.push(" if (sectionPlaneActive"+i+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 0.0) { discard; }"),n.push(" }")}return n.push(" outColor = 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;o<l;o++){var u=r.lights[o];"ambient"!==u.type&&(s.push("uniform vec4 lightColor"+o+";"),"dir"===u.type&&s.push("uniform vec3 lightDir"+o+";"),"point"===u.type&&s.push("uniform vec3 lightPos"+o+";"),"spot"===u.type&&(s.push("uniform vec3 lightPos"+o+";"),s.push("uniform vec3 lightDir"+o+";")))}if(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("}")),s.push("uniform float gammaFactor;"),s.push("vec4 linearToLinear( in vec4 value ) {"),s.push(" return value;"),s.push("}"),s.push("vec4 sRGBToLinear( in vec4 value ) {"),s.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 );"),s.push("}"),s.push("vec4 gammaToLinear( in vec4 value) {"),s.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),s.push("}"),t&&(s.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),s.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),s.push("}")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;"),a&&s.push("in vec4 vClipPosition;");for(var c=0,f=n.sectionPlanes.length;c<f;c++)s.push("uniform bool sectionPlaneActive"+c+";"),s.push("uniform vec3 sectionPlanePos"+c+";"),s.push("uniform vec3 sectionPlaneDir"+c+";")}if(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.x == 0.0 && texel.y == 0.0 && texel.z == 0.0) {"),s.push(" return 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 = 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<A;p++)s.push("if (sectionPlaneActive"+p+") {"),s.push(" dist += clamp(dot(-sectionPlaneDir"+p+".xyz, vWorldPosition.xyz - sectionPlanePos"+p+".xyz), 0.0, 1000.0);"),s.push("}");a?(s.push(" if (dist > (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;d<v;d++){var h=r.lights[d];if("ambient"!==h.type){if("dir"===h.type)"view"===h.space?s.push("light.direction = normalize(lightDir"+d+");"):s.push("light.direction = normalize((viewMatrix * vec4(lightDir"+d+", 0.0)).xyz);");else if("point"===h.type)"view"===h.space?s.push("light.direction = normalize(lightPos"+d+" - vViewPosition.xyz);"):s.push("light.direction = normalize((viewMatrix * vec4(lightPos"+d+", 0.0)).xyz);");else{if("spot"!==h.type)continue;"view"===h.space?s.push("light.direction = normalize(lightDir"+d+");"):s.push("light.direction = normalize((viewMatrix * vec4(lightDir"+d+", 0.0)).xyz);")}s.push("light.color = lightColor"+d+".rgb * lightColor"+d+".a;"),s.push("computePBRLighting(light, geometry, material, reflectedLight);")}}return s.push("vec3 emissiveColor = sRGBToLinear(texture(uEmissiveMap, vUV)).rgb;"),s.push("float aoFactor = texture(uAOMap, vUV).r;"),s.push("vec3 outgoingLight = (lightAmbient.rgb * lightAmbient.a * baseColor * opacity * rgb) + (reflectedLight.diffuse) + (reflectedLight.specular) + emissiveColor;"),s.push("vec4 fragColor;"),this._withSAO?(s.push(" float viewportWidth = uSAOParams[0];"),s.push(" float viewportHeight = uSAOParams[1];"),s.push(" float blendCutoff = uSAOParams[2];"),s.push(" float blendFactor = uSAOParams[3];"),s.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),s.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),s.push(" fragColor = vec4(outgoingLight.rgb * ambient * aoFactor, opacity);")):s.push(" fragColor = vec4(outgoingLight.rgb * aoFactor, opacity);"),t&&s.push("fragColor = linearToGamma(fragColor, gammaFactor);"),s.push("outColor = fragColor;"),e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),n}(),Co=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 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<o;s++)a.push("uniform bool sectionPlaneActive"+s+";"),a.push("uniform vec3 sectionPlanePos"+s+";"),a.push("uniform vec3 sectionPlaneDir"+s+";")}this._addMatricesUniformBlockLines(a),a.push("uniform vec4 lightAmbient;");for(var l=0,u=n.lights.length;l<u;l++){var c=n.lights[l];"ambient"!==c.type&&(a.push("uniform vec4 lightColor"+l+";"),"dir"===c.type&&a.push("uniform vec3 lightDir"+l+";"),"point"===c.type&&a.push("uniform vec3 lightPos"+l+";"),"spot"===c.type&&(a.push("uniform vec3 lightPos"+l+";"),a.push("uniform vec3 lightDir"+l+";")))}if(a.push("in vec4 vViewPosition;"),a.push("in vec4 vColor;"),a.push("in vec2 vUV;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),i){a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(var f=0,p=r.sectionPlanes.length;f<p;f++)a.push("if (sectionPlaneActive"+f+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+f+".xyz, vWorldPosition.xyz - sectionPlanePos"+f+".xyz), 0.0, 1000.0);"),a.push("}");a.push(" if (dist > 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;A<d;A++){var v=n.lights[A];if("ambient"!==v.type){if("dir"===v.type)"view"===v.space?a.push("viewLightDir = normalize(lightDir"+A+");"):a.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+A+", 0.0)).xyz);");else if("point"===v.type)"view"===v.space?a.push("viewLightDir = -normalize(lightPos"+A+" - viewPosition.xyz);"):a.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+A+", 0.0)).xyz);");else{if("spot"!==v.type)continue;"view"===v.space?a.push("viewLightDir = normalize(lightDir"+A+");"):a.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+A+", 0.0)).xyz);")}a.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),a.push("reflectedColor += lambertian * (lightColor"+A+".rgb * lightColor"+A+".a);")}}return a.push("vec4 color = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);"),t?a.push("vec4 colorTexel = color * sRGBToLinear(texture(uColorMap, vUV));"):a.push("vec4 colorTexel = color * texture(uColorMap, vUV);"),a.push("float opacity = color.a;"),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, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(colorTexel.rgb * ambient, opacity);")):a.push(" outColor = vec4(colorTexel.rgb, opacity);"),t&&a.push("outColor = linearToGamma(outColor, gammaFactor);"),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}]),n}(),Bo=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorTextureRenderer&&!this._colorTextureRenderer.getValid()&&(this._colorTextureRenderer.destroy(),this._colorTextureRenderer=null),this._colorTextureRendererWithSAO&&!this._colorTextureRendererWithSAO.getValid()&&(this._colorTextureRendererWithSAO.destroy(),this._colorTextureRendererWithSAO=null),this._pbrRenderer&&!this._pbrRenderer.getValid()&&(this._pbrRenderer.destroy(),this._pbrRenderer=null),this._pbrRendererWithSAO&&!this._pbrRendererWithSAO.getValid()&&(this._pbrRendererWithSAO.destroy(),this._pbrRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new vo(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new vo(this._scene,!0)),this._colorRendererWithSAO}},{key:"flatColorRenderer",get:function(){return this._flatColorRenderer||(this._flatColorRenderer=new ho(this._scene,!1)),this._flatColorRenderer}},{key:"flatColorRendererWithSAO",get:function(){return this._flatColorRendererWithSAO||(this._flatColorRendererWithSAO=new ho(this._scene,!0)),this._flatColorRendererWithSAO}},{key:"colorTextureRenderer",get:function(){return this._colorTextureRenderer||(this._colorTextureRenderer=new _o(this._scene,!1)),this._colorTextureRenderer}},{key:"colorTextureRendererWithSAO",get:function(){return this._colorTextureRendererWithSAO||(this._colorTextureRendererWithSAO=new _o(this._scene,!0)),this._colorTextureRendererWithSAO}},{key:"pbrRenderer",get:function(){return this._pbrRenderer||(this._pbrRenderer=new Ro(this._scene,!1)),this._pbrRenderer}},{key:"pbrRendererWithSAO",get:function(){return this._pbrRendererWithSAO||(this._pbrRendererWithSAO=new Ro(this._scene,!0)),this._pbrRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Io(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new bo(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new Do(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new yo(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new mo(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new wo(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new To(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new Co(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new go(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Eo(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new Po(this._scene)),this._shadowRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._colorTextureRenderer&&this._colorTextureRenderer.destroy(),this._colorTextureRendererWithSAO&&this._colorTextureRendererWithSAO.destroy(),this._pbrRenderer&&this._pbrRenderer.destroy(),this._pbrRendererWithSAO&&this._pbrRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}]),e}(),Oo={};var So=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.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<r;h+=3)i[h+0]=Math.floor(v(e[h+0]-a)*p),i[h+1]=Math.floor(v(e[h+1]-s)*A),i[h+2]=Math.floor(v(e[h+2]-o)*d);return Z.identityMat4(No),Z.translationMat4v(t,No),Z.identityMat4(Lo),Z.scalingMat4v([l/f,u/f,c/f],Lo),Z.mulMat4(No,Lo,n),i}function Mo(e,t){var n=e[0],r=e[1],i=e[2],a=e[3]-n,s=e[4]-r,o=e[5]-i,l=65525;return Z.identityMat4(No),Z.translationMat4v(e,No),Z.identityMat4(Lo),Z.scalingMat4v([a/l,s/l,o/l],Lo),Z.mulMat4(No,Lo,t),t}function Fo(e,t,n){var r=e[0]/(Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2])),i=e[1]/(Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2]));if(e[2]<0){var a,s;a=(1-Math.abs(i))*(r>=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;w<h;w++){var g=this._uSectionPlanes[w];if(g){var T=m.sectionPlanesActivePerLayer[y+w];if(s.uniform1i(g.active,T?1:0),T){var E=I[w];if(l){var b=ge(E.dist,E.dir,l,Uo);s.uniform3fv(g.pos,b)}else s.uniform3fv(g.pos,E.pos);s.uniform3fv(g.dir,E.dir)}}}s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,t._state.positionsDecodeMatrix),this._aPosition.bindArrayBuffer(o.positionsBuf),this._aOffset&&this._aOffset.bindArrayBuffer(o.offsetsBuf),this._aFlags&&this._aFlags.bindArrayBuffer(o.flagsBuf),o.indicesBuf.bind(),s.drawElements(s.TRIANGLES,o.indicesBuf.numItems,o.indicesBuf.itemType,0),o.indicesBuf.unbind()}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new ft(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSolid=n.getLocation("solid"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._aPosition=n.getAttribute("position"),this._aOffset=n.getAttribute("offset"),this._aFlags=n.getAttribute("flags"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc"),this.uVectorA=n.getLocation("snapVectorA"),this.uInverseVectorAB=n.getLocation("snapInvVectorAB"),this._uLayerNumber=n.getLocation("layerNumber"),this._uCoordinateScaler=n.getLocation("coordinateScaler")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in highp vec3 relativeToOriginPosition;"),r.push("out highp ivec4 outCoords;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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;w<h;w++){var g=this._uSectionPlanes[w];if(g){var T=m.sectionPlanesActivePerLayer[y+w];if(s.uniform1i(g.active,T?1:0),T){var E=I[w];if(l){var b=ge(E.dist,E.dir,l,ko);s.uniform3fv(g.pos,b)}else s.uniform3fv(g.pos,E.pos);s.uniform3fv(g.dir,E.dir)}}}s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,t._state.positionsDecodeMatrix),this._aPosition.bindArrayBuffer(o.positionsBuf),this._aOffset&&this._aOffset.bindArrayBuffer(o.offsetsBuf),this._aFlags&&this._aFlags.bindArrayBuffer(o.flagsBuf),"edge"===e.snapMode?(o.edgeIndicesBuf.bind(),s.drawElements(s.LINES,o.edgeIndicesBuf.numItems,o.edgeIndicesBuf.itemType,0),o.edgeIndicesBuf.unbind()):s.drawArrays(s.POINTS,0,o.positionsBuf.numItems)}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new ft(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._aPosition=n.getAttribute("position"),this._aOffset=n.getAttribute("offset"),this._aFlags=n.getAttribute("flags"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc"),this.uVectorA=n.getLocation("snapVectorA"),this.uInverseVectorAB=n.getLocation("snapInvVectorAB"),this._uLayerNumber=n.getLocation("layerNumber"),this._uCoordinateScaler=n.getLocation("coordinateScaler")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0;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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in highp vec3 relativeToOriginPosition;"),r.push("out highp ivec4 outCoords;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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+t<this._buffer.maxIndices}},{key:"createPortion",value:function(e){if(this._finalized)throw"Already finalized";var t,n=e.positions,r=e.positionsCompressed,i=e.normals,a=e.normalsCompressed,s=e.uv,o=e.uvCompressed,l=e.colors,u=e.colorsCompressed,c=e.indices,f=e.edgeIndices,p=e.color,A=e.metallic,d=e.roughness,v=e.opacity,h=e.meshMatrix,I=e.sceneModelMatrix,y=e.worldAABB,m=e.pickColor,w=this.model.scene,g=this._buffer,T=g.positions.length/3;if(this._state.positionsDecodeMatrix){if(!r)throw"positionsCompressed expected";t=r.length/3;for(var E=0,b=r.length;E<b;E++)g.positions.push(r[E]);var D=pn.getPositionsBounds(r),P=pn.decompressPosition(D.min,this._state.positionsDecodeMatrix,[]),R=pn.decompressPosition(D.max,this._state.positionsDecodeMatrix,[]);y[0]=P[0],y[1]=P[1],y[2]=P[2],y[3]=R[0],y[4]=R[1],y[5]=R[2],I&&(Z.AABB3ToOBB3(y,qo),Z.transformOBB3(I,qo),Z.OBB3ToAABB3(qo,y))}else{if(!n)throw"positions expected";t=n.length/3;for(var C=n.length,_=g.positions.length,B=0,O=n.length;B<O;B++)g.positions.push(n[B]);if(h)for(var S=_,N=_+C;S<N;S+=3)Ko[0]=g.positions[S+0],Ko[1]=g.positions[S+1],Ko[2]=g.positions[S+2],Z.transformPoint4(h,Ko,Yo),g.positions[S+0]=Yo[0],g.positions[S+1]=Yo[1],g.positions[S+2]=Yo[2],Z.expandAABB3Point3(this._modelAABB,Yo),I?(Z.transformPoint4(I,Yo,Xo),Z.expandAABB3Point3(y,Xo)):Z.expandAABB3Point3(y,Yo);else for(var L=_,x=_+C;L<x;L+=3)Ko[0]=g.positions[L+0],Ko[1]=g.positions[L+1],Ko[2]=g.positions[L+2],Z.expandAABB3Point3(this._modelAABB,Ko),I?(Z.transformPoint4(I,Ko,Yo),Z.expandAABB3Point3(y,Yo)):Z.expandAABB3Point3(y,Ko)}if(this._state.origin){var M=this._state.origin;y[0]+=M[0],y[1]+=M[1],y[2]+=M[2],y[3]+=M[0],y[4]+=M[1],y[5]+=M[2]}if(Z.expandAABB3(this.aabb,y),a&&a.length>0)for(var F=0,H=a.length;F<H;F++)g.normals.push(a[F]);else if(i&&i.length>0){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;c<n;c+=3)f[0]=t[c],f[1]=t[c+1],f[2]=t[c+2],Z.transformVec3(e,f,p),Z.normalizeVec3(p,p),o=s=Fo(p,"floor","floor"),l=u=a(p,Ho(s)),(l=a(p,Ho(s=Fo(p,"ceil","floor"))))>u&&(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;G<k;G+=3)g.colors.push(255*l[G]),g.colors.push(255*l[G+1]),g.colors.push(255*l[G+2]),g.colors.push(255);else if(u)for(var V=0,j=l.length;V<j;V+=3)g.colors.push(l[V]),g.colors.push(l[V+1]),g.colors.push(l[V+2]),g.colors.push(255);else if(p)for(var Q=p[0],W=p[1],z=p[2],K=v,Y=0;Y<t;Y++)g.colors.push(Q),g.colors.push(W),g.colors.push(z),g.colors.push(K);for(var X=null!=A?A:0,q=null!=d?d:255,J=0;J<t;J++)g.metallicRoughness.push(X),g.metallicRoughness.push(q);if(s&&s.length>0)for(var $=0,ee=s.length;$<ee;$++)g.uv.push(s[$]);else if(o&&o.length>0)for(var te=0,ne=o.length;te<ne;te++)g.uv.push(o[te]);for(var re=0,ie=c.length;re<ie;re++)g.indices.push(T+c[re]);if(f)for(var ae=0,se=f.length;ae<se;ae++)g.edgeIndices.push(T+f[ae]);for(var oe=g.pickColors.length,le=oe,ue=oe+4*t;le<ue;le+=4)g.pickColors.push(m[0]),g.pickColors.push(m[1]),g.pickColors.push(m[2]),g.pickColors.push(m[3]);if(w.entityOffsetsEnabled)for(var ce=0;ce<t;ce++)g.offsets.push(0),g.offsets.push(0),g.offsets.push(0);var fe=this._portions.length,pe={vertsBaseIndex:T,numVerts:t,indicesBaseIndex:g.indices.length-c.length,numIndices:c.length};return w.pickSurfacePrecisionEnabled&&(pe.indices=c,w.entityOffsetsEnabled&&(pe.offset=new Float32Array(3))),this._portions.push(pe),this._numPortions++,this.model.numPortions++,this._numVerts+=pe.numVerts,fe}},{key:"finalize",value:function(){if(!this._finalized){var e=this._state,t=this.model.scene.canvas.gl,n=this._buffer;if(n.positions.length>0){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;i<a;i++){var s=this._portions[i],o=3*s.vertsBaseIndex,l=o+3*s.numVerts;s.quantizedPositions=r.slice(o,l)}}if(n.normals.length>0){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;f<a;f+=4)s[f+0]=o,s[f+1]=l,s[f+2]=u,s[f+3]=c;this._state.colorsBuf&&this._state.colorsBuf.setData(s,i,a)}},{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){var r=arguments.length>3&&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;T<E;T++){var b=0;b|=i,b|=a<<4,b|=m<<8,b|=w<<12,b|=g<<16,this._deferredFlagValues[T]=b}}else if(this._state.flagsBuf){for(var D=this._scratchMemory.getFloat32Array(f),P=0;P<f;P++){var R=0;R|=i,R|=a<<4,R|=m<<8,R|=w<<12,R|=g<<16,D[P]=R}this._state.flagsBuf.setData(D,c,f)}}},{key:"_setDeferredFlags",value:function(){this._deferredFlagValues&&(this._state.flagsBuf.setData(this._deferredFlagValues),this._deferredFlagValues=null)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";if(this.model.scene.entityOffsetsEnabled){for(var n=e,r=this._portions[n],i=3*r.vertsBaseIndex,a=3*r.numVerts,s=this._scratchMemory.getFloat32Array(a),o=t[0],l=t[1],u=t[2],c=0;c<a;c+=3)s[c+0]=o,s[c+1]=l,s[c+2]=u;this._state.offsetsBuf&&this._state.offsetsBuf.setData(s,i,a),this.model.scene.pickSurfacePrecisionEnabled&&(r.offset[0]=t[0],r.offset[1]=t[1],r.offset[2]=t[2])}else this.model.error("Entity#offset not enabled for this Viewer")}},{key:"getEachVertex",value:function(e,t){if(this.model.scene.pickSurfacePrecisionEnabled){var n=this._state,r=this._portions[e];if(r)for(var i=r.quantizedPositions,a=n.origin,s=r.offset,o=a[0]+s[0],l=a[1]+s[1],u=a[2]+s[2],c=Ko,f=0,p=i.length;f<p;f+=3)c[0]=i[f],c[1]=i[f+1],c[2]=i[f+2],c[3]=1,Z.decompressPosition(c,n.positionsDecodeMatrix),Z.transformPoint4(this.model.worldMatrix,c),c[0]+=o,c[1]+=l,c[2]+=u,t(c);else this.model.error("portion not found: "+e)}}},{key:"getElementsCountAndOffset",value:function(e){var t=null,n=null,r=this._portions[e];return r&&(t=r.numIndices,n=r.indicesBaseIndex),{count:t,offset:n}}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.withSAO&&this.model.saoEnabled?t.pbrEnabled&&this.model.pbrEnabled&&this._state.pbrSupported?this._batchingRenderers.pbrRendererWithSAO&&this._batchingRenderers.pbrRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):t.colorTextureEnabled&&this.model.colorTextureEnabled&&this._state.colorTextureSupported?this._batchingRenderers.colorTextureRendererWithSAO&&this._batchingRenderers.colorTextureRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):this._state.normalsBuf?this._batchingRenderers.colorRendererWithSAO&&this._batchingRenderers.colorRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):this._batchingRenderers.flatColorRendererWithSAO&&this._batchingRenderers.flatColorRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):t.pbrEnabled&&this.model.pbrEnabled&&this._state.pbrSupported?this._batchingRenderers.pbrRenderer&&this._batchingRenderers.pbrRenderer.drawLayer(t,this,eo.COLOR_OPAQUE):t.colorTextureEnabled&&this.model.colorTextureEnabled&&this._state.colorTextureSupported?this._batchingRenderers.colorTextureRenderer&&this._batchingRenderers.colorTextureRenderer.drawLayer(t,this,eo.COLOR_OPAQUE):this._state.normalsBuf?this._batchingRenderers.colorRenderer&&this._batchingRenderers.colorRenderer.drawLayer(t,this,eo.COLOR_OPAQUE):this._batchingRenderers.flatColorRenderer&&this._batchingRenderers.flatColorRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"_updateBackfaceCull",value:function(e,t){var n=this.model.backfaces||!this.solid||e.sectioned;if(t.backfaces!==n){var r=t.gl;n?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),t.backfaces=n}}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.pbrEnabled&&this.model.pbrEnabled&&this._state.pbrSupported?this._batchingRenderers.pbrRenderer&&this._batchingRenderers.pbrRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT):t.colorTextureEnabled&&this.model.colorTextureEnabled&&this._state.colorTextureSupported?this._batchingRenderers.colorTextureRenderer&&this._batchingRenderers.colorTextureRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT):this._state.normalsBuf?this._batchingRenderers.colorRenderer&&this._batchingRenderers.colorRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT):this._batchingRenderers.flatColorRenderer&&this._batchingRenderers.flatColorRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT))}},{key:"drawDepth",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.depthRenderer&&this._batchingRenderers.depthRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.normalsRenderer&&this._batchingRenderers.normalsRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.silhouetteRenderer&&this._batchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_XRAYED))}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.silhouetteRenderer&&this._batchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_HIGHLIGHTED))}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.silhouetteRenderer&&this._batchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_SELECTED))}},{key:"drawEdgesColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._batchingRenderers.edgesColorRenderer&&this._batchingRenderers.edgesColorRenderer.drawLayer(t,this,eo.EDGES_COLOR_OPAQUE)}},{key:"drawEdgesColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&0!==this._numTransparentLayerPortions&&this._batchingRenderers.edgesColorRenderer&&this._batchingRenderers.edgesColorRenderer.drawLayer(t,this,eo.EDGES_COLOR_TRANSPARENT)}},{key:"drawEdgesHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._batchingRenderers.edgesRenderer&&this._batchingRenderers.edgesRenderer.drawLayer(t,this,eo.EDGES_HIGHLIGHTED)}},{key:"drawEdgesSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._batchingRenderers.edgesRenderer&&this._batchingRenderers.edgesRenderer.drawLayer(t,this,eo.EDGES_SELECTED)}},{key:"drawEdgesXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._batchingRenderers.edgesRenderer&&this._batchingRenderers.edgesRenderer.drawLayer(t,this,eo.EDGES_XRAYED)}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.occlusionRenderer&&this._batchingRenderers.occlusionRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawShadow",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.shadowRenderer&&this._batchingRenderers.shadowRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawPickMesh",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.pickMeshRenderer&&this._batchingRenderers.pickMeshRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.pickDepthRenderer&&this._batchingRenderers.pickDepthRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawPickNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.pickNormalsFlatRenderer&&this._batchingRenderers.pickNormalsFlatRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawSnapInitDepthBuf",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._snapBatchingRenderers.snapDepthBufInitRenderer&&this._snapBatchingRenderers.snapDepthBufInitRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawSnapDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._snapBatchingRenderers.snapDepthRenderer&&this._snapBatchingRenderers.snapDepthRenderer.drawLayer(t,this,eo.PICK))}},{key:"precisionRayPickSurface",value:function(e,t,n,r,i){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;var a=this._state,s=this._portions[e];if(!s)return this.model.error("portion not found: "+e),!1;var o=s.quantizedPositions,l=s.indices,u=a.origin,c=s.offset,f=Jo,p=Zo;f.set(u?Z.subVec3(t,u,$o):t),p.set(n),c&&Z.subVec3(f,c),Z.transformRay(this.model.worldNormalMatrix,f,p,f,p);for(var A=el,d=tl,v=nl,h=!1,I=0,y=rl,m=0,w=l.length;m<w;m+=3){var g=3*l[m],T=3*l[m+1],E=3*l[m+2];if(A[0]=o[g],A[1]=o[g+1],A[2]=o[g+2],d[0]=o[T],d[1]=o[T+1],d[2]=o[T+2],v[0]=o[E],v[1]=o[E+1],v[2]=o[E+2],Z.decompressPosition(A,a.positionsDecodeMatrix),Z.decompressPosition(d,a.positionsDecodeMatrix),Z.decompressPosition(v,a.positionsDecodeMatrix),Z.rayTriangleIntersect(f,p,A,d,v,y)){Z.transformPoint3(this.model.worldMatrix,y,y),c&&Z.addVec3(y,c),u&&Z.addVec3(y,u);var b=Math.abs(Z.lenVec3(Z.subVec3(y,t,[])));(!h||b>I)&&(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<t;e++)"ambient"!==(n=a.lights[e]).type&&(o.push("uniform vec4 lightColor"+e+";"),"dir"===n.type&&o.push("uniform vec3 lightDir"+e+";"),"point"===n.type&&o.push("uniform vec3 lightPos"+e+";"),"spot"===n.type&&(o.push("uniform vec3 lightPos"+e+";"),o.push("uniform vec3 lightDir"+e+";")));for(o.push("vec3 octDecode(vec2 oct) {"),o.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),o.push(" if (v.z < 0.0) {"),o.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);"),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;e<t;e++)if("ambient"!==(n=a.lights[e]).type){if("dir"===n.type)"view"===n.space?o.push("viewLightDir = normalize(lightDir"+e+");"):o.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+e+", 0.0)).xyz);");else if("point"===n.type)"view"===n.space?o.push("viewLightDir = -normalize(lightPos"+e+" - viewPosition.xyz);"):o.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+e+", 0.0)).xyz);");else{if("spot"!==n.type)continue;"view"===n.space?o.push("viewLightDir = normalize(lightDir"+e+");"):o.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+e+", 0.0)).xyz);")}o.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),o.push("reflectedColor += lambertian * (lightColor"+e+".rgb * lightColor"+e+".a);")}return o.push("vec3 rgb = (vec3(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0));"),o.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedColor * rgb), float(color.a) / 255.0);"),o.push("vec4 clipPos = projMatrix * viewPosition;"),r.logarithmicDepthBufferEnabled&&(o.push("vFragDepth = 1.0 + clipPos.w;"),o.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s&&(o.push("vWorldPosition = worldPosition;"),o.push("vFlags = flags;")),o.push("gl_Position = clipPos;"),o.push("}"),o.push("}"),o}},{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 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}}]),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<l;o++)s.push("uniform bool sectionPlaneActive"+o+";"),s.push("uniform vec3 sectionPlanePos"+o+";"),s.push("uniform vec3 sectionPlaneDir"+o+";")}for(this._addMatricesUniformBlockLines(s),s.push("uniform vec4 lightAmbient;"),e=0,t=i.lights.length;e<t;e++){var u=i.lights[e];"ambient"!==u.type&&(s.push("uniform vec4 lightColor"+e+";"),"dir"===u.type&&s.push("uniform vec3 lightDir"+e+";"),"point"===u.type&&s.push("uniform vec3 lightPos"+e+";"),"spot"===u.type&&(s.push("uniform vec3 lightPos"+e+";"),s.push("uniform vec3 lightDir"+e+";")))}if(s.push("in vec4 vViewPosition;"),s.push("in vec4 vColor;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),a){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var c=0,f=r.sectionPlanes.length;c<f;c++)s.push("if (sectionPlaneActive"+c+") {"),s.push(" dist += clamp(dot(-sectionPlaneDir"+c+".xyz, vWorldPosition.xyz - sectionPlanePos"+c+".xyz), 0.0, 1000.0);"),s.push("}");s.push(" if (dist > 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;e<t;e++){var p=i.lights[e];if("ambient"!==p.type){if("dir"===p.type)"view"===p.space?s.push("viewLightDir = normalize(lightDir"+e+");"):s.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+e+", 0.0)).xyz);");else if("point"===p.type)"view"===p.space?s.push("viewLightDir = -normalize(lightPos"+e+" - viewPosition.xyz);"):s.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+e+", 0.0)).xyz);");else{if("spot"!==p.type)continue;"view"===p.space?s.push("viewLightDir = normalize(lightDir"+e+");"):s.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+e+", 0.0)).xyz);")}s.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),s.push("reflectedColor += lambertian * (lightColor"+e+".rgb * lightColor"+e+".a);")}}return s.push("vec4 fragColor = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);"),this._withSAO?(s.push(" float viewportWidth = uSAOParams[0];"),s.push(" float viewportHeight = uSAOParams[1];"),s.push(" float blendCutoff = uSAOParams[2];"),s.push(" float blendFactor = uSAOParams[3];"),s.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),s.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),s.push(" outColor = vec4(fragColor.rgb * ambient, 1.0);")):s.push(" outColor = fragColor;"),n.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),n}(),ol=function(e){I(n,lo);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("// 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vPickColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vViewPosition;"),r.push("vec4 packDepth(const in float depth) {"),r.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),r.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),r.push(" vec4 res = fract(depth * bitShift);"),r.push(" res -= res.xxyz * bitMask;"),r.push(" return res;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vWorldNormal;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return 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<t;e++)a.push("uniform bool sectionPlaneActive"+e+";"),a.push("uniform vec3 sectionPlanePos"+e+";"),a.push("uniform vec3 sectionPlaneDir"+e+";");if(a.push("in vec2 vHighPrecisionZW;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),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<t;e++)a.push("if (sectionPlaneActive"+e+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+e+".xyz, vWorldPosition.xyz - sectionPlanePos"+e+".xyz), 0.0, 1000.0);"),a.push("}");a.push("if (dist > 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vViewNormal;"),r.push("vec3 packNormalToRGB( const in vec3 normal ) {"),r.push(" return normalize( normal ) * 0.5 + 0.5;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vViewNormal;"),r.push("vec3 packNormalToRGB( const in vec3 normal ) {"),r.push(" return normalize( normal ) * 0.5 + 0.5;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = 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;o<l;o++){var u=r.lights[o];"ambient"!==u.type&&(s.push("uniform vec4 lightColor"+o+";"),"dir"===u.type&&s.push("uniform vec3 lightDir"+o+";"),"point"===u.type&&s.push("uniform vec3 lightPos"+o+";"),"spot"===u.type&&(s.push("uniform vec3 lightPos"+o+";"),s.push("uniform vec3 lightDir"+o+";")))}if(s.push("uniform float gammaFactor;"),s.push("vec4 linearToLinear( in vec4 value ) {"),s.push(" return value;"),s.push("}"),s.push("vec4 sRGBToLinear( in vec4 value ) {"),s.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 );"),s.push("}"),s.push("vec4 gammaToLinear( in vec4 value) {"),s.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),s.push("}"),t&&(s.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),s.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),s.push("}")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;"),a&&s.push("in vec4 vClipPosition;");for(var c=0,f=n.sectionPlanes.length;c<f;c++)s.push("uniform bool sectionPlaneActive"+c+";"),s.push("uniform vec3 sectionPlanePos"+c+";"),s.push("uniform vec3 sectionPlaneDir"+c+";")}if(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),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<A;p++)s.push("if (sectionPlaneActive"+p+") {"),s.push(" dist += clamp(dot(-sectionPlaneDir"+p+".xyz, vWorldPosition.xyz - sectionPlanePos"+p+".xyz), 0.0, 1000.0);"),s.push("}");a?(s.push(" if (dist > (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;d<v;d++){var h=r.lights[d];if("ambient"!==h.type){if("dir"===h.type)"view"===h.space?s.push("light.direction = normalize(lightDir"+d+");"):s.push("light.direction = normalize((viewMatrix * vec4(lightDir"+d+", 0.0)).xyz);");else if("point"===h.type)"view"===h.space?s.push("light.direction = normalize(lightPos"+d+" - vViewPosition.xyz);"):s.push("light.direction = normalize((viewMatrix * vec4(lightPos"+d+", 0.0)).xyz);");else{if("spot"!==h.type)continue;"view"===h.space?s.push("light.direction = normalize(lightDir"+d+");"):s.push("light.direction = normalize((viewMatrix * vec4(lightDir"+d+", 0.0)).xyz);")}s.push("light.color = lightColor"+d+".rgb * lightColor"+d+".a;"),s.push("computePBRLighting(light, geometry, material, reflectedLight);")}}return s.push("vec3 emissiveColor = sRGBToLinear(texture(uEmissiveMap, vUV)).rgb;"),s.push("vec3 outgoingLight = (lightAmbient.rgb * lightAmbient.a * baseColor * opacity * rgb) + (reflectedLight.diffuse) + (reflectedLight.specular) + emissiveColor;"),s.push("vec4 fragColor;"),this._withSAO?(s.push(" float viewportWidth = uSAOParams[0];"),s.push(" float viewportHeight = uSAOParams[1];"),s.push(" float blendCutoff = uSAOParams[2];"),s.push(" float blendFactor = uSAOParams[3];"),s.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),s.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),s.push(" fragColor = vec4(outgoingLight.rgb * ambient, opacity);")):s.push(" fragColor = vec4(outgoingLight.rgb, opacity);"),t&&s.push("fragColor = linearToGamma(fragColor, gammaFactor);"),s.push("outColor = fragColor;"),e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),n}(),ml=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 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vWorldNormal;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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<u;l++)o.push("uniform bool sectionPlaneActive"+l+";"),o.push("uniform vec3 sectionPlanePos"+l+";"),o.push("uniform vec3 sectionPlaneDir"+l+";")}for(this._addMatricesUniformBlockLines(o),o.push("uniform vec4 lightAmbient;"),e=0,t=a.lights.length;e<t;e++){var c=a.lights[e];"ambient"!==c.type&&(o.push("uniform vec4 lightColor"+e+";"),"dir"===c.type&&o.push("uniform vec3 lightDir"+e+";"),"point"===c.type&&o.push("uniform vec3 lightPos"+e+";"),"spot"===c.type&&(o.push("uniform vec3 lightPos"+e+";"),o.push("uniform vec3 lightDir"+e+";")))}if(o.push("in vec4 vViewPosition;"),o.push("in vec4 vColor;"),o.push("in vec2 vUV;"),o.push("out vec4 outColor;"),o.push("void main(void) {"),s){o.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),o.push(" if (clippable) {"),o.push(" float dist = 0.0;");for(var f=0,p=i.sectionPlanes.length;f<p;f++)o.push("if (sectionPlaneActive"+f+") {"),o.push(" dist += clamp(dot(-sectionPlaneDir"+f+".xyz, vWorldPosition.xyz - sectionPlanePos"+f+".xyz), 0.0, 1000.0);"),o.push("}");o.push(" if (dist > 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;e<t;e++){var A=a.lights[e];if("ambient"!==A.type){if("dir"===A.type)"view"===A.space?o.push("viewLightDir = normalize(lightDir"+e+");"):o.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+e+", 0.0)).xyz);");else if("point"===A.type)"view"===A.space?o.push("viewLightDir = -normalize(lightPos"+e+" - viewPosition.xyz);"):o.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+e+", 0.0)).xyz);");else{if("spot"!==A.type)continue;"view"===A.space?o.push("viewLightDir = normalize(lightDir"+e+");"):o.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+e+", 0.0)).xyz);")}o.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),o.push("reflectedColor += lambertian * (lightColor"+e+".rgb * lightColor"+e+".a);")}}return o.push("vec4 color = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);"),r?o.push("vec4 colorTexel = color * sRGBToLinear(texture(uColorMap, vUV));"):o.push("vec4 colorTexel = color * texture(uColorMap, vUV);"),o.push("float opacity = color.a;"),this._withSAO?(o.push(" float viewportWidth = uSAOParams[0];"),o.push(" float viewportHeight = uSAOParams[1];"),o.push(" float blendCutoff = uSAOParams[2];"),o.push(" float blendFactor = uSAOParams[3];"),o.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),o.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),o.push(" outColor = vec4(vColor.rgb * colorTexel.rgb * ambient, opacity);")):o.push(" outColor = vec4(vColor.rgb * colorTexel.rgb, opacity);"),r&&o.push("outColor = linearToGamma(outColor, gammaFactor);"),n.logarithmicDepthBufferEnabled&&o.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),o.push("}"),o}}]),n}(),gl=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._pbrRenderer&&!this._pbrRenderer.getValid()&&(this._pbrRenderer.destroy(),this._pbrRenderer=null),this._pbrRendererWithSAO&&!this._pbrRendererWithSAO.getValid()&&(this._pbrRendererWithSAO.destroy(),this._pbrRendererWithSAO=null),this._colorTextureRenderer&&!this._colorTextureRenderer.getValid()&&(this._colorTextureRenderer.destroy(),this._colorTextureRenderer=null),this._colorTextureRendererWithSAO&&!this._colorTextureRendererWithSAO.getValid()&&(this._colorTextureRendererWithSAO.destroy(),this._colorTextureRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=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 al(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new al(this._scene,!0)),this._colorRendererWithSAO}},{key:"flatColorRenderer",get:function(){return this._flatColorRenderer||(this._flatColorRenderer=new sl(this._scene,!1)),this._flatColorRenderer}},{key:"flatColorRendererWithSAO",get:function(){return this._flatColorRendererWithSAO||(this._flatColorRendererWithSAO=new sl(this._scene,!0)),this._flatColorRendererWithSAO}},{key:"pbrRenderer",get:function(){return this._pbrRenderer||(this._pbrRenderer=new yl(this._scene,!1)),this._pbrRenderer}},{key:"pbrRendererWithSAO",get:function(){return this._pbrRendererWithSAO||(this._pbrRendererWithSAO=new yl(this._scene,!0)),this._pbrRendererWithSAO}},{key:"colorTextureRenderer",get:function(){return this._colorTextureRenderer||(this._colorTextureRenderer=new wl(this._scene,!1)),this._colorTextureRenderer}},{key:"colorTextureRendererWithSAO",get:function(){return this._colorTextureRendererWithSAO||(this._colorTextureRendererWithSAO=new wl(this._scene,!0)),this._colorTextureRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ol(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new dl(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new vl(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new ll(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new ul(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new cl(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new pl(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new ml(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new fl(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Al(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new hl(this._scene)),this._shadowRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._pbrRenderer&&this._pbrRenderer.destroy(),this._pbrRendererWithSAO&&this._pbrRendererWithSAO.destroy(),this._colorTextureRenderer&&this._colorTextureRenderer.destroy(),this._colorTextureRendererWithSAO&&this._colorTextureRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}]),e}(),Tl={};var El=Z.vec3(),bl=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(),!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;w<h;w++){var g=this._uSectionPlanes[w];if(g){var T=m.sectionPlanesActivePerLayer[y+w];if(a.uniform1i(g.active,T?1:0),T){var E=I[w];if(o){var b=ge(E.dist,E.dir,o,El);a.uniform3fv(g.pos,b)}else a.uniform3fv(g.pos,E.pos);a.uniform3fv(g.dir,E.dir)}}}a.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,s.positionsDecodeMatrix),this._aModelMatrixCol0.bindArrayBuffer(s.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(s.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(s.modelMatrixCol2Buf),a.vertexAttribDivisor(this._aModelMatrixCol0.location,1),a.vertexAttribDivisor(this._aModelMatrixCol1.location,1),a.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aPosition.bindArrayBuffer(s.positionsBuf),this._aFlags&&(this._aFlags.bindArrayBuffer(s.flagsBuf),a.vertexAttribDivisor(this._aFlags.location,1)),this._aOffset&&(this._aOffset.bindArrayBuffer(s.offsetsBuf),a.vertexAttribDivisor(this._aOffset.location,1)),s.indicesBuf.bind(),a.drawElementsInstanced(a.TRIANGLES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),s.indicesBuf.unbind(),a.vertexAttribDivisor(this._aModelMatrixCol0.location,0),a.vertexAttribDivisor(this._aModelMatrixCol1.location,0),a.vertexAttribDivisor(this._aModelMatrixCol2.location,0),this._aFlags&&a.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&a.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new ft(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._aPosition=n.getAttribute("position"),this._aOffset=n.getAttribute("offset"),this._aFlags=n.getAttribute("flags"),this._aModelMatrixCol0=n.getAttribute("modelMatrixCol0"),this._aModelMatrixCol1=n.getAttribute("modelMatrixCol1"),this._aModelMatrixCol2=n.getAttribute("modelMatrixCol2"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc"),this.uVectorA=n.getLocation("snapVectorA"),this.uInverseVectorAB=n.getLocation("snapInvVectorAB"),this._uLayerNumber=n.getLocation("layerNumber"),this._uCoordinateScaler=n.getLocation("coordinateScaler")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in highp vec3 relativeToOriginPosition;"),r.push("out highp ivec4 outCoords;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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;w<h;w++){var g=this._uSectionPlanes[w];if(g){var T=m.sectionPlanesActivePerLayer[y+w];if(a.uniform1i(g.active,T?1:0),T){var E=I[w];if(o){var b=ge(E.dist,E.dir,o,Dl);a.uniform3fv(g.pos,b)}else a.uniform3fv(g.pos,E.pos);a.uniform3fv(g.dir,E.dir)}}}a.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,s.positionsDecodeMatrix),this._aModelMatrixCol0.bindArrayBuffer(s.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(s.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(s.modelMatrixCol2Buf),a.vertexAttribDivisor(this._aModelMatrixCol0.location,1),a.vertexAttribDivisor(this._aModelMatrixCol1.location,1),a.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aPosition.bindArrayBuffer(s.positionsBuf),this._aFlags.bindArrayBuffer(s.flagsBuf),a.vertexAttribDivisor(this._aFlags.location,1),this._aOffset&&(this._aOffset.bindArrayBuffer(s.offsetsBuf),a.vertexAttribDivisor(this._aOffset.location,1)),"edge"===e.snapMode?(s.edgeIndicesBuf.bind(),a.drawElementsInstanced(a.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0,s.numInstances),s.edgeIndicesBuf.unbind()):a.drawArraysInstanced(a.POINTS,0,s.positionsBuf.numItems,s.numInstances),a.vertexAttribDivisor(this._aModelMatrixCol0.location,0),a.vertexAttribDivisor(this._aModelMatrixCol1.location,0),a.vertexAttribDivisor(this._aModelMatrixCol2.location,0),a.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&a.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new ft(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._aPosition=n.getAttribute("position"),this._aOffset=n.getAttribute("offset"),this._aFlags=n.getAttribute("flags"),this._aModelMatrixCol0=n.getAttribute("modelMatrixCol0"),this._aModelMatrixCol1=n.getAttribute("modelMatrixCol1"),this._aModelMatrixCol2=n.getAttribute("modelMatrixCol2"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc"),this.uVectorA=n.getLocation("snapVectorA"),this.uInverseVectorAB=n.getLocation("snapInvVectorAB"),this._uLayerNumber=n.getLocation("layerNumber"),this._uCoordinateScaler=n.getLocation("coordinateScaler")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in highp vec3 relativeToOriginPosition;"),r.push("out highp ivec4 outCoords;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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;I<d;I+=3)Ol[0]=v[I+0],Ol[1]=v[I+1],Ol[2]=v[I+2],Z.transformPoint4(h,Ol,Sl),Z.transformPoint4(a,Sl,Ol),s?(Z.transformPoint4(s,Ol,Nl),Z.expandAABB3Point3(o,Nl)):Z.expandAABB3Point3(o,Ol);if(this._state.origin){var y=this._state.origin;o[0]+=y[0],o[1]+=y[1],o[2]+=y[2],o[3]+=y[0],o[4]+=y[1],o[5]+=y[2]}Z.expandAABB3(this.aabb,o),this._state.numInstances++;var m=this._portions.length,w={};return this.model.scene.pickSurfacePrecisionEnabled&&(w.matrix=a.slice(),w.inverseMatrix=null,w.normalMatrix=null),this._portions.push(w),this._numPortions++,this.model.numPortions++,m}},{key:"finalize",value:function(){if(!this._finalized){var e=this._state,t=e.geometry,n=e.textureSet,r=this.model.scene.canvas.gl,i=this._colors.length,a=i/4;if(i>0){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;v<h;v+=3)f[0]=a[v],f[1]=a[v+1],f[2]=a[v+2],Z.decompressPosition(f,d),Z.transformPoint3(p,f),Z.transformPoint3(A,f),f[0]+=l,f[1]+=u,f[2]+=c,t(f);else this.model.error("portion not found: "+e)}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.withSAO&&this.model.saoEnabled?t.pbrEnabled&&this.model.pbrEnabled&&this._state.pbrSupported?this._instancingRenderers.pbrRendererWithSAO&&this._instancingRenderers.pbrRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):t.colorTextureEnabled&&this.model.colorTextureEnabled&&this._state.colorTextureSupported?this._instancingRenderers.colorTextureRendererWithSAO&&this._instancingRenderers.colorTextureRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):this._state.normalsBuf?this._instancingRenderers.colorRendererWithSAO&&this._instancingRenderers.colorRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):this._instancingRenderers.flatColorRendererWithSAO&&this._instancingRenderers.flatColorRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):t.pbrEnabled&&this.model.pbrEnabled&&this._state.pbrSupported?this._instancingRenderers.pbrRenderer&&this._instancingRenderers.pbrRenderer.drawLayer(t,this,eo.COLOR_OPAQUE):t.colorTextureEnabled&&this.model.colorTextureEnabled&&this._state.colorTextureSupported?this._instancingRenderers.colorTextureRenderer&&this._instancingRenderers.colorTextureRenderer.drawLayer(t,this,eo.COLOR_OPAQUE):this._state.normalsBuf?this._instancingRenderers.colorRenderer&&this._instancingRenderers.colorRenderer.drawLayer(t,this,eo.COLOR_OPAQUE):this._instancingRenderers.flatColorRenderer&&this._instancingRenderers.flatColorRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"_updateBackfaceCull",value:function(e,t){var n=this.model.backfaces||!this.solid||e.sectioned;if(t.backfaces!==n){var r=t.gl;n?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),t.backfaces=n}}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.pbrEnabled&&this.model.pbrEnabled&&this._state.pbrSupported?this._instancingRenderers.pbrRenderer&&this._instancingRenderers.pbrRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT):t.colorTextureEnabled&&this.model.colorTextureEnabled&&this._state.colorTextureSupported?this._instancingRenderers.colorTextureRenderer&&this._instancingRenderers.colorTextureRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT):this._state.normalsBuf?this._instancingRenderers.colorRenderer&&this._instancingRenderers.colorRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT):this._instancingRenderers.flatColorRenderer&&this._instancingRenderers.flatColorRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT))}},{key:"drawDepth",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.depthRenderer&&this._instancingRenderers.depthRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.normalsRenderer&&this._instancingRenderers.normalsRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.silhouetteRenderer&&this._instancingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_XRAYED))}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.silhouetteRenderer&&this._instancingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_HIGHLIGHTED))}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.silhouetteRenderer&&this._instancingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_SELECTED))}},{key:"drawEdgesColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._instancingRenderers.edgesColorRenderer&&this._instancingRenderers.edgesColorRenderer.drawLayer(t,this,eo.EDGES_COLOR_OPAQUE)}},{key:"drawEdgesColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._instancingRenderers.edgesColorRenderer&&this._instancingRenderers.edgesColorRenderer.drawLayer(t,this,eo.EDGES_COLOR_TRANSPARENT)}},{key:"drawEdgesXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._instancingRenderers.edgesRenderer&&this._instancingRenderers.edgesRenderer.drawLayer(t,this,eo.EDGES_XRAYED)}},{key:"drawEdgesHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._instancingRenderers.edgesRenderer&&this._instancingRenderers.edgesRenderer.drawLayer(t,this,eo.EDGES_HIGHLIGHTED)}},{key:"drawEdgesSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._instancingRenderers.edgesRenderer&&this._instancingRenderers.edgesRenderer.drawLayer(t,this,eo.EDGES_SELECTED)}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.occlusionRenderer&&this._instancingRenderers.occlusionRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawShadow",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.shadowRenderer&&this._instancingRenderers.shadowRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawPickMesh",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.pickMeshRenderer&&this._instancingRenderers.pickMeshRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.pickDepthRenderer&&this._instancingRenderers.pickDepthRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawPickNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.pickNormalsRenderer&&this._instancingRenderers.pickNormalsRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawSnapInitDepthBuf",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._snapInstancingRenderers.snapDepthBufInitRenderer&&this._snapInstancingRenderers.snapDepthBufInitRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawSnapDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._snapInstancingRenderers.snapDepthRenderer&&this._snapInstancingRenderers.snapDepthRenderer.drawLayer(t,this,eo.PICK))}},{key:"precisionRayPickSurface",value:function(e,t,n,r,i){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;var a=this._state.geometry,s=this._state,o=this._portions[e];if(!o)return this.model.error("portion not found: "+e),!1;o.inverseMatrix||(o.inverseMatrix=Z.inverseMat4(o.matrix,Z.mat4())),i&&!o.normalMatrix&&(o.normalMatrix=Z.transposeMat4(o.inverseMatrix,Z.mat4()));var l=a.quantizedPositions,u=a.indices,c=s.origin,f=o.offset,p=xl,A=Ml;p.set(c?Z.subVec3(t,c,Fl):t),A.set(n),f&&Z.subVec3(p,f),Z.transformRay(this.model.worldNormalMatrix,p,A,p,A),Z.transformRay(o.inverseMatrix,p,A,p,A);for(var d=Hl,v=Ul,h=Gl,I=!1,y=0,m=kl,w=0,g=u.length;w<g;w+=3){var T=3*u[w+0],E=3*u[w+1],b=3*u[w+2];d[0]=l[T],d[1]=l[T+1],d[2]=l[T+2],v[0]=l[E],v[1]=l[E+1],v[2]=l[E+2],h[0]=l[b],h[1]=l[b+1],h[2]=l[b+2];var D=s.geometry.positionsDecodeMatrix;if(Z.decompressPosition(d,D),Z.decompressPosition(v,D),Z.decompressPosition(h,D),Z.rayTriangleIntersect(p,A,d,v,h,m)){Z.transformPoint3(o.matrix,m,m),Z.transformPoint3(this.model.worldMatrix,m,m),f&&Z.addVec3(m,f),c&&Z.addVec3(m,c);var P=Math.abs(Z.lenVec3(Z.subVec3(m,t,[])));(!I||P>y)&&(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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("uniform vec4 color;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = 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+t<this._buffer.maxIndices}},{key:"createPortion",value:function(e){if(this._finalized)throw"Already finalized";var t=e.positions,n=e.positionsCompressed,r=e.indices,i=e.color,a=e.opacity,s=e.meshMatrix,o=e.worldMatrix,l=e.worldAABB;e.pickColor;var u,c=this._buffer,f=c.positions.length/3;if(this._preCompressedPositionsExpected){if(!n)throw"positionsCompressed expected";u=n.length/3;for(var p=0,A=n.length;p<A;p++)c.positions.push(n[p]);var d=pn.getPositionsBounds(n),v=pn.decompressPosition(d.min,this._state.positionsDecodeMatrix,[]),h=pn.decompressPosition(d.max,this._state.positionsDecodeMatrix,[]);l[0]=v[0],l[1]=v[1],l[2]=v[2],l[3]=h[0],l[4]=h[1],l[5]=h[2],o&&(Z.AABB3ToOBB3(l,Jl),Z.transformOBB3(o,Jl),Z.OBB3ToAABB3(Jl,l))}else{if(!t)throw"positions expected";u=t.length/3;for(var I=t.length,y=c.positions.length,m=0,w=t.length;m<w;m++)c.positions.push(t[m]);if(s)for(var g=y,T=y+I;g<T;g+=3)Yl[0]=c.positions[g+0],Yl[1]=c.positions[g+1],Yl[2]=c.positions[g+2],Z.transformPoint4(s,Yl,Xl),c.positions[g+0]=Xl[0],c.positions[g+1]=Xl[1],c.positions[g+2]=Xl[2],Z.expandAABB3Point3(this._modelAABB,Xl),o?(Z.transformPoint4(o,Xl,ql),Z.expandAABB3Point3(l,ql)):Z.expandAABB3Point3(l,Xl);else for(var E=y,b=y+I;E<b;E+=3)Yl[0]=c.positions[E+0],Yl[1]=c.positions[E+1],Yl[2]=c.positions[E+2],Z.expandAABB3Point3(this._modelAABB,Yl),o?(Z.transformPoint4(o,Yl,Xl),Z.expandAABB3Point3(l,Xl)):Z.expandAABB3Point3(l,Yl)}if(this._state.origin){var D=this._state.origin;l[0]+=D[0],l[1]+=D[1],l[2]+=D[2],l[3]+=D[0],l[4]+=D[1],l[5]+=D[2]}if(Z.expandAABB3(this.aabb,l),i)for(var P=i[0],R=i[1],C=i[2],_=a,B=0;B<u;B++)c.colors.push(P),c.colors.push(R),c.colors.push(C),c.colors.push(_);if(r)for(var O=0,S=r.length;O<S;O++)c.indices.push(r[O]+f);if(this.model.scene.entityOffsetsEnabled)for(var N=0;N<u;N++)c.offsets.push(0),c.offsets.push(0),c.offsets.push(0);var L=this._portions.length/2;return this._portions.push(f),this._portions.push(u),this._numPortions++,this.model.numPortions++,this._numVerts+=u,L}},{key:"finalize",value:function(){if(!this._finalized){var e=this._state,t=this.model.scene.canvas.gl,n=this._buffer;if(n.positions.length>0)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;c<i;c+=4)a[c+0]=s,a[c+1]=o,a[c+2]=l,a[c+3]=u;this._state.colorsBuf.setData(a,r,i)}},{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){var r=arguments.length>3&&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;m<w;m++){var g=0;g|=i,g|=a<<4,g|=I<<12,g|=y<<16,this._deferredFlagValues[m]=g}}else if(this._state.flagsBuf){for(var T=this._scratchMemory.getFloat32Array(c),E=0;E<c;E++){var b=0;b|=i,b|=a<<4,b|=I<<12,b|=y<<16,T[E]=b}this._state.flagsBuf.setData(T,u,c)}}},{key:"_setDeferredFlags",value:function(){this._deferredFlagValues&&(this._state.flagsBuf.setData(this._deferredFlagValues),this._deferredFlagValues=null)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";if(this.model.scene.entityOffsetsEnabled){for(var n=2*e,r=3*this._portions[n],i=3*this._portions[n+1],a=this._scratchMemory.getFloat32Array(i),s=t[0],o=t[1],l=t[2],u=0;u<i;u+=3)a[u+0]=s,a[u+1]=o,a[u+2]=l;this._state.offsetsBuf.setData(a,r,i)}else 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._batchingRenderers.colorRenderer&&this._batchingRenderers.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._batchingRenderers.colorRenderer&&this._batchingRenderers.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._batchingRenderers.silhouetteRenderer&&this._batchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._batchingRenderers.silhouetteRenderer&&this._batchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._batchingRenderers.silhouetteRenderer&&this._batchingRenderers.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:"drawPickMesh",value:function(e){}},{key:"drawPickDepths",value:function(e){}},{key:"drawPickNormals",value:function(e){}},{key:"drawOcclusion",value:function(e){}},{key:"drawShadow",value:function(e){}},{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.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicesBuf=null),e.destroy()}}]),e}(),$l=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,{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 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<t;e++)a.push("uniform bool sectionPlaneActive"+e+";"),a.push("uniform vec3 sectionPlanePos"+e+";"),a.push("uniform vec3 sectionPlaneDir"+e+";");if(a.push("in vec4 vColor;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),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<t;e++)a.push("if (sectionPlaneActive"+e+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+e+".xyz, vWorldPosition.xyz - sectionPlanePos"+e+".xyz), 0.0, 1000.0);"),a.push("}");a.push("if (dist > 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("uniform vec4 color;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = 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;f<c;f+=4)au[0]=u[f+0],au[1]=u[f+1],au[2]=u[f+2],Z.transformPoint4(r,au,su),i?(Z.transformPoint4(i,su,ou),Z.expandAABB3Point3(a,ou)):Z.expandAABB3Point3(a,su);if(this._state.origin){var p=this._state.origin;a[0]+=p[0],a[1]+=p[1],a[2]+=p[2],a[3]+=p[0],a[4]+=p[1],a[5]+=p[2]}Z.expandAABB3(this.aabb,a),this._state.numInstances++;var A=this._portions.length;return this._portions.push({}),this._numPortions++,this.model.numPortions++,A}},{key:"finalize",value:function(){if(this._finalized)throw"Already finalized";var e=this.model.scene.canvas.gl,t=this._colors.length,n=t/4;if(t>0){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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return 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<t;e++)a.push("uniform bool sectionPlaneActive"+e+";"),a.push("uniform vec3 sectionPlanePos"+e+";"),a.push("uniform vec3 sectionPlaneDir"+e+";");if(a.push("uniform vec4 color;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),n.pointsMaterial.roundPoints&&(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(" }")),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<t;e++)a.push("if (sectionPlaneActive"+e+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+e+".xyz, vWorldPosition.xyz - sectionPlanePos"+e+".xyz), 0.0, 1000.0);"),a.push("}");a.push(" if (dist > 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vPickColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vViewPosition;"),r.push("vec4 packDepth(const in float depth) {"),r.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),r.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),r.push(" vec4 res = fract(depth * bitShift);"),r.push(" res -= res.xxyz * bitMask;"),r.push(" return res;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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;A<d;A++)f.positions.push(r[A]);var v=pn.getPositionsBounds(r),h=pn.decompressPosition(v.min,this._state.positionsDecodeMatrix,yu),I=pn.decompressPosition(v.max,this._state.positionsDecodeMatrix,mu);u[0]=h[0],u[1]=h[1],u[2]=h[2],u[3]=I[0],u[4]=I[1],u[5]=I[2],l&&(Z.AABB3ToOBB3(u,Eu),Z.transformOBB3(l,Eu),Z.OBB3ToAABB3(Eu,u)),t=r.length/3}else{if(!n)throw"positions expected";t=n.length/3;for(var y=n.length,m=f.positions.length,w=0,g=n.length;w<g;w++)f.positions.push(n[w]);if(o)for(var T=m,E=m+y;T<E;T+=3)wu[0]=f.positions[T+0],wu[1]=f.positions[T+1],wu[2]=f.positions[T+2],Z.transformPoint4(o,wu,gu),f.positions[T+0]=gu[0],f.positions[T+1]=gu[1],f.positions[T+2]=gu[2],Z.expandAABB3Point3(this._modelAABB,gu),l?(Z.transformPoint4(l,gu,Tu),Z.expandAABB3Point3(u,Tu)):Z.expandAABB3Point3(u,gu);else for(var b=m,D=m+y;b<D;b+=3)wu[0]=f.positions[b+0],wu[1]=f.positions[b+1],wu[2]=f.positions[b+2],Z.expandAABB3Point3(this._modelAABB,wu),l?(Z.transformPoint4(l,wu,gu),Z.expandAABB3Point3(u,gu)):Z.expandAABB3Point3(u,wu)}if(this._state.origin){var P=this._state.origin;u[0]+=P[0],u[1]+=P[1],u[2]+=P[2],u[3]+=P[0],u[4]+=P[1],u[5]+=P[2]}if(Z.expandAABB3(this.aabb,u),a)for(var R=0,C=a.length;R<C;R++)f.colors.push(a[R]);else if(s)for(var _=0,B=s.length;_<B;_++)f.colors.push(255*s[_]);else if(i)for(var O=i[0],S=i[1],N=i[2],L=0;L<t;L++)f.colors.push(O),f.colors.push(S),f.colors.push(N),f.colors.push(1);for(var x=f.pickColors.length,M=x,F=x+4*t;M<F;M+=4)f.pickColors.push(c[0]),f.pickColors.push(c[1]),f.pickColors.push(c[2]),f.pickColors.push(c[3]);if(this.model.scene.entityOffsetsEnabled)for(var H=0;H<t;H++)f.offsets.push(0),f.offsets.push(0),f.offsets.push(0);var U=this._portions.length/2;return this._portions.push(p),this._portions.push(t),this._numPortions++,this.model.numPortions++,U}},{key:"finalize",value:function(){if(!this._finalized){var e=this._state,t=this.model.scene.canvas.gl,n=this._buffer;if(n.positions.length>0)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;u<i;u+=4)a[u+0]=s,a[u+1]=o,a[u+2]=l;this._state.colorsBuf.setData(a,r,i)}},{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,i,a=2*e,s=this._portions[a],o=this._portions[a+1],l=this._scratchMemory.getFloat32Array(o),u=!!(t&Te),c=!!(t&Re),f=!!(t&Ce),p=!!(t&_e),A=!!(t&be),d=!!(t&Ee);r=!u||d||c||f&&!this.model.scene.highlightMaterial.glowThrough||p&&!this.model.scene.selectedMaterial.glowThrough?eo.NOT_RENDERED:n?eo.COLOR_TRANSPARENT:eo.COLOR_OPAQUE,i=!u||d?eo.NOT_RENDERED:p?eo.SILHOUETTE_SELECTED:f?eo.SILHOUETTE_HIGHLIGHTED:c?eo.SILHOUETTE_XRAYED:eo.NOT_RENDERED;for(var v=u&&!d&&A?eo.PICK:eo.NOT_RENDERED,h=t&De?1:0,I=0;I<o;I++){var y=0;y|=r,y|=i<<4,y|=v<<12,y|=h<<16,l[I]=y}this._state.flagsBuf.setData(l,s)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";if(this.model.scene.entityOffsetsEnabled){for(var n=2*e,r=3*this._portions[n],i=3*this._portions[n+1],a=this._scratchMemory.getFloat32Array(i),s=t[0],o=t[1],l=t[2],u=0;u<i;u+=3)a[u+0]=s,a[u+1]=o,a[u+2]=l;this._state.offsetsBuf.setData(a,r,i)}else 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._pointsBatchingRenderers.colorRenderer&&this._pointsBatchingRenderers.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._pointsBatchingRenderers.colorRenderer&&this._pointsBatchingRenderers.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._pointsBatchingRenderers.silhouetteRenderer&&this._pointsBatchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsBatchingRenderers.silhouetteRenderer&&this._pointsBatchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsBatchingRenderers.silhouetteRenderer&&this._pointsBatchingRenderers.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:"drawPickMesh",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsBatchingRenderers.pickMeshRenderer&&this._pointsBatchingRenderers.pickMeshRenderer.drawLayer(t,this,eo.PICK)}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsBatchingRenderers.pickDepthRenderer&&this._pointsBatchingRenderers.pickDepthRenderer.drawLayer(t,this,eo.PICK)}},{key:"drawPickNormals",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsBatchingRenderers.occlusionRenderer&&this._pointsBatchingRenderers.occlusionRenderer.drawLayer(t,this,eo.COLOR_OPAQUE)}},{key:"drawShadow",value:function(e,t){}},{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.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}]),e}(),Du=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,{incrementDrawState:!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 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vPickColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vViewPosition;"),r.push("vec4 packDepth(const in float depth) {"),r.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),r.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),r.push(" vec4 res = fract(depth * bitShift);"),r.push(" res -= res.xxyz * bitMask;"),r.push(" return res;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return 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<t;e++)a.push("uniform bool sectionPlaneActive"+e+";"),a.push("uniform vec3 sectionPlanePos"+e+";"),a.push("uniform vec3 sectionPlaneDir"+e+";");if(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("const float shiftRight8 = 1.0 / 256.;"),a.push("vec4 packDepthToRGBA( const in float v ) {"),a.push(" vec4 r = vec4( fract( v * packFactors ), v );"),a.push(" r.yzw -= r.xyz * shiftRight8;"),a.push(" return r * packUpScale;"),a.push("}"),a.push("out vec4 outColor;"),a.push("void main(void) {"),n.pointsMaterial.roundPoints&&(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(" }")),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<t;e++)a.push("if (sectionPlaneActive"+e+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+e+".xyz, vWorldPosition.xyz - sectionPlanePos"+e+".xyz), 0.0, 1000.0);"),a.push("}");a.push("if (dist > 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vViewNormal;"),r.push("vec3 packNormalToRGB( const in vec3 normal ) {"),r.push(" return normalize( normal ) * 0.5 + 0.5;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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(" }"),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<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = 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;o<s;o+=4)Mu[0]=a[o+0],Mu[1]=a[o+1],Mu[2]=a[o+2],Z.transformPoint4(t,Mu,Fu),n?(Z.transformPoint4(n,Fu,Hu),Z.expandAABB3Point3(r,Hu)):Z.expandAABB3Point3(r,Fu);if(this._state.origin){var l=this._state.origin;r[0]+=l[0],r[1]+=l[1],r[2]+=l[2],r[3]+=l[0],r[4]+=l[1],r[5]+=l[2]}Z.expandAABB3(this.aabb,r),this._state.numInstances++;var u=this._portions.length;return this._portions.push({}),this._numPortions++,this.model.numPortions++,u}},{key:"finalize",value:function(){if(this._finalized)throw"Already finalized";var e=this.model.scene.canvas.gl,t=this._pickColors.length/4;if(t>0){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;t<n;t+=2){var r=this.handlers[t],i=this.handlers[t+1];if(r.global&&(r.lastIndex=0),r.test(e))return i}return null}}]),e}(),Wu=new Qu,zu=function(){function e(t){b(this,e),this.manager=void 0!==t?t:Wu,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}return P(e,[{key:"load",value:function(){}},{key:"loadAsync",value:function(e,t){var n=this;return new Promise((function(r,i){n.load(e,r,t,i)}))}},{key:"parse",value:function(){}},{key:"setCrossOrigin",value:function(e){return this.crossOrigin=e,this}},{key:"setWithCredentials",value:function(e){return this.withCredentials=e,this}},{key:"setPath",value:function(e){return this.path=e,this}},{key:"setResourcePath",value:function(e){return this.resourcePath=e,this}},{key:"setRequestHeader",value:function(e){return this.requestHeader=e,this}}]),e}(),Ku={},Yu=function(e){I(n,zu);var t=m(n);function n(e){return b(this,n),t.call(this,e)}return P(n,[{key:"load",value:function(e,t,n,r){var i=this;void 0===e&&(e=""),void 0!==this.path&&(e=this.path+e),e=this.manager.resolveURL(e);var a=ju.get(e);if(void 0!==a)return this.manager.itemStart(e),setTimeout((function(){t&&t(a),i.manager.itemEnd(e)}),0),a;if(void 0===Ku[e]){Ku[e]=[],Ku[e].push({onLoad:t,onProgress:n,onError:r});var s=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),o=this.mimeType,l=this.responseType;fetch(s).then((function(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;var n=Ku[e],r=t.body.getReader(),i=t.headers.get("Content-Length"),a=i?parseInt(i):0,s=0!==a,o=0,l=new ReadableStream({start:function(e){!function t(){r.read().then((function(r){var i=r.done,l=r.value;if(i)e.close();else{o+=l.byteLength;for(var u=new ProgressEvent("progress",{lengthComputable:s,loaded:o,total:a}),c=0,f=n.length;c<f;c++){var p=n[c];p.onProgress&&p.onProgress(u)}e.enqueue(l),t()}}))}()}});return new Response(l)}throw Error('fetch for "'.concat(t.url,'" responded with ').concat(t.status,": ").concat(t.statusText))})).then((function(e){switch(l){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((function(e){return(new DOMParser).parseFromString(e,o)}));case"json":return e.json();default:if(void 0===o)return e.text();var t=/charset="?([^;"\s]*)"?/i.exec(o),n=t&&t[1]?t[1].toLowerCase():void 0,r=new TextDecoder(n);return e.arrayBuffer().then((function(e){return r.decode(e)}))}})).then((function(t){ju.add(e,t);var n=Ku[e];delete Ku[e];for(var r=0,i=n.length;r<i;r++){var a=n[r];a.onLoad&&a.onLoad(t)}})).catch((function(t){var n=Ku[e];if(void 0===n)throw i.manager.itemError(e),t;delete Ku[e];for(var r=0,a=n.length;r<a;r++){var s=n[r];s.onError&&s.onError(t)}i.manager.itemError(e)})).finally((function(){i.manager.itemEnd(e)})),this.manager.itemStart(e)}else Ku[e].push({onLoad:t,onProgress:n,onError:r})}},{key:"setResponseType",value:function(e){return this.responseType=e,this}},{key:"setMimeType",value:function(e){return this.mimeType=e,this}}]),n}(),Xu=function(){function e(){var t=arguments.length>0&&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;e<this.pool;e++)if(!(this.workerStatus&1<<e))return e;return-1}},{key:"_onMessage",value:function(e,t){var n=this.workersResolve[e];if(n&&n(t),this.queue.length){var r=this.queue.shift(),i=r.resolve,a=r.msg,s=r.transfer;this.workersResolve[e]=i,this.workers[e].postMessage(a,s)}else this.workerStatus^=1<<e}},{key:"setWorkerCreator",value:function(e){this.workerCreator=e}},{key:"setWorkerLimit",value:function(e){this.pool=e}},{key:"postMessage",value:function(e,t){var n=this;return new Promise((function(r){var i=n._getIdleWorker();-1!==i?(n._initWorker(i),n.workerStatus|=1<<i,n.workersResolve[i]=r,n.workers[i].postMessage(e,t)):n.queue.push({resolve:r,msg:e,transfer:t})}))}},{key:"destroy",value:function(){this.workers.forEach((function(e){return e.terminate()})),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}]),e}(),qu=0,Ju=function(){function e(t){var n=t.viewer,r=t.transcoderPath,i=t.workerLimit;b(this,e),this._transcoderPath=r||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new Xu,this._workerSourceURL="",i&&this._workerPool.setWorkerLimit(i);var a=n.capabilities;this._workerConfig={astcSupported:a.astcSupported,etc1Supported:a.etc1Supported,etc2Supported:a.etc2Supported,dxtSupported:a.dxtSupported,bptcSupported:a.bptcSupported,pvrtcSupported:a.pvrtcSupported},this._supportedFileTypes=["xkt2"]}return P(e,[{key:"_init",value:function(){var t=this;if(!this._transcoderPending){var n=new Yu;n.setPath(this._transcoderPath),n.setWithCredentials(this.withCredentials);var r=n.loadAsync("basis_transcoder.js"),i=new Yu;i.setPath(this._transcoderPath),i.setResponseType("arraybuffer"),i.setWithCredentials(this.withCredentials);var a=i.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([r,a]).then((function(n){var r=p(n,2),i=r[0],a=r[1],s=e.BasisWorker.toString(),o=["/* constants */","let _EngineFormat = "+JSON.stringify(e.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(e.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(e.BasisFormat),"/* basis_transcoder.js */",i,"/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join("\n");t._workerSourceURL=URL.createObjectURL(new Blob([o])),t._transcoderBinary=a,t._workerPool.setWorkerCreator((function(){var e=new Worker(t._workerSourceURL),n=t._transcoderBinary.slice(0);return e.postMessage({type:"init",config:t._workerConfig,transcoderBinary:n},[n]),e}))})),qu>0&&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<A.length;d++){var v=A[d];if(e[v.if]&&(v.basisFormat.includes(t)&&!(c&&v.transcoderFormat.length<2)&&(!v.needsPowerOfTwo||u(n)&&u(s))))return{transcoderFormat:f=v.transcoderFormat[c?1:0],engineFormat:p=v.engineFormat[c?1:0]}}return console.warn("KTX2TextureTranscoder: No suitable compressed texture format found. Decoding to RGBA32."),f=i.RGBA32,p=r.RGBAFormat,{transcoderFormat:f,engineFormat:p}}(f,p,A,v),m=y.transcoderFormat,w=y.engineFormat;if(!p||!A||!d)throw c(),new Error("KTX2TextureTranscoder: Invalid texture");if(!s.startTranscoding())throw c(),new Error("KTX2TextureTranscoder: .startTranscoding failed");for(var g=[],T=0;T<d;T++){var E=s.getImageLevelInfo(T,0,0),b=E.origWidth,D=E.origHeight,P=new Uint8Array(s.getImageTranscodedSizeInBytes(T,0,0,m));if(!s.transcodeImage(P,T,0,0,m,0,-1,-1))throw c(),new Error("KTX2TextureTranscoder: .transcodeImage failed.");g.push({data:P,width:b,height:D})}return c(),{width:p,height:A,hasAlpha:v,mipmaps:g,format:w,dfdTransferFn:h,dfdFlags:I}}(f.buffers[0]),s=t.width,c=t.height,p=t.hasAlpha,A=t.mipmaps,d=t.format,v=t.dfdTransferFn,h=t.dfdFlags,I=[],y=0;y<A.length;++y)I.push(A[y].data.buffer);self.postMessage({type:"transcode",id:f.id,width:s,height:c,hasAlpha:p,mipmaps:A,format:d,dfdTransferFn:v,dfdFlags:h},I)}catch(e){console.error("[KTX2TextureTranscoder.BasisWorker]: ".concat(e)),self.postMessage({type:"error",id:f.id,error:e.message})}}))}}));var s=[{if:"astcSupported",basisFormat:[a.UASTC_4x4],transcoderFormat:[i.ASTC_4x4,i.ASTC_4x4],engineFormat:[r.RGBA_ASTC_4x4_Format,r.RGBA_ASTC_4x4_Format],priorityETC1S:1/0,priorityUASTC:1,needsPowerOfTwo:!1},{if:"bptcSupported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[i.BC7_M5,i.BC7_M5],engineFormat:[r.RGBA_BPTC_Format,r.RGBA_BPTC_Format],priorityETC1S:3,priorityUASTC:2,needsPowerOfTwo:!1},{if:"dxtSupported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[i.BC1,i.BC3],engineFormat:[r.RGB_S3TC_DXT1_Format,r.RGBA_S3TC_DXT5_Format],priorityETC1S:4,priorityUASTC:5,needsPowerOfTwo:!1},{if:"etc2Supported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[i.ETC1,i.ETC2],engineFormat:[r.RGB_ETC2_Format,r.RGBA_ETC2_EAC_Format],priorityETC1S:1,priorityUASTC:3,needsPowerOfTwo:!1},{if:"etc1Supported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[i.ETC1],engineFormat:[r.RGB_ETC1_Format],priorityETC1S:2,priorityUASTC:4,needsPowerOfTwo:!1},{if:"pvrtcSupported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[i.PVRTC1_4_RGB,i.PVRTC1_4_RGBA],engineFormat:[r.RGB_PVRTC_4BPPV1_Format,r.RGBA_PVRTC_4BPPV1_Format],priorityETC1S:5,priorityUASTC:6,needsPowerOfTwo:!0}],o=s.sort((function(e,t){return e.priorityETC1S-t.priorityETC1S})),l=s.sort((function(e,t){return e.priorityUASTC-t.priorityUASTC}));function u(e){return e<=2||0==(e&e-1)&&0!==e}};var Zu={};function $u(e){var t=e.scene.id,n=Zu[t];return n||(n=new Ju({viewer:e}),Zu[t]=n,e.scene.on("destroyed",(function(){delete Zu[t],n.destroy()}))),n}
10
+ 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;n<r;n++)if(t[e.meshIds[n]].geometryId)return!0;return!1}(a))return i.push(n),"continue";var s=Z.collapseAABB3(),o=0;a.meshIds.forEach((function(e){var n,r,i=t[e];if(i.positionsCompressed){var a=pn.getPositionsBounds(i.positionsCompressed);n=pn.decompressPosition(a.min,i.positionsDecodeMatrix,[]),r=pn.decompressPosition(a.max,i.positionsDecodeMatrix,[])}else{var l=pn.getPositionsBounds(i.positions);n=l.min,r=l.max}n[0]+=i.origin[0],n[1]+=i.origin[1],n[2]+=i.origin[2],r[0]+=i.origin[0],r[1]+=i.origin[1],r[2]+=i.origin[2],Z.expandAABB3Point3(s,n),Z.expandAABB3Point3(s,r),o+=i.numPrimitives})),r[n]={aabb:s,numPrimitives:o,entityId:a.id}},s=0;s<n;s++)a(s);var o,l=[],u={};if(Object.keys(r).length>0){o=function(e){for(var t=[],n=0,r=e.length;n<r;n++){var i=e[n];i&&t.push({minX:i.aabb[0],minY:i.aabb[1],minZ:i.aabb[2],maxX:i.aabb[3],maxY:i.aabb[4],maxZ:i.aabb[5],entity:{id:n,xeokitId:i.entityId,meshes:[{numPrimitives:i.numPrimitives}]},numPrimitives:i.numPrimitives})}var a=new Qn(4);return a.load(t),a}(r);var c=Wn({aabbTree:o});l=c.orderedEntityIds,u=c.clusteringResult.entityIdToClusterIdMapping}return{orderedClusteredIndexes:l,entityIdToClusterIdMapping:u,instancedIndexes:i,rTreeBasedAabbTree:o}}for(var Kn=Z.vec3(),Yn=180/Math.PI,Xn=new Float32Array(262144),qn=-256;qn<256;qn++)for(var Jn=-256;Jn<256;Jn++){var Zn=(qn+256<<9)+(Jn+256),$n=Math.max(Math.abs(qn),Math.abs(Jn));Xn[Zn]=Math.atan2(qn/$n,Jn/$n)}function er(e,t){var n=256/Math.max(Math.abs(e),Math.abs(t)),r=Math.round(e*n)+255,i=Math.round(t*n)+255;return Xn[(r<<9)+i]}var tr=function(){function e(){b(this,e),this._aabbTree=null,this._orderedMeshList=[],this._orderedEntityList=[],this._frustumProps={dirty:!0,wMultiply:1,hMultiply:1},this._cullFrame=0,this.finalized=!1}return P(e,[{key:"initializeVFCState",value:function(e,t){if(this.finalized)throw"Already finalized";var n=zn(e,t);this._aabbTree=n.rTreeBasedAabbTree;for(var r=0,i=n.orderedClusteredIndexes.length;r<i;r++){for(var a=n.orderedClusteredIndexes[r],s=n.entityIdToClusterIdMapping[a],o=e[a],l=[],u=0,c=o.meshIds.length;u<c;u++){var f=o.meshIds[u];t[f].id=this._orderedMeshList.length,l.push(this._orderedMeshList.length),this._orderedMeshList.push({clusterNumber:s,mesh:t[f]})}o.meshIds=l,this._orderedEntityList.push(o)}for(var p=0,A=n.instancedIndexes.length;p<A;p++){for(var d=e[n.instancedIndexes[p]],v=[],h=0,I=d.meshIds.length;h<I;h++){var y=d.meshIds[h];t[y].id=this._orderedMeshList.length,v.push(this._orderedMeshList.length),this._orderedMeshList.push({clusterNumber:99999,mesh:t[y]})}d.meshIds=v,this._orderedEntityList.push(d)}}},{key:"finalize",value:function(e,t){if(this.finalized)throw"Already finalized";for(var n=-1,r=0,i=this._orderedMeshList.length;r<i;r++){var a=this._orderedMeshList[r],s=a.clusterNumber,o=a.mesh;-1!==n&&n!==s&&t.call(e),e._createMesh(o),n=s}for(var l=0,u=this._orderedEntityList.length;l<u;l++)e._createEntity(this._orderedEntityList[l]);this._orderedMeshList=[],this._orderedEntityList=[],this.finalized=!0}},{key:"applyViewFrustumCulling",value:function(e){if(!this.finalized)throw"Not finalized";if(this._aabbTree){this._canvasElement||(this._canvasElement=e.scene.canvas.canvas),this._camera||(this._camera=e.scene.camera),this._ensureFrustumPropsUpdated(e),this._initializeCullingDataIfNeeded(e);var t=this._searchVisibleNodesWithFrustumCulling();this._cullFrame++,this._markVisibleFrameOfVisibleNodes(t,this._cullFrame),this._cullNonVisibleNodes(e,this._cullFrame)}}},{key:"_initializeCullingDataIfNeeded",value:function(e){if(!this._internalNodesList&&this._aabbTree){var t=this._aabbTree.all(),n=0;t.forEach((function(e){n=Math.max(n,e.entity.id)}));var r=new Array(n+1);t.forEach((function(t){r[t.entity.id]=e.objects[t.entity.xeokitId]})),this._internalNodesList=r,this._lastVisibleFrameOfNodes=new Array(r.length),this._lastVisibleFrameOfNodes.fill(0)}}},{key:"_searchVisibleNodesWithFrustumCulling",value:function(){var e=this;return this._aabbTree.searchCustom((function(t,n){return e._aabbIntersectsCameraFrustum(t,n)}),(function(t){return e._aabbContainedInCameraFrustum(t)}))}},{key:"_markVisibleFrameOfVisibleNodes",value:function(e,t){for(var n=this._lastVisibleFrameOfNodes,r=0,i=e.length;r<i;r++)n[e[r].entity.id]=t}},{key:"_cullNonVisibleNodes",value:function(e,t){for(var n=this._internalNodesList,r=this._lastVisibleFrameOfNodes,i=0,a=n.length;i<a;i++)n[i]&&(n[i].culledVFC=r[i]!==t)}},{key:"_getPointsForBBox",value:function(e){for(var t=[],n=0;n<8;n++)t.push(new Float32Array([1&n?e.maxX:e.minX,2&n?e.maxY:e.minY,4&n?e.maxZ:e.minZ]));return t}},{key:"_aabbIntersectsCameraFrustum",value:function(e,t){if(t)return!0;if("ortho"===this._camera.projection)return this._frustumProps.dirty=!1,!0;var n=this._aabbIntersectsCameraFrustum_internal(e);return!!((4096&n||!(1&n||2&n)||1&n)&&(8192&n||!(16&n||32&n)||16&n)&&(16384&n||!(256&n||512&n)||256&n))}},{key:"_aabbContainedInCameraFrustum",value:function(e){if("ortho"===this._camera.projection)return this._frustumProps.dirty=!1,!0;var t=e._check;return 1&t&&16&t&&256&t}},{key:"_ensureFrustumPropsUpdated",value:function(e){var t=Math.min(this._canvasElement.width,this._canvasElement.height);this._frustumProps.wMultiply=this._canvasElement.width/t,this._frustumProps.hMultiply=this._canvasElement.height/t;var n=this._canvasElement.width/this._canvasElement.height,r=this._camera.perspective.fov;n<1&&(r/=n),r=Math.min(r,120),this._frustumProps.fov=r;var i=Z.inverseMat4(e.worldMatrix,Z.mat4()),a=Z.transformVec3(i,this._camera.eye,[0,0,0]),s=Z.transformVec3(i,this._camera.look,[0,0,0]);this._frustumProps.forward=Z.normalizeVec3(Z.subVec3(s,a,[0,0,0]),[0,0,0]),this._frustumProps.up=Z.normalizeVec3(this._camera.up,[0,0,0]),this._frustumProps.right=Z.normalizeVec3(Z.cross3Vec3(this._frustumProps.forward,this._frustumProps.up,[0,0,0]),[0,0,0]),this._frustumProps.eye=a.slice(),this._frustumProps.CAM_FACTOR_1=this._frustumProps.fov/2*this._frustumProps.wMultiply/Yn,this._frustumProps.CAM_FACTOR_2=this._frustumProps.fov/2*this._frustumProps.hMultiply/Yn}},{key:"_aabbIntersectsCameraFrustum_internal",value:function(e){var t=e._points||this._getPointsForBBox(e);e._points=t;for(var n=819,r=0,i=t.length;r<i;r++){var a=t[r],s=Kn;s[0]=a[0]-this._frustumProps.eye[0],s[1]=a[1]-this._frustumProps.eye[1],s[2]=a[2]-this._frustumProps.eye[2];var o=Z.dotVec3(s,this._frustumProps.forward);o<0?(n|=4,n&=-2):(n|=8,n&=-3);var l=er(Z.dotVec3(s,this._frustumProps.right),o);Math.abs(l)>this._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;t<n;t++)e._vfcManagerList[t].applyViewFrustumCulling()}))}},{key:"enabled",get:function(){return this._enabled},set:function(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}},{key:"getVFCManager",value:function(e){var t=new nr(this.scene,e);return this._vfcManagers[t.id]=t,this._vfcManagerList=Object.values(this._vfcManagers),t}},{key:"putVFCManager",value:function(e){delete this._vfcManagers[e.id],this._vfcManagerList=Object.values(this._vfcManagers)}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this)}}]),n}();function ir(e,t){for(var n,r,i={},a=0,s=t.length;a<s;a++)n=t[a],(r=e.component[n])?r.isEntity?i[n]=!0:e.warn("pick(): Component is not an Entity: "+n):e.warn("pick(): Component not found: "+n);return i}var ar=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),r=t.call(this,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;r<i;r++)n.push("cp");return n.push(";"),e=n.join("")},this.addSectionPlane=function(t){this.sectionPlanes.push(t),e=null},this.removeSectionPlane=function(t){for(var n=0,r=this.sectionPlanes.length;n<r;n++)if(this.sectionPlanes[n].id===t.id)return this.sectionPlanes.splice(n,1),void(e=null)}},r._lightsState=new function(){var e=Z.vec4([0,0,0,0]),t=Z.vec4();this.lights=[],this.reflectionMaps=[],this.lightMaps=[];var n=null,r=null;this.getHash=function(){if(n)return n;for(var e,t=[],r=this.lights,i=0,a=r.length;i<a;i++)e=r[i],t.push("/"),t.push(e.type),t.push("world"===e.space?"w":"v"),e.castsShadow&&t.push("sh");return this.lightMaps.length>0&&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;t<i;t++){if(this.lights[t].id===e.id)return this.lights.splice(t,1),r&&r.id===e.id&&(r=null),void(n=null)}},this.addReflectionMap=function(e){this.reflectionMaps.push(e),n=null},this.removeReflectionMap=function(e){for(var t=0,r=this.reflectionMaps.length;t<r;t++)if(this.reflectionMaps[t].id===e.id)return this.reflectionMaps.splice(t,1),void(n=null)},this.addLightMap=function(e){this.lightMaps.push(e),n=null},this.removeLightMap=function(e){for(var t=0,r=this.lightMaps.length;t<r;t++)if(this.lightMaps[t].id===e.id)return this.lightMaps.splice(t,1),void(n=null)},this.getAmbientColorAndIntensity=function(){if(!r)for(var n=0,i=this.lights.length;n<i;n++){var a=this.lights[n];if("ambient"===a.type){r=a;break}}if(r){var s=r.color,o=r.intensity;return t[0]=s[0],t[1]=s[1],t[2]=s[2],t[3]=o,t}return e}},r.input=new Bt(g(r),{dontClear:!0,element:r.canvas.canvas,keyboardEventsElement:i.keyboardEventsElement}),r.metrics=new Pn(g(r),{units:i.units,scale:i.scale,origin:i.origin}),r.sao=new Rn(g(r),{enabled:i.saoEnabled}),r.ticksPerRender=i.ticksPerRender,r.ticksPerOcclusionTest=i.ticksPerOcclusionTest,r.passes=i.passes,r.clearEachPass=i.clearEachPass,r.gammaInput=i.gammaInput,r.gammaOutput=i.gammaOutput,r.gammaFactor=i.gammaFactor,r._entityOffsetsEnabled=!!i.entityOffsetsEnabled,r._logarithmicDepthBufferEnabled=!!i.logarithmicDepthBufferEnabled,r._dtxEnabled=!1!==i.dtxEnabled,r._pbrEnabled=!!i.pbrEnabled,r._colorTextureEnabled=!1!==i.colorTextureEnabled,r._dtxEnabled=!!i.dtxEnabled,Ae._addScene(g(r)),r._initDefaults(),r._viewport=new Nt(g(r),{id:"default.viewport",autoBoundary:!0,dontClear:!0}),r._camera=new $t(g(r),{id:"default.camera",dontClear:!0}),new nn(g(r),{color:[1,1,1],intensity:.7}),new tn(g(r),{dir:[.8,-.5,-.5],color:[.67,.67,1],intensity:.7,space:"world"}),new tn(g(r),{dir:[-.8,-1,.5],color:[1,1,.9],intensity:.9,space:"world"}),r._camera.on("dirty",(function(){r._renderer.imageDirty()})),r.lod=new kn(g(r),{enabled:i.lodEnabled}),r.vfc=new rr(g(r),{enabled:i.vfcEnabled}),r}return P(n,[{key:"type",get:function(){return"Scene"}},{key:"_initDefaults",value:function(){}},{key:"_addComponent",value:function(e){if(e.id&&this.components[e.id]&&(this.error("Component "+ae.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=Z.createUUID();this.components[e.id]=e;var t=e.type,n=this.types[e.type];n||(n=this.types[t]={}),n[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}},{key:"_removeComponent",value:function(e){var t=e.id,n=e.type;delete this.components[t];var r=this.types[n];r&&(delete r[t],ae.isEmptyObject(r)&&delete this.types[n]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}},{key:"_sectionPlaneCreated",value:function(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}},{key:"_bitmapCreated",value:function(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}},{key:"_lineSetCreated",value:function(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}},{key:"_lightCreated",value:function(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}},{key:"_lightMapCreated",value:function(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}},{key:"_reflectionMapCreated",value:function(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}},{key:"_sectionPlaneDestroyed",value:function(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}},{key:"_bitmapDestroyed",value:function(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}},{key:"_lineSetDestroyed",value:function(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}},{key:"_lightDestroyed",value:function(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}},{key:"_lightMapDestroyed",value:function(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}},{key:"_reflectionMapDestroyed",value:function(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}},{key:"_registerModel",value:function(e){this.models[e.id]=e,this._modelIds=null}},{key:"_deregisterModel",value:function(e){var t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}},{key:"_registerObject",value:function(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}},{key:"_deregisterObject",value:function(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}},{key:"_objectVisibilityUpdated",value:function(e){var t=!(arguments.length>1&&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;n<i;n++)t.pass=n,this.fire("rendering",t,!0),r=a||0===n,this._renderer.render({pass:n,clear:r,force:e}),this.fire("rendered",t,!0);this._saveAmbientColor()}}},{key:"_recompile",value:function(){for(var e in this._compilables)this._compilables.hasOwnProperty(e)&&this._compilables[e].compile();this._renderer.shadowsDirty(),this.fire("compile",this,!0)}},{key:"_saveAmbientColor",value:function(){var e=this.canvas;if(e.transparent||e.backgroundImage||e.backgroundColor)this._lastAmbientColor=null;else{var t=this._lightsState.getAmbientColorAndIntensity();this._lastAmbientColor&&this._lastAmbientColor[0]===t[0]&&this._lastAmbientColor[1]===t[1]&&this._lastAmbientColor[2]===t[2]&&this._lastAmbientColor[3]===t[3]||(e.backgroundColor=t,this._lastAmbientColor||(this._lastAmbientColor=Z.vec4([0,0,0,1])),this._lastAmbientColor.set(t))}}},{key:"modelIds",get:function(){return this._modelIds||(this._modelIds=Object.keys(this.models)),this._modelIds}},{key:"numObjects",get:function(){return this._numObjects}},{key:"objectIds",get:function(){return this._objectIds||(this._objectIds=Object.keys(this.objects)),this._objectIds}},{key:"numVisibleObjects",get:function(){return this._numVisibleObjects}},{key:"visibleObjectIds",get:function(){return this._visibleObjectIds||(this._visibleObjectIds=Object.keys(this.visibleObjects)),this._visibleObjectIds}},{key:"numXRayedObjects",get:function(){return this._numXRayedObjects}},{key:"xrayedObjectIds",get:function(){return this._xrayedObjectIds||(this._xrayedObjectIds=Object.keys(this.xrayedObjects)),this._xrayedObjectIds}},{key:"numHighlightedObjects",get:function(){return this._numHighlightedObjects}},{key:"highlightedObjectIds",get:function(){return this._highlightedObjectIds||(this._highlightedObjectIds=Object.keys(this.highlightedObjects)),this._highlightedObjectIds}},{key:"numSelectedObjects",get:function(){return this._numSelectedObjects}},{key:"selectedObjectIds",get:function(){return this._selectedObjectIds||(this._selectedObjectIds=Object.keys(this.selectedObjects)),this._selectedObjectIds}},{key:"numColorizedObjects",get:function(){return this._numColorizedObjects}},{key:"colorizedObjectIds",get:function(){return this._colorizedObjectIds||(this._colorizedObjectIds=Object.keys(this.colorizedObjects)),this._colorizedObjectIds}},{key:"opacityObjectIds",get:function(){return this._opacityObjectIds||(this._opacityObjectIds=Object.keys(this.opacityObjects)),this._opacityObjectIds}},{key:"offsetObjectIds",get:function(){return this._offsetObjectIds||(this._offsetObjectIds=Object.keys(this.offsetObjects)),this._offsetObjectIds}},{key:"ticksPerRender",get:function(){return this._ticksPerRender},set:function(e){null==e?e=1:(!ae.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'ticksPerRender': '"+e+"' - should be an integer greater than zero."),e=1),e!==this._ticksPerRender&&(this._ticksPerRender=e)}},{key:"ticksPerOcclusionTest",get:function(){return this._ticksPerOcclusionTest},set:function(e){null==e?e=20:(!ae.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'ticksPerOcclusionTest': '"+e+"' - should be an integer greater than zero."),e=20),e!==this._ticksPerOcclusionTest&&(this._ticksPerOcclusionTest=e)}},{key:"passes",get:function(){return this._passes},set:function(e){null==e?e=1:(!ae.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'passes': '"+e+"' - should be an integer greater than zero."),e=1),e!==this._passes&&(this._passes=e,this.glRedraw())}},{key:"clearEachPass",get:function(){return this._clearEachPass},set:function(e){(e=!!e)!==this._clearEachPass&&(this._clearEachPass=e,this.glRedraw())}},{key:"gammaInput",get:function(){return this._renderer.gammaInput},set:function(e){(e=!1!==e)!==this._renderer.gammaInput&&(this._renderer.gammaInput=e,this._needRecompile=!0,this.glRedraw())}},{key:"gammaOutput",get:function(){return this._renderer.gammaOutput},set:function(e){(e=!!e)!==this._renderer.gammaOutput&&(this._renderer.gammaOutput=e,this._needRecompile=!0,this.glRedraw())}},{key:"gammaFactor",get:function(){return this._renderer.gammaFactor},set:function(e){(e=null==e?2.2:e)!==this._renderer.gammaFactor&&(this._renderer.gammaFactor=e,this.glRedraw())}},{key:"geometry",get:function(){return this.components["default.geometry"]||hn(vn)}},{key:"material",get:function(){return this.components["default.material"]||new wn(this,{id:"default.material",emissive:[.4,.4,.4],dontClear:!0})}},{key:"xrayMaterial",get:function(){return this.components["default.xrayMaterial"]||new Tn(this,{id:"default.xrayMaterial",preset:"sepia",dontClear:!0})}},{key:"highlightMaterial",get:function(){return this.components["default.highlightMaterial"]||new Tn(this,{id:"default.highlightMaterial",preset:"yellowHighlight",dontClear:!0})}},{key:"selectedMaterial",get:function(){return this.components["default.selectedMaterial"]||new Tn(this,{id:"default.selectedMaterial",preset:"greenSelected",dontClear:!0})}},{key:"edgeMaterial",get:function(){return this.components["default.edgeMaterial"]||new bn(this,{id:"default.edgeMaterial",preset:"default",edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1,dontClear:!0})}},{key:"pointsMaterial",get:function(){return this.components["default.pointsMaterial"]||new _n(this,{id:"default.pointsMaterial",preset:"default",dontClear:!0})}},{key:"linesMaterial",get:function(){return this.components["default.linesMaterial"]||new On(this,{id:"default.linesMaterial",preset:"default",dontClear:!0})}},{key:"viewport",get:function(){return this._viewport}},{key:"camera",get:function(){return this._camera}},{key:"center",get:function(){if(this._aabbDirty||!this._center){this._center&&this._center||(this._center=Z.vec3());var e=this.aabb;this._center[0]=(e[0]+e[3])/2,this._center[1]=(e[1]+e[4])/2,this._center[2]=(e[2]+e[5])/2}return this._center}},{key:"aabb",get:function(){if(this._aabbDirty){this._aabb||(this._aabb=Z.AABB3());var e,t,n=Z.MAX_DOUBLE,r=Z.MAX_DOUBLE,i=Z.MAX_DOUBLE,a=Z.MIN_DOUBLE,s=Z.MIN_DOUBLE,o=Z.MIN_DOUBLE,l=this._collidables,u=!1;for(var c in l)if(l.hasOwnProperty(c)){if(!1===(t=l[c]).collidable)continue;(e=t.aabb)[0]<n&&(n=e[0]),e[1]<r&&(r=e[1]),e[2]<i&&(i=e[2]),e[3]>a&&(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;t<n;t++)this.lights[e[t]].destroy()}},{key:"clearSectionPlanes",value:function(){for(var e=Object.keys(this.sectionPlanes),t=0,n=e.length;t<n;t++)this.sectionPlanes[e[t]].destroy()}},{key:"clearBitmaps",value:function(){for(var e=Object.keys(this.bitmaps),t=0,n=e.length;t<n;t++)this.bitmaps[e[t]].destroy()}},{key:"clearLines",value:function(){for(var e=Object.keys(this.lineSets),t=0,n=e.length;t<n;t++)this.lineSets[e[t]].destroy()}},{key:"getAABB",value:function(e){if(void 0===e)return this.aabb;if(ae.isString(e)){var t=this.objects[e];if(t&&t.aabb)return t.aabb;e=[e]}if(0===e.length)return this.aabb;var n,r=Z.MAX_DOUBLE,i=Z.MAX_DOUBLE,a=Z.MAX_DOUBLE,s=Z.MIN_DOUBLE,o=Z.MIN_DOUBLE,l=Z.MIN_DOUBLE;if(this.withObjects(e,(function(e){if(e.collidable){var t=e.aabb;t[0]<r&&(r=t[0]),t[1]<i&&(i=t[1]),t[2]<a&&(a=t[2]),t[3]>s&&(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;r<i;r++){var a=e[r],s=this.objects[a];if(s)n=t(s)||n;else for(var o=this.modelIds,l=0,u=o.length;l<u;l++){var c=o[l],f=Z.globalizeObjectId(c,a);(s=this.objects[f])&&(n=t(s)||n)}}return n}},{key:"destroy",value:function(){for(var e in v(T(n.prototype),"destroy",this).call(this),this.components)this.components.hasOwnProperty(e)&&this.components[e].destroy();this.canvas.gl=null,this.components=null,this.models=null,this.objects=null,this.visibleObjects=null,this.xrayedObjects=null,this.highlightedObjects=null,this.selectedObjects=null,this.colorizedObjects=null,this.opacityObjects=null,this.sectionPlanes=null,this.lights=null,this.lightMaps=null,this.reflectionMaps=null,this._objectIds=null,this._visibleObjectIds=null,this._xrayedObjectIds=null,this._highlightedObjectIds=null,this._selectedObjectIds=null,this._colorizedObjectIds=null,this.types=null,this.components=null,this.canvas=null,this._renderer=null,this.input=null,this._viewport=null,this._camera=null}}]),n}(),sr=1e3,or=1001,lr=1002,ur=1003,cr=1004,fr=1004,pr=1005,Ar=1005,dr=1006,vr=1007,hr=1007,Ir=1008,yr=1008,mr=1009,wr=1010,gr=1011,Tr=1012,Er=1013,br=1014,Dr=1015,Pr=1016,Rr=1017,Cr=1018,_r=1020,Br=1021,Or=1022,Sr=1023,Nr=1024,Lr=1025,xr=1026,Mr=1027,Fr=1028,Hr=1029,Ur=1030,Gr=1031,kr=1033,Vr=33776,jr=33777,Qr=33778,Wr=33779,zr=35840,Kr=35841,Yr=35842,Xr=35843,qr=36196,Jr=37492,Zr=37496,$r=37808,ei=37809,ti=37810,ni=37811,ri=37812,ii=37813,ai=37814,si=37815,oi=37816,li=37817,ui=37818,ci=37819,fi=37820,pi=37821,Ai=36492,di=3e3,vi=3001,hi=1e4,Ii=10001,yi=10002,mi=10003,wi=function(e){"LambertMaterial"===e._material._state.type?(this.vertex=function(e){var t=e.scene,n=e.scene._sectionPlanesState,r=e.scene._lightsState,i=e._geometry._state,a=e._state.billboard,s=e._state.stationary,o=n.sectionPlanes.length>0,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<f;c++){var p=r.lights[c];"ambient"!==p.type&&(u.push("uniform vec4 lightColor"+c+";"),"dir"===p.type&&u.push("uniform vec3 lightDir"+c+";"),"point"===p.type&&u.push("uniform vec3 lightPos"+c+";"),"spot"===p.type&&(u.push("uniform vec3 lightPos"+c+";"),u.push("uniform vec3 lightDir"+c+";")))}l&&(u.push("vec3 octDecode(vec2 oct) {"),u.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),u.push(" if (v.z < 0.0) {"),u.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);"),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;A<d;A++){var v=r.lights[A];if("ambient"!==v.type){if("dir"===v.type)"view"===v.space?u.push("viewLightDir = normalize(lightDir"+A+");"):u.push("viewLightDir = normalize((viewMatrix2 * vec4(lightDir"+A+", 0.0)).xyz);");else if("point"===v.type)"view"===v.space?u.push("viewLightDir = -normalize(lightPos"+A+" - viewPosition.xyz);"):u.push("viewLightDir = -normalize((viewMatrix2 * vec4(lightPos"+A+", 0.0)).xyz);");else{if("spot"!==v.type)continue;"view"===v.space?u.push("viewLightDir = normalize(lightDir"+A+");"):u.push("viewLightDir = normalize((viewMatrix2 * vec4(lightDir"+A+", 0.0)).xyz);")}u.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),u.push("reflectedColor += lambertian * (lightColor"+A+".rgb * lightColor"+A+".a);")}}u.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * materialColor.rgb) + materialEmissive.rgb + (reflectedColor * materialColor.rgb), materialColor.a) * colorize;"),o&&u.push("vWorldPosition = worldPosition;");"points"===i.primitiveName&&u.push("gl_PointSize = pointSize;");u.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(u.push("vFragDepth = 1.0 + clipPos.w;"),u.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return u.push("gl_Position = clipPos;"),u.push("}"),u}(e),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState;e._material._state;var r=e._geometry._state,i=n.sectionPlanes.length>0,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<l;o++)s.push("uniform bool sectionPlaneActive"+o+";"),s.push("uniform vec3 sectionPlanePos"+o+";"),s.push("uniform vec3 sectionPlaneDir"+o+";")}s.push("in vec4 vColor;"),a&&(s.push("uniform float gammaFactor;"),s.push(" vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),s.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),s.push("}"));if(s.push("out vec4 outColor;"),s.push("void main(void) {"),i){s.push("if (clippable) {"),s.push(" float dist = 0.0;");for(var u=0,c=n.sectionPlanes.length;u<c;u++)s.push("if (sectionPlaneActive"+u+") {"),s.push(" dist += clamp(dot(-sectionPlaneDir"+u+".xyz, vWorldPosition.xyz - sectionPlanePos"+u+".xyz), 0.0, 1000.0);"),s.push("}");s.push(" if (dist > 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<I;h++)"ambient"!==(n=s.lights[h]).type&&("dir"===n.type&&v.push("uniform vec3 lightDir"+h+";"),"point"===n.type&&v.push("uniform vec3 lightPos"+h+";"),"spot"===n.type&&(v.push("uniform vec3 lightPos"+h+";"),v.push("uniform vec3 lightDir"+h+";")),"dir"===n.type&&"view"===n.space||v.push("out vec4 vViewLightReverseDirAndDist"+h+";"));d&&(v.push("vec3 octDecode(vec2 oct) {"),v.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),v.push(" if (v.z < 0.0) {"),v.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);"),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;y<m;y++)s.lights[y].castsShadow&&(v.push("uniform mat4 shadowViewMatrix"+y+";"),v.push("uniform mat4 shadowProjMatrix"+y+";"),v.push("out vec4 vShadowPosFromLight"+y+";"))}v.push("void main(void) {"),v.push("vec4 localPosition = vec4(position, 1.0); "),v.push("vec4 worldPosition;"),d&&v.push("localPosition = positionsDecodeMatrix * localPosition;");f&&(d?v.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):v.push("vec4 localNormal = vec4(normal, 0.0); "),v.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),v.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));v.push("mat4 viewMatrix2 = viewMatrix;"),v.push("mat4 modelMatrix2 = modelMatrix;"),u?v.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;"):l&&v.push("viewMatrix2[3] = vec4(0.0, 0.0, 0.0 ,1.0);");"spherical"===o||"cylindrical"===o?(v.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),v.push("billboard(modelMatrix2);"),v.push("billboard(viewMatrix2);"),v.push("billboard(modelViewMatrix);"),f&&(v.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),v.push("billboard(modelNormalMatrix2);"),v.push("billboard(viewNormalMatrix2);"),v.push("billboard(modelViewNormalMatrix);")),v.push("worldPosition = modelMatrix2 * localPosition;"),v.push("worldPosition.xyz = worldPosition.xyz + offset;"),v.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(v.push("worldPosition = modelMatrix2 * localPosition;"),v.push("worldPosition.xyz = worldPosition.xyz + offset;"),v.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));if(f){v.push("vec3 worldNormal = (modelNormalMatrix2 * localNormal).xyz; "),s.lightMaps.length>0&&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;w<g;w++)"ambient"!==(n=s.lights[w]).type&&("dir"===n.type&&"world"===n.space&&(v.push("tmpVec3 = vec3(viewMatrix2 * vec4(lightDir"+w+", 0.0) ).xyz;"),v.push("vViewLightReverseDirAndDist"+w+" = vec4(-tmpVec3, 0.0);")),"point"===n.type&&("world"===n.space?(v.push("tmpVec3 = (viewMatrix2 * vec4(lightPos"+w+", 1.0)).xyz - viewPosition.xyz;"),v.push("lightDist = abs(length(tmpVec3));")):(v.push("tmpVec3 = lightPos"+w+".xyz - viewPosition.xyz;"),v.push("lightDist = abs(length(tmpVec3));")),v.push("vViewLightReverseDirAndDist"+w+" = vec4(tmpVec3, lightDist);")))}c&&(d?v.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"):v.push("vUV = uv;"));a.colors&&v.push("vColor = color;");"points"===a.primitiveName&&v.push("gl_PointSize = pointSize;");p&&v.push("vWorldPosition = worldPosition;");v.push(" vViewPosition = viewPosition.xyz;"),v.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(v.push("vFragDepth = 1.0 + clipPos.w;"),v.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));l&&v.push("clipPos.z = clipPos.w;");if(v.push("gl_Position = clipPos;"),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);"),v.push("vec4 tempx; ");for(var T=0,E=s.lights.length;T<E;T++)s.lights[T].castsShadow&&v.push("vShadowPosFromLight"+T+" = texUnitConverter * shadowProjMatrix"+T+" * (shadowViewMatrix"+T+" * worldPosition); ")}return v.push("}"),v}(e),this.fragment=function(e){var t=e.scene;t.canvas.gl;var n=e._material,r=e._geometry._state,i=e.scene._sectionPlanesState,a=e.scene._lightsState,s=e._material._state,o=i.sectionPlanes.length>0,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;h<i.sectionPlanes.length;h++)v.push("uniform bool sectionPlaneActive"+h+";"),v.push("uniform vec3 sectionPlanePos"+h+";"),v.push("uniform vec3 sectionPlaneDir"+h+";")}l&&(a.lightMaps.length>0&&(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<y;I++){var m=a.lights[I];"ambient"!==m.type&&(v.push("uniform vec4 lightColor"+I+";"),"point"===m.type&&v.push("uniform vec3 lightAttenuation"+I+";"),"dir"===m.type&&"view"===m.space&&v.push("uniform vec3 lightDir"+I+";"),"point"===m.type&&"view"===m.space?v.push("uniform vec3 lightPos"+I+";"):v.push("in vec4 vViewLightReverseDirAndDist"+I+";"))}if(A)for(var w=0,g=a.lights.length;w<g;w++)a.lights[w].castsShadow&&(v.push("in vec4 vShadowPosFromLight"+w+";"),v.push("uniform sampler2D shadowMap"+w+";"));if(v.push("uniform vec4 colorize;"),v.push("out vec4 outColor;"),v.push("void main(void) {"),o){v.push("if (clippable) {"),v.push(" float dist = 0.0;");for(h=0;h<i.sectionPlanes.length;h++)v.push("if (sectionPlaneActive"+h+") {"),v.push(" dist += clamp(dot(-sectionPlaneDir"+h+".xyz, vWorldPosition.xyz - sectionPlanePos"+h+".xyz), 0.0, 1000.0);"),v.push("}");v.push(" if (dist > 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;T<E;T++){var b=a.lights[T];"ambient"!==b.type&&("dir"===b.type&&"view"===b.space?v.push("viewLightDir = -normalize(lightDir"+T+");"):"point"===b.type&&"view"===b.space?v.push("viewLightDir = normalize(lightPos"+T+" - vViewPosition);"):v.push("viewLightDir = normalize(vViewLightReverseDirAndDist"+T+".xyz);"),A&&b.castsShadow?(v.push("shadow = 0.0;"),v.push("fragmentDepth = vShadowPosFromLight"+T+".xyz;"),v.push("fragmentDepth.z -= shadowAcneRemover;"),v.push("for (int x = -3; x <= 3; x++) {"),v.push(" for (int y = -3; y <= 3; y++) {"),v.push(" float texelDepth = unpackDepth(texture(shadowMap"+T+", fragmentDepth.xy + vec2(x, y) * texelSize));"),v.push(" if (fragmentDepth.z < texelDepth) {"),v.push(" shadow += 1.0;"),v.push(" }"),v.push(" }"),v.push("}"),v.push("shadow = shadow / 9.0;"),v.push("light.color = lightColor"+T+".rgb * (lightColor"+T+".a * shadow);")):v.push("light.color = lightColor"+T+".rgb * (lightColor"+T+".a );"),v.push("light.direction = viewLightDir;"),c&&v.push("computePhongLighting(light, geometry, material, reflectedLight);"),(p||f)&&v.push("computePBRLighting(light, geometry, material, reflectedLight);"))}c?v.push("vec3 outgoingLight = (lightAmbient.rgb * lightAmbient.a * diffuseColor) + ((occlusion * (( reflectedLight.diffuse + reflectedLight.specular)))) + emissiveColor;"):v.push("vec3 outgoingLight = (occlusion * (reflectedLight.diffuse)) + (occlusion * reflectedLight.specular) + emissiveColor;")}else v.push("ambientColor *= (lightAmbient.rgb * lightAmbient.a);"),v.push("vec3 outgoingLight = emissiveColor + ambientColor;");v.push("vec4 fragColor = vec4(outgoingLight, alpha) * colorize;"),d&&v.push("fragColor = linearToGamma(fragColor, gammaFactor);");v.push("outColor = fragColor;"),t.logarithmicDepthBufferEnabled&&v.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return v.push("}"),v}(e))},gi={};function Ti(e){if(!e.receivesShadow)return!1;var t=e.scene._lightsState.lights;if(!t||0===t.length)return!1;for(var n=0,r=t.length;n<r;n++)if(t[n].castsShadow)return!0;return!1}function Ei(e){var t=e._geometry._state.primitiveName;return!(!e._geometry._state.autoVertexNormals&&!e._geometry._state.normalsBuf||"triangles"!==t&&"triangle-strip"!==t&&"triangle-fan"!==t)}gi[3e3]="linearToLinear",gi[3001]="sRGBToLinear";var bi=Z.vec3(),Di=new G({}),Pi=function(e,t){this.id=Di.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new wi(t),this._allocate(t)},Ri={};Pi.get=function(e){var t=e.scene,n=[t.canvas.canvas.id,(t.gammaInput?"gi;":";")+(t.gammaOutput?"go":""),t._lightsState.getHash(),t._sectionPlanesState.getHash(),e._geometry._state.hash,e._material._state.hash,e._state.drawHash].join(";"),r=Ri[n];if(!r){if((r=new Pi(n,e)).errors)return console.log(r.errors.join("\n")),null;Ri[n]=r,ee.memory.programs++}return r._useCount++,r},Pi.prototype.put=function(){0==--this._useCount&&(Di.removeItem(this.id),this._program&&this._program.destroy(),delete Ri[this._hash],ee.memory.programs--)},Pi.prototype.webglContextRestored=function(){this._program=null},Pi.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=Ze.MAX_TEXTURE_UNITS,r=t.scene,i=t._material,a=r.canvas.gl,s=this._program,o=t._state,l=t._material._state,u=t._geometry._state,c=r.camera,f=t.origin,p=o.background;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,p&&a.depthFunc(a.LEQUAL),this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,f?e.getRTCViewMatrix(o.originHash,f):c.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,c.viewNormalMatrix),o.clippable){var A=r._sectionPlanesState.sectionPlanes.length;if(A>0)for(var d=r._sectionPlanesState.sectionPlanes,v=t.renderFlags,h=0;h<A;h++){var I=this._uSectionPlanes[h];if(I){var y=v.sectionPlanesActivePerLayer[h];if(a.uniform1i(I.active,y?1:0),y){var m=d[h];a.uniform3fv(I.pos,f?ge(m.dist,m.dir,f,bi):m.pos),a.uniform3fv(I.dir,m.dir)}}}}if(l.id!==this._lastMaterialId){e.textureUnit=this._baseTextureUnit;var w=l.backfaces;e.backfaces!==w&&(w?a.disable(a.CULL_FACE):a.enable(a.CULL_FACE),e.backfaces=w);var g=l.frontface;switch(e.frontface!==g&&(g?a.frontFace(a.CCW):a.frontFace(a.CW),e.frontface=g),e.lineWidth!==l.lineWidth&&(a.lineWidth(l.lineWidth),e.lineWidth=l.lineWidth),this._uPointSize&&a.uniform1f(this._uPointSize,l.pointSize),l.type){case"LambertMaterial":this._uMaterialAmbient&&a.uniform3fv(this._uMaterialAmbient,l.ambient),this._uMaterialColor&&a.uniform4f(this._uMaterialColor,l.color[0],l.color[1],l.color[2],l.alpha),this._uMaterialEmissive&&a.uniform3fv(this._uMaterialEmissive,l.emissive);break;case"PhongMaterial":this._uMaterialShininess&&a.uniform1f(this._uMaterialShininess,l.shininess),this._uMaterialAmbient&&a.uniform3fv(this._uMaterialAmbient,l.ambient),this._uMaterialDiffuse&&a.uniform3fv(this._uMaterialDiffuse,l.diffuse),this._uMaterialSpecular&&a.uniform3fv(this._uMaterialSpecular,l.specular),this._uMaterialEmissive&&a.uniform3fv(this._uMaterialEmissive,l.emissive),this._uAlphaModeCutoff&&a.uniform4f(this._uAlphaModeCutoff,1*l.alpha,1===l.alphaMode?1:0,l.alphaCutoff,0),i._ambientMap&&i._ambientMap._state.texture&&this._uMaterialAmbientMap&&(s.bindTexture(this._uMaterialAmbientMap,i._ambientMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uMaterialAmbientMapMatrix&&a.uniformMatrix4fv(this._uMaterialAmbientMapMatrix,!1,i._ambientMap._state.matrix)),i._diffuseMap&&i._diffuseMap._state.texture&&this._uDiffuseMap&&(s.bindTexture(this._uDiffuseMap,i._diffuseMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uDiffuseMapMatrix&&a.uniformMatrix4fv(this._uDiffuseMapMatrix,!1,i._diffuseMap._state.matrix)),i._specularMap&&i._specularMap._state.texture&&this._uSpecularMap&&(s.bindTexture(this._uSpecularMap,i._specularMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uSpecularMapMatrix&&a.uniformMatrix4fv(this._uSpecularMapMatrix,!1,i._specularMap._state.matrix)),i._emissiveMap&&i._emissiveMap._state.texture&&this._uEmissiveMap&&(s.bindTexture(this._uEmissiveMap,i._emissiveMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uEmissiveMapMatrix&&a.uniformMatrix4fv(this._uEmissiveMapMatrix,!1,i._emissiveMap._state.matrix)),i._alphaMap&&i._alphaMap._state.texture&&this._uAlphaMap&&(s.bindTexture(this._uAlphaMap,i._alphaMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uAlphaMapMatrix&&a.uniformMatrix4fv(this._uAlphaMapMatrix,!1,i._alphaMap._state.matrix)),i._reflectivityMap&&i._reflectivityMap._state.texture&&this._uReflectivityMap&&(s.bindTexture(this._uReflectivityMap,i._reflectivityMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,this._uReflectivityMapMatrix&&a.uniformMatrix4fv(this._uReflectivityMapMatrix,!1,i._reflectivityMap._state.matrix)),i._normalMap&&i._normalMap._state.texture&&this._uNormalMap&&(s.bindTexture(this._uNormalMap,i._normalMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uNormalMapMatrix&&a.uniformMatrix4fv(this._uNormalMapMatrix,!1,i._normalMap._state.matrix)),i._occlusionMap&&i._occlusionMap._state.texture&&this._uOcclusionMap&&(s.bindTexture(this._uOcclusionMap,i._occlusionMap._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uOcclusionMapMatrix&&a.uniformMatrix4fv(this._uOcclusionMapMatrix,!1,i._occlusionMap._state.matrix)),i._diffuseFresnel&&(this._uDiffuseFresnelEdgeBias&&a.uniform1f(this._uDiffuseFresnelEdgeBias,i._diffuseFresnel.edgeBias),this._uDiffuseFresnelCenterBias&&a.uniform1f(this._uDiffuseFresnelCenterBias,i._diffuseFresnel.centerBias),this._uDiffuseFresnelEdgeColor&&a.uniform3fv(this._uDiffuseFresnelEdgeColor,i._diffuseFresnel.edgeColor),this._uDiffuseFresnelCenterColor&&a.uniform3fv(this._uDiffuseFresnelCenterColor,i._diffuseFresnel.centerColor),this._uDiffuseFresnelPower&&a.uniform1f(this._uDiffuseFresnelPower,i._diffuseFresnel.power)),i._specularFresnel&&(this._uSpecularFresnelEdgeBias&&a.uniform1f(this._uSpecularFresnelEdgeBias,i._specularFresnel.edgeBias),this._uSpecularFresnelCenterBias&&a.uniform1f(this._uSpecularFresnelCenterBias,i._specularFresnel.centerBias),this._uSpecularFresnelEdgeColor&&a.uniform3fv(this._uSpecularFresnelEdgeColor,i._specularFresnel.edgeColor),this._uSpecularFresnelCenterColor&&a.uniform3fv(this._uSpecularFresnelCenterColor,i._specularFresnel.centerColor),this._uSpecularFresnelPower&&a.uniform1f(this._uSpecularFresnelPower,i._specularFresnel.power)),i._alphaFresnel&&(this._uAlphaFresnelEdgeBias&&a.uniform1f(this._uAlphaFresnelEdgeBias,i._alphaFresnel.edgeBias),this._uAlphaFresnelCenterBias&&a.uniform1f(this._uAlphaFresnelCenterBias,i._alphaFresnel.centerBias),this._uAlphaFresnelEdgeColor&&a.uniform3fv(this._uAlphaFresnelEdgeColor,i._alphaFresnel.edgeColor),this._uAlphaFresnelCenterColor&&a.uniform3fv(this._uAlphaFresnelCenterColor,i._alphaFresnel.centerColor),this._uAlphaFresnelPower&&a.uniform1f(this._uAlphaFresnelPower,i._alphaFresnel.power)),i._reflectivityFresnel&&(this._uReflectivityFresnelEdgeBias&&a.uniform1f(this._uReflectivityFresnelEdgeBias,i._reflectivityFresnel.edgeBias),this._uReflectivityFresnelCenterBias&&a.uniform1f(this._uReflectivityFresnelCenterBias,i._reflectivityFresnel.centerBias),this._uReflectivityFresnelEdgeColor&&a.uniform3fv(this._uReflectivityFresnelEdgeColor,i._reflectivityFresnel.edgeColor),this._uReflectivityFresnelCenterColor&&a.uniform3fv(this._uReflectivityFresnelCenterColor,i._reflectivityFresnel.centerColor),this._uReflectivityFresnelPower&&a.uniform1f(this._uReflectivityFresnelPower,i._reflectivityFresnel.power)),i._emissiveFresnel&&(this._uEmissiveFresnelEdgeBias&&a.uniform1f(this._uEmissiveFresnelEdgeBias,i._emissiveFresnel.edgeBias),this._uEmissiveFresnelCenterBias&&a.uniform1f(this._uEmissiveFresnelCenterBias,i._emissiveFresnel.centerBias),this._uEmissiveFresnelEdgeColor&&a.uniform3fv(this._uEmissiveFresnelEdgeColor,i._emissiveFresnel.edgeColor),this._uEmissiveFresnelCenterColor&&a.uniform3fv(this._uEmissiveFresnelCenterColor,i._emissiveFresnel.centerColor),this._uEmissiveFresnelPower&&a.uniform1f(this._uEmissiveFresnelPower,i._emissiveFresnel.power));break;case"MetallicMaterial":this._uBaseColor&&a.uniform3fv(this._uBaseColor,l.baseColor),this._uMaterialMetallic&&a.uniform1f(this._uMaterialMetallic,l.metallic),this._uMaterialRoughness&&a.uniform1f(this._uMaterialRoughness,l.roughness),this._uMaterialSpecularF0&&a.uniform1f(this._uMaterialSpecularF0,l.specularF0),this._uMaterialEmissive&&a.uniform3fv(this._uMaterialEmissive,l.emissive),this._uAlphaModeCutoff&&a.uniform4f(this._uAlphaModeCutoff,1*l.alpha,1===l.alphaMode?1:0,l.alphaCutoff,0);var T=i._baseColorMap;T&&T._state.texture&&this._uBaseColorMap&&(s.bindTexture(this._uBaseColorMap,T._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uBaseColorMapMatrix&&a.uniformMatrix4fv(this._uBaseColorMapMatrix,!1,T._state.matrix));var E=i._metallicMap;E&&E._state.texture&&this._uMetallicMap&&(s.bindTexture(this._uMetallicMap,E._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uMetallicMapMatrix&&a.uniformMatrix4fv(this._uMetallicMapMatrix,!1,E._state.matrix));var b=i._roughnessMap;b&&b._state.texture&&this._uRoughnessMap&&(s.bindTexture(this._uRoughnessMap,b._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uRoughnessMapMatrix&&a.uniformMatrix4fv(this._uRoughnessMapMatrix,!1,b._state.matrix));var D=i._metallicRoughnessMap;D&&D._state.texture&&this._uMetallicRoughnessMap&&(s.bindTexture(this._uMetallicRoughnessMap,D._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uMetallicRoughnessMapMatrix&&a.uniformMatrix4fv(this._uMetallicRoughnessMapMatrix,!1,D._state.matrix)),(_=i._emissiveMap)&&_._state.texture&&this._uEmissiveMap&&(s.bindTexture(this._uEmissiveMap,_._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uEmissiveMapMatrix&&a.uniformMatrix4fv(this._uEmissiveMapMatrix,!1,_._state.matrix)),(B=i._occlusionMap)&&i._occlusionMap._state.texture&&this._uOcclusionMap&&(s.bindTexture(this._uOcclusionMap,B._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uOcclusionMapMatrix&&a.uniformMatrix4fv(this._uOcclusionMapMatrix,!1,B._state.matrix)),(O=i._alphaMap)&&O._state.texture&&this._uAlphaMap&&(s.bindTexture(this._uAlphaMap,O._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uAlphaMapMatrix&&a.uniformMatrix4fv(this._uAlphaMapMatrix,!1,O._state.matrix)),(S=i._normalMap)&&S._state.texture&&this._uNormalMap&&(s.bindTexture(this._uNormalMap,S._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uNormalMapMatrix&&a.uniformMatrix4fv(this._uNormalMapMatrix,!1,S._state.matrix));break;case"SpecularMaterial":this._uMaterialDiffuse&&a.uniform3fv(this._uMaterialDiffuse,l.diffuse),this._uMaterialSpecular&&a.uniform3fv(this._uMaterialSpecular,l.specular),this._uMaterialGlossiness&&a.uniform1f(this._uMaterialGlossiness,l.glossiness),this._uMaterialReflectivity&&a.uniform1f(this._uMaterialReflectivity,l.reflectivity),this._uMaterialEmissive&&a.uniform3fv(this._uMaterialEmissive,l.emissive),this._uAlphaModeCutoff&&a.uniform4f(this._uAlphaModeCutoff,1*l.alpha,1===l.alphaMode?1:0,l.alphaCutoff,0);var P=i._diffuseMap;P&&P._state.texture&&this._uDiffuseMap&&(s.bindTexture(this._uDiffuseMap,P._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uDiffuseMapMatrix&&a.uniformMatrix4fv(this._uDiffuseMapMatrix,!1,P._state.matrix));var R=i._specularMap;R&&R._state.texture&&this._uSpecularMap&&(s.bindTexture(this._uSpecularMap,R._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uSpecularMapMatrix&&a.uniformMatrix4fv(this._uSpecularMapMatrix,!1,R._state.matrix));var C=i._glossinessMap;C&&C._state.texture&&this._uGlossinessMap&&(s.bindTexture(this._uGlossinessMap,C._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uGlossinessMapMatrix&&a.uniformMatrix4fv(this._uGlossinessMapMatrix,!1,C._state.matrix));var _,B,O,S,N=i._specularGlossinessMap;N&&N._state.texture&&this._uSpecularGlossinessMap&&(s.bindTexture(this._uSpecularGlossinessMap,N._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uSpecularGlossinessMapMatrix&&a.uniformMatrix4fv(this._uSpecularGlossinessMapMatrix,!1,N._state.matrix)),(_=i._emissiveMap)&&_._state.texture&&this._uEmissiveMap&&(s.bindTexture(this._uEmissiveMap,_._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uEmissiveMapMatrix&&a.uniformMatrix4fv(this._uEmissiveMapMatrix,!1,_._state.matrix)),(B=i._occlusionMap)&&B._state.texture&&this._uOcclusionMap&&(s.bindTexture(this._uOcclusionMap,B._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uOcclusionMapMatrix&&a.uniformMatrix4fv(this._uOcclusionMapMatrix,!1,B._state.matrix)),(O=i._alphaMap)&&O._state.texture&&this._uAlphaMap&&(s.bindTexture(this._uAlphaMap,O._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uAlphaMapMatrix&&a.uniformMatrix4fv(this._uAlphaMapMatrix,!1,O._state.matrix)),(S=i._normalMap)&&S._state.texture&&this._uNormalMap&&(s.bindTexture(this._uNormalMap,S._state.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++,this._uNormalMapMatrix&&a.uniformMatrix4fv(this._uNormalMapMatrix,!1,S._state.matrix))}this._lastMaterialId=l.id}if(a.uniformMatrix4fv(this._uModelMatrix,a.FALSE,t.worldMatrix),this._uModelNormalMatrix&&a.uniformMatrix4fv(this._uModelNormalMatrix,a.FALSE,t.worldNormalMatrix),this._uClippable&&a.uniform1i(this._uClippable,o.clippable),this._uColorize){var L=o.colorize,x=this._lastColorize;x[0]===L[0]&&x[1]===L[1]&&x[2]===L[2]&&x[3]===L[3]||(a.uniform4fv(this._uColorize,L),x[0]=L[0],x[1]=L[1],x[2]=L[2],x[3]=L[3])}a.uniform3fv(this._uOffset,o.offset),u.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&a.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,u.positionsDecodeMatrix),this._uUVDecodeMatrix&&a.uniformMatrix3fv(this._uUVDecodeMatrix,!1,u.uvDecodeMatrix),this._aPosition&&(this._aPosition.bindArrayBuffer(u.positionsBuf),e.bindArray++),this._aNormal&&(this._aNormal.bindArrayBuffer(u.normalsBuf),e.bindArray++),this._aUV&&(this._aUV.bindArrayBuffer(u.uvBuf),e.bindArray++),this._aColor&&(this._aColor.bindArrayBuffer(u.colorsBuf),e.bindArray++),this._aFlags&&(this._aFlags.bindArrayBuffer(u.flagsBuf),e.bindArray++),u.indicesBuf&&(u.indicesBuf.bind(),e.bindArray++),this._lastGeometryId=u.id),u.indicesBuf?(a.drawElements(u.primitive,u.indicesBuf.numItems,u.indicesBuf.itemType,0),e.drawElements++):u.positions&&(a.drawArrays(a.TRIANGLES,0,u.positions.numItems),e.drawArrays++),p&&a.depthFunc(a.LESS)},Pi.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl,r=e._material,i=t._lightsState,a=t._sectionPlanesState,s=e._material._state;if(this._program=new ft(n,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var o=this._program;this._uPositionsDecodeMatrix=o.getLocation("positionsDecodeMatrix"),this._uUVDecodeMatrix=o.getLocation("uvDecodeMatrix"),this._uModelMatrix=o.getLocation("modelMatrix"),this._uModelNormalMatrix=o.getLocation("modelNormalMatrix"),this._uViewMatrix=o.getLocation("viewMatrix"),this._uViewNormalMatrix=o.getLocation("viewNormalMatrix"),this._uProjMatrix=o.getLocation("projMatrix"),this._uGammaFactor=o.getLocation("gammaFactor"),this._uLightAmbient=[],this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[],this._uShadowViewMatrix=[],this._uShadowProjMatrix=[],t.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=o.getLocation("logDepthBufFC"));for(var l,u=i.lights,c=0,f=u.length;c<f;c++){switch((l=u[c]).type){case"ambient":this._uLightAmbient[c]=o.getLocation("lightAmbient");break;case"dir":this._uLightColor[c]=o.getLocation("lightColor"+c),this._uLightPos[c]=null,this._uLightDir[c]=o.getLocation("lightDir"+c);break;case"point":this._uLightColor[c]=o.getLocation("lightColor"+c),this._uLightPos[c]=o.getLocation("lightPos"+c),this._uLightDir[c]=null,this._uLightAttenuation[c]=o.getLocation("lightAttenuation"+c);break;case"spot":this._uLightColor[c]=o.getLocation("lightColor"+c),this._uLightPos[c]=o.getLocation("lightPos"+c),this._uLightDir[c]=o.getLocation("lightDir"+c),this._uLightAttenuation[c]=o.getLocation("lightAttenuation"+c)}l.castsShadow&&(this._uShadowViewMatrix[c]=o.getLocation("shadowViewMatrix"+c),this._uShadowProjMatrix[c]=o.getLocation("shadowProjMatrix"+c))}i.lightMaps.length>0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(c=0,f=a.sectionPlanes.length;c<f;c++)this._uSectionPlanes.push({active:o.getLocation("sectionPlaneActive"+c),pos:o.getLocation("sectionPlanePos"+c),dir:o.getLocation("sectionPlaneDir"+c)});switch(this._uPointSize=o.getLocation("pointSize"),s.type){case"LambertMaterial":this._uMaterialColor=o.getLocation("materialColor"),this._uMaterialEmissive=o.getLocation("materialEmissive"),this._uAlphaModeCutoff=o.getLocation("materialAlphaModeCutoff");break;case"PhongMaterial":this._uMaterialAmbient=o.getLocation("materialAmbient"),this._uMaterialDiffuse=o.getLocation("materialDiffuse"),this._uMaterialSpecular=o.getLocation("materialSpecular"),this._uMaterialEmissive=o.getLocation("materialEmissive"),this._uAlphaModeCutoff=o.getLocation("materialAlphaModeCutoff"),this._uMaterialShininess=o.getLocation("materialShininess"),r._ambientMap&&(this._uMaterialAmbientMap="ambientMap",this._uMaterialAmbientMapMatrix=o.getLocation("ambientMapMatrix")),r._diffuseMap&&(this._uDiffuseMap="diffuseMap",this._uDiffuseMapMatrix=o.getLocation("diffuseMapMatrix")),r._specularMap&&(this._uSpecularMap="specularMap",this._uSpecularMapMatrix=o.getLocation("specularMapMatrix")),r._emissiveMap&&(this._uEmissiveMap="emissiveMap",this._uEmissiveMapMatrix=o.getLocation("emissiveMapMatrix")),r._alphaMap&&(this._uAlphaMap="alphaMap",this._uAlphaMapMatrix=o.getLocation("alphaMapMatrix")),r._reflectivityMap&&(this._uReflectivityMap="reflectivityMap",this._uReflectivityMapMatrix=o.getLocation("reflectivityMapMatrix")),r._normalMap&&(this._uNormalMap="normalMap",this._uNormalMapMatrix=o.getLocation("normalMapMatrix")),r._occlusionMap&&(this._uOcclusionMap="occlusionMap",this._uOcclusionMapMatrix=o.getLocation("occlusionMapMatrix")),r._diffuseFresnel&&(this._uDiffuseFresnelEdgeBias=o.getLocation("diffuseFresnelEdgeBias"),this._uDiffuseFresnelCenterBias=o.getLocation("diffuseFresnelCenterBias"),this._uDiffuseFresnelEdgeColor=o.getLocation("diffuseFresnelEdgeColor"),this._uDiffuseFresnelCenterColor=o.getLocation("diffuseFresnelCenterColor"),this._uDiffuseFresnelPower=o.getLocation("diffuseFresnelPower")),r._specularFresnel&&(this._uSpecularFresnelEdgeBias=o.getLocation("specularFresnelEdgeBias"),this._uSpecularFresnelCenterBias=o.getLocation("specularFresnelCenterBias"),this._uSpecularFresnelEdgeColor=o.getLocation("specularFresnelEdgeColor"),this._uSpecularFresnelCenterColor=o.getLocation("specularFresnelCenterColor"),this._uSpecularFresnelPower=o.getLocation("specularFresnelPower")),r._alphaFresnel&&(this._uAlphaFresnelEdgeBias=o.getLocation("alphaFresnelEdgeBias"),this._uAlphaFresnelCenterBias=o.getLocation("alphaFresnelCenterBias"),this._uAlphaFresnelEdgeColor=o.getLocation("alphaFresnelEdgeColor"),this._uAlphaFresnelCenterColor=o.getLocation("alphaFresnelCenterColor"),this._uAlphaFresnelPower=o.getLocation("alphaFresnelPower")),r._reflectivityFresnel&&(this._uReflectivityFresnelEdgeBias=o.getLocation("reflectivityFresnelEdgeBias"),this._uReflectivityFresnelCenterBias=o.getLocation("reflectivityFresnelCenterBias"),this._uReflectivityFresnelEdgeColor=o.getLocation("reflectivityFresnelEdgeColor"),this._uReflectivityFresnelCenterColor=o.getLocation("reflectivityFresnelCenterColor"),this._uReflectivityFresnelPower=o.getLocation("reflectivityFresnelPower")),r._emissiveFresnel&&(this._uEmissiveFresnelEdgeBias=o.getLocation("emissiveFresnelEdgeBias"),this._uEmissiveFresnelCenterBias=o.getLocation("emissiveFresnelCenterBias"),this._uEmissiveFresnelEdgeColor=o.getLocation("emissiveFresnelEdgeColor"),this._uEmissiveFresnelCenterColor=o.getLocation("emissiveFresnelCenterColor"),this._uEmissiveFresnelPower=o.getLocation("emissiveFresnelPower"));break;case"MetallicMaterial":this._uBaseColor=o.getLocation("materialBaseColor"),this._uMaterialMetallic=o.getLocation("materialMetallic"),this._uMaterialRoughness=o.getLocation("materialRoughness"),this._uMaterialSpecularF0=o.getLocation("materialSpecularF0"),this._uMaterialEmissive=o.getLocation("materialEmissive"),this._uAlphaModeCutoff=o.getLocation("materialAlphaModeCutoff"),r._baseColorMap&&(this._uBaseColorMap="baseColorMap",this._uBaseColorMapMatrix=o.getLocation("baseColorMapMatrix")),r._metallicMap&&(this._uMetallicMap="metallicMap",this._uMetallicMapMatrix=o.getLocation("metallicMapMatrix")),r._roughnessMap&&(this._uRoughnessMap="roughnessMap",this._uRoughnessMapMatrix=o.getLocation("roughnessMapMatrix")),r._metallicRoughnessMap&&(this._uMetallicRoughnessMap="metallicRoughnessMap",this._uMetallicRoughnessMapMatrix=o.getLocation("metallicRoughnessMapMatrix")),r._emissiveMap&&(this._uEmissiveMap="emissiveMap",this._uEmissiveMapMatrix=o.getLocation("emissiveMapMatrix")),r._occlusionMap&&(this._uOcclusionMap="occlusionMap",this._uOcclusionMapMatrix=o.getLocation("occlusionMapMatrix")),r._alphaMap&&(this._uAlphaMap="alphaMap",this._uAlphaMapMatrix=o.getLocation("alphaMapMatrix")),r._normalMap&&(this._uNormalMap="normalMap",this._uNormalMapMatrix=o.getLocation("normalMapMatrix"));break;case"SpecularMaterial":this._uMaterialDiffuse=o.getLocation("materialDiffuse"),this._uMaterialSpecular=o.getLocation("materialSpecular"),this._uMaterialGlossiness=o.getLocation("materialGlossiness"),this._uMaterialReflectivity=o.getLocation("reflectivityFresnel"),this._uMaterialEmissive=o.getLocation("materialEmissive"),this._uAlphaModeCutoff=o.getLocation("materialAlphaModeCutoff"),r._diffuseMap&&(this._uDiffuseMap="diffuseMap",this._uDiffuseMapMatrix=o.getLocation("diffuseMapMatrix")),r._specularMap&&(this._uSpecularMap="specularMap",this._uSpecularMapMatrix=o.getLocation("specularMapMatrix")),r._glossinessMap&&(this._uGlossinessMap="glossinessMap",this._uGlossinessMapMatrix=o.getLocation("glossinessMapMatrix")),r._specularGlossinessMap&&(this._uSpecularGlossinessMap="materialSpecularGlossinessMap",this._uSpecularGlossinessMapMatrix=o.getLocation("materialSpecularGlossinessMapMatrix")),r._emissiveMap&&(this._uEmissiveMap="emissiveMap",this._uEmissiveMapMatrix=o.getLocation("emissiveMapMatrix")),r._occlusionMap&&(this._uOcclusionMap="occlusionMap",this._uOcclusionMapMatrix=o.getLocation("occlusionMapMatrix")),r._alphaMap&&(this._uAlphaMap="alphaMap",this._uAlphaMapMatrix=o.getLocation("alphaMapMatrix")),r._normalMap&&(this._uNormalMap="normalMap",this._uNormalMapMatrix=o.getLocation("normalMapMatrix"))}this._aPosition=o.getAttribute("position"),this._aNormal=o.getAttribute("normal"),this._aUV=o.getAttribute("uv"),this._aColor=o.getAttribute("color"),this._aFlags=o.getAttribute("flags"),this._uClippable=o.getLocation("clippable"),this._uColorize=o.getLocation("colorize"),this._uOffset=o.getLocation("offset"),this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null,this._lastColorize=new Float32Array(4),this._baseTextureUnit=0}},Pi.prototype._bindProgram=function(e){var t,n=Ze.MAX_TEXTURE_UNITS,r=this._scene,i=r.canvas.gl,a=r._lightsState,s=r.camera.project,o=this._program;if(o.bind(),e.useProgram++,e.textureUnit=0,this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null,this._lastColorize[0]=-1,this._lastColorize[1]=-1,this._lastColorize[2]=-1,this._lastColorize[3]=-1,i.uniformMatrix4fv(this._uProjMatrix,!1,s.matrix),r.logarithmicDepthBufferEnabled){var l=2/(Math.log(s.far+1)/Math.LN2);i.uniform1f(this._uLogDepthBufFC,l)}for(var u=0,c=a.lights.length;u<c;u++)if(t=a.lights[u],this._uLightAmbient[u])i.uniform4f(this._uLightAmbient[u],t.color[0],t.color[1],t.color[2],t.intensity);else if(this._uLightColor[u]&&i.uniform4f(this._uLightColor[u],t.color[0],t.color[1],t.color[2],t.intensity),this._uLightPos[u]&&(i.uniform3fv(this._uLightPos[u],t.pos),this._uLightAttenuation[u]&&i.uniform1f(this._uLightAttenuation[u],t.attenuation)),this._uLightDir[u]&&i.uniform3fv(this._uLightDir[u],t.dir),t.castsShadow){this._uShadowViewMatrix[u]&&i.uniformMatrix4fv(this._uShadowViewMatrix[u],!1,t.getShadowViewMatrix()),this._uShadowProjMatrix[u]&&i.uniformMatrix4fv(this._uShadowProjMatrix[u],!1,t.getShadowProjMatrix());var f=t.getShadowRenderBuf();f&&(o.bindTexture("shadowMap"+u,f.getTexture(),e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++)}a.lightMaps.length>0&&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<c;u++){var f=n.lights[u];"ambient"!==f.type&&(l.push("uniform vec4 lightColor"+u+";"),"dir"===f.type&&l.push("uniform vec3 lightDir"+u+";"),"point"===f.type&&l.push("uniform vec3 lightPos"+u+";"),"spot"===f.type&&l.push("uniform vec3 lightPos"+u+";"))}a&&(l.push("vec3 octDecode(vec2 oct) {"),l.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),l.push(" if (v.z < 0.0) {"),l.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);"),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;p<A;p++){var d=n.lights[p];if("ambient"!==d.type){if("dir"===d.type)"view"===d.space?l.push("viewLightDir = normalize(lightDir"+p+");"):l.push("viewLightDir = normalize((viewMatrix2 * vec4(lightDir"+p+", 0.0)).xyz);");else{if("point"!==d.type)continue;"view"===d.space?l.push("viewLightDir = normalize(lightPos"+p+" - viewPosition.xyz);"):l.push("viewLightDir = normalize((viewMatrix2 * vec4(lightPos"+p+", 0.0)).xyz);")}l.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),l.push("reflectedColor += lambertian * (lightColor"+p+".rgb * lightColor"+p+".a);")}}l.push("vColor = vec4(reflectedColor * fillColor.rgb, fillColor.a);"),i&&l.push("vWorldPosition = worldPosition;");"points"===e._geometry._state.primitiveName&&l.push("gl_PointSize = pointSize;");l.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(l.push("vFragDepth = 1.0 + clipPos.w;"),l.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return l.push("gl_Position = clipPos;"),l.push("}"),l}(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("// 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<o;s++)a.push("uniform bool sectionPlaneActive"+s+";"),a.push("uniform vec3 sectionPlanePos"+s+";"),a.push("uniform vec3 sectionPlaneDir"+s+";")}if(a.push("in vec4 vColor;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),i){a.push("if (clippable) {"),a.push(" float dist = 0.0;");for(var l=0,u=n.sectionPlanes.length;l<u;l++)a.push("if (sectionPlaneActive"+l+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+l+".xyz, vWorldPosition.xyz - sectionPlanePos"+l+".xyz), 0.0, 1000.0);"),a.push("}");a.push(" if (dist > 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;A<c;A++){var d=this._uSectionPlanes[A];if(d){var v=p.sectionPlanesActivePerLayer[A];if(a.uniform1i(d.active,v?1:0),v){var h=f[A];a.uniform3fv(d.pos,u?ge(h.dist,h.dir,u,Bi):h.pos),a.uniform3fv(d.dir,h.dir)}}}}if(s.id!==this._lastMaterialId){var I=s.fillColor,y=s.backfaces;e.backfaces!==y&&(y?a.disable(a.CULL_FACE):a.enable(a.CULL_FACE),e.backfaces=y),a.uniform4f(this._uFillColor,I[0],I[1],I[2],s.fillAlpha),this._lastMaterialId=s.id}a.uniformMatrix4fv(this._uModelMatrix,a.FALSE,t.worldMatrix),this._uModelNormalMatrix&&a.uniformMatrix4fv(this._uModelNormalMatrix,a.FALSE,t.worldNormalMatrix),this._uClippable&&a.uniform1i(this._uClippable,o.clippable),a.uniform3fv(this._uOffset,o.offset),l.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&a.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,l.positionsDecodeMatrix),this._uUVDecodeMatrix&&a.uniformMatrix3fv(this._uUVDecodeMatrix,!1,l.uvDecodeMatrix),this._aPosition&&(this._aPosition.bindArrayBuffer(l.positionsBuf),e.bindArray++),this._aNormal&&(this._aNormal.bindArrayBuffer(l.normalsBuf),e.bindArray++),l.indicesBuf?(l.indicesBuf.bind(),e.bindArray++):l.positionsBuf,this._lastGeometryId=l.id),l.indicesBuf?(a.drawElements(l.primitive,l.indicesBuf.numItems,l.indicesBuf.itemType,0),e.drawElements++):l.positionsBuf&&(a.drawArrays(a.TRIANGLES,0,l.positionsBuf.numItems),e.drawArrays++)},Oi.prototype._allocate=function(e){var t=e.scene,n=t._lightsState,r=t._sectionPlanesState,i=t.canvas.gl;if(this._program=new ft(i,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var a=this._program;this._uPositionsDecodeMatrix=a.getLocation("positionsDecodeMatrix"),this._uModelMatrix=a.getLocation("modelMatrix"),this._uModelNormalMatrix=a.getLocation("modelNormalMatrix"),this._uViewMatrix=a.getLocation("viewMatrix"),this._uViewNormalMatrix=a.getLocation("viewNormalMatrix"),this._uProjMatrix=a.getLocation("projMatrix"),this._uLightAmbient=[],this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];for(var s=0,o=n.lights.length;s<o;s++){switch(n.lights[s].type){case"ambient":this._uLightAmbient[s]=a.getLocation("lightAmbient");break;case"dir":this._uLightColor[s]=a.getLocation("lightColor"+s),this._uLightPos[s]=null,this._uLightDir[s]=a.getLocation("lightDir"+s);break;case"point":this._uLightColor[s]=a.getLocation("lightColor"+s),this._uLightPos[s]=a.getLocation("lightPos"+s),this._uLightDir[s]=null,this._uLightAttenuation[s]=a.getLocation("lightAttenuation"+s)}}this._uSectionPlanes=[];for(var l=0,u=r.sectionPlanes.length;l<u;l++)this._uSectionPlanes.push({active:a.getLocation("sectionPlaneActive"+l),pos:a.getLocation("sectionPlanePos"+l),dir:a.getLocation("sectionPlaneDir"+l)});this._uFillColor=a.getLocation("fillColor"),this._aPosition=a.getAttribute("position"),this._aNormal=a.getAttribute("normal"),this._uClippable=a.getLocation("clippable"),this._uGammaFactor=a.getLocation("gammaFactor"),this._uOffset=a.getLocation("offset"),t.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=a.getLocation("logDepthBufFC")),this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null}},Oi.prototype._bindProgram=function(e){var t=this._scene,n=t.canvas.gl,r=t._lightsState,i=t.camera,a=i.project;if(this._program.bind(),e.useProgram++,e.textureUnit=0,this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null,this._lastIndicesBufId=null,n.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.normalMatrix),n.uniformMatrix4fv(this._uProjMatrix,!1,a.matrix),t.logarithmicDepthBufferEnabled){var s=2/(Math.log(a.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,s)}for(var o=0,l=r.lights.length;o<l;o++){var u=r.lights[o];this._uLightAmbient[o]?n.uniform4f(this._uLightAmbient[o],u.color[0],u.color[1],u.color[2],u.intensity):(this._uLightColor[o]&&n.uniform4f(this._uLightColor[o],u.color[0],u.color[1],u.color[2],u.intensity),this._uLightPos[o]&&(n.uniform3fv(this._uLightPos[o],u.pos),this._uLightAttenuation[o]&&n.uniform1f(this._uLightAttenuation[o],u.attenuation)),this._uLightDir[o]&&n.uniform3fv(this._uLightDir[o],u.dir))}this._uGammaFactor&&n.uniform1f(this._uGammaFactor,t.gammaFactor)};var Ni=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene,n=t._sectionPlanesState.sectionPlanes.length>0,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<o;s++)a.push("uniform bool sectionPlaneActive"+s+";"),a.push("uniform vec3 sectionPlanePos"+s+";"),a.push("uniform vec3 sectionPlaneDir"+s+";")}if(a.push("in vec4 vColor;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),i){a.push("if (clippable) {"),a.push(" float dist = 0.0;");for(var l=0,u=n.sectionPlanes.length;l<u;l++)a.push("if (sectionPlaneActive"+l+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+l+".xyz, vWorldPosition.xyz - sectionPlanePos"+l+".xyz), 0.0, 1000.0);"),a.push("}");a.push(" if (dist > 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;v<p;v++){var h=this._uSectionPlanes[v];if(h){var I=d.sectionPlanesActivePerLayer[v];if(o.uniform1i(h.active,I?1:0),I){var y=A[v];o.uniform3fv(h.pos,f?ge(y.dist,y.dir,f,xi):y.pos),o.uniform3fv(h.dir,y.dir)}}}}switch(n){case 0:r=t._xrayMaterial._state;break;case 1:r=t._highlightMaterial._state;break;case 2:r=t._selectedMaterial._state;break;default:r=t._edgeMaterial._state}if(r.id!==this._lastMaterialId){var m=r.backfaces;if(e.backfaces!==m&&(m?o.disable(o.CULL_FACE):o.enable(o.CULL_FACE),e.backfaces=m),e.lineWidth!==r.edgeWidth&&(o.lineWidth(r.edgeWidth),e.lineWidth=r.edgeWidth),this._uEdgeColor){var w=r.edgeColor,g=r.edgeAlpha;o.uniform4f(this._uEdgeColor,w[0],w[1],w[2],g)}this._lastMaterialId=r.id}o.uniformMatrix4fv(this._uModelMatrix,o.FALSE,t.worldMatrix),this._uClippable&&o.uniform1i(this._uClippable,l.clippable),o.uniform3fv(this._uOffset,l.offset),c.primitive===o.TRIANGLES?i=u._getEdgeIndices():c.primitive===o.LINES&&(i=c.indicesBuf),i&&(c.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&o.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,c.positionsDecodeMatrix),this._aPosition&&(this._aPosition.bindArrayBuffer(c.positionsBuf,c.compressGeometry?o.UNSIGNED_SHORT:o.FLOAT),e.bindArray++),i.bind(),e.bindArray++,this._lastGeometryId=c.id),o.drawElements(o.LINES,i.numItems,i.itemType,0),e.drawElements++)},Mi.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl,r=t._sectionPlanesState;if(this._program=new ft(n,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var i=this._program;this._uPositionsDecodeMatrix=i.getLocation("positionsDecodeMatrix"),this._uModelMatrix=i.getLocation("modelMatrix"),this._uViewMatrix=i.getLocation("viewMatrix"),this._uProjMatrix=i.getLocation("projMatrix"),this._uSectionPlanes=[];for(var a=0,s=r.sectionPlanes.length;a<s;a++)this._uSectionPlanes.push({active:i.getLocation("sectionPlaneActive"+a),pos:i.getLocation("sectionPlanePos"+a),dir:i.getLocation("sectionPlaneDir"+a)});this._uEdgeColor=i.getLocation("edgeColor"),this._aPosition=i.getAttribute("position"),this._uClippable=i.getLocation("clippable"),this._uGammaFactor=i.getLocation("gammaFactor"),this._uOffset=i.getLocation("offset"),t.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=i.getLocation("logDepthBufFC")),this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null}},Mi.prototype._bindProgram=function(e){var t=this._program,n=this._scene,r=n.canvas.gl,i=n.camera.project;if(t.bind(),e.useProgram++,this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null,r.uniformMatrix4fv(this._uProjMatrix,!1,i.matrix),n.logarithmicDepthBufferEnabled){var a=2/(Math.log(i.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,a)}this._uGammaFactor&&r.uniform1f(this._uGammaFactor,n.gammaFactor)};var Hi=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene,n=t._sectionPlanesState.sectionPlanes.length>0,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<n.sectionPlanes.length;a++)i.push("uniform bool sectionPlaneActive"+a+";"),i.push("uniform vec3 sectionPlanePos"+a+";"),i.push("uniform vec3 sectionPlaneDir"+a+";")}if(i.push("out vec4 outColor;"),i.push("void main(void) {"),r){i.push("if (clippable) {"),i.push(" float dist = 0.0;");for(a=0;a<n.sectionPlanes.length;a++)i.push("if (sectionPlaneActive"+a+") {"),i.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),i.push("}");i.push(" if (dist > 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<l;f++){var p=this._uSectionPlanes[f];if(p){var A=c.sectionPlanesActivePerLayer[f];if(r.uniform1i(p.active,A?1:0),A){var d=u[f];r.uniform3fv(p.pos,o?ge(d.dist,d.dir,o,Ui):d.pos),r.uniform3fv(p.dir,d.dir)}}}}if(a.id!==this._lastMaterialId){var v=a.backfaces;e.backfaces!==v&&(v?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),e.backfaces=v);var h=a.frontface;e.frontface!==h&&(h?r.frontFace(r.CCW):r.frontFace(r.CW),e.frontface=h),this._lastMaterialId=a.id}r.uniformMatrix4fv(this._uProjMatrix,!1,e.pickProjMatrix),r.uniformMatrix4fv(this._uModelMatrix,!1,t.worldMatrix),this._uClippable&&r.uniform1i(this._uClippable,t._state.clippable),r.uniform3fv(this._uOffset,t._state.offset),s.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&r.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,s.positionsDecodeMatrix),this._aPosition&&(this._aPosition.bindArrayBuffer(s.positionsBuf,s.compressGeometry?r.UNSIGNED_SHORT:r.FLOAT),e.bindArray++),s.indicesBuf&&(s.indicesBuf.bind(),e.bindArray++),this._lastGeometryId=s.id);var I=t._state.pickID,y=I>>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;i<a;i++)this._uSectionPlanes.push({active:r.getLocation("sectionPlaneActive"+i),pos:r.getLocation("sectionPlanePos"+i),dir:r.getLocation("sectionPlaneDir"+i)});this._aPosition=r.getAttribute("position"),this._uClippable=r.getLocation("clippable"),this._uPickColor=r.getLocation("pickColor"),this._uOffset=r.getLocation("offset"),t.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=r.getLocation("logDepthBufFC")),this._lastMaterialId=null,this._lastGeometryId=null}},Gi.prototype._bindProgram=function(e){var t=this._scene,n=t.canvas.gl,r=t.camera.project;if(this._program.bind(),e.useProgram++,t.logarithmicDepthBufferEnabled){var i=2/(Math.log(r.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,i)}this._lastMaterialId=null,this._lastGeometryId=null};var Vi=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene,n=t._sectionPlanesState.sectionPlanes.length>0,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<n.sectionPlanes.length;a++)i.push("uniform bool sectionPlaneActive"+a+";"),i.push("uniform vec3 sectionPlanePos"+a+";"),i.push("uniform vec3 sectionPlaneDir"+a+";")}if(i.push("out vec4 outColor;"),i.push("void main(void) {"),r){i.push("if (clippable) {"),i.push(" float dist = 0.0;");for(var s=0;s<n.sectionPlanes.length;s++)i.push("if (sectionPlaneActive"+s+") {"),i.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),i.push("}");i.push(" if (dist > 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;y<v;y++){var m=this._uSectionPlanes[y];if(m){var w=I.sectionPlanesActivePerLayer[y];if(r.uniform1i(m.active,w?1:0),w){var g=h[y];r.uniform3fv(m.pos,l?ge(g.dist,g.dir,l,ji):g.pos),r.uniform3fv(m.dir,g.dir)}}}}r.uniformMatrix4fv(this._uProjMatrix,!1,e.pickProjMatrix),n.logarithmicDepthBufferEnabled&&r.uniform1f(this._uZFar,n.camera.project.far),e.backfaces!==u&&(u?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),e.backfaces=u),e.frontface!==c&&(c?r.frontFace(r.CCW):r.frontFace(r.CW),e.frontface=c),r.uniformMatrix4fv(this._uModelMatrix,!1,t.worldMatrix),this._uClippable&&r.uniform1i(this._uClippable,t._state.clippable),r.uniform3fv(this._uOffset,t._state.offset),this._uPositionsDecodeMatrix?(r.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,o.positionsDecodeMatrix),this._aPosition.bindArrayBuffer(p,o.compressGeometry?r.UNSIGNED_SHORT:r.FLOAT)):this._aPosition.bindArrayBuffer(p),A.bind(),r.enableVertexAttribArray(this._aColor.location),r.vertexAttribPointer(this._aColor.location,A.itemSize,A.itemType,!0,0,0),r.drawArrays(o.primitive,0,p.numItems/3)},Qi.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl;if(this._program=new ft(n,this._shaderSource),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._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var i=0,a=t._sectionPlanesState.sectionPlanes.length;i<a;i++)this._uSectionPlanes.push({active:r.getLocation("sectionPlaneActive"+i),pos:r.getLocation("sectionPlanePos"+i),dir:r.getLocation("sectionPlaneDir"+i)});this._aPosition=r.getAttribute("position"),this._aColor=r.getAttribute("color"),this._uClippable=r.getLocation("clippable"),this._uOffset=r.getLocation("offset"),t.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=r.getLocation("logDepthBufFC"))}};var zi=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene,n=t._sectionPlanesState.sectionPlanes.length>0,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<n.sectionPlanes.length;a++)i.push("uniform bool sectionPlaneActive"+a+";"),i.push("uniform vec3 sectionPlanePos"+a+";"),i.push("uniform vec3 sectionPlaneDir"+a+";")}if(i.push("out vec4 outColor;"),i.push("void main(void) {"),r){i.push("if (clippable) {"),i.push(" float dist = 0.0;");for(a=0;a<n.sectionPlanes.length;a++)i.push("if (sectionPlaneActive"+a+") {"),i.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),i.push("}");i.push(" if (dist > 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;d<f;d++){var v=this._uSectionPlanes[d];if(v){var h=A.sectionPlanesActivePerLayer[d];if(r.uniform1i(v.active,h?1:0),h){var I=p[d];r.uniform3fv(v.pos,o?ge(I.dist,I.dir,o,Ki):I.pos),r.uniform3fv(v.dir,I.dir)}}}}r.uniformMatrix4fv(this._uProjMatrix,!1,c._project._state.matrix),r.uniformMatrix4fv(this._uModelMatrix,r.FALSE,t.worldMatrix),this._uClippable&&r.uniform1i(this._uClippable,t._state.clippable),r.uniform3fv(this._uOffset,t._state.offset),s.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&r.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,s.positionsDecodeMatrix),this._aPosition&&(this._aPosition.bindArrayBuffer(s.positionsBuf,s.compressGeometry?r.UNSIGNED_SHORT:r.FLOAT),e.bindArray++),s.indicesBuf&&(s.indicesBuf.bind(),e.bindArray++),this._lastGeometryId=s.id),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)},Yi.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;i<a;i++)this._uSectionPlanes.push({active:r.getLocation("sectionPlaneActive"+i),pos:r.getLocation("sectionPlanePos"+i),dir:r.getLocation("sectionPlaneDir"+i)});this._aPosition=r.getAttribute("position"),this._uClippable=r.getLocation("clippable"),this._uOffset=r.getLocation("offset"),t.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=r.getLocation("logDepthBufFC")),this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null}},Yi.prototype._bindProgram=function(e){var t=this._scene,n=t.camera.project,r=t.canvas.gl;if(this._program.bind(),e.useProgram++,r.uniformMatrix4fv(this._uProjMatrix,!1,n.matrix),t.logarithmicDepthBufferEnabled){var i=2/(Math.log(n.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,i)}this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null};var qi=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene._sectionPlanesState.sectionPlanes.length>0,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<n.sectionPlanes.length;a++)i.push("uniform bool sectionPlaneActive"+a+";"),i.push("uniform vec3 sectionPlanePos"+a+";"),i.push("uniform vec3 sectionPlaneDir"+a+";")}if(i.push("vec4 encodeFloat( const in float depth ) {"),i.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"),i.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"),i.push(" vec4 comp = fract(depth * bitShift);"),i.push(" comp -= comp.xxyz * bitMask;"),i.push(" return comp;"),i.push("}"),i.push("out vec4 outColor;"),i.push("void main(void) {"),r){i.push("if (clippable) {"),i.push(" float dist = 0.0;");for(a=0;a<n.sectionPlanes.length;a++)i.push("if (sectionPlaneActive"+a+") {"),i.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),i.push("}");i.push(" if (dist > 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;i<a;i++)this._uSectionPlanes.push({active:r.getLocation("sectionPlaneActive"+i),pos:r.getLocation("sectionPlanePos"+i),dir:r.getLocation("sectionPlaneDir"+i)});this._aPosition=r.getAttribute("position"),this._uClippable=r.getLocation("clippable"),this._uOffset=r.getLocation("offset"),this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null}},Ji.prototype._bindProgram=function(e){this._program||this._allocate(mesh);var t=this._scene,n=t.canvas.gl,r=t._sectionPlanesState;if(this._program.bind(),e.useProgram++,n.uniformMatrix4fv(this._uShadowViewMatrix,!1,e.shadowViewMatrix),n.uniformMatrix4fv(this._uShadowProjMatrix,!1,e.shadowProjMatrix),this._lastMaterialId=null,this._lastVertexBufsId=null,this._lastGeometryId=null,r.sectionPlanes.length>0)for(var i,a,s,o=0,l=this._uSectionPlanes.length;o<l;o++)a=(i=this._uSectionPlanes[o]).active,s=r.sectionPlanes[o],a&&n.uniform1i(a,s.active),i.pos&&n.uniform3fv(i.pos,s.pos),i.dir&&n.uniform3fv(i.dir,s.dir)};var $i=function(){function e(){b(this,e),this.visibleLayers=[],this.sectionPlanesActivePerLayer=[],this.reset()}return P(e,[{key:"reset",value:function(){this.culled=!1,this.sectioned=!1,this.numLayers=0,this.numVisibleLayers=0,this.colorOpaque=!1,this.colorTransparent=!1,this.edgesOpaque=!1,this.edgesTransparent=!1,this.xrayedSilhouetteOpaque=!1,this.xrayedEdgesOpaque=!1,this.xrayedSilhouetteTransparent=!1,this.xrayedEdgesTransparent=!1,this.highlightedSilhouetteOpaque=!1,this.highlightedEdgesOpaque=!1,this.highlightedSilhouetteTransparent=!1,this.highlightedEdgesTransparent=!1,this.selectedSilhouetteOpaque=!1,this.selectedEdgesOpaque=!1,this.selectedSilhouetteTransparent=!1,this.selectedEdgesTransparent=!1}}]),e}(),ea=Z.OBB3(),ta=Z.vec4(),na=Z.vec4(),ra=Z.vec4(),ia=Z.vec3([1,0,0]),aa=Z.vec3([0,1,0]),sa=Z.vec3([0,0,1]),oa=Z.vec3(3),la=Z.vec3(3),ua=Z.identityMat4(),ca=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i)).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;t<n;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}},{key:"_buildWorldNormalMatrix",value:function(){this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldNormalMatrix||(this._worldNormalMatrix=Z.mat4()),Z.transposeMat4(this._worldMatrix,this._worldNormalMatrix),Z.inverseMat4(this._worldNormalMatrix),this._worldNormalMatrixDirty=!1}},{key:"_setAABBDirty",value:function(){if(this.collidable)for(var e=this;e;e=e._parentNode)e._aabbDirty=!0}},{key:"_updateAABB",value:function(){this.scene._aabbDirty=!0,this._aabb||(this._aabb=Z.AABB3()),this._buildAABB(this.worldMatrix,this._aabb),this._aabbDirty=!1}},{key:"_webglContextRestored",value:function(){this._drawRenderer&&this._drawRenderer.webglContextRestored(),this._shadowRenderer&&this._shadowRenderer.webglContextRestored(),this._emphasisFillRenderer&&this._emphasisFillRenderer.webglContextRestored(),this._emphasisEdgesRenderer&&this._emphasisEdgesRenderer.webglContextRestored(),this._pickMeshRenderer&&this._pickMeshRenderer.webglContextRestored(),this._pickTriangleRenderer&&this._pickMeshRenderer.webglContextRestored(),this._occlusionRenderer&&this._occlusionRenderer.webglContextRestored()}},{key:"_makeDrawHash",value:function(){var e=this.scene,t=[e.canvas.canvas.id,(e.gammaInput?"gi;":";")+(e.gammaOutput?"go":""),e._lightsState.getHash(),e._sectionPlanesState.getHash()],n=this._state;return n.stationary&&t.push("/s"),"none"===n.billboard?t.push("/n"):"spherical"===n.billboard?t.push("/s"):"cylindrical"===n.billboard&&t.push("/c"),n.receivesShadow&&t.push("/rs"),t.push(";"),t.join("")}},{key:"_makePickHash",value:function(){var e=this.scene,t=[e.canvas.canvas.id,e._sectionPlanesState.getHash()],n=this._state;return n.stationary&&t.push("/s"),"none"===n.billboard?t.push("/n"):"spherical"===n.billboard?t.push("/s"):"cylindrical"===n.billboard&&t.push("/c"),t.push(";"),t.join("")}},{key:"_makeOcclusionHash",value:function(){var e=this.scene,t=[e.canvas.canvas.id,e._sectionPlanesState.getHash()],n=this._state;return n.stationary&&t.push("/s"),"none"===n.billboard?t.push("/n"):"spherical"===n.billboard?t.push("/s"):"cylindrical"===n.billboard&&t.push("/c"),t.push(";"),t.join("")}},{key:"_buildAABB",value:function(e,t){Z.transformOBB3(e,this._geometry.obb,ea),Z.OBB3ToAABB3(ea,t);var n=this._state.offset;if(t[0]+=n[0],t[1]+=n[1],t[2]+=n[2],t[3]+=n[0],t[4]+=n[1],t[5]+=n[2],this._state.origin){var r=this._state.origin;t[0]+=r[0],t[1]+=r[1],t[2]+=r[2],t[3]+=r[0],t[4]+=r[1],t[5]+=r[2]}}},{key:"rotate",value:function(e,t){return ta[0]=e[0],ta[1]=e[1],ta[2]=e[2],ta[3]=t*Z.DEGTORAD,Z.angleAxisToQuaternion(ta,na),Z.mulQuaternions(this.quaternion,na,ra),this.quaternion=ra,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return ta[0]=e[0],ta[1]=e[1],ta[2]=e[2],ta[3]=t*Z.DEGTORAD,Z.angleAxisToQuaternion(ta,na),Z.mulQuaternions(na,this.quaternion,na),this}},{key:"rotateX",value:function(e){return this.rotate(ia,e)}},{key:"rotateY",value:function(e){return this.rotate(aa,e)}},{key:"rotateZ",value:function(e){return this.rotate(sa,e)}},{key:"translate",value:function(e,t){return Z.vec3ApplyQuaternion(this.quaternion,e,oa),Z.mulVec3Scalar(oa,t,la),Z.addVec3(this.position,la,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"translateX",value:function(e){return this.translate(ia,e)}},{key:"translateY",value:function(e){return this.translate(aa,e)}},{key:"translateZ",value:function(e){return this.translate(sa,e)}},{key:"_putDrawRenderers",value:function(){this._drawRenderer&&(this._drawRenderer.put(),this._drawRenderer=null),this._shadowRenderer&&(this._shadowRenderer.put(),this._shadowRenderer=null),this._emphasisFillRenderer&&(this._emphasisFillRenderer.put(),this._emphasisFillRenderer=null),this._emphasisEdgesRenderer&&(this._emphasisEdgesRenderer.put(),this._emphasisEdgesRenderer=null)}},{key:"_putPickRenderers",value:function(){this._pickMeshRenderer&&(this._pickMeshRenderer.put(),this._pickMeshRenderer=null),this._pickTriangleRenderer&&(this._pickTriangleRenderer.put(),this._pickTriangleRenderer=null)}},{key:"_putOcclusionRenderer",value:function(){this._occlusionRenderer&&(this._occlusionRenderer.put(),this._occlusionRenderer=null)}},{key:"stateSortCompare",value:function(e,t){return e._state.layer-t._state.layer||e._drawRenderer.id-t._drawRenderer.id||e._material._state.id-t._material._state.id||e._geometry._state.id-t._geometry._state.id}},{key:"rebuildRenderFlags",value:function(){this.renderFlags.reset(),this._getActiveSectionPlanes()?(this.renderFlags.numLayers=1,this.renderFlags.numVisibleLayers=1,this.renderFlags.visibleLayers[0]=0,this._updateRenderFlags()):this.renderFlags.culled=!0}},{key:"_updateRenderFlags",value:function(){var e=this.renderFlags,t=this._state;if(t.xrayed){var n=this._xrayMaterial._state;n.fill&&(n.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),n.edges&&(n.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}else{if(this._material._state.alpha<1||t.colorize[3]<1?e.colorTransparent=!0:e.colorOpaque=!0,t.edges)this._edgeMaterial._state.alpha<1?e.edgesTransparent=!0:e.edgesOpaque=!0;if(t.selected){var r=this._selectedMaterial._state;r.fill&&(r.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),r.edges&&(r.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}else if(t.highlighted){var i=this._highlightMaterial._state;i.fill&&(i.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),i.edges&&(i.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"_getActiveSectionPlanes",value:function(){if(this._state.clippable){var e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(var n=0;n<t;n++){var r=e[n],i=this.renderFlags;if(r.active)if(this._state.origin){var a=Z.planeAABB3Intersect(r.dir,r.dist,this.aabb);if(-1===a)return!1;var s=0===a;i.sectionPlanesActivePerLayer[n]=s}else i.sectionPlanesActivePerLayer[n]=!0;else i.sectionPlanesActivePerLayer[n]=!1}}return!0}},{key:"drawColorOpaque",value:function(e){(this._drawRenderer||(this._drawRenderer=Pi.get(this)))&&this._drawRenderer.drawMesh(e,this)}},{key:"drawColorTransparent",value:function(e){(this._drawRenderer||(this._drawRenderer=Pi.get(this)))&&this._drawRenderer.drawMesh(e,this)}},{key:"drawSilhouetteXRayed",value:function(e){(this._emphasisFillRenderer||(this._emphasisFillRenderer=Oi.get(this)))&&this._emphasisFillRenderer.drawMesh(e,this,0)}},{key:"drawSilhouetteHighlighted",value:function(e){(this._emphasisFillRenderer||(this._emphasisFillRenderer=Oi.get(this)))&&this._emphasisFillRenderer.drawMesh(e,this,1)}},{key:"drawSilhouetteSelected",value:function(e){(this._emphasisFillRenderer||(this._emphasisFillRenderer=Oi.get(this)))&&this._emphasisFillRenderer.drawMesh(e,this,2)}},{key:"drawEdgesColorOpaque",value:function(e){(this._emphasisEdgesRenderer||(this._emphasisEdgesRenderer=Mi.get(this)))&&this._emphasisEdgesRenderer.drawMesh(e,this,3)}},{key:"drawEdgesColorTransparent",value:function(e){(this._emphasisEdgesRenderer||(this._emphasisEdgesRenderer=Mi.get(this)))&&this._emphasisEdgesRenderer.drawMesh(e,this,3)}},{key:"drawEdgesXRayed",value:function(e){(this._emphasisEdgesRenderer||(this._emphasisEdgesRenderer=Mi.get(this)))&&this._emphasisEdgesRenderer.drawMesh(e,this,0)}},{key:"drawEdgesHighlighted",value:function(e){(this._emphasisEdgesRenderer||(this._emphasisEdgesRenderer=Mi.get(this)))&&this._emphasisEdgesRenderer.drawMesh(e,this,1)}},{key:"drawEdgesSelected",value:function(e){(this._emphasisEdgesRenderer||(this._emphasisEdgesRenderer=Mi.get(this)))&&this._emphasisEdgesRenderer.drawMesh(e,this,2)}},{key:"drawOcclusion",value:function(e){(this._state.occluder&&this._occlusionRenderer||(this._occlusionRenderer=Yi.get(this)))&&this._occlusionRenderer.drawMesh(e,this)}},{key:"drawShadow",value:function(e){(this._shadowRenderer||(this._shadowRenderer=Ji.get(this)))&&this._shadowRenderer.drawMesh(e,this)}},{key:"drawPickMesh",value:function(e){(this._pickMeshRenderer||(this._pickMeshRenderer=Gi.get(this)))&&this._pickMeshRenderer.drawMesh(e,this)}},{key:"canPickTriangle",value:function(){return this._geometry.isReadableGeometry}},{key:"drawPickTriangles",value:function(e){(this._pickTriangleRenderer||(this._pickTriangleRenderer=Qi.get(this)))&&this._pickTriangleRenderer.drawMesh(e,this)}},{key:"pickTriangleSurface",value:function(e,t,n){fa(this,e,t,n)}},{key:"drawPickVertices",value:function(e){}},{key:"delegatePickedEntity",value:function(){return this}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._putDrawRenderers(),this._putPickRenderers(),this._putOcclusionRenderer(),this.scene._renderer.putPickID(this._state.pickID),this._isObject&&(this.scene._deregisterObject(this),this._visible&&this.scene._objectVisibilityUpdated(this,!1,!1),this._xrayed&&this.scene._objectXRayedUpdated(this,!1,!1),this._selected&&this.scene._objectSelectedUpdated(this,!1,!1),this._highlighted&&this.scene._objectHighlightedUpdated(this,!1,!1),this.scene._objectColorizeUpdated(this,!1),this.scene._objectOpacityUpdated(this,!1),this.offset.some((function(e){return 0!==e}))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}]),n}(),fa=function(){var e=Z.vec3(),t=Z.vec3(),n=Z.vec3(),r=Z.vec3(),i=Z.vec3(),a=Z.vec3(),s=Z.vec4(),o=Z.vec3(),l=Z.vec3(),u=Z.vec3(),c=Z.vec3(),f=Z.vec3(),p=Z.vec3(),A=Z.vec3(),d=Z.vec3(),v=Z.vec3(),h=Z.vec4(),I=Z.vec4(),y=Z.vec4(),m=Z.vec3(),w=Z.vec3(),g=Z.vec3(),T=Z.vec3(),E=Z.vec3(),b=Z.vec3(),D=Z.vec3(),P=Z.vec3(),R=Z.vec3(),C=Z.vec3(),_=Z.vec3();return function(B,O,S,N){var L=N.primIndex;if(null!=L&&L>-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;s<a;s++)for(o=0;o<=i;o++)A=(p=s*(i+1)+o)+i,B.push(p),B.push(A),B.push(A+1),B.push(p),B.push(A+1),B.push(p+1);if(!I&&t>0){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;o<i;o++)y=d,p=d+1+o,B.push(p),B.push(p+1),B.push(y)}if(!I&&n>0){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;o<i;o++)y=d,p=d+1+o,B.push(y),B.push(p+1),B.push(p)}return ae.apply(e,{positions:R,normals:C,uv:_,indices:B})}function Aa(){var e=arguments.length>0&&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<s;l++)for(u=0;u<o;u++)g=(w=l*(o+1)+u)+o+1,D.push(w+1),D.push(g+1),D.push(g),D.push(w+1),D.push(g),D.push(w);return ae.apply(e,{positions:T,normals:E,uv:b,indices:D})}var da={" ":{width:16,points:[]},"!":{width:10,points:[[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},'"':{width:16,points:[[4,21],[4,14],[-1,-1],[12,21],[12,14]]},"#":{width:21,points:[[11,25],[4,-7],[-1,-1],[17,25],[10,-7],[-1,-1],[4,12],[18,12],[-1,-1],[3,6],[17,6]]},$:{width:20,points:[[8,25],[8,-4],[-1,-1],[12,25],[12,-4],[-1,-1],[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},"%":{width:24,points:[[21,21],[3,0],[-1,-1],[8,21],[10,19],[10,17],[9,15],[7,14],[5,14],[3,16],[3,18],[4,20],[6,21],[8,21],[10,20],[13,19],[16,19],[19,20],[21,21],[-1,-1],[17,7],[15,6],[14,4],[14,2],[16,0],[18,0],[20,1],[21,3],[21,5],[19,7],[17,7]]},"&":{width:26,points:[[23,12],[23,13],[22,14],[21,14],[20,13],[19,11],[17,6],[15,3],[13,1],[11,0],[7,0],[5,1],[4,2],[3,4],[3,6],[4,8],[5,9],[12,13],[13,14],[14,16],[14,18],[13,20],[11,21],[9,20],[8,18],[8,16],[9,13],[11,10],[16,3],[18,1],[20,0],[22,0],[23,1],[23,2]]},"'":{width:10,points:[[5,19],[4,20],[5,21],[6,20],[6,18],[5,16],[4,15]]},"(":{width:14,points:[[11,25],[9,23],[7,20],[5,16],[4,11],[4,7],[5,2],[7,-2],[9,-5],[11,-7]]},")":{width:14,points:[[3,25],[5,23],[7,20],[9,16],[10,11],[10,7],[9,2],[7,-2],[5,-5],[3,-7]]},"*":{width:16,points:[[8,21],[8,9],[-1,-1],[3,18],[13,12],[-1,-1],[13,18],[3,12]]},"+":{width:26,points:[[13,18],[13,0],[-1,-1],[4,9],[22,9]]},",":{width:10,points:[[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"-":{width:26,points:[[4,9],[22,9]]},".":{width:10,points:[[5,2],[4,1],[5,0],[6,1],[5,2]]},"/":{width:22,points:[[20,25],[2,-7]]},0:{width:20,points:[[9,21],[6,20],[4,17],[3,12],[3,9],[4,4],[6,1],[9,0],[11,0],[14,1],[16,4],[17,9],[17,12],[16,17],[14,20],[11,21],[9,21]]},1:{width:20,points:[[6,17],[8,18],[11,21],[11,0]]},2:{width:20,points:[[4,16],[4,17],[5,19],[6,20],[8,21],[12,21],[14,20],[15,19],[16,17],[16,15],[15,13],[13,10],[3,0],[17,0]]},3:{width:20,points:[[5,21],[16,21],[10,13],[13,13],[15,12],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},4:{width:20,points:[[13,21],[3,7],[18,7],[-1,-1],[13,21],[13,0]]},5:{width:20,points:[[15,21],[5,21],[4,12],[5,13],[8,14],[11,14],[14,13],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},6:{width:20,points:[[16,18],[15,20],[12,21],[10,21],[7,20],[5,17],[4,12],[4,7],[5,3],[7,1],[10,0],[11,0],[14,1],[16,3],[17,6],[17,7],[16,10],[14,12],[11,13],[10,13],[7,12],[5,10],[4,7]]},7:{width:20,points:[[17,21],[7,0],[-1,-1],[3,21],[17,21]]},8:{width:20,points:[[8,21],[5,20],[4,18],[4,16],[5,14],[7,13],[11,12],[14,11],[16,9],[17,7],[17,4],[16,2],[15,1],[12,0],[8,0],[5,1],[4,2],[3,4],[3,7],[4,9],[6,11],[9,12],[13,13],[15,14],[16,16],[16,18],[15,20],[12,21],[8,21]]},9:{width:20,points:[[16,14],[15,11],[13,9],[10,8],[9,8],[6,9],[4,11],[3,14],[3,15],[4,18],[6,20],[9,21],[10,21],[13,20],[15,18],[16,14],[16,9],[15,4],[13,1],[10,0],[8,0],[5,1],[4,3]]},":":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},";":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"<":{width:24,points:[[20,18],[4,9],[20,0]]},"=":{width:26,points:[[4,12],[22,12],[-1,-1],[4,6],[22,6]]},">":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function 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;T<y.length;T++){u=0,f=(c=y[T]).length;for(var E=0;E<f;E++)if(p=da[c.charAt(E)]){A=1,d=-1,v=-1,h=p.points.length;for(var b=0;b<h;b++)-1!==(I=p.points[b])[0]||-1!==I[1]?(s.push(u+I[0]*a*g+n),s.push(w+I[1]*a*g+r),s.push(0+i),-1===d?d=m:(-1===v||(d=v),v=m),m++,A?A=!1:(o.push(d),o.push(v))):A=1;u+=p.width*g*a}w-=35*g*a}return ae.apply(e,{primitive:"lines",positions:s,indices:o})}var ha=function(e){I(n,z);var t=m(n);function n(e,r){var i;b(this,n),r=r||{},i=t.call(this,"AxisGizmo",e,r);var a=e.scene.camera;r.canvasId||r.canvasElement||i.error("Config expected: either 'canvasId' or 'canvasElement'");try{i._axisGizmoScene=new ar(e,{canvasId:r.canvasId,canvasElement:r.canvasElement,transparent:!0})}catch(e){return i.error(e),w(i)}var s=i._axisGizmoScene;s.clearLights(),new nn(s,{color:[.45,.45,.5],intensity:.9}),new tn(s,{dir:[-.5,.5,-.6],color:[.8,.8,.7],intensity:1,space:"view"}),new tn(s,{dir:[.5,-.5,-.6],color:[.8,.8,.8],intensity:1,space:"view"});var o=s.camera;a.on("matrix",(function(){var e=a.eye,t=a.look,n=a.up,r=Z.mulVec3Scalar(Z.normalizeVec3(Z.subVec3(e,t,[])),22);o.look=[0,0,0],o.eye=r,o.up=n}));var l=new vn(s,pa({radiusTop:.01,radiusBottom:.6,height:1.7,radialSegments:20,heightSegments:1,openEnded:!1})),u=new vn(s,pa({radiusTop:.2,radiusBottom:.2,height:4.5,radialSegments:20,heightSegments:1,openEnded:!1})),c=new wn(s,{diffuse:[1,.3,.3],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),f=new wn(s,{emissive:[1,.3,.3],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),p=new wn(s,{diffuse:[.3,1,.3],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),A=new wn(s,{emissive:[.3,1,.3],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),d=new wn(s,{diffuse:[.3,.3,1],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),v=new wn(s,{emissive:[.3,.3,1],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2}),h=new wn(s,{diffuse:[.5,.5,.5],ambient:[0,0,0],specular:[.6,.6,.3],shininess:80,lineWidth:2});return i._meshes=[new ca(s,{geometry:new vn(s,Aa({radius:9,heightSegments:60,widthSegments:60})),material:new wn(s,{diffuse:[0,0,0],emissive:[.1,.1,.1],ambient:[.1,.1,.2],specular:[0,0,0],alpha:.4,alphaMode:"blend",frontface:"cw"}),pickable:!1,collidable:!1,visible:!1!==r.visible}),new ca(s,{geometry:new vn(s,Aa({radius:1})),material:h,pickable:!1,collidable:!1,visible:!1!==r.visible}),new ca(s,{geometry:l,material:c,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[5,0,0],rotation:[0,0,-90]}),new ca(s,{geometry:u,material:c,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[2,0,0],rotation:[0,0,90]}),new ca(s,{geometry:new vn(s,va({text:"X",size:1.5})),material:f,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[7,0,0],billboard:"spherical"}),new ca(s,{geometry:l,material:p,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[0,5,0]}),new ca(s,{geometry:u,material:p,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[0,2,0]}),new ca(s,{geometry:new vn(s,va({text:"Y",size:1.5})),material:A,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[0,7,0],billboard:"spherical"}),new ca(s,{geometry:l,material:d,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[0,0,5],rotation:[90,0,0]}),new ca(s,{geometry:u,material:d,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[0,0,2],rotation:[90,0,0]}),new ca(s,{geometry:new vn(s,va({text:"Z",size:1.5})),material:v,pickable:!1,collidable:!1,visible:!1!==r.visible,position:[0,0,7],billboard:"spherical"})],i}return P(n,[{key:"setVisible",value:function(e){for(var t=0;t<this._meshes.length;t++)this._meshes[t].visible=e}},{key:"destroy",value:function(){this._axisGizmoCanvas=null,this._axisGizmoScene.destroy(),this._axisGizmoScene=null,v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Ia=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({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;s<o;s++)r.addChild(a[s],i.inheritStates);if(i.parentId){var l=r.scene.components[i.parentId];l?l.isNode?l.addChild(g(r)):r.error("Parent is not a Node: '"+i.parentId+"'"):r.error("Parent not found: '"+i.parentId+"'")}else i.parent&&(i.parent.isNode||r.error("Parent is not a Node"),i.parent.addChild(g(r)));return r}return P(n,[{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._origin},set:function(e){e?(this._origin||(this._origin=Z.vec3()),this._origin.set(e)):this._origin&&(this._origin=null);for(var t=0,n=this._children.length;t<n;t++)this._children[t].origin=e;this.glRedraw()}},{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._visible},set:function(e){e=!1!==e,this._visible=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].visible=e;this._isObject&&this.scene._objectVisibilityUpdated(this,e)}},{key:"xrayed",get:function(){return this._xrayed},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].xrayed=e;this._isObject&&this.scene._objectXRayedUpdated(this,e)}},{key:"highlighted",get:function(){return this._highlighted},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].highlighted=e;this._isObject&&this.scene._objectHighlightedUpdated(this,e)}},{key:"selected",get:function(){return this._selected},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].selected=e;this._isObject&&this.scene._objectSelectedUpdated(this,e)}},{key:"edges",get:function(){return this._edges},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].edges=e}},{key:"culled",get:function(){return this._culled},set:function(e){e=!!e,this._culled=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].culled=e}},{key:"clippable",get:function(){return this._clippable},set:function(e){e=!1!==e,this._clippable=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].clippable=e}},{key:"collidable",get:function(){return this._collidable},set:function(e){e=!1!==e,this._collidable=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].collidable=e}},{key:"pickable",get:function(){return this._pickable},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].pickable=e}},{key:"colorize",get:function(){return this._colorize.slice(0,3)},set:function(e){var t=this._colorize;t||((t=this._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);for(var n=0,r=this._children.length;n<r;n++)this._children[n].colorize=t;if(this._isObject){var i=!!e;this.scene._objectColorizeUpdated(this,i)}}},{key:"opacity",get:function(){return this._colorize[3]},set:function(e){var t=this._colorize;t||((t=this._colorize=new Float32Array(4))[0]=1,t[1]=1,t[2]=1),t[3]=null!=e?e:1;for(var n=0,r=this._children.length;n<r;n++)this._children[n].opacity=e;if(this._isObject){var i=null!=e;this.scene._objectOpacityUpdated(this,i)}}},{key:"castsShadow",get:function(){return this._castsShadow},set:function(e){e=!!e,this._castsShadow=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].castsShadow=e}},{key:"receivesShadow",get:function(){return this._receivesShadow},set:function(e){e=!!e,this._receivesShadow=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].receivesShadow=e}},{key:"saoEnabled",get:function(){return!1}},{key:"offset",get:function(){return this._offset},set:function(e){e?(this._offset[0]=e[0],this._offset[1]=e[1],this._offset[2]=e[2]):(this._offset[0]=0,this._offset[1]=0,this._offset[2]=0);for(var t=0,n=this._children.length;t<n;t++)this._children[t].offset=this._offset;this._isObject&&this.scene._objectOffsetUpdated(this,e)}},{key:"isNode",get:function(){return!0}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}},{key:"_setWorldMatrixDirty",value:function(){this._worldMatrixDirty=!0;for(var e=0,t=this._children.length;e<t;e++)this._children[e]._setWorldMatrixDirty()}},{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;t<n;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}},{key:"_setSubtreeAABBsDirty",value:function(e){if(e._aabbDirty=!0,e._children)for(var t=0,n=e._children.length;t<n;t++)this._setSubtreeAABBsDirty(e._children[t])}},{key:"_setAABBDirty",value:function(){if(this._setSubtreeAABBsDirty(this),this.collidable)for(var e=this;e;e=e._parentNode)e._aabbDirty=!0}},{key:"_updateAABB",value:function(){if(this.scene._aabbDirty=!0,this._aabb||(this._aabb=Z.AABB3()),this._buildAABB)this._buildAABB(this.worldMatrix,this._aabb);else{var e;Z.collapseAABB3(this._aabb);for(var t=0,n=this._children.length;t<n;t++)(e=this._children[t]).collidable&&Z.expandAABB3(this._aabb,e.aabb)}this._aabbDirty=!1}},{key:"addChild",value:function(e,t){if(ae.isNumeric(e)||ae.isString(e)){var n=e;if(!(e=this.scene.component[n]))return void this.warn("Component not found: "+ae.inQuotes(n));if(!e.isNode&&!e.isMesh)return void this.error("Not a Node or Mesh: "+n)}else{if(!e.isNode&&!e.isMesh)return void this.error("Not a Node or Mesh: "+e.id);if(e._parentNode){if(e._parentNode.id===this.id)return void this.warn("Already a child: "+e.id);e._parentNode.removeChild(e)}}if(e.id,e.scene.id===this.scene.id)return this._children.push(e),e._parentNode=this,t&&(e.visible=this.visible,e.culled=this.culled,e.xrayed=this.xrayed,e.highlited=this.highlighted,e.selected=this.selected,e.edges=this.edges,e.clippable=this.clippable,e.pickable=this.pickable,e.collidable=this.collidable,e.castsShadow=this.castsShadow,e.receivesShadow=this.receivesShadow,e.colorize=this.colorize,e.opacity=this.opacity,e.offset=this.offset),e._setWorldMatrixDirty(),e._setAABBDirty(),this._numTriangles+=e.numTriangles,e;this.error("Child not in same Scene: "+e.id)}},{key:"removeChild",value:function(e){for(var t=0,n=this._children.length;t<n;t++)if(this._children[t].id===e.id)return e._parentNode=null,this._children=this._children.splice(t,1),e._setWorldMatrixDirty(),e._setAABBDirty(),this._setAABBDirty(),void(this._numTriangles-=e.numTriangles)}},{key:"removeChildren",value:function(){for(var e,t=0,n=this._children.length;t<n;t++)(e=this._children[t])._parentNode=null,e._setWorldMatrixDirty(),e._setAABBDirty(),this._numTriangles-=e.numTriangles;this._children=[],this._setAABBDirty()}},{key:"numChildren",get:function(){return this._children.length}},{key:"children",get:function(){return this._children}},{key:"parent",get:function(){return this._parentNode},set:function(e){if(ae.isNumeric(e)||ae.isString(e)){var t=e;if(!(e=this.scene.components[t]))return void this.warn("Node not found: "+ae.inQuotes(t));if(!e.isNode)return void this.error("Not a Node: "+e.id)}e.scene.id===this.scene.id?this._parentNode&&this._parentNode.id===e.id?this.warn("Already a child of Node: "+e.id):e.addChild(this):this.error("Node not in same Scene: "+e.id)}},{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||Pa),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:"rotate",value:function(e,t){return ya[0]=e[0],ya[1]=e[1],ya[2]=e[2],ya[3]=t*Z.DEGTORAD,Z.angleAxisToQuaternion(ya,ma),Z.mulQuaternions(this.quaternion,ma,wa),this.quaternion=wa,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return ya[0]=e[0],ya[1]=e[1],ya[2]=e[2],ya[3]=t*Z.DEGTORAD,Z.angleAxisToQuaternion(ya,ma),Z.mulQuaternions(ma,this.quaternion,ma),this}},{key:"rotateX",value:function(e){return this.rotate(ga,e)}},{key:"rotateY",value:function(e){return this.rotate(Ta,e)}},{key:"rotateZ",value:function(e){return this.rotate(Ea,e)}},{key:"translate",value:function(e,t){return Z.vec3ApplyQuaternion(this.quaternion,e,ba),Z.mulVec3Scalar(ba,t,Da),Z.addVec3(this.position,Da,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"translateX",value:function(e){return this.translate(ga,e)}},{key:"translateY",value:function(e){return this.translate(Ta,e)}},{key:"translateZ",value:function(e){return this.translate(Ea,e)}},{key:"type",get:function(){return"Node"}},{key:"destroy",value:function(){if(v(T(n.prototype),"destroy",this).call(this),this._parentNode&&this._parentNode.removeChild(this),this._isObject&&(this.scene._deregisterObject(this),this._visible&&this.scene._objectVisibilityUpdated(this,!1,!1),this._xrayed&&this.scene._objectXRayedUpdated(this,!1,!1),this._selected&&this.scene._objectSelectedUpdated(this,!1,!1),this._highlighted&&this.scene._objectHighlightedUpdated(this,!1,!1),this.scene._objectColorizeUpdated(this,!1),this.scene._objectOpacityUpdated(this,!1),this.offset.some((function(e){return 0!==e}))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length)for(var e=this._children.splice(),t=0,r=e.length;t<r;t++)e[t].destroy();this._children=[],this._setAABBDirty(),this.scene._aabbDirty=!0}}]),n}(),Ca=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:"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;r<i;r++)t.texImage2D(n[r],0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,Ma);else t.texImage2D(this.target,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,Ma);t.bindTexture(this.target,null)}},{key:"setTarget",value:function(e){this.target=e||this.gl.TEXTURE_2D}},{key:"setImage",value:function(e){var t=arguments.length>1&&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;I<y;I++)n.texImage2D(h[I],0,d,p,A,v[I])}else n.texImage2D(n.TEXTURE_2D,0,d,p,A,e);r&&n.generateMipmap(this.target),n.bindTexture(this.target,null),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,i),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a),n.pixelStorei(n.UNPACK_ALIGNMENT,s),n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,o)}},{key:"setCompressedData",value:function(e){var t=e.mipmaps,n=e.props,r=void 0===n?{}:n,i=this.gl,a=t.length;void 0!==r.format&&(this.format=r.format),void 0!==r.internalFormat&&(this.internalFormat=r.internalFormat),void 0!==r.encoding&&(this.encoding=r.encoding),void 0!==r.type&&(this.type=r.type),void 0!==r.flipY&&(this.flipY=r.flipY),void 0!==r.premultiplyAlpha&&(this.premultiplyAlpha=r.premultiplyAlpha),void 0!==r.unpackAlignment&&(this.unpackAlignment=r.unpackAlignment),void 0!==r.minFilter&&(this.minFilter=r.minFilter),void 0!==r.magFilter&&(this.magFilter=r.magFilter),void 0!==r.wrapS&&(this.wrapS=r.wrapS),void 0!==r.wrapT&&(this.wrapT=r.wrapT),void 0!==r.wrapR&&(this.wrapR=r.wrapR),i.activeTexture(i.TEXTURE0+0),i.bindTexture(this.target,this.texture);var s=t.length>1;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;A<d;A++){var v=t[A];1023!==this.format?null!==c?i.compressedTexSubImage2D(i.TEXTURE_2D,A,0,0,v.width,v.height,c,v.data):console.warn("Attempt to load unsupported compressed texture format in .setCompressedData()"):i.texSubImage2D(i.TEXTURE_2D,A,0,0,v.width,v.height,c,f,v.data)}i.bindTexture(this.target,null)}},{key:"setProps",value:function(e){var t=this.gl;t.bindTexture(this.target,this.texture),this._uploadProps(e),t.bindTexture(this.target,null)}},{key:"_uploadProps",value:function(e){var t=this.gl;if(void 0!==e.format&&(this.format=e.format),void 0!==e.internalFormat&&(this.internalFormat=e.internalFormat),void 0!==e.encoding&&(this.encoding=e.encoding),void 0!==e.type&&(this.type=e.type),void 0!==e.minFilter){var n=xa(t,e.minFilter);n&&(this.minFilter=e.minFilter,t.texParameteri(this.target,t.TEXTURE_MIN_FILTER,n),n!==t.NEAREST_MIPMAP_NEAREST&&n!==t.LINEAR_MIPMAP_NEAREST&&n!==t.NEAREST_MIPMAP_LINEAR&&n!==t.LINEAR_MIPMAP_LINEAR||t.generateMipmap(this.target))}if(void 0!==e.magFilter){var r=xa(t,e.magFilter);r&&(this.magFilter=e.magFilter,t.texParameteri(this.target,t.TEXTURE_MAG_FILTER,r))}if(void 0!==e.wrapS){var i=xa(t,e.wrapS);i&&(this.wrapS=e.wrapS,t.texParameteri(this.target,t.TEXTURE_WRAP_S,i))}if(void 0!==e.wrapT){var a=xa(t,e.wrapT);a&&(this.wrapT=e.wrapT,t.texParameteri(this.target,t.TEXTURE_WRAP_T,a))}}},{key:"bind",value:function(e){if(this.allocated){if(this.texture){var t=this.gl;return t.activeTexture(t["TEXTURE"+e]),t.bindTexture(this.target,this.texture),!0}return!1}}},{key:"unbind",value:function(e){if(this.allocated&&this.texture){var t=this.gl;t.activeTexture(t["TEXTURE"+e]),t.bindTexture(this.target,null)}}},{key:"destroy",value:function(){this.allocated&&this.texture&&(this.gl.deleteTexture(this.texture),this.texture=null)}}]),e}();function Ha(e,t,n,r,i){var a=arguments.length>5&&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;c<a.i_verts.length;c++)u[c]=c;i.processes--,n(ae.apply(t,{primitive:"triangles",positions:s,normals:o.length>0?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;a<g;a++){var _=a*E-I;for(s=0;s<w;s++)o=s*T-h,b[R]=o+A,b[R+1]=d,b[R+2]=-_+v,D[R+2]=-1,P[C]=s/y,P[C+1]=(m-a)/m,R+=3,C+=2}R=0;var B=new(b.length/3>65535?Uint32Array:Uint16Array)(y*m*6);for(a=0;a<m;a++)for(s=0;s<y;s++)l=s+w*a,u=s+w*(a+1),c=s+1+w*(a+1),f=s+1+w*a,B[R]=f,B[R+1]=u,B[R+2]=l,B[R+3]=f,B[R+4]=c,B[R+5]=u,R+=6;return ae.apply(e,{positions:b,normals:D,uv:P,indices:B})}function es(){var e=arguments.length>0&&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;r<t.length;r++)n=n.concat(String.fromCharCode(t[r]));return n},Ya.parse._strToBuff=function(e){for(var t=new ArrayBuffer(e.length),n=new Uint8Array(t),r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return t},Ya.parse._readLine=function(e,t){for(var n="";10!=e[t];)n+=String.fromCharCode(e[t++]);return n},Ya.parse.fromJSON=function(e){return JSON.parse(Ya.parse._buffToStr(e))},Ya.parse.toJSON=function(e){var t=JSON.stringify(e);return Ya.parse._strToBuff(t)},Ya.parse.fromOBJ=function(e){for(var t={groups:{},c_verts:[],c_uvt:[],c_norms:[],i_verts:[],i_uvt:[],i_norms:[]},n={from:0,to:0},r=0,i=new Uint8Array(e);r<i.length;){var a=Ya.parse._readLine(i,r);r+=a.length+1;var s=(a=(a=a.replace(/ +(?= )/g,"")).replace(/(^\s+|\s+$)/g,"")).split(" ");if("g"==s[0]&&(n.to=t.i_verts.length,null==t.groups[s[1]]&&(t.groups[s[1]]={from:t.i_verts.length,to:0}),n=t.groups[s[1]]),"v"==s[0]){var o=parseFloat(s[1]),l=parseFloat(s[2]),u=parseFloat(s[3]);t.c_verts.push(o,l,u)}if("vt"==s[0]){o=parseFloat(s[1]),l=1-parseFloat(s[2]);t.c_uvt.push(o,l)}if("vn"==s[0]){o=parseFloat(s[1]),l=parseFloat(s[2]),u=parseFloat(s[3]);t.c_norms.push(o,l,u)}if("f"==s[0]){var c=s[1].split("/"),f=s[2].split("/"),p=s[3].split("/"),A=parseInt(c[0])-1,d=parseInt(f[0])-1,v=parseInt(p[0])-1,h=parseInt(c[1])-1,I=parseInt(f[1])-1,y=parseInt(p[1])-1,m=parseInt(c[2])-1,w=parseInt(f[2])-1,g=parseInt(p[2])-1,T=t.c_verts.length/3,E=t.c_uvt.length/2,b=t.c_norms.length/3;if(A<0&&(A=T+A+1),d<0&&(d=T+d+1),v<0&&(v=T+v+1),h<0&&(h=E+h+1),I<0&&(I=E+I+1),y<0&&(y=E+y+1),m<0&&(m=b+m+1),w<0&&(w=b+w+1),g<0&&(g=b+g+1),t.i_verts.push(A,d,v),t.i_uvt.push(h,I,y),t.i_norms.push(m,w,g),5==s.length){var D=s[4].split("/"),P=parseInt(D[0])-1,R=parseInt(D[1])-1,C=parseInt(D[2])-1;P<0&&(P=T+P+1),R<0&&(R=E+R+1),C<0&&(C=b+C+1),t.i_verts.push(A,v,P),t.i_uvt.push(h,y,R),t.i_norms.push(m,g,C)}}}return n.to=t.i_verts.length,t},Ya.parse.fromMD2=function(e){e=new Uint8Array(e);var t={},n={};n.ident=Ya.bin.ril(e,0),n.version=Ya.bin.ril(e,4),n.skinwidth=Ya.bin.ril(e,8),n.skinheight=Ya.bin.ril(e,12),n.framesize=Ya.bin.ril(e,16),n.num_skins=Ya.bin.ril(e,20),n.num_vertices=Ya.bin.ril(e,24),n.num_st=Ya.bin.ril(e,28),n.num_tris=Ya.bin.ril(e,32),n.num_glcmds=Ya.bin.ril(e,36),n.num_frames=Ya.bin.ril(e,40),n.offset_skins=Ya.bin.ril(e,44),n.offset_st=Ya.bin.ril(e,48),n.offset_tris=Ya.bin.ril(e,52),n.offset_frames=Ya.bin.ril(e,56),n.offset_glcmds=Ya.bin.ril(e,60),n.offset_end=Ya.bin.ril(e,64);var r=n.offset_st;t.c_uvt=[];for(var i=0;i<n.num_st;i++){var a=Ya.bin.rsl(e,r)/n.skinwidth,s=Ya.bin.rsl(e,r+2)/n.skinheight;t.c_uvt.push(a,s),r+=4}r=n.offset_tris;var o=[],l=[];t.i_verts=o,t.i_uvt=l;for(i=0;i<n.num_tris;i++)o.push(Ya.bin.rsl(e,r),Ya.bin.rsl(e,r+2),Ya.bin.rsl(e,r+4)),l.push(Ya.bin.rsl(e,r+6),Ya.bin.rsl(e,r+8),Ya.bin.rsl(e,r+10)),r+=12;r=n.offset_skins;t.skins=[];for(i=0;i<n.num_skins;i++)t.skins.push(Ya.bin.rASCII0(e,r)),r+=64;r=n.offset_frames;t.frames=[];var u=Ya.parse.fromMD2._normals;for(i=0;i<n.num_frames;i++){var c={},f=Ya.bin.rf(e,r),p=Ya.bin.rf(e,r+4),A=Ya.bin.rf(e,r+8);r+=12;var d=Ya.bin.rf(e,r),v=Ya.bin.rf(e,r+4),h=Ya.bin.rf(e,r+8);r+=12,c.name=Ya.bin.rASCII0(e,r),r+=16,c.verts=[],c.norms=[];for(var I=0;I<n.num_vertices;I++)c.verts.push(e[r]*f+d,e[r+1]*p+v,e[r+2]*A+h),c.norms.push(u[3*e[r+3]],u[3*e[r+3]+1],u[3*e[r+3]+2]),r+=4;t.frames.push(c)}return t},Ya.parse.fromMD2._normals=[-.525731,0,.850651,-.442863,.238856,.864188,-.295242,0,.955423,-.309017,.5,.809017,-.16246,.262866,.951056,0,0,1,0,.850651,.525731,-.147621,.716567,.681718,.147621,.716567,.681718,0,.525731,.850651,.309017,.5,.809017,.525731,0,.850651,.295242,0,.955423,.442863,.238856,.864188,.16246,.262866,.951056,-.681718,.147621,.716567,-.809017,.309017,.5,-.587785,.425325,.688191,-.850651,.525731,0,-.864188,.442863,.238856,-.716567,.681718,.147621,-.688191,.587785,.425325,-.5,.809017,.309017,-.238856,.864188,.442863,-.425325,.688191,.587785,-.716567,.681718,-.147621,-.5,.809017,-.309017,-.525731,.850651,0,0,.850651,-.525731,-.238856,.864188,-.442863,0,.955423,-.295242,-.262866,.951056,-.16246,0,1,0,0,.955423,.295242,-.262866,.951056,.16246,.238856,.864188,.442863,.262866,.951056,.16246,.5,.809017,.309017,.238856,.864188,-.442863,.262866,.951056,-.16246,.5,.809017,-.309017,.850651,.525731,0,.716567,.681718,.147621,.716567,.681718,-.147621,.525731,.850651,0,.425325,.688191,.587785,.864188,.442863,.238856,.688191,.587785,.425325,.809017,.309017,.5,.681718,.147621,.716567,.587785,.425325,.688191,.955423,.295242,0,1,0,0,.951056,.16246,.262866,.850651,-.525731,0,.955423,-.295242,0,.864188,-.442863,.238856,.951056,-.16246,.262866,.809017,-.309017,.5,.681718,-.147621,.716567,.850651,0,.525731,.864188,.442863,-.238856,.809017,.309017,-.5,.951056,.16246,-.262866,.525731,0,-.850651,.681718,.147621,-.716567,.681718,-.147621,-.716567,.850651,0,-.525731,.809017,-.309017,-.5,.864188,-.442863,-.238856,.951056,-.16246,-.262866,.147621,.716567,-.681718,.309017,.5,-.809017,.425325,.688191,-.587785,.442863,.238856,-.864188,.587785,.425325,-.688191,.688191,.587785,-.425325,-.147621,.716567,-.681718,-.309017,.5,-.809017,0,.525731,-.850651,-.525731,0,-.850651,-.442863,.238856,-.864188,-.295242,0,-.955423,-.16246,.262866,-.951056,0,0,-1,.295242,0,-.955423,.16246,.262866,-.951056,-.442863,-.238856,-.864188,-.309017,-.5,-.809017,-.16246,-.262866,-.951056,0,-.850651,-.525731,-.147621,-.716567,-.681718,.147621,-.716567,-.681718,0,-.525731,-.850651,.309017,-.5,-.809017,.442863,-.238856,-.864188,.16246,-.262866,-.951056,.238856,-.864188,-.442863,.5,-.809017,-.309017,.425325,-.688191,-.587785,.716567,-.681718,-.147621,.688191,-.587785,-.425325,.587785,-.425325,-.688191,0,-.955423,-.295242,0,-1,0,.262866,-.951056,-.16246,0,-.850651,.525731,0,-.955423,.295242,.238856,-.864188,.442863,.262866,-.951056,.16246,.5,-.809017,.309017,.716567,-.681718,.147621,.525731,-.850651,0,-.238856,-.864188,-.442863,-.5,-.809017,-.309017,-.262866,-.951056,-.16246,-.850651,-.525731,0,-.716567,-.681718,-.147621,-.716567,-.681718,.147621,-.525731,-.850651,0,-.5,-.809017,.309017,-.238856,-.864188,.442863,-.262866,-.951056,.16246,-.864188,-.442863,.238856,-.809017,-.309017,.5,-.688191,-.587785,.425325,-.681718,-.147621,.716567,-.442863,-.238856,.864188,-.587785,-.425325,.688191,-.309017,-.5,.809017,-.147621,-.716567,.681718,-.425325,-.688191,.587785,-.16246,-.262866,.951056,.442863,-.238856,.864188,.16246,-.262866,.951056,.309017,-.5,.809017,.147621,-.716567,.681718,0,-.525731,.850651,.425325,-.688191,.587785,.587785,-.425325,.688191,.688191,-.587785,.425325,-.955423,.295242,0,-.951056,.16246,.262866,-1,0,0,-.850651,0,.525731,-.955423,-.295242,0,-.951056,-.16246,.262866,-.864188,.442863,-.238856,-.951056,.16246,-.262866,-.809017,.309017,-.5,-.864188,-.442863,-.238856,-.951056,-.16246,-.262866,-.809017,-.309017,-.5,-.681718,.147621,-.716567,-.681718,-.147621,-.716567,-.850651,0,-.525731,-.688191,.587785,-.425325,-.587785,.425325,-.688191,-.425325,.688191,-.587785,-.425325,-.688191,-.587785,-.587785,-.425325,-.688191,-.688191,-.587785,-.425325],Ya.parse.fromCollada=function(e){var t=Ya.parse._buffToStr(e),n=(new DOMParser).parseFromString(t,"text/xml"),r={},i=(n=n.childNodes[0]).getElementsByTagName("asset")[0],a=n.getElementsByTagName("library_geometries")[0],s=n.getElementsByTagName("library_images")[0],o=n.getElementsByTagName("library_materials")[0],l=n.getElementsByTagName("library_effects")[0];return i&&(r.asset=Ya.parse.fromCollada._asset(i)),a&&(r.geometries=Ya.parse.fromCollada._libGeometries(a)),s&&(r.images=Ya.parse.fromCollada._libImages(s)),o&&(r.materials=Ya.parse.fromCollada._libMaterials(o)),l&&(r.effects=Ya.parse.fromCollada._libEffects(l)),r},Ya.parse.fromCollada._asset=function(e){return{created:e.getElementsByTagName("created")[0].textContent,modified:e.getElementsByTagName("modified")[0].textContent,up_axis:e.getElementsByTagName("up_axis")[0].textContent}},Ya.parse.fromCollada._libGeometries=function(e){e=e.getElementsByTagName("geometry");for(var t=[],n=0;n<e.length;n++){var r=e[n],i=Ya.parse.fromCollada._getMesh(r.getElementsByTagName("mesh")[0]);t.push(i)}return t},Ya.parse.fromCollada._getMesh=function(e){for(var t={},n=e.getElementsByTagName("source"),r=t.sources={},i=0;i<n.length;i++){for(var a=n[i].getElementsByTagName("float_array")[0].textContent.split(" "),s=a.length-(""==a[a.length-1]?1:0),o=new Array(s),l=0;l<s;l++)o[l]=parseFloat(a[l]);r[n[i].getAttribute("id")]=o}t.triangles=[];var u=e.getElementsByTagName("triangles");if(null==u)return t;for(i=0;i<u.length;i++){var c={},f=u[i];c.material=f.getAttribute("material");var p=f.getElementsByTagName("input"),A=[];for(l=0;l<p.length;l++){var d=p[l];o=[];A[parseInt(d.getAttribute("offset"))]=o;var v=d.getAttribute("semantic");c["s_"+v]="VERTEX"==v?e.getElementsByTagName("vertices")[0].getElementsByTagName("input")[0].getAttribute("source").substring(1):d.getAttribute("source").substring(1),c["i_"+v]=o,r[c["s_"+v]]}var h=f.getElementsByTagName("p")[0].textContent.split(" "),I=3*Math.floor(h.length/3);for(l=0;l<I;l++)A[l%p.length].push(parseInt(h[l]));t.triangles.push(c)}return t},Ya.parse.fromCollada._libImages=function(e){e=e.getElementsByTagName("image");for(var t={},n=0;n<e.length;n++)t[e[n].getAttribute("id")]=e[n].getElementsByTagName("init_from")[0].textContent;return t},Ya.parse.fromCollada._libMaterials=function(e){e=e.getElementsByTagName("material");for(var t={},n=0;n<e.length;n++)t[e[n].getAttribute("name")]=e[n].getElementsByTagName("instance_effect")[0].getAttribute("url").substring(1);return t},Ya.parse.fromCollada._libEffects=function(e){e=e.getElementsByTagName("effect");for(var t={},n=0;n<e.length;n++){for(var r={},i=e[n].getElementsByTagName("newparam"),a=0;a<i.length;a++){var s=i[a].getElementsByTagName("surface")[0];s&&(r.surface=s.getElementsByTagName("init_from")[0].textContent)}t[e[n].getAttribute("id")]=r}return t},Ya.parse.from3DS=function(e){e=new Uint8Array(e);var t={};if(19789!=Ya.bin.rsl(e,0))return null;for(var n=Ya.bin.ril(e,2),r=6;r<n;){var i=Ya.bin.rsl(e,r),a=Ya.bin.ril(e,r+2);15677==i&&(t.edit=Ya.parse.from3DS._edit3ds(e,r,a)),45056==i&&(t.keyf=Ya.parse.from3DS._keyf3ds(e,r,a)),r+=a}return t},Ya.parse.from3DS._edit3ds=function(e,t,n){for(var r={},i=t+6;i<t+n;){var a=Ya.bin.rsl(e,i),s=Ya.bin.ril(e,i+2);16384==a&&(null==r.objects&&(r.objects=[]),r.objects.push(Ya.parse.from3DS._edit_object(e,i,s))),i+=s}return r},Ya.parse.from3DS._keyf3ds=function(e,t,n){for(var r={},i=t+6;i<t+n;){var a=Ya.bin.rsl(e,i),s=Ya.bin.ril(e,i+2);45058==a&&(null==r.desc&&(r.desc=[]),r.desc.push(Ya.parse.from3DS._keyf_objdes(e,i,s))),i+=s}return r},Ya.parse.from3DS._keyf_objdes=function(e,t,n){for(var r={},i=t+6;i<t+n;){var a=Ya.bin.rsl(e,i),s=Ya.bin.ril(e,i+2);45072==a&&(r.hierarchy=Ya.parse.from3DS._keyf_objhierarch(e,i,s)),45073==a&&(r.dummy_name=Ya.bin.rASCII0(e,i+6)),i+=s}return r},Ya.parse.from3DS._keyf_objhierarch=function(e,t,n){var r={},i=t+6;return r.name=Ya.bin.rASCII0(e,i),i+=r.name.length+1,r.hierarchy=Ya.bin.rsl(e,i+4),r},Ya.parse.from3DS._edit_object=function(e,t,n){var r={},i=t+6;for(r.name=Ya.bin.rASCII0(e,i),i+=r.name.length+1;i<t+n;){var a=Ya.bin.rsl(e,i),s=Ya.bin.ril(e,i+2);16640==a&&(r.mesh=Ya.parse.from3DS._obj_trimesh(e,i,s)),i+=s}return r},Ya.parse.from3DS._obj_trimesh=function(e,t,n){for(var r={},i=t+6;i<t+n;){var a=Ya.bin.rsl(e,i),s=Ya.bin.ril(e,i+2);16656==a&&(r.vertices=Ya.parse.from3DS._tri_vertexl(e,i,s)),16672==a&&(r.indices=Ya.parse.from3DS._tri_facel1(e,i,s)),16704==a&&(r.uvt=Ya.parse.from3DS._tri_mappingcoors(e,i,s)),16736==a&&(r.local=Ya.parse.from3DS._tri_local(e,i,s)),i+=s}return r},Ya.parse.from3DS._tri_vertexl=function(e,t,n){var r=[],i=t+6,a=Ya.bin.rsl(e,i);i+=2;for(var s=0;s<a;s++)r.push(Ya.bin.rf(e,i)),r.push(Ya.bin.rf(e,i+4)),r.push(Ya.bin.rf(e,i+8)),i+=12;return r},Ya.parse.from3DS._tri_facel1=function(e,t,n){var r=[],i=t+6,a=Ya.bin.rsl(e,i);i+=2;for(var s=0;s<a;s++)r.push(Ya.bin.rsl(e,i)),r.push(Ya.bin.rsl(e,i+2)),r.push(Ya.bin.rsl(e,i+4)),i+=8;return r},Ya.parse.from3DS._tri_mappingcoors=function(e,t,n){var r=[],i=t+6,a=Ya.bin.rsl(e,i);i+=2;for(var s=0;s<a;s++)r.push(Ya.bin.rf(e,i)),r.push(1-Ya.bin.rf(e,i+4)),i+=8;return r},Ya.parse.from3DS._tri_local=function(e,t,n){var r={},i=t+6;return r.X=[Ya.bin.rf(e,i),Ya.bin.rf(e,i+4),Ya.bin.rf(e,i+8)],i+=12,r.Y=[Ya.bin.rf(e,i),Ya.bin.rf(e,i+4),Ya.bin.rf(e,i+8)],i+=12,r.Z=[Ya.bin.rf(e,i),Ya.bin.rf(e,i+4),Ya.bin.rf(e,i+8)],i+=12,r.C=[Ya.bin.rf(e,i),Ya.bin.rf(e,i+4),Ya.bin.rf(e,i+8)],i+=12,r},Ya.parse.fromBIV=function(e){e=new Uint8Array(e);var t={},n={};return n.id=Ya.bin.ril(e,0),n.verS=Ya.bin.ril(e,4),n.texS=Ya.bin.ril(e,8),n.indS=Ya.bin.ril(e,12),n.verO=Ya.bin.ril(e,16),n.verL=Ya.bin.ril(e,20),n.texO=Ya.bin.ril(e,24),n.texL=Ya.bin.ril(e,28),n.indO=Ya.bin.ril(e,32),n.indL=Ya.bin.ril(e,36),0!=n.verO&&(t.vertices=Ya.parse.fromBIV._readFloats(e,n.verO,n.verL)),0!=n.texO&&(t.uvt=Ya.parse.fromBIV._readFloats(e,n.texO,n.texL)),0!=n.indO&&(t.indices=Ya.parse.fromBIV._readInts(e,n.indO,n.indL,n.indS)),t},Ya.parse.toBIV=function(e){for(var t=0,n=0;n<e.indices.length;n++)t=Math.max(t,e.indices[n]);var r=32;t<=65535&&(r=16);var i=40;e.vertices&&(i+=4*e.vertices.length),e.uvt&&(i+=4*e.uvt.length),e.indices&&(i+=e.indices.length*r/8);var a=new Uint8Array(i);Ya.bin.wil(a,0,1769365870),Ya.bin.wil(a,4,32),Ya.bin.wil(a,8,32),Ya.bin.wil(a,12,r);var s=40;return e.vertices&&(Ya.bin.wil(a,16,s),Ya.bin.wil(a,20,4*e.vertices.length),Ya.parse.fromBIV._writeFloats(a,s,e.vertices),s+=4*e.vertices.length),e.uvt&&(Ya.bin.wil(a,24,s),Ya.bin.wil(a,28,4*e.uvt.length),Ya.parse.fromBIV._writeFloats(a,s,e.uvt),s+=4*e.uvt.length),e.indices&&(Ya.bin.wil(a,32,s),Ya.bin.wil(a,36,4*e.indices.length),Ya.parse.fromBIV._writeInts(a,s,e.indices,r)),a.buffer},Ya.parse.fromBIV._readFloats=function(e,t,n){for(var r=[],i=0;i<n/4;i++)r.push(Ya.bin.rf(e,t+4*i));return r},Ya.parse.fromBIV._writeFloats=function(e,t,n){for(var r=0;r<n.length;r++)Ya.bin.wf(e,t+4*r,n[r])},Ya.parse.fromBIV._readInts=function(e,t,n,r){for(var i=[],a=0;a<n/4;a++)16==r&&i.push(Ya.bin.rsl(e,t+2*a)),32==r&&i.push(Ya.bin.ril(e,t+4*a));return i},Ya.parse.fromBIV._writeInts=function(e,t,n,r){for(var i=0;i<n.length;i++)16==r&&Ya.bin.wsl(e,t+2*i,n[i]),32==r&&Ya.bin.wil(e,t+4*i,n[i])},Ya.gen={},Ya.gen.Plane=function(e,t,n,r){n||(n=1),r||(r=1);for(var i={verts:[],inds:[],uvt:[]},a=e+1,s=t+1,o=0;o<s;o++)for(var l=0;l<a;l++){var u=l*(2/e)-1,c=o*(2/t)-1;i.verts.push(u,c,0),i.uvt.push(n*l/e,r*o/t),o<t&&l<e&&i.inds.push(o*a+l,o*a+l+1,(o+1)*a+l,o*a+l+1,(o+1)*a+l,(o+1)*a+l+1)}return i},Ya.gen.Cube=function(){return{verts:[-1,1,-1,1,1,-1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,1,-1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,1,-1,1,-1,1,1,-1,-1,-1,1,-1,1,1,-1,-1,1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,1,-1,1],inds:[0,1,2,1,2,3,4,5,6,5,6,7,8,9,10,9,10,11,12,13,14,13,14,15,16,17,18,17,18,19,20,21,22,21,22,23],uvt:[1/4,1/4,.5,1/4,1/4,.5,.5,.5,1,1/4,3/4,1/4,1,.5,3/4,.5,0,1/4,1/4,1/4,0,.5,1/4,.5,3/4,1/4,.5,1/4,3/4,.5,.5,.5,1/4,1/4,.5,1/4,1/4,0,.5,0,1/4,.5,.5,.5,1/4,3/4,.5,3/4]}},Ya.gen.Sphere=function(e,t){for(var n={verts:[],inds:[],uvt:[]},r=e+1,i=t+1,a=0;a<i;a++)for(var s=0;s<r;s++){var o=-Math.PI/2+a*Math.PI/t,l=2*s*Math.PI/e,u=Math.cos(o)*Math.cos(l),c=Math.sin(o),f=Math.cos(o)*Math.sin(l);n.verts.push(u,c,f),n.uvt.push(s/e,a/t),a<t&&s<e&&n.inds.push(r*a+s,r*a+s+1,r*(a+1)+s,r*a+s+1,r*(a+1)+s,r*(a+1)+s+1)}return n},Ya.mat={},Ya.mat.scale=function(e,t,n){return[e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1]},Ya.mat.translate=function(e,t,n){return[1,0,0,0,0,1,0,0,0,0,1,0,e,t,n,1]},Ya.mat.rotateDeg=function(e,t,n){var r=Math.PI/180;return Ya.mat.rotate(e*r,t*r,n*r)},Ya.mat.rotate=function(e,t,n){var r=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],i=e,a=t,s=n,o=Math.cos(i),l=Math.cos(a),u=Math.cos(s),c=Math.sin(i),f=Math.sin(a),p=Math.sin(s);return r[0]=l*u,r[1]=-l*p,r[2]=f,r[4]=o*p+c*f*u,r[5]=o*u-c*f*p,r[6]=-c*l,r[8]=c*p-o*f*u,r[9]=c*u+o*f*p,r[10]=o*l,r},Ya.edit={},Ya.edit.interpolate=function(e,t,n,r){for(var i=0;i<e.length;i++)n[i]=e[i]+r*(t[i]-e[i])},Ya.edit.transform=function(e,t){for(var n=0;n<e.length;n+=3){var r=e[n],i=e[n+1],a=e[n+2];e[n+0]=t[0]*r+t[4]*i+t[8]*a+t[12],e[n+1]=t[1]*r+t[5]*i+t[9]*a+t[13],e[n+2]=t[2]*r+t[6]*i+t[10]*a+t[14]}},Ya.edit.unwrap=function(e,t,n){for(var r=new Array(Math.floor(e.length/3)*n),i=0;i<e.length;i++)for(var a=0;a<n;a++)r[i*n+a]=t[e[i]*n+a];return r},Ya.edit.remap=function(e,t,n,r){for(var i=new Array(n.length),a=0;a<e.length;a++)for(var s=0;s<r;s++)i[t[a]*r+s]=n[e[a]*r+s];return i},Ya.utils={},Ya.utils.getAABB=function(e){var t,n,r,i,a,s;i=a=s=-(t=n=r=999999999);for(var o=0;o<e.length;o+=3){var l=e[o+0],u=e[o+1],c=e[o+2];l<t&&(t=l),l>i&&(i=l),u<n&&(n=u),u>a&&(a=u),c<r&&(r=c),u>s&&(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;a<s;a+=2)r._indices.push(a),r._indices.push(a+1)}return r._mesh=new ca(g(r),{visible:i.visible,clippable:i.clippable,collidable:i.collidable,geometry:new Ka(g(r),{primitive:"lines",positions:r._positions,indices:r._indices,origin:i.origin}),material:new wn(g(r),{diffuse:i.color||[0,0,0],emissive:i.color||[0,0,0]})}),r.scene._lineSetCreated(g(r)),r}return P(n,[{key:"visible",get:function(){return this._mesh.visible},set:function(e){this._mesh.visible=e}},{key:"positions",get:function(){return this._positions}},{key:"indices",get:function(){return this._indices}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._lineSetDestroyed(this)}}]),n}(),rs=Z.vec3(),is=Z.vec3(),as=Z.vec3(),ss=Z.vec3(),os=function(e){I(n,z);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,"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;T<E;T++){var b=g[2*T],D=g[2*T+1];s.lines.push({start_point:{x:w[3*b+0],y:w[3*b+1],z:w[3*b+2]},end_point:{x:w[3*D+0],y:w[3*D+1],z:w[3*D+2]}})}}var P=n.bitmaps;for(var R in P)if(P.hasOwnProperty(R)){var C=P[R],_=C.pos,B=C.normal,O=C.up;r.yUp&&(_=cs(_),B=cs(B),O=cs(O)),Z.addVec3(_,i),s.bitmaps||(s.bitmaps=[]),s.bitmaps.push({bitmap_type:C.type,bitmap_data:C.imageData,location:ls(_),normal:ls(B),up:ls(O),height:C.height})}s.components={visibility:{view_setup_hints:{spaces_visible:!!t.spacesVisible,space_boundaries_visible:!!t.spaceBoundariesVisible,openings_visible:!!t.openingsVisible}}};var S=new Set(n.opacityObjectIds),N=new Set(n.xrayedObjectIds),L=new Set(n.colorizedObjectIds),x=Object.values(n.objects).filter((function(e){return S.has(e.id)||L.has(e.id)||N.has(e.id)})).reduce((function(t,r){var i,a=ps(r.colorize);r.xrayed?(i=0===n.xrayMaterial.fillAlpha&&0!==n.xrayMaterial.edgeAlpha?.1:n.xrayMaterial.fillAlpha,a=(i=Math.round(255*i).toString(16).padStart(2,"0"))+a):S.has(r.id)&&(a=(i=Math.round(255*r.opacity).toString(16).padStart(2,"0"))+a),t[a]||(t[a]=[]);var s=r.id,o=r.originalSystemId,l={ifc_guid:o,originating_system:e.originatingSystem};return o!==s&&(l.authoring_tool_id=s),t[a].push(l),t}),{}),M=Object.entries(x).map((function(e){var t=p(e,2);return{color:t[0],components:t[1]}}));s.components.coloring=M;var F=n.objectIds,H=n.visibleObjects,U=n.visibleObjectIds,G=F.filter((function(e){return!H[e]})),k=n.selectedObjectIds;return t.defaultInvisible||U.length<G.length?(s.components.visibility.exceptions=this._createBCFComponents(U),s.components.visibility.default_visibility=!1):(s.components.visibility.exceptions=this._createBCFComponents(G),s.components.visibility.default_visibility=!0),s.components.selection=this._createBCFComponents(k),!1!==t.snapshot&&(s.snapshot={snapshot_type:"png",snapshot_data:this.viewer.getSnapshot({format:"png"})}),s}},{key:"_createBCFComponents",value:function(e){for(var t=this.viewer.scene,n=[],r=0,i=e.length;r<i;r++){var a=e[r],s=t.objects[a];if(s){var o={ifc_guid:s.originalSystemId,originating_system:this.originatingSystem};s.originalSystemId!==a&&(o.authoring_tool_id=a),n.push(o)}}return n}},{key:"setViewpoint",value:function(e){var t=this,n=arguments.length>1&&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;I<y;I+=4)i[p]=l+Math.floor((1+r[I+0]/r[I+3])*c/2),i[p+1]=o+Math.floor((1-r[I+1]/r[I+3])*f/2),p+=2;if(this._originDot.setPos(i[0],i[1]),this._targetDot.setPos(i[6],i[7]),this._lengthWire.setStartAndEnd(i[0],i[1],i[6],i[7]),this._xAxisWire.setStartAndEnd(i[0],i[1],i[2],i[3]),this._yAxisWire.setStartAndEnd(i[2],i[3],i[4],i[5]),this._zAxisWire.setStartAndEnd(i[4],i[5],i[6],i[7]),this.labelsVisible){this._lengthLabel.setPosOnWire(i[0],i[1],i[6],i[7]),this._xAxisLabel.setPosOnWire(i[0],i[1],i[2],i[3]),this._yAxisLabel.setPosOnWire(i[2],i[3],i[4],i[5]),this._zAxisLabel.setPosOnWire(i[4],i[5],i[6],i[7]);var m=this._approximate?" ~ ":" = ";this._length=Math.abs(Z.lenVec3(Z.subVec3(this._targetWorld,this._originWorld,As))),this._lengthLabel.setText(m+(this._length*d).toFixed(2)+h);var w=Math.abs(ds(i[0],i[1],i[2],i[3])),g=Math.abs(ds(i[2],i[3],i[4],i[5])),T=Math.abs(ds(i[4],i[5],i[6],i[7])),E=this.plugin.labelMinAxisLength;this._xAxisLabelCulled=w<E,this._yAxisLabelCulled=g<E,this._zAxisLabelCulled=T<E,this._xAxisLabelCulled?this._xAxisLabel.setCulled(!0):(this._xAxisLabel.setText(m+Math.abs((this._targetWorld[0]-this._originWorld[0])*d).toFixed(2)+h),this._xAxisLabel.setCulled(!this.axisVisible)),this._yAxisLabelCulled?this._yAxisLabel.setCulled(!0):(this._yAxisLabel.setText(m+Math.abs((this._targetWorld[1]-this._originWorld[1])*d).toFixed(2)+h),this._yAxisLabel.setCulled(!this.axisVisible)),this._zAxisLabelCulled?this._zAxisLabel.setCulled(!0):(this._zAxisLabel.setText(m+Math.abs((this._targetWorld[2]-this._originWorld[2])*d).toFixed(2)+h),this._zAxisLabel.setCulled(!this.axisVisible))}else this._lengthLabel.setCulled(!0),this._xAxisLabel.setCulled(!0),this._yAxisLabel.setCulled(!0),this._zAxisLabel.setCulled(!0);this._originDot.setVisible(this._visible&&this._originVisible),this._targetDot.setVisible(this._visible&&this._targetVisible),this._xAxisWire.setVisible(this.axisVisible&&this.xAxisVisible),this._yAxisWire.setVisible(this.axisVisible&&this.yAxisVisible),this._zAxisWire.setVisible(this.axisVisible&&this.zAxisVisible),this._lengthWire.setVisible(this.wireVisible),this._lengthLabel.setCulled(!this.wireVisible),this._cpDirty=!1}}}},{key:"approximate",get:function(){return this._approximate},set:function(e){e=!1!==e,this._approximate!==e&&(this._approximate=e,this._cpDirty=!0,this._needUpdate(0))}},{key:"origin",get:function(){return this._originMarker}},{key:"target",get:function(){return this._targetMarker}},{key:"length",get:function(){this._update();var e=this.plugin.viewer.scene.metrics.scale;return this._length*e}},{key:"color",get:function(){return this._color},set:function(e){this._color=e,this._originDot.setFillColor(e),this._targetDot.setFillColor(e),this._lengthWire.setColor(e),this._lengthLabel.setFillColor(e)}},{key:"visible",get:function(){return this._visible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultVisible,this._visible=e,this._originDot.setVisible(this._visible&&this._originVisible),this._targetDot.setVisible(this._visible&&this._targetVisible),this._lengthWire.setVisible(this._visible&&this._wireVisible),this._lengthLabel.setVisible(this._visible&&this._wireVisible);var t=this._visible&&this._axisVisible&&this._xAxisVisible,n=this._visible&&this._axisVisible&&this._yAxisVisible,r=this._visible&&this._axisVisible&&this._zAxisVisible;this._xAxisWire.setVisible(t),this._yAxisWire.setVisible(n),this._zAxisWire.setVisible(r),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled),this._yAxisLabel.setVisible(n&&!this._yAxisLabelCulled),this._zAxisLabel.setVisible(r&&!this._zAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"originVisible",get:function(){return this._originVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultOriginVisible,this._originVisible=e,this._originDot.setVisible(this._visible&&this._originVisible)}},{key:"targetVisible",get:function(){return this._targetVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultTargetVisible,this._targetVisible=e,this._targetDot.setVisible(this._visible&&this._targetVisible)}},{key:"axisEnabled",get:function(){return this._axisEnabled},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._axisEnabled=e;var t=this._visible&&this._axisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t&&this._xAxisVisible),this._yAxisWire.setVisible(t&&this._yAxisVisible),this._zAxisWire.setVisible(t&&this._zAxisVisible),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled&&this._xAxisVisible),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled&&this._xAxisVisible),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled&&this._xAxisVisible),this._cpDirty=!0,this._needUpdate()}},{key:"axisVisible",get:function(){return this._axisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._axisVisible=e;var t=this._visible&&this._axisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t&&this._xAxisVisible),this._yAxisWire.setVisible(t&&this._yAxisVisible),this._zAxisWire.setVisible(t&&this._zAxisVisible),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled&&this._xAxisVisible),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled&&this._yAxisVisible),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled&&this._zAxisVisible),this._cpDirty=!0,this._needUpdate()}},{key:"xAxisVisible",get:function(){return this._xAxisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._xAxisVisible=e;var t=this._visible&&this._axisVisible&&this._xAxisVisible&&this._axisEnabled;this._xAxisWire.setVisible(t),this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"yAxisVisible",get:function(){return this._yAxisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._yAxisVisible=e;var t=this._visible&&this._axisVisible&&this._yAxisVisible&&this._axisEnabled;this._yAxisWire.setVisible(t),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"zAxisVisible",get:function(){return this._zAxisVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultAxisVisible,this._zAxisVisible=e;var t=this._visible&&this._axisVisible&&this._zAxisVisible&&this._axisEnabled;this._zAxisWire.setVisible(t),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled),this._cpDirty=!0,this._needUpdate()}},{key:"wireVisible",get:function(){return this._wireVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultWireVisible,this._wireVisible=e;var t=this._visible&&this._wireVisible;this._lengthLabel.setVisible(t),this._lengthWire.setVisible(t)}},{key:"labelsVisible",get:function(){return this._labelsVisible},set:function(e){e=void 0!==e?Boolean(e):this.plugin.defaultLabelsVisible,this._labelsVisible=e;var t=this._visible&&this._labelsVisible;this._xAxisLabel.setVisible(t&&!this._xAxisLabelCulled&&this._clickable&&this._axisEnabled),this._yAxisLabel.setVisible(t&&!this._yAxisLabelCulled&&this._clickable&&this._axisEnabled),this._zAxisLabel.setVisible(t&&!this._zAxisLabelCulled&&this._clickable&&this._axisEnabled),this._lengthLabel.setVisible(t),this._cpDirty=!0,this._needUpdate()}},{key:"setHighlighted",value:function(e){this._originDot.setHighlighted(e),this._targetDot.setHighlighted(e),this._xAxisWire.setHighlighted(e),this._yAxisWire.setHighlighted(e),this._zAxisWire.setHighlighted(e),this._xAxisLabel.setHighlighted(e),this._yAxisLabel.setHighlighted(e),this._zAxisLabel.setHighlighted(e),this._lengthWire.setHighlighted(e),this._lengthLabel.setHighlighted(e)}},{key:"clickable",get:function(){return this._clickable},set:function(e){e=!!e,this._clickable=e,this._originDot.setClickable(this._clickable),this._targetDot.setClickable(this._clickable),this._xAxisWire.setClickable(this._clickable),this._yAxisWire.setClickable(this._clickable),this._zAxisWire.setClickable(this._clickable),this._lengthWire.setClickable(this._clickable),this._xAxisLabel.setClickable(this._clickable),this._yAxisLabel.setClickable(this._clickable),this._zAxisLabel.setClickable(this._clickable),this._lengthLabel.setClickable(this._clickable)}},{key:"destroy",value:function(){var e=this.plugin.viewer.scene,t=e.metrics;this._onViewMatrix&&e.camera.off(this._onViewMatrix),this._onProjMatrix&&e.camera.off(this._onProjMatrix),this._onCanvasBoundary&&e.canvas.off(this._onCanvasBoundary),this._onMetricsUnits&&t.off(this._onMetricsUnits),this._onMetricsScale&&t.off(this._onMetricsScale),this._onMetricsOrigin&&t.off(this._onMetricsOrigin),this._originDot.destroy(),this._targetDot.destroy(),this._xAxisWire.destroy(),this._yAxisWire.destroy(),this._zAxisWire.destroy(),this._lengthLabel.destroy(),this._xAxisLabel.destroy(),this._yAxisLabel.destroy(),this._zAxisLabel.destroy(),this._lengthWire.destroy(),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),hs=function(){function e(){var t=arguments.length>0&&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&&i<a;i++){r=r[n[i]]}return r}function ys(e){var t=arguments.length>1&&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;n<r;n++)t=e[n],this.addFrame(t.t||0,t.eye,t.look,t.up)}},{key:"loadFrame",value:function(e){var t=this.scene.camera;e=(e/=this._frames[this._frames.length-1].t-this._frames[0].t)<0?0:e>1?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;i<a;i++){var s=Z.lenVec3(Z.subVec3(this._frames[i].eye,this._frames[i-1].eye,t));r[i]=s,n+=s}for(var o=1,l=this._frames.length;o<l;o++){var u=r[o]/n*e;this._frames[o].t=this._frames[o-1].t+u}}}},{key:"clearFrames",value:function(){this._frames=[],this._eyeCurve.points=[],this._lookCurve.points=[],this._upCurve.points=[]}}]),n}(),Es=Z.vec3(),bs=Z.vec3(),Ds=Z.vec3(),Ps=Z.vec3(),Rs=Z.vec3(),Cs=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))._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]<r[0]||r[4]<r[1]||r[5]<r[2])return;if(r[3]===r[0]&&r[4]===r[1]&&r[5]===r[2])return;r=r.slice();var p=Z.getAABB3Center(r);this._look2=f||p;var A=Z.subVec3(this._eye1,this._look1,Es),d=Z.normalizeVec3(A),v=f?Z.getAABB3DiagPoint(r,f):Z.getAABB3Diag(r),h=e.fitFOV||this._fitFOV,I=Math.abs(v/Math.tan(h*Z.DEGTORAD));this._orthoScale2=1.1*v,this._eye2[0]=this._look2[0]+d[0]*I,this._eye2[1]=this._look2[1]+d[1]*I,this._eye2[2]=this._look2[2]+d[2]*I,this._up2[0]=this._up1[0],this._up2[1]=this._up1[1],this._up2[2]=this._up1[2],this._flyingEyeLookUp=!0}else(i||a||s)&&(this._flyingEyeLookUp=!!i&&!!a&&!!s,this._flyingEye=!!i&&!a,this._flyingLook=!!a&&!i,i&&(this._eye2[0]=i[0],this._eye2[1]=i[1],this._eye2[2]=i[2]),a&&(this._look2[0]=a[0],this._look2[1]=a[1],this._look2[2]=a[2]),s&&(this._up2[0]=s[0],this._up2[1]=s[1],this._up2[2]=s[2]));u?("ortho"===e.projection&&"ortho"!==l.projection&&(this._projection2="ortho",this._projMatrix1=l.projMatrix.slice(),this._projMatrix2=l.ortho.matrix.slice(),l.projection="customProjection"),"perspective"===e.projection&&"perspective"!==l.projection&&(this._projection2="perspective",this._projMatrix1=l.projMatrix.slice(),this._projMatrix2=l.perspective.matrix.slice(),l.projection="customProjection")):this._projection2=null,this.fire("started",e,!0),this._time1=Date.now(),this._time2=this._time1+(e.duration?1e3*e.duration:this._duration),this._flying=!0,Ae.scheduleTask(this._update,this)}},{key:"jumpTo",value:function(e){this._jumpTo(e)}},{key:"_jumpTo",value:function(e){this._flying&&this.stop();var t,n,r,i,a,s=this.scene.camera;if(e.aabb)t=e.aabb;else if(6===e.length)t=e;else if(e.eye||e.look||e.up)r=e.eye,i=e.look,a=e.up;else{var o=e;if((ae.isNumeric(o)||ae.isString(o))&&(n=o,!(o=this.scene.components[n])))return void this.error("Component not found: "+ae.inQuotes(n));t=o.aabb||this.scene.aabb}var l=e.poi;if(t){if(t[3]<=t[0]||t[4]<=t[1]||t[5]<=t[2])return;var u,c=l?Z.getAABB3DiagPoint(t,l):Z.getAABB3Diag(t);i=l||Z.getAABB3Center(t,i),this._trail?Z.subVec3(s.look,i,Rs):Z.subVec3(s.eye,s.look,Rs),Z.normalizeVec3(Rs),u=(void 0!==e.fit?e.fit:this._fit)?Math.abs(c/Math.tan((e.fitFOV||this._fitFOV)*Z.DEGTORAD)):Z.lenVec3(Z.subVec3(s.eye,s.look,Es)),Z.mulVec3Scalar(Rs,u),s.eye=Z.addVec3(i,Rs,Es),s.look=i,this.scene.camera.ortho.scale=1.1*c}else(r||i||a)&&(r&&(s.eye=r),i&&(s.look=i),a&&(s.up=a));e.projection&&(s.projection=e.projection)}},{key:"_update",value:function(){if(this._flying){var e=(Date.now()-this._time1)/(this._time2-this._time1),t=e>=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;s<e.length;s++)a(s)}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),ee.memory.textures--,this._state.destroy()}}]),n}(),Us=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._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;v<h;v++){var I=a[i[v]];if(I){if(s&&(this.objectsVisible[v]=I.visible),o&&(this.objectsEdges[v]=I.edges),l&&(this.objectsXrayed[v]=I.xrayed),u&&(this.objectsHighlighted[v]=I.highlighted),c&&(this.objectsSelected[v]=I.selected),f&&(this.objectsClippable[v]=I.clippable),p&&(this.objectsPickable[v]=I.pickable),A){var y=I.colorize;this.objectsColorize[3*v+0]=y[0],this.objectsColorize[3*v+1]=y[1],this.objectsColorize[3*v+2]=y[2]}d&&(this.objectsOpacity[v]=I.opacity),this.numObjects++}}}}},{key:"restoreObjects",value:function(e,t){var n=t.rootMetaObject;if(n)for(var r=n.getObjectIDsInSubtree(),i=this._mask,a=!i||i.visible,s=!i||i.edges,o=!i||i.xrayed,l=!i||i.highlighted,u=!i||i.selected,c=!i||i.clippable,f=!i||i.pickable,p=!i||i.colorize,A=!i||i.opacity,d=e.objects,v=0,h=r.length;v<h;v++){var I=d[r[v]];I&&(a&&(I.visible=this.objectsVisible[v]),s&&(I.edges=this.objectsEdges[v]),o&&(I.xrayed=this.objectsXrayed[v]),l&&(I.highlighted=this.objectsHighlighted[v]),u&&(I.selected=this.objectsSelected[v]),c&&(I.clippable=this.objectsClippable[v]),f&&(I.pickable=this.objectsPickable[v]),p&&(js[0]=this.objectsColorize[3*v+0],js[1]=this.objectsColorize[3*v+1],js[2]=this.objectsColorize[3*v+2],I.colorize=js),A&&(I.opacity=this.objectsOpacity[v]))}}}]),e}(),Ws=Z.vec3(),zs=function(){function e(){b(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}return P(e,[{key:"saveObjects",value:function(e,t){this.numObjects=0,this._mask=t?ae.apply(t,{}):null;var n=e.objects,r=!t||t.visible,i=!t||t.edges,a=!t||t.xrayed,s=!t||t.highlighted,o=!t||t.selected,l=!t||t.clippable,u=!t||t.pickable,c=!t||t.colorize,f=!t||t.opacity;for(var p in n)if(n.hasOwnProperty(p)){var A=n[p],d=this.numObjects;if(r&&(this.objectsVisible[d]=A.visible),i&&(this.objectsEdges[d]=A.edges),a&&(this.objectsXrayed[d]=A.xrayed),s&&(this.objectsHighlighted[d]=A.highlighted),o&&(this.objectsSelected[d]=A.selected),l&&(this.objectsClippable[d]=A.clippable),u&&(this.objectsPickable[d]=A.pickable),c){var v=A.colorize;v?(this.objectsColorize[3*d+0]=v[0],this.objectsColorize[3*d+1]=v[1],this.objectsColorize[3*d+2]=v[2],this.objectsHasColorize[d]=!0):this.objectsHasColorize[d]=!1}f&&(this.objectsOpacity[d]=A.opacity),this.numObjects++}}},{key:"restoreObjects",value:function(e){var t=this._mask,n=!t||t.visible,r=!t||t.edges,i=!t||t.xrayed,a=!t||t.highlighted,s=!t||t.selected,o=!t||t.clippable,l=!t||t.pickable,u=!t||t.colorize,c=!t||t.opacity,f=0,p=e.objects;for(var A in p)if(p.hasOwnProperty(A)){var d=p[A];n&&(d.visible=this.objectsVisible[f]),r&&(d.edges=this.objectsEdges[f]),i&&(d.xrayed=this.objectsXrayed[f]),a&&(d.highlighted=this.objectsHighlighted[f]),s&&(d.selected=this.objectsSelected[f]),o&&(d.clippable=this.objectsClippable[f]),l&&(d.pickable=this.objectsPickable[f]),u&&(this.objectsHasColorize[f]?(Ws[0]=this.objectsColorize[3*f+0],Ws[1]=this.objectsColorize[3*f+1],Ws[2]=this.objectsColorize[3*f+2],d.colorize=Ws):d.colorize=null),c&&(d.opacity=this.objectsOpacity[f]),f++}}}]),e}(),Ks=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)).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;n<r;n++)(t=this._curves[n]).off(this._dirtySubs[n]),t.off(this._destroyedSubs[n]);this._curves=[],this._dirtySubs=[],this._destroyedSubs=[];var i=this;function a(){i._dirty=!0}function s(){var e=this.id;for(n=0,r=i._curves.length;n<r;n++)if(i._curves[n].id===e)return i._curves=i._curves.slice(n,n+1),i._dirtySubs=i._dirtySubs.slice(n,n+1),i._destroyedSubs=i._destroyedSubs.slice(n,n+1),void(i._dirty=!0)}for(n=0,r=e.length;n<r;n++){if(t=e[n],ae.isNumeric(t)||ae.isString(t)){var o=t;if(!(t=this.scene.components[o])){this.error("Component not found: "+_inQuotes(o));continue}}var l=t.type;"xeokit.SplineCurve"===l||"xeokit.Path"===l||"xeokit.CubicBezierCurve"===l||"xeokit.QuadraticBezierCurve"===l?(this._curves.push(t),this._dirtySubs.push(t.on("dirty",a)),this._destroyedSubs.push(t.once("destroyed",s))):this.error("Component "+_inQuotes(t.id)+" is not a xeokit.SplineCurve, xeokit.Path or xeokit.QuadraticBezierCurve")}this._dirty=!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:"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<r.length;){if(r[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;e<r;e++)n+=this._curves[e].length,t.push(n);return this._cachedLengths=t,this._dirty=!1,t}},{key:"_getJSON",value:function(){for(var e=[],t=0,n=this._curves.length;t<n;t++)e.push(this._curves[t].id);return{curves:e,t:this._t}}},{key:"destroy",value:function(){var e,t,r;for(v(T(n.prototype),"destroy",this).call(this),e=0,t=this._curves.length;e<t;e++)(r=this._curves[e]).off(this._dirtySubs[e]),r.off(this._destroyedSubs[e])}}]),n}(),Xs=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)).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;u<a;u++){var c=this._uSectionPlanes[u];if(c){var f=l.sectionPlanesActivePerLayer[o+u];if(n.uniform1i(c.active,f?1:0),f){var p=s[u],A=e._state.origin;if(A){var d=ge(p.dist,p.dir,A,io);n.uniform3fv(c.pos,d)}else n.uniform3fv(c.pos,p.pos);n.uniform3fv(c.dir,p.dir)}}}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl,n=e._lightsState;if(this._program=new ft(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uRenderPass=r.getLocation("renderPass"),this._uColor=r.getLocation("color"),this._uColor||(this._uColor=r.getLocation("silhouetteColor")),this._uUVDecodeMatrix=r.getLocation("uvDecodeMatrix"),this._uPickInvisible=r.getLocation("pickInvisible"),this._uGammaFactor=r.getLocation("gammaFactor"),t.uniformBlockBinding(r.handle,t.getUniformBlockIndex(r.handle,"Matrices"),this._matricesUniformBlockBufferBindingPoint),this._uShadowViewMatrix=r.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=r.getLocation("shadowProjMatrix"),e.logarithmicDepthBufferEnabled&&(this._uZFar=r.getLocation("zFar")),this._uLightAmbient=r.getLocation("lightAmbient"),this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];for(var i=n.lights,a=0,s=i.length;a<s;a++)switch(i[a].type){case"dir":this._uLightColor[a]=r.getLocation("lightColor"+a),this._uLightPos[a]=null,this._uLightDir[a]=r.getLocation("lightDir"+a);break;case"point":this._uLightColor[a]=r.getLocation("lightColor"+a),this._uLightPos[a]=r.getLocation("lightPos"+a),this._uLightDir[a]=null,this._uLightAttenuation[a]=r.getLocation("lightAttenuation"+a);break;case"spot":this._uLightColor[a]=r.getLocation("lightColor"+a),this._uLightPos[a]=r.getLocation("lightPos"+a),this._uLightDir[a]=r.getLocation("lightDir"+a),this._uLightAttenuation[a]=r.getLocation("lightAttenuation"+a)}n.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),n.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(var o=0,l=e._sectionPlanesState.sectionPlanes.length;o<l;o++)this._uSectionPlanes.push({active:r.getLocation("sectionPlaneActive"+o),pos:r.getLocation("sectionPlanePos"+o),dir:r.getLocation("sectionPlaneDir"+o)});this._aPosition=r.getAttribute("position"),this._aOffset=r.getAttribute("offset"),this._aNormal=r.getAttribute("normal"),this._aUV=r.getAttribute("uv"),this._aColor=r.getAttribute("color"),this._aMetallicRoughness=r.getAttribute("metallicRoughness"),this._aFlags=r.getAttribute("flags"),this._aPickColor=r.getAttribute("pickColor"),this._uPickZNear=r.getLocation("pickZNear"),this._uPickZFar=r.getLocation("pickZFar"),this._uColorMap="uColorMap",this._uMetallicRoughMap="uMetallicRoughMap",this._uEmissiveMap="uEmissiveMap",this._uNormalMap="uNormalMap",this._uAOMap="uAOMap",this._instancing&&(this._aModelMatrixCol0=r.getAttribute("modelMatrixCol0"),this._aModelMatrixCol1=r.getAttribute("modelMatrixCol1"),this._aModelMatrixCol2=r.getAttribute("modelMatrixCol2"),this._aModelNormalMatrixCol0=r.getAttribute("modelNormalMatrixCol0"),this._aModelNormalMatrixCol1=r.getAttribute("modelNormalMatrixCol1"),this._aModelNormalMatrixCol2=r.getAttribute("modelNormalMatrixCol2")),this._withSAO&&(this._uOcclusionTexture="uOcclusionTexture",this._uSAOParams=r.getLocation("uSAOParams")),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=r.getLocation("logDepthBufFC")),e.pointsMaterial._state.filterIntensity&&(this._uIntensityRange=r.getLocation("intensityRange")),this._uPointSize=r.getLocation("pointSize"),this._uNearPlaneHeight=r.getLocation("nearPlaneHeight")}}},{key:"_bindProgram",value:function(e){var t=this._scene,n=t.canvas.gl,r=this._program,i=t._lightsState,a=i.lights,s=t.camera.project;r.bind(),e.textureUnit=0,this._uLightAmbient&&n.uniform4fv(this._uLightAmbient,i.getAmbientColorAndIntensity());for(var o=0,l=a.length;o<l;o++){var u=a[o];this._uLightColor[o]&&n.uniform4f(this._uLightColor[o],u.color[0],u.color[1],u.color[2],u.intensity),this._uLightPos[o]&&(n.uniform3fv(this._uLightPos[o],u.pos),this._uLightAttenuation[o]&&n.uniform1f(this._uLightAttenuation[o],u.attenuation)),this._uLightDir[o]&&n.uniform3fv(this._uLightDir[o],u.dir)}if(this._withSAO){var c=t.sao;if(c.possible){var f=n.drawingBufferWidth,p=n.drawingBufferHeight;ro[0]=f,ro[1]=p,ro[2]=c.blendCutoff,ro[3]=c.blendFactor,n.uniform4fv(this._uSAOParams,ro),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,0)}}if(t.logarithmicDepthBufferEnabled){var A=2/(Math.log(s.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,A)}this._uGammaFactor&&n.uniform1f(this._uGammaFactor,t.gammaFactor),this._uPickInvisible&&n.uniform1i(this._uPickInvisible,e.pickInvisible),this._uShadowViewMatrix&&n.uniformMatrix4fv(this._uShadowViewMatrix,!1,e.shadowViewMatrix),this._uShadowProjMatrix&&n.uniformMatrix4fv(this._uShadowProjMatrix,!1,e.shadowProjMatrix)}},{key:"_makeVAO",value:function(e){var t=this._scene.canvas.gl,n=t.createVertexArray();return t.bindVertexArray(n),this._instancing&&(this._aModelMatrixCol0.bindArrayBuffer(e.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(e.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(e.modelMatrixCol2Buf),t.vertexAttribDivisor(this._aModelMatrixCol0.location,1),t.vertexAttribDivisor(this._aModelMatrixCol1.location,1),t.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aModelNormalMatrixCol0&&(this._aModelNormalMatrixCol0.bindArrayBuffer(e.modelNormalMatrixCol0Buf),t.vertexAttribDivisor(this._aModelNormalMatrixCol0.location,1)),this._aModelNormalMatrixCol1&&(this._aModelNormalMatrixCol1.bindArrayBuffer(e.modelNormalMatrixCol1Buf),t.vertexAttribDivisor(this._aModelNormalMatrixCol1.location,1)),this._aModelNormalMatrixCol2&&(this._aModelNormalMatrixCol2.bindArrayBuffer(e.modelNormalMatrixCol2Buf),t.vertexAttribDivisor(this._aModelNormalMatrixCol2.location,1))),this._aPosition.bindArrayBuffer((this._instancing,e.positionsBuf)),this._aUV&&this._aUV.bindArrayBuffer((this._instancing,e.uvBuf)),this._aNormal&&this._aNormal.bindArrayBuffer((this._instancing,e.normalsBuf)),this._aMetallicRoughness&&(this._aMetallicRoughness.bindArrayBuffer(e.metallicRoughnessBuf),this._instancing&&t.vertexAttribDivisor(this._aMetallicRoughness.location,1)),this._aColor&&(this._aColor.bindArrayBuffer((e.colorsBuf,e.colorsBuf)),this._instancing&&e.colorsBuf&&t.vertexAttribDivisor(this._aColor.location,1)),this._aFlags&&(this._aFlags.bindArrayBuffer(e.flagsBuf),this._instancing&&t.vertexAttribDivisor(this._aFlags.location,1)),this._aOffset&&(this._aOffset.bindArrayBuffer(e.offsetsBuf),this._instancing&&t.vertexAttribDivisor(this._aOffset.location,1)),this._aPickColor&&(this._aPickColor.bindArrayBuffer(e.pickColorsBuf),this._instancing&&t.vertexAttribDivisor(this._aPickColor.location,1)),this._instancing,this._edges?e.edgeIndicesBuf.bind():e.indicesBuf&&e.indicesBuf.bind(),n}},{key:"drawLayer",value:function(e,t,n){var r=arguments.length>3&&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<o;s++)"ambient"!==(e=r.lights[s]).type&&(a.push("uniform vec4 lightColor"+s+";"),"dir"===e.type&&a.push("uniform vec3 lightDir"+s+";"),"point"===e.type&&a.push("uniform vec3 lightPos"+s+";"),"spot"===e.type&&(a.push("uniform vec3 lightPos"+s+";"),a.push("uniform vec3 lightDir"+s+";")));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("}"),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;l<u;l++)if("ambient"!==(e=r.lights[l]).type){if("dir"===e.type)"view"===e.space?a.push("viewLightDir = normalize(lightDir"+l+");"):a.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+l+", 0.0)).xyz);");else if("point"===e.type)"view"===e.space?a.push("viewLightDir = -normalize(lightPos"+l+" - viewPosition.xyz);"):a.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+l+", 0.0)).xyz);");else{if("spot"!==e.type)continue;"view"===e.space?a.push("viewLightDir = normalize(lightDir"+l+");"):a.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+l+", 0.0)).xyz);")}a.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),a.push("reflectedColor += lambertian * (lightColor"+l+".rgb * lightColor"+l+".a);")}return a.push("vec3 rgb = (vec3(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0));"),a.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedColor * rgb), float(color.a) / 255.0);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;")),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}}]),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<s;a++)i.push("uniform bool sectionPlaneActive"+a+";"),i.push("uniform vec3 sectionPlanePos"+a+";"),i.push("uniform vec3 sectionPlaneDir"+a+";")}this._addMatricesUniformBlockLines(i),i.push("uniform vec4 lightAmbient;");for(var o=0,l=t.lights.length;o<l;o++){var u=t.lights[o];"ambient"!==u.type&&(i.push("uniform vec4 lightColor"+o+";"),"dir"===u.type&&i.push("uniform vec3 lightDir"+o+";"),"point"===u.type&&i.push("uniform vec3 lightPos"+o+";"),"spot"===u.type&&(i.push("uniform vec3 lightPos"+o+";"),i.push("uniform vec3 lightDir"+o+";")))}if(i.push("in vec4 vViewPosition;"),i.push("in vec4 vColor;"),i.push("out vec4 outColor;"),i.push("void main(void) {"),r){i.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var c=0,f=n.sectionPlanes.length;c<f;c++)i.push("if (sectionPlaneActive"+c+") {"),i.push(" dist += clamp(dot(-sectionPlaneDir"+c+".xyz, vWorldPosition.xyz - sectionPlanePos"+c+".xyz), 0.0, 1000.0);"),i.push("}");i.push(" if (dist > 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;p<A;p++){var d=t.lights[p];if("ambient"!==d.type){if("dir"===d.type)"view"===d.space?i.push("viewLightDir = normalize(lightDir"+p+");"):i.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+p+", 0.0)).xyz);");else if("point"===d.type)"view"===d.space?i.push("viewLightDir = -normalize(lightPos"+p+" - viewPosition.xyz);"):i.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+p+", 0.0)).xyz);");else{if("spot"!==d.type)continue;"view"===d.space?i.push("viewLightDir = normalize(lightDir"+p+");"):i.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+p+", 0.0)).xyz);")}i.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),i.push("reflectedColor += lambertian * (lightColor"+p+".rgb * lightColor"+p+".a);")}}return i.push("vec4 fragColor = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);"),this._withSAO?(i.push(" float viewportWidth = uSAOParams[0];"),i.push(" float viewportHeight = uSAOParams[1];"),i.push(" float blendCutoff = uSAOParams[2];"),i.push(" float blendFactor = uSAOParams[3];"),i.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),i.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),i.push(" outColor = vec4(fragColor.rgb * ambient, 1.0);")):i.push(" outColor = fragColor;"),e.logarithmicDepthBufferEnabled&&i.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),i.push("}"),i}}]),n}(),Io=function(e){I(n,so);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 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<t;e++)a.push("uniform bool sectionPlaneActive"+e+";"),a.push("uniform vec3 sectionPlanePos"+e+";"),a.push("uniform vec3 sectionPlaneDir"+e+";");if(a.push("in vec4 vColor;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),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<t;e++)a.push("if (sectionPlaneActive"+e+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+e+".xyz, vWorldPosition.xyz - sectionPlanePos"+e+".xyz), 0.0, 1000.0);"),a.push("}");a.push(" if (dist > 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vPickColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vViewPosition;"),r.push("vec4 packDepth(const in float depth) {"),r.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),r.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),r.push(" vec4 res = fract(depth * bitShift);"),r.push(" res -= res.xxyz * bitMask;"),r.push(" return res;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vWorldNormal;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("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("const float shiftRight8 = 1.0 / 256.;"),r.push("vec4 packDepthToRGBA( const in float v ) {"),r.push(" vec4 r = vec4( fract( v * packFactors ), v );"),r.push(" r.yzw -= r.xyz * shiftRight8;"),r.push(" return r * packUpScale;"),r.push("}"),r.push("in vec2 vHighPrecisionZW;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vViewNormal;"),r.push("vec3 packNormalToRGB( const in vec3 normal ) {"),r.push(" return normalize( normal ) * 0.5 + 0.5;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<e.sectionPlanes.length;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in vec4 vViewPosition;"),n.push("vec4 encodeFloat( const in float v ) {"),n.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"),n.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"),n.push(" vec4 comp = fract(v * bitShift);"),n.push(" comp -= comp.xxyz * bitMask;"),n.push(" return comp;"),n.push("}"),n.push("out vec4 outColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i<e.sectionPlanes.length;i++)n.push(" if (sectionPlaneActive"+i+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 0.0) { discard; }"),n.push(" }")}return n.push(" outColor = 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;o<l;o++){var u=r.lights[o];"ambient"!==u.type&&(s.push("uniform vec4 lightColor"+o+";"),"dir"===u.type&&s.push("uniform vec3 lightDir"+o+";"),"point"===u.type&&s.push("uniform vec3 lightPos"+o+";"),"spot"===u.type&&(s.push("uniform vec3 lightPos"+o+";"),s.push("uniform vec3 lightDir"+o+";")))}if(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("}")),s.push("uniform float gammaFactor;"),s.push("vec4 linearToLinear( in vec4 value ) {"),s.push(" return value;"),s.push("}"),s.push("vec4 sRGBToLinear( in vec4 value ) {"),s.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 );"),s.push("}"),s.push("vec4 gammaToLinear( in vec4 value) {"),s.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),s.push("}"),t&&(s.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),s.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),s.push("}")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;"),a&&s.push("in vec4 vClipPosition;");for(var c=0,f=n.sectionPlanes.length;c<f;c++)s.push("uniform bool sectionPlaneActive"+c+";"),s.push("uniform vec3 sectionPlanePos"+c+";"),s.push("uniform vec3 sectionPlaneDir"+c+";")}if(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.x == 0.0 && texel.y == 0.0 && texel.z == 0.0) {"),s.push(" return 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 = 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<A;p++)s.push("if (sectionPlaneActive"+p+") {"),s.push(" dist += clamp(dot(-sectionPlaneDir"+p+".xyz, vWorldPosition.xyz - sectionPlanePos"+p+".xyz), 0.0, 1000.0);"),s.push("}");a?(s.push(" if (dist > (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;d<v;d++){var h=r.lights[d];if("ambient"!==h.type){if("dir"===h.type)"view"===h.space?s.push("light.direction = normalize(lightDir"+d+");"):s.push("light.direction = normalize((viewMatrix * vec4(lightDir"+d+", 0.0)).xyz);");else if("point"===h.type)"view"===h.space?s.push("light.direction = normalize(lightPos"+d+" - vViewPosition.xyz);"):s.push("light.direction = normalize((viewMatrix * vec4(lightPos"+d+", 0.0)).xyz);");else{if("spot"!==h.type)continue;"view"===h.space?s.push("light.direction = normalize(lightDir"+d+");"):s.push("light.direction = normalize((viewMatrix * vec4(lightDir"+d+", 0.0)).xyz);")}s.push("light.color = lightColor"+d+".rgb * lightColor"+d+".a;"),s.push("computePBRLighting(light, geometry, material, reflectedLight);")}}return s.push("vec3 emissiveColor = sRGBToLinear(texture(uEmissiveMap, vUV)).rgb;"),s.push("float aoFactor = texture(uAOMap, vUV).r;"),s.push("vec3 outgoingLight = (lightAmbient.rgb * lightAmbient.a * baseColor * opacity * rgb) + (reflectedLight.diffuse) + (reflectedLight.specular) + emissiveColor;"),s.push("vec4 fragColor;"),this._withSAO?(s.push(" float viewportWidth = uSAOParams[0];"),s.push(" float viewportHeight = uSAOParams[1];"),s.push(" float blendCutoff = uSAOParams[2];"),s.push(" float blendFactor = uSAOParams[3];"),s.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),s.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),s.push(" fragColor = vec4(outgoingLight.rgb * ambient * aoFactor, opacity);")):s.push(" fragColor = vec4(outgoingLight.rgb * aoFactor, opacity);"),t&&s.push("fragColor = linearToGamma(fragColor, gammaFactor);"),s.push("outColor = fragColor;"),e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),n}(),Co=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 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<o;s++)a.push("uniform bool sectionPlaneActive"+s+";"),a.push("uniform vec3 sectionPlanePos"+s+";"),a.push("uniform vec3 sectionPlaneDir"+s+";")}this._addMatricesUniformBlockLines(a),a.push("uniform vec4 lightAmbient;");for(var l=0,u=n.lights.length;l<u;l++){var c=n.lights[l];"ambient"!==c.type&&(a.push("uniform vec4 lightColor"+l+";"),"dir"===c.type&&a.push("uniform vec3 lightDir"+l+";"),"point"===c.type&&a.push("uniform vec3 lightPos"+l+";"),"spot"===c.type&&(a.push("uniform vec3 lightPos"+l+";"),a.push("uniform vec3 lightDir"+l+";")))}if(a.push("in vec4 vViewPosition;"),a.push("in vec4 vColor;"),a.push("in vec2 vUV;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),i){a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(var f=0,p=r.sectionPlanes.length;f<p;f++)a.push("if (sectionPlaneActive"+f+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+f+".xyz, vWorldPosition.xyz - sectionPlanePos"+f+".xyz), 0.0, 1000.0);"),a.push("}");a.push(" if (dist > 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;A<d;A++){var v=n.lights[A];if("ambient"!==v.type){if("dir"===v.type)"view"===v.space?a.push("viewLightDir = normalize(lightDir"+A+");"):a.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+A+", 0.0)).xyz);");else if("point"===v.type)"view"===v.space?a.push("viewLightDir = -normalize(lightPos"+A+" - viewPosition.xyz);"):a.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+A+", 0.0)).xyz);");else{if("spot"!==v.type)continue;"view"===v.space?a.push("viewLightDir = normalize(lightDir"+A+");"):a.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+A+", 0.0)).xyz);")}a.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),a.push("reflectedColor += lambertian * (lightColor"+A+".rgb * lightColor"+A+".a);")}}return a.push("vec4 color = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);"),t?a.push("vec4 colorTexel = color * sRGBToLinear(texture(uColorMap, vUV));"):a.push("vec4 colorTexel = color * texture(uColorMap, vUV);"),a.push("float opacity = color.a;"),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, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(colorTexel.rgb * ambient, opacity);")):a.push(" outColor = vec4(colorTexel.rgb, opacity);"),t&&a.push("outColor = linearToGamma(outColor, gammaFactor);"),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}]),n}(),Bo=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorTextureRenderer&&!this._colorTextureRenderer.getValid()&&(this._colorTextureRenderer.destroy(),this._colorTextureRenderer=null),this._colorTextureRendererWithSAO&&!this._colorTextureRendererWithSAO.getValid()&&(this._colorTextureRendererWithSAO.destroy(),this._colorTextureRendererWithSAO=null),this._pbrRenderer&&!this._pbrRenderer.getValid()&&(this._pbrRenderer.destroy(),this._pbrRenderer=null),this._pbrRendererWithSAO&&!this._pbrRendererWithSAO.getValid()&&(this._pbrRendererWithSAO.destroy(),this._pbrRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new vo(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new vo(this._scene,!0)),this._colorRendererWithSAO}},{key:"flatColorRenderer",get:function(){return this._flatColorRenderer||(this._flatColorRenderer=new ho(this._scene,!1)),this._flatColorRenderer}},{key:"flatColorRendererWithSAO",get:function(){return this._flatColorRendererWithSAO||(this._flatColorRendererWithSAO=new ho(this._scene,!0)),this._flatColorRendererWithSAO}},{key:"colorTextureRenderer",get:function(){return this._colorTextureRenderer||(this._colorTextureRenderer=new _o(this._scene,!1)),this._colorTextureRenderer}},{key:"colorTextureRendererWithSAO",get:function(){return this._colorTextureRendererWithSAO||(this._colorTextureRendererWithSAO=new _o(this._scene,!0)),this._colorTextureRendererWithSAO}},{key:"pbrRenderer",get:function(){return this._pbrRenderer||(this._pbrRenderer=new Ro(this._scene,!1)),this._pbrRenderer}},{key:"pbrRendererWithSAO",get:function(){return this._pbrRendererWithSAO||(this._pbrRendererWithSAO=new Ro(this._scene,!0)),this._pbrRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Io(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new bo(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new Do(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new yo(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new mo(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new wo(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new To(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new Co(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new go(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Eo(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new Po(this._scene)),this._shadowRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._colorTextureRenderer&&this._colorTextureRenderer.destroy(),this._colorTextureRendererWithSAO&&this._colorTextureRendererWithSAO.destroy(),this._pbrRenderer&&this._pbrRenderer.destroy(),this._pbrRendererWithSAO&&this._pbrRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}]),e}(),Oo={};var So=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.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<r;h+=3)i[h+0]=Math.floor(v(e[h+0]-a)*p),i[h+1]=Math.floor(v(e[h+1]-s)*A),i[h+2]=Math.floor(v(e[h+2]-o)*d);return Z.identityMat4(No),Z.translationMat4v(t,No),Z.identityMat4(Lo),Z.scalingMat4v([l/f,u/f,c/f],Lo),Z.mulMat4(No,Lo,n),i}function Mo(e,t){var n=e[0],r=e[1],i=e[2],a=e[3]-n,s=e[4]-r,o=e[5]-i,l=65525;return Z.identityMat4(No),Z.translationMat4v(e,No),Z.identityMat4(Lo),Z.scalingMat4v([a/l,s/l,o/l],Lo),Z.mulMat4(No,Lo,t),t}function Fo(e,t,n){var r=e[0]/(Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2])),i=e[1]/(Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2]));if(e[2]<0){var a,s;a=(1-Math.abs(i))*(r>=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;w<h;w++){var g=this._uSectionPlanes[w];if(g){var T=m.sectionPlanesActivePerLayer[y+w];if(s.uniform1i(g.active,T?1:0),T){var E=I[w];if(l){var b=ge(E.dist,E.dir,l,Uo);s.uniform3fv(g.pos,b)}else s.uniform3fv(g.pos,E.pos);s.uniform3fv(g.dir,E.dir)}}}s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,t._state.positionsDecodeMatrix),this._aPosition.bindArrayBuffer(o.positionsBuf),this._aOffset&&this._aOffset.bindArrayBuffer(o.offsetsBuf),this._aFlags&&this._aFlags.bindArrayBuffer(o.flagsBuf),o.indicesBuf.bind(),s.drawElements(s.TRIANGLES,o.indicesBuf.numItems,o.indicesBuf.itemType,0),o.indicesBuf.unbind()}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new ft(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSolid=n.getLocation("solid"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._aPosition=n.getAttribute("position"),this._aOffset=n.getAttribute("offset"),this._aFlags=n.getAttribute("flags"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc"),this.uVectorA=n.getLocation("snapVectorA"),this.uInverseVectorAB=n.getLocation("snapInvVectorAB"),this._uLayerNumber=n.getLocation("layerNumber"),this._uCoordinateScaler=n.getLocation("coordinateScaler")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in highp vec3 relativeToOriginPosition;"),r.push("out highp ivec4 outCoords;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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;w<h;w++){var g=this._uSectionPlanes[w];if(g){var T=m.sectionPlanesActivePerLayer[y+w];if(s.uniform1i(g.active,T?1:0),T){var E=I[w];if(l){var b=ge(E.dist,E.dir,l,ko);s.uniform3fv(g.pos,b)}else s.uniform3fv(g.pos,E.pos);s.uniform3fv(g.dir,E.dir)}}}s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,t._state.positionsDecodeMatrix),this._aPosition.bindArrayBuffer(o.positionsBuf),this._aOffset&&this._aOffset.bindArrayBuffer(o.offsetsBuf),this._aFlags&&this._aFlags.bindArrayBuffer(o.flagsBuf),"edge"===e.snapMode?(o.edgeIndicesBuf.bind(),s.drawElements(s.LINES,o.edgeIndicesBuf.numItems,o.edgeIndicesBuf.itemType,0),o.edgeIndicesBuf.unbind()):s.drawArrays(s.POINTS,0,o.positionsBuf.numItems)}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new ft(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._aPosition=n.getAttribute("position"),this._aOffset=n.getAttribute("offset"),this._aFlags=n.getAttribute("flags"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc"),this.uVectorA=n.getLocation("snapVectorA"),this.uInverseVectorAB=n.getLocation("snapInvVectorAB"),this._uLayerNumber=n.getLocation("layerNumber"),this._uCoordinateScaler=n.getLocation("coordinateScaler")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0;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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in highp vec3 relativeToOriginPosition;"),r.push("out highp ivec4 outCoords;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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+t<this._buffer.maxIndices}},{key:"createPortion",value:function(e){if(this._finalized)throw"Already finalized";var t,n=e.positions,r=e.positionsCompressed,i=e.normals,a=e.normalsCompressed,s=e.uv,o=e.uvCompressed,l=e.colors,u=e.colorsCompressed,c=e.indices,f=e.edgeIndices,p=e.color,A=e.metallic,d=e.roughness,v=e.opacity,h=e.meshMatrix,I=e.sceneModelMatrix,y=e.worldAABB,m=e.pickColor,w=this.model.scene,g=this._buffer,T=g.positions.length/3;if(this._state.positionsDecodeMatrix){if(!r)throw"positionsCompressed expected";t=r.length/3;for(var E=0,b=r.length;E<b;E++)g.positions.push(r[E]);var D=pn.getPositionsBounds(r),P=pn.decompressPosition(D.min,this._state.positionsDecodeMatrix,[]),R=pn.decompressPosition(D.max,this._state.positionsDecodeMatrix,[]);y[0]=P[0],y[1]=P[1],y[2]=P[2],y[3]=R[0],y[4]=R[1],y[5]=R[2],I&&(Z.AABB3ToOBB3(y,qo),Z.transformOBB3(I,qo),Z.OBB3ToAABB3(qo,y))}else{if(!n)throw"positions expected";t=n.length/3;for(var C=n.length,_=g.positions.length,B=0,O=n.length;B<O;B++)g.positions.push(n[B]);if(h)for(var S=_,N=_+C;S<N;S+=3)Ko[0]=g.positions[S+0],Ko[1]=g.positions[S+1],Ko[2]=g.positions[S+2],Z.transformPoint4(h,Ko,Yo),g.positions[S+0]=Yo[0],g.positions[S+1]=Yo[1],g.positions[S+2]=Yo[2],Z.expandAABB3Point3(this._modelAABB,Yo),I?(Z.transformPoint4(I,Yo,Xo),Z.expandAABB3Point3(y,Xo)):Z.expandAABB3Point3(y,Yo);else for(var L=_,x=_+C;L<x;L+=3)Ko[0]=g.positions[L+0],Ko[1]=g.positions[L+1],Ko[2]=g.positions[L+2],Z.expandAABB3Point3(this._modelAABB,Ko),I?(Z.transformPoint4(I,Ko,Yo),Z.expandAABB3Point3(y,Yo)):Z.expandAABB3Point3(y,Ko)}if(this._state.origin){var M=this._state.origin;y[0]+=M[0],y[1]+=M[1],y[2]+=M[2],y[3]+=M[0],y[4]+=M[1],y[5]+=M[2]}if(Z.expandAABB3(this.aabb,y),a&&a.length>0)for(var F=0,H=a.length;F<H;F++)g.normals.push(a[F]);else if(i&&i.length>0){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;c<n;c+=3)f[0]=t[c],f[1]=t[c+1],f[2]=t[c+2],Z.transformVec3(e,f,p),Z.normalizeVec3(p,p),o=s=Fo(p,"floor","floor"),l=u=a(p,Ho(s)),(l=a(p,Ho(s=Fo(p,"ceil","floor"))))>u&&(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;G<k;G+=3)g.colors.push(255*l[G]),g.colors.push(255*l[G+1]),g.colors.push(255*l[G+2]),g.colors.push(255);else if(u)for(var V=0,j=l.length;V<j;V+=3)g.colors.push(l[V]),g.colors.push(l[V+1]),g.colors.push(l[V+2]),g.colors.push(255);else if(p)for(var Q=p[0],W=p[1],z=p[2],K=v,Y=0;Y<t;Y++)g.colors.push(Q),g.colors.push(W),g.colors.push(z),g.colors.push(K);for(var X=null!=A?A:0,q=null!=d?d:255,J=0;J<t;J++)g.metallicRoughness.push(X),g.metallicRoughness.push(q);if(s&&s.length>0)for(var $=0,ee=s.length;$<ee;$++)g.uv.push(s[$]);else if(o&&o.length>0)for(var te=0,ne=o.length;te<ne;te++)g.uv.push(o[te]);for(var re=0,ie=c.length;re<ie;re++)g.indices.push(T+c[re]);if(f)for(var ae=0,se=f.length;ae<se;ae++)g.edgeIndices.push(T+f[ae]);for(var oe=g.pickColors.length,le=oe,ue=oe+4*t;le<ue;le+=4)g.pickColors.push(m[0]),g.pickColors.push(m[1]),g.pickColors.push(m[2]),g.pickColors.push(m[3]);if(w.entityOffsetsEnabled)for(var ce=0;ce<t;ce++)g.offsets.push(0),g.offsets.push(0),g.offsets.push(0);var fe=this._portions.length,pe={vertsBaseIndex:T,numVerts:t,indicesBaseIndex:g.indices.length-c.length,numIndices:c.length};return w.pickSurfacePrecisionEnabled&&(pe.indices=c,w.entityOffsetsEnabled&&(pe.offset=new Float32Array(3))),this._portions.push(pe),this._numPortions++,this.model.numPortions++,this._numVerts+=pe.numVerts,fe}},{key:"finalize",value:function(){if(!this._finalized){var e=this._state,t=this.model.scene.canvas.gl,n=this._buffer;if(n.positions.length>0){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;i<a;i++){var s=this._portions[i],o=3*s.vertsBaseIndex,l=o+3*s.numVerts;s.quantizedPositions=r.slice(o,l)}}if(n.normals.length>0){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;f<a;f+=4)s[f+0]=o,s[f+1]=l,s[f+2]=u,s[f+3]=c;this._state.colorsBuf&&this._state.colorsBuf.setData(s,i,a)}},{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){var r=arguments.length>3&&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;T<E;T++){var b=0;b|=i,b|=a<<4,b|=m<<8,b|=w<<12,b|=g<<16,this._deferredFlagValues[T]=b}}else if(this._state.flagsBuf){for(var D=this._scratchMemory.getFloat32Array(f),P=0;P<f;P++){var R=0;R|=i,R|=a<<4,R|=m<<8,R|=w<<12,R|=g<<16,D[P]=R}this._state.flagsBuf.setData(D,c,f)}}},{key:"_setDeferredFlags",value:function(){this._deferredFlagValues&&(this._state.flagsBuf.setData(this._deferredFlagValues),this._deferredFlagValues=null)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";if(this.model.scene.entityOffsetsEnabled){for(var n=e,r=this._portions[n],i=3*r.vertsBaseIndex,a=3*r.numVerts,s=this._scratchMemory.getFloat32Array(a),o=t[0],l=t[1],u=t[2],c=0;c<a;c+=3)s[c+0]=o,s[c+1]=l,s[c+2]=u;this._state.offsetsBuf&&this._state.offsetsBuf.setData(s,i,a),this.model.scene.pickSurfacePrecisionEnabled&&(r.offset[0]=t[0],r.offset[1]=t[1],r.offset[2]=t[2])}else this.model.error("Entity#offset not enabled for this Viewer")}},{key:"getEachVertex",value:function(e,t){if(this.model.scene.pickSurfacePrecisionEnabled){var n=this._state,r=this._portions[e];if(r)for(var i=r.quantizedPositions,a=n.origin,s=r.offset,o=a[0]+s[0],l=a[1]+s[1],u=a[2]+s[2],c=Ko,f=0,p=i.length;f<p;f+=3)c[0]=i[f],c[1]=i[f+1],c[2]=i[f+2],c[3]=1,Z.decompressPosition(c,n.positionsDecodeMatrix),Z.transformPoint4(this.model.worldMatrix,c),c[0]+=o,c[1]+=l,c[2]+=u,t(c);else this.model.error("portion not found: "+e)}}},{key:"getElementsCountAndOffset",value:function(e){var t=null,n=null,r=this._portions[e];return r&&(t=r.numIndices,n=r.indicesBaseIndex),{count:t,offset:n}}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.withSAO&&this.model.saoEnabled?t.pbrEnabled&&this.model.pbrEnabled&&this._state.pbrSupported?this._batchingRenderers.pbrRendererWithSAO&&this._batchingRenderers.pbrRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):t.colorTextureEnabled&&this.model.colorTextureEnabled&&this._state.colorTextureSupported?this._batchingRenderers.colorTextureRendererWithSAO&&this._batchingRenderers.colorTextureRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):this._state.normalsBuf?this._batchingRenderers.colorRendererWithSAO&&this._batchingRenderers.colorRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):this._batchingRenderers.flatColorRendererWithSAO&&this._batchingRenderers.flatColorRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):t.pbrEnabled&&this.model.pbrEnabled&&this._state.pbrSupported?this._batchingRenderers.pbrRenderer&&this._batchingRenderers.pbrRenderer.drawLayer(t,this,eo.COLOR_OPAQUE):t.colorTextureEnabled&&this.model.colorTextureEnabled&&this._state.colorTextureSupported?this._batchingRenderers.colorTextureRenderer&&this._batchingRenderers.colorTextureRenderer.drawLayer(t,this,eo.COLOR_OPAQUE):this._state.normalsBuf?this._batchingRenderers.colorRenderer&&this._batchingRenderers.colorRenderer.drawLayer(t,this,eo.COLOR_OPAQUE):this._batchingRenderers.flatColorRenderer&&this._batchingRenderers.flatColorRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"_updateBackfaceCull",value:function(e,t){var n=this.model.backfaces||!this.solid||e.sectioned;if(t.backfaces!==n){var r=t.gl;n?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),t.backfaces=n}}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.pbrEnabled&&this.model.pbrEnabled&&this._state.pbrSupported?this._batchingRenderers.pbrRenderer&&this._batchingRenderers.pbrRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT):t.colorTextureEnabled&&this.model.colorTextureEnabled&&this._state.colorTextureSupported?this._batchingRenderers.colorTextureRenderer&&this._batchingRenderers.colorTextureRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT):this._state.normalsBuf?this._batchingRenderers.colorRenderer&&this._batchingRenderers.colorRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT):this._batchingRenderers.flatColorRenderer&&this._batchingRenderers.flatColorRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT))}},{key:"drawDepth",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.depthRenderer&&this._batchingRenderers.depthRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.normalsRenderer&&this._batchingRenderers.normalsRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.silhouetteRenderer&&this._batchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_XRAYED))}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.silhouetteRenderer&&this._batchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_HIGHLIGHTED))}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.silhouetteRenderer&&this._batchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_SELECTED))}},{key:"drawEdgesColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._batchingRenderers.edgesColorRenderer&&this._batchingRenderers.edgesColorRenderer.drawLayer(t,this,eo.EDGES_COLOR_OPAQUE)}},{key:"drawEdgesColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&0!==this._numTransparentLayerPortions&&this._batchingRenderers.edgesColorRenderer&&this._batchingRenderers.edgesColorRenderer.drawLayer(t,this,eo.EDGES_COLOR_TRANSPARENT)}},{key:"drawEdgesHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._batchingRenderers.edgesRenderer&&this._batchingRenderers.edgesRenderer.drawLayer(t,this,eo.EDGES_HIGHLIGHTED)}},{key:"drawEdgesSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._batchingRenderers.edgesRenderer&&this._batchingRenderers.edgesRenderer.drawLayer(t,this,eo.EDGES_SELECTED)}},{key:"drawEdgesXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._batchingRenderers.edgesRenderer&&this._batchingRenderers.edgesRenderer.drawLayer(t,this,eo.EDGES_XRAYED)}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.occlusionRenderer&&this._batchingRenderers.occlusionRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawShadow",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.shadowRenderer&&this._batchingRenderers.shadowRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawPickMesh",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.pickMeshRenderer&&this._batchingRenderers.pickMeshRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.pickDepthRenderer&&this._batchingRenderers.pickDepthRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawPickNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._batchingRenderers.pickNormalsFlatRenderer&&this._batchingRenderers.pickNormalsFlatRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawSnapInitDepthBuf",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._snapBatchingRenderers.snapDepthBufInitRenderer&&this._snapBatchingRenderers.snapDepthBufInitRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawSnapDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._snapBatchingRenderers.snapDepthRenderer&&this._snapBatchingRenderers.snapDepthRenderer.drawLayer(t,this,eo.PICK))}},{key:"precisionRayPickSurface",value:function(e,t,n,r,i){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;var a=this._state,s=this._portions[e];if(!s)return this.model.error("portion not found: "+e),!1;var o=s.quantizedPositions,l=s.indices,u=a.origin,c=s.offset,f=Jo,p=Zo;f.set(u?Z.subVec3(t,u,$o):t),p.set(n),c&&Z.subVec3(f,c),Z.transformRay(this.model.worldNormalMatrix,f,p,f,p);for(var A=el,d=tl,v=nl,h=!1,I=0,y=rl,m=0,w=l.length;m<w;m+=3){var g=3*l[m],T=3*l[m+1],E=3*l[m+2];if(A[0]=o[g],A[1]=o[g+1],A[2]=o[g+2],d[0]=o[T],d[1]=o[T+1],d[2]=o[T+2],v[0]=o[E],v[1]=o[E+1],v[2]=o[E+2],Z.decompressPosition(A,a.positionsDecodeMatrix),Z.decompressPosition(d,a.positionsDecodeMatrix),Z.decompressPosition(v,a.positionsDecodeMatrix),Z.rayTriangleIntersect(f,p,A,d,v,y)){Z.transformPoint3(this.model.worldMatrix,y,y),c&&Z.addVec3(y,c),u&&Z.addVec3(y,u);var b=Math.abs(Z.lenVec3(Z.subVec3(y,t,[])));(!h||b>I)&&(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<t;e++)"ambient"!==(n=a.lights[e]).type&&(o.push("uniform vec4 lightColor"+e+";"),"dir"===n.type&&o.push("uniform vec3 lightDir"+e+";"),"point"===n.type&&o.push("uniform vec3 lightPos"+e+";"),"spot"===n.type&&(o.push("uniform vec3 lightPos"+e+";"),o.push("uniform vec3 lightDir"+e+";")));for(o.push("vec3 octDecode(vec2 oct) {"),o.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),o.push(" if (v.z < 0.0) {"),o.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);"),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;e<t;e++)if("ambient"!==(n=a.lights[e]).type){if("dir"===n.type)"view"===n.space?o.push("viewLightDir = normalize(lightDir"+e+");"):o.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+e+", 0.0)).xyz);");else if("point"===n.type)"view"===n.space?o.push("viewLightDir = -normalize(lightPos"+e+" - viewPosition.xyz);"):o.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+e+", 0.0)).xyz);");else{if("spot"!==n.type)continue;"view"===n.space?o.push("viewLightDir = normalize(lightDir"+e+");"):o.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+e+", 0.0)).xyz);")}o.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),o.push("reflectedColor += lambertian * (lightColor"+e+".rgb * lightColor"+e+".a);")}return o.push("vec3 rgb = (vec3(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0));"),o.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedColor * rgb), float(color.a) / 255.0);"),o.push("vec4 clipPos = projMatrix * viewPosition;"),r.logarithmicDepthBufferEnabled&&(o.push("vFragDepth = 1.0 + clipPos.w;"),o.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s&&(o.push("vWorldPosition = worldPosition;"),o.push("vFlags = flags;")),o.push("gl_Position = clipPos;"),o.push("}"),o.push("}"),o}},{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 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}}]),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<l;o++)s.push("uniform bool sectionPlaneActive"+o+";"),s.push("uniform vec3 sectionPlanePos"+o+";"),s.push("uniform vec3 sectionPlaneDir"+o+";")}for(this._addMatricesUniformBlockLines(s),s.push("uniform vec4 lightAmbient;"),e=0,t=i.lights.length;e<t;e++){var u=i.lights[e];"ambient"!==u.type&&(s.push("uniform vec4 lightColor"+e+";"),"dir"===u.type&&s.push("uniform vec3 lightDir"+e+";"),"point"===u.type&&s.push("uniform vec3 lightPos"+e+";"),"spot"===u.type&&(s.push("uniform vec3 lightPos"+e+";"),s.push("uniform vec3 lightDir"+e+";")))}if(s.push("in vec4 vViewPosition;"),s.push("in vec4 vColor;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),a){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var c=0,f=r.sectionPlanes.length;c<f;c++)s.push("if (sectionPlaneActive"+c+") {"),s.push(" dist += clamp(dot(-sectionPlaneDir"+c+".xyz, vWorldPosition.xyz - sectionPlanePos"+c+".xyz), 0.0, 1000.0);"),s.push("}");s.push(" if (dist > 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;e<t;e++){var p=i.lights[e];if("ambient"!==p.type){if("dir"===p.type)"view"===p.space?s.push("viewLightDir = normalize(lightDir"+e+");"):s.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+e+", 0.0)).xyz);");else if("point"===p.type)"view"===p.space?s.push("viewLightDir = -normalize(lightPos"+e+" - viewPosition.xyz);"):s.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+e+", 0.0)).xyz);");else{if("spot"!==p.type)continue;"view"===p.space?s.push("viewLightDir = normalize(lightDir"+e+");"):s.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+e+", 0.0)).xyz);")}s.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),s.push("reflectedColor += lambertian * (lightColor"+e+".rgb * lightColor"+e+".a);")}}return s.push("vec4 fragColor = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);"),this._withSAO?(s.push(" float viewportWidth = uSAOParams[0];"),s.push(" float viewportHeight = uSAOParams[1];"),s.push(" float blendCutoff = uSAOParams[2];"),s.push(" float blendFactor = uSAOParams[3];"),s.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),s.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),s.push(" outColor = vec4(fragColor.rgb * ambient, 1.0);")):s.push(" outColor = fragColor;"),n.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),n}(),ol=function(e){I(n,lo);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("// 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vPickColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vViewPosition;"),r.push("vec4 packDepth(const in float depth) {"),r.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),r.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),r.push(" vec4 res = fract(depth * bitShift);"),r.push(" res -= res.xxyz * bitMask;"),r.push(" return res;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vWorldNormal;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return 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<t;e++)a.push("uniform bool sectionPlaneActive"+e+";"),a.push("uniform vec3 sectionPlanePos"+e+";"),a.push("uniform vec3 sectionPlaneDir"+e+";");if(a.push("in vec2 vHighPrecisionZW;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),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<t;e++)a.push("if (sectionPlaneActive"+e+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+e+".xyz, vWorldPosition.xyz - sectionPlanePos"+e+".xyz), 0.0, 1000.0);"),a.push("}");a.push("if (dist > 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vViewNormal;"),r.push("vec3 packNormalToRGB( const in vec3 normal ) {"),r.push(" return normalize( normal ) * 0.5 + 0.5;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vViewNormal;"),r.push("vec3 packNormalToRGB( const in vec3 normal ) {"),r.push(" return normalize( normal ) * 0.5 + 0.5;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = 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;o<l;o++){var u=r.lights[o];"ambient"!==u.type&&(s.push("uniform vec4 lightColor"+o+";"),"dir"===u.type&&s.push("uniform vec3 lightDir"+o+";"),"point"===u.type&&s.push("uniform vec3 lightPos"+o+";"),"spot"===u.type&&(s.push("uniform vec3 lightPos"+o+";"),s.push("uniform vec3 lightDir"+o+";")))}if(s.push("uniform float gammaFactor;"),s.push("vec4 linearToLinear( in vec4 value ) {"),s.push(" return value;"),s.push("}"),s.push("vec4 sRGBToLinear( in vec4 value ) {"),s.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 );"),s.push("}"),s.push("vec4 gammaToLinear( in vec4 value) {"),s.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),s.push("}"),t&&(s.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),s.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),s.push("}")),i){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;"),a&&s.push("in vec4 vClipPosition;");for(var c=0,f=n.sectionPlanes.length;c<f;c++)s.push("uniform bool sectionPlaneActive"+c+";"),s.push("uniform vec3 sectionPlanePos"+c+";"),s.push("uniform vec3 sectionPlaneDir"+c+";")}if(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),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<A;p++)s.push("if (sectionPlaneActive"+p+") {"),s.push(" dist += clamp(dot(-sectionPlaneDir"+p+".xyz, vWorldPosition.xyz - sectionPlanePos"+p+".xyz), 0.0, 1000.0);"),s.push("}");a?(s.push(" if (dist > (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;d<v;d++){var h=r.lights[d];if("ambient"!==h.type){if("dir"===h.type)"view"===h.space?s.push("light.direction = normalize(lightDir"+d+");"):s.push("light.direction = normalize((viewMatrix * vec4(lightDir"+d+", 0.0)).xyz);");else if("point"===h.type)"view"===h.space?s.push("light.direction = normalize(lightPos"+d+" - vViewPosition.xyz);"):s.push("light.direction = normalize((viewMatrix * vec4(lightPos"+d+", 0.0)).xyz);");else{if("spot"!==h.type)continue;"view"===h.space?s.push("light.direction = normalize(lightDir"+d+");"):s.push("light.direction = normalize((viewMatrix * vec4(lightDir"+d+", 0.0)).xyz);")}s.push("light.color = lightColor"+d+".rgb * lightColor"+d+".a;"),s.push("computePBRLighting(light, geometry, material, reflectedLight);")}}return s.push("vec3 emissiveColor = sRGBToLinear(texture(uEmissiveMap, vUV)).rgb;"),s.push("vec3 outgoingLight = (lightAmbient.rgb * lightAmbient.a * baseColor * opacity * rgb) + (reflectedLight.diffuse) + (reflectedLight.specular) + emissiveColor;"),s.push("vec4 fragColor;"),this._withSAO?(s.push(" float viewportWidth = uSAOParams[0];"),s.push(" float viewportHeight = uSAOParams[1];"),s.push(" float blendCutoff = uSAOParams[2];"),s.push(" float blendFactor = uSAOParams[3];"),s.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),s.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),s.push(" fragColor = vec4(outgoingLight.rgb * ambient, opacity);")):s.push(" fragColor = vec4(outgoingLight.rgb, opacity);"),t&&s.push("fragColor = linearToGamma(fragColor, gammaFactor);"),s.push("outColor = fragColor;"),e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("}"),s}}]),n}(),ml=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 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vWorldNormal;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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<u;l++)o.push("uniform bool sectionPlaneActive"+l+";"),o.push("uniform vec3 sectionPlanePos"+l+";"),o.push("uniform vec3 sectionPlaneDir"+l+";")}for(this._addMatricesUniformBlockLines(o),o.push("uniform vec4 lightAmbient;"),e=0,t=a.lights.length;e<t;e++){var c=a.lights[e];"ambient"!==c.type&&(o.push("uniform vec4 lightColor"+e+";"),"dir"===c.type&&o.push("uniform vec3 lightDir"+e+";"),"point"===c.type&&o.push("uniform vec3 lightPos"+e+";"),"spot"===c.type&&(o.push("uniform vec3 lightPos"+e+";"),o.push("uniform vec3 lightDir"+e+";")))}if(o.push("in vec4 vViewPosition;"),o.push("in vec4 vColor;"),o.push("in vec2 vUV;"),o.push("out vec4 outColor;"),o.push("void main(void) {"),s){o.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),o.push(" if (clippable) {"),o.push(" float dist = 0.0;");for(var f=0,p=i.sectionPlanes.length;f<p;f++)o.push("if (sectionPlaneActive"+f+") {"),o.push(" dist += clamp(dot(-sectionPlaneDir"+f+".xyz, vWorldPosition.xyz - sectionPlanePos"+f+".xyz), 0.0, 1000.0);"),o.push("}");o.push(" if (dist > 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;e<t;e++){var A=a.lights[e];if("ambient"!==A.type){if("dir"===A.type)"view"===A.space?o.push("viewLightDir = normalize(lightDir"+e+");"):o.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+e+", 0.0)).xyz);");else if("point"===A.type)"view"===A.space?o.push("viewLightDir = -normalize(lightPos"+e+" - viewPosition.xyz);"):o.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+e+", 0.0)).xyz);");else{if("spot"!==A.type)continue;"view"===A.space?o.push("viewLightDir = normalize(lightDir"+e+");"):o.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+e+", 0.0)).xyz);")}o.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),o.push("reflectedColor += lambertian * (lightColor"+e+".rgb * lightColor"+e+".a);")}}return o.push("vec4 color = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);"),r?o.push("vec4 colorTexel = color * sRGBToLinear(texture(uColorMap, vUV));"):o.push("vec4 colorTexel = color * texture(uColorMap, vUV);"),o.push("float opacity = color.a;"),this._withSAO?(o.push(" float viewportWidth = uSAOParams[0];"),o.push(" float viewportHeight = uSAOParams[1];"),o.push(" float blendCutoff = uSAOParams[2];"),o.push(" float blendFactor = uSAOParams[3];"),o.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),o.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),o.push(" outColor = vec4(vColor.rgb * colorTexel.rgb * ambient, opacity);")):o.push(" outColor = vec4(vColor.rgb * colorTexel.rgb, opacity);"),r&&o.push("outColor = linearToGamma(outColor, gammaFactor);"),n.logarithmicDepthBufferEnabled&&o.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),o.push("}"),o}}]),n}(),gl=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._pbrRenderer&&!this._pbrRenderer.getValid()&&(this._pbrRenderer.destroy(),this._pbrRenderer=null),this._pbrRendererWithSAO&&!this._pbrRendererWithSAO.getValid()&&(this._pbrRendererWithSAO.destroy(),this._pbrRendererWithSAO=null),this._colorTextureRenderer&&!this._colorTextureRenderer.getValid()&&(this._colorTextureRenderer.destroy(),this._colorTextureRenderer=null),this._colorTextureRendererWithSAO&&!this._colorTextureRendererWithSAO.getValid()&&(this._colorTextureRendererWithSAO.destroy(),this._colorTextureRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=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 al(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new al(this._scene,!0)),this._colorRendererWithSAO}},{key:"flatColorRenderer",get:function(){return this._flatColorRenderer||(this._flatColorRenderer=new sl(this._scene,!1)),this._flatColorRenderer}},{key:"flatColorRendererWithSAO",get:function(){return this._flatColorRendererWithSAO||(this._flatColorRendererWithSAO=new sl(this._scene,!0)),this._flatColorRendererWithSAO}},{key:"pbrRenderer",get:function(){return this._pbrRenderer||(this._pbrRenderer=new yl(this._scene,!1)),this._pbrRenderer}},{key:"pbrRendererWithSAO",get:function(){return this._pbrRendererWithSAO||(this._pbrRendererWithSAO=new yl(this._scene,!0)),this._pbrRendererWithSAO}},{key:"colorTextureRenderer",get:function(){return this._colorTextureRenderer||(this._colorTextureRenderer=new wl(this._scene,!1)),this._colorTextureRenderer}},{key:"colorTextureRendererWithSAO",get:function(){return this._colorTextureRendererWithSAO||(this._colorTextureRendererWithSAO=new wl(this._scene,!0)),this._colorTextureRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ol(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new dl(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new vl(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new ll(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new ul(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new cl(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new pl(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new ml(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new fl(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Al(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new hl(this._scene)),this._shadowRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._pbrRenderer&&this._pbrRenderer.destroy(),this._pbrRendererWithSAO&&this._pbrRendererWithSAO.destroy(),this._colorTextureRenderer&&this._colorTextureRenderer.destroy(),this._colorTextureRendererWithSAO&&this._colorTextureRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}]),e}(),Tl={};var El=Z.vec3(),bl=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(),!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;w<h;w++){var g=this._uSectionPlanes[w];if(g){var T=m.sectionPlanesActivePerLayer[y+w];if(a.uniform1i(g.active,T?1:0),T){var E=I[w];if(o){var b=ge(E.dist,E.dir,o,El);a.uniform3fv(g.pos,b)}else a.uniform3fv(g.pos,E.pos);a.uniform3fv(g.dir,E.dir)}}}a.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,s.positionsDecodeMatrix),this._aModelMatrixCol0.bindArrayBuffer(s.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(s.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(s.modelMatrixCol2Buf),a.vertexAttribDivisor(this._aModelMatrixCol0.location,1),a.vertexAttribDivisor(this._aModelMatrixCol1.location,1),a.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aPosition.bindArrayBuffer(s.positionsBuf),this._aFlags&&(this._aFlags.bindArrayBuffer(s.flagsBuf),a.vertexAttribDivisor(this._aFlags.location,1)),this._aOffset&&(this._aOffset.bindArrayBuffer(s.offsetsBuf),a.vertexAttribDivisor(this._aOffset.location,1)),s.indicesBuf.bind(),a.drawElementsInstanced(a.TRIANGLES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),s.indicesBuf.unbind(),a.vertexAttribDivisor(this._aModelMatrixCol0.location,0),a.vertexAttribDivisor(this._aModelMatrixCol1.location,0),a.vertexAttribDivisor(this._aModelMatrixCol2.location,0),this._aFlags&&a.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&a.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new ft(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._aPosition=n.getAttribute("position"),this._aOffset=n.getAttribute("offset"),this._aFlags=n.getAttribute("flags"),this._aModelMatrixCol0=n.getAttribute("modelMatrixCol0"),this._aModelMatrixCol1=n.getAttribute("modelMatrixCol1"),this._aModelMatrixCol2=n.getAttribute("modelMatrixCol2"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc"),this.uVectorA=n.getLocation("snapVectorA"),this.uInverseVectorAB=n.getLocation("snapInvVectorAB"),this._uLayerNumber=n.getLocation("layerNumber"),this._uCoordinateScaler=n.getLocation("coordinateScaler")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in highp vec3 relativeToOriginPosition;"),r.push("out highp ivec4 outCoords;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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;w<h;w++){var g=this._uSectionPlanes[w];if(g){var T=m.sectionPlanesActivePerLayer[y+w];if(a.uniform1i(g.active,T?1:0),T){var E=I[w];if(o){var b=ge(E.dist,E.dir,o,Dl);a.uniform3fv(g.pos,b)}else a.uniform3fv(g.pos,E.pos);a.uniform3fv(g.dir,E.dir)}}}a.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,s.positionsDecodeMatrix),this._aModelMatrixCol0.bindArrayBuffer(s.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(s.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(s.modelMatrixCol2Buf),a.vertexAttribDivisor(this._aModelMatrixCol0.location,1),a.vertexAttribDivisor(this._aModelMatrixCol1.location,1),a.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aPosition.bindArrayBuffer(s.positionsBuf),this._aFlags.bindArrayBuffer(s.flagsBuf),a.vertexAttribDivisor(this._aFlags.location,1),this._aOffset&&(this._aOffset.bindArrayBuffer(s.offsetsBuf),a.vertexAttribDivisor(this._aOffset.location,1)),"edge"===e.snapMode?(s.edgeIndicesBuf.bind(),a.drawElementsInstanced(a.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0,s.numInstances),s.edgeIndicesBuf.unbind()):a.drawArraysInstanced(a.POINTS,0,s.positionsBuf.numItems,s.numInstances),a.vertexAttribDivisor(this._aModelMatrixCol0.location,0),a.vertexAttribDivisor(this._aModelMatrixCol1.location,0),a.vertexAttribDivisor(this._aModelMatrixCol2.location,0),a.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&a.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new ft(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._aPosition=n.getAttribute("position"),this._aOffset=n.getAttribute("offset"),this._aFlags=n.getAttribute("flags"),this._aModelMatrixCol0=n.getAttribute("modelMatrixCol0"),this._aModelMatrixCol1=n.getAttribute("modelMatrixCol1"),this._aModelMatrixCol2=n.getAttribute("modelMatrixCol2"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc"),this.uVectorA=n.getLocation("snapVectorA"),this.uInverseVectorAB=n.getLocation("snapInvVectorAB"),this._uLayerNumber=n.getLocation("layerNumber"),this._uCoordinateScaler=n.getLocation("coordinateScaler")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in highp vec3 relativeToOriginPosition;"),r.push("out highp ivec4 outCoords;"),r.push("void main(void) {"),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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;I<d;I+=3)Ol[0]=v[I+0],Ol[1]=v[I+1],Ol[2]=v[I+2],Z.transformPoint4(h,Ol,Sl),Z.transformPoint4(a,Sl,Ol),s?(Z.transformPoint4(s,Ol,Nl),Z.expandAABB3Point3(o,Nl)):Z.expandAABB3Point3(o,Ol);if(this._state.origin){var y=this._state.origin;o[0]+=y[0],o[1]+=y[1],o[2]+=y[2],o[3]+=y[0],o[4]+=y[1],o[5]+=y[2]}Z.expandAABB3(this.aabb,o),this._state.numInstances++;var m=this._portions.length,w={};return this.model.scene.pickSurfacePrecisionEnabled&&(w.matrix=a.slice(),w.inverseMatrix=null,w.normalMatrix=null),this._portions.push(w),this._numPortions++,this.model.numPortions++,m}},{key:"finalize",value:function(){if(!this._finalized){var e=this._state,t=e.geometry,n=e.textureSet,r=this.model.scene.canvas.gl,i=this._colors.length,a=i/4;if(i>0){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;v<h;v+=3)f[0]=a[v],f[1]=a[v+1],f[2]=a[v+2],Z.decompressPosition(f,d),Z.transformPoint3(p,f),Z.transformPoint3(A,f),f[0]+=l,f[1]+=u,f[2]+=c,t(f);else this.model.error("portion not found: "+e)}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.withSAO&&this.model.saoEnabled?t.pbrEnabled&&this.model.pbrEnabled&&this._state.pbrSupported?this._instancingRenderers.pbrRendererWithSAO&&this._instancingRenderers.pbrRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):t.colorTextureEnabled&&this.model.colorTextureEnabled&&this._state.colorTextureSupported?this._instancingRenderers.colorTextureRendererWithSAO&&this._instancingRenderers.colorTextureRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):this._state.normalsBuf?this._instancingRenderers.colorRendererWithSAO&&this._instancingRenderers.colorRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):this._instancingRenderers.flatColorRendererWithSAO&&this._instancingRenderers.flatColorRendererWithSAO.drawLayer(t,this,eo.COLOR_OPAQUE):t.pbrEnabled&&this.model.pbrEnabled&&this._state.pbrSupported?this._instancingRenderers.pbrRenderer&&this._instancingRenderers.pbrRenderer.drawLayer(t,this,eo.COLOR_OPAQUE):t.colorTextureEnabled&&this.model.colorTextureEnabled&&this._state.colorTextureSupported?this._instancingRenderers.colorTextureRenderer&&this._instancingRenderers.colorTextureRenderer.drawLayer(t,this,eo.COLOR_OPAQUE):this._state.normalsBuf?this._instancingRenderers.colorRenderer&&this._instancingRenderers.colorRenderer.drawLayer(t,this,eo.COLOR_OPAQUE):this._instancingRenderers.flatColorRenderer&&this._instancingRenderers.flatColorRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"_updateBackfaceCull",value:function(e,t){var n=this.model.backfaces||!this.solid||e.sectioned;if(t.backfaces!==n){var r=t.gl;n?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),t.backfaces=n}}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.pbrEnabled&&this.model.pbrEnabled&&this._state.pbrSupported?this._instancingRenderers.pbrRenderer&&this._instancingRenderers.pbrRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT):t.colorTextureEnabled&&this.model.colorTextureEnabled&&this._state.colorTextureSupported?this._instancingRenderers.colorTextureRenderer&&this._instancingRenderers.colorTextureRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT):this._state.normalsBuf?this._instancingRenderers.colorRenderer&&this._instancingRenderers.colorRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT):this._instancingRenderers.flatColorRenderer&&this._instancingRenderers.flatColorRenderer.drawLayer(t,this,eo.COLOR_TRANSPARENT))}},{key:"drawDepth",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.depthRenderer&&this._instancingRenderers.depthRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.normalsRenderer&&this._instancingRenderers.normalsRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.silhouetteRenderer&&this._instancingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_XRAYED))}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.silhouetteRenderer&&this._instancingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_HIGHLIGHTED))}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.silhouetteRenderer&&this._instancingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_SELECTED))}},{key:"drawEdgesColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._instancingRenderers.edgesColorRenderer&&this._instancingRenderers.edgesColorRenderer.drawLayer(t,this,eo.EDGES_COLOR_OPAQUE)}},{key:"drawEdgesColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._instancingRenderers.edgesColorRenderer&&this._instancingRenderers.edgesColorRenderer.drawLayer(t,this,eo.EDGES_COLOR_TRANSPARENT)}},{key:"drawEdgesXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._instancingRenderers.edgesRenderer&&this._instancingRenderers.edgesRenderer.drawLayer(t,this,eo.EDGES_XRAYED)}},{key:"drawEdgesHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._instancingRenderers.edgesRenderer&&this._instancingRenderers.edgesRenderer.drawLayer(t,this,eo.EDGES_HIGHLIGHTED)}},{key:"drawEdgesSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._instancingRenderers.edgesRenderer&&this._instancingRenderers.edgesRenderer.drawLayer(t,this,eo.EDGES_SELECTED)}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.occlusionRenderer&&this._instancingRenderers.occlusionRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawShadow",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.shadowRenderer&&this._instancingRenderers.shadowRenderer.drawLayer(t,this,eo.COLOR_OPAQUE))}},{key:"drawPickMesh",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.pickMeshRenderer&&this._instancingRenderers.pickMeshRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.pickDepthRenderer&&this._instancingRenderers.pickDepthRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawPickNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._instancingRenderers.pickNormalsRenderer&&this._instancingRenderers.pickNormalsRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawSnapInitDepthBuf",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._snapInstancingRenderers.snapDepthBufInitRenderer&&this._snapInstancingRenderers.snapDepthBufInitRenderer.drawLayer(t,this,eo.PICK))}},{key:"drawSnapDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._snapInstancingRenderers.snapDepthRenderer&&this._snapInstancingRenderers.snapDepthRenderer.drawLayer(t,this,eo.PICK))}},{key:"precisionRayPickSurface",value:function(e,t,n,r,i){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;var a=this._state.geometry,s=this._state,o=this._portions[e];if(!o)return this.model.error("portion not found: "+e),!1;o.inverseMatrix||(o.inverseMatrix=Z.inverseMat4(o.matrix,Z.mat4())),i&&!o.normalMatrix&&(o.normalMatrix=Z.transposeMat4(o.inverseMatrix,Z.mat4()));var l=a.quantizedPositions,u=a.indices,c=s.origin,f=o.offset,p=xl,A=Ml;p.set(c?Z.subVec3(t,c,Fl):t),A.set(n),f&&Z.subVec3(p,f),Z.transformRay(this.model.worldNormalMatrix,p,A,p,A),Z.transformRay(o.inverseMatrix,p,A,p,A);for(var d=Hl,v=Ul,h=Gl,I=!1,y=0,m=kl,w=0,g=u.length;w<g;w+=3){var T=3*u[w+0],E=3*u[w+1],b=3*u[w+2];d[0]=l[T],d[1]=l[T+1],d[2]=l[T+2],v[0]=l[E],v[1]=l[E+1],v[2]=l[E+2],h[0]=l[b],h[1]=l[b+1],h[2]=l[b+2];var D=s.geometry.positionsDecodeMatrix;if(Z.decompressPosition(d,D),Z.decompressPosition(v,D),Z.decompressPosition(h,D),Z.rayTriangleIntersect(p,A,d,v,h,m)){Z.transformPoint3(o.matrix,m,m),Z.transformPoint3(this.model.worldMatrix,m,m),f&&Z.addVec3(m,f),c&&Z.addVec3(m,c);var P=Math.abs(Z.lenVec3(Z.subVec3(m,t,[])));(!I||P>y)&&(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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("uniform vec4 color;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = 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+t<this._buffer.maxIndices}},{key:"createPortion",value:function(e){if(this._finalized)throw"Already finalized";var t=e.positions,n=e.positionsCompressed,r=e.indices,i=e.color,a=e.opacity,s=e.meshMatrix,o=e.worldMatrix,l=e.worldAABB;e.pickColor;var u,c=this._buffer,f=c.positions.length/3;if(this._preCompressedPositionsExpected){if(!n)throw"positionsCompressed expected";u=n.length/3;for(var p=0,A=n.length;p<A;p++)c.positions.push(n[p]);var d=pn.getPositionsBounds(n),v=pn.decompressPosition(d.min,this._state.positionsDecodeMatrix,[]),h=pn.decompressPosition(d.max,this._state.positionsDecodeMatrix,[]);l[0]=v[0],l[1]=v[1],l[2]=v[2],l[3]=h[0],l[4]=h[1],l[5]=h[2],o&&(Z.AABB3ToOBB3(l,Jl),Z.transformOBB3(o,Jl),Z.OBB3ToAABB3(Jl,l))}else{if(!t)throw"positions expected";u=t.length/3;for(var I=t.length,y=c.positions.length,m=0,w=t.length;m<w;m++)c.positions.push(t[m]);if(s)for(var g=y,T=y+I;g<T;g+=3)Yl[0]=c.positions[g+0],Yl[1]=c.positions[g+1],Yl[2]=c.positions[g+2],Z.transformPoint4(s,Yl,Xl),c.positions[g+0]=Xl[0],c.positions[g+1]=Xl[1],c.positions[g+2]=Xl[2],Z.expandAABB3Point3(this._modelAABB,Xl),o?(Z.transformPoint4(o,Xl,ql),Z.expandAABB3Point3(l,ql)):Z.expandAABB3Point3(l,Xl);else for(var E=y,b=y+I;E<b;E+=3)Yl[0]=c.positions[E+0],Yl[1]=c.positions[E+1],Yl[2]=c.positions[E+2],Z.expandAABB3Point3(this._modelAABB,Yl),o?(Z.transformPoint4(o,Yl,Xl),Z.expandAABB3Point3(l,Xl)):Z.expandAABB3Point3(l,Yl)}if(this._state.origin){var D=this._state.origin;l[0]+=D[0],l[1]+=D[1],l[2]+=D[2],l[3]+=D[0],l[4]+=D[1],l[5]+=D[2]}if(Z.expandAABB3(this.aabb,l),i)for(var P=i[0],R=i[1],C=i[2],_=a,B=0;B<u;B++)c.colors.push(P),c.colors.push(R),c.colors.push(C),c.colors.push(_);if(r)for(var O=0,S=r.length;O<S;O++)c.indices.push(r[O]+f);if(this.model.scene.entityOffsetsEnabled)for(var N=0;N<u;N++)c.offsets.push(0),c.offsets.push(0),c.offsets.push(0);var L=this._portions.length/2;return this._portions.push(f),this._portions.push(u),this._numPortions++,this.model.numPortions++,this._numVerts+=u,L}},{key:"finalize",value:function(){if(!this._finalized){var e=this._state,t=this.model.scene.canvas.gl,n=this._buffer;if(n.positions.length>0)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;c<i;c+=4)a[c+0]=s,a[c+1]=o,a[c+2]=l,a[c+3]=u;this._state.colorsBuf.setData(a,r,i)}},{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){var r=arguments.length>3&&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;m<w;m++){var g=0;g|=i,g|=a<<4,g|=I<<12,g|=y<<16,this._deferredFlagValues[m]=g}}else if(this._state.flagsBuf){for(var T=this._scratchMemory.getFloat32Array(c),E=0;E<c;E++){var b=0;b|=i,b|=a<<4,b|=I<<12,b|=y<<16,T[E]=b}this._state.flagsBuf.setData(T,u,c)}}},{key:"_setDeferredFlags",value:function(){this._deferredFlagValues&&(this._state.flagsBuf.setData(this._deferredFlagValues),this._deferredFlagValues=null)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";if(this.model.scene.entityOffsetsEnabled){for(var n=2*e,r=3*this._portions[n],i=3*this._portions[n+1],a=this._scratchMemory.getFloat32Array(i),s=t[0],o=t[1],l=t[2],u=0;u<i;u+=3)a[u+0]=s,a[u+1]=o,a[u+2]=l;this._state.offsetsBuf.setData(a,r,i)}else 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._batchingRenderers.colorRenderer&&this._batchingRenderers.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._batchingRenderers.colorRenderer&&this._batchingRenderers.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._batchingRenderers.silhouetteRenderer&&this._batchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._batchingRenderers.silhouetteRenderer&&this._batchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._batchingRenderers.silhouetteRenderer&&this._batchingRenderers.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:"drawPickMesh",value:function(e){}},{key:"drawPickDepths",value:function(e){}},{key:"drawPickNormals",value:function(e){}},{key:"drawOcclusion",value:function(e){}},{key:"drawShadow",value:function(e){}},{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.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicesBuf=null),e.destroy()}}]),e}(),$l=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,{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 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<t;e++)a.push("uniform bool sectionPlaneActive"+e+";"),a.push("uniform vec3 sectionPlanePos"+e+";"),a.push("uniform vec3 sectionPlaneDir"+e+";");if(a.push("in vec4 vColor;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),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<t;e++)a.push("if (sectionPlaneActive"+e+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+e+".xyz, vWorldPosition.xyz - sectionPlanePos"+e+".xyz), 0.0, 1000.0);"),a.push("}");a.push("if (dist > 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("uniform vec4 color;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = 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;f<c;f+=4)au[0]=u[f+0],au[1]=u[f+1],au[2]=u[f+2],Z.transformPoint4(r,au,su),i?(Z.transformPoint4(i,su,ou),Z.expandAABB3Point3(a,ou)):Z.expandAABB3Point3(a,su);if(this._state.origin){var p=this._state.origin;a[0]+=p[0],a[1]+=p[1],a[2]+=p[2],a[3]+=p[0],a[4]+=p[1],a[5]+=p[2]}Z.expandAABB3(this.aabb,a),this._state.numInstances++;var A=this._portions.length;return this._portions.push({}),this._numPortions++,this.model.numPortions++,A}},{key:"finalize",value:function(){if(this._finalized)throw"Already finalized";var e=this.model.scene.canvas.gl,t=this._colors.length,n=t/4;if(t>0){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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 0.0) { discard; }"),r.push("}")}return 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<t;e++)a.push("uniform bool sectionPlaneActive"+e+";"),a.push("uniform vec3 sectionPlanePos"+e+";"),a.push("uniform vec3 sectionPlaneDir"+e+";");if(a.push("uniform vec4 color;"),a.push("out vec4 outColor;"),a.push("void main(void) {"),n.pointsMaterial.roundPoints&&(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(" }")),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<t;e++)a.push("if (sectionPlaneActive"+e+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+e+".xyz, vWorldPosition.xyz - sectionPlanePos"+e+".xyz), 0.0, 1000.0);"),a.push("}");a.push(" if (dist > 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vPickColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vViewPosition;"),r.push("vec4 packDepth(const in float depth) {"),r.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),r.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),r.push(" vec4 res = fract(depth * bitShift);"),r.push(" res -= res.xxyz * bitMask;"),r.push(" return res;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&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;A<d;A++)f.positions.push(r[A]);var v=pn.getPositionsBounds(r),h=pn.decompressPosition(v.min,this._state.positionsDecodeMatrix,yu),I=pn.decompressPosition(v.max,this._state.positionsDecodeMatrix,mu);u[0]=h[0],u[1]=h[1],u[2]=h[2],u[3]=I[0],u[4]=I[1],u[5]=I[2],l&&(Z.AABB3ToOBB3(u,Eu),Z.transformOBB3(l,Eu),Z.OBB3ToAABB3(Eu,u)),t=r.length/3}else{if(!n)throw"positions expected";t=n.length/3;for(var y=n.length,m=f.positions.length,w=0,g=n.length;w<g;w++)f.positions.push(n[w]);if(o)for(var T=m,E=m+y;T<E;T+=3)wu[0]=f.positions[T+0],wu[1]=f.positions[T+1],wu[2]=f.positions[T+2],Z.transformPoint4(o,wu,gu),f.positions[T+0]=gu[0],f.positions[T+1]=gu[1],f.positions[T+2]=gu[2],Z.expandAABB3Point3(this._modelAABB,gu),l?(Z.transformPoint4(l,gu,Tu),Z.expandAABB3Point3(u,Tu)):Z.expandAABB3Point3(u,gu);else for(var b=m,D=m+y;b<D;b+=3)wu[0]=f.positions[b+0],wu[1]=f.positions[b+1],wu[2]=f.positions[b+2],Z.expandAABB3Point3(this._modelAABB,wu),l?(Z.transformPoint4(l,wu,gu),Z.expandAABB3Point3(u,gu)):Z.expandAABB3Point3(u,wu)}if(this._state.origin){var P=this._state.origin;u[0]+=P[0],u[1]+=P[1],u[2]+=P[2],u[3]+=P[0],u[4]+=P[1],u[5]+=P[2]}if(Z.expandAABB3(this.aabb,u),a)for(var R=0,C=a.length;R<C;R++)f.colors.push(a[R]);else if(s)for(var _=0,B=s.length;_<B;_++)f.colors.push(255*s[_]);else if(i)for(var O=i[0],S=i[1],N=i[2],L=0;L<t;L++)f.colors.push(O),f.colors.push(S),f.colors.push(N),f.colors.push(1);for(var x=f.pickColors.length,M=x,F=x+4*t;M<F;M+=4)f.pickColors.push(c[0]),f.pickColors.push(c[1]),f.pickColors.push(c[2]),f.pickColors.push(c[3]);if(this.model.scene.entityOffsetsEnabled)for(var H=0;H<t;H++)f.offsets.push(0),f.offsets.push(0),f.offsets.push(0);var U=this._portions.length/2;return this._portions.push(p),this._portions.push(t),this._numPortions++,this.model.numPortions++,U}},{key:"finalize",value:function(){if(!this._finalized){var e=this._state,t=this.model.scene.canvas.gl,n=this._buffer;if(n.positions.length>0)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;u<i;u+=4)a[u+0]=s,a[u+1]=o,a[u+2]=l;this._state.colorsBuf.setData(a,r,i)}},{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,i,a=2*e,s=this._portions[a],o=this._portions[a+1],l=this._scratchMemory.getFloat32Array(o),u=!!(t&Te),c=!!(t&Re),f=!!(t&Ce),p=!!(t&_e),A=!!(t&be),d=!!(t&Ee);r=!u||d||c||f&&!this.model.scene.highlightMaterial.glowThrough||p&&!this.model.scene.selectedMaterial.glowThrough?eo.NOT_RENDERED:n?eo.COLOR_TRANSPARENT:eo.COLOR_OPAQUE,i=!u||d?eo.NOT_RENDERED:p?eo.SILHOUETTE_SELECTED:f?eo.SILHOUETTE_HIGHLIGHTED:c?eo.SILHOUETTE_XRAYED:eo.NOT_RENDERED;for(var v=u&&!d&&A?eo.PICK:eo.NOT_RENDERED,h=t&De?1:0,I=0;I<o;I++){var y=0;y|=r,y|=i<<4,y|=v<<12,y|=h<<16,l[I]=y}this._state.flagsBuf.setData(l,s)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";if(this.model.scene.entityOffsetsEnabled){for(var n=2*e,r=3*this._portions[n],i=3*this._portions[n+1],a=this._scratchMemory.getFloat32Array(i),s=t[0],o=t[1],l=t[2],u=0;u<i;u+=3)a[u+0]=s,a[u+1]=o,a[u+2]=l;this._state.offsetsBuf.setData(a,r,i)}else 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._pointsBatchingRenderers.colorRenderer&&this._pointsBatchingRenderers.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._pointsBatchingRenderers.colorRenderer&&this._pointsBatchingRenderers.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._pointsBatchingRenderers.silhouetteRenderer&&this._pointsBatchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsBatchingRenderers.silhouetteRenderer&&this._pointsBatchingRenderers.silhouetteRenderer.drawLayer(t,this,eo.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsBatchingRenderers.silhouetteRenderer&&this._pointsBatchingRenderers.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:"drawPickMesh",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsBatchingRenderers.pickMeshRenderer&&this._pointsBatchingRenderers.pickMeshRenderer.drawLayer(t,this,eo.PICK)}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsBatchingRenderers.pickDepthRenderer&&this._pointsBatchingRenderers.pickDepthRenderer.drawLayer(t,this,eo.PICK)}},{key:"drawPickNormals",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsBatchingRenderers.occlusionRenderer&&this._pointsBatchingRenderers.occlusionRenderer.drawLayer(t,this,eo.COLOR_OPAQUE)}},{key:"drawShadow",value:function(e,t){}},{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.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}]),e}(),Du=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,{incrementDrawState:!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 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = 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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vPickColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vViewPosition;"),r.push("vec4 packDepth(const in float depth) {"),r.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),r.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),r.push(" vec4 res = fract(depth * bitShift);"),r.push(" res -= res.xxyz * bitMask;"),r.push(" return res;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&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<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("out vec4 outColor;"),r.push("void main(void) {"),e.pointsMaterial.roundPoints&&(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(" }")),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<t.sectionPlanes.length;a++)r.push("if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return 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<t;e++)a.push("uniform bool sectionPlaneActive"+e+";"),a.push("uniform vec3 sectionPlanePos"+e+";"),a.push("uniform vec3 sectionPlaneDir"+e+";");if(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("const float shiftRight8 = 1.0 / 256.;"),a.push("vec4 packDepthToRGBA( const in float v ) {"),a.push(" vec4 r = vec4( fract( v * packFactors ), v );"),a.push(" r.yzw -= r.xyz * shiftRight8;"),a.push(" return r * packUpScale;"),a.push("}"),a.push("out vec4 outColor;"),a.push("void main(void) {"),n.pointsMaterial.roundPoints&&(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(" }")),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<t;e++)a.push("if (sectionPlaneActive"+e+") {"),a.push(" dist += clamp(dot(-sectionPlaneDir"+e+".xyz, vWorldPosition.xyz - sectionPlanePos"+e+".xyz), 0.0, 1000.0);"),a.push("}");a.push("if (dist > 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<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vViewNormal;"),r.push("vec3 packNormalToRGB( const in vec3 normal ) {"),r.push(" return normalize( normal ) * 0.5 + 0.5;"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),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(" }"),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<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push("if (dist > 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = 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;o<s;o+=4)Mu[0]=a[o+0],Mu[1]=a[o+1],Mu[2]=a[o+2],Z.transformPoint4(t,Mu,Fu),n?(Z.transformPoint4(n,Fu,Hu),Z.expandAABB3Point3(r,Hu)):Z.expandAABB3Point3(r,Fu);if(this._state.origin){var l=this._state.origin;r[0]+=l[0],r[1]+=l[1],r[2]+=l[2],r[3]+=l[0],r[4]+=l[1],r[5]+=l[2]}Z.expandAABB3(this.aabb,r),this._state.numInstances++;var u=this._portions.length;return this._portions.push({}),this._numPortions++,this.model.numPortions++,u}},{key:"finalize",value:function(){if(this._finalized)throw"Already finalized";var e=this.model.scene.canvas.gl,t=this._pickColors.length/4;if(t>0){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;t<n;t+=2){var r=this.handlers[t],i=this.handlers[t+1];if(r.global&&(r.lastIndex=0),r.test(e))return i}return null}}]),e}(),Wu=new Qu,zu=function(){function e(t){b(this,e),this.manager=void 0!==t?t:Wu,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}return P(e,[{key:"load",value:function(){}},{key:"loadAsync",value:function(e,t){var n=this;return new Promise((function(r,i){n.load(e,r,t,i)}))}},{key:"parse",value:function(){}},{key:"setCrossOrigin",value:function(e){return this.crossOrigin=e,this}},{key:"setWithCredentials",value:function(e){return this.withCredentials=e,this}},{key:"setPath",value:function(e){return this.path=e,this}},{key:"setResourcePath",value:function(e){return this.resourcePath=e,this}},{key:"setRequestHeader",value:function(e){return this.requestHeader=e,this}}]),e}(),Ku={},Yu=function(e){I(n,zu);var t=m(n);function n(e){return b(this,n),t.call(this,e)}return P(n,[{key:"load",value:function(e,t,n,r){var i=this;void 0===e&&(e=""),void 0!==this.path&&(e=this.path+e),e=this.manager.resolveURL(e);var a=ju.get(e);if(void 0!==a)return this.manager.itemStart(e),setTimeout((function(){t&&t(a),i.manager.itemEnd(e)}),0),a;if(void 0===Ku[e]){Ku[e]=[],Ku[e].push({onLoad:t,onProgress:n,onError:r});var s=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),o=this.mimeType,l=this.responseType;fetch(s).then((function(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;var n=Ku[e],r=t.body.getReader(),i=t.headers.get("Content-Length"),a=i?parseInt(i):0,s=0!==a,o=0,l=new ReadableStream({start:function(e){!function t(){r.read().then((function(r){var i=r.done,l=r.value;if(i)e.close();else{o+=l.byteLength;for(var u=new ProgressEvent("progress",{lengthComputable:s,loaded:o,total:a}),c=0,f=n.length;c<f;c++){var p=n[c];p.onProgress&&p.onProgress(u)}e.enqueue(l),t()}}))}()}});return new Response(l)}throw Error('fetch for "'.concat(t.url,'" responded with ').concat(t.status,": ").concat(t.statusText))})).then((function(e){switch(l){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((function(e){return(new DOMParser).parseFromString(e,o)}));case"json":return e.json();default:if(void 0===o)return e.text();var t=/charset="?([^;"\s]*)"?/i.exec(o),n=t&&t[1]?t[1].toLowerCase():void 0,r=new TextDecoder(n);return e.arrayBuffer().then((function(e){return r.decode(e)}))}})).then((function(t){ju.add(e,t);var n=Ku[e];delete Ku[e];for(var r=0,i=n.length;r<i;r++){var a=n[r];a.onLoad&&a.onLoad(t)}})).catch((function(t){var n=Ku[e];if(void 0===n)throw i.manager.itemError(e),t;delete Ku[e];for(var r=0,a=n.length;r<a;r++){var s=n[r];s.onError&&s.onError(t)}i.manager.itemError(e)})).finally((function(){i.manager.itemEnd(e)})),this.manager.itemStart(e)}else Ku[e].push({onLoad:t,onProgress:n,onError:r})}},{key:"setResponseType",value:function(e){return this.responseType=e,this}},{key:"setMimeType",value:function(e){return this.mimeType=e,this}}]),n}(),Xu=function(){function e(){var t=arguments.length>0&&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;e<this.pool;e++)if(!(this.workerStatus&1<<e))return e;return-1}},{key:"_onMessage",value:function(e,t){var n=this.workersResolve[e];if(n&&n(t),this.queue.length){var r=this.queue.shift(),i=r.resolve,a=r.msg,s=r.transfer;this.workersResolve[e]=i,this.workers[e].postMessage(a,s)}else this.workerStatus^=1<<e}},{key:"setWorkerCreator",value:function(e){this.workerCreator=e}},{key:"setWorkerLimit",value:function(e){this.pool=e}},{key:"postMessage",value:function(e,t){var n=this;return new Promise((function(r){var i=n._getIdleWorker();-1!==i?(n._initWorker(i),n.workerStatus|=1<<i,n.workersResolve[i]=r,n.workers[i].postMessage(e,t)):n.queue.push({resolve:r,msg:e,transfer:t})}))}},{key:"destroy",value:function(){this.workers.forEach((function(e){return e.terminate()})),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}]),e}(),qu=0,Ju=function(){function e(t){var n=t.viewer,r=t.transcoderPath,i=t.workerLimit;b(this,e),this._transcoderPath=r||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new Xu,this._workerSourceURL="",i&&this._workerPool.setWorkerLimit(i);var a=n.capabilities;this._workerConfig={astcSupported:a.astcSupported,etc1Supported:a.etc1Supported,etc2Supported:a.etc2Supported,dxtSupported:a.dxtSupported,bptcSupported:a.bptcSupported,pvrtcSupported:a.pvrtcSupported},this._supportedFileTypes=["xkt2"]}return P(e,[{key:"_init",value:function(){var t=this;if(!this._transcoderPending){var n=new Yu;n.setPath(this._transcoderPath),n.setWithCredentials(this.withCredentials);var r=n.loadAsync("basis_transcoder.js"),i=new Yu;i.setPath(this._transcoderPath),i.setResponseType("arraybuffer"),i.setWithCredentials(this.withCredentials);var a=i.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([r,a]).then((function(n){var r=p(n,2),i=r[0],a=r[1],s=e.BasisWorker.toString(),o=["/* constants */","let _EngineFormat = "+JSON.stringify(e.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(e.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(e.BasisFormat),"/* basis_transcoder.js */",i,"/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join("\n");t._workerSourceURL=URL.createObjectURL(new Blob([o])),t._transcoderBinary=a,t._workerPool.setWorkerCreator((function(){var e=new Worker(t._workerSourceURL),n=t._transcoderBinary.slice(0);return e.postMessage({type:"init",config:t._workerConfig,transcoderBinary:n},[n]),e}))})),qu>0&&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<A.length;d++){var v=A[d];if(e[v.if]&&(v.basisFormat.includes(t)&&!(c&&v.transcoderFormat.length<2)&&(!v.needsPowerOfTwo||u(n)&&u(s))))return{transcoderFormat:f=v.transcoderFormat[c?1:0],engineFormat:p=v.engineFormat[c?1:0]}}return console.warn("KTX2TextureTranscoder: No suitable compressed texture format found. Decoding to RGBA32."),f=i.RGBA32,p=r.RGBAFormat,{transcoderFormat:f,engineFormat:p}}(f,p,A,v),m=y.transcoderFormat,w=y.engineFormat;if(!p||!A||!d)throw c(),new Error("KTX2TextureTranscoder: Invalid texture");if(!s.startTranscoding())throw c(),new Error("KTX2TextureTranscoder: .startTranscoding failed");for(var g=[],T=0;T<d;T++){var E=s.getImageLevelInfo(T,0,0),b=E.origWidth,D=E.origHeight,P=new Uint8Array(s.getImageTranscodedSizeInBytes(T,0,0,m));if(!s.transcodeImage(P,T,0,0,m,0,-1,-1))throw c(),new Error("KTX2TextureTranscoder: .transcodeImage failed.");g.push({data:P,width:b,height:D})}return c(),{width:p,height:A,hasAlpha:v,mipmaps:g,format:w,dfdTransferFn:h,dfdFlags:I}}(f.buffers[0]),s=t.width,c=t.height,p=t.hasAlpha,A=t.mipmaps,d=t.format,v=t.dfdTransferFn,h=t.dfdFlags,I=[],y=0;y<A.length;++y)I.push(A[y].data.buffer);self.postMessage({type:"transcode",id:f.id,width:s,height:c,hasAlpha:p,mipmaps:A,format:d,dfdTransferFn:v,dfdFlags:h},I)}catch(e){console.error("[KTX2TextureTranscoder.BasisWorker]: ".concat(e)),self.postMessage({type:"error",id:f.id,error:e.message})}}))}}));var s=[{if:"astcSupported",basisFormat:[a.UASTC_4x4],transcoderFormat:[i.ASTC_4x4,i.ASTC_4x4],engineFormat:[r.RGBA_ASTC_4x4_Format,r.RGBA_ASTC_4x4_Format],priorityETC1S:1/0,priorityUASTC:1,needsPowerOfTwo:!1},{if:"bptcSupported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[i.BC7_M5,i.BC7_M5],engineFormat:[r.RGBA_BPTC_Format,r.RGBA_BPTC_Format],priorityETC1S:3,priorityUASTC:2,needsPowerOfTwo:!1},{if:"dxtSupported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[i.BC1,i.BC3],engineFormat:[r.RGB_S3TC_DXT1_Format,r.RGBA_S3TC_DXT5_Format],priorityETC1S:4,priorityUASTC:5,needsPowerOfTwo:!1},{if:"etc2Supported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[i.ETC1,i.ETC2],engineFormat:[r.RGB_ETC2_Format,r.RGBA_ETC2_EAC_Format],priorityETC1S:1,priorityUASTC:3,needsPowerOfTwo:!1},{if:"etc1Supported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[i.ETC1],engineFormat:[r.RGB_ETC1_Format],priorityETC1S:2,priorityUASTC:4,needsPowerOfTwo:!1},{if:"pvrtcSupported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[i.PVRTC1_4_RGB,i.PVRTC1_4_RGBA],engineFormat:[r.RGB_PVRTC_4BPPV1_Format,r.RGBA_PVRTC_4BPPV1_Format],priorityETC1S:5,priorityUASTC:6,needsPowerOfTwo:!0}],o=s.sort((function(e,t){return e.priorityETC1S-t.priorityETC1S})),l=s.sort((function(e,t){return e.priorityUASTC-t.priorityUASTC}));function u(e){return e<=2||0==(e&e-1)&&0!==e}};var Zu={};function $u(e){var t=e.scene.id,n=Zu[t];return n||(n=new Ju({viewer:e}),Zu[t]=n,e.scene.on("destroyed",(function(){delete Zu[t],n.destroy()}))),n}
11
11
  /**
12
12
  * @author https://github.com/tmarti, with support from https://tribia.com/
13
13
  * @license MIT