TerrainEncoding-ea407edd.js 11 KB

1
  1. define(["exports","./Transforms-99272364","./Cartesian3-7e9cc2ff","./Check-741c5f3c","./defaultValue-81eec7ed","./Matrix2-e3fb4559","./AttributeCompression-e2e3f0dd","./ComponentDatatype-aaeec80f","./Math-5f585871","./Matrix4-d34187af"],(function(t,e,i,o,a,r,n,s,c,d){"use strict";function u(t,e){this._ellipsoid=t,this._cameraPosition=new i.Cartesian3,this._cameraPositionInScaledSpace=new i.Cartesian3,this._distanceToLimbInScaledSpaceSquared=0,a.defined(e)&&(this.cameraPosition=e)}Object.defineProperties(u.prototype,{ellipsoid:{get:function(){return this._ellipsoid}},cameraPosition:{get:function(){return this._cameraPosition},set:function(t){const e=this._ellipsoid.transformPositionToScaledSpace(t,this._cameraPositionInScaledSpace),o=i.Cartesian3.magnitudeSquared(e)-1;i.Cartesian3.clone(t,this._cameraPosition),this._cameraPositionInScaledSpace=e,this._distanceToLimbInScaledSpaceSquared=o}}});const l=new i.Cartesian3;u.prototype.isPointVisible=function(t){return y(this._ellipsoid.transformPositionToScaledSpace(t,l),this._cameraPositionInScaledSpace,this._distanceToLimbInScaledSpaceSquared)},u.prototype.isScaledSpacePointVisible=function(t){return y(t,this._cameraPositionInScaledSpace,this._distanceToLimbInScaledSpaceSquared)};const m=new i.Cartesian3;u.prototype.isScaledSpacePointVisiblePossiblyUnderEllipsoid=function(t,e){const i=this._ellipsoid;let o,r;return a.defined(e)&&e<0&&i.minimumRadius>-e?(r=m,r.x=this._cameraPosition.x/(i.radii.x+e),r.y=this._cameraPosition.y/(i.radii.y+e),r.z=this._cameraPosition.z/(i.radii.z+e),o=r.x*r.x+r.y*r.y+r.z*r.z-1):(r=this._cameraPositionInScaledSpace,o=this._distanceToLimbInScaledSpaceSquared),y(t,r,o)},u.prototype.computeHorizonCullingPoint=function(t,e,i){return S(this._ellipsoid,t,e,i)};const h=r.Ellipsoid.clone(r.Ellipsoid.UNIT_SPHERE);u.prototype.computeHorizonCullingPointPossiblyUnderEllipsoid=function(t,e,i,o){return S(x(this._ellipsoid,i,h),t,e,o)},u.prototype.computeHorizonCullingPointFromVertices=function(t,e,i,o,a){return g(this._ellipsoid,t,e,i,o,a)},u.prototype.computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid=function(t,e,i,o,a,r){return g(x(this._ellipsoid,a,h),t,e,i,o,r)};const f=[];u.prototype.computeHorizonCullingPointFromRectangle=function(t,o,a){const n=r.Rectangle.subsample(t,o,0,f),s=e.BoundingSphere.fromPoints(n);if(!(i.Cartesian3.magnitude(s.center)<.1*o.minimumRadius))return this.computeHorizonCullingPoint(s.center,n,a)};const p=new i.Cartesian3;function x(t,e,o){if(a.defined(e)&&e<0&&t.minimumRadius>-e){const a=i.Cartesian3.fromElements(t.radii.x+e,t.radii.y+e,t.radii.z+e,p);t=r.Ellipsoid.fromCartesian3(a,o)}return t}function S(t,e,o,r){a.defined(r)||(r=new i.Cartesian3);const n=z(t,e);let s=0;for(let e=0,i=o.length;e<i;++e){const i=T(t,o[e],n);if(i<0)return;s=Math.max(s,i)}return b(n,s,r)}const C=new i.Cartesian3;function g(t,e,o,r,n,s){a.defined(s)||(s=new i.Cartesian3),r=a.defaultValue(r,3),n=a.defaultValue(n,i.Cartesian3.ZERO);const c=z(t,e);let d=0;for(let e=0,i=o.length;e<i;e+=r){C.x=o[e]+n.x,C.y=o[e+1]+n.y,C.z=o[e+2]+n.z;const i=T(t,C,c);if(i<0)return;d=Math.max(d,i)}return b(c,d,s)}function y(t,e,o){const a=e,r=o,n=i.Cartesian3.subtract(t,a,l),s=-i.Cartesian3.dot(n,a);return!(r<0?s>0:s>r&&s*s/i.Cartesian3.magnitudeSquared(n)>r)}const N=new i.Cartesian3,M=new i.Cartesian3;function T(t,e,o){const a=t.transformPositionToScaledSpace(e,N);let r=i.Cartesian3.magnitudeSquared(a),n=Math.sqrt(r);const s=i.Cartesian3.divideByScalar(a,n,M);r=Math.max(1,r),n=Math.max(1,n);const c=1/n;return 1/(i.Cartesian3.dot(s,o)*c-i.Cartesian3.magnitude(i.Cartesian3.cross(s,o,s))*(Math.sqrt(r-1)*c))}function b(t,e,o){if(!(e<=0||e===1/0||e!=e))return i.Cartesian3.multiplyByScalar(t,e,o)}const P=new i.Cartesian3;function z(t,e){return i.Cartesian3.equals(e,i.Cartesian3.ZERO)?e:(t.transformPositionToScaledSpace(e,P),i.Cartesian3.normalize(P,P))}const _={getHeight:function(t,e,i){return(t-i)*e+i}},E=new i.Cartesian3;_.getPosition=function(t,e,o,a,r){const n=e.cartesianToCartographic(t,E),s=_.getHeight(n.height,o,a);return i.Cartesian3.fromRadians(n.longitude,n.latitude,s,e,r)};var H=Object.freeze({NONE:0,BITS12:1});const w=new i.Cartesian3,A=new i.Cartesian3,I=new r.Cartesian2,V=new d.Matrix4,q=new d.Matrix4,G=Math.pow(2,12);function O(t,e,o,r,n,s,c,u,l,m){let h,f,p=H.NONE;if(a.defined(e)&&a.defined(o)&&a.defined(r)&&a.defined(n)){const t=e.minimum,a=e.maximum,s=i.Cartesian3.subtract(a,t,A),c=r-o;p=Math.max(i.Cartesian3.maximumComponent(s),c)<G-1?H.BITS12:H.NONE,h=d.Matrix4.inverseTransformation(n,new d.Matrix4);const u=i.Cartesian3.negate(t,w);d.Matrix4.multiply(d.Matrix4.fromTranslation(u,V),h,h);const l=w;l.x=1/s.x,l.y=1/s.y,l.z=1/s.z,d.Matrix4.multiply(d.Matrix4.fromScale(l,V),h,h),f=d.Matrix4.clone(n),d.Matrix4.setTranslation(f,i.Cartesian3.ZERO,f),n=d.Matrix4.clone(n,new d.Matrix4);const m=d.Matrix4.fromTranslation(t,V),x=d.Matrix4.fromScale(s,q),S=d.Matrix4.multiply(m,x,V);d.Matrix4.multiply(n,S,n),d.Matrix4.multiply(f,S,f)}this.quantization=p,this.minimumHeight=o,this.maximumHeight=r,this.center=i.Cartesian3.clone(t),this.toScaledENU=h,this.fromScaledENU=n,this.matrix=f,this.hasVertexNormals=s,this.hasWebMercatorT=a.defaultValue(c,!1),this.hasGeodeticSurfaceNormals=a.defaultValue(u,!1),this.exaggeration=a.defaultValue(l,1),this.exaggerationRelativeHeight=a.defaultValue(m,0),this.stride=0,this._offsetGeodeticSurfaceNormal=0,this._offsetVertexNormal=0,this._calculateStrideAndOffsets()}O.prototype.encode=function(t,e,o,a,s,u,l,m){const h=a.x,f=a.y;if(this.quantization===H.BITS12){(o=d.Matrix4.multiplyByPoint(this.toScaledENU,o,w)).x=c.CesiumMath.clamp(o.x,0,1),o.y=c.CesiumMath.clamp(o.y,0,1),o.z=c.CesiumMath.clamp(o.z,0,1);const i=this.maximumHeight-this.minimumHeight,a=c.CesiumMath.clamp((s-this.minimumHeight)/i,0,1);r.Cartesian2.fromElements(o.x,o.y,I);const u=n.AttributeCompression.compressTextureCoordinates(I);r.Cartesian2.fromElements(o.z,a,I);const m=n.AttributeCompression.compressTextureCoordinates(I);r.Cartesian2.fromElements(h,f,I);const p=n.AttributeCompression.compressTextureCoordinates(I);if(t[e++]=u,t[e++]=m,t[e++]=p,this.hasWebMercatorT){r.Cartesian2.fromElements(l,0,I);const i=n.AttributeCompression.compressTextureCoordinates(I);t[e++]=i}}else i.Cartesian3.subtract(o,this.center,w),t[e++]=w.x,t[e++]=w.y,t[e++]=w.z,t[e++]=s,t[e++]=h,t[e++]=f,this.hasWebMercatorT&&(t[e++]=l);return this.hasVertexNormals&&(t[e++]=n.AttributeCompression.octPackFloat(u)),this.hasGeodeticSurfaceNormals&&(t[e++]=m.x,t[e++]=m.y,t[e++]=m.z),e};const B=new i.Cartesian3,R=new i.Cartesian3;O.prototype.addGeodeticSurfaceNormals=function(t,e,i){if(this.hasGeodeticSurfaceNormals)return;const o=this.stride,a=t.length/o;this.hasGeodeticSurfaceNormals=!0,this._calculateStrideAndOffsets();const r=this.stride;for(let n=0;n<a;n++){for(let i=0;i<o;i++){const a=n*o+i;e[n*r+i]=t[a]}const a=this.decodePosition(e,n,B),s=i.geodeticSurfaceNormal(a,R),c=n*r+this._offsetGeodeticSurfaceNormal;e[c]=s.x,e[c+1]=s.y,e[c+2]=s.z}},O.prototype.removeGeodeticSurfaceNormals=function(t,e){if(!this.hasGeodeticSurfaceNormals)return;const i=this.stride,o=t.length/i;this.hasGeodeticSurfaceNormals=!1,this._calculateStrideAndOffsets();const a=this.stride;for(let r=0;r<o;r++)for(let o=0;o<a;o++){const n=r*i+o;e[r*a+o]=t[n]}},O.prototype.decodePosition=function(t,e,o){if(a.defined(o)||(o=new i.Cartesian3),e*=this.stride,this.quantization===H.BITS12){const i=n.AttributeCompression.decompressTextureCoordinates(t[e],I);o.x=i.x,o.y=i.y;const a=n.AttributeCompression.decompressTextureCoordinates(t[e+1],I);return o.z=a.x,d.Matrix4.multiplyByPoint(this.fromScaledENU,o,o)}return o.x=t[e],o.y=t[e+1],o.z=t[e+2],i.Cartesian3.add(o,this.center,o)},O.prototype.getExaggeratedPosition=function(t,e,i){i=this.decodePosition(t,e,i);const o=this.exaggeration,a=this.exaggerationRelativeHeight;if(1!==o&&this.hasGeodeticSurfaceNormals){const r=this.decodeGeodeticSurfaceNormal(t,e,R),n=this.decodeHeight(t,e),s=_.getHeight(n,o,a)-n;i.x+=r.x*s,i.y+=r.y*s,i.z+=r.z*s}return i},O.prototype.decodeTextureCoordinates=function(t,e,i){return a.defined(i)||(i=new r.Cartesian2),e*=this.stride,this.quantization===H.BITS12?n.AttributeCompression.decompressTextureCoordinates(t[e+2],i):r.Cartesian2.fromElements(t[e+4],t[e+5],i)},O.prototype.decodeHeight=function(t,e){if(e*=this.stride,this.quantization===H.BITS12){return n.AttributeCompression.decompressTextureCoordinates(t[e+1],I).y*(this.maximumHeight-this.minimumHeight)+this.minimumHeight}return t[e+3]},O.prototype.decodeWebMercatorT=function(t,e){return e*=this.stride,this.quantization===H.BITS12?n.AttributeCompression.decompressTextureCoordinates(t[e+3],I).x:t[e+6]},O.prototype.getOctEncodedNormal=function(t,e,i){const o=t[e=e*this.stride+this._offsetVertexNormal]/256,a=Math.floor(o),n=256*(o-a);return r.Cartesian2.fromElements(a,n,i)},O.prototype.decodeGeodeticSurfaceNormal=function(t,e,i){return e=e*this.stride+this._offsetGeodeticSurfaceNormal,i.x=t[e],i.y=t[e+1],i.z=t[e+2],i},O.prototype._calculateStrideAndOffsets=function(){let t=0;if(this.quantization===H.BITS12)t+=3;else t+=6;this.hasWebMercatorT&&(t+=1),this.hasVertexNormals&&(this._offsetVertexNormal=t,t+=1),this.hasGeodeticSurfaceNormals&&(this._offsetGeodeticSurfaceNormal=t,t+=3),this.stride=t};const U={position3DAndHeight:0,textureCoordAndEncodedNormals:1,geodeticSurfaceNormal:2},W={compressed0:0,compressed1:1,geodeticSurfaceNormal:2};O.prototype.getAttributes=function(t){const e=s.ComponentDatatype.FLOAT,i=s.ComponentDatatype.getSizeInBytes(e),o=this.stride*i;let a=0;const r=[];function n(n,s){r.push({index:n,vertexBuffer:t,componentDatatype:e,componentsPerAttribute:s,offsetInBytes:a,strideInBytes:o}),a+=s*i}if(this.quantization===H.NONE){n(U.position3DAndHeight,4);let t=2;t+=this.hasWebMercatorT?1:0,t+=this.hasVertexNormals?1:0,n(U.textureCoordAndEncodedNormals,t),this.hasGeodeticSurfaceNormals&&n(U.geodeticSurfaceNormal,3)}else{const t=this.hasWebMercatorT||this.hasVertexNormals,e=this.hasWebMercatorT&&this.hasVertexNormals;n(W.compressed0,t?4:3),e&&n(W.compressed1,1),this.hasGeodeticSurfaceNormals&&n(W.geodeticSurfaceNormal,3)}return r},O.prototype.getAttributeLocations=function(){return this.quantization===H.NONE?U:W},O.clone=function(t,e){if(a.defined(t))return a.defined(e)||(e=new O),e.quantization=t.quantization,e.minimumHeight=t.minimumHeight,e.maximumHeight=t.maximumHeight,e.center=i.Cartesian3.clone(t.center),e.toScaledENU=d.Matrix4.clone(t.toScaledENU),e.fromScaledENU=d.Matrix4.clone(t.fromScaledENU),e.matrix=d.Matrix4.clone(t.matrix),e.hasVertexNormals=t.hasVertexNormals,e.hasWebMercatorT=t.hasWebMercatorT,e.hasGeodeticSurfaceNormals=t.hasGeodeticSurfaceNormals,e.exaggeration=t.exaggeration,e.exaggerationRelativeHeight=t.exaggerationRelativeHeight,e._calculateStrideAndOffsets(),e},t.EllipsoidalOccluder=u,t.TerrainEncoding=O}));