Agriculture-front-end/public/Cesium/Workers/createPolygonGeometry.js
2023-04-16 22:33:44 +08:00

2 lines
15 KiB
JavaScript

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