createVerticesFromQuantizedTerrainMesh.js 10 KB

1
  1. define(["./AttributeCompression-49f7b62a","./EllipsoidTangentPlane-53184efd","./buildModuleUrl-3d15f25c","./Cartesian2-6033fa5d","./Cartographic-67e73ef9","./when-92c6cf3c","./Rectangle-bab7abf0","./TerrainEncoding-5d55ad09","./IndexDatatype-4c0e98b8","./Math-92c3b5f7","./PrimitiveType-cdfe443e","./OrientedBoundingBox-513cf61d","./Check-52a7d806","./GeometryAttribute-ef657318","./WebMercatorProjection-39906b85","./createTaskProcessorWorker","./Intersect-b97e930a","./Cartesian4-ad128b5d","./IntersectionTests-a42760d9","./Plane-f8d22530","./Event-3390cd7d","./RuntimeError-c6a62a80","./ComponentDatatype-81047f82","./WebGLConstants-71f10989","./PolygonPipeline-b86e8785","./WindingOrder-1b9c8a87","./EllipsoidRhumbLine-8847d1a1","./Buffer-1d0f8963","./RenderState-94064c70","./BoundingRectangle-418864a2","./Color-45274500","./FeatureDetection-067cb23c"],(function(t,e,r,n,i,o,a,s,h,d,c,u,l,I,m,g,T,f,y,v,w,E,p,N,b,S,A,x,P,_,F,M){"use strict";function B(){l.t.throwInstantiationError()}Object.defineProperties(B.prototype,{errorEvent:{get:l.t.throwInstantiationError},credit:{get:l.t.throwInstantiationError},tilingScheme:{get:l.t.throwInstantiationError},ready:{get:l.t.throwInstantiationError},readyPromise:{get:l.t.throwInstantiationError},hasWaterMask:{get:l.t.throwInstantiationError},hasVertexNormals:{get:l.t.throwInstantiationError},availability:{get:l.t.throwInstantiationError}});var G=[];B.getRegularGridIndices=function(t,e){if(t*e>=d.e.FOUR_GIGABYTES)throw new l.t("The total number of vertices (width * height) must be less than 4,294,967,296.");var r=G[t];o.e(r)||(G[t]=r=[]);var n=r[e];return o.e(n)||C(t,e,n=t*e<d.e.SIXTY_FOUR_KILOBYTES?r[e]=new Uint16Array((t-1)*(e-1)*6+3*(t+e-2)):r[e]=new Uint32Array((t-1)*(e-1)*6+3*(t+e-2)),0),n},B.getRegularGridIndicesForReproject=function(t,e){if(t*e>=d.e.FOUR_GIGABYTES)throw new l.t("The total number of vertices (width * height) must be less than 4,294,967,296.");var r=G[t];o.e(r)||(G[t]=r=[]);var n=r[e];return o.e(n)||C(t,e,n=t*e<d.e.SIXTY_FOUR_KILOBYTES?r[e]=new Uint16Array((t-1)*(e-1)*6):r[e]=new Uint32Array((t-1)*(e-1)*6),0),n};var W=[];B.getRegularGridIndicesAndEdgeIndices=function(t,e){if(t*e>=d.e.FOUR_GIGABYTES)throw new l.t("The total number of vertices (width * height) must be less than 4,294,967,296.");var r=W[t];o.e(r)||(W[t]=r=[]);var n=r[e];if(!o.e(n)){var i=B.getRegularGridIndices(t,e),a=R(t,e),s=a.westIndicesSouthToNorth,h=a.southIndicesEastToWest,c=a.eastIndicesNorthToSouth,u=a.northIndicesWestToEast;n=r[e]={indices:i,westIndicesSouthToNorth:s,southIndicesEastToWest:h,eastIndicesNorthToSouth:c,northIndicesWestToEast:u}}return n};var O=[];function R(t,e){var r,n=new Array(e),i=new Array(t),o=new Array(e),a=new Array(t);for(r=0;r<t;++r)a[r]=r,i[r]=t*e-1-r;for(r=0;r<e;++r)o[r]=(r+1)*t-1,n[r]=(e-r-1)*t;return{westIndicesSouthToNorth:n,southIndicesEastToWest:i,eastIndicesNorthToSouth:o,northIndicesWestToEast:a}}function C(t,e,r,n){for(var i=0,o=0;o<e-1;++o){for(var a=0;a<t-1;++a){var s=i,h=s+t,d=h+1,c=s+1;r[n++]=s,r[n++]=h,r[n++]=c,r[n++]=c,r[n++]=h,r[n++]=d,++i}++i}var u=(e-1)/2,l=(t-1)/2;i=0;for(a=0;a<l;a++)r[n++]=i,r[n++]=i+1,r[n++]=i+2,i+=2;i=t*(e-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<u;a++)r[n++]=i+t,r[n++]=i,r[n++]=i+2*t,i+=2*t;i=t-1;for(a=0;a<u;a++)r[n++]=i,r[n++]=i+t,r[n++]=i+2*t,i+=2*t}function Y(t,e,r,n,i){for(var a=o.e(i),s=t[0],h=t.length,d=1;d<h;++d){var c=t[d];!a||i[s+"_"+c]?(r[n++]=s,r[n++]=c,r[n++]=e,r[n++]=e,r[n++]=c,r[n++]=e+1,s=c,++e):(s=c,++e)}return n}B.getRegularGridAndSkirtIndicesAndEdgeIndices=function(t,e){if(t*e>=d.e.FOUR_GIGABYTES)throw new l.t("The total number of vertices (width * height) must be less than 4,294,967,296.");var r=O[t];o.e(r)||(O[t]=r=[]);var n=r[e];if(!o.e(n)){var i=t*e,a=(t-1)*(e-1)*6,s=2*t+2*e,c=i+s,u=3*(t+e-2),I=a+6*Math.max(0,s-4)+u,m=R(t,e),g=m.westIndicesSouthToNorth,T=m.southIndicesEastToWest,f=m.eastIndicesNorthToSouth,y=m.northIndicesWestToEast,v=h.IndexDatatype.createTypedArray(c,I);C(t,e,v,0),B.addSkirtIndices(g,T,f,y,i,v,a+u),n=r[e]={indices:v,westIndicesSouthToNorth:g,southIndicesEastToWest:T,eastIndicesNorthToSouth:f,northIndicesWestToEast:y,indexCountWithoutSkirts:a}}return n},B.addSkirtIndices=function(t,e,r,n,i,o,a,s){var h=i;a=Y(t,h,o,a,s),a=Y(e,h+=t.length,o,a,s),a=Y(r,h+=e.length,o,a,s),Y(n,h+=r.length,o,a,s)},B.heightmapTerrainQuality=.25,B.getEstimatedLevelZeroGeometricErrorForAHeightmap=function(t,e,r){return 2*t.maximumRadius*Math.PI*B.heightmapTerrainQuality/(e*r)},B.prototype.requestTileGeometry=l.t.throwInstantiationError,B.prototype.getLevelMaximumGeometricError=l.t.throwInstantiationError,B.prototype.getTileDataAvailable=l.t.throwInstantiationError,B.prototype.loadTileDataAvailability=l.t.throwInstantiationError;var k=32767,H=new i.t,V=new i.t,U=new i.t,z=new i.t$1,L=new n.o,D=new i.t,j=new c.y,q=new c.y;function K(t,e,r,n,o,a,s,h,u){var l=Number.POSITIVE_INFINITY,I=o.north,m=o.south,g=o.east,T=o.west;g<T&&(g+=d.e.TWO_PI);for(var f=t.length,y=0;y<f;++y){var v=t[y],w=r[v],E=n[v];z.longitude=d.e.lerp(T,g,E.x),z.latitude=d.e.lerp(m,I,E.y),z.height=w-e;var p=a.cartographicToCartesian(z,H);c.y.multiplyByPoint(s,p,p),i.t.minimumByComponent(p,h,h),i.t.maximumByComponent(p,u,u),l=Math.min(l,z.height)}return l}function Q(e,r,n,a,s,h,u,l,g,T,f,y,v,w,E){var p=o.e(u),N=g.north,b=g.south,S=g.east,A=g.west;S<A&&(S+=d.e.TWO_PI);for(var x=n.length,P=0;P<x;++P){var _=n[P],F=s[_],M=h[_];z.longitude=d.e.lerp(A,S,M.x)+w,z.latitude=d.e.lerp(b,N,M.y)+E,z.height=F-T;var B,G=l.cartographicToCartesian(z,H);if(p){var W=2*_;if(L.x=u[W],L.y=u[W+1],1!==f){var O=t.t.octDecode(L.x,L.y,D),R=I.m.eastNorthUpToFixedFrame(H,l,q),C=c.y.inverseTransformation(R,j);c.y.multiplyByPointAsVector(C,O,O),O.z*=f,i.t.normalize(O,O),c.y.multiplyByPointAsVector(R,O,O),i.t.normalize(O,O),t.t.octEncode(O,L)}}a.hasWebMercatorT&&(B=(m.t.geodeticLatitudeToMercatorAngle(z.latitude)-y)*v),r=a.encode(e,r,G,M,z.height,L,B)}}function X(t,e){var r;return"function"==typeof t.slice&&"function"!=typeof(r=t.slice()).sort&&(r=void 0),o.e(r)||(r=Array.prototype.slice.call(t)),r.sort(e),r}var Z=g((function(l,g){var T,f,y=l.quantizedVertices,v=y.length/3,w=l.octEncodedNormals,E=l.westIndices.length+l.eastIndices.length+l.southIndices.length+l.northIndices.length,p=l.includeWebMercatorT,N=a.h.clone(l.rectangle),b=N.west,S=N.south,A=N.east,x=N.north,P=a.t.clone(l.ellipsoid),_=l.exaggeration,F=l.minimumHeight*_,M=l.maximumHeight*_,G=o.e(l.validMinimumHeight)?l.validMinimumHeight*_:F*_,W=o.e(l.validMaximumHeight)?l.validMaximumHeight*_:M*_,O=l.relativeToCenter,R=I.m.eastNorthUpToFixedFrame(O,P),C=c.y.inverseTransformation(R,new c.y);p&&(T=m.t.geodeticLatitudeToMercatorAngle(S),f=1/(m.t.geodeticLatitudeToMercatorAngle(x)-T));var Y=y.subarray(0,v),Z=y.subarray(v,2*v),$=y.subarray(2*v,3*v),J=o.e(w),tt=new Array(v),et=new Array(v),rt=new Array(v),nt=p?new Array(v):[],it=V;it.x=Number.POSITIVE_INFINITY,it.y=Number.POSITIVE_INFINITY,it.z=Number.POSITIVE_INFINITY;var ot=U;ot.x=Number.NEGATIVE_INFINITY,ot.y=Number.NEGATIVE_INFINITY,ot.z=Number.NEGATIVE_INFINITY;for(var at=Number.POSITIVE_INFINITY,st=Number.NEGATIVE_INFINITY,ht=Number.POSITIVE_INFINITY,dt=Number.NEGATIVE_INFINITY,ct=0;ct<v;++ct){var ut=Y[ct],lt=Z[ct],It=ut/k,mt=lt/k,gt=d.e.lerp(F,M,$[ct]/k);z.longitude=d.e.lerp(b,A,It),z.latitude=d.e.lerp(S,x,mt),z.height=gt,at=Math.min(z.longitude,at),st=Math.max(z.longitude,st),ht=Math.min(z.latitude,ht),dt=Math.max(z.latitude,dt);var Tt=P.cartographicToCartesian(z);tt[ct]=new n.o(It,mt),et[ct]=gt,rt[ct]=Tt,p&&(nt[ct]=(m.t.geodeticLatitudeToMercatorAngle(z.latitude)-T)*f),c.y.multiplyByPoint(C,Tt,H),i.t.minimumByComponent(H,it,it),i.t.maximumByComponent(H,ot,ot)}var ft,yt,vt=X(l.westIndices,(function(t,e){return tt[t].y-tt[e].y})),wt=X(l.eastIndices,(function(t,e){return tt[e].y-tt[t].y})),Et=X(l.southIndices,(function(t,e){return tt[e].x-tt[t].x})),pt=X(l.northIndices,(function(t,e){return tt[t].x-tt[e].x}));yt=r.i.fromPoints(rt),ft=u.x.fromRectangle(N,F,M,P);var Nt,bt=u.x.fromRectangle(N,G,W,P);(1!==_||F<0)&&(Nt=new s.s(P).computeHorizonCullingPointPossiblyUnderEllipsoid(O,rt,F));var St=F;St=Math.min(St,K(l.westIndices,l.westSkirtHeight,et,tt,N,P,C,it,ot)),St=Math.min(St,K(l.southIndices,l.southSkirtHeight,et,tt,N,P,C,it,ot)),St=Math.min(St,K(l.eastIndices,l.eastSkirtHeight,et,tt,N,P,C,it,ot)),St=Math.min(St,K(l.northIndices,l.northSkirtHeight,et,tt,N,P,C,it,ot));for(var At=new e.e(it,ot,O),xt=new s.h(At,St,M,R,J,p),Pt=xt.getStride(),_t=new Float32Array(v*Pt+E*Pt),Ft=0,Mt=0;Mt<v;++Mt){if(J){var Bt=2*Mt;if(L.x=w[Bt],L.y=w[Bt+1],1!==_){var Gt=t.t.octDecode(L.x,L.y,D),Wt=I.m.eastNorthUpToFixedFrame(rt[Mt],P,q),Ot=c.y.inverseTransformation(Wt,j);c.y.multiplyByPointAsVector(Ot,Gt,Gt),Gt.z*=_,i.t.normalize(Gt,Gt),c.y.multiplyByPointAsVector(Wt,Gt,Gt),i.t.normalize(Gt,Gt),t.t.octEncode(Gt,L)}}Ft=xt.encode(_t,Ft,rt[Mt],tt[Mt],et[Mt],L,nt[Mt])}var Rt=Math.max(0,2*(E-4)),Ct=l.indices.length+3*Rt,Yt=h.IndexDatatype.createTypedArray(v+E,Ct);Yt.set(l.indices,0);var kt=1e-4,Ht=(st-at)*kt,Vt=(dt-ht)*kt,Ut=-Ht,zt=Ht,Lt=Vt,Dt=-Vt,jt=v*Pt;Q(_t,jt,vt,xt,et,tt,w,P,N,l.westSkirtHeight,_,T,f,Ut,0),Q(_t,jt+=l.westIndices.length*Pt,Et,xt,et,tt,w,P,N,l.southSkirtHeight,_,T,f,0,Dt),Q(_t,jt+=l.southIndices.length*Pt,wt,xt,et,tt,w,P,N,l.eastSkirtHeight,_,T,f,zt,0),Q(_t,jt+=l.eastIndices.length*Pt,pt,xt,et,tt,w,P,N,l.northSkirtHeight,_,T,f,0,Lt);var qt=function(t,e,r,n){if(n<12)return;for(var i={},o=t.length,a=0;a<o;a+=3){var s=t[a],h=t[a+1],d=t[a+2];(e[s]===k&&e[h]===k||0===e[s]&&0===e[h]||r[s]===k&&r[h]===k||0===r[s]&&0===r[h])&&(i[s+"_"+h]=1,i[h+"_"+s]=1),(e[h]===k&&e[d]===k||0===e[h]&&0===e[d]||r[h]===k&&r[d]===k||0===r[h]&&0===r[d])&&(i[h+"_"+d]=1,i[d+"_"+h]=1),(e[d]===k&&e[s]===k||0===e[d]&&0===e[s]||r[d]===k&&r[s]===k||0===r[d]&&0===r[s])&&(i[d+"_"+s]=1,i[s+"_"+d]=1)}return i}(l.indices,Y,Z,l.level);return B.addSkirtIndices(vt,Et,wt,pt,v,Yt,l.indices.length,qt),g.push(_t.buffer,Yt.buffer),{vertices:_t.buffer,indices:Yt.buffer,westIndicesSouthToNorth:vt,southIndicesEastToWest:Et,eastIndicesNorthToSouth:wt,northIndicesWestToEast:pt,vertexStride:Pt,center:O,minimumHeight:F,maximumHeight:M,boundingSphere:yt,orientedBoundingBox:ft,validOrientedBoundingBox:bt,occludeePointInScaledSpace:Nt,encoding:xt,indexCountWithoutSkirts:l.indices.length}}));return Z}));