createWallOutlineGeometry.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./defaultValue-94c3e563', './Matrix2-fc7e9822', './Transforms-a076dbe6', './ComponentDatatype-4a60b8d6', './RuntimeError-c581ca93', './GeometryAttribute-2ecf73f6', './GeometryAttributes-7df9bef6', './IndexDatatype-db156785', './WallGeometryLibrary-9abfba7e', './_commonjsHelpers-3aae1032-f55dc0c4', './combine-761d9c3f', './WebGLConstants-7dccdc96', './arrayRemoveDuplicates-06991c15', './PolylinePipeline-7608e667', './EllipsoidGeodesic-dc94f381', './EllipsoidRhumbLine-daebc75b', './IntersectionTests-5deed78b', './Plane-e20fba8c'], (function (defaultValue, Matrix2, Transforms, ComponentDatatype, RuntimeError, GeometryAttribute, GeometryAttributes, IndexDatatype, WallGeometryLibrary, _commonjsHelpers3aae1032, combine, WebGLConstants, arrayRemoveDuplicates, PolylinePipeline, EllipsoidGeodesic, EllipsoidRhumbLine, IntersectionTests, Plane) { 'use strict';
  3. const scratchCartesian3Position1 = new Matrix2.Cartesian3();
  4. const scratchCartesian3Position2 = new Matrix2.Cartesian3();
  5. /**
  6. * A description of a wall outline. A wall is defined by a series of points,
  7. * which extrude down to the ground. Optionally, they can extrude downwards to a specified height.
  8. *
  9. * @alias WallOutlineGeometry
  10. * @constructor
  11. *
  12. * @param {Object} options Object with the following properties:
  13. * @param {Cartesian3[]} options.positions An array of Cartesian objects, which are the points of the wall.
  14. * @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.
  15. * @param {Number[]} [options.maximumHeights] An array parallel to <code>positions</code> that give the maximum height of the
  16. * wall at <code>positions</code>. If undefined, the height of each position in used.
  17. * @param {Number[]} [options.minimumHeights] An array parallel to <code>positions</code> that give the minimum height of the
  18. * wall at <code>positions</code>. If undefined, the height at each position is 0.0.
  19. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for coordinate manipulation
  20. *
  21. * @exception {DeveloperError} positions length must be greater than or equal to 2.
  22. * @exception {DeveloperError} positions and maximumHeights must have the same length.
  23. * @exception {DeveloperError} positions and minimumHeights must have the same length.
  24. *
  25. * @see WallGeometry#createGeometry
  26. * @see WallGeometry#fromConstantHeight
  27. *
  28. * @example
  29. * // create a wall outline that spans from ground level to 10000 meters
  30. * const wall = new Cesium.WallOutlineGeometry({
  31. * positions : Cesium.Cartesian3.fromDegreesArrayHeights([
  32. * 19.0, 47.0, 10000.0,
  33. * 19.0, 48.0, 10000.0,
  34. * 20.0, 48.0, 10000.0,
  35. * 20.0, 47.0, 10000.0,
  36. * 19.0, 47.0, 10000.0
  37. * ])
  38. * });
  39. * const geometry = Cesium.WallOutlineGeometry.createGeometry(wall);
  40. */
  41. function WallOutlineGeometry(options) {
  42. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  43. const wallPositions = options.positions;
  44. const maximumHeights = options.maximumHeights;
  45. const minimumHeights = options.minimumHeights;
  46. //>>includeStart('debug', pragmas.debug);
  47. if (!defaultValue.defined(wallPositions)) {
  48. throw new RuntimeError.DeveloperError("options.positions is required.");
  49. }
  50. if (
  51. defaultValue.defined(maximumHeights) &&
  52. maximumHeights.length !== wallPositions.length
  53. ) {
  54. throw new RuntimeError.DeveloperError(
  55. "options.positions and options.maximumHeights must have the same length."
  56. );
  57. }
  58. if (
  59. defaultValue.defined(minimumHeights) &&
  60. minimumHeights.length !== wallPositions.length
  61. ) {
  62. throw new RuntimeError.DeveloperError(
  63. "options.positions and options.minimumHeights must have the same length."
  64. );
  65. }
  66. //>>includeEnd('debug');
  67. const granularity = defaultValue.defaultValue(
  68. options.granularity,
  69. ComponentDatatype.CesiumMath.RADIANS_PER_DEGREE
  70. );
  71. const ellipsoid = defaultValue.defaultValue(options.ellipsoid, Matrix2.Ellipsoid.WGS84);
  72. this._positions = wallPositions;
  73. this._minimumHeights = minimumHeights;
  74. this._maximumHeights = maximumHeights;
  75. this._granularity = granularity;
  76. this._ellipsoid = Matrix2.Ellipsoid.clone(ellipsoid);
  77. this._workerName = "createWallOutlineGeometry";
  78. let numComponents = 1 + wallPositions.length * Matrix2.Cartesian3.packedLength + 2;
  79. if (defaultValue.defined(minimumHeights)) {
  80. numComponents += minimumHeights.length;
  81. }
  82. if (defaultValue.defined(maximumHeights)) {
  83. numComponents += maximumHeights.length;
  84. }
  85. /**
  86. * The number of elements used to pack the object into an array.
  87. * @type {Number}
  88. */
  89. this.packedLength = numComponents + Matrix2.Ellipsoid.packedLength + 1;
  90. }
  91. /**
  92. * Stores the provided instance into the provided array.
  93. *
  94. * @param {WallOutlineGeometry} value The value to pack.
  95. * @param {Number[]} array The array to pack into.
  96. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  97. *
  98. * @returns {Number[]} The array that was packed into
  99. */
  100. WallOutlineGeometry.pack = function (value, array, startingIndex) {
  101. //>>includeStart('debug', pragmas.debug);
  102. if (!defaultValue.defined(value)) {
  103. throw new RuntimeError.DeveloperError("value is required");
  104. }
  105. if (!defaultValue.defined(array)) {
  106. throw new RuntimeError.DeveloperError("array is required");
  107. }
  108. //>>includeEnd('debug');
  109. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  110. let i;
  111. const positions = value._positions;
  112. let length = positions.length;
  113. array[startingIndex++] = length;
  114. for (i = 0; i < length; ++i, startingIndex += Matrix2.Cartesian3.packedLength) {
  115. Matrix2.Cartesian3.pack(positions[i], array, startingIndex);
  116. }
  117. const minimumHeights = value._minimumHeights;
  118. length = defaultValue.defined(minimumHeights) ? minimumHeights.length : 0;
  119. array[startingIndex++] = length;
  120. if (defaultValue.defined(minimumHeights)) {
  121. for (i = 0; i < length; ++i) {
  122. array[startingIndex++] = minimumHeights[i];
  123. }
  124. }
  125. const maximumHeights = value._maximumHeights;
  126. length = defaultValue.defined(maximumHeights) ? maximumHeights.length : 0;
  127. array[startingIndex++] = length;
  128. if (defaultValue.defined(maximumHeights)) {
  129. for (i = 0; i < length; ++i) {
  130. array[startingIndex++] = maximumHeights[i];
  131. }
  132. }
  133. Matrix2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  134. startingIndex += Matrix2.Ellipsoid.packedLength;
  135. array[startingIndex] = value._granularity;
  136. return array;
  137. };
  138. const scratchEllipsoid = Matrix2.Ellipsoid.clone(Matrix2.Ellipsoid.UNIT_SPHERE);
  139. const scratchOptions = {
  140. positions: undefined,
  141. minimumHeights: undefined,
  142. maximumHeights: undefined,
  143. ellipsoid: scratchEllipsoid,
  144. granularity: undefined,
  145. };
  146. /**
  147. * Retrieves an instance from a packed array.
  148. *
  149. * @param {Number[]} array The packed array.
  150. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  151. * @param {WallOutlineGeometry} [result] The object into which to store the result.
  152. * @returns {WallOutlineGeometry} The modified result parameter or a new WallOutlineGeometry instance if one was not provided.
  153. */
  154. WallOutlineGeometry.unpack = function (array, startingIndex, result) {
  155. //>>includeStart('debug', pragmas.debug);
  156. if (!defaultValue.defined(array)) {
  157. throw new RuntimeError.DeveloperError("array is required");
  158. }
  159. //>>includeEnd('debug');
  160. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  161. let i;
  162. let length = array[startingIndex++];
  163. const positions = new Array(length);
  164. for (i = 0; i < length; ++i, startingIndex += Matrix2.Cartesian3.packedLength) {
  165. positions[i] = Matrix2.Cartesian3.unpack(array, startingIndex);
  166. }
  167. length = array[startingIndex++];
  168. let minimumHeights;
  169. if (length > 0) {
  170. minimumHeights = new Array(length);
  171. for (i = 0; i < length; ++i) {
  172. minimumHeights[i] = array[startingIndex++];
  173. }
  174. }
  175. length = array[startingIndex++];
  176. let maximumHeights;
  177. if (length > 0) {
  178. maximumHeights = new Array(length);
  179. for (i = 0; i < length; ++i) {
  180. maximumHeights[i] = array[startingIndex++];
  181. }
  182. }
  183. const ellipsoid = Matrix2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  184. startingIndex += Matrix2.Ellipsoid.packedLength;
  185. const granularity = array[startingIndex];
  186. if (!defaultValue.defined(result)) {
  187. scratchOptions.positions = positions;
  188. scratchOptions.minimumHeights = minimumHeights;
  189. scratchOptions.maximumHeights = maximumHeights;
  190. scratchOptions.granularity = granularity;
  191. return new WallOutlineGeometry(scratchOptions);
  192. }
  193. result._positions = positions;
  194. result._minimumHeights = minimumHeights;
  195. result._maximumHeights = maximumHeights;
  196. result._ellipsoid = Matrix2.Ellipsoid.clone(ellipsoid, result._ellipsoid);
  197. result._granularity = granularity;
  198. return result;
  199. };
  200. /**
  201. * A description of a walloutline. A wall is defined by a series of points,
  202. * which extrude down to the ground. Optionally, they can extrude downwards to a specified height.
  203. *
  204. * @param {Object} options Object with the following properties:
  205. * @param {Cartesian3[]} options.positions An array of Cartesian objects, which are the points of the wall.
  206. * @param {Number} [options.maximumHeight] A constant that defines the maximum height of the
  207. * wall at <code>positions</code>. If undefined, the height of each position in used.
  208. * @param {Number} [options.minimumHeight] A constant that defines the minimum height of the
  209. * wall at <code>positions</code>. If undefined, the height at each position is 0.0.
  210. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for coordinate manipulation
  211. * @returns {WallOutlineGeometry}
  212. *
  213. *
  214. * @example
  215. * // create a wall that spans from 10000 meters to 20000 meters
  216. * const wall = Cesium.WallOutlineGeometry.fromConstantHeights({
  217. * positions : Cesium.Cartesian3.fromDegreesArray([
  218. * 19.0, 47.0,
  219. * 19.0, 48.0,
  220. * 20.0, 48.0,
  221. * 20.0, 47.0,
  222. * 19.0, 47.0,
  223. * ]),
  224. * minimumHeight : 20000.0,
  225. * maximumHeight : 10000.0
  226. * });
  227. * const geometry = Cesium.WallOutlineGeometry.createGeometry(wall);
  228. *
  229. * @see WallOutlineGeometry#createGeometry
  230. */
  231. WallOutlineGeometry.fromConstantHeights = function (options) {
  232. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  233. const positions = options.positions;
  234. //>>includeStart('debug', pragmas.debug);
  235. if (!defaultValue.defined(positions)) {
  236. throw new RuntimeError.DeveloperError("options.positions is required.");
  237. }
  238. //>>includeEnd('debug');
  239. let minHeights;
  240. let maxHeights;
  241. const min = options.minimumHeight;
  242. const max = options.maximumHeight;
  243. const doMin = defaultValue.defined(min);
  244. const doMax = defaultValue.defined(max);
  245. if (doMin || doMax) {
  246. const length = positions.length;
  247. minHeights = doMin ? new Array(length) : undefined;
  248. maxHeights = doMax ? new Array(length) : undefined;
  249. for (let i = 0; i < length; ++i) {
  250. if (doMin) {
  251. minHeights[i] = min;
  252. }
  253. if (doMax) {
  254. maxHeights[i] = max;
  255. }
  256. }
  257. }
  258. const newOptions = {
  259. positions: positions,
  260. maximumHeights: maxHeights,
  261. minimumHeights: minHeights,
  262. ellipsoid: options.ellipsoid,
  263. };
  264. return new WallOutlineGeometry(newOptions);
  265. };
  266. /**
  267. * Computes the geometric representation of a wall outline, including its vertices, indices, and a bounding sphere.
  268. *
  269. * @param {WallOutlineGeometry} wallGeometry A description of the wall outline.
  270. * @returns {Geometry|undefined} The computed vertices and indices.
  271. */
  272. WallOutlineGeometry.createGeometry = function (wallGeometry) {
  273. const wallPositions = wallGeometry._positions;
  274. const minimumHeights = wallGeometry._minimumHeights;
  275. const maximumHeights = wallGeometry._maximumHeights;
  276. const granularity = wallGeometry._granularity;
  277. const ellipsoid = wallGeometry._ellipsoid;
  278. const pos = WallGeometryLibrary.WallGeometryLibrary.computePositions(
  279. ellipsoid,
  280. wallPositions,
  281. maximumHeights,
  282. minimumHeights,
  283. granularity,
  284. false
  285. );
  286. if (!defaultValue.defined(pos)) {
  287. return;
  288. }
  289. const bottomPositions = pos.bottomPositions;
  290. const topPositions = pos.topPositions;
  291. let length = topPositions.length;
  292. let size = length * 2;
  293. const positions = new Float64Array(size);
  294. let positionIndex = 0;
  295. // add lower and upper points one after the other, lower
  296. // points being even and upper points being odd
  297. length /= 3;
  298. let i;
  299. for (i = 0; i < length; ++i) {
  300. const i3 = i * 3;
  301. const topPosition = Matrix2.Cartesian3.fromArray(
  302. topPositions,
  303. i3,
  304. scratchCartesian3Position1
  305. );
  306. const bottomPosition = Matrix2.Cartesian3.fromArray(
  307. bottomPositions,
  308. i3,
  309. scratchCartesian3Position2
  310. );
  311. // insert the lower point
  312. positions[positionIndex++] = bottomPosition.x;
  313. positions[positionIndex++] = bottomPosition.y;
  314. positions[positionIndex++] = bottomPosition.z;
  315. // insert the upper point
  316. positions[positionIndex++] = topPosition.x;
  317. positions[positionIndex++] = topPosition.y;
  318. positions[positionIndex++] = topPosition.z;
  319. }
  320. const attributes = new GeometryAttributes.GeometryAttributes({
  321. position: new GeometryAttribute.GeometryAttribute({
  322. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  323. componentsPerAttribute: 3,
  324. values: positions,
  325. }),
  326. });
  327. const numVertices = size / 3;
  328. size = 2 * numVertices - 4 + numVertices;
  329. const indices = IndexDatatype.IndexDatatype.createTypedArray(numVertices, size);
  330. let edgeIndex = 0;
  331. for (i = 0; i < numVertices - 2; i += 2) {
  332. const LL = i;
  333. const LR = i + 2;
  334. const pl = Matrix2.Cartesian3.fromArray(
  335. positions,
  336. LL * 3,
  337. scratchCartesian3Position1
  338. );
  339. const pr = Matrix2.Cartesian3.fromArray(
  340. positions,
  341. LR * 3,
  342. scratchCartesian3Position2
  343. );
  344. if (Matrix2.Cartesian3.equalsEpsilon(pl, pr, ComponentDatatype.CesiumMath.EPSILON10)) {
  345. continue;
  346. }
  347. const UL = i + 1;
  348. const UR = i + 3;
  349. indices[edgeIndex++] = UL;
  350. indices[edgeIndex++] = LL;
  351. indices[edgeIndex++] = UL;
  352. indices[edgeIndex++] = UR;
  353. indices[edgeIndex++] = LL;
  354. indices[edgeIndex++] = LR;
  355. }
  356. indices[edgeIndex++] = numVertices - 2;
  357. indices[edgeIndex++] = numVertices - 1;
  358. return new GeometryAttribute.Geometry({
  359. attributes: attributes,
  360. indices: indices,
  361. primitiveType: GeometryAttribute.PrimitiveType.LINES,
  362. boundingSphere: new Transforms.BoundingSphere.fromVertices(positions),
  363. });
  364. };
  365. function createWallOutlineGeometry(wallGeometry, offset) {
  366. if (defaultValue.defined(offset)) {
  367. wallGeometry = WallOutlineGeometry.unpack(wallGeometry, offset);
  368. }
  369. wallGeometry._ellipsoid = Matrix2.Ellipsoid.clone(wallGeometry._ellipsoid);
  370. return WallOutlineGeometry.createGeometry(wallGeometry);
  371. }
  372. return createWallOutlineGeometry;
  373. }));