import{a as N}from"./chunk-EZRSLM27.js";import{d as Q}from"./chunk-ZPW6H6BB.js";import{b as d,i as Z}from"./chunk-HMXXHGCW.js";import{a as k}from"./chunk-NFDMGE7Q.js";import{b as s,c as U,d as x,e as O}from"./chunk-VDZXURWO.js";import{a as w}from"./chunk-UEFEFMYS.js";import{a as P}from"./chunk-5HWP5DW7.js";import{a as D,b as T}from"./chunk-3K67FZLU.js";import{e as h}from"./chunk-55TU6MJR.js";function z(o,t){T.typeOf.object("ellipsoid",o),this._ellipsoid=o,this._cameraPosition=new s,this._cameraPositionInScaledSpace=new s,this._distanceToLimbInScaledSpaceSquared=0,h(t)&&(this.cameraPosition=t)}Object.defineProperties(z.prototype,{ellipsoid:{get:function(){return this._ellipsoid}},cameraPosition:{get:function(){return this._cameraPosition},set:function(o){let e=this._ellipsoid.transformPositionToScaledSpace(o,this._cameraPositionInScaledSpace),a=s.magnitudeSquared(e)-1;s.clone(o,this._cameraPosition),this._cameraPositionInScaledSpace=e,this._distanceToLimbInScaledSpaceSquared=a}}});var v=new s;z.prototype.isPointVisible=function(o){let e=this._ellipsoid.transformPositionToScaledSpace(o,v);return W(e,this._cameraPositionInScaledSpace,this._distanceToLimbInScaledSpaceSquared)};z.prototype.isScaledSpacePointVisible=function(o){return W(o,this._cameraPositionInScaledSpace,this._distanceToLimbInScaledSpaceSquared)};var nt=new s;z.prototype.isScaledSpacePointVisiblePossiblyUnderEllipsoid=function(o,t){let e=this._ellipsoid,a,i;return h(t)&&t<0&&e.minimumRadius>-t?(i=nt,i.x=this._cameraPosition.x/(e.radii.x+t),i.y=this._cameraPosition.y/(e.radii.y+t),i.z=this._cameraPosition.z/(e.radii.z+t),a=i.x*i.x+i.y*i.y+i.z*i.z-1):(i=this._cameraPositionInScaledSpace,a=this._distanceToLimbInScaledSpaceSquared),W(o,i,a)};z.prototype.computeHorizonCullingPoint=function(o,t,e){return X(this._ellipsoid,o,t,e)};var J=O.clone(O.UNIT_SPHERE);z.prototype.computeHorizonCullingPointPossiblyUnderEllipsoid=function(o,t,e,a){let i=K(this._ellipsoid,e,J);return X(i,o,t,a)};z.prototype.computeHorizonCullingPointFromVertices=function(o,t,e,a,i){return Y(this._ellipsoid,o,t,e,a,i)};z.prototype.computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid=function(o,t,e,a,i,c){let n=K(this._ellipsoid,i,J);return Y(n,o,t,e,a,c)};var st=[];z.prototype.computeHorizonCullingPointFromRectangle=function(o,t,e){T.typeOf.object("rectangle",o);let a=Z.subsample(o,t,0,st),i=Q.fromPoints(a);if(!(s.magnitude(i.center)<.1*t.minimumRadius))return this.computeHorizonCullingPoint(i.center,a,e)};var ct=new s;function K(o,t,e){if(h(t)&&t<0&&o.minimumRadius>-t){let a=s.fromElements(o.radii.x+t,o.radii.y+t,o.radii.z+t,ct);o=O.fromCartesian3(a,e)}return o}function X(o,t,e,a){T.typeOf.object("directionToPoint",t),T.defined("positions",e),h(a)||(a=new s);let i=tt(o,t),c=0;for(let n=0,r=e.length;n<r;++n){let m=e[n],p=$(o,m,i);if(p<0)return;c=Math.max(c,p)}return B(i,c,a)}var V=new s;function Y(o,t,e,a,i,c){T.typeOf.object("directionToPoint",t),T.defined("vertices",e),T.typeOf.number("stride",a),h(c)||(c=new s),a=P(a,3),i=P(i,s.ZERO);let n=tt(o,t),r=0;for(let m=0,p=e.length;m<p;m+=a){V.x=e[m]+i.x,V.y=e[m+1]+i.y,V.z=e[m+2]+i.z;let u=$(o,V,n);if(u<0)return;r=Math.max(r,u)}return B(n,r,c)}function W(o,t,e){let a=t,i=e,c=s.subtract(o,a,v),n=-s.dot(c,a);return!(i<0?n>0:n>i&&n*n/s.magnitudeSquared(c)>i)}var rt=new s,mt=new s;function $(o,t,e){let a=o.transformPositionToScaledSpace(t,rt),i=s.magnitudeSquared(a),c=Math.sqrt(i),n=s.divideByScalar(a,c,mt);i=Math.max(1,i),c=Math.max(1,c);let r=s.dot(n,e),m=s.magnitude(s.cross(n,e,n)),p=1/c,u=Math.sqrt(i-1)*p;return 1/(r*p-m*u)}function B(o,t,e){if(!(t<=0||t===1/0||t!==t))return s.multiplyByScalar(o,t,e)}var F=new s;function tt(o,t){return s.equals(t,s.ZERO)?t:(o.transformPositionToScaledSpace(t,F),s.normalize(F,F))}var Pt=z;var G={};G.getHeight=function(o,t,e){if(!Number.isFinite(t))throw new D("scale must be a finite number.");if(!Number.isFinite(e))throw new D("relativeHeight must be a finite number.");return(o-e)*t+e};var dt=new U;G.getPosition=function(o,t,e,a,i){let c=t.cartesianToCartographic(o,dt);if(!h(c))return s.clone(o,i);let n=G.getHeight(c.height,e,a);return s.fromRadians(c.longitude,c.latitude,n,t,i)};var ot=G;var ht={NONE:0,BITS12:1},S=Object.freeze(ht);var C=new s,lt=new s,f=new x,H=new d,pt=new d,ut=Math.pow(2,12);function l(o,t,e,a,i,c,n,r,m,p){let u=S.NONE,y,g;if(h(t)&&h(e)&&h(a)&&h(i)){let E=t.minimum,I=t.maximum,_=s.subtract(I,E,lt),A=a-e;Math.max(s.maximumComponent(_),A)<ut-1?u=S.BITS12:u=S.NONE,y=d.inverseTransformation(i,new d);let R=s.negate(E,C);d.multiply(d.fromTranslation(R,H),y,y);let b=C;b.x=1/_.x,b.y=1/_.y,b.z=1/_.z,d.multiply(d.fromScale(b,H),y,y),g=d.clone(i),d.setTranslation(g,s.ZERO,g),i=d.clone(i,new d);let it=d.fromTranslation(E,H),at=d.fromScale(_,pt),j=d.multiply(it,at,H);d.multiply(i,j,i),d.multiply(g,j,g)}this.quantization=u,this.minimumHeight=e,this.maximumHeight=a,this.center=s.clone(o),this.toScaledENU=y,this.fromScaledENU=i,this.matrix=g,this.hasVertexNormals=c,this.hasWebMercatorT=P(n,!1),this.hasGeodeticSurfaceNormals=P(r,!1),this.exaggeration=P(m,1),this.exaggerationRelativeHeight=P(p,0),this.stride=0,this._offsetGeodeticSurfaceNormal=0,this._offsetVertexNormal=0,this._calculateStrideAndOffsets()}l.prototype.encode=function(o,t,e,a,i,c,n,r,m,p,u){let y=a.x,g=a.y;if(this.quantization===S.BITS12){e=d.multiplyByPoint(this.toScaledENU,e,C),e.x=w.clamp(e.x,0,1),e.y=w.clamp(e.y,0,1),e.z=w.clamp(e.z,0,1);let E=this.maximumHeight-this.minimumHeight,I=w.clamp((i-this.minimumHeight)/E,0,1);x.fromElements(e.x,e.y,f);let _=N.compressTextureCoordinates(f);x.fromElements(e.z,I,f);let A=N.compressTextureCoordinates(f);x.fromElements(y,g,f);let L=N.compressTextureCoordinates(f);if(o[t++]=_,o[t++]=A,o[t++]=L,this.hasWebMercatorT){x.fromElements(n,0,f);let R=N.compressTextureCoordinates(f);o[t++]=R}}else s.subtract(e,this.center,C),o[t++]=C.x,o[t++]=C.y,o[t++]=C.z,o[t++]=i,o[t++]=y,o[t++]=g,this.hasWebMercatorT&&(o[t++]=n);return this.hasVertexNormals&&(m?o[t++]=c:(p&&(c.x=123.456,c.y=123.456),o[t++]=N.octPackFloat(c))),this.hasGeodeticSurfaceNormals&&(o[t++]=r.x,o[t++]=r.y,o[t++]=r.z),o[t++]=u,t};var St=new s,et=new s;l.prototype.addGeodeticSurfaceNormals=function(o,t,e){if(this.hasGeodeticSurfaceNormals)return;let a=this.stride,i=o.length/a;this.hasGeodeticSurfaceNormals=!0,this._calculateStrideAndOffsets();let c=this.stride;for(let n=0;n<i;n++){for(let u=0;u<a;u++){let y=n*a+u,g=n*c+u;t[g]=o[y]}let r=this.decodePosition(t,n,St),m=e.geodeticSurfaceNormal(r,et),p=n*c+this._offsetGeodeticSurfaceNormal;t[p]=m.x,t[p+1]=m.y,t[p+2]=m.z}};l.prototype.removeGeodeticSurfaceNormals=function(o,t){if(!this.hasGeodeticSurfaceNormals)return;let e=this.stride,a=o.length/e;this.hasGeodeticSurfaceNormals=!1,this._calculateStrideAndOffsets();let i=this.stride;for(let c=0;c<a;c++)for(let n=0;n<i;n++){let r=c*e+n,m=c*i+n;t[m]=o[r]}};l.prototype.decodePosition=function(o,t,e){if(h(e)||(e=new s),t*=this.stride,this.quantization===S.BITS12){let a=N.decompressTextureCoordinates(o[t],f);e.x=a.x,e.y=a.y;let i=N.decompressTextureCoordinates(o[t+1],f);return e.z=i.x,d.multiplyByPoint(this.fromScaledENU,e,e)}return e.x=o[t],e.y=o[t+1],e.z=o[t+2],s.add(e,this.center,e)};l.prototype.getExaggeratedPosition=function(o,t,e){e=this.decodePosition(o,t,e);let a=this.exaggeration,i=this.exaggerationRelativeHeight;if(a!==1&&this.hasGeodeticSurfaceNormals){let n=this.decodeGeodeticSurfaceNormal(o,t,et),r=this.decodeHeight(o,t),m=ot.getHeight(r,a,i)-r;e.x+=n.x*m,e.y+=n.y*m,e.z+=n.z*m}return e};l.prototype.decodeTextureCoordinates=function(o,t,e){return h(e)||(e=new x),t*=this.stride,this.quantization===S.BITS12?N.decompressTextureCoordinates(o[t+2],e):x.fromElements(o[t+4],o[t+5],e)};l.prototype.decodeHeight=function(o,t){return t*=this.stride,this.quantization===S.BITS12?N.decompressTextureCoordinates(o[t+1],f).y*(this.maximumHeight-this.minimumHeight)+this.minimumHeight:o[t+3]};l.prototype.decodeWebMercatorT=function(o,t){return t*=this.stride,this.quantization===S.BITS12?N.decompressTextureCoordinates(o[t+3],f).x:o[t+6]};l.prototype.getOctEncodedNormal=function(o,t,e){t=t*this.stride+this._offsetVertexNormal;let a=o[t]/256,i=Math.floor(a),c=(a-i)*256;return x.fromElements(i,c,e)};l.prototype.decodeGeodeticSurfaceNormal=function(o,t,e){return t=t*this.stride+this._offsetGeodeticSurfaceNormal,e.x=o[t],e.y=o[t+1],e.z=o[t+2],e};l.prototype._calculateStrideAndOffsets=function(){let o=0;switch(this.quantization){case S.BITS12:o+=3;break;default:o+=6}this.hasWebMercatorT&&(o+=1),this.hasVertexNormals&&(this._offsetVertexNormal=o,o+=1),this.hasGeodeticSurfaceNormals&&(this._offsetGeodeticSurfaceNormal=o,o+=3),o+=1,this.stride=o};var q={position3DAndHeight:0,textureCoordAndEncodedNormals:1,geodeticSurfaceNormal:2,skirt:3},M={compressed0:0,compressed1:1,geodeticSurfaceNormal:2,skirt:3};l.prototype.getAttributes=function(o){let t=k.FLOAT,e=k.getSizeInBytes(t),a=this.stride*e,i=0,c=[];function n(r,m){c.push({index:r,vertexBuffer:o,componentDatatype:t,componentsPerAttribute:m,offsetInBytes:i,strideInBytes:a}),i+=m*e}if(this.quantization===S.NONE){n(q.position3DAndHeight,4);let r=2;r+=this.hasWebMercatorT?1:0,r+=this.hasVertexNormals?1:0,n(q.textureCoordAndEncodedNormals,r),this.hasGeodeticSurfaceNormals&&n(q.geodeticSurfaceNormal,3),n(q.skirt,1)}else{let r=this.hasWebMercatorT||this.hasVertexNormals,m=this.hasWebMercatorT&&this.hasVertexNormals;n(M.compressed0,r?4:3),m&&n(M.compressed1,1),this.hasGeodeticSurfaceNormals&&n(M.geodeticSurfaceNormal,3),n(M.skirt,1)}return c};l.prototype.getAttributeLocations=function(){return this.quantization===S.NONE?q:M};l.clone=function(o,t){if(h(o))return h(t)||(t=new l),t.quantization=o.quantization,t.minimumHeight=o.minimumHeight,t.maximumHeight=o.maximumHeight,t.center=s.clone(o.center),t.toScaledENU=d.clone(o.toScaledENU),t.fromScaledENU=d.clone(o.fromScaledENU),t.matrix=d.clone(o.matrix),t.hasVertexNormals=o.hasVertexNormals,t.hasWebMercatorT=o.hasWebMercatorT,t.hasGeodeticSurfaceNormals=o.hasGeodeticSurfaceNormals,t.exaggeration=o.exaggeration,t.exaggerationRelativeHeight=o.exaggerationRelativeHeight,t._calculateStrideAndOffsets(),t};var Wt=l;export{Pt as a,Wt as b};
|