/** * Cesium - https://github.com/CesiumGS/cesium * * Copyright 2011-2020 Cesium Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Columbus View (Pat. Pend.) * * Portions licensed separately. * See https://github.com/CesiumGS/cesium/blob/master/LICENSE.md for full licensing details. */ define(["./when-8d13db60","./Check-70bec281","./Math-61ede240","./Cartographic-f27b0939","./Cartesian2-09435a6c","./BoundingSphere-c409f092","./Cartesian4-5af5bb24","./RuntimeError-ba10bc3e","./WebGLConstants-4c11ee5f","./ComponentDatatype-5862616f","./FeatureDetection-7bd32c34","./Transforms-1509c877","./buildModuleUrl-392763e2","./AttributeCompression-75ce15eb","./IntersectionTests-dbfba52c","./Plane-2bcb9154","./WebMercatorProjection-bc9aa7fe","./createTaskProcessorWorker","./EllipsoidTangentPlane-9c25b2da","./OrientedBoundingBox-7b25e901","./TerrainEncoding-3dab0ca0"],function(Ye,We,Xe,Ze,je,qe,e,n,t,i,a,Ge,r,s,l,o,Qe,f,Je,Ke,$e){var u=Object.freeze({NONE:0,LERC:1}),et={};et.DEFAULT_STRUCTURE=Object.freeze({heightScale:1,heightOffset:0,elementsPerHeight:1,stride:1,elementMultiplier:256,isBigEndian:!1});var tt=new Ze.Cartesian3,it=new qe.Matrix4,at=new Ze.Cartesian3,rt=new Ze.Cartesian3;et.computeVertices=function(e){if(!Ye.defined(e)||!Ye.defined(e.heightmap))throw new We.DeveloperError("options.heightmap is required.");if(!Ye.defined(e.width)||!Ye.defined(e.height))throw new We.DeveloperError("options.width and options.height are required.");if(!Ye.defined(e.nativeRectangle))throw new We.DeveloperError("options.nativeRectangle is required.");if(!Ye.defined(e.skirtHeight))throw new We.DeveloperError("options.skirtHeight is required.");var t,i,a,r,n=Math.cos,s=Math.sin,l=Math.sqrt,o=Math.atan,f=Math.exp,u=Xe.CesiumMath.PI_OVER_TWO,d=Xe.CesiumMath.toRadians,c=e.heightmap,h=e.width,m=e.height,g=e.skirtHeight,p=Ye.defaultValue(e.isGeographic,!0),w=Ye.defaultValue(e.ellipsoid,je.Ellipsoid.WGS84),x=1/w.maximumRadius,k=e.nativeRectangle,y=e.rectangle;r=Ye.defined(y)?(t=y.west,i=y.south,a=y.east,y.north):p?(t=d(k.west),i=d(k.south),a=d(k.east),d(k.north)):(t=k.west*x,i=u-2*o(f(-k.south*x)),a=k.east*x,u-2*o(f(-k.north*x)));var b=e.relativeToCenter,v=Ye.defined(b);b=v?b:Ze.Cartesian3.ZERO;var I=Ye.defaultValue(e.exaggeration,1),U=Ye.defaultValue(e.includeWebMercatorT,!1),T=Ye.defaultValue(e.structure,et.DEFAULT_STRUCTURE),M=Ye.defaultValue(T.heightScale,et.DEFAULT_STRUCTURE.heightScale),V=Ye.defaultValue(T.heightOffset,et.DEFAULT_STRUCTURE.heightOffset),A=Ye.defaultValue(T.elementsPerHeight,et.DEFAULT_STRUCTURE.elementsPerHeight),D=Ye.defaultValue(T.stride,et.DEFAULT_STRUCTURE.stride),B=Ye.defaultValue(T.elementMultiplier,et.DEFAULT_STRUCTURE.elementMultiplier),S=Ye.defaultValue(T.isBigEndian,et.DEFAULT_STRUCTURE.isBigEndian),P=je.Rectangle.computeWidth(k),E=je.Rectangle.computeHeight(k),C=P/(h-1),F=E/(m-1);p||(P*=x,E*=x);var L,O,N=w.radiiSquared,R=N.x,z=N.y,H=N.z,_=65536,Y=-65536,W=Ge.Transforms.eastNorthUpToFixedFrame(b,w),X=qe.Matrix4.inverseTransformation(W,it);U&&(L=Qe.WebMercatorProjection.geodeticLatitudeToMercatorAngle(i),O=1/(Qe.WebMercatorProjection.geodeticLatitudeToMercatorAngle(r)-L));var Z=at;Z.x=Number.POSITIVE_INFINITY,Z.y=Number.POSITIVE_INFINITY,Z.z=Number.POSITIVE_INFINITY;var j=rt;j.x=Number.NEGATIVE_INFINITY,j.y=Number.NEGATIVE_INFINITY,j.z=Number.NEGATIVE_INFINITY;var q=Number.POSITIVE_INFINITY,G=h*m,Q=G+(0>3],T<<=7&M),g=0;g>3]),s[M++]=128&T?(l&&(l[M]=1),m=(n=A.encoding<2?v[I++]:U)>=6,2===(y.offsetType=b))y.offset=n.getInt8(1),x++;else if(1===b)y.offset=n.getInt16(1,!0),x+=2;else{if(0!==b)throw"Invalid block offset type";y.offset=n.getFloat32(1,!0),x+=4}if(1===y.encoding)if(b=n.getUint8(x),x++,y.bitsPerPixel=63&b,b>>=6,2===(y.numValidPixelsType=b))y.numValidPixels=n.getUint8(x),x++;else if(1===b)y.numValidPixels=n.getUint16(x,!0),x+=2;else{if(0!==b)throw"Invalid valid pixel count type";y.numValidPixels=n.getUint32(x,!0),x+=4}}var v;if(t+=x,3!==y.encoding)if(0===y.encoding){var I=(a.pixels.numBytes-1)/4;if(I!==Math.floor(I))throw"uncompressed block has invalid length";v=new ArrayBuffer(4*I),new Uint8Array(v).set(new Uint8Array(e,t,4*I));var U=new Float32Array(v);y.rawData=U,t+=4*I}else if(1===y.encoding){var T=Math.ceil(y.numValidPixels*y.bitsPerPixel/8),M=Math.ceil(T/4);v=new ArrayBuffer(4*M),new Uint8Array(v).set(new Uint8Array(e,t,T)),y.stuffedData=new Uint32Array(v),t+=T}}else t++}return a.eofOffset=t,a},D=function(e,t,i,a,r,n,s){var l,o,f,u=(1<>>c-t&u,c-=t;else{var g=t-c;o=(f&u)<>>(c=32-g)}n[l]=o>>g-i&h,g-=i):(f=(u&h)<<(d=i-g)&h,f+=(u=e[m++])>>>(g=32-d)),t[o]=r[f];else for(c=Math.ceil((l-n)/s),o=0;o>>g-i&h,g-=i):(f=(u&h)<<(d=i-g)&h,f+=(u=e[m++])>>>(g=32-d)),t[o]=f>>d-t&l,d-=t):(c=(s&l)<<(u=t-d)&l,c+=(s=e[o++])>>>(d=32-u)),h[f]=c>>g&c,m-=i,g+=i):(f=u>>>g&c,m=32-(d=i-m),f|=((u=e[h++])&(1<>>g&c,m-=i,g+=i):(f=u>>>g&c,m=32-(d=i-m),f|=((u=e[h++])&(1<>>h&l,d-=t,h+=t):(c=s>>>h&l,d=32-(u=t-d),c|=((s=e[o++])&(1<>>u-i&o,u-=i):(n=(s&o)<<(l=i-u)&o,n+=(s=e[f++])>>>(u=32-l)),t[r]=n;return t},E=function(e,t,i,a){var r,n,s,l,o=(1<>>d&o,u-=i,d+=i):(n=s>>>d&o,u=32-(l=i-u),n|=((s=e[f++])&(1<>>16),i=(65535&i)+(i>>>16)}return 1&a&&(i+=t+=e[n]<<8),((i=(65535&i)+(i>>>16))<<16|(t=(65535&t)+(t>>>16)))>>>0},readHeaderInfo:function(e,t){var i=t.ptr,a=new Uint8Array(e,i,6),r={};if(r.fileIdentifierString=String.fromCharCode.apply(null,a),0!==r.fileIdentifierString.lastIndexOf("Lerc2",0))throw"Unexpected file identifier string (expect Lerc2 ): "+r.fileIdentifierString;i+=6;var n,s=new DataView(e,i,8),l=s.getInt32(0,!0);if(i+=4,3<=(r.fileVersion=l)&&(r.checksum=s.getUint32(4,!0),i+=4),s=new DataView(e,i,12),r.height=s.getUint32(0,!0),r.width=s.getUint32(4,!0),i+=8,4<=l?(r.numDims=s.getUint32(8,!0),i+=4):r.numDims=1,s=new DataView(e,i,40),r.numValidPixel=s.getUint32(0,!0),r.microBlockSize=s.getInt32(4,!0),r.blobSize=s.getInt32(8,!0),r.imageType=s.getInt32(12,!0),r.maxZError=s.getFloat64(16,!0),r.zMin=s.getFloat64(24,!0),r.zMax=s.getFloat64(32,!0),i+=40,t.headerInfo=r,t.ptr=i,3<=l&&(n=4<=l?52:48,this.computeChecksumFletcher32(new Uint8Array(e,i-n,r.blobSize-14))!==r.checksum))throw"Checksum failed.";return!0},checkMinMaxRanges:function(e,t){var i=t.headerInfo,a=this.getDataTypeArray(i.imageType),r=i.numDims*this.getDataTypeSize(i.imageType),n=this.readSubArray(e,t.ptr,a,r),s=this.readSubArray(e,t.ptr+r,a,r);t.ptr+=2*r;var l,o=!0;for(l=0;l>3],m<<=7&g):m=i[g>>3],128&m&&(a[g]=1);t.pixels.resultMask=a,f.bitset=i,r+=f.numBytes}return t.ptr=r,t.mask=f,!0},readDataOneSweep:function(e,t,i){var a,r=t.ptr,n=t.headerInfo,s=n.numDims,l=n.width*n.height,o=n.imageType,f=n.numValidPixel*z.getDataTypeSize(o)*s,u=t.pixels.resultMask;if(i===Uint8Array)a=new Uint8Array(e,r,f);else{var d=new ArrayBuffer(f);new Uint8Array(d).set(new Uint8Array(e,r,f)),a=new i(d)}if(a.length===l*s)t.pixels.resultPixels=a;else{t.pixels.resultPixels=new i(l*s);var c=0,h=0,m=0,g=0;if(1>>32-d,d<=32-x?32===(x+=d)&&(x=0,p=w[++k]):(x+=d-32,p=w[++k],c[f].second|=p>>>32-x));var y=0,b=0,v=new C;for(o=0;o>>M&1?(V.right||(V.right=new C),V.right):(V.left||(V.left=new C),V.left),0!==M||V.val||(V.val=I[1]);return{decodeLut:A,numBitsLUTQick:b,numBitsLUT:y,tree:v,stuffedData:w,srcPtr:k,bitPos:x}},readHuffman:function(e,t,i){var a,r,n,s,l,o,f,u,d,c=t.headerInfo,h=c.numDims,m=t.headerInfo.height,g=t.headerInfo.width,p=g*m,w=this.readHuffmanTree(e,t),x=w.decodeLut,k=w.tree,y=w.stuffedData,b=w.srcPtr,v=w.bitPos,I=w.numBitsLUTQick,U=w.numBitsLUT,T=0===t.headerInfo.imageType?128:0,M=t.pixels.resultMask,V=0;0>>32-I,32-v>>64-v-I),x[l])r=x[l][1],v+=x[l][0];else for(l=s=D<>>32-U,32-v>>64-v-U),a=k,d=0;d>>U-d-1&1?a.right:a.left).left&&!a.right){r=a.val,v=v+d+1;break}32<=v&&(v-=32,D=y[++b]),n=r-T,B?(n+=0>>32-I,32-v>>64-v-I),x[l])r=x[l][1],v+=x[l][0];else for(l=s=D<>>32-U,32-v>>64-v-U),a=k,d=0;d>>U-d-1&1?a.right:a.left).left&&!a.right){r=a.val,v=v+d+1;break}32<=v&&(v-=32,D=y[++b]),n=r-T,B?(0>6,c=0===d?4:3-d,h=0<(32&u),m=31&u,g=0;if(1===c)g=f.getUint8(l),l++;else if(2===c)g=f.getUint16(l,!0),l+=2;else{if(4!==c)throw"Invalid valid pixel count type";g=f.getUint32(l,!0),l+=4}var p,w,x,k,y,b,v,I,U,T=2*n.maxZError,M=1>>U;)U++;k=Math.ceil(g*U/8),y=Math.ceil(k/4),w=new ArrayBuffer(4*y),(x=new Uint8Array(w)).set(new Uint8Array(e,t.ptr,k)),p=new Uint32Array(w),t.ptr+=k,b=3<=s?S(v,m,I-1,a,T,M):A(v,m,I-1,a,T,M),3<=s?B(p,i,U,g,b):V(p,i,U,g,b)}else t.counter.bitstuffer++,U=m,t.ptr+=l,0>6&255,(M>>2&15)!==(v*s>>3&15))throw"integrity issue";if(3<(g=3&M))throw t.ptr+=E,"Invalid block encoding ("+g+")";if(2!==g)if(0===g){if(t.counter.uncompressed++,t.ptr+=E,B=(B=I*U*o)<(S=e.byteLength-t.ptr)?B:S,h=new ArrayBuffer(B%o==0?B:B+o-B%o),new Uint8Array(h).set(new Uint8Array(e,t.ptr,B)),m=new i(h),P=0,N)for(k=0;k