createCoplanarPolygonOutlineGeometry.js 3.6 KB

12345678910111213141516171819202122232425
  1. /**
  2. * @license
  3. * Cesium - https://github.com/CesiumGS/cesium
  4. * Version 1.95
  5. *
  6. * Copyright 2011-2022 Cesium Contributors
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * Columbus View (Pat. Pend.)
  21. *
  22. * Portions licensed separately.
  23. * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
  24. */
  25. define(["./arrayRemoveDuplicates-6f91355d","./Transforms-d3d3b2a9","./Matrix2-73789715","./RuntimeError-4f8ec8a2","./ComponentDatatype-e7fbe225","./CoplanarPolygonGeometryLibrary-edaba606","./defaultValue-97284df2","./GeometryAttribute-fd1d7e90","./GeometryAttributes-734a3446","./GeometryInstance-4bfcfe78","./GeometryPipeline-a847e31f","./IndexDatatype-65271ba3","./PolygonGeometryLibrary-c8ae4a5a","./_commonjsHelpers-3aae1032-65601a27","./combine-d11b1f00","./WebGLConstants-6da700a2","./OrientedBoundingBox-ee3011f6","./EllipsoidTangentPlane-7ae496b2","./AxisAlignedBoundingBox-b1c095aa","./IntersectionTests-33ace2d6","./Plane-e916220d","./AttributeCompression-5744d52e","./EncodedCartesian3-a9a8a281","./ArcType-de5d8777","./EllipsoidRhumbLine-60f14314","./PolygonPipeline-9bda6d1d"],(function(e,t,n,o,r,a,i,y,l,s,c,u,p,d,m,f,g,b,h,P,G,L,C,T,E,H){"use strict";function A(e){const t=e.length,n=new Float64Array(3*t),o=u.IndexDatatype.createTypedArray(t,2*t);let a=0,i=0;for(let r=0;r<t;r++){const y=e[r];n[a++]=y.x,n[a++]=y.y,n[a++]=y.z,o[i++]=r,o[i++]=(r+1)%t}const s=new l.GeometryAttributes({position:new y.GeometryAttribute({componentDatatype:r.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:n})});return new y.Geometry({attributes:s,indices:o,primitiveType:y.PrimitiveType.LINES})}function k(e){const t=(e=i.defaultValue(e,i.defaultValue.EMPTY_OBJECT)).polygonHierarchy;this._polygonHierarchy=t,this._workerName="createCoplanarPolygonOutlineGeometry",this.packedLength=p.PolygonGeometryLibrary.computeHierarchyPackedLength(t,n.Cartesian3)+1}k.fromPositions=function(e){return new k({polygonHierarchy:{positions:(e=i.defaultValue(e,i.defaultValue.EMPTY_OBJECT)).positions}})},k.pack=function(e,t,o){return o=i.defaultValue(o,0),t[o=p.PolygonGeometryLibrary.packPolygonHierarchy(e._polygonHierarchy,t,o,n.Cartesian3)]=e.packedLength,t};const _={polygonHierarchy:{}};return k.unpack=function(e,t,o){t=i.defaultValue(t,0);const r=p.PolygonGeometryLibrary.unpackPolygonHierarchy(e,t,n.Cartesian3);t=r.startingIndex,delete r.startingIndex;const a=e[t];return i.defined(o)||(o=new k(_)),o._polygonHierarchy=r,o.packedLength=a,o},k.createGeometry=function(o){const r=o._polygonHierarchy;let i=r.positions;if(i=e.arrayRemoveDuplicates(i,n.Cartesian3.equalsEpsilon,!0),i.length<3)return;if(!a.CoplanarPolygonGeometryLibrary.validOutline(i))return;const l=p.PolygonGeometryLibrary.polygonOutlinesFromHierarchy(r,!1);if(0===l.length)return;const u=[];for(let e=0;e<l.length;e++){const t=new s.GeometryInstance({geometry:A(l[e])});u.push(t)}const d=c.GeometryPipeline.combineInstances(u)[0],m=t.BoundingSphere.fromPoints(r.positions);return new y.Geometry({attributes:d.attributes,indices:d.indices,primitiveType:d.primitiveType,boundingSphere:m})},function(e,t){return i.defined(t)&&(e=k.unpack(e,t)),e._ellipsoid=n.Ellipsoid.clone(e._ellipsoid),k.createGeometry(e)}}));