Agriculture-front-end/public/Cesium/Workers/upsampleQuantizedTerrainMesh.js
2023-09-11 21:56:39 +08:00

2 lines
8.4 KiB
JavaScript

define(["./AttributeCompression-90851096","./BoundingSphere-561b54d0","./Cartesian2-47311507","./Cartographic-3309dd0d","./when-b60132fc","./TerrainEncoding-e04be3ba","./IndexDatatype-8a5eead4","./Check-7b2a090c","./Math-119be1a3","./OrientedBoundingBox-f1d7843f","./createTaskProcessorWorker","./Cartesian4-3ca25aab","./RuntimeError-4a5c8994","./ComponentDatatype-c140a87d","./WebGLConstants-4ae0db90","./EllipsoidTangentPlane-b2b18d75","./IntersectionTests-0c6d0a14","./Plane-097b3a8f","./Transforms-cb0006b0","./buildModuleUrl-3addfe33","./FeatureDetection-c3b71206"],(function(e,t,i,n,s,r,h,u,o,a,d,p,f,l,c,g,m,x,v,C,w){"use strict";var y={clipTriangleAtAxisAlignedThreshold:function(e,t,i,n,r,h){var u,o,a;s.defined(h)?h.length=0:h=[],t?(u=i<e,o=n<e,a=r<e):(u=i>e,o=n>e,a=r>e);var d,p,f,l,c,g,m=u+o+a;return 1===m?u?(d=(e-i)/(n-i),p=(e-i)/(r-i),h.push(1),h.push(2),1!==p&&(h.push(-1),h.push(0),h.push(2),h.push(p)),1!==d&&(h.push(-1),h.push(0),h.push(1),h.push(d))):o?(f=(e-n)/(r-n),l=(e-n)/(i-n),h.push(2),h.push(0),1!==l&&(h.push(-1),h.push(1),h.push(0),h.push(l)),1!==f&&(h.push(-1),h.push(1),h.push(2),h.push(f))):a&&(c=(e-r)/(i-r),g=(e-r)/(n-r),h.push(0),h.push(1),1!==g&&(h.push(-1),h.push(2),h.push(1),h.push(g)),1!==c&&(h.push(-1),h.push(2),h.push(0),h.push(c))):2===m?u||i===e?o||n===e?a||r===e||(p=(e-i)/(r-i),f=(e-n)/(r-n),h.push(2),h.push(-1),h.push(0),h.push(2),h.push(p),h.push(-1),h.push(1),h.push(2),h.push(f)):(g=(e-r)/(n-r),d=(e-i)/(n-i),h.push(1),h.push(-1),h.push(2),h.push(1),h.push(g),h.push(-1),h.push(0),h.push(1),h.push(d)):(l=(e-n)/(i-n),c=(e-r)/(i-r),h.push(0),h.push(-1),h.push(1),h.push(0),h.push(l),h.push(-1),h.push(2),h.push(0),h.push(c)):3!==m&&(h.push(0),h.push(1),h.push(2)),h},computeBarycentricCoordinates:function(e,t,i,r,h,u,o,a,d){var p=i-o,f=o-h,l=u-a,c=r-a,g=1/(l*p+f*c),m=t-a,x=e-o,v=(l*x+f*m)*g,C=(-c*x+p*m)*g,w=1-v-C;return s.defined(d)?(d.x=v,d.y=C,d.z=w,d):new n.Cartesian3(v,C,w)},computeLineSegmentLineSegmentIntersection:function(e,t,n,r,h,u,o,a,d){var p=(a-u)*(n-e)-(o-h)*(r-t);if(0!==p){var f=((o-h)*(t-u)-(a-u)*(e-h))/p,l=((n-e)*(t-u)-(r-t)*(e-h))/p;return f>=0&&f<=1&&l>=0&&l<=1?(s.defined(d)||(d=new i.Cartesian2),d.x=e+f*(n-e),d.y=t+f*(r-t),d):void 0}}},B=32767,b=16383,I=[],A=[],T=[],z=new n.Cartographic,M=new n.Cartesian3,N=[],V=[],E=[],H=[],R=[],O=new n.Cartesian3,S=new t.BoundingSphere,U=new a.OrientedBoundingBox,F=new i.Cartesian2,P=new n.Cartesian3;function D(){this.vertexBuffer=void 0,this.index=void 0,this.first=void 0,this.second=void 0,this.ratio=void 0}D.prototype.clone=function(e){return s.defined(e)||(e=new D),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},D.prototype.initializeIndexed=function(e,t,i,n,s){this.uBuffer=e,this.vBuffer=t,this.heightBuffer=i,this.normalBuffer=n,this.index=s,this.first=void 0,this.second=void 0,this.ratio=void 0},D.prototype.initializeFromClipResult=function(e,t,i){var n=t+1;return-1!==e[t]?i[e[t]].clone(this):(this.vertexBuffer=void 0,this.index=void 0,this.first=i[e[n]],++n,this.second=i[e[n]],++n,this.ratio=e[n],++n),n},D.prototype.getKey=function(){return this.isIndexed()?this.index:JSON.stringify({first:this.first.getKey(),second:this.second.getKey(),ratio:this.ratio})},D.prototype.isIndexed=function(){return s.defined(this.index)},D.prototype.getH=function(e,t){if(s.defined(this.index))return this.heightBuffer[this.index];var i=this.first.getH(e,t),n=this.second.getH(e,t);return 0===t+i/B*e||0===t+n/B*e?0:o.CesiumMath.lerp(this.first.getH(),this.second.getH(),this.ratio)},D.prototype.getU=function(){return s.defined(this.index)?this.uBuffer[this.index]:o.CesiumMath.lerp(this.first.getU(),this.second.getU(),this.ratio)},D.prototype.getV=function(){return s.defined(this.index)?this.vBuffer[this.index]:o.CesiumMath.lerp(this.first.getV(),this.second.getV(),this.ratio)};var k=new i.Cartesian2,W=-1,X=[new n.Cartesian3,new n.Cartesian3],K=[new n.Cartesian3,new n.Cartesian3];function L(t,i){++W;var s=X[W],r=K[W];return s=e.AttributeCompression.octDecode(t.first.getNormalX(),t.first.getNormalY(),s),r=e.AttributeCompression.octDecode(t.second.getNormalX(),t.second.getNormalY(),r),M=n.Cartesian3.lerp(s,r,t.ratio,M),n.Cartesian3.normalize(M,M),e.AttributeCompression.octEncode(M,i),--W,i}D.prototype.getNormalX=function(){return s.defined(this.index)?this.normalBuffer[2*this.index]:(k=L(this,k)).x},D.prototype.getNormalY=function(){return s.defined(this.index)?this.normalBuffer[2*this.index+1]:(k=L(this,k)).y};var Y=[];function _(e,t,i,n,r,h,u,o,a,d,p){if(0!==u.length){for(var f=0,l=0;l<u.length;)l=Y[f++].initializeFromClipResult(u,l,o);for(var c=0;c<f;++c){var g=Y[c];if(g.isIndexed())g.newIndex=h[g.index],g.uBuffer=e,g.vBuffer=t,g.heightBuffer=i,a&&(g.normalBuffer=n);else{var m=g.getKey();if(s.defined(h[m]))g.newIndex=h[m];else{var x=e.length;e.push(g.getU()),t.push(g.getV()),i.push(g.getH(d,p)),a&&(n.push(g.getNormalX()),n.push(g.getNormalY())),g.newIndex=x,h[m]=x}}}3===f?(r.push(Y[0].newIndex),r.push(Y[1].newIndex),r.push(Y[2].newIndex)):4===f&&(r.push(Y[0].newIndex),r.push(Y[1].newIndex),r.push(Y[2].newIndex),r.push(Y[0].newIndex),r.push(Y[2].newIndex),r.push(Y[3].newIndex))}}return Y.push(new D),Y.push(new D),Y.push(new D),Y.push(new D),d((function(e,s){var u=e.isEastChild,d=e.isNorthChild,p=u?b:0,f=u?B:b,l=d?b:0,c=d?B:b,g=N,m=V,x=E,v=R;g.length=0,m.length=0,x.length=0,v.length=0;var C=H;C.length=0;var w={},k=e.vertices,W=e.indices;W=W.subarray(0,e.indexCountWithoutSkirts);var X,K,L,Y,G,J=r.TerrainEncoding.clone(e.encoding),Z=J.hasVertexNormals,j=e.exaggeration,q=0,Q=e.vertexCountWithoutSkirts,$=e.minimumHeight,ee=e.maximumHeight,te=new Array(Q),ie=new Array(Q),ne=new Array(Q),se=Z?new Array(2*Q):void 0;for(K=0,L=0;K<Q;++K,L+=2){var re=J.decodeTextureCoordinates(k,K,F);if(X=J.decodeHeight(k,K)/j,Y=o.CesiumMath.clamp(re.x*B|0,0,B),G=o.CesiumMath.clamp(re.y*B|0,0,B),ne[K]=o.CesiumMath.clamp((X-$)/(ee-$)*B|0,0,B),Y<20&&(Y=0),G<20&&(G=0),B-Y<20&&(Y=B),B-G<20&&(G=B),te[K]=Y,ie[K]=G,Z){var he=J.getOctEncodedNormal(k,K,P);se[L]=he.x,se[L+1]=he.y}(u&&Y>=b||!u&&Y<=b)&&(d&&G>=b||!d&&G<=b)&&(w[K]=q,g.push(Y),m.push(G),x.push(ne[K]),Z&&(v.push(se[L]),v.push(se[L+1])),++q)}var ue=[];ue.push(new D),ue.push(new D),ue.push(new D);var oe,ae=[];for(ae.push(new D),ae.push(new D),ae.push(new D),K=0;K<W.length;K+=3){var de=W[K],pe=W[K+1],fe=W[K+2],le=te[de],ce=te[pe],ge=te[fe];ue[0].initializeIndexed(te,ie,ne,se,de),ue[1].initializeIndexed(te,ie,ne,se,pe),ue[2].initializeIndexed(te,ie,ne,se,fe);var me=y.clipTriangleAtAxisAlignedThreshold(b,u,le,ce,ge,I);(oe=0)>=me.length||((oe=ae[0].initializeFromClipResult(me,oe,ue))>=me.length||(oe=ae[1].initializeFromClipResult(me,oe,ue))>=me.length||(oe=ae[2].initializeFromClipResult(me,oe,ue),_(g,m,x,v,C,w,y.clipTriangleAtAxisAlignedThreshold(b,d,ae[0].getV(),ae[1].getV(),ae[2].getV(),A),ae,Z,ee,$),oe<me.length&&(ae[2].clone(ae[1]),ae[2].initializeFromClipResult(me,oe,ue),_(g,m,x,v,C,w,y.clipTriangleAtAxisAlignedThreshold(b,d,ae[0].getV(),ae[1].getV(),ae[2].getV(),A),ae,Z,ee,$))))}var xe=u?-32767:0,ve=d?-32767:0,Ce=[],we=[],ye=[],Be=[],be=Number.MAX_VALUE,Ie=-be,Ae=T;Ae.length=0;var Te=i.Ellipsoid.clone(e.ellipsoid),ze=i.Rectangle.clone(e.childRectangle),Me=ze.north,Ne=ze.south,Ve=ze.east,Ee=ze.west;for(Ve<Ee&&(Ve+=o.CesiumMath.TWO_PI),K=0;K<g.length;++K)(Y=Math.round(g[K]))<=p?(Ce.push(K),Y=0):Y>=f?(ye.push(K),Y=B):Y=2*Y+xe,g[K]=Y,(G=Math.round(m[K]))<=l?(we.push(K),G=0):G>=c?(Be.push(K),G=B):G=2*G+ve,m[K]=G,(X=o.CesiumMath.lerp($,ee,x[K]/B))<be&&(be=X),X>Ie&&(Ie=X),x[K]=X,z.longitude=o.CesiumMath.lerp(Ee,Ve,Y/B),z.latitude=o.CesiumMath.lerp(Ne,Me,G/B),z.height=X,Te.cartographicToCartesian(z,M),Ae.push(M.x),Ae.push(M.y),Ae.push(M.z);var He=t.BoundingSphere.fromVertices(Ae,n.Cartesian3.ZERO,3,S),Re=a.OrientedBoundingBox.fromRectangle(ze,be,Ie,Te,U),Oe=new r.EllipsoidalOccluder(Te).computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid(He.center,Ae,3,He.center,be,O),Se=Ie-be,Ue=new Uint16Array(g.length+m.length+x.length);for(K=0;K<g.length;++K)Ue[K]=g[K];var Fe=g.length;for(K=0;K<m.length;++K)Ue[Fe+K]=m[K];for(Fe+=m.length,K=0;K<x.length;++K)Ue[Fe+K]=B*(x[K]-be)/Se;var Pe,De=h.IndexDatatype.createTypedArray(g.length,C);if(Z){var ke=new Uint8Array(v);s.push(Ue.buffer,De.buffer,ke.buffer),Pe=ke.buffer}else s.push(Ue.buffer,De.buffer);return{vertices:Ue.buffer,encodedNormals:Pe,indices:De.buffer,minimumHeight:be,maximumHeight:Ie,westIndices:Ce,southIndices:we,eastIndices:ye,northIndices:Be,boundingSphere:He,orientedBoundingBox:Re,horizonOcclusionPoint:Oe}}))}));