upsampleQuantizedTerrainMesh.js 8.1 KB

1
  1. define(["./AttributeCompression-1f045b73","./Transforms-d5c6ad6e","./Matrix2-ccd5b911","./when-4bbc8319","./TerrainEncoding-bccee540","./IndexDatatype-b7d979a6","./RuntimeError-346a3079","./ComponentDatatype-93750d1a","./OrientedBoundingBox-0a826a8b","./createTaskProcessorWorker","./combine-83860057","./WebGLConstants-1c8239cc","./EllipsoidTangentPlane-e000bae1","./AxisAlignedBoundingBox-883f9c89","./IntersectionTests-4d6f5c54","./Plane-18bb00f8"],function(s,ue,oe,g,ae,pe,e,de,le,t,i,n,r,h,u,o){"use strict";var fe={clipTriangleAtAxisAlignedThreshold:function(e,t,i,n,s,r){var h,u;g.defined(r)?r.length=0:r=[];var o,a,p,d,l,f,c=t?(h=i<e,u=n<e,s<e):(h=e<i,u=e<n,e<s),t=h+u+c;return 1===t?h?(o=(e-i)/(n-i),a=(e-i)/(s-i),r.push(1),r.push(2),1!==a&&(r.push(-1),r.push(0),r.push(2),r.push(a)),1!==o&&(r.push(-1),r.push(0),r.push(1),r.push(o))):u?(p=(e-n)/(s-n),d=(e-n)/(i-n),r.push(2),r.push(0),1!==d&&(r.push(-1),r.push(1),r.push(0),r.push(d)),1!==p&&(r.push(-1),r.push(1),r.push(2),r.push(p))):c&&(l=(e-s)/(i-s),f=(e-s)/(n-s),r.push(0),r.push(1),1!==f&&(r.push(-1),r.push(2),r.push(1),r.push(f)),1!==l&&(r.push(-1),r.push(2),r.push(0),r.push(l))):2===t?h||i===e?u||n===e?c||s===e||(a=(e-i)/(s-i),p=(e-n)/(s-n),r.push(2),r.push(-1),r.push(0),r.push(2),r.push(a),r.push(-1),r.push(1),r.push(2),r.push(p)):(f=(e-s)/(n-s),o=(e-i)/(n-i),r.push(1),r.push(-1),r.push(2),r.push(1),r.push(f),r.push(-1),r.push(0),r.push(1),r.push(o)):(d=(e-n)/(i-n),l=(e-s)/(i-s),r.push(0),r.push(-1),r.push(1),r.push(0),r.push(d),r.push(-1),r.push(2),r.push(0),r.push(l)):3!==t&&(r.push(0),r.push(1),r.push(2)),r},computeBarycentricCoordinates:function(e,t,i,n,s,r,h,u,o){var a=i-h,i=h-s,s=r-u,r=n-u,n=1/(s*a+i*r),u=t-u,h=e-h,i=(s*h+i*u)*n,u=(-r*h+a*u)*n,n=1-i-u;return g.defined(o)?(o.x=i,o.y=u,o.z=n,o):new oe.Cartesian3(i,u,n)},computeLineSegmentLineSegmentIntersection:function(e,t,i,n,s,r,h,u,o){var a=(h-s)*(t-r)-(u-r)*(e-s),p=(i-e)*(t-r)-(n-t)*(e-s),s=(u-r)*(i-e)-(h-s)*(n-t);if(0!=s){a=a/s,s=p/s;return 0<=a&&a<=1&&0<=s&&s<=1?((o=!g.defined(o)?new oe.Cartesian2:o).x=e+a*(i-e),o.y=t+a*(n-t),o):void 0}}},ce=32767,ge=16383,me=[],xe=[],we=[],ve=new oe.Cartographic,Ce=new oe.Cartesian3,Be=[],ye=[],be=[],Ie=[],Ae=[],Te=new oe.Cartesian3,ze=new ue.BoundingSphere,Me=new le.OrientedBoundingBox,Ne=new oe.Cartesian2,Ve=new oe.Cartesian3;function Ee(){this.vertexBuffer=void 0,this.index=void 0,this.first=void 0,this.second=void 0,this.ratio=void 0}Ee.prototype.clone=function(e){return(e=!g.defined(e)?new Ee:e).uBuffer=this.uBuffer,e.vBuffer=this.vBuffer,e.heightBuffer=this.heightBuffer,e.normalBuffer=this.normalBuffer,e.index=this.index,e.first=this.first,e.second=this.second,e.ratio=this.ratio,e},Ee.prototype.initializeIndexed=function(e,t,i,n,s){this.uBuffer=e,this.vBuffer=t,this.heightBuffer=i,this.normalBuffer=n,this.index=s,this.first=void 0,this.second=void 0,this.ratio=void 0},Ee.prototype.initializeFromClipResult=function(e,t,i){var n=t+1;return-1!==e[t]?i[e[t]].clone(this):(this.vertexBuffer=void 0,this.index=void 0,this.first=i[e[n]],this.second=i[e[++n]],this.ratio=e[++n],++n),n},Ee.prototype.getKey=function(){return this.isIndexed()?this.index:JSON.stringify({first:this.first.getKey(),second:this.second.getKey(),ratio:this.ratio})},Ee.prototype.isIndexed=function(){return g.defined(this.index)},Ee.prototype.getH=function(){return g.defined(this.index)?this.heightBuffer[this.index]:de.CesiumMath.lerp(this.first.getH(),this.second.getH(),this.ratio)},Ee.prototype.getU=function(){return g.defined(this.index)?this.uBuffer[this.index]:de.CesiumMath.lerp(this.first.getU(),this.second.getU(),this.ratio)},Ee.prototype.getV=function(){return g.defined(this.index)?this.vBuffer[this.index]:de.CesiumMath.lerp(this.first.getV(),this.second.getV(),this.ratio)};var a=new oe.Cartesian2,p=-1,d=[new oe.Cartesian3,new oe.Cartesian3],l=[new oe.Cartesian3,new oe.Cartesian3];function f(e,t){var i=d[++p],n=l[p],i=s.AttributeCompression.octDecode(e.first.getNormalX(),e.first.getNormalY(),i),n=s.AttributeCompression.octDecode(e.second.getNormalX(),e.second.getNormalY(),n);return Ce=oe.Cartesian3.lerp(i,n,e.ratio,Ce),oe.Cartesian3.normalize(Ce,Ce),s.AttributeCompression.octEncode(Ce,t),--p,t}Ee.prototype.getNormalX=function(){return g.defined(this.index)?this.normalBuffer[2*this.index]:(a=f(this,a)).x},Ee.prototype.getNormalY=function(){return g.defined(this.index)?this.normalBuffer[2*this.index+1]:(a=f(this,a)).y};var m=[];function Re(e,t,i,n,s,r,h,u,o){if(0!==h.length){for(var a=0,p=0;p<h.length;)p=m[a++].initializeFromClipResult(h,p,u);for(var d=0;d<a;++d){var l,f,c=m[d];c.isIndexed()?(c.newIndex=r[c.index],c.uBuffer=e,c.vBuffer=t,c.heightBuffer=i,o&&(c.normalBuffer=n)):(l=c.getKey(),g.defined(r[l])?c.newIndex=r[l]:(f=e.length,e.push(c.getU()),t.push(c.getV()),i.push(c.getH()),o&&(n.push(c.getNormalX()),n.push(c.getNormalY())),c.newIndex=f,r[l]=f))}3===a?(s.push(m[0].newIndex),s.push(m[1].newIndex),s.push(m[2].newIndex)):4===a&&(s.push(m[0].newIndex),s.push(m[1].newIndex),s.push(m[2].newIndex),s.push(m[0].newIndex),s.push(m[2].newIndex),s.push(m[3].newIndex))}}return m.push(new Ee),m.push(new Ee),m.push(new Ee),m.push(new Ee),t(function(e,t){var i=e.isEastChild,n=e.isNorthChild,s=i?ge:0,r=i?ce:ge,h=n?ge:0,u=n?ce:ge,o=Be,a=ye,p=be,d=Ae;o.length=0,a.length=0,p.length=0,d.length=0;var l=Ie;l.length=0;for(var f={},c=e.vertices,g=(g=e.indices).subarray(0,e.indexCountWithoutSkirts),m=ae.TerrainEncoding.clone(e.encoding),x=m.hasVertexNormals,w=0,v=e.vertexCountWithoutSkirts,C=e.minimumHeight,B=e.maximumHeight,y=new Array(v),b=new Array(v),I=new Array(v),A=x?new Array(2*v):void 0,T=0,z=0;T<v;++T,z+=2){var M=m.decodeTextureCoordinates(c,T,Ne),N=m.decodeHeight(c,T),V=de.CesiumMath.clamp(M.x*ce|0,0,ce),E=de.CesiumMath.clamp(M.y*ce|0,0,ce);I[T]=de.CesiumMath.clamp((N-C)/(B-C)*ce|0,0,ce),ce-(V=V<20?0:V)<20&&(V=ce),ce-(E=E<20?0:E)<20&&(E=ce),y[T]=V,b[T]=E,x&&(M=m.getOctEncodedNormal(c,T,Ve),A[z]=M.x,A[z+1]=M.y),(i&&ge<=V||!i&&V<=ge)&&(n&&ge<=E||!n&&E<=ge)&&(f[T]=w,o.push(V),a.push(E),p.push(I[T]),x&&(d.push(A[z]),d.push(A[z+1])),++w)}var R=[];R.push(new Ee),R.push(new Ee),R.push(new Ee);var H=[];for(H.push(new Ee),H.push(new Ee),H.push(new Ee),T=0;T<g.length;T+=3){var O=g[T],S=g[T+1],U=g[T+2],F=y[O],P=y[S],D=y[U];R[0].initializeIndexed(y,b,I,A,O),R[1].initializeIndexed(y,b,I,A,S),R[2].initializeIndexed(y,b,I,A,U);P=fe.clipTriangleAtAxisAlignedThreshold(ge,i,F,P,D,me);P.length<=0||(D=H[0].initializeFromClipResult(P,0,R))>=P.length||(D=H[1].initializeFromClipResult(P,D,R))>=P.length||(D=H[2].initializeFromClipResult(P,D,R),Re(o,a,p,d,l,f,fe.clipTriangleAtAxisAlignedThreshold(ge,n,H[0].getV(),H[1].getV(),H[2].getV(),xe),H,x),D<P.length&&(H[2].clone(H[1]),H[2].initializeFromClipResult(P,D,R),Re(o,a,p,d,l,f,fe.clipTriangleAtAxisAlignedThreshold(ge,n,H[0].getV(),H[1].getV(),H[2].getV(),xe),H,x)))}var W=i?-ce:0,X=n?-ce:0,k=[],K=[],L=[],Y=[],_=Number.MAX_VALUE,G=-_,J=we;J.length=0;var Z=oe.Ellipsoid.clone(e.ellipsoid),j=(he=oe.Rectangle.clone(e.childRectangle)).north,q=he.south,Q=he.east,$=he.west;for(Q<$&&(Q+=de.CesiumMath.TWO_PI),T=0;T<o.length;++T)V=(V=Math.round(o[T]))<=s?(k.push(T),0):r<=V?(L.push(T),ce):2*V+W,o[T]=V,E=(E=Math.round(a[T]))<=h?(K.push(T),0):u<=E?(Y.push(T),ce):2*E+X,a[T]=E,(N=de.CesiumMath.lerp(C,B,p[T]/ce))<_&&(_=N),G<N&&(G=N),p[T]=N,ve.longitude=de.CesiumMath.lerp($,Q,V/ce),ve.latitude=de.CesiumMath.lerp(q,j,E/ce),ve.height=N,Z.cartographicToCartesian(ve,Ce),J.push(Ce.x),J.push(Ce.y),J.push(Ce.z);var ee=ue.BoundingSphere.fromVertices(J,oe.Cartesian3.ZERO,3,ze),te=le.OrientedBoundingBox.fromRectangle(he,_,G,Z,Me),e=new ae.EllipsoidalOccluder(Z).computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid(ee.center,J,3,ee.center,_,Te),ie=G-_,ne=new Uint16Array(o.length+a.length+p.length);for(T=0;T<o.length;++T)ne[T]=o[T];var se=o.length;for(T=0;T<a.length;++T)ne[se+T]=a[T];for(se+=a.length,T=0;T<p.length;++T)ne[se+T]=ce*(p[T]-_)/ie;var re,he=pe.IndexDatatype.createTypedArray(o.length,l);return x?(re=new Uint8Array(d),t.push(ne.buffer,he.buffer,re.buffer),re=re.buffer):t.push(ne.buffer,he.buffer),{vertices:ne.buffer,encodedNormals:re,indices:he.buffer,minimumHeight:_,maximumHeight:G,westIndices:k,southIndices:K,eastIndices:L,northIndices:Y,boundingSphere:ee,orientedBoundingBox:te,horizonOcclusionPoint:e}})});