upsampleQuantizedTerrainMesh.js 9.4 KB

1
  1. define(["./AttributeCompression-49f7b62a","./buildModuleUrl-3d15f25c","./Cartesian2-6033fa5d","./Cartographic-67e73ef9","./when-92c6cf3c","./Rectangle-bab7abf0","./TerrainEncoding-5d55ad09","./IndexDatatype-4c0e98b8","./Check-52a7d806","./Math-92c3b5f7","./OrientedBoundingBox-513cf61d","./createTaskProcessorWorker","./Intersect-b97e930a","./PrimitiveType-cdfe443e","./Cartesian4-ad128b5d","./RuntimeError-c6a62a80","./WebGLConstants-71f10989","./Event-3390cd7d","./ComponentDatatype-81047f82","./EllipsoidTangentPlane-53184efd","./IntersectionTests-a42760d9","./Plane-f8d22530","./GeometryAttribute-ef657318","./FeatureDetection-067cb23c","./PolygonPipeline-b86e8785","./WindingOrder-1b9c8a87","./EllipsoidRhumbLine-8847d1a1","./Buffer-1d0f8963","./RenderState-94064c70","./BoundingRectangle-418864a2","./Color-45274500"],(function(e,t,i,n,r,s,h,u,o,p,d,a,f,l,c,g,m,x,w,v,y,b,B,I,A,C,H,T,O,z,N){"use strict";var R={clipTriangleAtAxisAlignedThreshold:function(e,t,i,n,s,h){if(!r.e(e))throw new o.t("threshold is required.");if(!r.e(t))throw new o.t("keepAbove is required.");if(!r.e(i))throw new o.t("u0 is required.");if(!r.e(n))throw new o.t("u1 is required.");if(!r.e(s))throw new o.t("u2 is required.");var u,p,d;r.e(h)?h.length=0:h=[],t?(u=i<e,p=n<e,d=s<e):(u=i>e,p=n>e,d=s>e);var a,f,l,c,g,m,x=u+p+d;return 1===x?u?(a=(e-i)/(n-i),f=(e-i)/(s-i),h.push(1),h.push(2),1!==f&&(h.push(-1),h.push(0),h.push(2),h.push(f)),1!==a&&(h.push(-1),h.push(0),h.push(1),h.push(a))):p?(l=(e-n)/(s-n),c=(e-n)/(i-n),h.push(2),h.push(0),1!==c&&(h.push(-1),h.push(1),h.push(0),h.push(c)),1!==l&&(h.push(-1),h.push(1),h.push(2),h.push(l))):d&&(g=(e-s)/(i-s),m=(e-s)/(n-s),h.push(0),h.push(1),1!==m&&(h.push(-1),h.push(2),h.push(1),h.push(m)),1!==g&&(h.push(-1),h.push(2),h.push(0),h.push(g))):2===x?u||i===e?p||n===e?!d&&s!==e&&(f=(e-i)/(s-i),l=(e-n)/(s-n),h.push(2),h.push(-1),h.push(0),h.push(2),h.push(f),h.push(-1),h.push(1),h.push(2),h.push(l)):(m=(e-s)/(n-s),a=(e-i)/(n-i),h.push(1),h.push(-1),h.push(2),h.push(1),h.push(m),h.push(-1),h.push(0),h.push(1),h.push(a)):(c=(e-n)/(i-n),g=(e-s)/(i-s),h.push(0),h.push(-1),h.push(1),h.push(0),h.push(c),h.push(-1),h.push(2),h.push(0),h.push(g)):3!==x&&(h.push(0),h.push(1),h.push(2)),h},computeBarycentricCoordinates:function(e,t,i,s,h,u,p,d,a){if(!r.e(e))throw new o.t("x is required.");if(!r.e(t))throw new o.t("y is required.");if(!r.e(i))throw new o.t("x1 is required.");if(!r.e(s))throw new o.t("y1 is required.");if(!r.e(h))throw new o.t("x2 is required.");if(!r.e(u))throw new o.t("y2 is required.");if(!r.e(p))throw new o.t("x3 is required.");if(!r.e(d))throw new o.t("y3 is required.");var f=i-p,l=p-h,c=u-d,g=s-d,m=1/(c*f+l*g),x=t-d,w=e-p,v=(c*w+l*x)*m,y=(-g*w+f*x)*m,b=1-v-y;return r.e(a)?(a.x=v,a.y=y,a.z=b,a):new n.t(v,y,b)},computeLineSegmentLineSegmentIntersection:function(e,t,n,s,h,u,p,d,a){o.o.typeOf.number("x00",e),o.o.typeOf.number("y00",t),o.o.typeOf.number("x01",n),o.o.typeOf.number("y01",s),o.o.typeOf.number("x10",h),o.o.typeOf.number("y10",u),o.o.typeOf.number("x11",p),o.o.typeOf.number("y11",d);var f=(d-u)*(n-e)-(p-h)*(s-t);if(0!==f){var l=((p-h)*(t-u)-(d-u)*(e-h))/f,c=((n-e)*(t-u)-(s-t)*(e-h))/f;if(l>=0&&l<=1&&c>=0&&c<=1)return r.e(a)||(a=new i.o),a.x=e+l*(n-e),a.y=t+l*(s-t),a}}},V=32767,q=16383,E=[],M=[],P=[],U=new n.t$1,F=new n.t,S=[],k=[],D=[],L=[],W=[],X=new n.t,K=new t.i,Y=new d.x,_=new i.o,G=new n.t;function J(){this.vertexBuffer=void 0,this.index=void 0,this.first=void 0,this.second=void 0,this.ratio=void 0}J.prototype.clone=function(e){return r.e(e)||(e=new J),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},J.prototype.initializeIndexed=function(e,t,i,n,r){this.uBuffer=e,this.vBuffer=t,this.heightBuffer=i,this.normalBuffer=n,this.index=r,this.first=void 0,this.second=void 0,this.ratio=void 0},J.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]],++n,this.second=i[e[n]],++n,this.ratio=e[n],++n),n},J.prototype.getKey=function(){return this.isIndexed()?this.index:JSON.stringify({first:this.first.getKey(),second:this.second.getKey(),ratio:this.ratio})},J.prototype.isIndexed=function(){return r.e(this.index)},J.prototype.getH=function(e,t){if(r.e(this.index))return this.heightBuffer[this.index];var i=this.first.getH(e,t),n=this.second.getH(e,t);return 0===t+i/V*e||0===t+n/V*e?0:p.e.lerp(this.first.getH(),this.second.getH(),this.ratio)},J.prototype.getU=function(){return r.e(this.index)?this.uBuffer[this.index]:p.e.lerp(this.first.getU(),this.second.getU(),this.ratio)},J.prototype.getV=function(){return r.e(this.index)?this.vBuffer[this.index]:p.e.lerp(this.first.getV(),this.second.getV(),this.ratio)};var Z=new i.o,$=-1,j=[new n.t,new n.t],Q=[new n.t,new n.t];function ee(t,i){++$;var r=j[$],s=Q[$];return r=e.t.octDecode(t.first.getNormalX(),t.first.getNormalY(),r),s=e.t.octDecode(t.second.getNormalX(),t.second.getNormalY(),s),F=n.t.lerp(r,s,t.ratio,F),n.t.normalize(F,F),e.t.octEncode(F,i),--$,i}J.prototype.getNormalX=function(){return r.e(this.index)?this.normalBuffer[2*this.index]:(Z=ee(this,Z)).x},J.prototype.getNormalY=function(){return r.e(this.index)?this.normalBuffer[2*this.index+1]:(Z=ee(this,Z)).y};var te=[];function ie(e,t,i,n,s,h,u,o,p,d,a){if(0!==u.length){for(var f=0,l=0;l<u.length;)l=te[f++].initializeFromClipResult(u,l,o);for(var c=0;c<f;++c){var g=te[c];if(g.isIndexed())g.newIndex=h[g.index],g.uBuffer=e,g.vBuffer=t,g.heightBuffer=i,p&&(g.normalBuffer=n);else{var m=g.getKey();if(r.e(h[m]))g.newIndex=h[m];else{var x=e.length;e.push(g.getU()),t.push(g.getV()),i.push(g.getH(d,a)),p&&(n.push(g.getNormalX()),n.push(g.getNormalY())),g.newIndex=x,h[m]=x}}}3===f?(s.push(te[0].newIndex),s.push(te[1].newIndex),s.push(te[2].newIndex)):4===f&&(s.push(te[0].newIndex),s.push(te[1].newIndex),s.push(te[2].newIndex),s.push(te[0].newIndex),s.push(te[2].newIndex),s.push(te[3].newIndex))}}return te.push(new J),te.push(new J),te.push(new J),te.push(new J),a((function(e,i){var o=e.isEastChild,a=e.isNorthChild,f=o?q:0,l=o?V:q,c=a?q:0,g=a?V:q,m=S,x=k,w=D,v=W;m.length=0,x.length=0,w.length=0,v.length=0;var y=L;y.length=0;var b={},B=e.vertices,I=e.indices;I=I.subarray(0,e.indexCountWithoutSkirts);var A,C,H,T,O,z=h.h.clone(e.encoding),N=z.hasVertexNormals,Z=e.exaggeration,$=0,j=e.vertexCountWithoutSkirts,Q=e.minimumHeight,ee=e.maximumHeight,te=r.e(e.validMinimumHeight)?e.validMinimumHeight:e.minimumHeight,ne=r.e(e.validMaximumHeight)?e.validMaximumHeight:e.maximumHeight,re=new Array(j),se=new Array(j),he=new Array(j),ue=N?new Array(2*j):void 0;for(C=0,H=0;C<j;++C,H+=2){var oe=z.decodeTextureCoordinates(B,C,_);if(A=z.decodeHeight(B,C)/Z,T=p.e.clamp(oe.x*V|0,0,V),O=p.e.clamp(oe.y*V|0,0,V),he[C]=p.e.clamp((A-Q)/(ee-Q)*V|0,0,V),T<20&&(T=0),O<20&&(O=0),V-T<20&&(T=V),V-O<20&&(O=V),re[C]=T,se[C]=O,N){var pe=z.getOctEncodedNormal(B,C,G);ue[H]=pe.x,ue[H+1]=pe.y}(o&&T>=q||!o&&T<=q)&&(a&&O>=q||!a&&O<=q)&&(b[C]=$,m.push(T),x.push(O),w.push(he[C]),N&&(v.push(ue[H]),v.push(ue[H+1])),++$)}var de=[];de.push(new J),de.push(new J),de.push(new J);var ae,fe=[];for(fe.push(new J),fe.push(new J),fe.push(new J),C=0;C<I.length;C+=3){var le=I[C],ce=I[C+1],ge=I[C+2],me=re[le],xe=re[ce],we=re[ge];de[0].initializeIndexed(re,se,he,ue,le),de[1].initializeIndexed(re,se,he,ue,ce),de[2].initializeIndexed(re,se,he,ue,ge);var ve=R.clipTriangleAtAxisAlignedThreshold(q,o,me,xe,we,E);(ae=0)>=ve.length||((ae=fe[0].initializeFromClipResult(ve,ae,de))>=ve.length||(ae=fe[1].initializeFromClipResult(ve,ae,de))>=ve.length||(ae=fe[2].initializeFromClipResult(ve,ae,de),ie(m,x,w,v,y,b,R.clipTriangleAtAxisAlignedThreshold(q,a,fe[0].getV(),fe[1].getV(),fe[2].getV(),M),fe,N,ee,Q),ae<ve.length&&(fe[2].clone(fe[1]),fe[2].initializeFromClipResult(ve,ae,de),ie(m,x,w,v,y,b,R.clipTriangleAtAxisAlignedThreshold(q,a,fe[0].getV(),fe[1].getV(),fe[2].getV(),M),fe,N,ee,Q))))}var ye=o?-32767:0,be=a?-32767:0,Be=[],Ie=[],Ae=[],Ce=[],He=Number.MAX_VALUE,Te=-He,Oe=Number.MAX_VALUE,ze=-He,Ne=P;Ne.length=0;var Re=s.t.clone(e.ellipsoid),Ve=s.h.clone(e.childRectangle),qe=Ve.north,Ee=Ve.south,Me=Ve.east,Pe=Ve.west;for(Me<Pe&&(Me+=p.e.TWO_PI),C=0;C<m.length;++C){(T=Math.round(m[C]))<=f?(Be.push(C),T=0):T>=l?(Ae.push(C),T=V):T=2*T+ye,m[C]=T,(O=Math.round(x[C]))<=c?(Ie.push(C),O=0):O>=g?(Ce.push(C),O=V):O=2*O+be,x[C]=O,(A=p.e.lerp(Q,ee,w[C]/V))<He&&(He=A),A>Te&&(Te=A);var Ue=A;(Ue=p.e.clamp(Ue,te,ne))<Oe&&(Oe=Ue),Ue>ze&&(ze=Ue),w[C]=A,U.longitude=p.e.lerp(Pe,Me,T/V),U.latitude=p.e.lerp(Ee,qe,O/V),U.height=A,Re.cartographicToCartesian(U,F),Ne.push(F.x),Ne.push(F.y),Ne.push(F.z)}var Fe=t.i.fromVertices(Ne,n.t.ZERO,3,K),Se=d.x.fromRectangle(Ve,He,Te,Re,Y),ke=d.x.fromRectangle(Ve,Oe,ze,Re,Y),De=new h.s(Re).computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid(Fe.center,Ne,3,Fe.center,He,X),Le=Te-He,We=new Uint16Array(m.length+x.length+w.length);for(C=0;C<m.length;++C)We[C]=m[C];var Xe=m.length;for(C=0;C<x.length;++C)We[Xe+C]=x[C];for(Xe+=x.length,C=0;C<w.length;++C)We[Xe+C]=V*(w[C]-He)/Le;var Ke,Ye=u.IndexDatatype.createTypedArray(m.length,y);if(N){var _e=new Uint8Array(v);i.push(We.buffer,Ye.buffer,_e.buffer),Ke=_e.buffer}else i.push(We.buffer,Ye.buffer);return{vertices:We.buffer,encodedNormals:Ke,indices:Ye.buffer,minimumHeight:He,maximumHeight:Te,westIndices:Be,southIndices:Ie,eastIndices:Ae,northIndices:Ce,boundingSphere:Fe,orientedBoundingBox:Se,horizonOcclusionPoint:De,validMinimumHeight:Oe,validMaximumHeight:ze,validOrientedBoundingBox:ke}}))}));