UNPKG

cesium

Version:

CesiumJS is a JavaScript library for creating 3D globes and 2D maps in a web browser without a plugin.

27 lines (25 loc) 15.3 kB
/** * @license * Cesium - https://github.com/CesiumGS/cesium * Version 1.144.0 * * Copyright 2011-2022 Cesium Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Columbus View (Pat. Pend.) * * Portions licensed separately. * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details. */ import{a as M}from"./chunk-SL3G6WV5.js";import{a as ut}from"./chunk-AEIJDD3C.js";import"./chunk-WNW5RVPR.js";import"./chunk-PTFQE44E.js";import{a as bt}from"./chunk-3BERLVP2.js";import{a as G}from"./chunk-ER474XE6.js";import"./chunk-HCBOUAOS.js";import"./chunk-LXB5W3RT.js";import{b as _t}from"./chunk-L3KCARNY.js";import{a as Pt}from"./chunk-XBXKBB6E.js";import"./chunk-BMZ3PJJO.js";import"./chunk-Q2AGSIFJ.js";import"./chunk-4XQS6KUO.js";import{a as Nt}from"./chunk-CVUC3Z4F.js";import{a as Dt}from"./chunk-WF6KNLYB.js";import{b as Mt,c as Ct,d as x}from"./chunk-VGKISNF5.js";import{c as St}from"./chunk-VPJRLZMB.js";import"./chunk-635BMVFD.js";import{j as Et}from"./chunk-Y7Z6CVXH.js";import"./chunk-HHFPYI7Q.js";import{a as F}from"./chunk-SSZI3JCE.js";import"./chunk-LP5YXEIX.js";import"./chunk-AMKKUAL3.js";import{a as At,c as Y}from"./chunk-WORPNHJT.js";import{a as o,c as Tt}from"./chunk-SWCW4GSU.js";import{a as st}from"./chunk-PZM5FOOW.js";import{b as it}from"./chunk-3MNKUQ6L.js";import{f as X}from"./chunk-J4SK6SKL.js";var Rt=new o,kt=new o,yt=new o,wt=new o,jt=new o,Ht=new o,at=new o,dt=new o;function Ut(t,e){for(let i=0;i<t.length;i++)t[i]=e.scaleToGeodeticSurface(t[i],t[i]);return t}function Z(t,e,i,r,d,f){let g=t.normals,O=t.tangents,p=t.bitangents,s=o.normalize(o.cross(i,e,at),at);f.normal&&M.addAttribute(g,e,r,d),f.tangent&&M.addAttribute(O,s,r,d),f.bitangent&&M.addAttribute(p,i,r,d)}function Bt(t,e,i){let r=t.positions,d=t.corners,f=t.endPositions,g=t.lefts,O=t.normals,p=new Dt,s=0,a=0,n,c=0,u;for(n=0;n<r.length;n+=2)u=r[n].length-3,s+=u,c+=u*2,a+=r[n+1].length-3;for(s+=3,a+=3,n=0;n<d.length;n++){let l=d[n].leftPositions;X(l)?(u=l.length,s+=u,c+=u):(u=d[n].rightPositions.length,a+=u,c+=u)}let A=X(f),h;A&&(h=f[0].length-3,s+=h,a+=h,h/=3,c+=h*6);let E=s+a,m=new Float64Array(E),k=e.normal?new Float32Array(E):void 0,C=e.tangent?new Float32Array(E):void 0,D=e.bitangent?new Float32Array(E):void 0,V={normals:k,tangents:C,bitangents:D},b=0,y=E-1,j,N,L,H,P=Rt,w=kt,nt,ot,pt=h/2,_=Nt.createTypedArray(E/3,c),T=0;if(A){ot=yt,nt=wt;let l=f[0];for(P=o.fromArray(O,0,P),w=o.fromArray(g,0,w),n=0;n<pt;n++)ot=o.fromArray(l,(pt-1-n)*3,ot),nt=o.fromArray(l,(pt+n)*3,nt),M.addAttribute(m,nt,b),M.addAttribute(m,ot,void 0,y),Z(V,P,w,b,y,e),N=b/3,H=N+1,j=(y-2)/3,L=j-1,_[T++]=j,_[T++]=N,_[T++]=L,_[T++]=L,_[T++]=N,_[T++]=H,b+=3,y-=3}let mt=0,ft=0,rt=r[mt++],q=r[mt++];m.set(rt,b),m.set(q,y-q.length+1),w=o.fromArray(g,ft,w);let lt,ct;for(u=q.length-3,n=0;n<u;n+=3)lt=i.geodeticSurfaceNormal(o.fromArray(rt,n,at),at),ct=i.geodeticSurfaceNormal(o.fromArray(q,u-n,dt),dt),P=o.normalize(o.add(lt,ct,P),P),Z(V,P,w,b,y,e),N=b/3,H=N+1,j=(y-2)/3,L=j-1,_[T++]=j,_[T++]=N,_[T++]=L,_[T++]=L,_[T++]=N,_[T++]=H,b+=3,y-=3;for(lt=i.geodeticSurfaceNormal(o.fromArray(rt,u,at),at),ct=i.geodeticSurfaceNormal(o.fromArray(q,u,dt),dt),P=o.normalize(o.add(lt,ct,P),P),ft+=3,n=0;n<d.length;n++){let l,v=d[n],$=v.leftPositions,z=v.rightPositions,J,S,R=Ht,U=yt,B=wt;if(P=o.fromArray(O,ft,P),X($)){for(Z(V,P,w,void 0,y,e),y-=3,J=H,S=L,l=0;l<$.length/3;l++)R=o.fromArray($,l*3,R),_[T++]=J,_[T++]=S-l-1,_[T++]=S-l,M.addAttribute(m,R,void 0,y),U=o.fromArray(m,(S-l-1)*3,U),B=o.fromArray(m,J*3,B),w=o.normalize(o.subtract(U,B,w),w),Z(V,P,w,void 0,y,e),y-=3;R=o.fromArray(m,J*3,R),U=o.subtract(o.fromArray(m,S*3,U),R,U),B=o.subtract(o.fromArray(m,(S-l)*3,B),R,B),w=o.normalize(o.add(U,B,w),w),Z(V,P,w,b,void 0,e),b+=3}else{for(Z(V,P,w,b,void 0,e),b+=3,J=L,S=H,l=0;l<z.length/3;l++)R=o.fromArray(z,l*3,R),_[T++]=J,_[T++]=S+l,_[T++]=S+l+1,M.addAttribute(m,R,b),U=o.fromArray(m,J*3,U),B=o.fromArray(m,(S+l)*3,B),w=o.normalize(o.subtract(U,B,w),w),Z(V,P,w,b,void 0,e),b+=3;R=o.fromArray(m,J*3,R),U=o.subtract(o.fromArray(m,(S+l)*3,U),R,U),B=o.subtract(o.fromArray(m,S*3,B),R,B),w=o.normalize(o.negate(o.add(B,U,w),w),w),Z(V,P,w,void 0,y,e),y-=3}for(rt=r[mt++],q=r[mt++],rt.splice(0,3),q.splice(q.length-3,3),m.set(rt,b),m.set(q,y-q.length+1),u=q.length-3,ft+=3,w=o.fromArray(g,ft,w),l=0;l<q.length;l+=3)lt=i.geodeticSurfaceNormal(o.fromArray(rt,l,at),at),ct=i.geodeticSurfaceNormal(o.fromArray(q,u-l,dt),dt),P=o.normalize(o.add(lt,ct,P),P),Z(V,P,w,b,y,e),H=b/3,N=H-1,L=(y-2)/3,j=L+1,_[T++]=j,_[T++]=N,_[T++]=L,_[T++]=L,_[T++]=N,_[T++]=H,b+=3,y-=3;b-=3,y+=3}if(P=o.fromArray(O,O.length-3,P),Z(V,P,w,b,y,e),A){b+=3,y-=3,ot=yt,nt=wt;let l=f[1];for(n=0;n<pt;n++)ot=o.fromArray(l,(h-n-1)*3,ot),nt=o.fromArray(l,n*3,nt),M.addAttribute(m,ot,void 0,y),M.addAttribute(m,nt,b),Z(V,P,w,b,y,e),H=b/3,N=H-1,L=(y-2)/3,j=L+1,_[T++]=j,_[T++]=N,_[T++]=L,_[T++]=L,_[T++]=N,_[T++]=H,b+=3,y-=3}if(p.position=new x({componentDatatype:F.DOUBLE,componentsPerAttribute:3,values:m}),e.st){let l=new Float32Array(E/3*2),v,$,z=0;if(A){s/=3,a/=3;let J=Math.PI/(h+1);$=1/(s-h+1),v=1/(a-h+1);let S,R=h/2;for(n=R+1;n<h+1;n++)S=st.PI_OVER_TWO+J*n,l[z++]=v*(1+Math.cos(S)),l[z++]=.5*(1+Math.sin(S));for(n=1;n<a-h+1;n++)l[z++]=n*v,l[z++]=0;for(n=h;n>R;n--)S=st.PI_OVER_TWO-n*J,l[z++]=1-v*(1+Math.cos(S)),l[z++]=.5*(1+Math.sin(S));for(n=R;n>0;n--)S=st.PI_OVER_TWO-J*n,l[z++]=1-$*(1+Math.cos(S)),l[z++]=.5*(1+Math.sin(S));for(n=s-h;n>0;n--)l[z++]=n*$,l[z++]=1;for(n=1;n<R+1;n++)S=st.PI_OVER_TWO+J*n,l[z++]=$*(1+Math.cos(S)),l[z++]=.5*(1+Math.sin(S))}else{for(s/=3,a/=3,$=1/(s-1),v=1/(a-1),n=0;n<a;n++)l[z++]=n*v,l[z++]=0;for(n=s;n>0;n--)l[z++]=(n-1)*$,l[z++]=1}p.st=new x({componentDatatype:F.FLOAT,componentsPerAttribute:2,values:l})}return e.normal&&(p.normal=new x({componentDatatype:F.FLOAT,componentsPerAttribute:3,values:V.normals})),e.tangent&&(p.tangent=new x({componentDatatype:F.FLOAT,componentsPerAttribute:3,values:V.tangents})),e.bitangent&&(p.bitangent=new x({componentDatatype:F.FLOAT,componentsPerAttribute:3,values:V.bitangents})),{attributes:p,indices:_}}function qt(t,e){if(!e.normal&&!e.tangent&&!e.bitangent&&!e.st)return t;let i=t.position.values,r,d;(e.normal||e.bitangent)&&(r=t.normal.values,d=t.bitangent.values);let f=t.position.values.length/18,g=f*3,O=f*2,p=g*2,s;if(e.normal||e.bitangent||e.tangent){let a=e.normal?new Float32Array(g*6):void 0,n=e.tangent?new Float32Array(g*6):void 0,c=e.bitangent?new Float32Array(g*6):void 0,u=Rt,A=kt,h=yt,E=wt,m=jt,k=Ht,C=p;for(s=0;s<g;s+=3){let D=C+p;u=o.fromArray(i,s,u),A=o.fromArray(i,s+g,A),h=o.fromArray(i,(s+3)%g,h),A=o.subtract(A,u,A),h=o.subtract(h,u,h),E=o.normalize(o.cross(A,h,E),E),e.normal&&(M.addAttribute(a,E,D),M.addAttribute(a,E,D+3),M.addAttribute(a,E,C),M.addAttribute(a,E,C+3)),(e.tangent||e.bitangent)&&(k=o.fromArray(r,s,k),e.bitangent&&(M.addAttribute(c,k,D),M.addAttribute(c,k,D+3),M.addAttribute(c,k,C),M.addAttribute(c,k,C+3)),e.tangent&&(m=o.normalize(o.cross(k,E,m),m),M.addAttribute(n,m,D),M.addAttribute(n,m,D+3),M.addAttribute(n,m,C),M.addAttribute(n,m,C+3))),C+=6}if(e.normal){for(a.set(r),s=0;s<g;s+=3)a[s+g]=-r[s],a[s+g+1]=-r[s+1],a[s+g+2]=-r[s+2];t.normal.values=a}else t.normal=void 0;if(e.bitangent?(c.set(d),c.set(d,g),t.bitangent.values=c):t.bitangent=void 0,e.tangent){let D=t.tangent.values;n.set(D),n.set(D,g),t.tangent.values=n}}if(e.st){let a=t.st.values,n=new Float32Array(O*6);n.set(a),n.set(a,O);let c=O*2;for(let u=0;u<2;u++){for(n[c++]=a[0],n[c++]=a[1],s=2;s<O;s+=2){let A=a[s],h=a[s+1];n[c++]=A,n[c++]=h,n[c++]=A,n[c++]=h}n[c++]=a[0],n[c++]=a[1]}t.st.values=n}return t}function Ot(t,e,i){i[e++]=t[0],i[e++]=t[1],i[e++]=t[2];for(let r=3;r<t.length;r+=3){let d=t[r],f=t[r+1],g=t[r+2];i[e++]=d,i[e++]=f,i[e++]=g,i[e++]=d,i[e++]=f,i[e++]=g}return i[e++]=t[0],i[e++]=t[1],i[e]=t[2],i}function Jt(t,e){let i=new G({position:e.position,normal:e.normal||e.bitangent||t.shadowVolume,tangent:e.tangent,bitangent:e.normal||e.bitangent,st:e.st}),r=t.ellipsoid,d=M.computePositions(t),f=Bt(d,i,r),g=t.height,O=t.extrudedHeight,p=f.attributes,s=f.indices,a=p.position.values,n=a.length,c=new Float64Array(n*6),u=new Float64Array(n);u.set(a);let A=new Float64Array(n*4);a=_t.scaleToGeodeticHeight(a,g,r),A=Ot(a,0,A),u=_t.scaleToGeodeticHeight(u,O,r),A=Ot(u,n*2,A),c.set(a),c.set(u,n),c.set(A,n*2),p.position.values=c,p=qt(p,e);let h,E=n/3;if(t.shadowVolume){let N=p.normal.values;n=N.length;let L=new Float32Array(n*6);for(h=0;h<n;h++)N[h]=-N[h];L.set(N,n),L=Ot(N,n*4,L),p.extrudeDirection=new x({componentDatatype:F.FLOAT,componentsPerAttribute:3,values:L}),e.normal||(p.normal=void 0)}if(X(t.offsetAttribute)){let N=new Uint8Array(E*6);if(t.offsetAttribute===bt.TOP)N=N.fill(1,0,E).fill(1,E*2,E*4);else{let L=t.offsetAttribute===bt.NONE?0:1;N=N.fill(L)}p.applyOffset=new x({componentDatatype:F.UNSIGNED_BYTE,componentsPerAttribute:1,values:N})}let m=s.length,k=E+E,C=Nt.createTypedArray(c.length/3,m*2+k*3);C.set(s);let D=m;for(h=0;h<m;h+=3){let N=s[h],L=s[h+1],H=s[h+2];C[D++]=H+E,C[D++]=L+E,C[D++]=N+E}let V,b,y,j;for(h=0;h<k;h+=2)V=h+k,b=V+k,y=V+1,j=b+1,C[D++]=V,C[D++]=b,C[D++]=y,C[D++]=y,C[D++]=b,C[D++]=j;return{attributes:p,indices:C}}var Vt=new o,ht=new o,Q=new At;function zt(t,e,i,r,d,f){let g=o.subtract(e,t,Vt);o.normalize(g,g);let O=i.geodeticSurfaceNormal(t,ht),p=o.cross(g,O,Vt);o.multiplyByScalar(p,r,p);let s=d.latitude,a=d.longitude,n=f.latitude,c=f.longitude;o.add(t,p,ht),i.cartesianToCartographic(ht,Q);let u=Q.latitude,A=Q.longitude;s=Math.min(s,u),a=Math.min(a,A),n=Math.max(n,u),c=Math.max(c,A),o.subtract(t,p,ht),i.cartesianToCartographic(ht,Q),u=Q.latitude,A=Q.longitude,s=Math.min(s,u),a=Math.min(a,A),n=Math.max(n,u),c=Math.max(c,A),d.latitude=s,d.longitude=a,f.latitude=n,f.longitude=c}var K=new o,gt=new o,I=new At,W=new At;function Yt(t,e,i,r,d){t=Ut(t,e);let f=Pt(t,o.equalsEpsilon),g=f.length;if(g<2||i<=0)return new Et;let O=i*.5;I.latitude=Number.POSITIVE_INFINITY,I.longitude=Number.POSITIVE_INFINITY,W.latitude=Number.NEGATIVE_INFINITY,W.longitude=Number.NEGATIVE_INFINITY;let p,s;if(r===ut.ROUNDED){let c=f[0];o.subtract(c,f[1],K),o.normalize(K,K),o.multiplyByScalar(K,O,K),o.add(c,K,gt),e.cartesianToCartographic(gt,Q),p=Q.latitude,s=Q.longitude,I.latitude=Math.min(I.latitude,p),I.longitude=Math.min(I.longitude,s),W.latitude=Math.max(W.latitude,p),W.longitude=Math.max(W.longitude,s)}for(let c=0;c<g-1;++c)zt(f[c],f[c+1],e,O,I,W);let a=f[g-1];o.subtract(a,f[g-2],K),o.normalize(K,K),o.multiplyByScalar(K,O,K),o.add(a,K,gt),zt(a,gt,e,O,I,W),r===ut.ROUNDED&&(e.cartesianToCartographic(gt,Q),p=Q.latitude,s=Q.longitude,I.latitude=Math.min(I.latitude,p),I.longitude=Math.min(I.longitude,s),W.latitude=Math.max(W.latitude,p),W.longitude=Math.max(W.longitude,s));let n=X(d)?d:new Et;return n.north=W.latitude,n.south=I.latitude,n.east=W.longitude,n.west=I.longitude,n}function et(t){t=t??Tt.EMPTY_OBJECT;let e=t.positions,i=t.width;it.defined("options.positions",e),it.defined("options.width",i);let r=t.height??0,d=t.extrudedHeight??r;this._positions=e,this._ellipsoid=Y.clone(t.ellipsoid??Y.default),this._vertexFormat=G.clone(t.vertexFormat??G.DEFAULT),this._width=i,this._height=Math.max(r,d),this._extrudedHeight=Math.min(r,d),this._cornerType=t.cornerType??ut.ROUNDED,this._granularity=t.granularity??st.RADIANS_PER_DEGREE,this._shadowVolume=t.shadowVolume??!1,this._workerName="createCorridorGeometry",this._offsetAttribute=t.offsetAttribute,this._rectangle=void 0,this.packedLength=1+e.length*o.packedLength+Y.packedLength+G.packedLength+7}et.pack=function(t,e,i){it.defined("value",t),it.defined("array",e),i=i??0;let r=t._positions,d=r.length;e[i++]=d;for(let f=0;f<d;++f,i+=o.packedLength)o.pack(r[f],e,i);return Y.pack(t._ellipsoid,e,i),i+=Y.packedLength,G.pack(t._vertexFormat,e,i),i+=G.packedLength,e[i++]=t._width,e[i++]=t._height,e[i++]=t._extrudedHeight,e[i++]=t._cornerType,e[i++]=t._granularity,e[i++]=t._shadowVolume?1:0,e[i]=t._offsetAttribute??-1,e};var It=Y.clone(Y.UNIT_SPHERE),Wt=new G,tt={positions:void 0,ellipsoid:It,vertexFormat:Wt,width:void 0,height:void 0,extrudedHeight:void 0,cornerType:void 0,granularity:void 0,shadowVolume:void 0,offsetAttribute:void 0};et.unpack=function(t,e,i){it.defined("array",t),e=e??0;let r=t[e++],d=new Array(r);for(let A=0;A<r;++A,e+=o.packedLength)d[A]=o.unpack(t,e);let f=Y.unpack(t,e,It);e+=Y.packedLength;let g=G.unpack(t,e,Wt);e+=G.packedLength;let O=t[e++],p=t[e++],s=t[e++],a=t[e++],n=t[e++],c=t[e++]===1,u=t[e];return X(i)?(i._positions=d,i._ellipsoid=Y.clone(f,i._ellipsoid),i._vertexFormat=G.clone(g,i._vertexFormat),i._width=O,i._height=p,i._extrudedHeight=s,i._cornerType=a,i._granularity=n,i._shadowVolume=c,i._offsetAttribute=u===-1?void 0:u,i):(tt.positions=d,tt.width=O,tt.height=p,tt.extrudedHeight=s,tt.cornerType=a,tt.granularity=n,tt.shadowVolume=c,tt.offsetAttribute=u===-1?void 0:u,new et(tt))};et.computeRectangle=function(t,e){t=t??Tt.EMPTY_OBJECT;let i=t.positions,r=t.width;it.defined("options.positions",i),it.defined("options.width",r);let d=t.ellipsoid??Y.default,f=t.cornerType??ut.ROUNDED;return Yt(i,d,r,f,e)};et.createGeometry=function(t){let e=t._positions,i=t._width,r=t._ellipsoid;e=Ut(e,r);let d=Pt(e,o.equalsEpsilon);if(d.length<2||i<=0)return;let f=t._height,g=t._extrudedHeight,O=!st.equalsEpsilon(f,g,0,st.EPSILON2),p=t._vertexFormat,s={ellipsoid:r,positions:d,width:i,cornerType:t._cornerType,granularity:t._granularity,saveAttributes:!0},a;if(O)s.height=f,s.extrudedHeight=g,s.shadowVolume=t._shadowVolume,s.offsetAttribute=t._offsetAttribute,a=Jt(s,p);else{let u=M.computePositions(s);if(a=Bt(u,p,r),a.attributes.position.values=_t.scaleToGeodeticHeight(a.attributes.position.values,f,r),X(t._offsetAttribute)){let A=t._offsetAttribute===bt.NONE?0:1,h=a.attributes.position.values.length,E=new Uint8Array(h/3).fill(A);a.attributes.applyOffset=new x({componentDatatype:F.UNSIGNED_BYTE,componentsPerAttribute:1,values:E})}}let n=a.attributes,c=St.fromVertices(n.position.values,void 0,3);return p.position||(a.attributes.position.values=void 0),new Ct({attributes:n,indices:a.indices,primitiveType:Mt.TRIANGLES,boundingSphere:c,offsetAttribute:t._offsetAttribute})};et.createShadowVolume=function(t,e,i){let r=t._granularity,d=t._ellipsoid,f=e(r,d),g=i(r,d);return new et({positions:t._positions,width:t._width,cornerType:t._cornerType,ellipsoid:d,granularity:r,extrudedHeight:f,height:g,vertexFormat:G.POSITION_ONLY,shadowVolume:!0})};Object.defineProperties(et.prototype,{rectangle:{get:function(){return X(this._rectangle)||(this._rectangle=Yt(this._positions,this._ellipsoid,this._width,this._cornerType)),this._rectangle}},textureCoordinateRotationPoints:{get:function(){return[0,0,0,1,1,0]}}});var Lt=et;function Gt(t,e){return X(e)&&(t=Lt.unpack(t,e)),t._ellipsoid=Y.clone(t._ellipsoid),Lt.createGeometry(t)}var Ae=Gt;export{Ae as default};