define(["./AttributeCompression-8ecc041c","./Cartesian2-49b1de22","./Color-91231c89","./when-54c2dc71","./IndexDatatype-46306178","./Math-44e92d6b","./OrientedBoundingBox-3669ebd4","./createTaskProcessorWorker","./Check-6c0211bc","./Transforms-e9dbfb40","./RuntimeError-2109023a","./WebGLConstants-76bb35d1","./EllipsoidTangentPlane-c4704d0f","./IntersectionTests-6ead8677","./Plane-8f7e53d1"],function(ye,Ie,me,we,ve,xe,Ae,e,a,r,n,t,i,o,s){"use strict";var Ee=new Ie.Cartesian3,Ne=new Ie.Ellipsoid,Te=new Ie.Rectangle,ke={min:void 0,max:void 0,indexBytesPerElement:void 0};function Be(e,a,r){var n=a.length,t=2+n*Ae.OrientedBoundingBox.packedLength+1+function(e){for(var a=e.length,r=0,n=0;n<a;++n)r+=me.Color.packedLength+3+e[n].batchIds.length;return r}(r),i=new Float64Array(t),o=0;i[o++]=e,i[o++]=n;for(var s=0;s<n;++s)Ae.OrientedBoundingBox.pack(a[s],i,o),o+=Ae.OrientedBoundingBox.packedLength;var d=r.length;i[o++]=d;for(var f=0;f<d;++f){var c=r[f];me.Color.pack(c.color,i,o),o+=me.Color.packedLength,i[o++]=c.offset,i[o++]=c.count;var u=c.batchIds,h=u.length;i[o++]=h;for(var l=0;l<h;++l)i[o++]=u[l]}return i}var Le=new Ie.Cartesian3,Oe=new Ie.Cartesian3,Ue=new Ie.Cartesian3,Pe=new Ie.Cartesian3,Fe=new Ie.Cartesian3,Se=new Ie.Cartographic,Re=new Ie.Rectangle;return e(function(e,a){var r;i=e.packedBuffer,r=new Float64Array(i),i=0,ke.indexBytesPerElement=r[i++],ke.min=r[i++],ke.max=r[i++],Ie.Cartesian3.unpack(r,3,Ee),i+=Ie.Cartesian3.packedLength,Ie.Ellipsoid.unpack(r,i,Ne),i+=Ie.Ellipsoid.packedLength,Ie.Rectangle.unpack(r,i,Te);var n,t=new(2===ke.indexBytesPerElement?Uint16Array:Uint32Array)(e.indices),i=new Uint16Array(e.positions),o=new Uint32Array(e.counts),s=new Uint32Array(e.indexCounts),d=new Uint32Array(e.batchIds),f=new Uint32Array(e.batchTableColors),c=new Array(o.length),u=Ee,h=Ne,l=Te,g=ke.min,p=ke.max,b=e.minimumHeights,C=e.maximumHeights;we.defined(b)&&we.defined(C)&&(b=new Float32Array(b),C=new Float32Array(C));var y=i.length/2,I=i.subarray(0,y),m=i.subarray(y,2*y);ye.AttributeCompression.zigZagDeltaDecode(I,m);for(var w=new Float64Array(3*y),v=0;v<y;++v){var x=I[v],A=m[v],x=xe.CesiumMath.lerp(l.west,l.east,x/32767),A=xe.CesiumMath.lerp(l.south,l.north,A/32767),A=Ie.Cartographic.fromRadians(x,A,0,Se),A=h.cartographicToCartesian(A,Le);Ie.Cartesian3.pack(A,w,3*v)}var E=o.length,N=new Array(E),T=new Array(E),k=0,B=0;for(v=0;v<E;++v)N[v]=k,T[v]=B,k+=o[v],B+=s[v];var L,O=new Float32Array(3*y*2),U=new Uint16Array(2*y),P=new Uint32Array(T.length),F=new Uint32Array(s.length),S=[],R={};for(v=0;v<E;++v)n=f[v],we.defined(R[n])?(R[n].positionLength+=o[v],R[n].indexLength+=s[v],R[n].batchIds.push(v)):R[n]={positionLength:o[v],indexLength:s[v],offset:0,indexOffset:0,batchIds:[v]};var D,M=0,_=0;for(n in R)R.hasOwnProperty(n)&&((L=R[n]).offset=M,L.indexOffset=_,M+=2*L.positionLength,_+=D=2*L.indexLength+6*L.positionLength,L.indexLength=D);var G=[];for(n in R)R.hasOwnProperty(n)&&(L=R[n],G.push({color:me.Color.fromRgba(parseInt(n)),offset:L.indexOffset,count:L.indexLength,batchIds:L.batchIds}));for(v=0;v<E;++v){var Y=(L=R[n=f[v]]).offset,V=3*Y,H=Y,W=N[v],z=o[v],Z=d[v],j=g,q=p;we.defined(b)&&we.defined(C)&&(j=b[v],q=C[v]);for(var J=Number.POSITIVE_INFINITY,K=Number.NEGATIVE_INFINITY,Q=Number.POSITIVE_INFINITY,X=Number.NEGATIVE_INFINITY,$=0;$<z;++$){var ee=Ie.Cartesian3.unpack(w,3*W+3*$,Le);h.scaleToGeodeticSurface(ee,ee);var ae=h.cartesianToCartographic(ee,Se),re=ae.latitude,ne=ae.longitude,J=Math.min(re,J),K=Math.max(re,K),Q=Math.min(ne,Q),X=Math.max(ne,X),ae=h.geodeticSurfaceNormal(ee,Oe),re=Ie.Cartesian3.multiplyByScalar(ae,j,Ue),ne=Ie.Cartesian3.add(ee,re,Pe),re=Ie.Cartesian3.multiplyByScalar(ae,q,re),re=Ie.Cartesian3.add(ee,re,Fe);Ie.Cartesian3.subtract(re,u,re),Ie.Cartesian3.subtract(ne,u,ne),Ie.Cartesian3.pack(re,O,V),Ie.Cartesian3.pack(ne,O,V+3),U[H]=Z,U[H+1]=Z,V+=6,H+=2}(l=Re).west=Q,l.east=X,l.south=J,l.north=K,c[v]=Ae.OrientedBoundingBox.fromRectangle(l,g,p,h);var te=L.indexOffset,ie=T[v],oe=s[v];for(P[v]=te,$=0;$<oe;$+=3){var se=t[ie+$]-W,de=t[ie+$+1]-W,fe=t[ie+$+2]-W;S[te++]=2*se+Y,S[te++]=2*de+Y,S[te++]=2*fe+Y,S[te++]=2*fe+1+Y,S[te++]=2*de+1+Y,S[te++]=2*se+1+Y}for($=0;$<z;++$){var ce=$,ue=($+1)%z;S[te++]=2*ce+1+Y,S[te++]=2*ue+Y,S[te++]=2*ce+Y,S[te++]=2*ce+1+Y,S[te++]=2*ue+1+Y,S[te++]=2*ue+Y}L.offset+=2*z,L.indexOffset=te,F[v]=te-P[v]}S=ve.IndexDatatype.createTypedArray(O.length/3,S);for(var he=G.length,le=0;le<he;++le){for(var ge=G[le].batchIds,pe=0,be=ge.length,Ce=0;Ce<be;++Ce)pe+=F[ge[Ce]];G[le].count=pe}return i=Be(2===S.BYTES_PER_ELEMENT?ve.IndexDatatype.UNSIGNED_SHORT:ve.IndexDatatype.UNSIGNED_INT,c,G),a.push(O.buffer,S.buffer,P.buffer,F.buffer,U.buffer,i.buffer),{positions:O.buffer,indices:S.buffer,indexOffsets:P.buffer,indexCounts:F.buffer,batchIds:U.buffer,packedBuffer:i.buffer}})});
