surprise
2023-12-29 18377dc5d61caf3a6a0835e17015ac2601f8709d
1
define(["./AttributeCompression-747df01a","./Transforms-b2d190a4","./Matrix2-671a840a","./defaultValue-69ee94f4","./TerrainEncoding-8b4ef476","./IndexDatatype-1cbc8622","./RuntimeError-ac440aa5","./ComponentDatatype-a9820060","./OrientedBoundingBox-20c61072","./createTaskProcessorWorker","./_commonjsHelpers-3aae1032-15991586","./combine-0259f56f","./PixelFormat-9ceadbf3","./WebGLConstants-f63312fc","./EllipsoidTangentPlane-8dba80f8","./AxisAlignedBoundingBox-41c092aa","./IntersectionTests-3c5a408d","./Plane-2cd3a9dd"],(function(e,t,n,i,s,r,h,o,u,d,p,a,l,f,c,g,m,x){"use strict";const w={clipTriangleAtAxisAlignedThreshold:function(e,t,n,s,r,h){let o,u,d;i.defined(h)?h.length=0:h=[],t?(o=n<e,u=s<e,d=r<e):(o=n>e,u=s>e,d=r>e);const p=o+u+d;let a,l,f,c,g,m;return 1===p?o?(a=(e-n)/(s-n),l=(e-n)/(r-n),h.push(1),h.push(2),1!==l&&(h.push(-1),h.push(0),h.push(2),h.push(l)),1!==a&&(h.push(-1),h.push(0),h.push(1),h.push(a))):u?(f=(e-s)/(r-s),c=(e-s)/(n-s),h.push(2),h.push(0),1!==c&&(h.push(-1),h.push(1),h.push(0),h.push(c)),1!==f&&(h.push(-1),h.push(1),h.push(2),h.push(f))):d&&(g=(e-r)/(n-r),m=(e-r)/(s-r),h.push(0),h.push(1),1!==m&&(h.push(-1),h.push(2),h.push(1),h.push(m)),1!==g&&(h.push(-1),h.push(2),h.push(0),h.push(g))):2===p?o||n===e?u||s===e?d||r===e||(l=(e-n)/(r-n),f=(e-s)/(r-s),h.push(2),h.push(-1),h.push(0),h.push(2),h.push(l),h.push(-1),h.push(1),h.push(2),h.push(f)):(m=(e-r)/(s-r),a=(e-n)/(s-n),h.push(1),h.push(-1),h.push(2),h.push(1),h.push(m),h.push(-1),h.push(0),h.push(1),h.push(a)):(c=(e-s)/(n-s),g=(e-r)/(n-r),h.push(0),h.push(-1),h.push(1),h.push(0),h.push(c),h.push(-1),h.push(2),h.push(0),h.push(g)):3!==p&&(h.push(0),h.push(1),h.push(2)),h},computeBarycentricCoordinates:function(e,t,s,r,h,o,u,d,p){const a=s-u,l=u-h,f=o-d,c=r-d,g=1/(f*a+l*c),m=t-d,x=e-u,w=(f*x+l*m)*g,C=(-c*x+a*m)*g,B=1-w-C;return i.defined(p)?(p.x=w,p.y=C,p.z=B,p):new n.Cartesian3(w,C,B)},computeLineSegmentLineSegmentIntersection:function(e,t,s,r,h,o,u,d,p){const a=(d-o)*(s-e)-(u-h)*(r-t);if(0===a)return;const l=((u-h)*(t-o)-(d-o)*(e-h))/a,f=((s-e)*(t-o)-(r-t)*(e-h))/a;return l>=0&&l<=1&&f>=0&&f<=1?(i.defined(p)||(p=new n.Cartesian2),p.x=e+l*(s-e),p.y=t+l*(r-t),p):void 0}},C=32767,B=16383,y=[],I=[],A=[],b=new n.Cartographic;let v=new n.Cartesian3;const T=[],z=[],V=[],M=[],N=[],E=new n.Cartesian3,H=new t.BoundingSphere,R=new u.OrientedBoundingBox,O=new n.Cartesian2,F=new n.Cartesian3;function P(){this.vertexBuffer=void 0,this.index=void 0,this.first=void 0,this.second=void 0,this.ratio=void 0}P.prototype.clone=function(e){return i.defined(e)||(e=new P),e.uBuffer=this.uBuffer,e.vBuffer=this.vBuffer,e.heightBuffer=this.heightBuffer,e.normalBuffer=this.normalBuffer,e.index=this.index,e.first=this.first,e.second=this.second,e.ratio=this.ratio,e},P.prototype.initializeIndexed=function(e,t,n,i,s){this.uBuffer=e,this.vBuffer=t,this.heightBuffer=n,this.normalBuffer=i,this.index=s,this.first=void 0,this.second=void 0,this.ratio=void 0},P.prototype.initializeFromClipResult=function(e,t,n){let i=t+1;return-1!==e[t]?n[e[t]].clone(this):(this.vertexBuffer=void 0,this.index=void 0,this.first=n[e[i]],++i,this.second=n[e[i]],++i,this.ratio=e[i],++i),i},P.prototype.getKey=function(){return this.isIndexed()?this.index:JSON.stringify({first:this.first.getKey(),second:this.second.getKey(),ratio:this.ratio})},P.prototype.isIndexed=function(){return i.defined(this.index)},P.prototype.getH=function(){return i.defined(this.index)?this.heightBuffer[this.index]:o.CesiumMath.lerp(this.first.getH(),this.second.getH(),this.ratio)},P.prototype.getU=function(){return i.defined(this.index)?this.uBuffer[this.index]:o.CesiumMath.lerp(this.first.getU(),this.second.getU(),this.ratio)},P.prototype.getV=function(){return i.defined(this.index)?this.vBuffer[this.index]:o.CesiumMath.lerp(this.first.getV(),this.second.getV(),this.ratio)};let S=new n.Cartesian2,U=-1;const D=[new n.Cartesian3,new n.Cartesian3],W=[new n.Cartesian3,new n.Cartesian3];function X(t,i){++U;let s=D[U],r=W[U];return s=e.AttributeCompression.octDecode(t.first.getNormalX(),t.first.getNormalY(),s),r=e.AttributeCompression.octDecode(t.second.getNormalX(),t.second.getNormalY(),r),v=n.Cartesian3.lerp(s,r,t.ratio,v),n.Cartesian3.normalize(v,v),e.AttributeCompression.octEncode(v,i),--U,i}P.prototype.getNormalX=function(){return i.defined(this.index)?this.normalBuffer[2*this.index]:(S=X(this,S),S.x)},P.prototype.getNormalY=function(){return i.defined(this.index)?this.normalBuffer[2*this.index+1]:(S=X(this,S),S.y)};const k=[];function K(e,t,n,s,r,h,o,u,d){if(0===o.length)return;let p=0,a=0;for(;a<o.length;)a=k[p++].initializeFromClipResult(o,a,u);for(let r=0;r<p;++r){const o=k[r];if(o.isIndexed())o.newIndex=h[o.index],o.uBuffer=e,o.vBuffer=t,o.heightBuffer=n,d&&(o.normalBuffer=s);else{const r=o.getKey();if(i.defined(h[r]))o.newIndex=h[r];else{const i=e.length;e.push(o.getU()),t.push(o.getV()),n.push(o.getH()),d&&(s.push(o.getNormalX()),s.push(o.getNormalY())),o.newIndex=i,h[r]=i}}}3===p?(r.push(k[0].newIndex),r.push(k[1].newIndex),r.push(k[2].newIndex)):4===p&&(r.push(k[0].newIndex),r.push(k[1].newIndex),r.push(k[2].newIndex),r.push(k[0].newIndex),r.push(k[2].newIndex),r.push(k[3].newIndex))}return k.push(new P),k.push(new P),k.push(new P),k.push(new P),d((function(e,i){const h=e.isEastChild,d=e.isNorthChild,p=h?B:0,a=h?C:B,l=d?B:0,f=d?C:B,c=T,g=z,m=V,x=N;c.length=0,g.length=0,m.length=0,x.length=0;const S=M;S.length=0;const U={},D=e.vertices;let W=e.indices;W=W.subarray(0,e.indexCountWithoutSkirts);const X=s.TerrainEncoding.clone(e.encoding),k=X.hasVertexNormals;let L=0;const Y=e.vertexCountWithoutSkirts,_=e.minimumHeight,j=e.maximumHeight,G=new Array(Y),J=new Array(Y),Z=new Array(Y),q=k?new Array(2*Y):void 0;let Q,$,ee,te,ne;for($=0,ee=0;$<Y;++$,ee+=2){const e=X.decodeTextureCoordinates(D,$,O);if(Q=X.decodeHeight(D,$),te=o.CesiumMath.clamp(e.x*C|0,0,C),ne=o.CesiumMath.clamp(e.y*C|0,0,C),Z[$]=o.CesiumMath.clamp((Q-_)/(j-_)*C|0,0,C),te<20&&(te=0),ne<20&&(ne=0),C-te<20&&(te=C),C-ne<20&&(ne=C),G[$]=te,J[$]=ne,k){const e=X.getOctEncodedNormal(D,$,F);q[ee]=e.x,q[ee+1]=e.y}(h&&te>=B||!h&&te<=B)&&(d&&ne>=B||!d&&ne<=B)&&(U[$]=L,c.push(te),g.push(ne),m.push(Z[$]),k&&(x.push(q[ee]),x.push(q[ee+1])),++L)}const ie=[];ie.push(new P),ie.push(new P),ie.push(new P);const se=[];let re,he;for(se.push(new P),se.push(new P),se.push(new P),$=0;$<W.length;$+=3){const e=W[$],t=W[$+1],n=W[$+2],i=G[e],s=G[t],r=G[n];ie[0].initializeIndexed(G,J,Z,q,e),ie[1].initializeIndexed(G,J,Z,q,t),ie[2].initializeIndexed(G,J,Z,q,n);const o=w.clipTriangleAtAxisAlignedThreshold(B,h,i,s,r,y);re=0,re>=o.length||(re=se[0].initializeFromClipResult(o,re,ie),re>=o.length||(re=se[1].initializeFromClipResult(o,re,ie),re>=o.length||(re=se[2].initializeFromClipResult(o,re,ie),he=w.clipTriangleAtAxisAlignedThreshold(B,d,se[0].getV(),se[1].getV(),se[2].getV(),I),K(c,g,m,x,S,U,he,se,k),re<o.length&&(se[2].clone(se[1]),se[2].initializeFromClipResult(o,re,ie),he=w.clipTriangleAtAxisAlignedThreshold(B,d,se[0].getV(),se[1].getV(),se[2].getV(),I),K(c,g,m,x,S,U,he,se,k)))))}const oe=h?-32767:0,ue=d?-32767:0,de=[],pe=[],ae=[],le=[];let fe=Number.MAX_VALUE,ce=-fe;const ge=A;ge.length=0;const me=n.Ellipsoid.clone(e.ellipsoid),xe=n.Rectangle.clone(e.childRectangle),we=xe.north,Ce=xe.south;let Be=xe.east;const ye=xe.west;for(Be<ye&&(Be+=o.CesiumMath.TWO_PI),$=0;$<c.length;++$)te=Math.round(c[$]),te<=p?(de.push($),te=0):te>=a?(ae.push($),te=C):te=2*te+oe,c[$]=te,ne=Math.round(g[$]),ne<=l?(pe.push($),ne=0):ne>=f?(le.push($),ne=C):ne=2*ne+ue,g[$]=ne,Q=o.CesiumMath.lerp(_,j,m[$]/C),Q<fe&&(fe=Q),Q>ce&&(ce=Q),m[$]=Q,b.longitude=o.CesiumMath.lerp(ye,Be,te/C),b.latitude=o.CesiumMath.lerp(Ce,we,ne/C),b.height=Q,me.cartographicToCartesian(b,v),ge.push(v.x),ge.push(v.y),ge.push(v.z);const Ie=t.BoundingSphere.fromVertices(ge,n.Cartesian3.ZERO,3,H),Ae=u.OrientedBoundingBox.fromRectangle(xe,fe,ce,me,R),be=new s.EllipsoidalOccluder(me).computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid(Ie.center,ge,3,Ie.center,fe,E),ve=ce-fe,Te=new Uint16Array(c.length+g.length+m.length);for($=0;$<c.length;++$)Te[$]=c[$];let ze=c.length;for($=0;$<g.length;++$)Te[ze+$]=g[$];for(ze+=g.length,$=0;$<m.length;++$)Te[ze+$]=C*(m[$]-fe)/ve;const Ve=r.IndexDatatype.createTypedArray(c.length,S);let Me;if(k){const e=new Uint8Array(x);i.push(Te.buffer,Ve.buffer,e.buffer),Me=e.buffer}else i.push(Te.buffer,Ve.buffer);return{vertices:Te.buffer,encodedNormals:Me,indices:Ve.buffer,minimumHeight:fe,maximumHeight:ce,westIndices:de,southIndices:pe,eastIndices:ae,northIndices:le,boundingSphere:Ie,orientedBoundingBox:Ae,horizonOcclusionPoint:be}}))}));