createVerticesFromQuantizedTerrainMesh.js 10 KB

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