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