createVerticesFromGoogleEarthEnterpriseBuffer.js 7.2 KB

1
  1. define(["./AxisAlignedBoundingBox-122de82b","./Transforms-73e77b72","./Cartesian2-b4b7b0b3","./when-208fe5b0","./TerrainEncoding-e1b1da20","./Math-8386669c","./OrientedBoundingBox-2e9d8f93","./RuntimeError-7f634f5d","./WebMercatorProjection-1b058022","./createTaskProcessorWorker","./Check-5e798bbf","./AttributeCompression-9711314b","./ComponentDatatype-2da3a966","./WebGLConstants-5e2a49ab","./EllipsoidTangentPlane-69cc10ff","./IntersectionTests-40db2afa","./Plane-b91bfb59"],function(ve,Me,be,xe,Ne,Se,we,Be,Pe,e,t,i,n,a,r,o,s){"use strict";var Ae=Uint16Array.BYTES_PER_ELEMENT,ye=Int32Array.BYTES_PER_ELEMENT,Re=Uint32Array.BYTES_PER_ELEMENT,_e=Float32Array.BYTES_PER_ELEMENT,We=Float64Array.BYTES_PER_ELEMENT;function Fe(e,t,i){i=xe.defaultValue(i,Se.CesiumMath);for(var n=e.length,a=0;a<n;++a)if(i.equalsEpsilon(e[a],t,Se.CesiumMath.EPSILON12))return a;return-1}var Oe=new be.Cartographic,Ye=new be.Cartesian3,ke=new be.Cartesian3,Ue=new be.Cartesian3,Ve=new Me.Matrix4;function He(e,t,i,n,a,r,o,s,u,h,d){for(var c=s.length,g=0;g<c;++g){var l=s[g],m=l.cartographic,p=l.index,I=e.length,E=m.longitude,f=m.latitude,f=Se.CesiumMath.clamp(f,-Se.CesiumMath.PI_OVER_TWO,Se.CesiumMath.PI_OVER_TWO),m=m.height-o.skirtHeight;o.hMin=Math.min(o.hMin,m),be.Cartographic.fromRadians(E,f,m,Oe),h&&(Oe.longitude+=u),h?g===c-1?Oe.latitude+=d:0===g&&(Oe.latitude-=d):Oe.latitude+=u;f=o.ellipsoid.cartographicToCartesian(Oe);e.push(f),t.push(m),i.push(be.Cartesian2.clone(i[p])),0<n.length&&n.push(n[p]),0<a.length&&a.push(a[p]),Me.Matrix4.multiplyByPoint(o.toENU,f,Ye);m=o.minimum,f=o.maximum;be.Cartesian3.minimumByComponent(Ye,m,m),be.Cartesian3.maximumByComponent(Ye,f,f);f=o.lastBorderPoint;xe.defined(f)&&(f=f.index,r.push(f,I-1,I,I,p,f)),o.lastBorderPoint=l}}return e(function(e,t){e.ellipsoid=be.Ellipsoid.clone(e.ellipsoid),e.rectangle=be.Rectangle.clone(e.rectangle);var i=function(e,t,i,n,a,r,o,s,u,h,d){var c,g,l,m,p;le=xe.defined(n)?(c=n.west,g=n.south,l=n.east,m=n.north,p=n.width,n.height):(c=Se.CesiumMath.toRadians(a.west),g=Se.CesiumMath.toRadians(a.south),l=Se.CesiumMath.toRadians(a.east),m=Se.CesiumMath.toRadians(a.north),p=Se.CesiumMath.toRadians(n.width),Se.CesiumMath.toRadians(n.height));var I,E,f=[g,m],T=[c,l],C=Me.Transforms.eastNorthUpToFixedFrame(t,i),v=Me.Matrix4.inverseTransformation(C,Ve);u&&(I=Pe.WebMercatorProjection.geodeticLatitudeToMercatorAngle(g),E=1/(Pe.WebMercatorProjection.geodeticLatitudeToMercatorAngle(m)-I));var M=1!==r,b=new DataView(e),x=Number.POSITIVE_INFINITY,N=Number.NEGATIVE_INFINITY,S=ke;S.x=Number.POSITIVE_INFINITY,S.y=Number.POSITIVE_INFINITY,S.z=Number.POSITIVE_INFINITY;var w=Ue;w.x=Number.NEGATIVE_INFINITY,w.y=Number.NEGATIVE_INFINITY,w.z=Number.NEGATIVE_INFINITY;var B,P,A=0,y=0,R=0;for(P=0;P<4;++P){var _=A;B=b.getUint32(_,!0),_+=Re;var W=Se.CesiumMath.toRadians(180*b.getFloat64(_,!0));_+=We,-1===Fe(T,W)&&T.push(W);W=Se.CesiumMath.toRadians(180*b.getFloat64(_,!0));_+=We,-1===Fe(f,W)&&f.push(W),_+=2*We;W=b.getInt32(_,!0);_+=ye,y+=W,W=b.getInt32(_,!0),R+=3*W,A+=B+Re}var F=[],O=[],Y=new Array(y),k=new Array(y),U=new Array(y),V=u?new Array(y):[],H=M?new Array(y):[],L=new Array(R),D=[],G=[],j=[],z=[],q=0,J=0;for(P=A=0;P<4;++P){B=b.getUint32(A,!0);var K=A+=Re,Q=Se.CesiumMath.toRadians(180*b.getFloat64(A,!0));A+=We;var X=Se.CesiumMath.toRadians(180*b.getFloat64(A,!0));A+=We;var Z=Se.CesiumMath.toRadians(180*b.getFloat64(A,!0)),$=.5*Z;A+=We;var ee=Se.CesiumMath.toRadians(180*b.getFloat64(A,!0)),te=.5*ee;A+=We;var ie=b.getInt32(A,!0);A+=ye;var ne=b.getInt32(A,!0);A+=ye,A+=ye;for(var ae=new Array(ie),re=0;re<ie;++re){var oe=Q+b.getUint8(A++)*Z;Oe.longitude=oe;var se=X+b.getUint8(A++)*ee;Oe.latitude=se;var ue=b.getFloat32(A,!0);if(A+=_e,0!==ue&&ue<d&&(ue*=-Math.pow(2,h)),ue*=6371010,Oe.height=ue,-1!==Fe(T,oe)||-1!==Fe(f,se)){var he=Fe(F,Oe,be.Cartographic);if(-1!==he){ae[re]=O[he];continue}F.push(be.Cartographic.clone(Oe)),O.push(q)}ae[re]=q,Math.abs(oe-c)<$?D.push({index:q,cartographic:be.Cartographic.clone(Oe)}):Math.abs(oe-l)<$?j.push({index:q,cartographic:be.Cartographic.clone(Oe)}):Math.abs(se-g)<te?G.push({index:q,cartographic:be.Cartographic.clone(Oe)}):Math.abs(se-m)<te&&z.push({index:q,cartographic:be.Cartographic.clone(Oe)}),x=Math.min(ue,x),N=Math.max(ue,N),U[q]=ue;he=i.cartographicToCartesian(Oe);Y[q]=he,u&&(V[q]=(Pe.WebMercatorProjection.geodeticLatitudeToMercatorAngle(se)-I)*E),M&&(ue=i.geodeticSurfaceNormal(he),H[q]=ue),Me.Matrix4.multiplyByPoint(v,he,Ye),be.Cartesian3.minimumByComponent(Ye,S,S),be.Cartesian3.maximumByComponent(Ye,w,w);oe=(oe-c)/(l-c);oe=Se.CesiumMath.clamp(oe,0,1);se=(se-g)/(m-g);se=Se.CesiumMath.clamp(se,0,1),k[q]=new be.Cartesian2(oe,se),++q}for(var de=3*ne,ce=0;ce<de;++ce,++J)L[J]=ae[b.getUint16(A,!0)],A+=Ae;if(B!==A-K)throw new Be.RuntimeError("Invalid terrain tile.")}Y.length=q,k.length=q,U.length=q,u&&(V.length=q);M&&(H.length=q);var ge=q,a=J,e={hMin:x,lastBorderPoint:void 0,skirtHeight:s,toENU:v,ellipsoid:i,minimum:S,maximum:w};D.sort(function(e,t){return t.cartographic.latitude-e.cartographic.latitude}),G.sort(function(e,t){return e.cartographic.longitude-t.cartographic.longitude}),j.sort(function(e,t){return e.cartographic.latitude-t.cartographic.latitude}),z.sort(function(e,t){return t.cartographic.longitude-e.cartographic.longitude});s=1e-5;{var le;He(Y,U,k,V,H,L,e,D,-s*p,!0,-s*le),He(Y,U,k,V,H,L,e,G,-s*le,!1),He(Y,U,k,V,H,L,e,j,s*p,!0,s*le),He(Y,U,k,V,H,L,e,z,s*le,!1),0<D.length&&0<z.length&&(pe=D[0].index,Ie=z[z.length-1].index,le=Y.length-1,L.push(Ie,le,ge,ge,pe,Ie))}y=Y.length;var me,pe=Me.BoundingSphere.fromPoints(Y);xe.defined(n)&&(me=we.OrientedBoundingBox.fromRectangle(n,x,N,i));for(var Ie=new Ne.EllipsoidalOccluder(i).computeHorizonCullingPointPossiblyUnderEllipsoid(t,Y,x),n=new ve.AxisAlignedBoundingBox(S,w,t),Ee=new Ne.TerrainEncoding(t,n,e.hMin,N,C,!1,u,M,r,o),fe=new Float32Array(y*Ee.stride),Te=0,Ce=0;Ce<y;++Ce)Te=Ee.encode(fe,Te,Y[Ce],k[Ce],U[Ce],void 0,V[Ce],H[Ce]);e=D.map(function(e){return e.index}).reverse(),C=G.map(function(e){return e.index}).reverse(),r=j.map(function(e){return e.index}).reverse(),o=z.map(function(e){return e.index}).reverse();return C.unshift(r[r.length-1]),C.push(e[0]),o.unshift(e[e.length-1]),o.push(r[0]),{vertices:fe,indices:new Uint16Array(L),maximumHeight:N,minimumHeight:x,encoding:Ee,boundingSphere3D:pe,orientedBoundingBox:me,occludeePointInScaledSpace:Ie,vertexCountWithoutSkirts:ge,indexCountWithoutSkirts:a,westIndicesSouthToNorth:e,southIndicesEastToWest:C,eastIndicesNorthToSouth:r,northIndicesWestToEast:o}}(e.buffer,e.relativeToCenter,e.ellipsoid,e.rectangle,e.nativeRectangle,e.exaggeration,e.exaggerationRelativeHeight,e.skirtHeight,e.includeWebMercatorT,e.negativeAltitudeExponentBias,e.negativeElevationThreshold),n=i.vertices;return t.push(n.buffer),e=i.indices,t.push(e.buffer),{vertices:n.buffer,indices:e.buffer,numberOfAttributes:i.encoding.stride,minimumHeight:i.minimumHeight,maximumHeight:i.maximumHeight,boundingSphere3D:i.boundingSphere3D,orientedBoundingBox:i.orientedBoundingBox,occludeePointInScaledSpace:i.occludeePointInScaledSpace,encoding:i.encoding,vertexCountWithoutSkirts:i.vertexCountWithoutSkirts,indexCountWithoutSkirts:i.indexCountWithoutSkirts,westIndicesSouthToNorth:i.westIndicesSouthToNorth,southIndicesEastToWest:i.southIndicesEastToWest,eastIndicesNorthToSouth:i.eastIndicesNorthToSouth,northIndicesWestToEast:i.northIndicesWestToEast}})});