TerrainEncoding-0e08edec.js 8.5 KB

1
  1. define(["exports","./buildModuleUrl-8cce5713","./Cartesian4-b0ddc4ba","./Check-7b2a090c","./when-b60132fc","./AttributeCompression-399750a1","./FeatureDetection-ab6f364c","./Math-31e539c2"],(function(t,e,i,r,a,n,o,s){"use strict";function c(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(c.prototype,{ellipsoid:{get:function(){return this._ellipsoid}},cameraPosition:{get:function(){return this._cameraPosition},set:function(t){var e=this._ellipsoid.transformPositionToScaledSpace(t,this._cameraPositionInScaledSpace),r=i.Cartesian3.magnitudeSquared(e)-1;i.Cartesian3.clone(t,this._cameraPosition),this._cameraPositionInScaledSpace=e,this._distanceToLimbInScaledSpaceSquared=r}}});var m=new i.Cartesian3;c.prototype.isPointVisible=function(t){return S(this._ellipsoid.transformPositionToScaledSpace(t,m),this._cameraPositionInScaledSpace,this._distanceToLimbInScaledSpaceSquared)},c.prototype.isScaledSpacePointVisible=function(t){return S(t,this._cameraPositionInScaledSpace,this._distanceToLimbInScaledSpaceSquared)};var u=new i.Cartesian3;c.prototype.isScaledSpacePointVisiblePossiblyUnderEllipsoid=function(t,e){var i,r,n=this._ellipsoid;return a.defined(e)&&e<0&&n.minimumRadius>-e?((r=u).x=this._cameraPosition.x/(n.radii.x+e),r.y=this._cameraPosition.y/(n.radii.y+e),r.z=this._cameraPosition.z/(n.radii.z+e),i=r.x*r.x+r.y*r.y+r.z*r.z-1):(r=this._cameraPositionInScaledSpace,i=this._distanceToLimbInScaledSpaceSquared),S(t,r,i)},c.prototype.computeHorizonCullingPoint=function(t,e,i){return f(this._ellipsoid,t,e,i)};var d=e.Ellipsoid.clone(e.Ellipsoid.UNIT_SPHERE);c.prototype.computeHorizonCullingPointPossiblyUnderEllipsoid=function(t,e,i,r){return f(h(this._ellipsoid,i,d),t,e,r)},c.prototype.computeHorizonCullingPointFromVertices=function(t,e,i,r,a){return C(this._ellipsoid,t,e,i,r,a)},c.prototype.computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid=function(t,e,i,r,a,n){return C(h(this._ellipsoid,a,d),t,e,i,r,n)};var l=[];c.prototype.computeHorizonCullingPointFromRectangle=function(t,r,a){var n=e.Rectangle.subsample(t,r,0,l),o=e.BoundingSphere.fromPoints(n);if(!(i.Cartesian3.magnitude(o.center)<.1*r.minimumRadius))return this.computeHorizonCullingPoint(o.center,n,a)};var p=new i.Cartesian3;function h(t,r,n){if(a.defined(r)&&r<0&&t.minimumRadius>-r){var o=i.Cartesian3.fromElements(t.radii.x+r,t.radii.y+r,t.radii.z+r,p);t=e.Ellipsoid.fromCartesian3(o,n)}return t}function f(t,e,r,n){a.defined(n)||(n=new i.Cartesian3);for(var o=T(t,e),s=0,c=0,m=r.length;c<m;++c){var u=M(t,r[c],o);if(u<0)return;s=Math.max(s,u)}return v(o,s,n)}var x=new i.Cartesian3;function C(t,e,r,n,o,s){a.defined(s)||(s=new i.Cartesian3),n=a.defaultValue(n,3),o=a.defaultValue(o,i.Cartesian3.ZERO);for(var c=T(t,e),m=0,u=0,d=r.length;u<d;u+=n){x.x=r[u]+o.x,x.y=r[u+1]+o.y,x.z=r[u+2]+o.z;var l=M(t,x,c);if(l<0)return;m=Math.max(m,l)}return v(c,m,s)}function S(t,e,r){var a=e,n=r,o=i.Cartesian3.subtract(t,a,m),s=-i.Cartesian3.dot(o,a);return!(n<0?s>0:s>n&&s*s/i.Cartesian3.magnitudeSquared(o)>n)}var y=new i.Cartesian3,b=new i.Cartesian3;function M(t,e,r){var a=t.transformPositionToScaledSpace(e,y),n=i.Cartesian3.magnitudeSquared(a),o=Math.sqrt(n),s=i.Cartesian3.divideByScalar(a,o,b);n=Math.max(1,n);var c=1/(o=Math.max(1,o));return 1/(i.Cartesian3.dot(s,r)*c-i.Cartesian3.magnitude(i.Cartesian3.cross(s,r,s))*(Math.sqrt(n-1)*c))}function v(t,e,r){if(!(e<=0||e===1/0||e!=e))return i.Cartesian3.multiplyByScalar(t,e,r)}var g=new i.Cartesian3;function T(t,e){return i.Cartesian3.equals(e,i.Cartesian3.ZERO)?e:(t.transformPositionToScaledSpace(e,g),i.Cartesian3.normalize(g,g))}var P=Object.freeze({NONE:0,BITS12:1}),E=new i.Cartesian3,z=new i.Cartesian3,N=new e.Cartesian2,I=new e.Matrix4,B=new e.Matrix4,_=Math.pow(2,12);function w(t,r,n,o,s,c){var m,u,d,l=P.NONE;if(a.defined(t)&&a.defined(r)&&a.defined(n)&&a.defined(o)){var p=t.minimum,h=t.maximum,f=i.Cartesian3.subtract(h,p,z),x=n-r;l=Math.max(i.Cartesian3.maximumComponent(f),x)<_-1?P.BITS12:P.NONE,l=P.NONE,m=t.center,u=e.Matrix4.inverseTransformation(o,new e.Matrix4);var C=i.Cartesian3.negate(p,E);e.Matrix4.multiply(e.Matrix4.fromTranslation(C,I),u,u);var S=E;S.x=1/f.x,S.y=1/f.y,S.z=1/f.z,e.Matrix4.multiply(e.Matrix4.fromScale(S,I),u,u),d=e.Matrix4.clone(o),e.Matrix4.setTranslation(d,i.Cartesian3.ZERO,d),o=e.Matrix4.clone(o,new e.Matrix4);var y=e.Matrix4.fromTranslation(p,I),b=e.Matrix4.fromScale(f,B),M=e.Matrix4.multiply(y,b,I);e.Matrix4.multiply(o,M,o),e.Matrix4.multiply(d,M,d)}this.quantization=l,this.minimumHeight=r,this.maximumHeight=n,this.center=m,this.toScaledENU=u,this.fromScaledENU=o,this.matrix=d,this.hasVertexNormals=s,this.hasWebMercatorT=a.defaultValue(c,!1)}w.prototype.encode=function(t,r,a,o,c,m,u){var d=o.x,l=o.y;if(this.quantization===P.BITS12){(a=e.Matrix4.multiplyByPoint(this.toScaledENU,a,E)).x=s.Math3D.clamp(a.x,0,1),a.y=s.Math3D.clamp(a.y,0,1),a.z=s.Math3D.clamp(a.z,0,1);var p=this.maximumHeight-this.minimumHeight,h=s.Math3D.clamp((c-this.minimumHeight)/p,0,1);e.Cartesian2.fromElements(a.x,a.y,N);var f=n.AttributeCompression.compressTextureCoordinates(N);e.Cartesian2.fromElements(a.z,h,N);var x=n.AttributeCompression.compressTextureCoordinates(N);e.Cartesian2.fromElements(d,l,N);var C=n.AttributeCompression.compressTextureCoordinates(N);if(t[r++]=f,t[r++]=x,t[r++]=C,this.hasWebMercatorT){e.Cartesian2.fromElements(u,0,N);var S=n.AttributeCompression.compressTextureCoordinates(N);t[r++]=S}}else i.Cartesian3.subtract(a,this.center,E),t[r++]=E.x,t[r++]=E.y,t[r++]=E.z,t[r++]=c,t[r++]=d,t[r++]=l,this.hasWebMercatorT&&(t[r++]=u);return this.hasVertexNormals&&(t[r++]=n.AttributeCompression.octPackFloat(m)),r},w.prototype.decodePosition=function(t,r,o){if(a.defined(o)||(o=new i.Cartesian3),r*=this.getStride(),this.quantization===P.BITS12){var s=n.AttributeCompression.decompressTextureCoordinates(t[r],N);o.x=s.x,o.y=s.y;var c=n.AttributeCompression.decompressTextureCoordinates(t[r+1],N);return o.z=c.x,e.Matrix4.multiplyByPoint(this.fromScaledENU,o,o)}return o.x=t[r],o.y=t[r+1],o.z=t[r+2],i.Cartesian3.add(o,this.center,o)},w.prototype.decodeTextureCoordinates=function(t,i,r){return a.defined(r)||(r=new e.Cartesian2),i*=this.getStride(),this.quantization===P.BITS12?n.AttributeCompression.decompressTextureCoordinates(t[i+2],r):e.Cartesian2.fromElements(t[i+4],t[i+5],r)},w.prototype.decodeHeight=function(t,e){return e*=this.getStride(),this.quantization===P.BITS12?n.AttributeCompression.decompressTextureCoordinates(t[e+1],N).y*(this.maximumHeight-this.minimumHeight)+this.minimumHeight:t[e+3]},w.prototype.decodeWebMercatorT=function(t,e){return e*=this.getStride(),this.quantization===P.BITS12?n.AttributeCompression.decompressTextureCoordinates(t[e+3],N).x:t[e+6]},w.prototype.getOctEncodedNormal=function(t,i,r){var a=t[i=(i+1)*this.getStride()-1]/256,n=Math.floor(a),o=256*(a-n);return e.Cartesian2.fromElements(n,o,r)},w.prototype.getStride=function(){var t;if(this.quantization===P.BITS12)t=3;else t=6;return this.hasWebMercatorT&&++t,this.hasVertexNormals&&++t,t};var A={position3DAndHeight:0,textureCoordAndEncodedNormals:1},q={compressed0:0,compressed1:1};w.prototype.getAttributes=function(t){var e,i=o.ComponentDatatype.FLOAT,r=o.ComponentDatatype.getSizeInBytes(i);if(this.quantization===P.NONE){var a=2;return this.hasWebMercatorT&&++a,this.hasVertexNormals&&++a,[{index:A.position3DAndHeight,vertexBuffer:t,componentDatatype:i,componentsPerAttribute:4,offsetInBytes:0,strideInBytes:e=(4+a)*r},{index:A.textureCoordAndEncodedNormals,vertexBuffer:t,componentDatatype:i,componentsPerAttribute:a,offsetInBytes:4*r,strideInBytes:e}]}var n=3,s=0;return(this.hasWebMercatorT||this.hasVertexNormals)&&++n,this.hasWebMercatorT&&this.hasVertexNormals?(++s,[{index:q.compressed0,vertexBuffer:t,componentDatatype:i,componentsPerAttribute:n,offsetInBytes:0,strideInBytes:e=(n+s)*r},{index:q.compressed1,vertexBuffer:t,componentDatatype:i,componentsPerAttribute:s,offsetInBytes:n*r,strideInBytes:e}]):[{index:q.compressed0,vertexBuffer:t,componentDatatype:i,componentsPerAttribute:n}]},w.prototype.getAttributeLocations=function(){return this.quantization===P.NONE?A:q},w.clone=function(t,r){return a.defined(r)||(r=new w),r.quantization=t.quantization,r.minimumHeight=t.minimumHeight,r.maximumHeight=t.maximumHeight,r.center=i.Cartesian3.clone(t.center),r.toScaledENU=e.Matrix4.clone(t.toScaledENU),r.fromScaledENU=e.Matrix4.clone(t.fromScaledENU),r.matrix=e.Matrix4.clone(t.matrix),r.hasVertexNormals=t.hasVertexNormals,r.hasWebMercatorT=t.hasWebMercatorT,r},t.EllipsoidalOccluder=c,t.TerrainEncoding=w}));