createPolylineVolumeOutlineGeometry.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./defaultValue-94c3e563', './Matrix2-69c32d33', './arrayRemoveDuplicates-87160c89', './BoundingRectangle-41078ce4', './Transforms-323408fe', './ComponentDatatype-b1ea011a', './PolylineVolumeGeometryLibrary-8388aac3', './RuntimeError-c581ca93', './GeometryAttribute-cb73bb3f', './GeometryAttributes-7df9bef6', './IndexDatatype-c4099fe9', './PolygonPipeline-d1884135', './_commonjsHelpers-3aae1032-f55dc0c4', './combine-761d9c3f', './WebGLConstants-7dccdc96', './EllipsoidTangentPlane-1e8d1fc2', './AxisAlignedBoundingBox-df2331b2', './IntersectionTests-d5d945ac', './Plane-069b6800', './PolylinePipeline-aa50e501', './EllipsoidGeodesic-98096082', './EllipsoidRhumbLine-5cb6da82'], (function (defaultValue, Matrix2, arrayRemoveDuplicates, BoundingRectangle, Transforms, ComponentDatatype, PolylineVolumeGeometryLibrary, RuntimeError, GeometryAttribute, GeometryAttributes, IndexDatatype, PolygonPipeline, _commonjsHelpers3aae1032, combine, WebGLConstants, EllipsoidTangentPlane, AxisAlignedBoundingBox, IntersectionTests, Plane, PolylinePipeline, EllipsoidGeodesic, EllipsoidRhumbLine) { 'use strict';
  3. function computeAttributes(positions, shape) {
  4. const attributes = new GeometryAttributes.GeometryAttributes();
  5. attributes.position = new GeometryAttribute.GeometryAttribute({
  6. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  7. componentsPerAttribute: 3,
  8. values: positions,
  9. });
  10. const shapeLength = shape.length;
  11. const vertexCount = attributes.position.values.length / 3;
  12. const positionLength = positions.length / 3;
  13. const shapeCount = positionLength / shapeLength;
  14. const indices = IndexDatatype.IndexDatatype.createTypedArray(
  15. vertexCount,
  16. 2 * shapeLength * (shapeCount + 1)
  17. );
  18. let i, j;
  19. let index = 0;
  20. i = 0;
  21. let offset = i * shapeLength;
  22. for (j = 0; j < shapeLength - 1; j++) {
  23. indices[index++] = j + offset;
  24. indices[index++] = j + offset + 1;
  25. }
  26. indices[index++] = shapeLength - 1 + offset;
  27. indices[index++] = offset;
  28. i = shapeCount - 1;
  29. offset = i * shapeLength;
  30. for (j = 0; j < shapeLength - 1; j++) {
  31. indices[index++] = j + offset;
  32. indices[index++] = j + offset + 1;
  33. }
  34. indices[index++] = shapeLength - 1 + offset;
  35. indices[index++] = offset;
  36. for (i = 0; i < shapeCount - 1; i++) {
  37. const firstOffset = shapeLength * i;
  38. const secondOffset = firstOffset + shapeLength;
  39. for (j = 0; j < shapeLength; j++) {
  40. indices[index++] = j + firstOffset;
  41. indices[index++] = j + secondOffset;
  42. }
  43. }
  44. const geometry = new GeometryAttribute.Geometry({
  45. attributes: attributes,
  46. indices: IndexDatatype.IndexDatatype.createTypedArray(vertexCount, indices),
  47. boundingSphere: Transforms.BoundingSphere.fromVertices(positions),
  48. primitiveType: GeometryAttribute.PrimitiveType.LINES,
  49. });
  50. return geometry;
  51. }
  52. /**
  53. * A description of a polyline with a volume (a 2D shape extruded along a polyline).
  54. *
  55. * @alias PolylineVolumeOutlineGeometry
  56. * @constructor
  57. *
  58. * @param {Object} options Object with the following properties:
  59. * @param {Cartesian3[]} options.polylinePositions An array of positions that define the center of the polyline volume.
  60. * @param {Cartesian2[]} options.shapePositions An array of positions that define the shape to be extruded along the polyline
  61. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.
  62. * @param {Number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.
  63. * @param {CornerType} [options.cornerType=CornerType.ROUNDED] Determines the style of the corners.
  64. *
  65. * @see PolylineVolumeOutlineGeometry#createGeometry
  66. *
  67. * @example
  68. * function computeCircle(radius) {
  69. * const positions = [];
  70. * for (let i = 0; i < 360; i++) {
  71. * const radians = Cesium.Math.toRadians(i);
  72. * positions.push(new Cesium.Cartesian2(radius * Math.cos(radians), radius * Math.sin(radians)));
  73. * }
  74. * return positions;
  75. * }
  76. *
  77. * const volumeOutline = new Cesium.PolylineVolumeOutlineGeometry({
  78. * polylinePositions : Cesium.Cartesian3.fromDegreesArray([
  79. * -72.0, 40.0,
  80. * -70.0, 35.0
  81. * ]),
  82. * shapePositions : computeCircle(100000.0)
  83. * });
  84. */
  85. function PolylineVolumeOutlineGeometry(options) {
  86. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  87. const positions = options.polylinePositions;
  88. const shape = options.shapePositions;
  89. //>>includeStart('debug', pragmas.debug);
  90. if (!defaultValue.defined(positions)) {
  91. throw new RuntimeError.DeveloperError("options.polylinePositions is required.");
  92. }
  93. if (!defaultValue.defined(shape)) {
  94. throw new RuntimeError.DeveloperError("options.shapePositions is required.");
  95. }
  96. //>>includeEnd('debug');
  97. this._positions = positions;
  98. this._shape = shape;
  99. this._ellipsoid = Matrix2.Ellipsoid.clone(
  100. defaultValue.defaultValue(options.ellipsoid, Matrix2.Ellipsoid.WGS84)
  101. );
  102. this._cornerType = defaultValue.defaultValue(options.cornerType, PolylineVolumeGeometryLibrary.CornerType.ROUNDED);
  103. this._granularity = defaultValue.defaultValue(
  104. options.granularity,
  105. ComponentDatatype.CesiumMath.RADIANS_PER_DEGREE
  106. );
  107. this._workerName = "createPolylineVolumeOutlineGeometry";
  108. let numComponents = 1 + positions.length * Matrix2.Cartesian3.packedLength;
  109. numComponents += 1 + shape.length * Matrix2.Cartesian2.packedLength;
  110. /**
  111. * The number of elements used to pack the object into an array.
  112. * @type {Number}
  113. */
  114. this.packedLength = numComponents + Matrix2.Ellipsoid.packedLength + 2;
  115. }
  116. /**
  117. * Stores the provided instance into the provided array.
  118. *
  119. * @param {PolylineVolumeOutlineGeometry} value The value to pack.
  120. * @param {Number[]} array The array to pack into.
  121. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  122. *
  123. * @returns {Number[]} The array that was packed into
  124. */
  125. PolylineVolumeOutlineGeometry.pack = function (value, array, startingIndex) {
  126. //>>includeStart('debug', pragmas.debug);
  127. if (!defaultValue.defined(value)) {
  128. throw new RuntimeError.DeveloperError("value is required");
  129. }
  130. if (!defaultValue.defined(array)) {
  131. throw new RuntimeError.DeveloperError("array is required");
  132. }
  133. //>>includeEnd('debug');
  134. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  135. let i;
  136. const positions = value._positions;
  137. let length = positions.length;
  138. array[startingIndex++] = length;
  139. for (i = 0; i < length; ++i, startingIndex += Matrix2.Cartesian3.packedLength) {
  140. Matrix2.Cartesian3.pack(positions[i], array, startingIndex);
  141. }
  142. const shape = value._shape;
  143. length = shape.length;
  144. array[startingIndex++] = length;
  145. for (i = 0; i < length; ++i, startingIndex += Matrix2.Cartesian2.packedLength) {
  146. Matrix2.Cartesian2.pack(shape[i], array, startingIndex);
  147. }
  148. Matrix2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  149. startingIndex += Matrix2.Ellipsoid.packedLength;
  150. array[startingIndex++] = value._cornerType;
  151. array[startingIndex] = value._granularity;
  152. return array;
  153. };
  154. const scratchEllipsoid = Matrix2.Ellipsoid.clone(Matrix2.Ellipsoid.UNIT_SPHERE);
  155. const scratchOptions = {
  156. polylinePositions: undefined,
  157. shapePositions: undefined,
  158. ellipsoid: scratchEllipsoid,
  159. height: undefined,
  160. cornerType: undefined,
  161. granularity: undefined,
  162. };
  163. /**
  164. * Retrieves an instance from a packed array.
  165. *
  166. * @param {Number[]} array The packed array.
  167. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  168. * @param {PolylineVolumeOutlineGeometry} [result] The object into which to store the result.
  169. * @returns {PolylineVolumeOutlineGeometry} The modified result parameter or a new PolylineVolumeOutlineGeometry instance if one was not provided.
  170. */
  171. PolylineVolumeOutlineGeometry.unpack = function (array, startingIndex, result) {
  172. //>>includeStart('debug', pragmas.debug);
  173. if (!defaultValue.defined(array)) {
  174. throw new RuntimeError.DeveloperError("array is required");
  175. }
  176. //>>includeEnd('debug');
  177. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  178. let i;
  179. let length = array[startingIndex++];
  180. const positions = new Array(length);
  181. for (i = 0; i < length; ++i, startingIndex += Matrix2.Cartesian3.packedLength) {
  182. positions[i] = Matrix2.Cartesian3.unpack(array, startingIndex);
  183. }
  184. length = array[startingIndex++];
  185. const shape = new Array(length);
  186. for (i = 0; i < length; ++i, startingIndex += Matrix2.Cartesian2.packedLength) {
  187. shape[i] = Matrix2.Cartesian2.unpack(array, startingIndex);
  188. }
  189. const ellipsoid = Matrix2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  190. startingIndex += Matrix2.Ellipsoid.packedLength;
  191. const cornerType = array[startingIndex++];
  192. const granularity = array[startingIndex];
  193. if (!defaultValue.defined(result)) {
  194. scratchOptions.polylinePositions = positions;
  195. scratchOptions.shapePositions = shape;
  196. scratchOptions.cornerType = cornerType;
  197. scratchOptions.granularity = granularity;
  198. return new PolylineVolumeOutlineGeometry(scratchOptions);
  199. }
  200. result._positions = positions;
  201. result._shape = shape;
  202. result._ellipsoid = Matrix2.Ellipsoid.clone(ellipsoid, result._ellipsoid);
  203. result._cornerType = cornerType;
  204. result._granularity = granularity;
  205. return result;
  206. };
  207. const brScratch = new BoundingRectangle.BoundingRectangle();
  208. /**
  209. * Computes the geometric representation of the outline of a polyline with a volume, including its vertices, indices, and a bounding sphere.
  210. *
  211. * @param {PolylineVolumeOutlineGeometry} polylineVolumeOutlineGeometry A description of the polyline volume outline.
  212. * @returns {Geometry|undefined} The computed vertices and indices.
  213. */
  214. PolylineVolumeOutlineGeometry.createGeometry = function (
  215. polylineVolumeOutlineGeometry
  216. ) {
  217. const positions = polylineVolumeOutlineGeometry._positions;
  218. const cleanPositions = arrayRemoveDuplicates.arrayRemoveDuplicates(
  219. positions,
  220. Matrix2.Cartesian3.equalsEpsilon
  221. );
  222. let shape2D = polylineVolumeOutlineGeometry._shape;
  223. shape2D = PolylineVolumeGeometryLibrary.PolylineVolumeGeometryLibrary.removeDuplicatesFromShape(shape2D);
  224. if (cleanPositions.length < 2 || shape2D.length < 3) {
  225. return undefined;
  226. }
  227. if (
  228. PolygonPipeline.PolygonPipeline.computeWindingOrder2D(shape2D) === PolygonPipeline.WindingOrder.CLOCKWISE
  229. ) {
  230. shape2D.reverse();
  231. }
  232. const boundingRectangle = BoundingRectangle.BoundingRectangle.fromPoints(shape2D, brScratch);
  233. const computedPositions = PolylineVolumeGeometryLibrary.PolylineVolumeGeometryLibrary.computePositions(
  234. cleanPositions,
  235. shape2D,
  236. boundingRectangle,
  237. polylineVolumeOutlineGeometry,
  238. false
  239. );
  240. return computeAttributes(computedPositions, shape2D);
  241. };
  242. function createPolylineVolumeOutlineGeometry(
  243. polylineVolumeOutlineGeometry,
  244. offset
  245. ) {
  246. if (defaultValue.defined(offset)) {
  247. polylineVolumeOutlineGeometry = PolylineVolumeOutlineGeometry.unpack(
  248. polylineVolumeOutlineGeometry,
  249. offset
  250. );
  251. }
  252. polylineVolumeOutlineGeometry._ellipsoid = Matrix2.Ellipsoid.clone(
  253. polylineVolumeOutlineGeometry._ellipsoid
  254. );
  255. return PolylineVolumeOutlineGeometry.createGeometry(
  256. polylineVolumeOutlineGeometry
  257. );
  258. }
  259. return createPolylineVolumeOutlineGeometry;
  260. }));