@jdultra/threedtiles 14.0.22 → 14.0.24

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.
@@ -1499,5 +1499,5 @@ out vec2 vUv;
1499
1499
  void main() {
1500
1500
  vUv = uv;
1501
1501
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
1502
- }`}function Ao(B,A,g,I){const Q=B.getX(g),C=B.getY(g),a=B.getZ(g),e=A.getX(g),i=A.getY(g),t=A.getZ(g);I.set(Q,C,a,C,e,i,a,i,t)}function go(B,A,g){const I=B.determinant();if(Math.abs(I)<1e-12)return void g.set(0,0,0);const Q=1/I,C=new l.Matrix3().copy(B);C.elements[0]=A.x,C.elements[3]=A.y,C.elements[6]=A.z;const a=new l.Matrix3().copy(B);a.elements[1]=A.x,a.elements[4]=A.y,a.elements[7]=A.z;const e=new l.Matrix3().copy(B);e.elements[2]=A.x,e.elements[5]=A.y,e.elements[8]=A.z,g.set(C.determinant()*Q,a.determinant()*Q,e.determinant()*Q)}function KI(B,A){if(!A||Array.isArray(A)&&A.length!==3)throw new Error(`${B} must be a length-3 array [x,y,z]`);return A}function Fe(B,A,g){return{kind:"cuboid",params:{hx:Number(B),hy:Number(A),hz:Number(g)}}}const GQ={createBall:function(B){return{kind:"ball",params:{radius:Number(B)}}},createCuboid:Fe,createBox:function(B,A,g){return Fe(B,A,g)},createRoundCuboid:function(B,A,g,I){return{kind:"roundCuboid",params:{hx:Number(B),hy:Number(A),hz:Number(g),radius:Number(I)}}},createCapsule:function(B,A){return{kind:"capsule",params:{halfHeight:Number(B),radius:Number(A)}}},createCone:function(B,A){return{kind:"cone",params:{halfHeight:Number(B),radius:Number(A)}}},createCylinder:function(B,A){return{kind:"cylinder",params:{halfHeight:Number(B),radius:Number(A)}}},createSegment:function(B,A){return{kind:"segment",params:{a:KI("a",B),b:KI("b",A)}}},createTriangle:function(B,A,g){return{kind:"triangle",params:{a:KI("a",B),b:KI("b",A),c:KI("c",g)}}},createPolyline:function(B,A){return{kind:"polyline",params:{vertices:B,indices:A||null}}},createConvexHull:function(B){return{kind:"convexHull",params:{vertices:B}}},createHeightfield:function(B,A,g,I={x:1,y:1,z:1}){return{kind:"heightfield",params:{rows:Number(B),cols:Number(A),heights:g,scale:I}}}};var FA;const Fg=new Y.Sphere(new Y.Vector3(0,0,0),1),Jg=new ag([0,0,0,1,0,0,0,1,0,0,0,1]);new Y.Box3;const Pg=new Y.Vector3(0,0,0),GI=new Y.Vector3(0,0,0),Io=new Y.Vector3(0,1,0),wB=new Y.Ray,fB=new Y.Matrix4;new Y.Matrix4,new Y.Frustum;const yB=new Y.Vector3,FB=[],pe=new Y.Quaternion,kg={};function Me(){var B=[];for(let A in kg)kg.hasOwnProperty(A)&&kg[A]>0&&B.push(A);return B}class RQ extends Y.Object3D{constructor(A){super();const g=this;g.physics=A.physics||{};const I=g.physics;if(I&&typeof I=="object"&&(I.type||(I.type="fixed"),I.shape==null&&(I.shape="none"),I.mass==null&&(I.mass=1),Array.isArray(I.velocity)||I.velocity&&I.velocity.isVector3||(I.velocity=[0,0,0]),Array.isArray(I.angularVelocity)||I.angularVelocity&&I.angularVelocity.isVector3||(I.angularVelocity=[0,0,0]),I.maxLOD==null&&(I.maxLOD=1/0),I.colliders&&typeof I.colliders=="object")){const e=I.colliders;e.maxLOD==null&&(e.maxLOD=Number.isFinite(I.maxLOD)?I.maxLOD:1/0),Array.isArray(e.priority)?(e.priority=e.priority.filter(i=>i==="mesh"||i==="hull"||i==="bounds"),e.priority.length===0&&(e.priority=["mesh","hull","bounds"])):e.priority=["mesh","hull","bounds"],Array.isArray(e.byGeometricError)||(e.byGeometricError=[]),Array.isArray(e.byLevel)||(e.byLevel=[])}if(g.splatsMesh=A.splatsMesh,g.oldUltraMeshSplats=A.oldUltraMeshSplats,g.iosCompatibility=A.iosCompatibility,g.splatsQuality=A.splatsQuality!=null?A.splatsQuality:.75,g.splatsCPUCulling=A.splatsCPUCulling!=null&&A.splatsCPUCulling,this.contentURL=[],A.domWidth&&A.domHeight?this.rendererSize=new Y.Vector2(A.domWidth,A.domHeight):this.rendererSize=new Y.Vector2(1e3,1e3),this.setClipShape(A.clipShape),this.loadingStrategy=A.loadingStrategy?A.loadingStrategy.toUpperCase():"INCREMENTAL",this.distanceBias=Math.max(1e-4,A.distanceBias?A.distanceBias:1),this.proxy=A.proxy,this.drawBoundingVolume=!!A.drawBoundingVolume&&A.drawBoundingVolume,this.displayErrors=A.displayErrors,this.displayCopyright=A.displayCopyright,A.queryParams&&(this.queryParams={...A.queryParams}),this.uuid=Aa(),A.tileLoader)this.tileLoader=A.tileLoader;else{const e={};e.meshCallback=A.meshCallback?A.meshCallback:(t,E)=>{t.material.wireframe=!1,t.material.side=Y.DoubleSide},e.pointsCallback=A.pointsCallback?A.pointsCallback:(t,E)=>{t.material.size=Math.pow(E,.33),t.material.sizeAttenuation=!0},e.proxy=this.proxy,e.renderer=A.renderer,e.dracoLoader=A.dracoLoader,e.ktx2Loader=A.ktx2Loader,g.tileLoader=new ZC(e);const i=this.update;this.update=t=>{i.call(g,t),g.tileLoader.update()}}this.displayCopyright=!!A.displayCopyright,this.geometricErrorMultiplier=A.geometricErrorMultiplier?A.geometricErrorMultiplier:1,this.splatsCropRadius=Number.MAX_VALUE,this.splatsSizeMultiplier=1,this.splatsExposureEV=A&&A.splatsExposureEV!==void 0?A.splatsExposureEV:0,this.splatsSaturation=A&&A.splatsSaturation!==void 0?A.splatsSaturation:1,this.splatsContrast=A&&A.splatsContrast!==void 0?A.splatsContrast:1;const Q=A&&A.splatsTempTint!==void 0?A.splatsTempTint:[0,0];if(this.splatsTempTint=Array.isArray(Q)?[Number(Q[0]||0),Number(Q[1]||0)]:[Number(Q.temp||0),Number(Q.tint||0)],this.renderer=A.renderer,this.meshCallback=A.meshCallback,this.loadOutsideView=A.loadOutsideView,this.cameraOnLoad=A.cameraOnLoad,this.parentTile=A.parentTile,this.occlusionCullingService=A.occlusionCullingService,this.static=A.static,this.occlusionCullingService&&(this.color=new Y.Color,this.color.setHex(16777215*Math.random()),this.colorID=Y.MathUtils.clamp(255*g.color.r,0,255)<<16^Y.MathUtils.clamp(255*g.color.g,0,255)<<8^Y.MathUtils.clamp(255*g.color.b,0,255)),this.static&&(this.matrixAutoUpdate=!1,this.matrixWorldAutoUpdate=!1),this.childrenTiles=[],this.meshContent=[],this.tileContent,this.refine,this.rootPath,this.geometricError,this.boundingVolume,this.json,this.materialVisibility=!1,this.level=A.level?A.level:0,this.hasMeshContent=0,this.hasUnloadedJSONContent=0,this.centerModel=A.centerModel,this.abortController=new AbortController,this.onLoadCallback=A.onLoadCallback,A.json)g._setup(A);else if(A.url){var C=A.url;if(g.queryParams){var a="";for(let e in g.queryParams)g.queryParams.hasOwnProperty(e)&&(a+="&"+e+"="+g.queryParams[e]);C.includes("?")?C+=a:C+="?"+a.substring(1)}(g.proxy?()=>fetch(g.proxy,{method:"POST",body:C,signal:g.abortController.signal}):()=>fetch(C,{signal:g.abortController.signal}))().then(e=>{if(!e.ok)throw new Error(`couldn't load "${A.url}". Request failed with status ${e.status} : ${e.statusText}`);e.json().then(i=>AQ(i,C)).then(i=>{g._setup({rootPath:BI.dirname(A.url),json:i})})}).catch(e=>{g.displayErrors&&Ge(e)})}}setClipShape(A){if(A instanceof ag||A instanceof Y.Sphere)this.clipShape=A;else if(A instanceof Y.Box3){const g=new Y.Vector3,I=new Y.Vector3;A.getCenter(g),A.getSize(I).multiplyScalar(.5),this.clipShape=new ag([g.x,g.y,g.z,I.x,0,0,0,I.y,0,0,0,I.z])}else A=void 0;this.childrenTiles&&this.childrenTiles.forEach(g=>{g._setClipShape(this.clipShape)})}_setClipShape(A){this.clipShape=A,this.childrenTiles&&this.childrenTiles.forEach(g=>{g._setClipShape(this.clipShape)})}setSplatsSizeMultiplier(A){this.splatsSizeMultiplier=A,this.splatsMesh&&this.splatsMesh.setSplatsSizeMultiplier(this.splatsSizeMultiplier)}setSplatsCropRadius(A){this.splatsCropRadius=A,this.splatsMesh&&this.splatsMesh.setSplatsCropRadius(this.splatsCropRadius)}setSplatsDepthBias(A){this.splatsDepthBias=A,this.splatsMesh&&this.splatsMesh.setDepthBias(this.splatsDepthBias)}setSplatsCPUCulling(A){this.splatsCPUCulling=A,this.splatsMesh&&this.splatsMesh.setSplatsCPUCulling(A)}setSplatsQuality(A){this.splatsQuality=A,this.splatsMesh&&this.splatsMesh.setQuality(A)}setSplatsExposureEV(A){this.splatsExposureEV=A,this.splatsMesh&&typeof this.splatsMesh.setExposureEV=="function"&&this.splatsMesh.setExposureEV(A)}setSplatsSaturation(A){this.splatsSaturation=A,this.splatsMesh&&typeof this.splatsMesh.setSaturation=="function"&&this.splatsMesh.setSaturation(A)}setSplatsContrast(A){this.splatsContrast=A,this.splatsMesh&&typeof this.splatsMesh.setContrast=="function"&&this.splatsMesh.setContrast(A)}setSplatsTempTint(A,g){this.splatsTempTint=[A,g],this.splatsMesh&&typeof this.splatsMesh.setTempTint=="function"&&this.splatsMesh.setTempTint(A,g)}updateMatrices(){this.updateMatrix(),this.splatsMesh&&this.splatsMesh.updateMatrix(),this.static&&(this.traverse(A=>{A.isObject3D&&(A.matrixWorldAutoUpdate=!0)}),this.splatsMesh&&(this.splatsMesh.matrixWorldAutoUpdate=!0)),this.updateMatrixWorld(!0),this.static&&(this.traverse(A=>{A.isObject3D&&(A.matrixWorldAutoUpdate=!1)}),this.splatsMesh&&(this.splatsMesh.matrixWorldAutoUpdate=!1))}setCanvasSize(A,g){this.rendererSize.set(A,g)}async _setup(A){const g=this;if(A.json.extensionsRequired&&(A.json.extensionsRequired.includes("JDULTRA_gaussian_splats")||A.json.extensionsRequired.includes("JDULTRA_gaussian_splats_V2"))&&(g.oldUltraMeshSplats=!0),A.json.root?(g.json=A.json.root,g.json.refine||(g.json.refine=A.json.refine),g.json.geometricError||(g.json.geometricError=A.json.geometricError),g.json.transform||(g.json.transform=A.json.transform),g.json.boundingVolume||(g.json.boundingVolume=A.json.boundingVolume)):g.json=A.json,g.json.children||(g.json.getChildren?g.json.children=await g.json.getChildren():g.json.children=[]),g.rootPath=A.json.rootPath?A.json.rootPath:A.rootPath,g.json.refine?g.refine=g.json.refine:g.refine=A.parentRefine,g.json.geometricError?g.geometricError=g.json.geometricError:g.geometricError=A.parentGeometricError,g.json.transform){let Q=new Y.Matrix4;Q.elements=g.json.transform,g.applyMatrix4(Q)}if(g.json.boundingVolume)if(g.json.boundingVolume.box)g.boundingVolume=new ag(g.json.boundingVolume.box);else if(g.json.boundingVolume.region){const Q=g.json.boundingVolume.region;g._transformWGS84ToCartesian(Q[0],Q[1],Q[4],Pg),g._transformWGS84ToCartesian(Q[2],Q[3],Q[5],GI),Pg.lerp(GI,.5),g.boundingVolume=new Y.Sphere(new Y.Vector3(Pg.x,Pg.y,Pg.z),Pg.distanceTo(GI))}else if(g.json.boundingVolume.sphere){const Q=g.json.boundingVolume.sphere;g.boundingVolume=new Y.Sphere(new Y.Vector3(Q[0],Q[1],Q[2]),Q[3])}else g.boundingVolume=A.parentBoundingVolume;else g.boundingVolume=A.parentBoundingVolume;function I(Q){Q.uri&&Q.uri.includes("json")||Q.url&&Q.url.includes("json")?g.hasUnloadedJSONContent++:g.hasMeshContent++}if(g.json.content?(I(g.json.content),g.hasMeshContent==0&&(g.level=Math.max(0,g.parentTile?g.parentTile.level+.01:0)),g._load()):g.json.contents&&(g.json.contents.forEach(Q=>I(Q)),g.hasMeshContent==0&&(g.level=Math.max(0,g.parentTile?g.parentTile.level+.01:0))),g.centerModel&&(GI.copy(g.boundingVolume.center),this.json.boundingVolume.region&&(this._transformWGS84ToCartesian(.5*(this.json.boundingVolume.region[0]+this.json.boundingVolume.region[2]),.5*(this.json.boundingVolume.region[1]+this.json.boundingVolume.region[3]),.5*(this.json.boundingVolume.region[4]+this.json.boundingVolume.region[5]),Pg),pe.setFromUnitVectors(Pg.normalize(),Io.normalize()),g.applyQuaternion(pe)),GI.applyMatrix4(g.matrix),g.position.sub(GI),g.updateMatrices()),g.onLoadCallback&&g.onLoadCallback(g),!g.parentTile&&g.physics&&g.physics.sim&&(g.physics.rigidBodyID=g.physics.sim.addObject({object:g,type:g.physics.type,mass:g.physics.mass,position:g.position,rotation:g.quaternion,velocity:g.physics.velocity,angularVelocity:g.physics.angularVelocity})),g.isSetup=!0,g.level>0&&g.drawBoundingVolume)if(g.bbox&&console.log("double setup"),this.boundingVolume.aabb){let Q=this.boundingVolume.aabb.clone();Q.applyMatrix4(this.matrixWorld),g.bbox=new Y.Box3Helper(Q,new Y.Color(Math.random(),Math.random(),Math.random())),g.add(g.bbox),g.bbox.material.visible=!1}else g.boundingVolume instanceof ag&&(g.bbox=g.boundingVolume.helper(),g.add(g.bbox),g.bbox.material.visible=!1)}_assembleURL(A,g){A.endsWith("/")||(A+="/");try{const I=new URL(A);let Q=I.pathname.split("/").filter(a=>a!==""),C=g.split("/").filter(a=>a!=="");for(let a=1;a<=Q.length&&!(a>=C.length);a++)if(Q.slice(Q.length-a,Q.length).join("/")===C.slice(0,a).join("/")){for(let i=0;i<a;i++)Q.pop();break}for(;C.length>0&&C[0]==="..";)Q.pop(),C.shift();return`${I.protocol}//${I.host}/${[...Q,...C].join("/")}`}catch{return A.endsWith("/")||g.startsWith("/")?A+g:A+"/"+g}}_extractQueryParams(A,g){try{const I=new URL(A);for(let[Q,C]of I.searchParams)g[Q]=C;return I.search="",I.toString()}catch{return A}}async _load(A=!0,g=!0){var I=this;if(!I.deleted||!g){if(I.json.content)await Q(I.json.content,null,A,g);else if(I.json.contents){let C=I.json.contents.map((a,e)=>Q(a,e,A,g));Promise.all(C)}}async function Q(C,a,e,i){let t;C.uri?t=C.uri:C.url&&(t=C.url);const E=/^(?:http|https|ftp|tcp|udp):\/\/\S+/;if(E.test(I.rootPath)?E.test(t)||(t=I._assembleURL(I.rootPath,t)):t=I.rootPath+BI.sep+t,t.startsWith("/local-tiles")||(t=I._extractQueryParams(t,I.queryParams)),I.queryParams){var o="";for(let r in I.queryParams)I.queryParams.hasOwnProperty(r)&&(o+="&"+r+"="+I.queryParams[r]);t.includes("?")?t+=o:t+="?"+o.substring(1)}if(t)if(I.contentURL.push(t),i&&(t.includes(".b3dm")||t.includes(".glb")||t.includes(".gltf")))try{I.tileLoader.get(I.abortController,I.uuid,t,r=>{if(!I.deleted){if(r.asset&&r.asset.copyright&&(r.asset.copyright.split(";").forEach(n=>{kg[n]?kg[n]++:kg[n]=1}),I.displayCopyright&&NQ()),r.isSplatsData){if(!I.splatsMesh){if(I.splatsMesh=new be(I.tileLoader.renderer,void 0,void 0,I.oldUltraMeshSplats?.25:1),I.splatsMesh.setQuality(I.splatsQuality),I.splatsMesh.setSplatsCPUCulling(I.splatsCPUCulling),I.splatsMesh.setSplatsCropRadius(I.splatsCropRadius),I.splatsMesh.setSplatsSizeMultiplier(I.splatsSizeMultiplier),I.splatsExposureEV!==void 0&&typeof I.splatsMesh.setExposureEV=="function"&&I.splatsMesh.setExposureEV(I.splatsExposureEV),I.splatsSaturation!==void 0&&typeof I.splatsMesh.setSaturation=="function"&&I.splatsMesh.setSaturation(I.splatsSaturation),I.splatsContrast!==void 0&&typeof I.splatsMesh.setContrast=="function"&&I.splatsMesh.setContrast(I.splatsContrast),I.splatsTempTint!==void 0&&typeof I.splatsMesh.setTempTint=="function"){const n=I.splatsTempTint||[0,0];I.splatsMesh.setTempTint(n[0],n[1])}I.static&&(I.splatsMesh.matrixAutoUpdate=!1,I.splatsMesh.matrixWorldAutoUpdate=!1),I.add(I.splatsMesh),I.updateMatrices()}r=I.splatsMesh.addSplatsTile(r.positions,r.colors,r.cov0,r.cov1)}return r.isSplatsBatch||(r.traverse(n=>{if((n.isMesh||n.isPoints)&&n.layers.disable(0),n.isMesh&&I.occlusionCullingService){const s=n.geometry.attributes.position,c=[];for(let D=0;D<s.count;D++)c.push(I.color.r,I.color.g,I.color.b);n.geometry.setAttribute("color",new Y.Float32BufferAttribute(c,3))}}),I.add(r),I.updateMatrices()),I.meshContent.push(r),r}},I.cameraOnLoad?()=>I.loadingStrategy=="IMMEDIATE"?I._calculateDistanceToCamera(I.cameraOnLoad):I.loadingStrategy=="INCREMENTAL"?I.parentTile?I.parentTile._calculateDistanceToCamera(I.cameraOnLoad)/Math.max(1,I.parentTile.level):I._calculateDistanceToCamera(I.cameraOnLoad)/Math.max(1,I.level):I.loadingStrategy=="PERLEVEL"?I.parentTile?I.level+I.parentTile._calculateDistanceToCamera(I.cameraOnLoad):I.level+I._calculateDistanceToCamera(I.cameraOnLoad):0:()=>0,()=>I._getSiblings(),I.level,I.loadingStrategy,!I.json.boundingVolume.region,!!I.json.boundingVolume.region,I.geometricError,I.oldUltraMeshSplats)}catch(r){I.displayErrors&&Ge(r)}else e&&t.includes(".json")&&(I.jsonRequested=t,I.tileLoader.get(I.abortController,I.uuid,t,async r=>{I.jsonReceived=!0,r.rootPath=BI.dirname(t),I.json.children.push(r),a==null?delete I.json.content:I.json.contents.splice(a,1),I.hasUnloadedJSONContent--}))}}dispose(){const A=this;if(A.physics&&A.physics.sim&&(A.colliderUUID&&(A.physics.sim.detachCollider({colliderId:A.colliderUUID}),A.colliderUUID=void 0),Array.isArray(A.colliderUUIDs)&&A.colliderUUIDs.length)){for(const g of A.colliderUUIDs)A.physics.sim.detachCollider({colliderId:g});A.colliderUUIDs=[]}A.meshContent.forEach(g=>{g&&g.asset&&g.asset.copyright&&(g.asset.copyright.split(";").forEach(I=>{kg[I]&&kg[I]--}),A.displayCopyright&&NQ())}),A.childrenTiles.forEach(g=>g.dispose()),A.deleted=!0,A.splatsMesh&&(A.meshContent.forEach(g=>g.hide()),A.parentTile||(A.splatsMesh.dispose(),A.splatsMesh=void 0)),A.contentURL&&(A.contentURL.forEach(g=>{A.tileLoader.invalidate(g,A.uuid)}),A.contentURL=[]),A.abortController&&!A.jsonRequested&&A.abortController.abort("tile not needed"),this.parent=null,A.meshContent=[],A.bbox&&A.bbox.dispose(),this.dispatchEvent({type:"removed"})}_disposeMeshContent(){const A=this;if(!A.deleted){A.deleted=!0,A.abortController&&(A.abortController.abort("tile not needed"),A.abortController=new AbortController);for(let g=A.meshContent.length-1;g>=0;g--){const I=A.meshContent[g];I&&I.asset&&I.asset.copyright&&(I.asset.copyright.split(";").forEach(Q=>{kg[Q]&&kg[Q]--}),A.displayCopyright&&NQ()),A.remove(I)}A.splatsMesh&&A.meshContent.forEach(g=>g.hide()),A.meshContent=[],A.contentURL.forEach(g=>{A.tileLoader.invalidate(g,A.uuid)}),A.contentURL=[]}}_disposeChildren(){var A=this;A.childrenTiles.forEach(g=>{g.dispose(),A.remove(g)}),A.childrenTiles=[]}raycast(A,g){if(this.splatsMesh){wB.copy(A.ray),fB.copy(this.matrixWorld).invert(),wB.applyMatrix4(fB);let I=!1;if(this.boundingVolume instanceof ag)I=this.boundingVolume.intersectsRay(wB);else{if(!(this.boundingVolume instanceof Y.Sphere))return!1;I=ray.intersectsSphere(this.boundingVolume)}return I&&this.materialVisibility&&this.splatsReady&&(FB.length=0,this.meshContent.forEach(Q=>{Q.isSplatsBatch&&(Q.raycast(wB,FB,A.params.Points.threshold),FB.forEach(C=>{C.point.applyMatrix4(this.matrixWorld)}),g.push(...FB))})),I}return super.raycast(A,g)}update(A){this.splatsMesh&&this.splatsMesh.updateShaderParams(A,this.renderer);const g=new Y.Frustum;g.setFromProjectionMatrix(new Y.Matrix4().multiplyMatrices(A.projectionMatrix,A.matrixWorldInverse));let I=[0],Q=[0],C=[0],a=[0];if(this.refine=="REPLACE"?this.loadingStrategy==="IMMEDIATE"?(this._updateImmediate(A,g),this._statsImmediate(C,I,a,Q)):(this._update(A,g),this._stats(C,I,a,Q)):(this._update(A,g),this._stats(C,I,a,Q)),I>0&&(a[0]/=I[0]),this.splatsMesh)if(yB.copy(A.position),fB.copy(this.matrixWorld).invert(),yB.applyMatrix4(fB),this.splatsCPUCulling){const e=new Y.Matrix4().multiplyMatrices(A.projectionMatrix,A.matrixWorldInverse).multiply(this.matrixWorld);this.splatsMesh.sort(yB,e)}else this.splatsMesh.sort(yB);return this.splatsMesh&&this.splatsMesh.update(),{numTilesLoaded:I[0],numTilesRendered:Q[0],maxLOD:C[0],percentageLoaded:a[0]}}_updateImmediate(A,g){this._computeMetricRecursive(A,g),this._updateNodeVisibilityImmediate(),this._expandTreeImmediate(A),this.shouldBeVisible=this.metric>0||!!this.loadOutsideView,this._shouldBeVisibleUpdateImmediate(),this._trimTreeImmediate(),this._loadMeshImmediate()}_statsImmediate(A,g,I,Q){A[0]=Math.max(A[0],this.level),(this.shouldBeVisible||this.materialVisibility)&&(g[0]++,this.materialVisibility&&I[0]++),this.materialVisibility&&Q[0]++,this.childrenTiles.forEach(C=>{C._statsImmediate(A,g,I,Q)})}_stats(A,g,I,Q){A[0]=Math.max(A[0],this.level),this.hasMeshContent&&(g[0]++,this.meshContent.length==this.hasMeshContent&&I[0]++,this.materialVisibility&&Q[0]++),this.childrenTiles.forEach(C=>{C._stats(A,g,I,Q)})}_trimTreeImmediate(){const A=this;if(A.metric!=null)if(A.hasMeshContent&&A.shouldBeVisible&&A.materialVisibility){if(A.splatsMesh&&!A.splatsReady)return;A._disposeChildren()}else A.childrenTiles.forEach(g=>{g._trimTreeImmediate()})}_updateNodeVisibilityImmediate(A=!1){const g=this;if(g.hasMeshContent)if(g.shouldBeVisible)g.meshContent.length==g.hasMeshContent?g.materialVisibility?g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(!0)}):(g._changeContentVisibility(!0),g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(A)})):g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(A)});else{if(!g.loadOutsideView&&g.metric<0)return g._changeContentVisibility(!1),g.meshContent.length>0&&g._disposeMeshContent(),void g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(!0)});if(!g.materialVisibility||g.splatsMesh&&!g.splatsReady)g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(A)});else if(A)g._changeContentVisibility(!1),g.meshContent.length>0&&g._disposeMeshContent(),g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(A)});else{let I=!0;g.childrenTiles.every(Q=>!!Q._isReadyImmediate()||(I=!1,!1)),I&&g.childrenTiles.length>0?(g._changeContentVisibility(!1),g.meshContent.length>0&&g._disposeMeshContent(),g.childrenTiles.forEach(Q=>{Q._updateNodeVisibilityImmediate(A)})):g.childrenTiles.forEach(Q=>{Q._updateNodeVisibilityImmediate(!g.splatsMesh||!!g.splatsReady)})}}else g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(A)})}_shouldBeVisibleUpdateImmediate(){const A=this;A.hasMeshContent?A.metric==null?A.shouldBeVisible=!1:A.metric<0?(A.shouldBeVisible=!!A.loadOutsideView,A.childrenTiles.forEach(g=>{g._setShouldNotBeVisibleRecursive()})):A.metric<A.geometricErrorMultiplier*A.geometricError?A.hasUnloadedJSONContent||(A.json&&A.json.children&&A.json.children.length>0?(A.shouldBeVisible=!1,A.childrenTiles.forEach(g=>{g.shouldBeVisible=!0,g._shouldBeVisibleUpdateImmediate()})):A.shouldBeVisible=!0):A.childrenTiles.forEach(g=>{g._setShouldNotBeVisibleRecursive()}):(A.childrenTiles.forEach(g=>{g.shouldBeVisible=!0,g._shouldBeVisibleUpdateImmediate()}),A.shouldBeVisible=!1)}_setShouldNotBeVisibleRecursive(){this.shouldBeVisible=!1,this.childrenTiles.forEach(A=>{A._setShouldNotBeVisibleRecursive()})}_loadMeshImmediate(){const A=this;A.hasMeshContent&&A.shouldBeVisible?A.meshContent.length<A.hasMeshContent&&A.contentURL.length==0&&(A.deleted=!1,A._load(!1,!0)):A.childrenTiles.forEach(g=>{g._loadMeshImmediate()})}_computeMetricRecursive(A,g){const I=this;I.metric=-1,I.isSetup&&(I.boundingVolume&&I.geometricError&&(I.metric=I._calculateUpdateMetric(A,g)),I.childrenTiles.forEach(Q=>Q._computeMetricRecursive(A,g)))}_expandTreeImmediate(A){const g=this;g.hasUnloadedJSONContent||(g.hasMeshContent?g.occlusionCullingService&&g.hasMeshContent&&!g.occlusionCullingService.hasID(g.colorID)||g.metric>=0&&g.metric<g.geometricErrorMultiplier*g.geometricError&&g.json&&g.json.children&&g.childrenTiles.length<g.json.children.length&&g._loadJsonChildren(A):g.json&&g.json.children&&g.childrenTiles.length<g.json.children.length&&g._loadJsonChildren(A)),g.childrenTiles.forEach(I=>I._expandTreeImmediate(A))}_update(A,g){const I=this;if(!I.isSetup)return;const Q=I.materialVisibility;I.boundingVolume&&I.geometricError&&(I.metric=I._calculateUpdateMetric(A,g)),I.childrenTiles.forEach(C=>C._update(A,g)),function(C){if(C<0)return I.inFrustum=!1,void I._changeContentVisibility(!!I.loadOutsideView);if(I.inFrustum=!0,!!I.hasMeshContent&&!(I.meshContent.length<I.hasMeshContent)){if(I.childrenTiles.length==0)return void I._changeContentVisibility(!0);if(C>=I.geometricErrorMultiplier*I.geometricError)I._changeContentVisibility(!0);else if(C<I.geometricErrorMultiplier*I.geometricError&&I.refine=="REPLACE"){let a=!0;I.childrenTiles.every(e=>!!e._isReady()||(a=!1,!1)),a?I._changeContentVisibility(!1):I._changeContentVisibility(!0)}}}(I.metric),function(C){C<0&&I.hasMeshContent||I.occlusionCullingService&&I.hasMeshContent&&!I.occlusionCullingService.hasID(I.colorID)||(!I.hasMeshContent||C<=I.geometricErrorMultiplier*I.geometricError&&(I.meshContent.length>0||I.splatsMesh))&&I.json&&I.json.children&&I.childrenTiles.length!=I.json.children.length&&I._loadJsonChildren(A)}(I.metric),function(C,a){if(I.hasMeshContent){if(!I.inFrustum)return void I._disposeChildren();if(I.occlusionCullingService&&!a&&I.hasMeshContent&&I.meshContent.length>0&&I.materialVisibility&&I._areAllChildrenLoadedAndHidden())return I.splatsMesh&&I.materialVisibility&&!I.splatsReady?void 0:void I._disposeChildren();if(C>=I.geometricErrorMultiplier*I.geometricError){if(I.splatsMesh&&I.materialVisibility&&!I.splatsReady)return;I._disposeChildren()}}}(I.metric,Q)}_loadJsonChildren(A){const g=this;for(let I=g.json.children.length-1;I>=0;I--)g.json.children[I].root||g.json.children[I].children||g.json.children[I].getChildren||g.json.children[I].content||g.json.children[I].contents||g.json.children.splice(I,1);g.json.children.forEach(I=>{let Q=new RQ({parentTile:g,queryParams:g.queryParams,parentGeometricError:g.geometricError,parentBoundingVolume:g.boundingVolume,parentRefine:g.refine,json:I,rootPath:g.rootPath,geometricErrorMultiplier:g.geometricErrorMultiplier,loadOutsideView:g.loadOutsideView,level:Math.floor(g.level)+1,tileLoader:g.tileLoader,cameraOnLoad:A,occlusionCullingService:g.occlusionCullingService,renderer:g.renderer,static:g.static,centerModel:!1,displayErrors:g.displayErrors,displayCopyright:g.displayCopyright,distanceBias:g.distanceBias,loadingStrategy:g.loadingStrategy,drawBoundingVolume:g.drawBoundingVolume,splatsMesh:g.splatsMesh,clipShape:g.clipShape,oldUltraMeshSplats:g.oldUltraMeshSplats,physics:g.physics});g.childrenTiles.push(Q),g.add(Q)}),g.updateMatrices(!0)}_areAllChildrenLoadedAndHidden(){let A=!0;const g=this;return this.childrenTiles.every(I=>{if(I.hasMeshContent){if(I.childrenTiles.length>0)return A=!1,!1;if(I.metric<0)return!0;if(I.materialVisibility&&(!g.splatsMesh||g.splatsReady)||g.occlusionCullingService.hasID(I.colorID))return A=!1,!1}else if(!I._areAllChildrenLoadedAndHidden())return A=!1,!1;return!0}),A}_isReady(){if(this.metric==null)return!1;if(this.metric<0)return!0;if(this.hasUnloadedJSONContent)return!1;if(!this.hasMeshContent&&this.json.children.length==0&&!this.hasUnloadedJSONContent)return!0;if(!this.hasMeshContent||this.meshContent.length==0||!this.materialVisibility){if(this.children.length>0){var A=!0;return this.childrenTiles.every(g=>!!g._isReady()||(A=!1,!1)),A}return!1}return!this.hasMeshContent||!(this.meshContent.length<this.hasMeshContent)&&!!this.materialVisibility}_isReadyImmediate(){if(this.materialVisibility||!this.loadOutsideView&&this.metric<0)return!0;if(this.childrenTiles.length>0){var A=!0;return this.childrenTiles.every(g=>!!g._isReadyImmediate()||(A=!1,!1)),A}return!1}_changeContentVisibility(A){const g=this;if(g.materialVisibility!=A){if(g.bbox&&(g.bbox.material.visible=A),g.splatsMesh)A!=g.materialVisibility&&(g.meshContent.forEach(I=>{A&&I.isSplatsBatch?I.show(()=>{g.materialVisibility&&(g.splatsReady=!0)}):(I.hide(),g.splatsReady=!1)}),g.materialVisibility=A);else{if(g.hasMeshContent&&g.meshContent.length>0&&(A?g.meshContent.forEach(I=>{I.traverse(Q=>{(Q.isMesh||Q.isPoints)&&Q.layers.enable(0)})}):g.meshContent.forEach(I=>{I.traverse(Q=>{(Q.isMesh||Q.isPoints)&&Q.layers.disable(0)})})),g.materialVisibility==A)return;g.materialVisibility=A}g._updateCollider()}}setPose(A,g,I){if(!A.isVector3)throw new TypeError("OGC3DTile.setPose: 'position' must be an instance of THREE.Vector3");if(!I.isVector3)throw new TypeError("OGC3DTile.setPose: 'scale' must be an instance of THREE.Vector3");if(!g.isEuler&&!g.isQuaternion)throw new TypeError("OGC3DTile.setPose: 'rotation' must be a THREE.Euler or THREE.Quaternion");this.physics&&this.physics.sim&&this.physics.rigidBodyID?(this.physics.sim.setPose({bodyId:this.physics.rigidBodyID,position:A,rotation:g}),I&&!I.equals(this.scale)&&(this.scale.copy(I),this.updateMatrices(),this.traverse(Q=>{Q._updateCollider&&Q._updateCollider()}))):(this.scale.copy(I),g.isQuaternion?this.setRotationFromQuaternion(g):this.setRotationFromEuler(g),this.position.copy(A),this.updateMatrices())}_updateCollider(){const A=this;if(!A.physics||!A.physics.sim)return;const g=A.physics.rigidBodyID,I=Math.floor(A.level||0),Q=!!A.materialVisibility,C=Array.isArray(A.childrenTiles)&&A.childrenTiles.length>0,a=A.physics&&A.physics.colliders&&typeof A.physics.colliders=="object"?A.physics.colliders:null,e=Number.isFinite(a?.maxLOD)?a.maxLOD:Number.isFinite(A.physics.maxLOD)?A.physics.maxLOD:1/0,i=(G,N)=>{const F=Array.isArray(N)&&N.length?N:["mesh","hull","bounds"];for(const k of F)if(G.includes(k))return k;return null},t=()=>{const G=a?.priority||["mesh","hull","bounds"];if(a&&Array.isArray(a.byGeometricError)&&a.byGeometricError.length){const N=A.geometricError;if(typeof N=="number"){const F=[];for(const m of a.byGeometricError){if(!m||!m.shape)continue;const S=typeof m.min=="number"?m.min:-1/0,j=typeof m.max=="number"?m.max:1/0;N>=S&&N<j&&F.push(m.shape)}const k=i(F,G);if(k)return k}return a.defaultShape?a.defaultShape:A.physics.shape?A.physics.shape:"none"}if(a&&Array.isArray(a.byLevel)&&a.byLevel.length){const N=Math.floor(A.level||0),F=[];for(const m of a.byLevel){if(!m||!m.shape)continue;const S=typeof m.min=="number"?m.min:-1/0,j=typeof m.max=="number"?m.max:1/0;N>=S&&N<=j&&F.push(m.shape)}return i(F,G)||(a.defaultShape?a.defaultShape:A.physics.shape?A.physics.shape:"none")}return A.physics.shape||"none"},E=t(),o=()=>{A.colliderUUID&&(A.physics.sim.detachCollider({colliderId:A.colliderUUID}),A.colliderUUID=void 0)},r=()=>{if(Array.isArray(A.colliderUUIDs)&&A.colliderUUIDs.length){for(const G of A.colliderUUIDs)A.physics.sim.detachCollider({colliderId:G});A.colliderUUIDs=[]}},n=()=>{o(),r(),A._activeColliderShape=void 0};if(!g||!E||E==="none"||I>e)return n(),void(A._activeColliderShape=void 0);const s=Q&&I<=e,c=A._activeColliderShape||"none";c===E||!Q&&I===e&&C||(c!=="mesh"&&c!=="hull"||E!=="bounds"?c!=="bounds"||E!=="mesh"&&E!=="hull"?c==="mesh"&&E==="hull"||c==="hull"&&E==="mesh"?r():n():o():r(),A._activeColliderShape=E&&E!=="none"?E:void 0);let D=A;for(;D&&D.parentTile;)D=D.parentTile;const d=new Y.Vector3,h=new Y.Quaternion,u=new Y.Vector3;D&&D.matrixWorld&&D.matrixWorld.decompose(d,h,u);const f=new Y.Matrix4().compose(d,h,new Y.Vector3(1,1,1)),R=new Y.Matrix4().copy(f).invert();if(E!=="bounds"){if(E==="mesh"||E==="hull")if(console.log(E+" "+this.level),o(),s){if(!A.hasMeshContent||A.meshContent.length!==A.hasMeshContent)return;if(!Array.isArray(A.colliderUUIDs)||A.colliderUUIDs.length===0){A.colliderUUIDs=[];const G=E==="hull"?"addConvexHullCollider":"attachTrimeshCollider",N=F=>{if(!(F&&F.isMesh&&F.geometry&&F.geometry.isBufferGeometry))return;const k=new Y.Matrix4().multiplyMatrices(R,F.matrixWorld),m=new Y.Vector3,S=new Y.Quaternion,j=new Y.Vector3;k.decompose(m,S,j);const z=new Y.Vector3;F.getWorldScale(z),z.set(Math.abs(z.x),Math.abs(z.y),Math.abs(z.z)),A.physics.sim[G]({bodyId:g,geometry:F.geometry,localPosition:[m.x,m.y,m.z],localRotation:S,localScale:[z.x,z.y,z.z]}).then($=>{const _=t(),X=!A.deleted&&(_==="mesh"||_==="hull"),CA=Math.floor(A.level||0)<=e,sA=Math.floor(A.level||0)===e&&Array.isArray(A.childrenTiles)&&A.childrenTiles.length>0;X&&(A.materialVisibility?CA:CA&&sA)?($&&A.colliderUUIDs.push($),A._activeColliderShape=E):$&&A.physics.sim.detachCollider({colliderId:$})}).catch(()=>{})};for(const F of A.meshContent)F&&!F.isSplatsBatch&&(F.isMesh&&N(F),F.traverse&&F.traverse(k=>{k.isMesh&&N(k)}))}}else I===e&&C||(r(),A._activeColliderShape=void 0)}else if(r(),s){if(!A.colliderUUID){if(A.boundingVolume instanceof ag||A.boundingVolume?.isOBB){const G=A.localToWorld(A.boundingVolume.center.clone()).clone().applyMatrix4(R),N=A.localToWorld(new Y.Vector3(0,0,0)).clone().applyMatrix4(R),F=A.boundingVolume.e1.clone().multiplyScalar(A.boundingVolume.halfSize.x),k=A.boundingVolume.e2.clone().multiplyScalar(A.boundingVolume.halfSize.y),m=A.boundingVolume.e3.clone().multiplyScalar(A.boundingVolume.halfSize.z),S=A.localToWorld(F.clone()).applyMatrix4(R),j=A.localToWorld(k.clone()).applyMatrix4(R),z=A.localToWorld(m.clone()).applyMatrix4(R),$=S.clone().sub(N),_=j.clone().sub(N),X=z.clone().sub(N),CA=$.length(),sA=_.length(),oA=X.length(),fA=CA>0?$.clone().multiplyScalar(1/CA):new Y.Vector3(1,0,0),bA=sA>0?_.clone().multiplyScalar(1/sA):new Y.Vector3(0,1,0),iA=oA>0?X.clone().multiplyScalar(1/oA):new Y.Vector3(0,0,1),yA=new Y.Matrix4().makeBasis(fA,bA,iA),EA=new Y.Quaternion().setFromRotationMatrix(yA);A.colliderUUID=A.physics.sim.attachShapeCollider({bodyId:g,shape:GQ.createBox(CA,sA,oA),localPosition:[G.x,G.y,G.z],localRotation:EA}),A._activeColliderShape="bounds"}else if(A.boundingVolume instanceof Y.Sphere||A.boundingVolume?.isSphere){const G=A.localToWorld(A.boundingVolume.center.clone()).clone().applyMatrix4(R),N=A.localToWorld(new Y.Vector3(0,0,0)).clone().applyMatrix4(R),F=A.localToWorld(new Y.Vector3(1,0,0)).applyMatrix4(R).sub(N).length(),k=A.localToWorld(new Y.Vector3(0,1,0)).applyMatrix4(R).sub(N).length(),m=A.localToWorld(new Y.Vector3(0,0,1)).applyMatrix4(R).sub(N).length(),S=Math.max(F,k,m),j=A.boundingVolume.radius*S;A.colliderUUID=A.physics.sim.attachShapeCollider({bodyId:g,shape:GQ.createBall(j),localPosition:[G.x,G.y,G.z]}),A._activeColliderShape="bounds"}}}else I===e&&C||(o(),A._activeColliderShape=void 0)}_calculateUpdateMetric(A,g){let I=0;if(this.boundingVolume instanceof ag){if(Jg.copy(this.boundingVolume),Jg.applyMatrix4(this.matrixWorld),!Jg.inFrustum(g))return-1;if(this.clipShape!=null&&(this.clipShape.isSphere&&!Jg.intersectsSphere(this.clipShape)||this.clipShape.isOBB&&!Jg.intersectsOBB(this.clipShape)))return Number.MAX_VALUE;I=Math.max(0,Jg.distanceToPoint(A.position)-A.near)}else{if(!(this.boundingVolume instanceof Y.Sphere))return console.error("unsupported shape"),-1;if(Fg.copy(this.boundingVolume),Fg.applyMatrix4(this.matrixWorld),this.clipShape!=null&&(this.clipShape.isOBB&&!this.clipShape.intersectsSphere(Fg)||this.clipShape.isSphere&&!this.clipShape.intersectsSphere(Fg)))return Number.MAX_VALUE;if(!g.intersectsSphere(Fg))return-1;I=Math.max(0,A.position.distanceTo(Fg.center)-Fg.radius-A.near)}if(I=Math.pow(I,this.distanceBias),I==0)return 0;const Q=this.matrixWorld.getMaxScaleOnAxis();this.renderer&&this.renderer.getDrawingBufferSize(this.rendererSize);let C=this.rendererSize.y,a=A.fov;return A.aspect<1&&(a*=A.aspect,C=this.rendererSize.x),16*(2*Math.tan(.5*a*.017453292519943295)*I)/(C*Q)}_getSiblings(){const A=this,g=[];if(!A.parentTile)return g;let I=A.parentTile;for(;!I.hasMeshContent&&I.parentTile;)I=I.parentTile;return I.childrenTiles.forEach(Q=>{if(Q&&Q!=A){for(;!Q.hasMeshContent&&Q.childrenTiles[0];)Q=Q.childrenTiles[0];g.push(Q)}}),g}_calculateDistanceToCamera(A){return this.boundingVolume instanceof ag?(Jg.copy(this.boundingVolume),Jg.applyMatrix4(this.matrixWorld),Math.max(0,Jg.distanceToPoint(A.position))):this.boundingVolume instanceof Y.Sphere?(Fg.copy(this.boundingVolume),Fg.applyMatrix4(this.matrixWorld),Math.max(0,A.position.distanceTo(Fg.center)-Fg.radius)):(console.error("unsupported shape"),-1)}setGeometricErrorMultiplier(A){this.geometricErrorMultiplier=A,this.childrenTiles.forEach(g=>g.setGeometricErrorMultiplier(A))}setDistanceBias(A){this.distanceBias=A,this.childrenTiles.forEach(g=>g.setDistanceBias(A))}_transformWGS84ToCartesian(A,g,I,Q){const C=6378137/Math.sqrt(1-.006694384442042*Math.pow(Math.sin(g),2)),a=Math.cos(g),e=Math.cos(A),i=Math.sin(g),t=C+I,E=t*a*e,o=t*a*Math.sin(A),r=(.993305615557957*C+I)*i;Q.set(E,o,r)}hideCopyright(){(function(){FA||((FA=document.createElement("div")).style.position="fixed",FA.style.bottom="20px",FA.style.left="20px",FA.style.color="white",FA.style.textShadow="2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000",FA.style.padding="10px",FA.style.backgroundColor="rgba(0, 0, 0, 0.1)",document.body.appendChild(FA)),FA.style.opacity=0})()}showCopyright(){(function(){FA||((FA=document.createElement("div")).style.position="fixed",FA.style.bottom="20px",FA.style.left="20px",FA.style.color="white",FA.style.textShadow="2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000",FA.style.padding="10px",FA.style.backgroundColor="rgba(0, 0, 0, 0.1)",document.body.appendChild(FA)),FA.style.opacity=1})()}}function Ge(B){var A=document.createElement("div");A.textContent=B,A.style.position="fixed",A.style.top="10px",A.style.left="50%",A.style.transform="translateX(-50%)",A.style.padding="10px",A.style.backgroundColor="#ff8800",A.style.color="#ffffff",A.style.zIndex="9999",document.body.appendChild(A),setTimeout(function(){A.remove()},8e3)}function NQ(){FA||((FA=document.createElement("div")).style.position="fixed",FA.style.bottom="20px",FA.style.left="20px",FA.style.color="white",FA.style.textShadow="2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000",FA.style.padding="10px",FA.style.backgroundColor="rgba(0, 0, 0, 0.1)",document.body.appendChild(FA));const B=Me();let A="";B.forEach(g=>{A+=g+", "}),A=A.slice(0,-2),FA.textContent=A}const ig=new Y.Sphere(new Y.Vector3(0,0,0),1),Vg=new Y.Vector3(0,0,0),kQ=new Y.Vector3(0,0,0),Bo=new Y.Vector3(0,1,0),mQ=new Y.Vector2,Re=new Y.Quaternion,Ne=new Y.Matrix4;class UQ extends Y.Object3D{constructor(A){super();const g=this;if(A.queryParams&&(this.queryParams={...A.queryParams}),this.uuid=Aa(),A.tileLoader?this.tileLoader=A.tileLoader:console.error("an instanced tileset must be provided an InstancedTilesetLoader"),this.master=A.master,this.loadOutsideView=A.loadOutsideView,this.cameraOnLoad=A.cameraOnLoad,this.parentTile=A.parentTile,this.distanceBias=Math.max(1e-4,A.distanceBias?A.distanceBias:1),this.childrenTiles=[],this.jsonChildren=[],this.meshContent=new Set,this.static=A.static,this.static&&(this.matrixAutoUpdate=!1,this.matrixWorldAutoUpdate=!1),this.tileContent,this.refinement,this.rootPath,this.geometricError,this.boundingVolume,this.json,this.materialVisibility=!1,this.inFrustum=!0,this.level=A.level?A.level:0,this.hasMeshContent=0,this.hasUnloadedJSONContent=0,this.centerModel=A.centerModel,this.deleted=!1,this.abortController=new AbortController,A.json)this.rootPath=A.json.rootPath?A.json.rootPath:A.rootPath,A.json.children&&(this.jsonChildren=A.json.children),g.setup(A);else if(A.url){this.loadJson=(C,a)=>{const e=BI.dirname(a);g.setup({rootPath:e,json:C,onLoadCallback:A.onLoadCallback})};var I=A.url;if(g.queryParams){var Q="";for(let C in g.queryParams)g.queryParams.hasOwnProperty(C)&&(Q+="&"+C+"="+g.queryParams[C]);I.includes("?")?I+=Q:I+="?"+Q.substring(1)}g.tileLoader.get(g.abortController,I,g.uuid,g)}}async setup(A){const g=this;A.json.root?(g.json=A.json.root,!g.json.children&&g.json.getChildren&&(g.json.children=await g.json.getChildren()),g.jsonChildren=g.json.children,g.json.refinement||(g.json.refinement=A.json.refinement),g.json.geometricError||(g.json.geometricError=A.json.geometricError),g.json.transform||(g.json.transform=A.json.transform),g.json.boundingVolume||(g.json.boundingVolume=A.json.boundingVolume)):(g.json=A.json,!g.json.children&&g.json.getChildren&&(g.json.children=await g.json.getChildren(),g.jsonChildren=g.json.children)),g.rootPath=A.json.rootPath?A.json.rootPath:A.rootPath,g.json.refinement?g.refinement=g.json.refinement:g.refinement=A.parentRefinement,g.json.geometricError?g.geometricError=g.json.geometricError:g.geometricError=A.parentGeometricError;let I=new Y.Matrix4;if(g.json.transform&&!g.centerModel&&(I.elements=g.json.transform),g.applyMatrix4(I),g.parentTile&&g.parentTile.matrix&&(g.matrix.premultiply(g.parentTile.matrix),g.matrix.decompose(g.position,g.quaternion,g.scale)),g.matrixWorldNeedsUpdate=!0,g.updateWorldMatrix(!0,!0),g.json.boundingVolume)if(g.json.boundingVolume.box)g.boundingVolume=new ag(g.json.boundingVolume.box);else if(g.json.boundingVolume.region){const C=g.json.boundingVolume.region;g.transformWGS84ToCartesian(C[0],C[1],C[4],Vg),g.transformWGS84ToCartesian(C[2],C[3],C[5],kQ),Vg.lerp(kQ,.5),g.boundingVolume=new Y.Sphere(new Y.Vector3(Vg.x,Vg.y,Vg.z),Vg.distanceTo(kQ))}else if(g.json.boundingVolume.sphere){const C=g.json.boundingVolume.sphere;g.boundingVolume=new Y.Sphere(new Y.Vector3(C[0],C[1],C[2]),C[3])}else g.boundingVolume=A.parentBoundingVolume;else g.boundingVolume=A.parentBoundingVolume;function Q(C){C.uri&&C.uri.includes("json")||C.url&&C.url.includes("json")?g.hasUnloadedJSONContent++:g.hasMeshContent++}if(g.json.content?(Q(g.json.content),g.load()):g.json.contents&&(g.json.contents.forEach(C=>Q(C)),g.load()),g.centerModel){const C=new Y.Sphere;g.boundingVolume instanceof ag?C.copy(g.boundingVolume.sphere):g.boundingVolume instanceof Y.Sphere&&C.copy(g.boundingVolume),this.json.boundingVolume.region&&(g.transformWGS84ToCartesian(.5*(g.json.boundingVolume.region[0]+g.json.boundingVolume.region[2]),.5*(g.json.boundingVolume.region[1]+g.json.boundingVolume.region[3]),.5*(g.json.boundingVolume.region[4]+g.json.boundingVolume.region[5]),Vg),Re.setFromUnitVectors(Vg.normalize(),Bo.normalize()),g.master.applyQuaternion(Re),g.master.updateWorldMatrix(!1,!1)),Ne.makeTranslation(-C.center.x*g.scale.x,-C.center.y*g.scale.y,-C.center.z*g.scale.z),g.master.matrix.multiply(Ne),g.master.matrix.decompose(g.master.position,g.master.quaternion,g.master.scale)}g.isSetup=!0,A.onLoadCallback&&A.onLoadCallback(g)}isAbsolutePathOrURL(A){const g=/^(?:http|https|ftp|tcp|udp):\/\/\S+/.test(A),I=A.startsWith("/")&&!A.startsWith("//");return g||I}assembleURL(A,g){A.endsWith("/")||(A+="/");const I=new URL(A);let Q=I.pathname.split("/").filter(a=>a!==""),C=g.split("/").filter(a=>a!=="");for(let a=1;a<=Q.length&&!(a>=C.length);a++)if(Q.slice(Q.length-a,Q.length).join("/")===C.slice(0,a).join("/")){for(let e=0;e<a;e++)Q.pop();break}for(;C.length>0&&C[0]==="..";)Q.pop(),C.shift();return`${I.protocol}//${I.host}/${[...Q,...C].join("/")}`}extractQueryParams(A,g){const I=new URL(A);for(let[Q,C]of I.searchParams)g[Q]=C;return I.search="",I.toString()}load(){var A=this;function g(I){let Q;I.uri?Q=I.uri:I.url&&(Q=I.url);const C=/^(?:http|https|ftp|tcp|udp):\/\/\S+/;if(C.test(A.rootPath)?C.test(Q)||(Q=A.assembleURL(A.rootPath,Q)):BI.isAbsolute(A.rootPath)&&(Q=A.rootPath+BI.sep+Q),Q=A.extractQueryParams(Q,A.queryParams),A.queryParams){var a="";for(let e in A.queryParams)A.queryParams.hasOwnProperty(e)&&(a+="&"+e+"="+A.queryParams[e]);Q.includes("?")?Q+=a:Q+="?"+a.substring(1)}Q&&(Q.includes(".b3dm")||Q.includes(".glb")||Q.includes(".gltf")?(A.contentURL=Q,A.tileLoader.get(A.abortController,Q,A.uuid,A,A.cameraOnLoad?()=>A.calculateDistanceToCamera(A.cameraOnLoad):()=>0,()=>A.getSiblings(),A.level,!A.json.boundingVolume.region,!!A.json.boundingVolume.region,A.geometricError)):Q.includes(".json")&&A.tileLoader.get(A.abortController,Q,A.uuid,A))}A.deleted||(A.json.content?g(A.json.content):A.json.contents&&A.json.contents.forEach(I=>g(I)))}loadMesh(A){this.deleted||this.meshContent.add(A)}loadJson(A,g){this.deleted||(this.json.children&&(this.jsonChildren=this.json.children),A.rootPath=BI.dirname(g),this.jsonChildren.push(A),this.hasUnloadedJSONContent--)}dispose(){const A=this;A.childrenTiles.forEach(g=>g.dispose()),A.deleted=!0,A.abortController&&A.abortController.abort(),this.parent=null,this.parentTile=null,this.dispatchEvent({type:"removed"})}disposeChildren(){this.childrenTiles.forEach(A=>A.dispose()),this.childrenTiles=[]}_update(A,g){const I=this;function Q(C){if(I.hasMeshContent&&!(I.meshContent.size<I.hasMeshContent)){if(C<0)return I.inFrustum=!1,void I.changeContentVisibility(!!I.loadOutsideView);if(I.inFrustum=!0,I.childrenTiles.length!=0){if(C>=I.master.geometricErrorMultiplier*I.geometricError)I.changeContentVisibility(!0);else if(C<I.master.geometricErrorMultiplier*I.geometricError){let a=!0;I.childrenTiles.every(e=>!!e.isReady()||(a=!1,!1)),a&&I.changeContentVisibility(!1)}}else I.changeContentVisibility(!0)}}I.isSetup&&(I.materialVisibility,I.boundingVolume&&I.geometricError&&(I.metric=I.calculateUpdateMetric(A,g)),I.childrenTiles.forEach(C=>C._update(A,g)),Q(I.metric),function(C){C<0&&I.hasMeshContent||(!I.hasMeshContent&&I.rootPath||C<I.master.geometricErrorMultiplier*I.geometricError&&I.meshContent.size>0)&&I.json&&I.jsonChildren&&I.childrenTiles.length!=I.jsonChildren.length&&I.jsonChildren.forEach(a=>{if(!(a.root||a.children||a.getChildren||a.content||a.contents))return;let e=new UQ({parentTile:I,queryParams:I.queryParams,parentGeometricError:I.geometricError,parentBoundingVolume:I.boundingVolume,parentRefinement:I.refinement,json:a,rootPath:I.rootPath,loadOutsideView:I.loadOutsideView,level:I.level+1,tileLoader:I.tileLoader,cameraOnLoad:A,master:I.master,centerModel:!1});I.childrenTiles.push(e)})}(I.metric),function(C){if(I.hasMeshContent){if(!I.inFrustum)return I.disposeChildren(),void Q(C);C>=I.master.geometricErrorMultiplier*I.geometricError&&(I.disposeChildren(),Q(C))}}(I.metric))}areAllChildrenLoadedAndHidden(){let A=!0;return this.childrenTiles.every(g=>{if(g.hasMeshContent){if(g.childrenTiles.length>0)return A=!1,!1;if(!g.inFrustum)return!0;if(!g.materialVisibility||g.meshesToDisplay!=g.meshesDisplayed)return A=!1,!1}else if(!g.areAllChildrenLoadedAndHidden())return A=!1,!1;return!0}),A}isReady(){if(!this.inFrustum)return!0;if(this.hasUnloadedJSONContent)return!1;if(!this.hasMeshContent||this.meshContent.size==0||!this.materialVisibility){if(this.childrenTiles.length>0){var A=!0;return this.childrenTiles.every(g=>!!g.isReady()||(A=!1,!1)),A}return!1}return!this.hasMeshContent||!(this.meshContent.size<this.hasMeshContent)&&!!this.materialVisibility}changeContentVisibility(A){this.materialVisibility=A}calculateUpdateMetric(A,g){if(this.boundingVolume instanceof ag){if(ig.copy(this.boundingVolume.sphere),ig.applyMatrix4(this.matrixWorld),!g.intersectsSphere(ig))return-1}else{if(!(this.boundingVolume instanceof Y.Sphere))return console.error("unsupported shape"),-1;if(ig.copy(this.boundingVolume),ig.applyMatrix4(this.matrixWorld),!g.intersectsSphere(ig))return-1}let I=Math.max(0,A.position.distanceTo(ig.center)-ig.radius);if(I=Math.pow(I,this.distanceBias),I==0)return 0;const Q=this.matrixWorld.getMaxScaleOnAxis();this.master._renderSize(mQ);let C=mQ.y,a=A.fov;A.aspect<1&&(a*=A.aspect,C=mQ.x);let e=2*Math.tan(.5*a*.017453292519943295)*I;return 16*window.devicePixelRatio*e/(C*Q)}getSiblings(){const A=this,g=[];if(!A.parentTile)return g;let I=A.parentTile;for(;!I.hasMeshContent&&I.parentTile;)I=I.parentTile;return I.childrenTiles.forEach(Q=>{if(Q&&Q!=A){for(;!Q.hasMeshContent&&Q.childrenTiles[0];)Q=Q.childrenTiles[0];g.push(Q)}}),g}calculateDistanceToCamera(A){return this.boundingVolume instanceof ag?(ig.copy(this.boundingVolume.sphere),ig.applyMatrix4(this.matrixWorld)):this.boundingVolume instanceof Y.Sphere?(ig.copy(this.boundingVolume),ig.applyMatrix4(this.matrixWorld)):console.error("unsupported shape"),Math.max(0,A.position.distanceTo(ig.center)-ig.radius)}getWorldMatrix(){return this.matrixWorld}transformWGS84ToCartesian(A,g,I,Q){const C=6378137/Math.sqrt(1-.006694384442042*Math.pow(Math.sin(g),2)),a=Math.cos(g),e=Math.cos(A),i=Math.sin(g),t=C+I,E=t*a*e,o=t*a*Math.sin(A),r=(.993305615557957*C+I)*i;Q.set(E,o,r)}}class Qo extends Y.Object3D{constructor(A){super(),A.master=this,A.domWidth&&A.domHeight?this.rendererSize=new Y.Vector2(A.domWidth,A.domHeight):this.rendererSize=new Y.Vector2(1e3,1e3),this.renderer=A.renderer,this.distanceBias=Math.max(1e-4,A.distanceBias?A.distanceBias:1),this.geometricErrorMultiplier=A.geometricErrorMultiplier?A.geometricErrorMultiplier:1,this.tileset=new UQ(A),A.static&&(this.matrixAutoUpdate=!1),this.tileLoader=A.tileLoader}_renderSize(A){this.renderer?this.renderer.getDrawingBufferSize(A):A.copy(this.rendererSize)}setCanvasSize(A,g){this.rendererSize.set(A,g)}update(A,g){if(g)this.tileset._update(A,g);else{const I=new Y.Frustum;I.setFromProjectionMatrix(new Y.Matrix4().multiplyMatrices(A.projectionMatrix,A.matrixWorldInverse)),this.tileset._update(A,I)}}setGeometricErrorMultiplier(A){this.geometricErrorMultiplier=A||1}}class Co{constructor(A){const g=this;g.scene=A,g.instancedTiles=[],g.instancedMesh,g.reuseableMatrix=new Y.Matrix4}addInstance(A){const g=this;A.added=!0,A.listOMesh=g.instancedTiles,g.instancedTiles.push(A),g.instancedMesh&&A.loadMesh(g.instancedMesh)}addToScene(){const A=this;A.instancedMesh.setMatrixAt(0,new Y.Matrix4),A.instancedMesh.instanceMatrix.needsUpdate=!0,A.instancedMesh.count=1,A.scene.add(A.instancedMesh),A.instancedMesh.onAfterRender=()=>{delete A.instancedMesh.onAfterRender,A.instancedMesh.displayedOnce=!0}}setObject(A){const g=this;g.instancedMesh=A,g.instancedMesh.matrixAutoUpdate=!1,g.instancedMesh.matrixWorldAutoUpdate=!1,g.scene.children.includes(A)||this.addToScene();for(let I=0;I<g.instancedTiles.length;I++)g.instancedTiles[I].loadMesh(g.instancedMesh)}update(){const A=this;for(let g=A.instancedTiles.length-1;g>=0;g--)A.instancedTiles[g].deleted&&A.instancedTiles.splice(g,1);if(A.instancedMesh){A.instancedMesh.count=0,A.instancedMesh.instancedTiles=[];for(let g=0;g<A.instancedTiles.length;g++)A.instancedTiles[g].meshContent.add(A.instancedMesh),A.instancedTiles[g].materialVisibility&&(A.instancedMesh.count++,A.reuseableMatrix.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),A.reuseableMatrix.multiply(A.instancedTiles[g].matrixWorld),A.reuseableMatrix.multiply(A.instancedMesh.baseMatrix),A.instancedMesh.setMatrixAt(A.instancedMesh.count-1,A.reuseableMatrix),A.instancedMesh.instancedTiles.push(A.instancedTiles[g]));A.instancedMesh.instanceMatrix.needsUpdate=!0,A.instancedMesh.needsUpdate=!0,A.instancedMesh.computeBoundingSphere()}}getCount(){return this.instancedTiles.length}dispose(){const A=this;return!(A.instancedTiles.length>0)&&!!A.instancedMesh&&(A.scene.remove(A.instancedMesh),A.instancedMesh.traverse(g=>{if(g.dispose&&g.dispose(),g.material)if(g.material.length)for(let I=0;I<g.material.length;++I)g.material[I].dispose();else g.material.dispose();g.geometry&&g.geometry.dispose()}),A.instancedMesh.dispose(),!0)}}class ao{constructor(){const A=this;A.count=0,A.json,A.instancedTiles=[]}addInstance(A){this.instancedTiles.push(A),this.json&&A.loadJson(this.json,this.url)}setObject(A,g){const I=this;I.json=A,I.url=g;for(let Q=0;Q<I.instancedTiles.length;Q++)I.instancedTiles[Q].loadJson(I.json,I.url)}getCount(){return this.instancedTiles.length}update(){const A=this;for(let g=A.instancedTiles.length-1;g>=0;g--)A.instancedTiles[g].deleted&&A.instancedTiles.splice(g,1)}dispose(){return!(!this.json||this.instancedTiles.length!=0)}}let iI=0;async function eo(B){return new Promise(A=>{const g=setInterval(()=>{B.hasDracoLoader&&!B.dracoLoader||B.hasKTX2Loader&&!B.ktx2Loader||(clearInterval(g),A())},10)})}function Eo(B){return new Worker(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/physicsRapier.worker-jgQ9dgLt.js").href:new URL("assets/physicsRapier.worker-jgQ9dgLt.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),{type:"module",name:B?.name})}function io(B){return new Worker(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/physicsHelper.worker-Cr8S3sZk.js").href:new URL("assets/physicsHelper.worker-Cr8S3sZk.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),{type:"module",name:B?.name})}function tg(B,A=[0,-9.81,0]){return B?Array.isArray(B)&&B.length===3?[Number(B[0]),Number(B[1]),Number(B[2])]:B.isVector3?[B.x,B.y,B.z]:typeof B=="object"&&"x"in B&&"y"in B&&"z"in B?[Number(B.x),Number(B.y),Number(B.z)]:A.slice():A.slice()}function jI(B,A=[0,0,0,1]){if(!B)return A.slice();if(Array.isArray(B)&&B.length===4)return[Number(B[0]),Number(B[1]),Number(B[2]),Number(B[3])];if(B.isQuaternion)return[B.x,B.y,B.z,B.w];if(B.isEuler){const g=new Y.Quaternion().setFromEuler(B);return[g.x,g.y,g.z,g.w]}return A.slice()}function ke(B){if(Array.isArray(B)||B&&B.isVector3)return{mode:"vector",vector:tg(B)};const A=B||{};return(A.mode||"vector").toLowerCase()==="geocentric"?{mode:"geocentric",planetCenter:tg(A.planetCenter||[0,0,0],[0,0,0]),intensity:typeof A.intensity=="number"?A.intensity:9.81}:{mode:"vector",vector:tg(A.vector||A,[0,-9.81,0])}}function pB(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}ZA.ColliderShape=GQ,ZA.InstancedOGC3DTile=Qo,ZA.InstancedTileLoader=class{constructor(B,A){if(this.zUpToYUpMatrix=new Y.Matrix4,this.zUpToYUpMatrix.set(1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1),this.maxCachedItems=100,this.maxInstances=1,this.proxy=A.proxy,A&&(this.meshCallback=A.meshCallback,this.pointsCallback=A.pointsCallback,A.maxCachedItems&&(this.maxCachedItems=A.maxCachedItems),A.maxInstances&&(this.maxInstances=A.maxInstances)),this.gltfLoader=new $Q,A&&A.dracoLoader)this.gltfLoader.setDRACOLoader(A.dracoLoader),this.hasDracoLoader=!0;else{const g=new CC;g.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),this.gltfLoader.setDRACOLoader(g),this.gltfLoader.hasDracoLoader=!0}if(A&&A.ktx2Loader)this.gltfLoader.setKTX2Loader(A.ktx2Loader),this.hasKTX2Loader=!0;else if(A&&A.renderer){const g=new rg;g.setTranscoderPath("https://storage.googleapis.com/ogc-3d-tiles/basis/").detectSupport(A.renderer),this.gltfLoader.setKTX2Loader(g),this.gltfLoader.hasKTX2Loader=!0}this.gltfLoader.setMeshoptDecoder(XC),this.hasMeshOptDecoder=!0,this.b3dmDecoder=new XQ(this.gltfLoader),this.cache=new WQ,this.scene=B,this.ready=[],this.downloads=[],this.nextReady=[],this.nextDownloads=[]}update(){const B=this;B._checkSize(),B.cache._data.forEach(A=>{A.update()}),iI<8&&B._download(),B._loadBatch()}_download(){const B=this;if(B.nextDownloads.length!=0||(B._getNextDownloads(),B.nextDownloads.length!=0))for(;B.nextDownloads.length>0;){const g=B.nextDownloads.shift();if(g){if(g.path.includes(".b3dm")&&(A=B.proxy?()=>fetch(B.proxy,{method:"POST",body:g.path}):()=>fetch(g.path),iI++,A().then(I=>{if(!I.ok)throw console.error("could not load tile with path : "+g.path),new Error(`couldn't load "${g.path}". Request failed with status ${I.status} : ${I.statusText}`);return I.arrayBuffer()}).then(I=>this.b3dmDecoder.parseB3DMInstanced(I,Q=>{B.meshCallback(Q,g.geometricError)},B.maxInstances,g.sceneZupToYup,g.meshZupToYup)).then(I=>{I.frustumCulled=!1,g.tile.setObject(I),B.ready.unshift(g)}).catch(I=>console.error(I)).finally(()=>{iI--})),g.path.includes(".glb")||g.path.includes(".gltf"))A=B.proxy?()=>fetch(B.proxy,{method:"POST",body:g.path}):()=>fetch(g.path),iI++,A().then(I=>{if(!I.ok)throw new Error("missing content");return I.arrayBuffer()}).then(async I=>{await eo(this.gltfLoader),this.gltfLoader.parse(I,null,Q=>{let C;Q.scene.asset=Q.asset,g.sceneZupToYup&&Q.scene.applyMatrix4(this.zUpToYUpMatrix),Q.scene.traverse(a=>{a.geometricError=g.geometricError,a.isMesh&&(g.meshZupToYup&&a.applyMatrix4(this.zUpToYUpMatrix),B.meshCallback&&B.meshCallback(a,a.geometricError)),a.isPoints&&console.error("instanced point cloud is not supported")}),Q.scene.updateWorldMatrix(!1,!0),Q.scene.traverse(a=>{a.isMesh&&(C=new Y.InstancedMesh(a.geometry,a.material,B.maxInstances),C.baseMatrix=a.matrixWorld)}),B.ready.unshift(g),C?(C.frustumCulled=!1,g.tile.setObject(C)):Q.scene.traverse(a=>{a.dispose&&a.dispose(),a.material&&a.material.dispose()})})},I=>{console.error("could not load tile : "+g.path)}).finally(()=>{iI--});else if(g.path.includes(".json")){var A;A=B.proxy?()=>fetch(B.proxy,{method:"POST",body:g.path}):()=>fetch(g.path),iI++,A().then(I=>{if(!I.ok)throw console.error("could not load tile with path : "+g.path),new Error(`couldn't load "${g.path}". Request failed with status ${I.status} : ${I.statusText}`);return I.json()}).then(I=>AQ(I,g.path)).then(I=>{g.tile.setObject(I,g.path),B.ready.unshift(g)}).catch(I=>console.error(I)).finally(()=>{iI--})}}}}_loadBatch(){return this.nextReady.length==0&&(this._getNextReady(),this.nextReady.length==0)?0:this.nextReady.shift()?1:0}_getNextReady(){let B=Number.MAX_VALUE,A=-1;for(let g=this.ready.length-1;g>=0;g--)this.ready[g].distanceFunction||this.nextReady.push(this.ready.splice(g,1)[0]);if(!(this.nextReady.length>0)){for(let g=this.ready.length-1;g>=0;g--){const I=this.ready[g].distanceFunction()*this.ready[g].level;I<B&&(B=I,A=g)}if(A>=0){const g=this.ready.splice(A,1).pop();this.nextReady.push(g);const I=g.getSiblings();for(let Q=this.ready.length-1;Q>=0;Q--)I.includes(this.ready[Q].uuid)&&this.nextready.push(this.ready.splice(Q,1).pop())}}}get(B,A,g,I,Q,C,a,e,i,t){const E=this,o=function(n){for(var s=n.split("/"),c=[],D=0,d=0;d<s.length;d++){var h=s[d];h!=="."&&h!==""&&h!==".."?c[D++]=h:h===".."&&D>0&&D--}if(D===0)return"/";var u="";for(d=0;d<D;d++)u+="/"+c[d];return u}(A);if(!(A.includes(".b3dm")||A.includes(".json")||A.includes(".glb")||A.includes(".gltf")))return void console.error("the 3DTiles cache can only be used to load B3DM, gltf and json data");const r=E.cache.get(o);if(r)r.addInstance(I);else if(A.includes(".b3dm")||A.includes(".glb")||A.includes(".gltf")){const n=new Co(E.scene);n.addInstance(I),E.cache.put(o,n);const s=new AbortController;B.signal.addEventListener("abort",()=>{n.getCount()==0&&s.abort()}),this.downloads.push({abortController:s,tile:n,key:o,path:A,distanceFunction:Q,getSiblings:C,level:a,uuid:g,sceneZupToYup:e,meshZupToYup:i,geometricError:t,shouldDoDownload:()=>!0})}else if(A.includes(".json")){const n=new ao;n.addInstance(I),E.cache.put(o,n);const s=new AbortController;B.signal.addEventListener("abort",()=>{n.getCount()==0&&s.abort()}),this.downloads.push({abortController:s,tile:n,key:o,path:A,distanceFunction:Q,getSiblings:C,level:a,shouldDoDownload:()=>!0})}}_getNextDownloads(){let B=Number.MAX_VALUE,A=-1;for(let g=this.downloads.length-1;g>=0;g--){const I=this.downloads[g];I.shouldDoDownload()?I.distanceFunction||this.nextDownloads.push(this.downloads.splice(g,1)[0]):this.downloads.splice(g,1)}if(!(this.nextDownloads.length>0)){for(let g=this.downloads.length-1;g>=0;g--){const I=this.downloads[g],Q=I.distanceFunction()*I.level;Q<B&&(B=Q,A=g)}if(A>=0){const g=this.downloads.splice(A,1).pop();this.nextDownloads.push(g);const I=g.getSiblings();for(let Q=this.downloads.length-1;Q>=0;Q--)I.includes(this.downloads[Q].uuid)&&this.nextDownloads.push(this.downloads.splice(Q,1).pop())}}}_checkSize(){const B=this;let A=0;for(;B.cache.size()>B.maxCachedItems&&A<B.cache.size();){A++;const g=B.cache.head();B.cache.remove(g.key),g.value.dispose()||B.cache.put(g.key,g.value)}}},ZA.OBB=ag,ZA.OGC3DTile=RQ,ZA.OcclusionCullingService=class{constructor(){this.cullMap=[],this.cullMaterial=new Y.MeshBasicMaterial({vertexColors:!0}),this.cullMaterial.side=Y.FrontSide,this.cullTarget=this._createCullTarget(),this.cullPixels=new Uint8Array(4*this.cullTarget.width*this.cullTarget.height)}setSide(B){this.cullMaterial.side=B}_createCullTarget(){const B=new Y.WebGLRenderTarget(Math.floor(.05*window.innerWidth),Math.floor(.05*window.innerHeight));return B.texture.format=Y.RGBAFormat,B.texture.colorSpace=Y.LinearSRGBColorSpace,B.texture.minFilter=Y.NearestFilter,B.texture.magFilter=Y.NearestFilter,B.texture.generateMipmaps=!1,B.stencilBuffer=!1,B.depthBuffer=!0,B.depthTexture=new Y.DepthTexture,B.depthTexture.format=Y.DepthFormat,B.depthTexture.type=Y.UnsignedShortType,B}update(B,A,g){let I=A.getRenderTarget(),Q=B.overrideMaterial;B.overrideMaterial=this.cullMaterial,A.setRenderTarget(this.cullTarget),A.render(B,g),B.overrideMaterial=Q,A.setRenderTarget(I),A.readRenderTargetPixels(this.cullTarget,0,0,this.cullTarget.width,this.cullTarget.height,this.cullPixels),this.cullMap=[];for(let C=0;C<this.cullPixels.length;C+=4){const a=Y.MathUtils.clamp(this.cullPixels[C],0,255)<<16^Y.MathUtils.clamp(this.cullPixels[C+1],0,255)<<8^Y.MathUtils.clamp(this.cullPixels[C+2],0,255);this.cullMap[a]=!0}}hasID(B){return this.cullMap[B]}},ZA.Physics=class{constructor(B={}){this.updateIntervalMs=typeof B.updateIntervalMs=="number"?B.updateIntervalMs:16,this.fixedDt=typeof B.fixedDt=="number"?B.fixedDt:this.updateIntervalMs/1e3,this.gravity=ke(B.gravity),this.autoStart=B.autoStart!==!1,this.sharedMemorySupported=typeof SharedArrayBuffer<"u"&&!(!globalThis||!globalThis.crossOriginIsolated),this.worker=new Eo({}),this._msgId=0,this._pending=new Map,this._onWorkerMessage=this._onWorkerMessage.bind(this),this.worker.onmessage=this._onWorkerMessage,this.worker.onerror=A=>{console.error("Physics worker error:",A?.message||A)},this.helperWorker=null,this._helperMsgId=0,this._helperPending=new Map,this._onHelperMessage=this._onHelperMessage?this._onHelperMessage.bind(this):A=>{},this._paused=!1,this._lastTickTime=pB(),this._lastState=null,this._currentState=null,this._interpolationMax=1.25,this._nextBodyId=1,this._nextColliderId=1,this.rigidBodies=new Map,this.bodyToColliders=new Map,this.colliderToBody=new Map,this._listeners=new Map,this._initPromise=this._post({type:"init",gravity:this.gravity,sharedMemorySupported:this.sharedMemorySupported,fixedDt:this.fixedDt}),this.autoStart&&this._initPromise.then(()=>{this._scheduleNextTick()}).catch(A=>{console.error("Physics init failed:",A)})}addObject(B={}){const A="rb-"+this._nextBodyId++,g=(B.type||"dynamic").toLowerCase(),I=typeof B.mass=="number"?B.mass:1,Q=tg(B.position,[0,0,0]),C=jI(B.rotation,[0,0,0,1]),a=B.velocity?tg(B.velocity,[0,0,0]):void 0,e=B.angularVelocity?tg(B.angularVelocity,[0,0,0]):void 0;return this.rigidBodies.set(A,{id:A,object:B.object||null,type:g,mass:I,last:{p:Q,q:C},current:{p:Q.slice(),q:C.slice()}}),this.bodyToColliders.set(A,new Set),this._post({type:"addObject",id:A,body:{type:g,mass:I,p:Q,q:C,v:a,w:e}}),A}attachTrimeshCollider({bodyId:B,geometry:A,positions:g,indices:I,localPosition:Q,localRotation:C,localScale:a}){if(!this.rigidBodies.has(B))return console.warn(`attachTrimeshCollider: unknown bodyId ${B}`),Promise.resolve(null);let e=null,i=null;if(A&&A.isBufferGeometry){const D=A.getAttribute("position");if(D)if(D.isInterleavedBufferAttribute){const h=D.count;e=new Float32Array(3*h);for(let u=0;u<h;u++)e[3*u+0]=D.getX(u),e[3*u+1]=D.getY(u),e[3*u+2]=D.getZ(u)}else D.array&&(e=new Float32Array(D.array));else console.warn("attachTrimeshCollider: geometry has no position attribute");const d=A.getIndex?.();if(d&&d.array){const h=d.array;i=new Uint32Array(h)}}else g&&(e=Array.isArray(g)||g instanceof Float32Array?new Float32Array(g):new Float32Array(g.buffer||g)),I&&(i=Array.isArray(I)||I instanceof Uint32Array?new Uint32Array(I):new Uint32Array(I.buffer||I));if(!(e instanceof Float32Array))return console.warn("attachTrimeshCollider: missing or invalid positions buffer"),Promise.resolve(null);const t=Q?tg(Q,[0,0,0]):[0,0,0],E=C?jI(C,[0,0,0,1]):[0,0,0,1],o=Array.isArray(a)&&a.length===3?[Number(a[0]),Number(a[1]),Number(a[2])]:[1,1,1],r="col-"+this._nextColliderId++,n=this.bodyToColliders.get(B)||new Set;n.add(r),this.bodyToColliders.set(B,n),this.colliderToBody.set(r,B);const s={type:"attachTrimeshCollider",id:r,bodyId:B,positions:e,indices:i||null,local:{p:t,q:E,s:o}},c=[];return e?.buffer&&c.push(e.buffer),i?.buffer&&c.push(i.buffer),this._post(s,c).then(()=>r)}addConvexHullCollider({bodyId:B,geometry:A,positions:g,indices:I,localPosition:Q,localRotation:C,localScale:a}){if(!this.rigidBodies.has(B))return console.warn(`addConvexHullCollider: unknown bodyId ${B}`),Promise.resolve(null);let e=null,i=null;if(A&&A.isBufferGeometry){const D=A.getAttribute("position");if(D)if(D.isInterleavedBufferAttribute){const h=D.count;e=new Float32Array(3*h);for(let u=0;u<h;u++)e[3*u+0]=D.getX(u),e[3*u+1]=D.getY(u),e[3*u+2]=D.getZ(u)}else D.array&&(e=new Float32Array(D.array));else console.warn("addConvexHullCollider: geometry has no position attribute");const d=A.getIndex?.();if(d&&d.array){const h=d.array;i=new Uint32Array(h)}}else g&&(e=Array.isArray(g)||g instanceof Float32Array?new Float32Array(g):new Float32Array(g.buffer||g)),I&&(i=Array.isArray(I)||I instanceof Uint32Array?new Uint32Array(I):new Uint32Array(I.buffer||I));if(!(e instanceof Float32Array))return console.warn("addConvexHullCollider: missing or invalid positions buffer"),Promise.resolve(null);const t=Q?tg(Q,[0,0,0]):[0,0,0],E=C?jI(C,[0,0,0,1]):[0,0,0,1],o=Array.isArray(a)&&a.length===3?[Number(a[0]),Number(a[1]),Number(a[2])]:[1,1,1],r="col-"+this._nextColliderId++,n=this.bodyToColliders.get(B)||new Set;n.add(r),this.bodyToColliders.set(B,n),this.colliderToBody.set(r,B);const s={type:"computeConvexHull",positions:e,indices:i||null,localScale:o},c=[];return e?.buffer&&c.push(e.buffer),i?.buffer&&c.push(i.buffer),this._helperPost(s,c).then(D=>{const d=D?.vertices;if(!(d instanceof Float32Array)||d.length<9)throw new Error("convex hull computation failed or returned insufficient vertices");const h={type:"attachShapeCollider",id:r,bodyId:B,shape:{kind:"convexHull",params:{vertices:d}},local:{p:t,q:E}},u=[];return d?.buffer&&u.push(d.buffer),this._post(h,u).then(()=>r)}).catch(D=>{const d=this.bodyToColliders.get(B);return d&&d.delete(r),this.colliderToBody.delete(r),console.warn("addConvexHullCollider failed:",D),null})}attachShapeCollider({bodyId:B,shape:A,localPosition:g,localRotation:I}){if(!this.rigidBodies.has(B))return console.warn(`attachShapeCollider: unknown bodyId ${B}`),Promise.resolve(null);if(!A||typeof A!="object")return console.warn("attachShapeCollider: missing or invalid shape descriptor"),Promise.resolve(null);const Q=g?tg(g,[0,0,0]):[0,0,0],C=I?jI(I,[0,0,0,1]):[0,0,0,1],a="col-"+this._nextColliderId++,e=this.bodyToColliders.get(B)||new Set;e.add(a),this.bodyToColliders.set(B,e),this.colliderToBody.set(a,B);const i={type:"attachShapeCollider",id:a,bodyId:B,shape:A,local:{p:Q,q:C}};return this._post(i),a}detachCollider({colliderId:B}){const A=this.colliderToBody.get(B);if(!A)return;const g=this.bodyToColliders.get(A);g&&g.delete(B),this.colliderToBody.delete(B),this._post({type:"detachCollider",colliderId:B})}removeObject({bodyId:B}){if(!this.rigidBodies.has(B))return;const A=this.bodyToColliders.get(B);if(A)for(const g of A)this.colliderToBody.delete(g);this.bodyToColliders.delete(B),this.rigidBodies.delete(B),this._post({type:"removeObject",id:B})}applyForce({bodyId:B,force:A,worldPoint:g,wake:I=!0,impulse:Q=!1}){if(!this.rigidBodies.has(B))return void console.warn(`applyForce: unknown bodyId ${B}`);const C=tg(A,[0,0,0]),a=g?tg(g,[0,0,0]):void 0;this._post({type:"applyForce",id:B,force:C,point:a,wake:!!I,impulse:!!Q})}setGravity(B){this.gravity=ke(B),this._post({type:"setGravity",gravity:this.gravity})}setPose({bodyId:B,position:A,rotation:g,wake:I=!0}){if(!this.rigidBodies.has(B))return void console.warn(`setPose: unknown bodyId ${B}`);const Q=A!=null?tg(A,[0,0,0]):null,C=g!=null?jI(g,[0,0,0,1]):null;this._post({type:"setPose",id:B,p:Q,q:C,wake:!!I});const a=this.rigidBodies.get(B);a&&(Q&&(a.last.p=Q.slice(),a.current.p=Q.slice(),a.object?.isObject3D&&a.object.position.set(Q[0],Q[1],Q[2])),C&&(a.last.q=C.slice(),a.current.q=C.slice(),a.object?.isObject3D&&a.object.quaternion.set(C[0],C[1],C[2],C[3])),a.object?.isObject3D&&(a.object.updateMatrices?a.object.updateMatrices():(a.object.matrixAutoUpdate!==!1&&a.object.updateMatrix(),a.object.matrixWorldAutoUpdate!==!1&&a.object.updateMatrixWorld(!0))))}raycast({origin:B,direction:A,maxToi:g=1e6,filter:I}){const Q=tg(B,[0,0,0]),C=tg(A,[0,-1,0]);return this._post({type:"raycast",origin:Q,direction:C,maxToi:g,filter:I||null})}pause(){this._paused=!0}resume(){this._paused&&(this._paused=!1,this._lastTickTime=pB(),this._scheduleNextTick())}setUpdateInterval(B){this.updateIntervalMs=Math.max(1,Number(B)||16)}stepOnce(B){const A=typeof B=="number"?B:this.fixedDt;return this._post({type:"step",dt:A})}update(){if(!this._currentState)return;const B=this._lastState||this._currentState,A=this._currentState,g=pB(),I=B.timeMs||g,Q=A.timeMs||g,C=Math.max(.001,Q-I);let a=Y.MathUtils.clamp((g-Q)/C+1,0,this._interpolationMax);a=Y.MathUtils.clamp(a,0,1);const e=new Y.Quaternion,i=new Y.Quaternion,t=new Y.Quaternion;for(const[E,o]of this.rigidBodies.entries()){const r=B.bodies?.[E],n=A.bodies?.[E];if(!n&&!r)continue;const s=r?.p||o.current.p,c=r?.q||o.current.q,D=n?.p||o.current.p,d=n?.q||o.current.q,h=Y.MathUtils.lerp(s[0],D[0],a),u=Y.MathUtils.lerp(s[1],D[1],a),f=Y.MathUtils.lerp(s[2],D[2],a);e.set(c[0],c[1],c[2],c[3]),i.set(d[0],d[1],d[2],d[3]),t.copy(e).slerp(i,a),o.object&&o.object.isObject3D&&(o.object.position.set(h,u,f),o.object.quaternion.copy(t),o.object.updateMatrices?o.object.updateMatrices():(o.object.matrixAutoUpdate!==!1&&o.object.updateMatrix(),o.object.matrixWorldAutoUpdate!==!1&&o.object.updateMatrixWorld(!0))),o.last={p:s.slice(),q:c.slice()},o.current={p:D.slice(),q:d.slice()}}}dispose(){try{this.worker.terminate()}catch{}try{this.helperWorker?.terminate()}catch{}this.rigidBodies.clear(),this.bodyToColliders.clear(),this.colliderToBody.clear(),this._pending.clear(),this._listeners.clear(),this._lastState=null,this._currentState=null}_scheduleNextTick(){this._paused||setTimeout(()=>this._onTick(),this.updateIntervalMs)}_onTick(){if(this._paused)return;const B=pB();Math.max(1e-6,(B-this._lastTickTime)/1e3),this._lastTickTime=B,this._post({type:"step",dt:this.fixedDt}),this.update(),this._scheduleNextTick()}_onWorkerMessage(B){const A=B.data||{};if(A.replyTo){const g=this._pending.get(A.replyTo);g&&(this._pending.delete(A.replyTo),A.error?g.rej?g.rej(A.error):console.error("Physics worker error:",A.error):g.res&&g.res(A.result))}else switch(A.type){case"state":this._lastState=this._currentState,this._currentState=A.state||null,this._emit("state",this._currentState);break;case"event":this._emit("event",A.event)}}_ensureHelperWorker(){this.helperWorker||(this.helperWorker=new io({}),this.helperWorker.onmessage=this._onHelperMessage,this.helperWorker.onerror=B=>{console.error("Physics helper worker error:",B?.message||B)})}_onHelperMessage(B){const A=B.data||{};if(A.replyTo){const g=this._helperPending.get(A.replyTo);g&&(this._helperPending.delete(A.replyTo),A.error?g.rej?g.rej(A.error):console.error("Physics helper worker error:",A.error):g.res&&g.res(A.result))}}_helperPost(B,A=[]){this._ensureHelperWorker();const g=++this._helperMsgId,I={...B,_envId:g};return this.helperWorker.postMessage(I,A),new Promise((Q,C)=>{this._helperPending.set(g,{res:Q,rej:C})})}_post(B,A=[]){const g=++this._msgId,I={...B,_envId:g};return this.worker.postMessage(I,A),new Promise((Q,C)=>{this._pending.set(g,{res:Q,rej:C})})}on(B,A){return this._listeners.has(B)||this._listeners.set(B,new Set),this._listeners.get(B).add(A),()=>this.off(B,A)}off(B,A){const g=this._listeners.get(B);g&&g.delete(A)}_emit(B,A){const g=this._listeners.get(B);if(g)for(const I of g)try{I(A)}catch(Q){console.error(Q)}}},ZA.SplatsMesh=be,ZA.TileLoader=ZC,ZA.getOGC3DTilesCopyrightInfo=Me,ZA.splatsFragmentShader=fe,ZA.splatsVertexShader=we,Object.defineProperty(ZA,Symbol.toStringTag,{value:"Module"})});
1502
+ }`}function Ao(B,A,g,I){const Q=B.getX(g),C=B.getY(g),a=B.getZ(g),e=A.getX(g),i=A.getY(g),t=A.getZ(g);I.set(Q,C,a,C,e,i,a,i,t)}function go(B,A,g){const I=B.determinant();if(Math.abs(I)<1e-12)return void g.set(0,0,0);const Q=1/I,C=new l.Matrix3().copy(B);C.elements[0]=A.x,C.elements[3]=A.y,C.elements[6]=A.z;const a=new l.Matrix3().copy(B);a.elements[1]=A.x,a.elements[4]=A.y,a.elements[7]=A.z;const e=new l.Matrix3().copy(B);e.elements[2]=A.x,e.elements[5]=A.y,e.elements[8]=A.z,g.set(C.determinant()*Q,a.determinant()*Q,e.determinant()*Q)}function KI(B,A){if(!A||Array.isArray(A)&&A.length!==3)throw new Error(`${B} must be a length-3 array [x,y,z]`);return A}function Fe(B,A,g){return{kind:"cuboid",params:{hx:Number(B),hy:Number(A),hz:Number(g)}}}const GQ={createBall:function(B){return{kind:"ball",params:{radius:Number(B)}}},createCuboid:Fe,createBox:function(B,A,g){return Fe(B,A,g)},createRoundCuboid:function(B,A,g,I){return{kind:"roundCuboid",params:{hx:Number(B),hy:Number(A),hz:Number(g),radius:Number(I)}}},createCapsule:function(B,A){return{kind:"capsule",params:{halfHeight:Number(B),radius:Number(A)}}},createCone:function(B,A){return{kind:"cone",params:{halfHeight:Number(B),radius:Number(A)}}},createCylinder:function(B,A){return{kind:"cylinder",params:{halfHeight:Number(B),radius:Number(A)}}},createSegment:function(B,A){return{kind:"segment",params:{a:KI("a",B),b:KI("b",A)}}},createTriangle:function(B,A,g){return{kind:"triangle",params:{a:KI("a",B),b:KI("b",A),c:KI("c",g)}}},createPolyline:function(B,A){return{kind:"polyline",params:{vertices:B,indices:A||null}}},createConvexHull:function(B){return{kind:"convexHull",params:{vertices:B}}},createHeightfield:function(B,A,g,I={x:1,y:1,z:1}){return{kind:"heightfield",params:{rows:Number(B),cols:Number(A),heights:g,scale:I}}}};var FA;const Fg=new Y.Sphere(new Y.Vector3(0,0,0),1),Jg=new ag([0,0,0,1,0,0,0,1,0,0,0,1]);new Y.Box3;const Pg=new Y.Vector3(0,0,0),GI=new Y.Vector3(0,0,0),Io=new Y.Vector3(0,1,0),wB=new Y.Ray,fB=new Y.Matrix4;new Y.Matrix4,new Y.Frustum;const yB=new Y.Vector3,FB=[],pe=new Y.Quaternion,kg={};function Me(){var B=[];for(let A in kg)kg.hasOwnProperty(A)&&kg[A]>0&&B.push(A);return B}class RQ extends Y.Object3D{constructor(A){super();const g=this;g.physics=A.physics||{};const I=g.physics;if(I&&typeof I=="object"&&(I.type||(I.type="fixed"),I.shape==null&&(I.shape="none"),I.mass==null&&(I.mass=1),Array.isArray(I.velocity)||I.velocity&&I.velocity.isVector3||(I.velocity=[0,0,0]),Array.isArray(I.angularVelocity)||I.angularVelocity&&I.angularVelocity.isVector3||(I.angularVelocity=[0,0,0]),I.maxLOD==null&&(I.maxLOD=1/0),I.colliders&&typeof I.colliders=="object")){const e=I.colliders;e.maxLOD==null&&(e.maxLOD=Number.isFinite(I.maxLOD)?I.maxLOD:1/0),Array.isArray(e.priority)?(e.priority=e.priority.filter(i=>i==="mesh"||i==="hull"||i==="bounds"),e.priority.length===0&&(e.priority=["mesh","hull","bounds"])):e.priority=["mesh","hull","bounds"],Array.isArray(e.byGeometricError)||(e.byGeometricError=[]),Array.isArray(e.byLevel)||(e.byLevel=[])}if(g.splatsMesh=A.splatsMesh,g.oldUltraMeshSplats=A.oldUltraMeshSplats,g.iosCompatibility=A.iosCompatibility,g.splatsQuality=A.splatsQuality!=null?A.splatsQuality:.75,g.splatsCPUCulling=A.splatsCPUCulling!=null&&A.splatsCPUCulling,this.contentURL=[],A.domWidth&&A.domHeight?this.rendererSize=new Y.Vector2(A.domWidth,A.domHeight):this.rendererSize=new Y.Vector2(1e3,1e3),this.setClipShape(A.clipShape),this.loadingStrategy=A.loadingStrategy?A.loadingStrategy.toUpperCase():"INCREMENTAL",this.distanceBias=Math.max(1e-4,A.distanceBias?A.distanceBias:1),this.proxy=A.proxy,this.drawBoundingVolume=!!A.drawBoundingVolume&&A.drawBoundingVolume,this.displayErrors=A.displayErrors,this.displayCopyright=A.displayCopyright,A.queryParams&&(this.queryParams={...A.queryParams}),this.uuid=Aa(),A.tileLoader)this.tileLoader=A.tileLoader;else{const e={};e.meshCallback=A.meshCallback?A.meshCallback:(t,E)=>{t.material.wireframe=!1,t.material.side=Y.DoubleSide},e.pointsCallback=A.pointsCallback?A.pointsCallback:(t,E)=>{t.material.size=Math.pow(E,.33),t.material.sizeAttenuation=!0},e.proxy=this.proxy,e.renderer=A.renderer,e.dracoLoader=A.dracoLoader,e.ktx2Loader=A.ktx2Loader,g.tileLoader=new ZC(e);const i=this.update;this.update=t=>{i.call(g,t),g.tileLoader.update()}}this.displayCopyright=!!A.displayCopyright,this.geometricErrorMultiplier=A.geometricErrorMultiplier?A.geometricErrorMultiplier:1,this.splatsCropRadius=Number.MAX_VALUE,this.splatsSizeMultiplier=1,this.splatsExposureEV=A&&A.splatsExposureEV!==void 0?A.splatsExposureEV:0,this.splatsSaturation=A&&A.splatsSaturation!==void 0?A.splatsSaturation:1,this.splatsContrast=A&&A.splatsContrast!==void 0?A.splatsContrast:1;const Q=A&&A.splatsTempTint!==void 0?A.splatsTempTint:[0,0];if(this.splatsTempTint=Array.isArray(Q)?[Number(Q[0]||0),Number(Q[1]||0)]:[Number(Q.temp||0),Number(Q.tint||0)],this.renderer=A.renderer,this.meshCallback=A.meshCallback,this.loadOutsideView=A.loadOutsideView,this.cameraOnLoad=A.cameraOnLoad,this.parentTile=A.parentTile,this.occlusionCullingService=A.occlusionCullingService,this.static=A.static,this.occlusionCullingService&&(this.color=new Y.Color,this.color.setHex(16777215*Math.random()),this.colorID=Y.MathUtils.clamp(255*g.color.r,0,255)<<16^Y.MathUtils.clamp(255*g.color.g,0,255)<<8^Y.MathUtils.clamp(255*g.color.b,0,255)),this.static&&(this.matrixAutoUpdate=!1,this.matrixWorldAutoUpdate=!1),this.childrenTiles=[],this.meshContent=[],this.tileContent,this.refine,this.rootPath,this.geometricError,this.boundingVolume,this.json,this.materialVisibility=!1,this.level=A.level?A.level:0,this.hasMeshContent=0,this.hasUnloadedJSONContent=0,this.centerModel=A.centerModel,this.abortController=new AbortController,this.onLoadCallback=A.onLoadCallback,A.json)g._setup(A);else if(A.url){var C=A.url;if(g.queryParams){var a="";for(let e in g.queryParams)g.queryParams.hasOwnProperty(e)&&(a+="&"+e+"="+g.queryParams[e]);C.includes("?")?C+=a:C+="?"+a.substring(1)}(g.proxy?()=>fetch(g.proxy,{method:"POST",body:C,signal:g.abortController.signal}):()=>fetch(C,{signal:g.abortController.signal}))().then(e=>{if(!e.ok)throw new Error(`couldn't load "${A.url}". Request failed with status ${e.status} : ${e.statusText}`);e.json().then(i=>AQ(i,C)).then(i=>{g._setup({rootPath:BI.dirname(A.url),json:i})})}).catch(e=>{g.displayErrors&&Ge(e)})}}setClipShape(A){if(A instanceof ag||A instanceof Y.Sphere)this.clipShape=A;else if(A instanceof Y.Box3){const g=new Y.Vector3,I=new Y.Vector3;A.getCenter(g),A.getSize(I).multiplyScalar(.5),this.clipShape=new ag([g.x,g.y,g.z,I.x,0,0,0,I.y,0,0,0,I.z])}else A=void 0;this.childrenTiles&&this.childrenTiles.forEach(g=>{g._setClipShape(this.clipShape)})}_setClipShape(A){this.clipShape=A,this.childrenTiles&&this.childrenTiles.forEach(g=>{g._setClipShape(this.clipShape)})}setSplatsSizeMultiplier(A){this.splatsSizeMultiplier=A,this.splatsMesh&&this.splatsMesh.setSplatsSizeMultiplier(this.splatsSizeMultiplier)}setSplatsCropRadius(A){this.splatsCropRadius=A,this.splatsMesh&&this.splatsMesh.setSplatsCropRadius(this.splatsCropRadius)}setSplatsDepthBias(A){this.splatsDepthBias=A,this.splatsMesh&&this.splatsMesh.setDepthBias(this.splatsDepthBias)}setSplatsCPUCulling(A){this.splatsCPUCulling=A,this.splatsMesh&&this.splatsMesh.setSplatsCPUCulling(A)}setSplatsQuality(A){this.splatsQuality=A,this.splatsMesh&&this.splatsMesh.setQuality(A)}setSplatsExposureEV(A){this.splatsExposureEV=A,this.splatsMesh&&typeof this.splatsMesh.setExposureEV=="function"&&this.splatsMesh.setExposureEV(A)}setSplatsSaturation(A){this.splatsSaturation=A,this.splatsMesh&&typeof this.splatsMesh.setSaturation=="function"&&this.splatsMesh.setSaturation(A)}setSplatsContrast(A){this.splatsContrast=A,this.splatsMesh&&typeof this.splatsMesh.setContrast=="function"&&this.splatsMesh.setContrast(A)}setSplatsTempTint(A,g){this.splatsTempTint=[A,g],this.splatsMesh&&typeof this.splatsMesh.setTempTint=="function"&&this.splatsMesh.setTempTint(A,g)}updateMatrices(){this.updateMatrix(),this.splatsMesh&&this.splatsMesh.updateMatrix(),this.static&&(this.traverse(A=>{A.isObject3D&&(A.matrixWorldAutoUpdate=!0)}),this.splatsMesh&&(this.splatsMesh.matrixWorldAutoUpdate=!0)),this.updateMatrixWorld(!0),this.static&&(this.traverse(A=>{A.isObject3D&&(A.matrixWorldAutoUpdate=!1)}),this.splatsMesh&&(this.splatsMesh.matrixWorldAutoUpdate=!1))}setCanvasSize(A,g){this.rendererSize.set(A,g)}async _setup(A){const g=this;if(A.json.extensionsRequired&&(A.json.extensionsRequired.includes("JDULTRA_gaussian_splats")||A.json.extensionsRequired.includes("JDULTRA_gaussian_splats_V2"))&&(g.oldUltraMeshSplats=!0),A.json.root?(g.json=A.json.root,g.json.refine||(g.json.refine=A.json.refine),g.json.geometricError||(g.json.geometricError=A.json.geometricError),g.json.transform||(g.json.transform=A.json.transform),g.json.boundingVolume||(g.json.boundingVolume=A.json.boundingVolume)):g.json=A.json,g.json.children||(g.json.getChildren?g.json.children=await g.json.getChildren():g.json.children=[]),g.rootPath=A.json.rootPath?A.json.rootPath:A.rootPath,g.json.refine?g.refine=g.json.refine:g.refine=A.parentRefine,g.json.geometricError?g.geometricError=g.json.geometricError:g.geometricError=A.parentGeometricError,g.json.transform){let Q=new Y.Matrix4;Q.elements=g.json.transform,g.applyMatrix4(Q)}if(g.json.boundingVolume)if(g.json.boundingVolume.box)g.boundingVolume=new ag(g.json.boundingVolume.box);else if(g.json.boundingVolume.region){const Q=g.json.boundingVolume.region;g._transformWGS84ToCartesian(Q[0],Q[1],Q[4],Pg),g._transformWGS84ToCartesian(Q[2],Q[3],Q[5],GI),Pg.lerp(GI,.5),g.boundingVolume=new Y.Sphere(new Y.Vector3(Pg.x,Pg.y,Pg.z),Pg.distanceTo(GI))}else if(g.json.boundingVolume.sphere){const Q=g.json.boundingVolume.sphere;g.boundingVolume=new Y.Sphere(new Y.Vector3(Q[0],Q[1],Q[2]),Q[3])}else g.boundingVolume=A.parentBoundingVolume;else g.boundingVolume=A.parentBoundingVolume;function I(Q){Q.uri&&Q.uri.includes("json")||Q.url&&Q.url.includes("json")?g.hasUnloadedJSONContent++:g.hasMeshContent++}if(g.json.content?(I(g.json.content),g.hasMeshContent==0&&(g.level=Math.max(0,g.parentTile?g.parentTile.level+.01:0)),g._load()):g.json.contents&&(g.json.contents.forEach(Q=>I(Q)),g.hasMeshContent==0&&(g.level=Math.max(0,g.parentTile?g.parentTile.level+.01:0))),g.centerModel&&(GI.copy(g.boundingVolume.center),this.json.boundingVolume.region&&(this._transformWGS84ToCartesian(.5*(this.json.boundingVolume.region[0]+this.json.boundingVolume.region[2]),.5*(this.json.boundingVolume.region[1]+this.json.boundingVolume.region[3]),.5*(this.json.boundingVolume.region[4]+this.json.boundingVolume.region[5]),Pg),pe.setFromUnitVectors(Pg.normalize(),Io.normalize()),g.applyQuaternion(pe)),GI.applyMatrix4(g.matrix),g.position.sub(GI),g.updateMatrices()),g.onLoadCallback&&g.onLoadCallback(g),!g.parentTile&&g.physics&&g.physics.sim&&(g.physics.rigidBodyID=g.physics.sim.addObject({object:g,type:g.physics.type,mass:g.physics.mass,position:g.position,rotation:g.quaternion,velocity:g.physics.velocity,angularVelocity:g.physics.angularVelocity})),g.isSetup=!0,g.level>0&&g.drawBoundingVolume)if(g.bbox&&console.log("double setup"),this.boundingVolume.aabb){let Q=this.boundingVolume.aabb.clone();Q.applyMatrix4(this.matrixWorld),g.bbox=new Y.Box3Helper(Q,new Y.Color(Math.random(),Math.random(),Math.random())),g.add(g.bbox),g.bbox.material.visible=!1}else g.boundingVolume instanceof ag&&(g.bbox=g.boundingVolume.helper(),g.add(g.bbox),g.bbox.material.visible=!1)}_assembleURL(A,g){A.endsWith("/")||(A+="/");try{const I=new URL(A);let Q=I.pathname.split("/").filter(a=>a!==""),C=g.split("/").filter(a=>a!=="");for(let a=1;a<=Q.length&&!(a>=C.length);a++)if(Q.slice(Q.length-a,Q.length).join("/")===C.slice(0,a).join("/")){for(let i=0;i<a;i++)Q.pop();break}for(;C.length>0&&C[0]==="..";)Q.pop(),C.shift();return`${I.protocol}//${I.host}/${[...Q,...C].join("/")}`}catch{return A.endsWith("/")||g.startsWith("/")?A+g:A+"/"+g}}_extractQueryParams(A,g){try{const I=new URL(A);for(let[Q,C]of I.searchParams)g[Q]=C;return I.search="",I.toString()}catch{return A}}async _load(A=!0,g=!0){var I=this;if(!I.deleted||!g){if(I.json.content)await Q(I.json.content,null,A,g);else if(I.json.contents){let C=I.json.contents.map((a,e)=>Q(a,e,A,g));Promise.all(C)}}async function Q(C,a,e,i){let t;C.uri?t=C.uri:C.url&&(t=C.url);const E=/^(?:http|https|ftp|tcp|udp):\/\/\S+/;if(E.test(I.rootPath)?E.test(t)||(t=I._assembleURL(I.rootPath,t)):t=I.rootPath+BI.sep+t,t.startsWith("/local-tiles")||(t=I._extractQueryParams(t,I.queryParams)),I.queryParams){var o="";for(let r in I.queryParams)I.queryParams.hasOwnProperty(r)&&(o+="&"+r+"="+I.queryParams[r]);t.includes("?")?t+=o:t+="?"+o.substring(1)}if(t)if(I.contentURL.push(t),i&&(t.includes(".b3dm")||t.includes(".glb")||t.includes(".gltf")))try{I.tileLoader.get(I.abortController,I.uuid,t,r=>{if(!I.deleted){if(r.asset&&r.asset.copyright&&(r.asset.copyright.split(";").forEach(n=>{kg[n]?kg[n]++:kg[n]=1}),I.displayCopyright&&NQ()),r.isSplatsData){if(!I.splatsMesh){if(I.splatsMesh=new be(I.tileLoader.renderer,void 0,void 0,I.oldUltraMeshSplats?.25:1),I.splatsMesh.setQuality(I.splatsQuality),I.splatsMesh.setSplatsCPUCulling(I.splatsCPUCulling),I.splatsMesh.setSplatsCropRadius(I.splatsCropRadius),I.splatsMesh.setSplatsSizeMultiplier(I.splatsSizeMultiplier),I.splatsExposureEV!==void 0&&typeof I.splatsMesh.setExposureEV=="function"&&I.splatsMesh.setExposureEV(I.splatsExposureEV),I.splatsSaturation!==void 0&&typeof I.splatsMesh.setSaturation=="function"&&I.splatsMesh.setSaturation(I.splatsSaturation),I.splatsContrast!==void 0&&typeof I.splatsMesh.setContrast=="function"&&I.splatsMesh.setContrast(I.splatsContrast),I.splatsTempTint!==void 0&&typeof I.splatsMesh.setTempTint=="function"){const n=I.splatsTempTint||[0,0];I.splatsMesh.setTempTint(n[0],n[1])}I.static&&(I.splatsMesh.matrixAutoUpdate=!1,I.splatsMesh.matrixWorldAutoUpdate=!1),I.add(I.splatsMesh),I.updateMatrices()}r=I.splatsMesh.addSplatsTile(r.positions,r.colors,r.cov0,r.cov1)}return r.isSplatsBatch||(r.traverse(n=>{if((n.isMesh||n.isPoints)&&n.layers.disable(0),n.isMesh&&I.occlusionCullingService){const s=n.geometry.attributes.position,c=[];for(let D=0;D<s.count;D++)c.push(I.color.r,I.color.g,I.color.b);n.geometry.setAttribute("color",new Y.Float32BufferAttribute(c,3))}}),I.add(r),I.updateMatrices()),I.meshContent.push(r),r}},I.cameraOnLoad?()=>I.loadingStrategy=="IMMEDIATE"?I._calculateDistanceToCamera(I.cameraOnLoad):I.loadingStrategy=="INCREMENTAL"?I.parentTile?I.parentTile._calculateDistanceToCamera(I.cameraOnLoad)/Math.max(1,I.parentTile.level):I._calculateDistanceToCamera(I.cameraOnLoad)/Math.max(1,I.level):I.loadingStrategy=="PERLEVEL"?I.parentTile?I.level+I.parentTile._calculateDistanceToCamera(I.cameraOnLoad):I.level+I._calculateDistanceToCamera(I.cameraOnLoad):0:()=>0,()=>I._getSiblings(),I.level,I.loadingStrategy,!I.json.boundingVolume.region,!!I.json.boundingVolume.region,I.geometricError,I.oldUltraMeshSplats)}catch(r){I.displayErrors&&Ge(r)}else e&&t.includes(".json")&&(I.jsonRequested=t,I.tileLoader.get(I.abortController,I.uuid,t,async r=>{I.jsonReceived=!0,r.rootPath=BI.dirname(t),I.json.children.push(r),a==null?delete I.json.content:I.json.contents.splice(a,1),I.hasUnloadedJSONContent--}))}}dispose(){const A=this;if(A.physics&&A.physics.sim&&(A.colliderUUID&&(A.physics.sim.detachCollider({colliderId:A.colliderUUID}),A.colliderUUID=void 0),Array.isArray(A.colliderUUIDs)&&A.colliderUUIDs.length)){for(const g of A.colliderUUIDs)A.physics.sim.detachCollider({colliderId:g});A.colliderUUIDs=[]}A.meshContent.forEach(g=>{g&&g.asset&&g.asset.copyright&&(g.asset.copyright.split(";").forEach(I=>{kg[I]&&kg[I]--}),A.displayCopyright&&NQ())}),A.childrenTiles.forEach(g=>g.dispose()),A.deleted=!0,A.splatsMesh&&(A.meshContent.forEach(g=>g.hide()),A.parentTile||(A.splatsMesh.dispose(),A.splatsMesh=void 0)),A.contentURL&&(A.contentURL.forEach(g=>{A.tileLoader.invalidate(g,A.uuid)}),A.contentURL=[]),A.abortController&&!A.jsonRequested&&A.abortController.abort("tile not needed"),this.parent=null,A.meshContent=[],A.bbox&&A.bbox.dispose(),this.dispatchEvent({type:"removed"})}_disposeMeshContent(){const A=this;if(!A.deleted){A.deleted=!0,A.abortController&&(A.abortController.abort("tile not needed"),A.abortController=new AbortController);for(let g=A.meshContent.length-1;g>=0;g--){const I=A.meshContent[g];I&&I.asset&&I.asset.copyright&&(I.asset.copyright.split(";").forEach(Q=>{kg[Q]&&kg[Q]--}),A.displayCopyright&&NQ()),A.remove(I)}A.splatsMesh&&A.meshContent.forEach(g=>g.hide()),A.meshContent=[],A.contentURL.forEach(g=>{A.tileLoader.invalidate(g,A.uuid)}),A.contentURL=[]}}_disposeChildren(){var A=this;A.childrenTiles.forEach(g=>{g.dispose(),A.remove(g)}),A.childrenTiles=[]}raycast(A,g){if(this.splatsMesh){wB.copy(A.ray),fB.copy(this.matrixWorld).invert(),wB.applyMatrix4(fB);let I=!1;if(this.boundingVolume instanceof ag)I=this.boundingVolume.intersectsRay(wB);else{if(!(this.boundingVolume instanceof Y.Sphere))return!1;I=ray.intersectsSphere(this.boundingVolume)}return I&&this.materialVisibility&&this.splatsReady&&(FB.length=0,this.meshContent.forEach(Q=>{Q.isSplatsBatch&&(Q.raycast(wB,FB,A.params.Points.threshold),FB.forEach(C=>{C.point.applyMatrix4(this.matrixWorld)}),g.push(...FB))})),I}return super.raycast(A,g)}update(A){this.splatsMesh&&this.splatsMesh.updateShaderParams(A,this.renderer);const g=new Y.Frustum;g.setFromProjectionMatrix(new Y.Matrix4().multiplyMatrices(A.projectionMatrix,A.matrixWorldInverse));let I=[0],Q=[0],C=[0],a=[0];if(this.refine=="REPLACE"?this.loadingStrategy==="IMMEDIATE"?(this._updateImmediate(A,g),this._statsImmediate(C,I,a,Q)):(this._update(A,g),this._stats(C,I,a,Q)):(this._update(A,g),this._stats(C,I,a,Q)),I>0&&(a[0]/=I[0]),this.splatsMesh)if(yB.copy(A.position),fB.copy(this.matrixWorld).invert(),yB.applyMatrix4(fB),this.splatsCPUCulling){const e=new Y.Matrix4().multiplyMatrices(A.projectionMatrix,A.matrixWorldInverse).multiply(this.matrixWorld);this.splatsMesh.sort(yB,e)}else this.splatsMesh.sort(yB);return this.splatsMesh&&this.splatsMesh.update(),{numTilesLoaded:I[0],numTilesRendered:Q[0],maxLOD:C[0],percentageLoaded:a[0]}}_updateImmediate(A,g){this._computeMetricRecursive(A,g),this._updateNodeVisibilityImmediate(),this._expandTreeImmediate(A),this.shouldBeVisible=this.metric>0||!!this.loadOutsideView,this._shouldBeVisibleUpdateImmediate(),this._trimTreeImmediate(),this._loadMeshImmediate()}_statsImmediate(A,g,I,Q){A[0]=Math.max(A[0],this.level),(this.shouldBeVisible||this.materialVisibility)&&(g[0]++,this.materialVisibility&&I[0]++),this.materialVisibility&&Q[0]++,this.childrenTiles.forEach(C=>{C._statsImmediate(A,g,I,Q)})}_stats(A,g,I,Q){A[0]=Math.max(A[0],this.level),this.hasMeshContent&&(g[0]++,this.meshContent.length==this.hasMeshContent&&I[0]++,this.materialVisibility&&Q[0]++),this.childrenTiles.forEach(C=>{C._stats(A,g,I,Q)})}_trimTreeImmediate(){const A=this;if(A.metric!=null)if(A.hasMeshContent&&A.shouldBeVisible&&A.materialVisibility){if(A.splatsMesh&&!A.splatsReady)return;A._disposeChildren()}else A.childrenTiles.forEach(g=>{g._trimTreeImmediate()})}_updateNodeVisibilityImmediate(A=!1){const g=this;if(g.hasMeshContent)if(g.shouldBeVisible)g.meshContent.length==g.hasMeshContent?g.materialVisibility?g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(!0)}):(g._changeContentVisibility(!0),g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(A)})):g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(A)});else{if(!g.loadOutsideView&&g.metric<0)return g._changeContentVisibility(!1),g.meshContent.length>0&&g._disposeMeshContent(),void g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(!0)});if(!g.materialVisibility||g.splatsMesh&&!g.splatsReady)g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(A)});else if(A)g._changeContentVisibility(!1),g.meshContent.length>0&&g._disposeMeshContent(),g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(A)});else{let I=!0;g.childrenTiles.every(Q=>!!Q._isReadyImmediate()||(I=!1,!1)),I&&g.childrenTiles.length>0?(g._changeContentVisibility(!1),g.meshContent.length>0&&g._disposeMeshContent(),g.childrenTiles.forEach(Q=>{Q._updateNodeVisibilityImmediate(A)})):g.childrenTiles.forEach(Q=>{Q._updateNodeVisibilityImmediate(!g.splatsMesh||!!g.splatsReady)})}}else g.childrenTiles.forEach(I=>{I._updateNodeVisibilityImmediate(A)})}_shouldBeVisibleUpdateImmediate(){const A=this;A.hasMeshContent?A.metric==null?A.shouldBeVisible=!1:A.metric<0?(A.shouldBeVisible=!!A.loadOutsideView,A.childrenTiles.forEach(g=>{g._setShouldNotBeVisibleRecursive()})):A.metric<A.geometricErrorMultiplier*A.geometricError?A.hasUnloadedJSONContent||(A.json&&A.json.children&&A.json.children.length>0?(A.shouldBeVisible=!1,A.childrenTiles.forEach(g=>{g.shouldBeVisible=!0,g._shouldBeVisibleUpdateImmediate()})):A.shouldBeVisible=!0):A.childrenTiles.forEach(g=>{g._setShouldNotBeVisibleRecursive()}):(A.childrenTiles.forEach(g=>{g.shouldBeVisible=!0,g._shouldBeVisibleUpdateImmediate()}),A.shouldBeVisible=!1)}_setShouldNotBeVisibleRecursive(){this.shouldBeVisible=!1,this.childrenTiles.forEach(A=>{A._setShouldNotBeVisibleRecursive()})}_loadMeshImmediate(){const A=this;A.hasMeshContent&&A.shouldBeVisible?A.meshContent.length<A.hasMeshContent&&A.contentURL.length==0&&(A.deleted=!1,A._load(!1,!0)):A.childrenTiles.forEach(g=>{g._loadMeshImmediate()})}_computeMetricRecursive(A,g){const I=this;I.metric=-1,I.isSetup&&(I.boundingVolume&&I.geometricError&&(I.metric=I._calculateUpdateMetric(A,g)),I.childrenTiles.forEach(Q=>Q._computeMetricRecursive(A,g)))}_expandTreeImmediate(A){const g=this;g.hasUnloadedJSONContent||(g.hasMeshContent?g.occlusionCullingService&&g.hasMeshContent&&!g.occlusionCullingService.hasID(g.colorID)||g.metric>=0&&g.metric<g.geometricErrorMultiplier*g.geometricError&&g.json&&g.json.children&&g.childrenTiles.length<g.json.children.length&&g._loadJsonChildren(A):g.json&&g.json.children&&g.childrenTiles.length<g.json.children.length&&g._loadJsonChildren(A)),g.childrenTiles.forEach(I=>I._expandTreeImmediate(A))}_update(A,g){const I=this;if(!I.isSetup)return;const Q=I.materialVisibility;I.boundingVolume&&I.geometricError&&(I.metric=I._calculateUpdateMetric(A,g)),I.childrenTiles.forEach(C=>C._update(A,g)),function(C){if(C<0)return I.inFrustum=!1,void I._changeContentVisibility(!!I.loadOutsideView);if(I.inFrustum=!0,!!I.hasMeshContent&&!(I.meshContent.length<I.hasMeshContent)){if(I.childrenTiles.length==0)return void I._changeContentVisibility(!0);if(C>=I.geometricErrorMultiplier*I.geometricError)I._changeContentVisibility(!0);else if(C<I.geometricErrorMultiplier*I.geometricError&&I.refine=="REPLACE"){let a=!0;I.childrenTiles.every(e=>!!e._isReady()||(a=!1,!1)),a?I._changeContentVisibility(!1):I._changeContentVisibility(!0)}}}(I.metric),function(C){C<0&&I.hasMeshContent||I.occlusionCullingService&&I.hasMeshContent&&!I.occlusionCullingService.hasID(I.colorID)||(!I.hasMeshContent||C<=I.geometricErrorMultiplier*I.geometricError&&(I.meshContent.length>0||I.splatsMesh))&&I.json&&I.json.children&&I.childrenTiles.length!=I.json.children.length&&I._loadJsonChildren(A)}(I.metric),function(C,a){if(I.hasMeshContent){if(!I.inFrustum)return void I._disposeChildren();if(I.occlusionCullingService&&!a&&I.hasMeshContent&&I.meshContent.length>0&&I.materialVisibility&&I._areAllChildrenLoadedAndHidden())return I.splatsMesh&&I.materialVisibility&&!I.splatsReady?void 0:void I._disposeChildren();if(C>=I.geometricErrorMultiplier*I.geometricError){if(I.splatsMesh&&I.materialVisibility&&!I.splatsReady)return;I._disposeChildren()}}}(I.metric,Q)}_loadJsonChildren(A){const g=this;for(let I=g.json.children.length-1;I>=0;I--)g.json.children[I].root||g.json.children[I].children||g.json.children[I].getChildren||g.json.children[I].content||g.json.children[I].contents||g.json.children.splice(I,1);g.json.children.forEach(I=>{let Q=new RQ({parentTile:g,queryParams:g.queryParams,parentGeometricError:g.geometricError,parentBoundingVolume:g.boundingVolume,parentRefine:g.refine,json:I,rootPath:g.rootPath,geometricErrorMultiplier:g.geometricErrorMultiplier,loadOutsideView:g.loadOutsideView,level:Math.floor(g.level)+1,tileLoader:g.tileLoader,cameraOnLoad:A,occlusionCullingService:g.occlusionCullingService,renderer:g.renderer,static:g.static,centerModel:!1,displayErrors:g.displayErrors,displayCopyright:g.displayCopyright,distanceBias:g.distanceBias,loadingStrategy:g.loadingStrategy,drawBoundingVolume:g.drawBoundingVolume,splatsMesh:g.splatsMesh,clipShape:g.clipShape,oldUltraMeshSplats:g.oldUltraMeshSplats,physics:g.physics});g.childrenTiles.push(Q),g.add(Q)}),g.updateMatrices(!0)}_areAllChildrenLoadedAndHidden(){let A=!0;const g=this;return this.childrenTiles.every(I=>{if(I.hasMeshContent){if(I.childrenTiles.length>0)return A=!1,!1;if(I.metric<0)return!0;if(I.materialVisibility&&(!g.splatsMesh||g.splatsReady)||g.occlusionCullingService.hasID(I.colorID))return A=!1,!1}else if(!I._areAllChildrenLoadedAndHidden())return A=!1,!1;return!0}),A}_isReady(){if(this.metric==null)return!1;if(this.metric<0)return!0;if(this.hasUnloadedJSONContent)return!1;if(!this.hasMeshContent&&this.json.children.length==0&&!this.hasUnloadedJSONContent)return!0;if(!this.hasMeshContent||this.meshContent.length==0||!this.materialVisibility){if(this.children.length>0){var A=!0;return this.childrenTiles.every(g=>!!g._isReady()||(A=!1,!1)),A}return!1}return!this.hasMeshContent||!(this.meshContent.length<this.hasMeshContent)&&!!this.materialVisibility}_isReadyImmediate(){if(this.materialVisibility||!this.loadOutsideView&&this.metric<0)return!0;if(this.childrenTiles.length>0){var A=!0;return this.childrenTiles.every(g=>!!g._isReadyImmediate()||(A=!1,!1)),A}return!1}_changeContentVisibility(A){const g=this;if(g.materialVisibility!=A){if(g.bbox&&(g.bbox.material.visible=A),g.splatsMesh)A!=g.materialVisibility&&(g.meshContent.forEach(I=>{A&&I.isSplatsBatch?I.show(()=>{g.materialVisibility&&(g.splatsReady=!0)}):(I.hide(),g.splatsReady=!1)}),g.materialVisibility=A);else{if(g.hasMeshContent&&g.meshContent.length>0&&(A?g.meshContent.forEach(I=>{I.traverse(Q=>{(Q.isMesh||Q.isPoints)&&Q.layers.enable(0)})}):g.meshContent.forEach(I=>{I.traverse(Q=>{(Q.isMesh||Q.isPoints)&&Q.layers.disable(0)})})),g.materialVisibility==A)return;g.materialVisibility=A}g._updateCollider()}}setPose(A,g,I){if(!A.isVector3)throw new TypeError("OGC3DTile.setPose: 'position' must be an instance of THREE.Vector3");if(!I.isVector3)throw new TypeError("OGC3DTile.setPose: 'scale' must be an instance of THREE.Vector3");if(!g.isEuler&&!g.isQuaternion)throw new TypeError("OGC3DTile.setPose: 'rotation' must be a THREE.Euler or THREE.Quaternion");this.physics&&this.physics.sim&&this.physics.rigidBodyID?(this.physics.sim.setPose({bodyId:this.physics.rigidBodyID,position:A,rotation:g}),I&&!I.equals(this.scale)&&(this.scale.copy(I),this.updateMatrices(),this.traverse(Q=>{Q._updateCollider&&Q._updateCollider()}))):(this.scale.copy(I),g.isQuaternion?this.setRotationFromQuaternion(g):this.setRotationFromEuler(g),this.position.copy(A),this.updateMatrices())}_updateCollider(){const A=this;if(!A.physics||!A.physics.sim)return;const g=A.physics.rigidBodyID,I=Math.floor(A.level||0),Q=!!A.materialVisibility,C=Array.isArray(A.childrenTiles)&&A.childrenTiles.length>0,a=A.physics&&A.physics.colliders&&typeof A.physics.colliders=="object"?A.physics.colliders:null,e=Number.isFinite(a?.maxLOD)?a.maxLOD:Number.isFinite(A.physics.maxLOD)?A.physics.maxLOD:1/0,i=(G,N)=>{const F=Array.isArray(N)&&N.length?N:["mesh","hull","bounds"];for(const k of F)if(G.includes(k))return k;return null},t=()=>{const G=a?.priority||["mesh","hull","bounds"];if(a&&Array.isArray(a.byGeometricError)&&a.byGeometricError.length){const N=A.geometricError;if(typeof N=="number"){const F=[];for(const m of a.byGeometricError){if(!m||!m.shape)continue;const S=typeof m.min=="number"?m.min:-1/0,j=typeof m.max=="number"?m.max:1/0;N>=S&&N<j&&F.push(m.shape)}const k=i(F,G);if(k)return k}return a.defaultShape?a.defaultShape:A.physics.shape?A.physics.shape:"none"}if(a&&Array.isArray(a.byLevel)&&a.byLevel.length){const N=Math.floor(A.level||0),F=[];for(const m of a.byLevel){if(!m||!m.shape)continue;const S=typeof m.min=="number"?m.min:-1/0,j=typeof m.max=="number"?m.max:1/0;N>=S&&N<=j&&F.push(m.shape)}return i(F,G)||(a.defaultShape?a.defaultShape:A.physics.shape?A.physics.shape:"none")}return A.physics.shape||"none"},E=t(),o=()=>{A.colliderUUID&&(A.physics.sim.detachCollider({colliderId:A.colliderUUID}),A.colliderUUID=void 0)},r=()=>{if(Array.isArray(A.colliderUUIDs)&&A.colliderUUIDs.length){for(const G of A.colliderUUIDs)A.physics.sim.detachCollider({colliderId:G});A.colliderUUIDs=[]}},n=()=>{o(),r(),A._activeColliderShape=void 0};if(!g||!E||E==="none"||I>e)return n(),void(A._activeColliderShape=void 0);const s=Q&&I<=e,c=A._activeColliderShape||"none";c===E||!Q&&I===e&&C||(c!=="mesh"&&c!=="hull"||E!=="bounds"?c!=="bounds"||E!=="mesh"&&E!=="hull"?c==="mesh"&&E==="hull"||c==="hull"&&E==="mesh"?r():n():o():r(),A._activeColliderShape=E&&E!=="none"?E:void 0);let D=A;for(;D&&D.parentTile;)D=D.parentTile;const d=new Y.Vector3,h=new Y.Quaternion,u=new Y.Vector3;D&&D.matrixWorld&&D.matrixWorld.decompose(d,h,u);const f=new Y.Matrix4().compose(d,h,new Y.Vector3(1,1,1)),R=new Y.Matrix4().copy(f).invert();if(E!=="bounds"){if(E==="mesh"||E==="hull")if(o(),s){if(!A.hasMeshContent||A.meshContent.length!==A.hasMeshContent)return;if(!Array.isArray(A.colliderUUIDs)||A.colliderUUIDs.length===0){A.colliderUUIDs=[];const G=E==="hull"?"addConvexHullCollider":"attachTrimeshCollider",N=F=>{if(!(F&&F.isMesh&&F.geometry&&F.geometry.isBufferGeometry))return;const k=new Y.Matrix4().multiplyMatrices(R,F.matrixWorld),m=new Y.Vector3,S=new Y.Quaternion,j=new Y.Vector3;k.decompose(m,S,j);const z=new Y.Vector3;F.getWorldScale(z),z.set(Math.abs(z.x),Math.abs(z.y),Math.abs(z.z)),A.physics.sim[G]({bodyId:g,geometry:F.geometry,localPosition:[m.x,m.y,m.z],localRotation:S,localScale:[z.x,z.y,z.z]}).then($=>{const _=t(),X=!A.deleted&&(_==="mesh"||_==="hull"),CA=Math.floor(A.level||0)<=e,sA=Math.floor(A.level||0)===e&&Array.isArray(A.childrenTiles)&&A.childrenTiles.length>0;X&&(A.materialVisibility?CA:CA&&sA)?($&&A.colliderUUIDs.push($),A._activeColliderShape=E):$&&A.physics.sim.detachCollider({colliderId:$})}).catch(()=>{})};for(const F of A.meshContent)F&&!F.isSplatsBatch&&(F.isMesh&&N(F),F.traverse&&F.traverse(k=>{k.isMesh&&N(k)}))}}else I===e&&C||(r(),A._activeColliderShape=void 0)}else if(r(),s){if(!A.colliderUUID){if(A.boundingVolume instanceof ag||A.boundingVolume?.isOBB){const G=A.localToWorld(A.boundingVolume.center.clone()).clone().applyMatrix4(R),N=A.localToWorld(new Y.Vector3(0,0,0)).clone().applyMatrix4(R),F=A.boundingVolume.e1.clone().multiplyScalar(A.boundingVolume.halfSize.x),k=A.boundingVolume.e2.clone().multiplyScalar(A.boundingVolume.halfSize.y),m=A.boundingVolume.e3.clone().multiplyScalar(A.boundingVolume.halfSize.z),S=A.localToWorld(F.clone()).applyMatrix4(R),j=A.localToWorld(k.clone()).applyMatrix4(R),z=A.localToWorld(m.clone()).applyMatrix4(R),$=S.clone().sub(N),_=j.clone().sub(N),X=z.clone().sub(N),CA=$.length(),sA=_.length(),oA=X.length(),fA=CA>0?$.clone().multiplyScalar(1/CA):new Y.Vector3(1,0,0),bA=sA>0?_.clone().multiplyScalar(1/sA):new Y.Vector3(0,1,0),iA=oA>0?X.clone().multiplyScalar(1/oA):new Y.Vector3(0,0,1),yA=new Y.Matrix4().makeBasis(fA,bA,iA),EA=new Y.Quaternion().setFromRotationMatrix(yA);A.colliderUUID=A.physics.sim.attachShapeCollider({bodyId:g,shape:GQ.createBox(CA,sA,oA),localPosition:[G.x,G.y,G.z],localRotation:EA}),A._activeColliderShape="bounds"}else if(A.boundingVolume instanceof Y.Sphere||A.boundingVolume?.isSphere){const G=A.localToWorld(A.boundingVolume.center.clone()).clone().applyMatrix4(R),N=A.localToWorld(new Y.Vector3(0,0,0)).clone().applyMatrix4(R),F=A.localToWorld(new Y.Vector3(1,0,0)).applyMatrix4(R).sub(N).length(),k=A.localToWorld(new Y.Vector3(0,1,0)).applyMatrix4(R).sub(N).length(),m=A.localToWorld(new Y.Vector3(0,0,1)).applyMatrix4(R).sub(N).length(),S=Math.max(F,k,m),j=A.boundingVolume.radius*S;A.colliderUUID=A.physics.sim.attachShapeCollider({bodyId:g,shape:GQ.createBall(j),localPosition:[G.x,G.y,G.z]}),A._activeColliderShape="bounds"}}}else I===e&&C||(o(),A._activeColliderShape=void 0)}_calculateUpdateMetric(A,g){let I=0;if(this.boundingVolume instanceof ag){if(Jg.copy(this.boundingVolume),Jg.applyMatrix4(this.matrixWorld),!Jg.inFrustum(g))return-1;if(this.clipShape!=null&&(this.clipShape.isSphere&&!Jg.intersectsSphere(this.clipShape)||this.clipShape.isOBB&&!Jg.intersectsOBB(this.clipShape)))return Number.MAX_VALUE;I=Math.max(0,Jg.distanceToPoint(A.position)-A.near)}else{if(!(this.boundingVolume instanceof Y.Sphere))return console.error("unsupported shape"),-1;if(Fg.copy(this.boundingVolume),Fg.applyMatrix4(this.matrixWorld),this.clipShape!=null&&(this.clipShape.isOBB&&!this.clipShape.intersectsSphere(Fg)||this.clipShape.isSphere&&!this.clipShape.intersectsSphere(Fg)))return Number.MAX_VALUE;if(!g.intersectsSphere(Fg))return-1;I=Math.max(0,A.position.distanceTo(Fg.center)-Fg.radius-A.near)}if(I=Math.pow(I,this.distanceBias),I==0)return 0;const Q=this.matrixWorld.getMaxScaleOnAxis();this.renderer&&this.renderer.getDrawingBufferSize(this.rendererSize);let C=this.rendererSize.y,a=A.fov;return A.aspect<1&&(a*=A.aspect,C=this.rendererSize.x),16*(2*Math.tan(.5*a*.017453292519943295)*I)/(C*Q)}_getSiblings(){const A=this,g=[];if(!A.parentTile)return g;let I=A.parentTile;for(;!I.hasMeshContent&&I.parentTile;)I=I.parentTile;return I.childrenTiles.forEach(Q=>{if(Q&&Q!=A){for(;!Q.hasMeshContent&&Q.childrenTiles[0];)Q=Q.childrenTiles[0];g.push(Q)}}),g}_calculateDistanceToCamera(A){return this.boundingVolume instanceof ag?(Jg.copy(this.boundingVolume),Jg.applyMatrix4(this.matrixWorld),Math.max(0,Jg.distanceToPoint(A.position))):this.boundingVolume instanceof Y.Sphere?(Fg.copy(this.boundingVolume),Fg.applyMatrix4(this.matrixWorld),Math.max(0,A.position.distanceTo(Fg.center)-Fg.radius)):(console.error("unsupported shape"),-1)}setGeometricErrorMultiplier(A){this.geometricErrorMultiplier=A,this.childrenTiles.forEach(g=>g.setGeometricErrorMultiplier(A))}setDistanceBias(A){this.distanceBias=A,this.childrenTiles.forEach(g=>g.setDistanceBias(A))}_transformWGS84ToCartesian(A,g,I,Q){const C=6378137/Math.sqrt(1-.006694384442042*Math.pow(Math.sin(g),2)),a=Math.cos(g),e=Math.cos(A),i=Math.sin(g),t=C+I,E=t*a*e,o=t*a*Math.sin(A),r=(.993305615557957*C+I)*i;Q.set(E,o,r)}hideCopyright(){(function(){FA||((FA=document.createElement("div")).style.position="fixed",FA.style.bottom="20px",FA.style.left="20px",FA.style.color="white",FA.style.textShadow="2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000",FA.style.padding="10px",FA.style.backgroundColor="rgba(0, 0, 0, 0.1)",document.body.appendChild(FA)),FA.style.opacity=0})()}showCopyright(){(function(){FA||((FA=document.createElement("div")).style.position="fixed",FA.style.bottom="20px",FA.style.left="20px",FA.style.color="white",FA.style.textShadow="2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000",FA.style.padding="10px",FA.style.backgroundColor="rgba(0, 0, 0, 0.1)",document.body.appendChild(FA)),FA.style.opacity=1})()}}function Ge(B){var A=document.createElement("div");A.textContent=B,A.style.position="fixed",A.style.top="10px",A.style.left="50%",A.style.transform="translateX(-50%)",A.style.padding="10px",A.style.backgroundColor="#ff8800",A.style.color="#ffffff",A.style.zIndex="9999",document.body.appendChild(A),setTimeout(function(){A.remove()},8e3)}function NQ(){FA||((FA=document.createElement("div")).style.position="fixed",FA.style.bottom="20px",FA.style.left="20px",FA.style.color="white",FA.style.textShadow="2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000",FA.style.padding="10px",FA.style.backgroundColor="rgba(0, 0, 0, 0.1)",document.body.appendChild(FA));const B=Me();let A="";B.forEach(g=>{A+=g+", "}),A=A.slice(0,-2),FA.textContent=A}const ig=new Y.Sphere(new Y.Vector3(0,0,0),1),Vg=new Y.Vector3(0,0,0),kQ=new Y.Vector3(0,0,0),Bo=new Y.Vector3(0,1,0),mQ=new Y.Vector2,Re=new Y.Quaternion,Ne=new Y.Matrix4;class UQ extends Y.Object3D{constructor(A){super();const g=this;if(A.queryParams&&(this.queryParams={...A.queryParams}),this.uuid=Aa(),A.tileLoader?this.tileLoader=A.tileLoader:console.error("an instanced tileset must be provided an InstancedTilesetLoader"),this.master=A.master,this.loadOutsideView=A.loadOutsideView,this.cameraOnLoad=A.cameraOnLoad,this.parentTile=A.parentTile,this.distanceBias=Math.max(1e-4,A.distanceBias?A.distanceBias:1),this.childrenTiles=[],this.jsonChildren=[],this.meshContent=new Set,this.static=A.static,this.static&&(this.matrixAutoUpdate=!1,this.matrixWorldAutoUpdate=!1),this.tileContent,this.refinement,this.rootPath,this.geometricError,this.boundingVolume,this.json,this.materialVisibility=!1,this.inFrustum=!0,this.level=A.level?A.level:0,this.hasMeshContent=0,this.hasUnloadedJSONContent=0,this.centerModel=A.centerModel,this.deleted=!1,this.abortController=new AbortController,A.json)this.rootPath=A.json.rootPath?A.json.rootPath:A.rootPath,A.json.children&&(this.jsonChildren=A.json.children),g.setup(A);else if(A.url){this.loadJson=(C,a)=>{const e=BI.dirname(a);g.setup({rootPath:e,json:C,onLoadCallback:A.onLoadCallback})};var I=A.url;if(g.queryParams){var Q="";for(let C in g.queryParams)g.queryParams.hasOwnProperty(C)&&(Q+="&"+C+"="+g.queryParams[C]);I.includes("?")?I+=Q:I+="?"+Q.substring(1)}g.tileLoader.get(g.abortController,I,g.uuid,g)}}async setup(A){const g=this;A.json.root?(g.json=A.json.root,!g.json.children&&g.json.getChildren&&(g.json.children=await g.json.getChildren()),g.jsonChildren=g.json.children,g.json.refinement||(g.json.refinement=A.json.refinement),g.json.geometricError||(g.json.geometricError=A.json.geometricError),g.json.transform||(g.json.transform=A.json.transform),g.json.boundingVolume||(g.json.boundingVolume=A.json.boundingVolume)):(g.json=A.json,!g.json.children&&g.json.getChildren&&(g.json.children=await g.json.getChildren(),g.jsonChildren=g.json.children)),g.rootPath=A.json.rootPath?A.json.rootPath:A.rootPath,g.json.refinement?g.refinement=g.json.refinement:g.refinement=A.parentRefinement,g.json.geometricError?g.geometricError=g.json.geometricError:g.geometricError=A.parentGeometricError;let I=new Y.Matrix4;if(g.json.transform&&!g.centerModel&&(I.elements=g.json.transform),g.applyMatrix4(I),g.parentTile&&g.parentTile.matrix&&(g.matrix.premultiply(g.parentTile.matrix),g.matrix.decompose(g.position,g.quaternion,g.scale)),g.matrixWorldNeedsUpdate=!0,g.updateWorldMatrix(!0,!0),g.json.boundingVolume)if(g.json.boundingVolume.box)g.boundingVolume=new ag(g.json.boundingVolume.box);else if(g.json.boundingVolume.region){const C=g.json.boundingVolume.region;g.transformWGS84ToCartesian(C[0],C[1],C[4],Vg),g.transformWGS84ToCartesian(C[2],C[3],C[5],kQ),Vg.lerp(kQ,.5),g.boundingVolume=new Y.Sphere(new Y.Vector3(Vg.x,Vg.y,Vg.z),Vg.distanceTo(kQ))}else if(g.json.boundingVolume.sphere){const C=g.json.boundingVolume.sphere;g.boundingVolume=new Y.Sphere(new Y.Vector3(C[0],C[1],C[2]),C[3])}else g.boundingVolume=A.parentBoundingVolume;else g.boundingVolume=A.parentBoundingVolume;function Q(C){C.uri&&C.uri.includes("json")||C.url&&C.url.includes("json")?g.hasUnloadedJSONContent++:g.hasMeshContent++}if(g.json.content?(Q(g.json.content),g.load()):g.json.contents&&(g.json.contents.forEach(C=>Q(C)),g.load()),g.centerModel){const C=new Y.Sphere;g.boundingVolume instanceof ag?C.copy(g.boundingVolume.sphere):g.boundingVolume instanceof Y.Sphere&&C.copy(g.boundingVolume),this.json.boundingVolume.region&&(g.transformWGS84ToCartesian(.5*(g.json.boundingVolume.region[0]+g.json.boundingVolume.region[2]),.5*(g.json.boundingVolume.region[1]+g.json.boundingVolume.region[3]),.5*(g.json.boundingVolume.region[4]+g.json.boundingVolume.region[5]),Vg),Re.setFromUnitVectors(Vg.normalize(),Bo.normalize()),g.master.applyQuaternion(Re),g.master.updateWorldMatrix(!1,!1)),Ne.makeTranslation(-C.center.x*g.scale.x,-C.center.y*g.scale.y,-C.center.z*g.scale.z),g.master.matrix.multiply(Ne),g.master.matrix.decompose(g.master.position,g.master.quaternion,g.master.scale)}g.isSetup=!0,A.onLoadCallback&&A.onLoadCallback(g)}isAbsolutePathOrURL(A){const g=/^(?:http|https|ftp|tcp|udp):\/\/\S+/.test(A),I=A.startsWith("/")&&!A.startsWith("//");return g||I}assembleURL(A,g){A.endsWith("/")||(A+="/");const I=new URL(A);let Q=I.pathname.split("/").filter(a=>a!==""),C=g.split("/").filter(a=>a!=="");for(let a=1;a<=Q.length&&!(a>=C.length);a++)if(Q.slice(Q.length-a,Q.length).join("/")===C.slice(0,a).join("/")){for(let e=0;e<a;e++)Q.pop();break}for(;C.length>0&&C[0]==="..";)Q.pop(),C.shift();return`${I.protocol}//${I.host}/${[...Q,...C].join("/")}`}extractQueryParams(A,g){const I=new URL(A);for(let[Q,C]of I.searchParams)g[Q]=C;return I.search="",I.toString()}load(){var A=this;function g(I){let Q;I.uri?Q=I.uri:I.url&&(Q=I.url);const C=/^(?:http|https|ftp|tcp|udp):\/\/\S+/;if(C.test(A.rootPath)?C.test(Q)||(Q=A.assembleURL(A.rootPath,Q)):BI.isAbsolute(A.rootPath)&&(Q=A.rootPath+BI.sep+Q),Q=A.extractQueryParams(Q,A.queryParams),A.queryParams){var a="";for(let e in A.queryParams)A.queryParams.hasOwnProperty(e)&&(a+="&"+e+"="+A.queryParams[e]);Q.includes("?")?Q+=a:Q+="?"+a.substring(1)}Q&&(Q.includes(".b3dm")||Q.includes(".glb")||Q.includes(".gltf")?(A.contentURL=Q,A.tileLoader.get(A.abortController,Q,A.uuid,A,A.cameraOnLoad?()=>A.calculateDistanceToCamera(A.cameraOnLoad):()=>0,()=>A.getSiblings(),A.level,!A.json.boundingVolume.region,!!A.json.boundingVolume.region,A.geometricError)):Q.includes(".json")&&A.tileLoader.get(A.abortController,Q,A.uuid,A))}A.deleted||(A.json.content?g(A.json.content):A.json.contents&&A.json.contents.forEach(I=>g(I)))}loadMesh(A){this.deleted||this.meshContent.add(A)}loadJson(A,g){this.deleted||(this.json.children&&(this.jsonChildren=this.json.children),A.rootPath=BI.dirname(g),this.jsonChildren.push(A),this.hasUnloadedJSONContent--)}dispose(){const A=this;A.childrenTiles.forEach(g=>g.dispose()),A.deleted=!0,A.abortController&&A.abortController.abort(),this.parent=null,this.parentTile=null,this.dispatchEvent({type:"removed"})}disposeChildren(){this.childrenTiles.forEach(A=>A.dispose()),this.childrenTiles=[]}_update(A,g){const I=this;function Q(C){if(I.hasMeshContent&&!(I.meshContent.size<I.hasMeshContent)){if(C<0)return I.inFrustum=!1,void I.changeContentVisibility(!!I.loadOutsideView);if(I.inFrustum=!0,I.childrenTiles.length!=0){if(C>=I.master.geometricErrorMultiplier*I.geometricError)I.changeContentVisibility(!0);else if(C<I.master.geometricErrorMultiplier*I.geometricError){let a=!0;I.childrenTiles.every(e=>!!e.isReady()||(a=!1,!1)),a&&I.changeContentVisibility(!1)}}else I.changeContentVisibility(!0)}}I.isSetup&&(I.materialVisibility,I.boundingVolume&&I.geometricError&&(I.metric=I.calculateUpdateMetric(A,g)),I.childrenTiles.forEach(C=>C._update(A,g)),Q(I.metric),function(C){C<0&&I.hasMeshContent||(!I.hasMeshContent&&I.rootPath||C<I.master.geometricErrorMultiplier*I.geometricError&&I.meshContent.size>0)&&I.json&&I.jsonChildren&&I.childrenTiles.length!=I.jsonChildren.length&&I.jsonChildren.forEach(a=>{if(!(a.root||a.children||a.getChildren||a.content||a.contents))return;let e=new UQ({parentTile:I,queryParams:I.queryParams,parentGeometricError:I.geometricError,parentBoundingVolume:I.boundingVolume,parentRefinement:I.refinement,json:a,rootPath:I.rootPath,loadOutsideView:I.loadOutsideView,level:I.level+1,tileLoader:I.tileLoader,cameraOnLoad:A,master:I.master,centerModel:!1});I.childrenTiles.push(e)})}(I.metric),function(C){if(I.hasMeshContent){if(!I.inFrustum)return I.disposeChildren(),void Q(C);C>=I.master.geometricErrorMultiplier*I.geometricError&&(I.disposeChildren(),Q(C))}}(I.metric))}areAllChildrenLoadedAndHidden(){let A=!0;return this.childrenTiles.every(g=>{if(g.hasMeshContent){if(g.childrenTiles.length>0)return A=!1,!1;if(!g.inFrustum)return!0;if(!g.materialVisibility||g.meshesToDisplay!=g.meshesDisplayed)return A=!1,!1}else if(!g.areAllChildrenLoadedAndHidden())return A=!1,!1;return!0}),A}isReady(){if(!this.inFrustum)return!0;if(this.hasUnloadedJSONContent)return!1;if(!this.hasMeshContent||this.meshContent.size==0||!this.materialVisibility){if(this.childrenTiles.length>0){var A=!0;return this.childrenTiles.every(g=>!!g.isReady()||(A=!1,!1)),A}return!1}return!this.hasMeshContent||!(this.meshContent.size<this.hasMeshContent)&&!!this.materialVisibility}changeContentVisibility(A){this.materialVisibility=A}calculateUpdateMetric(A,g){if(this.boundingVolume instanceof ag){if(ig.copy(this.boundingVolume.sphere),ig.applyMatrix4(this.matrixWorld),!g.intersectsSphere(ig))return-1}else{if(!(this.boundingVolume instanceof Y.Sphere))return console.error("unsupported shape"),-1;if(ig.copy(this.boundingVolume),ig.applyMatrix4(this.matrixWorld),!g.intersectsSphere(ig))return-1}let I=Math.max(0,A.position.distanceTo(ig.center)-ig.radius);if(I=Math.pow(I,this.distanceBias),I==0)return 0;const Q=this.matrixWorld.getMaxScaleOnAxis();this.master._renderSize(mQ);let C=mQ.y,a=A.fov;A.aspect<1&&(a*=A.aspect,C=mQ.x);let e=2*Math.tan(.5*a*.017453292519943295)*I;return 16*window.devicePixelRatio*e/(C*Q)}getSiblings(){const A=this,g=[];if(!A.parentTile)return g;let I=A.parentTile;for(;!I.hasMeshContent&&I.parentTile;)I=I.parentTile;return I.childrenTiles.forEach(Q=>{if(Q&&Q!=A){for(;!Q.hasMeshContent&&Q.childrenTiles[0];)Q=Q.childrenTiles[0];g.push(Q)}}),g}calculateDistanceToCamera(A){return this.boundingVolume instanceof ag?(ig.copy(this.boundingVolume.sphere),ig.applyMatrix4(this.matrixWorld)):this.boundingVolume instanceof Y.Sphere?(ig.copy(this.boundingVolume),ig.applyMatrix4(this.matrixWorld)):console.error("unsupported shape"),Math.max(0,A.position.distanceTo(ig.center)-ig.radius)}getWorldMatrix(){return this.matrixWorld}transformWGS84ToCartesian(A,g,I,Q){const C=6378137/Math.sqrt(1-.006694384442042*Math.pow(Math.sin(g),2)),a=Math.cos(g),e=Math.cos(A),i=Math.sin(g),t=C+I,E=t*a*e,o=t*a*Math.sin(A),r=(.993305615557957*C+I)*i;Q.set(E,o,r)}}class Qo extends Y.Object3D{constructor(A){super(),A.master=this,A.domWidth&&A.domHeight?this.rendererSize=new Y.Vector2(A.domWidth,A.domHeight):this.rendererSize=new Y.Vector2(1e3,1e3),this.renderer=A.renderer,this.distanceBias=Math.max(1e-4,A.distanceBias?A.distanceBias:1),this.geometricErrorMultiplier=A.geometricErrorMultiplier?A.geometricErrorMultiplier:1,this.tileset=new UQ(A),A.static&&(this.matrixAutoUpdate=!1),this.tileLoader=A.tileLoader}_renderSize(A){this.renderer?this.renderer.getDrawingBufferSize(A):A.copy(this.rendererSize)}setCanvasSize(A,g){this.rendererSize.set(A,g)}update(A,g){if(g)this.tileset._update(A,g);else{const I=new Y.Frustum;I.setFromProjectionMatrix(new Y.Matrix4().multiplyMatrices(A.projectionMatrix,A.matrixWorldInverse)),this.tileset._update(A,I)}}setGeometricErrorMultiplier(A){this.geometricErrorMultiplier=A||1}}class Co{constructor(A){const g=this;g.scene=A,g.instancedTiles=[],g.instancedMesh,g.reuseableMatrix=new Y.Matrix4}addInstance(A){const g=this;A.added=!0,A.listOMesh=g.instancedTiles,g.instancedTiles.push(A),g.instancedMesh&&A.loadMesh(g.instancedMesh)}addToScene(){const A=this;A.instancedMesh.setMatrixAt(0,new Y.Matrix4),A.instancedMesh.instanceMatrix.needsUpdate=!0,A.instancedMesh.count=1,A.scene.add(A.instancedMesh),A.instancedMesh.onAfterRender=()=>{delete A.instancedMesh.onAfterRender,A.instancedMesh.displayedOnce=!0}}setObject(A){const g=this;g.instancedMesh=A,g.instancedMesh.matrixAutoUpdate=!1,g.instancedMesh.matrixWorldAutoUpdate=!1,g.scene.children.includes(A)||this.addToScene();for(let I=0;I<g.instancedTiles.length;I++)g.instancedTiles[I].loadMesh(g.instancedMesh)}update(){const A=this;for(let g=A.instancedTiles.length-1;g>=0;g--)A.instancedTiles[g].deleted&&A.instancedTiles.splice(g,1);if(A.instancedMesh){A.instancedMesh.count=0,A.instancedMesh.instancedTiles=[];for(let g=0;g<A.instancedTiles.length;g++)A.instancedTiles[g].meshContent.add(A.instancedMesh),A.instancedTiles[g].materialVisibility&&(A.instancedMesh.count++,A.reuseableMatrix.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),A.reuseableMatrix.multiply(A.instancedTiles[g].matrixWorld),A.reuseableMatrix.multiply(A.instancedMesh.baseMatrix),A.instancedMesh.setMatrixAt(A.instancedMesh.count-1,A.reuseableMatrix),A.instancedMesh.instancedTiles.push(A.instancedTiles[g]));A.instancedMesh.instanceMatrix.needsUpdate=!0,A.instancedMesh.needsUpdate=!0,A.instancedMesh.computeBoundingSphere()}}getCount(){return this.instancedTiles.length}dispose(){const A=this;return!(A.instancedTiles.length>0)&&!!A.instancedMesh&&(A.scene.remove(A.instancedMesh),A.instancedMesh.traverse(g=>{if(g.dispose&&g.dispose(),g.material)if(g.material.length)for(let I=0;I<g.material.length;++I)g.material[I].dispose();else g.material.dispose();g.geometry&&g.geometry.dispose()}),A.instancedMesh.dispose(),!0)}}class ao{constructor(){const A=this;A.count=0,A.json,A.instancedTiles=[]}addInstance(A){this.instancedTiles.push(A),this.json&&A.loadJson(this.json,this.url)}setObject(A,g){const I=this;I.json=A,I.url=g;for(let Q=0;Q<I.instancedTiles.length;Q++)I.instancedTiles[Q].loadJson(I.json,I.url)}getCount(){return this.instancedTiles.length}update(){const A=this;for(let g=A.instancedTiles.length-1;g>=0;g--)A.instancedTiles[g].deleted&&A.instancedTiles.splice(g,1)}dispose(){return!(!this.json||this.instancedTiles.length!=0)}}let iI=0;async function eo(B){return new Promise(A=>{const g=setInterval(()=>{B.hasDracoLoader&&!B.dracoLoader||B.hasKTX2Loader&&!B.ktx2Loader||(clearInterval(g),A())},10)})}function Eo(B){return new Worker(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/physicsRapier.worker-G7IM3mIE.js").href:new URL("assets/physicsRapier.worker-G7IM3mIE.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),{type:"module",name:B?.name})}function io(B){return new Worker(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/physicsHelper.worker-Cr8S3sZk.js").href:new URL("assets/physicsHelper.worker-Cr8S3sZk.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),{type:"module",name:B?.name})}function tg(B,A=[0,-9.81,0]){return B?Array.isArray(B)&&B.length===3?[Number(B[0]),Number(B[1]),Number(B[2])]:B.isVector3?[B.x,B.y,B.z]:typeof B=="object"&&"x"in B&&"y"in B&&"z"in B?[Number(B.x),Number(B.y),Number(B.z)]:A.slice():A.slice()}function jI(B,A=[0,0,0,1]){if(!B)return A.slice();if(Array.isArray(B)&&B.length===4)return[Number(B[0]),Number(B[1]),Number(B[2]),Number(B[3])];if(B.isQuaternion)return[B.x,B.y,B.z,B.w];if(B.isEuler){const g=new Y.Quaternion().setFromEuler(B);return[g.x,g.y,g.z,g.w]}return A.slice()}function ke(B){if(Array.isArray(B)||B&&B.isVector3)return{mode:"vector",vector:tg(B)};const A=B||{};return(A.mode||"vector").toLowerCase()==="geocentric"?{mode:"geocentric",planetCenter:tg(A.planetCenter||[0,0,0],[0,0,0]),intensity:typeof A.intensity=="number"?A.intensity:9.81}:{mode:"vector",vector:tg(A.vector||A,[0,-9.81,0])}}function pB(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}ZA.ColliderShape=GQ,ZA.InstancedOGC3DTile=Qo,ZA.InstancedTileLoader=class{constructor(B,A){if(this.zUpToYUpMatrix=new Y.Matrix4,this.zUpToYUpMatrix.set(1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1),this.maxCachedItems=100,this.maxInstances=1,this.proxy=A.proxy,A&&(this.meshCallback=A.meshCallback,this.pointsCallback=A.pointsCallback,A.maxCachedItems&&(this.maxCachedItems=A.maxCachedItems),A.maxInstances&&(this.maxInstances=A.maxInstances)),this.gltfLoader=new $Q,A&&A.dracoLoader)this.gltfLoader.setDRACOLoader(A.dracoLoader),this.hasDracoLoader=!0;else{const g=new CC;g.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),this.gltfLoader.setDRACOLoader(g),this.gltfLoader.hasDracoLoader=!0}if(A&&A.ktx2Loader)this.gltfLoader.setKTX2Loader(A.ktx2Loader),this.hasKTX2Loader=!0;else if(A&&A.renderer){const g=new rg;g.setTranscoderPath("https://storage.googleapis.com/ogc-3d-tiles/basis/").detectSupport(A.renderer),this.gltfLoader.setKTX2Loader(g),this.gltfLoader.hasKTX2Loader=!0}this.gltfLoader.setMeshoptDecoder(XC),this.hasMeshOptDecoder=!0,this.b3dmDecoder=new XQ(this.gltfLoader),this.cache=new WQ,this.scene=B,this.ready=[],this.downloads=[],this.nextReady=[],this.nextDownloads=[]}update(){const B=this;B._checkSize(),B.cache._data.forEach(A=>{A.update()}),iI<8&&B._download(),B._loadBatch()}_download(){const B=this;if(B.nextDownloads.length!=0||(B._getNextDownloads(),B.nextDownloads.length!=0))for(;B.nextDownloads.length>0;){const g=B.nextDownloads.shift();if(g){if(g.path.includes(".b3dm")&&(A=B.proxy?()=>fetch(B.proxy,{method:"POST",body:g.path}):()=>fetch(g.path),iI++,A().then(I=>{if(!I.ok)throw console.error("could not load tile with path : "+g.path),new Error(`couldn't load "${g.path}". Request failed with status ${I.status} : ${I.statusText}`);return I.arrayBuffer()}).then(I=>this.b3dmDecoder.parseB3DMInstanced(I,Q=>{B.meshCallback(Q,g.geometricError)},B.maxInstances,g.sceneZupToYup,g.meshZupToYup)).then(I=>{I.frustumCulled=!1,g.tile.setObject(I),B.ready.unshift(g)}).catch(I=>console.error(I)).finally(()=>{iI--})),g.path.includes(".glb")||g.path.includes(".gltf"))A=B.proxy?()=>fetch(B.proxy,{method:"POST",body:g.path}):()=>fetch(g.path),iI++,A().then(I=>{if(!I.ok)throw new Error("missing content");return I.arrayBuffer()}).then(async I=>{await eo(this.gltfLoader),this.gltfLoader.parse(I,null,Q=>{let C;Q.scene.asset=Q.asset,g.sceneZupToYup&&Q.scene.applyMatrix4(this.zUpToYUpMatrix),Q.scene.traverse(a=>{a.geometricError=g.geometricError,a.isMesh&&(g.meshZupToYup&&a.applyMatrix4(this.zUpToYUpMatrix),B.meshCallback&&B.meshCallback(a,a.geometricError)),a.isPoints&&console.error("instanced point cloud is not supported")}),Q.scene.updateWorldMatrix(!1,!0),Q.scene.traverse(a=>{a.isMesh&&(C=new Y.InstancedMesh(a.geometry,a.material,B.maxInstances),C.baseMatrix=a.matrixWorld)}),B.ready.unshift(g),C?(C.frustumCulled=!1,g.tile.setObject(C)):Q.scene.traverse(a=>{a.dispose&&a.dispose(),a.material&&a.material.dispose()})})},I=>{console.error("could not load tile : "+g.path)}).finally(()=>{iI--});else if(g.path.includes(".json")){var A;A=B.proxy?()=>fetch(B.proxy,{method:"POST",body:g.path}):()=>fetch(g.path),iI++,A().then(I=>{if(!I.ok)throw console.error("could not load tile with path : "+g.path),new Error(`couldn't load "${g.path}". Request failed with status ${I.status} : ${I.statusText}`);return I.json()}).then(I=>AQ(I,g.path)).then(I=>{g.tile.setObject(I,g.path),B.ready.unshift(g)}).catch(I=>console.error(I)).finally(()=>{iI--})}}}}_loadBatch(){return this.nextReady.length==0&&(this._getNextReady(),this.nextReady.length==0)?0:this.nextReady.shift()?1:0}_getNextReady(){let B=Number.MAX_VALUE,A=-1;for(let g=this.ready.length-1;g>=0;g--)this.ready[g].distanceFunction||this.nextReady.push(this.ready.splice(g,1)[0]);if(!(this.nextReady.length>0)){for(let g=this.ready.length-1;g>=0;g--){const I=this.ready[g].distanceFunction()*this.ready[g].level;I<B&&(B=I,A=g)}if(A>=0){const g=this.ready.splice(A,1).pop();this.nextReady.push(g);const I=g.getSiblings();for(let Q=this.ready.length-1;Q>=0;Q--)I.includes(this.ready[Q].uuid)&&this.nextready.push(this.ready.splice(Q,1).pop())}}}get(B,A,g,I,Q,C,a,e,i,t){const E=this,o=function(n){for(var s=n.split("/"),c=[],D=0,d=0;d<s.length;d++){var h=s[d];h!=="."&&h!==""&&h!==".."?c[D++]=h:h===".."&&D>0&&D--}if(D===0)return"/";var u="";for(d=0;d<D;d++)u+="/"+c[d];return u}(A);if(!(A.includes(".b3dm")||A.includes(".json")||A.includes(".glb")||A.includes(".gltf")))return void console.error("the 3DTiles cache can only be used to load B3DM, gltf and json data");const r=E.cache.get(o);if(r)r.addInstance(I);else if(A.includes(".b3dm")||A.includes(".glb")||A.includes(".gltf")){const n=new Co(E.scene);n.addInstance(I),E.cache.put(o,n);const s=new AbortController;B.signal.addEventListener("abort",()=>{n.getCount()==0&&s.abort()}),this.downloads.push({abortController:s,tile:n,key:o,path:A,distanceFunction:Q,getSiblings:C,level:a,uuid:g,sceneZupToYup:e,meshZupToYup:i,geometricError:t,shouldDoDownload:()=>!0})}else if(A.includes(".json")){const n=new ao;n.addInstance(I),E.cache.put(o,n);const s=new AbortController;B.signal.addEventListener("abort",()=>{n.getCount()==0&&s.abort()}),this.downloads.push({abortController:s,tile:n,key:o,path:A,distanceFunction:Q,getSiblings:C,level:a,shouldDoDownload:()=>!0})}}_getNextDownloads(){let B=Number.MAX_VALUE,A=-1;for(let g=this.downloads.length-1;g>=0;g--){const I=this.downloads[g];I.shouldDoDownload()?I.distanceFunction||this.nextDownloads.push(this.downloads.splice(g,1)[0]):this.downloads.splice(g,1)}if(!(this.nextDownloads.length>0)){for(let g=this.downloads.length-1;g>=0;g--){const I=this.downloads[g],Q=I.distanceFunction()*I.level;Q<B&&(B=Q,A=g)}if(A>=0){const g=this.downloads.splice(A,1).pop();this.nextDownloads.push(g);const I=g.getSiblings();for(let Q=this.downloads.length-1;Q>=0;Q--)I.includes(this.downloads[Q].uuid)&&this.nextDownloads.push(this.downloads.splice(Q,1).pop())}}}_checkSize(){const B=this;let A=0;for(;B.cache.size()>B.maxCachedItems&&A<B.cache.size();){A++;const g=B.cache.head();B.cache.remove(g.key),g.value.dispose()||B.cache.put(g.key,g.value)}}},ZA.OBB=ag,ZA.OGC3DTile=RQ,ZA.OcclusionCullingService=class{constructor(){this.cullMap=[],this.cullMaterial=new Y.MeshBasicMaterial({vertexColors:!0}),this.cullMaterial.side=Y.FrontSide,this.cullTarget=this._createCullTarget(),this.cullPixels=new Uint8Array(4*this.cullTarget.width*this.cullTarget.height)}setSide(B){this.cullMaterial.side=B}_createCullTarget(){const B=new Y.WebGLRenderTarget(Math.floor(.05*window.innerWidth),Math.floor(.05*window.innerHeight));return B.texture.format=Y.RGBAFormat,B.texture.colorSpace=Y.LinearSRGBColorSpace,B.texture.minFilter=Y.NearestFilter,B.texture.magFilter=Y.NearestFilter,B.texture.generateMipmaps=!1,B.stencilBuffer=!1,B.depthBuffer=!0,B.depthTexture=new Y.DepthTexture,B.depthTexture.format=Y.DepthFormat,B.depthTexture.type=Y.UnsignedShortType,B}update(B,A,g){let I=A.getRenderTarget(),Q=B.overrideMaterial;B.overrideMaterial=this.cullMaterial,A.setRenderTarget(this.cullTarget),A.render(B,g),B.overrideMaterial=Q,A.setRenderTarget(I),A.readRenderTargetPixels(this.cullTarget,0,0,this.cullTarget.width,this.cullTarget.height,this.cullPixels),this.cullMap=[];for(let C=0;C<this.cullPixels.length;C+=4){const a=Y.MathUtils.clamp(this.cullPixels[C],0,255)<<16^Y.MathUtils.clamp(this.cullPixels[C+1],0,255)<<8^Y.MathUtils.clamp(this.cullPixels[C+2],0,255);this.cullMap[a]=!0}}hasID(B){return this.cullMap[B]}},ZA.Physics=class{constructor(B={}){this.updateIntervalMs=typeof B.updateIntervalMs=="number"?B.updateIntervalMs:16,this.fixedDt=typeof B.fixedDt=="number"?B.fixedDt:this.updateIntervalMs/1e3,this.gravity=ke(B.gravity),this.autoStart=B.autoStart!==!1,this.sharedMemorySupported=typeof SharedArrayBuffer<"u"&&!(!globalThis||!globalThis.crossOriginIsolated),this.worker=new Eo({}),this._msgId=0,this._pending=new Map,this._onWorkerMessage=this._onWorkerMessage.bind(this),this.worker.onmessage=this._onWorkerMessage,this.worker.onerror=A=>{console.error("Physics worker error:",A?.message||A)},this.helperWorker=null,this._helperMsgId=0,this._helperPending=new Map,this._onHelperMessage=this._onHelperMessage?this._onHelperMessage.bind(this):A=>{},this._paused=!1,this._lastTickTime=pB(),this._lastState=null,this._currentState=null,this._interpolationMax=1.25,this._nextBodyId=1,this._nextColliderId=1,this.rigidBodies=new Map,this.bodyToColliders=new Map,this.colliderToBody=new Map,this._listeners=new Map,this._initPromise=this._post({type:"init",gravity:this.gravity,sharedMemorySupported:this.sharedMemorySupported,fixedDt:this.fixedDt}),this.autoStart&&this._initPromise.then(()=>{this._scheduleNextTick()}).catch(A=>{console.error("Physics init failed:",A)})}addObject(B={}){const A="rb-"+this._nextBodyId++,g=(B.type||"dynamic").toLowerCase(),I=typeof B.mass=="number"?B.mass:1,Q=tg(B.position,[0,0,0]),C=jI(B.rotation,[0,0,0,1]),a=B.velocity?tg(B.velocity,[0,0,0]):void 0,e=B.angularVelocity?tg(B.angularVelocity,[0,0,0]):void 0;return this.rigidBodies.set(A,{id:A,object:B.object||null,type:g,mass:I,last:{p:Q,q:C},current:{p:Q.slice(),q:C.slice()}}),this.bodyToColliders.set(A,new Set),this._post({type:"addObject",id:A,body:{type:g,mass:I,p:Q,q:C,v:a,w:e}}),A}attachTrimeshCollider({bodyId:B,geometry:A,positions:g,indices:I,localPosition:Q,localRotation:C,localScale:a}){if(!this.rigidBodies.has(B))return console.warn(`attachTrimeshCollider: unknown bodyId ${B}`),Promise.resolve(null);let e=null,i=null;if(A&&A.isBufferGeometry){const D=A.getAttribute("position");if(D)if(D.isInterleavedBufferAttribute){const h=D.count;e=new Float32Array(3*h);for(let u=0;u<h;u++)e[3*u+0]=D.getX(u),e[3*u+1]=D.getY(u),e[3*u+2]=D.getZ(u)}else D.array&&(e=new Float32Array(D.array));else console.warn("attachTrimeshCollider: geometry has no position attribute");const d=A.getIndex?.();if(d&&d.array){const h=d.array;i=new Uint32Array(h)}}else g&&(e=Array.isArray(g)||g instanceof Float32Array?new Float32Array(g):new Float32Array(g.buffer||g)),I&&(i=Array.isArray(I)||I instanceof Uint32Array?new Uint32Array(I):new Uint32Array(I.buffer||I));if(!(e instanceof Float32Array))return console.warn("attachTrimeshCollider: missing or invalid positions buffer"),Promise.resolve(null);const t=Q?tg(Q,[0,0,0]):[0,0,0],E=C?jI(C,[0,0,0,1]):[0,0,0,1],o=Array.isArray(a)&&a.length===3?[Number(a[0]),Number(a[1]),Number(a[2])]:[1,1,1],r="col-"+this._nextColliderId++,n=this.bodyToColliders.get(B)||new Set;n.add(r),this.bodyToColliders.set(B,n),this.colliderToBody.set(r,B);const s={type:"attachTrimeshCollider",id:r,bodyId:B,positions:e,indices:i||null,local:{p:t,q:E,s:o}},c=[];return e?.buffer&&c.push(e.buffer),i?.buffer&&c.push(i.buffer),this._post(s,c).then(()=>r)}addConvexHullCollider({bodyId:B,geometry:A,positions:g,indices:I,localPosition:Q,localRotation:C,localScale:a}){if(!this.rigidBodies.has(B))return console.warn(`addConvexHullCollider: unknown bodyId ${B}`),Promise.resolve(null);let e=null,i=null;if(A&&A.isBufferGeometry){const D=A.getAttribute("position");if(D)if(D.isInterleavedBufferAttribute){const h=D.count;e=new Float32Array(3*h);for(let u=0;u<h;u++)e[3*u+0]=D.getX(u),e[3*u+1]=D.getY(u),e[3*u+2]=D.getZ(u)}else D.array&&(e=new Float32Array(D.array));else console.warn("addConvexHullCollider: geometry has no position attribute");const d=A.getIndex?.();if(d&&d.array){const h=d.array;i=new Uint32Array(h)}}else g&&(e=Array.isArray(g)||g instanceof Float32Array?new Float32Array(g):new Float32Array(g.buffer||g)),I&&(i=Array.isArray(I)||I instanceof Uint32Array?new Uint32Array(I):new Uint32Array(I.buffer||I));if(!(e instanceof Float32Array))return console.warn("addConvexHullCollider: missing or invalid positions buffer"),Promise.resolve(null);const t=Q?tg(Q,[0,0,0]):[0,0,0],E=C?jI(C,[0,0,0,1]):[0,0,0,1],o=Array.isArray(a)&&a.length===3?[Number(a[0]),Number(a[1]),Number(a[2])]:[1,1,1],r="col-"+this._nextColliderId++,n=this.bodyToColliders.get(B)||new Set;n.add(r),this.bodyToColliders.set(B,n),this.colliderToBody.set(r,B);const s={type:"computeConvexHull",positions:e,indices:i||null,localScale:o},c=[];return e?.buffer&&c.push(e.buffer),i?.buffer&&c.push(i.buffer),this._helperPost(s,c).then(D=>{const d=D?.vertices;if(!(d instanceof Float32Array)||d.length<9)throw new Error("convex hull computation failed or returned insufficient vertices");const h={type:"attachShapeCollider",id:r,bodyId:B,shape:{kind:"convexHull",params:{vertices:d}},local:{p:t,q:E}},u=[];return d?.buffer&&u.push(d.buffer),this._post(h,u).then(()=>r)}).catch(D=>{const d=this.bodyToColliders.get(B);return d&&d.delete(r),this.colliderToBody.delete(r),console.warn("addConvexHullCollider failed:",D),null})}attachShapeCollider({bodyId:B,shape:A,localPosition:g,localRotation:I}){if(!this.rigidBodies.has(B))return console.warn(`attachShapeCollider: unknown bodyId ${B}`),Promise.resolve(null);if(!A||typeof A!="object")return console.warn("attachShapeCollider: missing or invalid shape descriptor"),Promise.resolve(null);const Q=g?tg(g,[0,0,0]):[0,0,0],C=I?jI(I,[0,0,0,1]):[0,0,0,1],a="col-"+this._nextColliderId++,e=this.bodyToColliders.get(B)||new Set;e.add(a),this.bodyToColliders.set(B,e),this.colliderToBody.set(a,B);const i={type:"attachShapeCollider",id:a,bodyId:B,shape:A,local:{p:Q,q:C}};return this._post(i),a}detachCollider({colliderId:B}){const A=this.colliderToBody.get(B);if(!A)return;const g=this.bodyToColliders.get(A);g&&g.delete(B),this.colliderToBody.delete(B),this._post({type:"detachCollider",colliderId:B})}removeObject({bodyId:B}){if(!this.rigidBodies.has(B))return;const A=this.bodyToColliders.get(B);if(A)for(const g of A)this.colliderToBody.delete(g);this.bodyToColliders.delete(B),this.rigidBodies.delete(B),this._post({type:"removeObject",id:B})}applyForce({bodyId:B,force:A,worldPoint:g,wake:I=!0,impulse:Q=!1}){if(!this.rigidBodies.has(B))return void console.warn(`applyForce: unknown bodyId ${B}`);const C=tg(A,[0,0,0]),a=g?tg(g,[0,0,0]):void 0;this._post({type:"applyForce",id:B,force:C,point:a,wake:!!I,impulse:!!Q})}setGravity(B){this.gravity=ke(B),this._post({type:"setGravity",gravity:this.gravity})}setPose({bodyId:B,position:A,rotation:g,wake:I=!0}){if(!this.rigidBodies.has(B))return void console.warn(`setPose: unknown bodyId ${B}`);const Q=A!=null?tg(A,[0,0,0]):null,C=g!=null?jI(g,[0,0,0,1]):null;this._post({type:"setPose",id:B,p:Q,q:C,wake:!!I});const a=this.rigidBodies.get(B);a&&(Q&&(a.last.p=Q.slice(),a.current.p=Q.slice(),a.object?.isObject3D&&a.object.position.set(Q[0],Q[1],Q[2])),C&&(a.last.q=C.slice(),a.current.q=C.slice(),a.object?.isObject3D&&a.object.quaternion.set(C[0],C[1],C[2],C[3])),a.object?.isObject3D&&(a.object.updateMatrices?a.object.updateMatrices():(a.object.matrixAutoUpdate!==!1&&a.object.updateMatrix(),a.object.matrixWorldAutoUpdate!==!1&&a.object.updateMatrixWorld(!0))))}raycast({origin:B,direction:A,maxToi:g=1e6,filter:I}){const Q=tg(B,[0,0,0]),C=tg(A,[0,-1,0]);return this._post({type:"raycast",origin:Q,direction:C,maxToi:g,filter:I||null})}pause(){this._paused=!0}resume(){this._paused&&(this._paused=!1,this._lastTickTime=pB(),this._scheduleNextTick())}setUpdateInterval(B){this.updateIntervalMs=Math.max(1,Number(B)||16)}stepOnce(B){const A=typeof B=="number"?B:this.fixedDt;return this._post({type:"step",dt:A})}update(){if(!this._currentState)return;const B=this._lastState||this._currentState,A=this._currentState,g=pB(),I=B.timeMs||g,Q=A.timeMs||g,C=Math.max(.001,Q-I);let a=Y.MathUtils.clamp((g-Q)/C+1,0,this._interpolationMax);a=Y.MathUtils.clamp(a,0,1);const e=new Y.Quaternion,i=new Y.Quaternion,t=new Y.Quaternion;for(const[E,o]of this.rigidBodies.entries()){const r=B.bodies?.[E],n=A.bodies?.[E];if(!n&&!r)continue;const s=r?.p||o.current.p,c=r?.q||o.current.q,D=n?.p||o.current.p,d=n?.q||o.current.q,h=Y.MathUtils.lerp(s[0],D[0],a),u=Y.MathUtils.lerp(s[1],D[1],a),f=Y.MathUtils.lerp(s[2],D[2],a);e.set(c[0],c[1],c[2],c[3]),i.set(d[0],d[1],d[2],d[3]),t.copy(e).slerp(i,a),o.object&&o.object.isObject3D&&(o.object.position.set(h,u,f),o.object.quaternion.copy(t),o.object.updateMatrices?o.object.updateMatrices():(o.object.matrixAutoUpdate!==!1&&o.object.updateMatrix(),o.object.matrixWorldAutoUpdate!==!1&&o.object.updateMatrixWorld(!0))),o.last={p:s.slice(),q:c.slice()},o.current={p:D.slice(),q:d.slice()}}}dispose(){try{this.worker.terminate()}catch{}try{this.helperWorker?.terminate()}catch{}this.rigidBodies.clear(),this.bodyToColliders.clear(),this.colliderToBody.clear(),this._pending.clear(),this._listeners.clear(),this._lastState=null,this._currentState=null}_scheduleNextTick(){this._paused||setTimeout(()=>this._onTick(),this.updateIntervalMs)}_onTick(){if(this._paused)return;const B=pB();Math.max(1e-6,(B-this._lastTickTime)/1e3),this._lastTickTime=B,this._post({type:"step",dt:this.fixedDt}),this.update(),this._scheduleNextTick()}_onWorkerMessage(B){const A=B.data||{};if(A.replyTo){const g=this._pending.get(A.replyTo);g&&(this._pending.delete(A.replyTo),A.error?g.rej?g.rej(A.error):console.error("Physics worker error:",A.error):g.res&&g.res(A.result))}else switch(A.type){case"state":this._lastState=this._currentState,this._currentState=A.state||null,this._emit("state",this._currentState);break;case"event":this._emit("event",A.event)}}_ensureHelperWorker(){this.helperWorker||(this.helperWorker=new io({}),this.helperWorker.onmessage=this._onHelperMessage,this.helperWorker.onerror=B=>{console.error("Physics helper worker error:",B?.message||B)})}_onHelperMessage(B){const A=B.data||{};if(A.replyTo){const g=this._helperPending.get(A.replyTo);g&&(this._helperPending.delete(A.replyTo),A.error?g.rej?g.rej(A.error):console.error("Physics helper worker error:",A.error):g.res&&g.res(A.result))}}_helperPost(B,A=[]){this._ensureHelperWorker();const g=++this._helperMsgId,I={...B,_envId:g};return this.helperWorker.postMessage(I,A),new Promise((Q,C)=>{this._helperPending.set(g,{res:Q,rej:C})})}_post(B,A=[]){const g=++this._msgId,I={...B,_envId:g};return this.worker.postMessage(I,A),new Promise((Q,C)=>{this._pending.set(g,{res:Q,rej:C})})}on(B,A){return this._listeners.has(B)||this._listeners.set(B,new Set),this._listeners.get(B).add(A),()=>this.off(B,A)}off(B,A){const g=this._listeners.get(B);g&&g.delete(A)}_emit(B,A){const g=this._listeners.get(B);if(g)for(const I of g)try{I(A)}catch(Q){console.error(Q)}}},ZA.SplatsMesh=be,ZA.TileLoader=ZC,ZA.getOGC3DTilesCopyrightInfo=Me,ZA.splatsFragmentShader=fe,ZA.splatsVertexShader=we,Object.defineProperty(ZA,Symbol.toStringTag,{value:"Module"})});
1503
1503
  //# sourceMappingURL=threedtiles.umd.js.map