Agriculture-front-end/public/Cesium/Workers/createPolygonGeometry.js
2023-09-11 21:56:39 +08:00

2 lines
15 KiB
JavaScript

define(["./when-b60132fc","./Cartesian2-47311507","./ArcType-29cf2197","./arrayFill-4513d7ad","./BoundingRectangle-01b3e970","./BoundingSphere-561b54d0","./Cartographic-3309dd0d","./Check-7b2a090c","./ComponentDatatype-c140a87d","./EllipsoidGeodesic-0f19ac62","./EllipsoidTangentPlane-b2b18d75","./GeometryAttribute-3a42bbdc","./GeometryInstance-41780fb6","./GeometryOffsetAttribute-fbeb6f1a","./GeometryPipeline-e1b82a4e","./IndexDatatype-8a5eead4","./Math-119be1a3","./PolygonGeometryLibrary-ae9ad77c","./PolygonPipeline-f49953b9","./Transforms-cb0006b0","./VertexFormat-6446fca0","./Cartesian4-3ca25aab","./RuntimeError-4a5c8994","./WebGLConstants-4ae0db90","./IntersectionTests-0c6d0a14","./Plane-097b3a8f","./PrimitiveType-39acab88","./AttributeCompression-90851096","./EncodedCartesian3-f1396b05","./arrayRemoveDuplicates-d2f048c5","./EllipsoidRhumbLine-ed1a6bf4","./GeometryAttributes-252e9929","./earcut-2.2.1-20c8012f","./buildModuleUrl-3addfe33","./FeatureDetection-c3b71206"],(function(e,t,a,r,o,i,n,s,l,u,c,p,y,d,g,m,h,f,b,v,_,P,x,C,w,T,A,E,I,G,V,F,N,H,O){"use strict";var R=new n.Cartographic,D=new n.Cartographic;function L(e,t,a,r){var o=r.cartesianToCartographic(e,R).height,i=r.cartesianToCartographic(t,D);i.height=o,r.cartographicToCartesian(i,t);var n=r.cartesianToCartographic(a,D);n.height=o-100,r.cartographicToCartesian(n,a)}var M=new o.BoundingRectangle,S=new n.Cartesian3,B=new n.Cartesian3,k=new n.Cartesian3,z=new n.Cartesian3,Y=new n.Cartesian3,U=new n.Cartesian3,W=new n.Cartesian3,j=new n.Cartesian3,Q=new n.Cartesian3,q=new t.Cartesian2,K=new t.Cartesian2,Z=new n.Cartesian3,J=new v.Quaternion,X=new i.Matrix3,$=new i.Matrix3;function ee(a){var o=a.vertexFormat,s=a.geometry,u=a.shadowVolume,c=s.attributes.position.values,y=c.length,g=a.wall,m=a.top||g,f=a.bottom||g;if(o.st||o.normal||o.tangent||o.bitangent||u){var b=a.boundingRectangle,_=a.tangentPlane,P=a.ellipsoid,x=a.stRotation,C=a.perPositionHeight,w=q;w.x=b.x,w.y=b.y;var T,A=o.st?new Float32Array(y/3*2):void 0;o.normal&&(T=C&&m&&!g?s.attributes.normal.values:new Float32Array(y));var E=o.tangent?new Float32Array(y):void 0,I=o.bitangent?new Float32Array(y):void 0,G=u?new Float32Array(y):void 0,V=0,F=0,N=B,H=k,O=z,R=!0,D=X,M=$;if(0!==x){var ee=v.Quaternion.fromAxisAngle(_._plane.normal,x,J);D=i.Matrix3.fromQuaternion(ee,D),ee=v.Quaternion.fromAxisAngle(_._plane.normal,-x,J),M=i.Matrix3.fromQuaternion(ee,M)}else D=i.Matrix3.clone(i.Matrix3.IDENTITY,D),M=i.Matrix3.clone(i.Matrix3.IDENTITY,M);var te=0,ae=0;m&&f&&(te=y/2,ae=y/3,y/=2);for(var re=0;re<y;re+=3){var oe=n.Cartesian3.fromArray(c,re,Z);if(o.st){var ie=i.Matrix3.multiplyByVector(D,oe,S);ie=P.scaleToGeodeticSurface(ie,ie);var ne=_.projectPointOntoPlane(ie,K);t.Cartesian2.subtract(ne,w,ne);var se=h.CesiumMath.clamp(ne.x/b.width,0,1),le=h.CesiumMath.clamp(ne.y/b.height,0,1);f&&(A[V+ae]=se,A[V+1+ae]=le),m&&(A[V]=se,A[V+1]=le),V+=2}if(o.normal||o.tangent||o.bitangent||u){var ue=F+1,ce=F+2;if(g){if(re+3<y){var pe=n.Cartesian3.fromArray(c,re+3,Y);if(R){var ye=n.Cartesian3.fromArray(c,re+y,U);C&&L(oe,pe,ye,P),n.Cartesian3.subtract(pe,oe,pe),n.Cartesian3.subtract(ye,oe,ye),N=n.Cartesian3.normalize(n.Cartesian3.cross(ye,pe,N),N),R=!1}n.Cartesian3.equalsEpsilon(pe,oe,h.CesiumMath.EPSILON10)&&(R=!0)}(o.tangent||o.bitangent)&&(O=P.geodeticSurfaceNormal(oe,O),o.tangent&&(H=n.Cartesian3.normalize(n.Cartesian3.cross(O,N,H),H)))}else N=P.geodeticSurfaceNormal(oe,N),(o.tangent||o.bitangent)&&(C&&(W=n.Cartesian3.fromArray(T,F,W),j=n.Cartesian3.cross(n.Cartesian3.UNIT_Z,W,j),j=n.Cartesian3.normalize(i.Matrix3.multiplyByVector(M,j,j),j),o.bitangent&&(Q=n.Cartesian3.normalize(n.Cartesian3.cross(W,j,Q),Q))),H=n.Cartesian3.cross(n.Cartesian3.UNIT_Z,N,H),H=n.Cartesian3.normalize(i.Matrix3.multiplyByVector(M,H,H),H),o.bitangent&&(O=n.Cartesian3.normalize(n.Cartesian3.cross(N,H,O),O)));o.normal&&(a.wall?(T[F+te]=N.x,T[ue+te]=N.y,T[ce+te]=N.z):f&&(T[F+te]=-N.x,T[ue+te]=-N.y,T[ce+te]=-N.z),(m&&!C||g)&&(T[F]=N.x,T[ue]=N.y,T[ce]=N.z)),u&&(g&&(N=P.geodeticSurfaceNormal(oe,N)),G[F+te]=-N.x,G[ue+te]=-N.y,G[ce+te]=-N.z),o.tangent&&(a.wall?(E[F+te]=H.x,E[ue+te]=H.y,E[ce+te]=H.z):f&&(E[F+te]=-H.x,E[ue+te]=-H.y,E[ce+te]=-H.z),m&&(C?(E[F]=j.x,E[ue]=j.y,E[ce]=j.z):(E[F]=H.x,E[ue]=H.y,E[ce]=H.z))),o.bitangent&&(f&&(I[F+te]=O.x,I[ue+te]=O.y,I[ce+te]=O.z),m&&(C?(I[F]=Q.x,I[ue]=Q.y,I[ce]=Q.z):(I[F]=O.x,I[ue]=O.y,I[ce]=O.z))),F+=3}}o.st&&(s.attributes.st=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:A})),o.normal&&(s.attributes.normal=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:T})),o.tangent&&(s.attributes.tangent=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:E})),o.bitangent&&(s.attributes.bitangent=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:I})),u&&(s.attributes.extrudeDirection=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:G}))}if(a.extrude&&e.defined(a.offsetAttribute)){var de=c.length/3,ge=new Uint8Array(de);if(a.offsetAttribute===d.GeometryOffsetAttribute.TOP)m&&f||g?ge=r.arrayFill(ge,1,0,de/2):m&&(ge=r.arrayFill(ge,1));else{var me=a.offsetAttribute===d.GeometryOffsetAttribute.NONE?0:1;ge=r.arrayFill(ge,me)}s.attributes.applyOffset=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:ge})}return s}var te=new n.Cartographic,ae=new n.Cartographic,re={west:0,east:0},oe=new u.EllipsoidGeodesic;function ie(r,o,i,n,s){if(s=e.defaultValue(s,new t.Rectangle),!e.defined(r)||r.length<3)return s.west=0,s.north=0,s.south=0,s.east=0,s;if(i===a.ArcType.RHUMB)return t.Rectangle.fromCartesianArray(r,o,s);oe.ellipsoid.equals(o)||(oe=new u.EllipsoidGeodesic(void 0,void 0,o)),s.west=Number.POSITIVE_INFINITY,s.east=Number.NEGATIVE_INFINITY,s.south=Number.POSITIVE_INFINITY,s.north=Number.NEGATIVE_INFINITY,re.west=Number.POSITIVE_INFINITY,re.east=Number.NEGATIVE_INFINITY;for(var l,c=1/h.CesiumMath.chordLength(n,o.maximumRadius),p=r.length,y=o.cartesianToCartographic(r[0],ae),d=te,g=1;g<p;g++)l=d,d=y,y=o.cartesianToCartographic(r[g],l),oe.setEndPoints(d,y),se(oe,c,s,re);return l=d,d=y,y=o.cartesianToCartographic(r[0],l),oe.setEndPoints(d,y),se(oe,c,s,re),s.east-s.west>re.west-re.east&&(s.east=re.east,s.west=re.west),s}var ne=new n.Cartographic;function se(e,t,a,r){for(var o=e.surfaceDistance,i=Math.ceil(o*t),n=i>0?o/(i-1):Number.POSITIVE_INFINITY,s=0,l=0;l<i;l++){var u=e.interpolateUsingSurfaceDistance(s,ne);s+=n;var c=u.longitude,p=u.latitude;a.west=Math.min(a.west,c),a.east=Math.max(a.east,c),a.south=Math.min(a.south,p),a.north=Math.max(a.north,p),r.west=c>0?Math.min(c,r.west):r.west,r.east=c<0?Math.max(c,r.east):r.east}}var le=[];function ue(e,t,a,r,o,i,n,s,l,u){var p,d={walls:[]};if(i||n){var g,h,v=f.PolygonGeometryLibrary.createGeometryFromPositions(e,t,a,o,s,l),_=v.attributes.position.values,P=v.indices;if(i&&n){var x=_.concat(_);g=x.length/3,(h=m.IndexDatatype.createTypedArray(g,2*P.length)).set(P);var C=P.length,w=g/2;for(p=0;p<C;p+=3){var T=h[p]+w,A=h[p+1]+w,E=h[p+2]+w;h[p+C]=E,h[p+1+C]=A,h[p+2+C]=T}if(v.attributes.position.values=x,o&&s.normal){var I=v.attributes.normal.values;v.attributes.normal.values=new Float32Array(x.length),v.attributes.normal.values.set(I)}v.indices=h}else if(n){for(g=_.length/3,h=m.IndexDatatype.createTypedArray(g,P.length),p=0;p<P.length;p+=3)h[p]=P[p+2],h[p+1]=P[p+1],h[p+2]=P[p];v.indices=h}d.topAndBottom=new y.GeometryInstance({geometry:v})}var G,V=r.outerRing,F=c.EllipsoidTangentPlane.fromPoints(V,e),N=F.projectPointsOntoPlane(V,le),H=b.PolygonPipeline.computeWindingOrder2D(N);H===b.WindingOrder.CLOCKWISE&&(V=V.slice().reverse()),u&&(G=f.PolygonGeometryLibrary.computeWallGeometry(V,e,a,o,l),d.walls.push(new y.GeometryInstance({geometry:G})));var O=r.holes;for(p=0;p<O.length;p++){var R=O[p];N=(F=c.EllipsoidTangentPlane.fromPoints(R,e)).projectPointsOntoPlane(R,le),(H=b.PolygonPipeline.computeWindingOrder2D(N))===b.WindingOrder.COUNTER_CLOCKWISE&&(R=R.slice().reverse()),G=f.PolygonGeometryLibrary.computeWallGeometry(R,e,a,o,l),d.walls.push(new y.GeometryInstance({geometry:G}))}return d}function ce(r){var o=r.polygonHierarchy,i=e.defaultValue(r.vertexFormat,_.VertexFormat.DEFAULT),n=e.defaultValue(r.ellipsoid,t.Ellipsoid.WGS84),s=e.defaultValue(r.granularity,h.CesiumMath.RADIANS_PER_DEGREE),l=e.defaultValue(r.stRotation,0),u=e.defaultValue(r.perPositionHeight,!1),c=u&&e.defined(r.extrudedHeight),p=e.defaultValue(r.height,0),y=e.defaultValue(r.extrudedHeight,p);if(!c){var d=Math.max(p,y);y=Math.min(p,y),p=d}this._vertexFormat=_.VertexFormat.clone(i),this._ellipsoid=t.Ellipsoid.clone(n),this._granularity=s,this._stRotation=l,this._height=p,this._extrudedHeight=y,this._closeTop=e.defaultValue(r.closeTop,!0),this._closeBottom=e.defaultValue(r.closeBottom,!0),this._extrudeOutering=e.defaultValue(r.extrudeOutering,!0),this._polygonHierarchy=o,this._perPositionHeight=u,this._perPositionHeightExtrude=c,this._shadowVolume=e.defaultValue(r.shadowVolume,!1),this._workerName="createPolygonGeometry",this._offsetAttribute=r.offsetAttribute,this._arcType=e.defaultValue(r.arcType,a.ArcType.GEODESIC),this._rectangle=void 0,this._textureCoordinateRotationPoints=void 0,this.packedLength=f.PolygonGeometryLibrary.computeHierarchyPackedLength(o)+t.Ellipsoid.packedLength+_.VertexFormat.packedLength+12}ce.fromPositions=function(t){return new ce({polygonHierarchy:{positions:(t=e.defaultValue(t,e.defaultValue.EMPTY_OBJECT)).positions},height:t.height,extrudedHeight:t.extrudedHeight,vertexFormat:t.vertexFormat,stRotation:t.stRotation,ellipsoid:t.ellipsoid,granularity:t.granularity,perPositionHeight:t.perPositionHeight,closeTop:t.closeTop,closeBottom:t.closeBottom,offsetAttribute:t.offsetAttribute,arcType:t.arcType})},ce.pack=function(a,r,o){return o=e.defaultValue(o,0),o=f.PolygonGeometryLibrary.packPolygonHierarchy(a._polygonHierarchy,r,o),t.Ellipsoid.pack(a._ellipsoid,r,o),o+=t.Ellipsoid.packedLength,_.VertexFormat.pack(a._vertexFormat,r,o),o+=_.VertexFormat.packedLength,r[o++]=a._height,r[o++]=a._extrudedHeight,r[o++]=a._granularity,r[o++]=a._stRotation,r[o++]=a._perPositionHeightExtrude?1:0,r[o++]=a._perPositionHeight?1:0,r[o++]=a._closeTop?1:0,r[o++]=a._closeBottom?1:0,r[o++]=a._shadowVolume?1:0,r[o++]=e.defaultValue(a._offsetAttribute,-1),r[o++]=a._arcType,r[o]=a.packedLength,r};var pe=t.Ellipsoid.clone(t.Ellipsoid.UNIT_SPHERE),ye=new _.VertexFormat,de={polygonHierarchy:{}};return ce.unpack=function(a,r,o){r=e.defaultValue(r,0);var i=f.PolygonGeometryLibrary.unpackPolygonHierarchy(a,r);r=i.startingIndex,delete i.startingIndex;var n=t.Ellipsoid.unpack(a,r,pe);r+=t.Ellipsoid.packedLength;var s=_.VertexFormat.unpack(a,r,ye);r+=_.VertexFormat.packedLength;var l=a[r++],u=a[r++],c=a[r++],p=a[r++],y=1===a[r++],d=1===a[r++],g=1===a[r++],m=1===a[r++],h=1===a[r++],b=a[r++],v=a[r++],P=a[r];return e.defined(o)||(o=new ce(de)),o._polygonHierarchy=i,o._ellipsoid=t.Ellipsoid.clone(n,o._ellipsoid),o._vertexFormat=_.VertexFormat.clone(s,o._vertexFormat),o._height=l,o._extrudedHeight=u,o._granularity=c,o._stRotation=p,o._perPositionHeightExtrude=y,o._perPositionHeight=d,o._closeTop=g,o._closeBottom=m,o._shadowVolume=h,o._offsetAttribute=-1===b?void 0:b,o._arcType=v,o.packedLength=P,o},ce.computeRectangle=function(r,o){var i=e.defaultValue(r.granularity,h.CesiumMath.RADIANS_PER_DEGREE),n=e.defaultValue(r.arcType,a.ArcType.GEODESIC),s=r.polygonHierarchy,l=e.defaultValue(r.ellipsoid,t.Ellipsoid.WGS84);return ie(s.positions,l,n,i,o)},ce.createGeometry=function(t){var a=t._vertexFormat,o=t._ellipsoid,n=t._granularity,s=t._stRotation,u=t._polygonHierarchy,v=t._perPositionHeight,_=t._closeTop,P=t._closeBottom,x=t._arcType,C=u.positions;if(!(C.length<3)){var w=c.EllipsoidTangentPlane.fromPoints(C,o),T=f.PolygonGeometryLibrary.polygonsFromHierarchy(u,w.projectPointsOntoPlane.bind(w),!v,o),A=T.hierarchy,E=T.polygons;if(0!==A.length){C=A[0].outerRing;var I,G=f.PolygonGeometryLibrary.computeBoundingRectangle(w.plane.normal,w.projectPointOntoPlane.bind(w),C,s,M),V=[],F=t._height,N=t._extrudedHeight,H={perPositionHeight:v,vertexFormat:a,geometry:void 0,tangentPlane:w,boundingRectangle:G,ellipsoid:o,stRotation:s,bottom:!1,top:!0,wall:!1,extrude:!1,arcType:x};if(t._perPositionHeightExtrude||!h.CesiumMath.equalsEpsilon(F,N,0,h.CesiumMath.EPSILON2))for(H.extrude=!0,H.top=_,H.bottom=P,H.shadowVolume=t._shadowVolume,H.offsetAttribute=t._offsetAttribute,I=0;I<E.length;I++){var O,R=ue(o,E[I],n,A[I],v,_,P,a,x,t._extrudeOutering);_&&P?(O=R.topAndBottom,H.geometry=f.PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(O.geometry,F,N,o,v)):_?((O=R.topAndBottom).geometry.attributes.position.values=b.PolygonPipeline.scaleToGeodeticHeight(O.geometry.attributes.position.values,F,o,!v),H.geometry=O.geometry):P&&((O=R.topAndBottom).geometry.attributes.position.values=b.PolygonPipeline.scaleToGeodeticHeight(O.geometry.attributes.position.values,N,o,!0),H.geometry=O.geometry),(_||P)&&(H.wall=!1,O.geometry=ee(H),V.push(O));var D=R.walls;H.wall=!0;for(var L=0;L<D.length;L++){var S=D[L];H.geometry=f.PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(S.geometry,F,N,o,v),S.geometry=ee(H),V.push(S)}}else for(I=0;I<E.length;I++){var B=new y.GeometryInstance({geometry:f.PolygonGeometryLibrary.createGeometryFromPositions(o,E[I],n,v,a,x)});if(B.geometry.attributes.position.values=b.PolygonPipeline.scaleToGeodeticHeight(B.geometry.attributes.position.values,F,o,!v),H.geometry=B.geometry,B.geometry=ee(H),e.defined(t._offsetAttribute)){var k=B.geometry.attributes.position.values.length,z=new Uint8Array(k/3),Y=t._offsetAttribute===d.GeometryOffsetAttribute.NONE?0:1;r.arrayFill(z,Y),B.geometry.attributes.applyOffset=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:z})}V.push(B)}var U=g.GeometryPipeline.combineInstances(V)[0];U.attributes.position.values=new Float64Array(U.attributes.position.values),U.indices=m.IndexDatatype.createTypedArray(U.attributes.position.values.length/3,U.indices);var W=U.attributes,j=i.BoundingSphere.fromVertices(W.position.values);return a.position||delete W.position,new p.Geometry({attributes:W,indices:U.indices,primitiveType:U.primitiveType,boundingSphere:j,offsetAttribute:t._offsetAttribute})}}},ce.createShadowVolume=function(e,t,a){var r=e._granularity,o=e._ellipsoid,i=t(r,o),n=a(r,o);return new ce({polygonHierarchy:e._polygonHierarchy,ellipsoid:o,stRotation:e._stRotation,granularity:r,perPositionHeight:!1,extrudedHeight:i,height:n,vertexFormat:_.VertexFormat.POSITION_ONLY,shadowVolume:!0,arcType:e._arcType})},Object.defineProperties(ce.prototype,{rectangle:{get:function(){if(!e.defined(this._rectangle)){var t=this._polygonHierarchy.positions;this._rectangle=ie(t,this._ellipsoid,this._arcType,this._granularity)}return this._rectangle}},textureCoordinateRotationPoints:{get:function(){return e.defined(this._textureCoordinateRotationPoints)||(this._textureCoordinateRotationPoints=function(e){var t=-e._stRotation;if(0===t)return[0,0,0,1,1,0];var a=e._ellipsoid,r=e._polygonHierarchy.positions,o=e.rectangle;return p.Geometry._textureCoordinateRotationPoints(r,t,a,o)}(this)),this._textureCoordinateRotationPoints}}}),function(a,r){return e.defined(r)&&(a=ce.unpack(a,r)),a._ellipsoid=t.Ellipsoid.clone(a._ellipsoid),ce.createGeometry(a)}}));