bmh_cesium/public/lib/cesiumjs/CesiumUnminified/Workers/createPolygonOutlineGeometry.js
2025-03-10 07:23:50 +08:00

2 lines
7.8 KiB
JavaScript

/* 2020-9-22 15:23:25 | 版权所有 军懋国兴 */
define(["./when-cbf8cd21","./Check-35e1a91d","./Math-69007a69","./Cartesian2-43e3a3be","./Transforms-2d1ac5ec","./RuntimeError-f4c64df1","./WebGLConstants-95ceb4e9","./ComponentDatatype-607c9a0c","./GeometryAttribute-2303bbfb","./GeometryAttributes-90846c5f","./AttributeCompression-ea810287","./GeometryPipeline-1ea64cde","./EncodedCartesian3-29a09d7b","./IndexDatatype-79bb407c","./IntersectionTests-459f6f08","./Plane-46b5436f","./GeometryOffsetAttribute-9c676324","./GeometryInstance-6264cc0f","./arrayRemoveDuplicates-d96adeb6","./EllipsoidTangentPlane-b5927ee3","./ArcType-2b58731c","./EllipsoidRhumbLine-357c11e7","./PolygonPipeline-2ee85025","./PolygonGeometryLibrary-bcb33f68"],function(E,c,v,h,A,e,t,G,_,T,i,H,r,L,o,n,C,O,a,D,I,y,w,x){"use strict";var k=[],S=[];function f(e){if(c.Check.typeOf.object("options",e),c.Check.typeOf.object("options.polygonHierarchy",e.polygonHierarchy),e.perPositionHeight&&E.defined(e.height))throw new c.DeveloperError("Cannot use both options.perPositionHeight and options.height");if(E.defined(e.arcType)&&e.arcType!==I.ArcType.GEODESIC&&e.arcType!==I.ArcType.RHUMB)throw new c.DeveloperError("Invalid arcType. Valid options are ArcType.GEODESIC and ArcType.RHUMB.");var t,i=e.polygonHierarchy,r=E.defaultValue(e.ellipsoid,h.Ellipsoid.WGS84),o=E.defaultValue(e.granularity,v.CesiumMath.RADIANS_PER_DEGREE),n=E.defaultValue(e.perPositionHeight,!1),a=n&&E.defined(e.extrudedHeight),y=E.defaultValue(e.arcType,I.ArcType.GEODESIC),s=E.defaultValue(e.height,0),l=E.defaultValue(e.extrudedHeight,s);a||(t=Math.max(s,l),l=Math.min(s,l),s=t),this._ellipsoid=h.Ellipsoid.clone(r),this._granularity=o,this._height=s,this._extrudedHeight=l,this._arcType=y,this._polygonHierarchy=i,this._perPositionHeight=n,this._perPositionHeightExtrude=a,this._offsetAttribute=e.offsetAttribute,this._workerName="createPolygonOutlineGeometry",this.packedLength=x.PolygonGeometryLibrary.computeHierarchyPackedLength(i)+h.Ellipsoid.packedLength+8}f.pack=function(e,t,i){return c.Check.typeOf.object("value",e),c.Check.defined("array",t),i=E.defaultValue(i,0),i=x.PolygonGeometryLibrary.packPolygonHierarchy(e._polygonHierarchy,t,i),h.Ellipsoid.pack(e._ellipsoid,t,i),i+=h.Ellipsoid.packedLength,t[i++]=e._height,t[i++]=e._extrudedHeight,t[i++]=e._granularity,t[i++]=e._perPositionHeightExtrude?1:0,t[i++]=e._perPositionHeight?1:0,t[i++]=e._arcType,t[i++]=E.defaultValue(e._offsetAttribute,-1),t[i]=e.packedLength,t};var g=h.Ellipsoid.clone(h.Ellipsoid.UNIT_SPHERE),m={polygonHierarchy:{}};return f.unpack=function(e,t,i){c.Check.defined("array",e),t=E.defaultValue(t,0);var r=x.PolygonGeometryLibrary.unpackPolygonHierarchy(e,t);t=r.startingIndex,delete r.startingIndex;var o=h.Ellipsoid.unpack(e,t,g);t+=h.Ellipsoid.packedLength;var n=e[t++],a=e[t++],y=e[t++],s=1===e[t++],l=1===e[t++],p=e[t++],u=e[t++],d=e[t];return E.defined(i)||(i=new f(m)),i._polygonHierarchy=r,i._ellipsoid=h.Ellipsoid.clone(o,i._ellipsoid),i._height=n,i._extrudedHeight=a,i._granularity=y,i._perPositionHeight=l,i._perPositionHeightExtrude=s,i._arcType=p,i._offsetAttribute=-1===u?void 0:u,i.packedLength=d,i},f.fromPositions=function(e){return e=E.defaultValue(e,E.defaultValue.EMPTY_OBJECT),c.Check.defined("options.positions",e.positions),new f({polygonHierarchy:{positions:e.positions},height:e.height,extrudedHeight:e.extrudedHeight,ellipsoid:e.ellipsoid,granularity:e.granularity,perPositionHeight:e.perPositionHeight,arcType:e.arcType,offsetAttribute:e.offsetAttribute})},f.createGeometry=function(e){var t=e._ellipsoid,i=e._granularity,r=e._polygonHierarchy,o=e._perPositionHeight,n=e._arcType,a=x.PolygonGeometryLibrary.polygonOutlinesFromHierarchy(r,!o,t);if(0!==a.length){var y,s,l,p,u,d,c,h=[],f=v.CesiumMath.chordLength(i,t.maximumRadius),g=e._height,m=e._extrudedHeight;if(e._perPositionHeightExtrude||!v.CesiumMath.equalsEpsilon(g,m,0,v.CesiumMath.EPSILON2))for(y=0;y<a.length;y++){(p=function(e,t,i,r,o){var n,a=D.EllipsoidTangentPlane.fromPoints(t,e).projectPointsOntoPlane(t,k);w.PolygonPipeline.computeWindingOrder2D(a)===w.WindingOrder.CLOCKWISE&&(a.reverse(),t=t.slice().reverse());var y=t.length,s=new Array(y),l=0;if(r)for(n=new Float64Array(2*y*3*2),P=0;P<y;++P){s[P]=l/3;var p=t[P],u=t[(P+1)%y];n[l++]=p.x,n[l++]=p.y,n[l++]=p.z,n[l++]=u.x,n[l++]=u.y,n[l++]=u.z}else{var d,c=0;if(o===I.ArcType.GEODESIC)for(P=0;P<y;P++)c+=x.PolygonGeometryLibrary.subdivideLineCount(t[P],t[(P+1)%y],i);else if(o===I.ArcType.RHUMB)for(P=0;P<y;P++)c+=x.PolygonGeometryLibrary.subdivideRhumbLineCount(e,t[P],t[(P+1)%y],i);for(n=new Float64Array(3*c*2),P=0;P<y;++P){s[P]=l/3,o===I.ArcType.GEODESIC?d=x.PolygonGeometryLibrary.subdivideLine(t[P],t[(P+1)%y],i,S):o===I.ArcType.RHUMB&&(d=x.PolygonGeometryLibrary.subdivideRhumbLine(e,t[P],t[(P+1)%y],i,S));for(var h=d.length,f=0;f<h;++f)n[l++]=d[f]}}y=n.length/6;for(var g=s.length,m=2*(2*y+g),b=L.IndexDatatype.createTypedArray(y+g,m),l=0,P=0;P<y;++P)b[l++]=P,b[l++]=(P+1)%y,b[l++]=P+y,b[l++]=(P+1)%y+y;for(P=0;P<g;P++){var E=s[P];b[l++]=E,b[l++]=E+y}return new O.GeometryInstance({geometry:new _.Geometry({attributes:new T.GeometryAttributes({position:new _.GeometryAttribute({componentDatatype:G.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:n})}),indices:b,primitiveType:_.PrimitiveType.LINES})})}(t,a[y],f,o,n)).geometry=x.PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(p.geometry,g,m,t,o),E.defined(e._offsetAttribute)&&(s=p.geometry.attributes.position.values.length/3,l=new Uint8Array(s),l=e._offsetAttribute===C.GeometryOffsetAttribute.TOP?C.arrayFill(l,1,0,s/2):(c=e._offsetAttribute===C.GeometryOffsetAttribute.NONE?0:1,C.arrayFill(l,c)),p.geometry.attributes.applyOffset=new _.GeometryAttribute({componentDatatype:G.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:l})),h.push(p)}else for(y=0;y<a.length;y++){(p=function(e,t,i,r,o){var n,a=D.EllipsoidTangentPlane.fromPoints(t,e).projectPointsOntoPlane(t,k);w.PolygonPipeline.computeWindingOrder2D(a)===w.WindingOrder.CLOCKWISE&&(a.reverse(),t=t.slice().reverse());var y=t.length,s=0;if(r)for(n=new Float64Array(2*y*3),m=0;m<y;m++){var l=t[m],p=t[(m+1)%y];n[s++]=l.x,n[s++]=l.y,n[s++]=l.z,n[s++]=p.x,n[s++]=p.y,n[s++]=p.z}else{var u,d=0;if(o===I.ArcType.GEODESIC)for(m=0;m<y;m++)d+=x.PolygonGeometryLibrary.subdivideLineCount(t[m],t[(m+1)%y],i);else if(o===I.ArcType.RHUMB)for(m=0;m<y;m++)d+=x.PolygonGeometryLibrary.subdivideRhumbLineCount(e,t[m],t[(m+1)%y],i);for(n=new Float64Array(3*d),m=0;m<y;m++){o===I.ArcType.GEODESIC?u=x.PolygonGeometryLibrary.subdivideLine(t[m],t[(m+1)%y],i,S):o===I.ArcType.RHUMB&&(u=x.PolygonGeometryLibrary.subdivideRhumbLine(e,t[m],t[(m+1)%y],i,S));for(var c=u.length,h=0;h<c;++h)n[s++]=u[h]}}for(var f=2*(y=n.length/3),g=L.IndexDatatype.createTypedArray(y,f),s=0,m=0;m<y-1;m++)g[s++]=m,g[s++]=m+1;return g[s++]=y-1,g[s++]=0,new O.GeometryInstance({geometry:new _.Geometry({attributes:new T.GeometryAttributes({position:new _.GeometryAttribute({componentDatatype:G.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:n})}),indices:g,primitiveType:_.PrimitiveType.LINES})})}(t,a[y],f,o,n)).geometry.attributes.position.values=w.PolygonPipeline.scaleToGeodeticHeight(p.geometry.attributes.position.values,g,t,!o),E.defined(e._offsetAttribute)&&(u=p.geometry.attributes.position.values.length,d=new Uint8Array(u/3),c=e._offsetAttribute===C.GeometryOffsetAttribute.NONE?0:1,C.arrayFill(d,c),p.geometry.attributes.applyOffset=new _.GeometryAttribute({componentDatatype:G.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:d})),h.push(p)}var b=H.GeometryPipeline.combineInstances(h)[0],P=A.BoundingSphere.fromVertices(b.attributes.position.values);return new _.Geometry({attributes:b.attributes,indices:b.indices,primitiveType:b.primitiveType,boundingSphere:P,offsetAttribute:e._offsetAttribute})}},function(e,t){return E.defined(t)&&(e=f.unpack(e,t)),e._ellipsoid=h.Ellipsoid.clone(e._ellipsoid),f.createGeometry(e)}});