createCoplanarPolygonOutlineGeometry.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./arrayRemoveDuplicates-06991c15', './Transforms-a076dbe6', './Matrix2-fc7e9822', './RuntimeError-c581ca93', './ComponentDatatype-4a60b8d6', './CoplanarPolygonGeometryLibrary-effcf1e1', './defaultValue-94c3e563', './GeometryAttribute-2ecf73f6', './GeometryAttributes-7df9bef6', './GeometryInstance-97bd792f', './GeometryPipeline-b4816e69', './IndexDatatype-db156785', './PolygonGeometryLibrary-6d3a5ed4', './_commonjsHelpers-3aae1032-f55dc0c4', './combine-761d9c3f', './WebGLConstants-7dccdc96', './OrientedBoundingBox-417528c0', './EllipsoidTangentPlane-d2c0c530', './AxisAlignedBoundingBox-8103739f', './IntersectionTests-5deed78b', './Plane-e20fba8c', './AttributeCompression-4d18cc04', './EncodedCartesian3-d3e254ea', './ArcType-0cf52f8c', './EllipsoidRhumbLine-daebc75b', './PolygonPipeline-cc031b9f'], (function (arrayRemoveDuplicates, Transforms, Matrix2, RuntimeError, ComponentDatatype, CoplanarPolygonGeometryLibrary, defaultValue, GeometryAttribute, GeometryAttributes, GeometryInstance, GeometryPipeline, IndexDatatype, PolygonGeometryLibrary, _commonjsHelpers3aae1032, combine, WebGLConstants, OrientedBoundingBox, EllipsoidTangentPlane, AxisAlignedBoundingBox, IntersectionTests, Plane, AttributeCompression, EncodedCartesian3, ArcType, EllipsoidRhumbLine, PolygonPipeline) { 'use strict';
  3. function createGeometryFromPositions(positions) {
  4. const length = positions.length;
  5. const flatPositions = new Float64Array(length * 3);
  6. const indices = IndexDatatype.IndexDatatype.createTypedArray(length, length * 2);
  7. let positionIndex = 0;
  8. let index = 0;
  9. for (let i = 0; i < length; i++) {
  10. const position = positions[i];
  11. flatPositions[positionIndex++] = position.x;
  12. flatPositions[positionIndex++] = position.y;
  13. flatPositions[positionIndex++] = position.z;
  14. indices[index++] = i;
  15. indices[index++] = (i + 1) % length;
  16. }
  17. const attributes = new GeometryAttributes.GeometryAttributes({
  18. position: new GeometryAttribute.GeometryAttribute({
  19. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  20. componentsPerAttribute: 3,
  21. values: flatPositions,
  22. }),
  23. });
  24. return new GeometryAttribute.Geometry({
  25. attributes: attributes,
  26. indices: indices,
  27. primitiveType: GeometryAttribute.PrimitiveType.LINES,
  28. });
  29. }
  30. /**
  31. * A description of the outline of a polygon composed of arbitrary coplanar positions.
  32. *
  33. * @alias CoplanarPolygonOutlineGeometry
  34. * @constructor
  35. *
  36. * @param {Object} options Object with the following properties:
  37. * @param {PolygonHierarchy} options.polygonHierarchy A polygon hierarchy that can include holes.
  38. *
  39. * @see CoplanarPolygonOutlineGeometry.createGeometry
  40. *
  41. * @example
  42. * const polygonOutline = new Cesium.CoplanarPolygonOutlineGeometry({
  43. * positions : Cesium.Cartesian3.fromDegreesArrayHeights([
  44. * -90.0, 30.0, 0.0,
  45. * -90.0, 30.0, 1000.0,
  46. * -80.0, 30.0, 1000.0,
  47. * -80.0, 30.0, 0.0
  48. * ])
  49. * });
  50. * const geometry = Cesium.CoplanarPolygonOutlineGeometry.createGeometry(polygonOutline);
  51. */
  52. function CoplanarPolygonOutlineGeometry(options) {
  53. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  54. const polygonHierarchy = options.polygonHierarchy;
  55. //>>includeStart('debug', pragmas.debug);
  56. RuntimeError.Check.defined("options.polygonHierarchy", polygonHierarchy);
  57. //>>includeEnd('debug');
  58. this._polygonHierarchy = polygonHierarchy;
  59. this._workerName = "createCoplanarPolygonOutlineGeometry";
  60. /**
  61. * The number of elements used to pack the object into an array.
  62. * @type {Number}
  63. */
  64. this.packedLength =
  65. PolygonGeometryLibrary.PolygonGeometryLibrary.computeHierarchyPackedLength(
  66. polygonHierarchy,
  67. Matrix2.Cartesian3
  68. ) + 1;
  69. }
  70. /**
  71. * A description of a coplanar polygon outline from an array of positions.
  72. *
  73. * @param {Object} options Object with the following properties:
  74. * @param {Cartesian3[]} options.positions An array of positions that defined the corner points of the polygon.
  75. * @returns {CoplanarPolygonOutlineGeometry}
  76. */
  77. CoplanarPolygonOutlineGeometry.fromPositions = function (options) {
  78. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  79. //>>includeStart('debug', pragmas.debug);
  80. RuntimeError.Check.defined("options.positions", options.positions);
  81. //>>includeEnd('debug');
  82. const newOptions = {
  83. polygonHierarchy: {
  84. positions: options.positions,
  85. },
  86. };
  87. return new CoplanarPolygonOutlineGeometry(newOptions);
  88. };
  89. /**
  90. * Stores the provided instance into the provided array.
  91. *
  92. * @param {CoplanarPolygonOutlineGeometry} value The value to pack.
  93. * @param {Number[]} array The array to pack into.
  94. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  95. *
  96. * @returns {Number[]} The array that was packed into
  97. */
  98. CoplanarPolygonOutlineGeometry.pack = function (value, array, startingIndex) {
  99. //>>includeStart('debug', pragmas.debug);
  100. RuntimeError.Check.typeOf.object("value", value);
  101. RuntimeError.Check.defined("array", array);
  102. //>>includeEnd('debug');
  103. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  104. startingIndex = PolygonGeometryLibrary.PolygonGeometryLibrary.packPolygonHierarchy(
  105. value._polygonHierarchy,
  106. array,
  107. startingIndex,
  108. Matrix2.Cartesian3
  109. );
  110. array[startingIndex] = value.packedLength;
  111. return array;
  112. };
  113. const scratchOptions = {
  114. polygonHierarchy: {},
  115. };
  116. /**
  117. * Retrieves an instance from a packed array.
  118. *
  119. * @param {Number[]} array The packed array.
  120. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  121. * @param {CoplanarPolygonOutlineGeometry} [result] The object into which to store the result.
  122. * @returns {CoplanarPolygonOutlineGeometry} The modified result parameter or a new CoplanarPolygonOutlineGeometry instance if one was not provided.
  123. */
  124. CoplanarPolygonOutlineGeometry.unpack = function (
  125. array,
  126. startingIndex,
  127. result
  128. ) {
  129. //>>includeStart('debug', pragmas.debug);
  130. RuntimeError.Check.defined("array", array);
  131. //>>includeEnd('debug');
  132. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  133. const polygonHierarchy = PolygonGeometryLibrary.PolygonGeometryLibrary.unpackPolygonHierarchy(
  134. array,
  135. startingIndex,
  136. Matrix2.Cartesian3
  137. );
  138. startingIndex = polygonHierarchy.startingIndex;
  139. delete polygonHierarchy.startingIndex;
  140. const packedLength = array[startingIndex];
  141. if (!defaultValue.defined(result)) {
  142. result = new CoplanarPolygonOutlineGeometry(scratchOptions);
  143. }
  144. result._polygonHierarchy = polygonHierarchy;
  145. result.packedLength = packedLength;
  146. return result;
  147. };
  148. /**
  149. * Computes the geometric representation of an arbitrary coplanar polygon, including its vertices, indices, and a bounding sphere.
  150. *
  151. * @param {CoplanarPolygonOutlineGeometry} polygonGeometry A description of the polygon.
  152. * @returns {Geometry|undefined} The computed vertices and indices.
  153. */
  154. CoplanarPolygonOutlineGeometry.createGeometry = function (polygonGeometry) {
  155. const polygonHierarchy = polygonGeometry._polygonHierarchy;
  156. let outerPositions = polygonHierarchy.positions;
  157. outerPositions = arrayRemoveDuplicates.arrayRemoveDuplicates(
  158. outerPositions,
  159. Matrix2.Cartesian3.equalsEpsilon,
  160. true
  161. );
  162. if (outerPositions.length < 3) {
  163. return;
  164. }
  165. const isValid = CoplanarPolygonGeometryLibrary.CoplanarPolygonGeometryLibrary.validOutline(outerPositions);
  166. if (!isValid) {
  167. return undefined;
  168. }
  169. const polygons = PolygonGeometryLibrary.PolygonGeometryLibrary.polygonOutlinesFromHierarchy(
  170. polygonHierarchy,
  171. false
  172. );
  173. if (polygons.length === 0) {
  174. return undefined;
  175. }
  176. const geometries = [];
  177. for (let i = 0; i < polygons.length; i++) {
  178. const geometryInstance = new GeometryInstance.GeometryInstance({
  179. geometry: createGeometryFromPositions(polygons[i]),
  180. });
  181. geometries.push(geometryInstance);
  182. }
  183. const geometry = GeometryPipeline.GeometryPipeline.combineInstances(geometries)[0];
  184. const boundingSphere = Transforms.BoundingSphere.fromPoints(polygonHierarchy.positions);
  185. return new GeometryAttribute.Geometry({
  186. attributes: geometry.attributes,
  187. indices: geometry.indices,
  188. primitiveType: geometry.primitiveType,
  189. boundingSphere: boundingSphere,
  190. });
  191. };
  192. function createCoplanarPolygonOutlineGeometry(polygonGeometry, offset) {
  193. if (defaultValue.defined(offset)) {
  194. polygonGeometry = CoplanarPolygonOutlineGeometry.unpack(
  195. polygonGeometry,
  196. offset
  197. );
  198. }
  199. polygonGeometry._ellipsoid = Matrix2.Ellipsoid.clone(polygonGeometry._ellipsoid);
  200. return CoplanarPolygonOutlineGeometry.createGeometry(polygonGeometry);
  201. }
  202. return createCoplanarPolygonOutlineGeometry;
  203. }));