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

2 lines
9.9 KiB
JavaScript

define(["./AttributeCompression-90851096","./EllipsoidTangentPlane-b2b18d75","./BoundingSphere-561b54d0","./Cartesian2-47311507","./Cartographic-3309dd0d","./when-b60132fc","./TerrainEncoding-e04be3ba","./IndexDatatype-8a5eead4","./Math-119be1a3","./OrientedBoundingBox-f1d7843f","./Check-7b2a090c","./Transforms-cb0006b0","./WebMercatorProjection-01b1b5e7","./createTaskProcessorWorker","./Cartesian4-3ca25aab","./IntersectionTests-0c6d0a14","./Plane-097b3a8f","./RuntimeError-4a5c8994","./ComponentDatatype-c140a87d","./WebGLConstants-4ae0db90","./buildModuleUrl-3addfe33","./FeatureDetection-c3b71206"],(function(e,t,r,n,i,o,a,s,d,c,u,h,l,I,m,g,T,f,p,v,E,y){"use strict";function w(){u.DeveloperError.throwInstantiationError()}Object.defineProperties(w.prototype,{errorEvent:{get:u.DeveloperError.throwInstantiationError},credit:{get:u.DeveloperError.throwInstantiationError},tilingScheme:{get:u.DeveloperError.throwInstantiationError},ready:{get:u.DeveloperError.throwInstantiationError},readyPromise:{get:u.DeveloperError.throwInstantiationError},hasWaterMask:{get:u.DeveloperError.throwInstantiationError},hasVertexNormals:{get:u.DeveloperError.throwInstantiationError},availability:{get:u.DeveloperError.throwInstantiationError}});var N=[];w.getRegularGridIndices=function(e,t){var r=N[e];o.defined(r)||(N[e]=r=[]);var n=r[t];return o.defined(n)||C(e,t,n=e*t<d.CesiumMath.SIXTY_FOUR_KILOBYTES?r[t]=new Uint16Array((e-1)*(t-1)*6+3*(e+t-2)):r[t]=new Uint32Array((e-1)*(t-1)*6+3*(e+t-2)),0),n},w.getRegularGridIndicesForReproject=function(e,t){var r=N[e];o.defined(r)||(N[e]=r=[]);var n=r[t];return o.defined(n)||C(e,t,n=e*t<d.CesiumMath.SIXTY_FOUR_KILOBYTES?r[t]=new Uint16Array((e-1)*(t-1)*6):r[t]=new Uint32Array((e-1)*(t-1)*6),0),n};var b=[];w.getRegularGridIndicesAndEdgeIndices=function(e,t){var r=b[e];o.defined(r)||(b[e]=r=[]);var n=r[t];if(!o.defined(n)){var i=w.getRegularGridIndices(e,t),a=M(e,t),s=a.westIndicesSouthToNorth,d=a.southIndicesEastToWest,c=a.eastIndicesNorthToSouth,u=a.northIndicesWestToEast;n=r[t]={indices:i,westIndicesSouthToNorth:s,southIndicesEastToWest:d,eastIndicesNorthToSouth:c,northIndicesWestToEast:u}}return n};var x=[];function M(e,t){var r,n=new Array(t),i=new Array(e),o=new Array(t),a=new Array(e);for(r=0;r<e;++r)a[r]=r,i[r]=e*t-1-r;for(r=0;r<t;++r)o[r]=(r+1)*e-1,n[r]=(t-r-1)*e;return{westIndicesSouthToNorth:n,southIndicesEastToWest:i,eastIndicesNorthToSouth:o,northIndicesWestToEast:a}}function C(e,t,r,n){for(var i=0,o=0;o<t-1;++o){for(var a=0;a<e-1;++a){var s=i,d=s+e,c=d+1,u=s+1;r[n++]=s,r[n++]=d,r[n++]=u,r[n++]=u,r[n++]=d,r[n++]=c,++i}++i}var h=(t-1)/2,l=(e-1)/2;i=0;for(a=0;a<l;a++)r[n++]=i,r[n++]=i+1,r[n++]=i+2,i+=2;i=e*(t-1);for(a=0;a<l;a++)r[n++]=i+1,r[n++]=i,r[n++]=i+2,i+=2;i=0;for(a=0;a<h;a++)r[n++]=i+e,r[n++]=i,r[n++]=i+2*e,i+=2*e;i=e-1;for(a=0;a<h;a++)r[n++]=i,r[n++]=i+e,r[n++]=i+2*e,i+=2*e}function S(e,t,r,n,i){for(var a=o.defined(i),s=e[0],d=e.length,c=1;c<d;++c){var u=e[c];!a||i[s+"_"+u]?(r[n++]=s,r[n++]=u,r[n++]=t,r[n++]=t,r[n++]=u,r[n++]=t+1,s=u,++t):(s=u,++t)}return n}w.getRegularGridAndSkirtIndicesAndEdgeIndices=function(e,t){var r=x[e];o.defined(r)||(x[e]=r=[]);var n=r[t];if(!o.defined(n)){var i=e*t,a=(e-1)*(t-1)*6,d=2*e+2*t,c=i+d,u=3*(e+t-2),h=a+6*Math.max(0,d-4)+u,l=M(e,t),I=l.westIndicesSouthToNorth,m=l.southIndicesEastToWest,g=l.eastIndicesNorthToSouth,T=l.northIndicesWestToEast,f=s.IndexDatatype.createTypedArray(c,h);C(e,t,f,0),w.addSkirtIndices(I,m,g,T,i,f,a+u),n=r[t]={indices:f,westIndicesSouthToNorth:I,southIndicesEastToWest:m,eastIndicesNorthToSouth:g,northIndicesWestToEast:T,indexCountWithoutSkirts:a}}return n},w.addSkirtIndices=function(e,t,r,n,i,o,a,s){var d=i;a=S(e,d,o,a,s),a=S(t,d+=e.length,o,a,s),a=S(r,d+=t.length,o,a,s),S(n,d+=r.length,o,a,s)},w.heightmapTerrainQuality=.25,w.getEstimatedLevelZeroGeometricErrorForAHeightmap=function(e,t,r){return 2*e.maximumRadius*Math.PI*w.heightmapTerrainQuality/(t*r)},w.prototype.requestTileGeometry=u.DeveloperError.throwInstantiationError,w.prototype.getLevelMaximumGeometricError=u.DeveloperError.throwInstantiationError,w.prototype.getTileDataAvailable=u.DeveloperError.throwInstantiationError,w.prototype.loadTileDataAvailability=u.DeveloperError.throwInstantiationError;var A=32767,P=new i.Cartesian3,W=new i.Cartesian3,_=new i.Cartesian3,F=new i.Cartographic,B=new n.Cartesian2,D=new i.Cartesian3,k=new r.Matrix4,V=new r.Matrix4;function O(e,t,n,o,a,s,c,u,h){var l=Number.POSITIVE_INFINITY,I=a.north,m=a.south,g=a.east,T=a.west;g<T&&(g+=d.CesiumMath.TWO_PI);for(var f=e.length,p=0;p<f;++p){var v=e[p],E=n[v],y=o[v];F.longitude=d.CesiumMath.lerp(T,g,y.x),F.latitude=d.CesiumMath.lerp(m,I,y.y),F.height=E-t;var w=s.cartographicToCartesian(F,P);r.Matrix4.multiplyByPoint(c,w,w),i.Cartesian3.minimumByComponent(w,u,u),i.Cartesian3.maximumByComponent(w,h,h),l=Math.min(l,F.height)}return l}function Y(t,n,a,s,c,u,I,m,g,T,f,p,v,E,y){var w=o.defined(I),N=g.north,b=g.south,x=g.east,M=g.west;x<M&&(x+=d.CesiumMath.TWO_PI);for(var C=a.length,S=0;S<C;++S){var A=a[S],W=c[A],_=u[A];F.longitude=d.CesiumMath.lerp(M,x,_.x)+E,F.latitude=d.CesiumMath.lerp(b,N,_.y)+y,F.height=W-T;var O,Y=m.cartographicToCartesian(F,P);if(w){var G=2*A;if(B.x=I[G],B.y=I[G+1],1!==f){var H=e.AttributeCompression.octDecode(B.x,B.y,D),R=h.Transforms.eastNorthUpToFixedFrame(P,m,V),U=r.Matrix4.inverseTransformation(R,k);r.Matrix4.multiplyByPointAsVector(U,H,H),H.z*=f,i.Cartesian3.normalize(H,H),r.Matrix4.multiplyByPointAsVector(R,H,H),i.Cartesian3.normalize(H,H),e.AttributeCompression.octEncode(H,B)}}s.hasWebMercatorT&&(O=(l.WebMercatorProjection.geodeticLatitudeToMercatorAngle(F.latitude)-p)*v),n=s.encode(t,n,Y,_,F.height,B,O)}}function G(e,t){var r;return"function"==typeof e.slice&&"function"!=typeof(r=e.slice()).sort&&(r=void 0),o.defined(r)||(r=Array.prototype.slice.call(e)),r.sort(t),r}return I((function(u,I){var m,g,T=u.quantizedVertices,f=T.length/3,p=u.octEncodedNormals,v=u.westIndices.length+u.eastIndices.length+u.southIndices.length+u.northIndices.length,E=u.includeWebMercatorT,y=n.Rectangle.clone(u.rectangle),N=y.west,b=y.south,x=y.east,M=y.north,C=n.Ellipsoid.clone(u.ellipsoid),S=u.exaggeration,H=u.minimumHeight*S,R=u.maximumHeight*S,U=u.relativeToCenter,z=h.Transforms.eastNorthUpToFixedFrame(U,C),L=r.Matrix4.inverseTransformation(z,new r.Matrix4);E&&(m=l.WebMercatorProjection.geodeticLatitudeToMercatorAngle(b),g=1/(l.WebMercatorProjection.geodeticLatitudeToMercatorAngle(M)-m));var j=T.subarray(0,f),q=T.subarray(f,2*f),K=T.subarray(2*f,3*f),Q=o.defined(p),X=new Array(f),Z=new Array(f),J=new Array(f),$=E?new Array(f):[],ee=W;ee.x=Number.POSITIVE_INFINITY,ee.y=Number.POSITIVE_INFINITY,ee.z=Number.POSITIVE_INFINITY;var te=_;te.x=Number.NEGATIVE_INFINITY,te.y=Number.NEGATIVE_INFINITY,te.z=Number.NEGATIVE_INFINITY;for(var re=Number.POSITIVE_INFINITY,ne=Number.NEGATIVE_INFINITY,ie=Number.POSITIVE_INFINITY,oe=Number.NEGATIVE_INFINITY,ae=0;ae<f;++ae){var se=j[ae],de=q[ae],ce=se/A,ue=de/A,he=d.CesiumMath.lerp(H,R,K[ae]/A);F.longitude=d.CesiumMath.lerp(N,x,ce),F.latitude=d.CesiumMath.lerp(b,M,ue),F.height=he,re=Math.min(F.longitude,re),ne=Math.max(F.longitude,ne),ie=Math.min(F.latitude,ie),oe=Math.max(F.latitude,oe);var le=C.cartographicToCartesian(F);X[ae]=new n.Cartesian2(ce,ue),Z[ae]=he,J[ae]=le,E&&($[ae]=(l.WebMercatorProjection.geodeticLatitudeToMercatorAngle(F.latitude)-m)*g),r.Matrix4.multiplyByPoint(L,le,P),i.Cartesian3.minimumByComponent(P,ee,ee),i.Cartesian3.maximumByComponent(P,te,te)}var Ie,me,ge,Te=G(u.westIndices,(function(e,t){return X[e].y-X[t].y})),fe=G(u.eastIndices,(function(e,t){return X[t].y-X[e].y})),pe=G(u.southIndices,(function(e,t){return X[t].x-X[e].x})),ve=G(u.northIndices,(function(e,t){return X[e].x-X[t].x}));me=r.BoundingSphere.fromPoints(J),Ie=c.OrientedBoundingBox.fromRectangle(y,H,R,C),(1!==S||H<0)&&(ge=new a.EllipsoidalOccluder(C).computeHorizonCullingPointPossiblyUnderEllipsoid(U,J,H));var Ee=H;Ee=Math.min(Ee,O(u.westIndices,u.westSkirtHeight,Z,X,y,C,L,ee,te)),Ee=Math.min(Ee,O(u.southIndices,u.southSkirtHeight,Z,X,y,C,L,ee,te)),Ee=Math.min(Ee,O(u.eastIndices,u.eastSkirtHeight,Z,X,y,C,L,ee,te)),Ee=Math.min(Ee,O(u.northIndices,u.northSkirtHeight,Z,X,y,C,L,ee,te));for(var ye=new t.AxisAlignedBoundingBox(ee,te,U),we=new a.TerrainEncoding(ye,Ee,R,z,Q,E),Ne=we.getStride(),be=new Float32Array(f*Ne+v*Ne),xe=0,Me=0;Me<f;++Me){if(Q){var Ce=2*Me;if(B.x=p[Ce],B.y=p[Ce+1],1!==S){var Se=e.AttributeCompression.octDecode(B.x,B.y,D),Ae=h.Transforms.eastNorthUpToFixedFrame(J[Me],C,V),Pe=r.Matrix4.inverseTransformation(Ae,k);r.Matrix4.multiplyByPointAsVector(Pe,Se,Se),Se.z*=S,i.Cartesian3.normalize(Se,Se),r.Matrix4.multiplyByPointAsVector(Ae,Se,Se),i.Cartesian3.normalize(Se,Se),e.AttributeCompression.octEncode(Se,B)}}xe=we.encode(be,xe,J[Me],X[Me],Z[Me],B,$[Me])}var We=Math.max(0,2*(v-4)),_e=u.indices.length+3*We,Fe=s.IndexDatatype.createTypedArray(f+v,_e);Fe.set(u.indices,0);var Be=1e-4,De=(ne-re)*Be,ke=(oe-ie)*Be,Ve=-De,Oe=De,Ye=ke,Ge=-ke,He=f*Ne;Y(be,He,Te,we,Z,X,p,C,y,u.westSkirtHeight,S,m,g,Ve,0),Y(be,He+=u.westIndices.length*Ne,pe,we,Z,X,p,C,y,u.southSkirtHeight,S,m,g,0,Ge),Y(be,He+=u.southIndices.length*Ne,fe,we,Z,X,p,C,y,u.eastSkirtHeight,S,m,g,Oe,0),Y(be,He+=u.eastIndices.length*Ne,ve,we,Z,X,p,C,y,u.northSkirtHeight,S,m,g,0,Ye);var Re=function(e,t,r,n){if(n<12)return;for(var i={},o=e.length,a=0;a<o;a+=3){var s=e[a],d=e[a+1],c=e[a+2];(t[s]===A&&t[d]===A||0===t[s]&&0===t[d]||r[s]===A&&r[d]===A||0===r[s]&&0===r[d])&&(i[s+"_"+d]=1,i[d+"_"+s]=1),(t[d]===A&&t[c]===A||0===t[d]&&0===t[c]||r[d]===A&&r[c]===A||0===r[d]&&0===r[c])&&(i[d+"_"+c]=1,i[c+"_"+d]=1),(t[c]===A&&t[s]===A||0===t[c]&&0===t[s]||r[c]===A&&r[s]===A||0===r[c]&&0===r[s])&&(i[c+"_"+s]=1,i[s+"_"+c]=1)}return i}(u.indices,j,q,u.level);return w.addSkirtIndices(Te,pe,fe,ve,f,Fe,u.indices.length,Re),I.push(be.buffer,Fe.buffer),{vertices:be.buffer,indices:Fe.buffer,westIndicesSouthToNorth:Te,southIndicesEastToWest:pe,eastIndicesNorthToSouth:fe,northIndicesWestToEast:ve,vertexStride:Ne,center:U,minimumHeight:H,maximumHeight:R,boundingSphere:me,orientedBoundingBox:Ie,occludeePointInScaledSpace:ge,encoding:we,indexCountWithoutSkirts:u.indices.length}}))}));