bmh_cesium/public/lib/cesiumjs/CesiumUnminified/Workers/createVerticesFromQuantizedTerrainMesh.js
2025-03-10 07:23:50 +08:00

2 lines
9.2 KiB
JavaScript

/* 2020-9-22 15:23:25 | 版权所有 军懋国兴 */
define(["./when-cbf8cd21","./Check-35e1a91d","./Math-69007a69","./Cartesian2-43e3a3be","./Transforms-2d1ac5ec","./RuntimeError-f4c64df1","./WebGLConstants-95ceb4e9","./ComponentDatatype-607c9a0c","./AttributeCompression-ea810287","./IndexDatatype-79bb407c","./IntersectionTests-459f6f08","./Plane-46b5436f","./WebMercatorProjection-3da37aae","./createTaskProcessorWorker","./EllipsoidTangentPlane-b5927ee3","./OrientedBoundingBox-5e0b7a7c","./TerrainEncoding-848fa40b"],function(Te,g,pe,Ee,fe,e,t,r,ve,ye,n,i,we,o,Ne,be,Me){"use strict";function xe(){g.DeveloperError.throwInstantiationError()}Object.defineProperties(xe.prototype,{errorEvent:{get:g.DeveloperError.throwInstantiationError},credit:{get:g.DeveloperError.throwInstantiationError},tilingScheme:{get:g.DeveloperError.throwInstantiationError},ready:{get:g.DeveloperError.throwInstantiationError},readyPromise:{get:g.DeveloperError.throwInstantiationError},hasWaterMask:{get:g.DeveloperError.throwInstantiationError},hasVertexNormals:{get:g.DeveloperError.throwInstantiationError},availability:{get:g.DeveloperError.throwInstantiationError}});var a=[];xe.getRegularGridIndices=function(e,t){if(e*t>=pe.CesiumMath.FOUR_GIGABYTES)throw new g.DeveloperError("The total number of vertices (width * height) must be less than 4,294,967,296.");var r=a[e];Te.defined(r)||(a[e]=r=[]);var n=r[t];return Te.defined(n)||E(e,t,n=e*t<pe.CesiumMath.SIXTY_FOUR_KILOBYTES?r[t]=new Uint16Array((e-1)*(t-1)*6):r[t]=new Uint32Array((e-1)*(t-1)*6),0),n};var c=[];xe.getRegularGridIndicesAndEdgeIndices=function(e,t){if(e*t>=pe.CesiumMath.FOUR_GIGABYTES)throw new g.DeveloperError("The total number of vertices (width * height) must be less than 4,294,967,296.");var r=c[e];Te.defined(r)||(c[e]=r=[]);var n,i,o,a,s,h,d=r[t];return Te.defined(d)||(n=xe.getRegularGridIndices(e,t),o=(i=p(e,t)).westIndicesSouthToNorth,a=i.southIndicesEastToWest,s=i.eastIndicesNorthToSouth,h=i.northIndicesWestToEast,d=r[t]={indices:n,westIndicesSouthToNorth:o,southIndicesEastToWest:a,eastIndicesNorthToSouth:s,northIndicesWestToEast:h}),d};var T=[];function p(e,t){for(var r=new Array(t),n=new Array(e),i=new Array(t),o=new Array(e),a=0;a<e;++a)n[o[a]=a]=e*t-1-a;for(a=0;a<t;++a)i[a]=(a+1)*e-1,r[a]=(t-a-1)*e;return{westIndicesSouthToNorth:r,southIndicesEastToWest:n,eastIndicesNorthToSouth:i,northIndicesWestToEast:o}}function E(e,t,r,n){for(var i=0,o=0;o<t-1;++o){for(var a=0;a<e-1;++a){var s=i+e,h=s+1,d=i+1;r[n++]=i,r[n++]=s,r[n++]=d,r[n++]=d,r[n++]=s,r[n++]=h,++i}++i}}function h(e,t,r,n){for(var i=e[0],o=e.length,a=1;a<o;++a){var s=e[a];r[n++]=i,r[n++]=s,r[n++]=t,r[n++]=t,r[n++]=s,r[n++]=t+1,i=s,++t}return n}xe.getRegularGridAndSkirtIndicesAndEdgeIndices=function(e,t){if(e*t>=pe.CesiumMath.FOUR_GIGABYTES)throw new g.DeveloperError("The total number of vertices (width * height) must be less than 4,294,967,296.");var r=T[e];Te.defined(r)||(T[e]=r=[]);var n,i,o,a,s,h,d,c,u,l,I,m=r[t];return Te.defined(m)||(a=(n=e*t)+(o=2*e+2*t),s=(i=(e-1)*(t-1)*6)+6*Math.max(0,o-4),d=(h=p(e,t)).westIndicesSouthToNorth,c=h.southIndicesEastToWest,u=h.eastIndicesNorthToSouth,l=h.northIndicesWestToEast,E(e,t,I=ye.IndexDatatype.createTypedArray(a,s),0),xe.addSkirtIndices(d,c,u,l,n,I,i),m=r[t]={indices:I,westIndicesSouthToNorth:d,southIndicesEastToWest:c,eastIndicesNorthToSouth:u,northIndicesWestToEast:l,indexCountWithoutSkirts:i}),m},xe.addSkirtIndices=function(e,t,r,n,i,o,a){var s=i;a=h(e,s,o,a),a=h(t,s+=e.length,o,a),a=h(r,s+=t.length,o,a),h(n,s+=r.length,o,a)},xe.heightmapTerrainQuality=.25,xe.getEstimatedLevelZeroGeometricErrorForAHeightmap=function(e,t,r){return 2*e.maximumRadius*Math.PI*xe.heightmapTerrainQuality/(t*r)},xe.prototype.requestTileGeometry=g.DeveloperError.throwInstantiationError,xe.prototype.getLevelMaximumGeometricError=g.DeveloperError.throwInstantiationError,xe.prototype.getTileDataAvailable=g.DeveloperError.throwInstantiationError,xe.prototype.loadTileDataAvailability=g.DeveloperError.throwInstantiationError;var Ce=32767,Se=new Ee.Cartesian3,Ae=new Ee.Cartesian3,Pe=new Ee.Cartesian3,We=new Ee.Cartographic,De=new Ee.Cartesian2,Be=new Ee.Cartesian3,Fe=new fe.Matrix4,Ge=new fe.Matrix4;function ke(e,t,r,n,i,o,a,s,h){var d=Number.POSITIVE_INFINITY,c=i.north,u=i.south,l=i.east,I=i.west;l<I&&(l+=pe.CesiumMath.TWO_PI);for(var m=e.length,g=0;g<m;++g){var T=e[g],p=r[T],E=n[T];We.longitude=pe.CesiumMath.lerp(I,l,E.x),We.latitude=pe.CesiumMath.lerp(u,c,E.y),We.height=p-t;var f=o.cartographicToCartesian(We,Se);fe.Matrix4.multiplyByPoint(a,f,f),Ee.Cartesian3.minimumByComponent(f,s,s),Ee.Cartesian3.maximumByComponent(f,h,h),d=Math.min(d,We.height)}return d}function _e(e,t,r,n,i,o,a,s,h,d,c,u,l,I,m){var g=Te.defined(a),T=h.north,p=h.south,E=h.east,f=h.west;E<f&&(E+=pe.CesiumMath.TWO_PI);for(var v=r.length,y=0;y<v;++y){var w=r[y],N=i[w],b=o[w];We.longitude=pe.CesiumMath.lerp(f,E,b.x)+I,We.latitude=pe.CesiumMath.lerp(p,T,b.y)+m,We.height=N-d;var M,x,C,S,A,P=s.cartographicToCartesian(We,Se);g&&(M=2*w,De.x=a[M],De.y=a[1+M],1!==c&&(x=ve.AttributeCompression.octDecode(De.x,De.y,Be),C=fe.Transforms.eastNorthUpToFixedFrame(Se,s,Ge),S=fe.Matrix4.inverseTransformation(C,Fe),fe.Matrix4.multiplyByPointAsVector(S,x,x),x.z*=c,Ee.Cartesian3.normalize(x,x),fe.Matrix4.multiplyByPointAsVector(C,x,x),Ee.Cartesian3.normalize(x,x),ve.AttributeCompression.octEncode(x,De))),n.hasWebMercatorT&&(A=(we.WebMercatorProjection.geodeticLatitudeToMercatorAngle(We.latitude)-u)*l),t=n.encode(e,t,P,b,We.height,De,A)}}function Oe(e,t){var r;return"function"==typeof e.slice&&"function"!=typeof(r=e.slice()).sort&&(r=void 0),Te.defined(r)||(r=Array.prototype.slice.call(e)),r.sort(t),r}return o(function(e,t){var r,n,i=e.quantizedVertices,o=i.length/3,a=e.octEncodedNormals,s=e.westIndices.length+e.eastIndices.length+e.southIndices.length+e.northIndices.length,h=e.includeWebMercatorT,d=Ee.Rectangle.clone(e.rectangle),c=d.west,u=d.south,l=d.east,I=d.north,m=Ee.Ellipsoid.clone(e.ellipsoid),g=e.exaggeration,T=e.minimumHeight*g,p=e.maximumHeight*g,E=e.relativeToCenter,f=fe.Transforms.eastNorthUpToFixedFrame(E,m),v=fe.Matrix4.inverseTransformation(f,new fe.Matrix4);h&&(r=we.WebMercatorProjection.geodeticLatitudeToMercatorAngle(u),n=1/(we.WebMercatorProjection.geodeticLatitudeToMercatorAngle(I)-r));var y=i.subarray(0,o),w=i.subarray(o,2*o),N=i.subarray(2*o,3*o),b=Te.defined(a),M=new Array(o),x=new Array(o),C=new Array(o),S=h?new Array(o):[],A=Ae;A.x=Number.POSITIVE_INFINITY,A.y=Number.POSITIVE_INFINITY,A.z=Number.POSITIVE_INFINITY;var P=Pe;P.x=Number.NEGATIVE_INFINITY,P.y=Number.NEGATIVE_INFINITY,P.z=Number.NEGATIVE_INFINITY;for(var W=Number.POSITIVE_INFINITY,D=Number.NEGATIVE_INFINITY,B=Number.POSITIVE_INFINITY,F=Number.NEGATIVE_INFINITY,G=0;G<o;++G){var k=y[G],_=w[G],O=k/Ce,V=_/Ce,Y=pe.CesiumMath.lerp(T,p,N[G]/Ce);We.longitude=pe.CesiumMath.lerp(c,l,O),We.latitude=pe.CesiumMath.lerp(u,I,V),We.height=Y,W=Math.min(We.longitude,W),D=Math.max(We.longitude,D),B=Math.min(We.latitude,B),F=Math.max(We.latitude,F);var H=m.cartographicToCartesian(We);M[G]=new Ee.Cartesian2(O,V),x[G]=Y,C[G]=H,h&&(S[G]=(we.WebMercatorProjection.geodeticLatitudeToMercatorAngle(We.latitude)-r)*n),fe.Matrix4.multiplyByPoint(v,H,Se),Ee.Cartesian3.minimumByComponent(Se,A,A),Ee.Cartesian3.maximumByComponent(Se,P,P)}var R,z,U,L=Oe(e.westIndices,function(e,t){return M[e].y-M[t].y}),j=Oe(e.eastIndices,function(e,t){return M[t].y-M[e].y}),q=Oe(e.southIndices,function(e,t){return M[t].x-M[e].x}),Q=Oe(e.northIndices,function(e,t){return M[e].x-M[t].x});1!==g&&(z=fe.BoundingSphere.fromPoints(C),R=be.OrientedBoundingBox.fromRectangle(d,T,p,m)),(1!==g||T<0)&&(U=new Me.EllipsoidalOccluder(m).computeHorizonCullingPointPossiblyUnderEllipsoid(E,C,T));var K=T,K=Math.min(K,ke(e.westIndices,e.westSkirtHeight,x,M,d,m,v,A,P));K=Math.min(K,ke(e.southIndices,e.southSkirtHeight,x,M,d,m,v,A,P)),K=Math.min(K,ke(e.eastIndices,e.eastSkirtHeight,x,M,d,m,v,A,P)),K=Math.min(K,ke(e.northIndices,e.northSkirtHeight,x,M,d,m,v,A,P));for(var X,Z,J,$,ee=new Ne.AxisAlignedBoundingBox(A,P,E),te=new Me.TerrainEncoding(ee,K,p,f,b,h),re=te.getStride(),ne=new Float32Array(o*re+s*re),ie=0,oe=0;oe<o;++oe){b&&(X=2*oe,De.x=a[X],De.y=a[1+X],1!==g&&(Z=ve.AttributeCompression.octDecode(De.x,De.y,Be),J=fe.Transforms.eastNorthUpToFixedFrame(C[oe],m,Ge),$=fe.Matrix4.inverseTransformation(J,Fe),fe.Matrix4.multiplyByPointAsVector($,Z,Z),Z.z*=g,Ee.Cartesian3.normalize(Z,Z),fe.Matrix4.multiplyByPointAsVector(J,Z,Z),Ee.Cartesian3.normalize(Z,Z),ve.AttributeCompression.octEncode(Z,De))),ie=te.encode(ne,ie,C[oe],M[oe],x[oe],De,S[oe])}var ae=Math.max(0,2*(s-4)),se=e.indices.length+3*ae,he=ye.IndexDatatype.createTypedArray(o+s,se);he.set(e.indices,0);var de=1e-4*(D-W),ce=1e-4*(F-B),ue=-de,le=de,Ie=ce,me=-ce,ge=o*re;return _e(ne,ge,L,te,x,M,a,m,d,e.westSkirtHeight,g,r,n,ue,0),_e(ne,ge+=e.westIndices.length*re,q,te,x,M,a,m,d,e.southSkirtHeight,g,r,n,0,me),_e(ne,ge+=e.southIndices.length*re,j,te,x,M,a,m,d,e.eastSkirtHeight,g,r,n,le,0),_e(ne,ge+=e.eastIndices.length*re,Q,te,x,M,a,m,d,e.northSkirtHeight,g,r,n,0,Ie),xe.addSkirtIndices(L,q,j,Q,o,he,e.indices.length),t.push(ne.buffer,he.buffer),{vertices:ne.buffer,indices:he.buffer,westIndicesSouthToNorth:L,southIndicesEastToWest:q,eastIndicesNorthToSouth:j,northIndicesWestToEast:Q,vertexStride:re,center:E,minimumHeight:T,maximumHeight:p,boundingSphere:z,orientedBoundingBox:R,occludeePointInScaledSpace:U,encoding:te,indexCountWithoutSkirts:e.indices.length}})});