createRectangleOutlineGeometry.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./defaultValue-94c3e563', './Matrix2-fc7e9822', './GeometryOffsetAttribute-3e8c299c', './Transforms-a076dbe6', './ComponentDatatype-4a60b8d6', './RuntimeError-c581ca93', './GeometryAttribute-2ecf73f6', './GeometryAttributes-7df9bef6', './IndexDatatype-db156785', './PolygonPipeline-cc031b9f', './RectangleGeometryLibrary-36556359', './_commonjsHelpers-3aae1032-f55dc0c4', './combine-761d9c3f', './WebGLConstants-7dccdc96', './EllipsoidRhumbLine-daebc75b'], (function (defaultValue, Matrix2, GeometryOffsetAttribute, Transforms, ComponentDatatype, RuntimeError, GeometryAttribute, GeometryAttributes, IndexDatatype, PolygonPipeline, RectangleGeometryLibrary, _commonjsHelpers3aae1032, combine, WebGLConstants, EllipsoidRhumbLine) { 'use strict';
  3. const bottomBoundingSphere = new Transforms.BoundingSphere();
  4. const topBoundingSphere = new Transforms.BoundingSphere();
  5. const positionScratch = new Matrix2.Cartesian3();
  6. const rectangleScratch = new Matrix2.Rectangle();
  7. function constructRectangle(geometry, computedOptions) {
  8. const ellipsoid = geometry._ellipsoid;
  9. const height = computedOptions.height;
  10. const width = computedOptions.width;
  11. const northCap = computedOptions.northCap;
  12. const southCap = computedOptions.southCap;
  13. let rowHeight = height;
  14. let widthMultiplier = 2;
  15. let size = 0;
  16. let corners = 4;
  17. if (northCap) {
  18. widthMultiplier -= 1;
  19. rowHeight -= 1;
  20. size += 1;
  21. corners -= 2;
  22. }
  23. if (southCap) {
  24. widthMultiplier -= 1;
  25. rowHeight -= 1;
  26. size += 1;
  27. corners -= 2;
  28. }
  29. size += widthMultiplier * width + 2 * rowHeight - corners;
  30. const positions = new Float64Array(size * 3);
  31. let posIndex = 0;
  32. let row = 0;
  33. let col;
  34. const position = positionScratch;
  35. if (northCap) {
  36. RectangleGeometryLibrary.RectangleGeometryLibrary.computePosition(
  37. computedOptions,
  38. ellipsoid,
  39. false,
  40. row,
  41. 0,
  42. position
  43. );
  44. positions[posIndex++] = position.x;
  45. positions[posIndex++] = position.y;
  46. positions[posIndex++] = position.z;
  47. } else {
  48. for (col = 0; col < width; col++) {
  49. RectangleGeometryLibrary.RectangleGeometryLibrary.computePosition(
  50. computedOptions,
  51. ellipsoid,
  52. false,
  53. row,
  54. col,
  55. position
  56. );
  57. positions[posIndex++] = position.x;
  58. positions[posIndex++] = position.y;
  59. positions[posIndex++] = position.z;
  60. }
  61. }
  62. col = width - 1;
  63. for (row = 1; row < height; row++) {
  64. RectangleGeometryLibrary.RectangleGeometryLibrary.computePosition(
  65. computedOptions,
  66. ellipsoid,
  67. false,
  68. row,
  69. col,
  70. position
  71. );
  72. positions[posIndex++] = position.x;
  73. positions[posIndex++] = position.y;
  74. positions[posIndex++] = position.z;
  75. }
  76. row = height - 1;
  77. if (!southCap) {
  78. // if southCap is true, we dont need to add any more points because the south pole point was added by the iteration above
  79. for (col = width - 2; col >= 0; col--) {
  80. RectangleGeometryLibrary.RectangleGeometryLibrary.computePosition(
  81. computedOptions,
  82. ellipsoid,
  83. false,
  84. row,
  85. col,
  86. position
  87. );
  88. positions[posIndex++] = position.x;
  89. positions[posIndex++] = position.y;
  90. positions[posIndex++] = position.z;
  91. }
  92. }
  93. col = 0;
  94. for (row = height - 2; row > 0; row--) {
  95. RectangleGeometryLibrary.RectangleGeometryLibrary.computePosition(
  96. computedOptions,
  97. ellipsoid,
  98. false,
  99. row,
  100. col,
  101. position
  102. );
  103. positions[posIndex++] = position.x;
  104. positions[posIndex++] = position.y;
  105. positions[posIndex++] = position.z;
  106. }
  107. const indicesSize = (positions.length / 3) * 2;
  108. const indices = IndexDatatype.IndexDatatype.createTypedArray(
  109. positions.length / 3,
  110. indicesSize
  111. );
  112. let index = 0;
  113. for (let i = 0; i < positions.length / 3 - 1; i++) {
  114. indices[index++] = i;
  115. indices[index++] = i + 1;
  116. }
  117. indices[index++] = positions.length / 3 - 1;
  118. indices[index++] = 0;
  119. const geo = new GeometryAttribute.Geometry({
  120. attributes: new GeometryAttributes.GeometryAttributes(),
  121. primitiveType: GeometryAttribute.PrimitiveType.LINES,
  122. });
  123. geo.attributes.position = new GeometryAttribute.GeometryAttribute({
  124. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  125. componentsPerAttribute: 3,
  126. values: positions,
  127. });
  128. geo.indices = indices;
  129. return geo;
  130. }
  131. function constructExtrudedRectangle(rectangleGeometry, computedOptions) {
  132. const surfaceHeight = rectangleGeometry._surfaceHeight;
  133. const extrudedHeight = rectangleGeometry._extrudedHeight;
  134. const ellipsoid = rectangleGeometry._ellipsoid;
  135. const minHeight = extrudedHeight;
  136. const maxHeight = surfaceHeight;
  137. const geo = constructRectangle(rectangleGeometry, computedOptions);
  138. const height = computedOptions.height;
  139. const width = computedOptions.width;
  140. const topPositions = PolygonPipeline.PolygonPipeline.scaleToGeodeticHeight(
  141. geo.attributes.position.values,
  142. maxHeight,
  143. ellipsoid,
  144. false
  145. );
  146. let length = topPositions.length;
  147. const positions = new Float64Array(length * 2);
  148. positions.set(topPositions);
  149. const bottomPositions = PolygonPipeline.PolygonPipeline.scaleToGeodeticHeight(
  150. geo.attributes.position.values,
  151. minHeight,
  152. ellipsoid
  153. );
  154. positions.set(bottomPositions, length);
  155. geo.attributes.position.values = positions;
  156. const northCap = computedOptions.northCap;
  157. const southCap = computedOptions.southCap;
  158. let corners = 4;
  159. if (northCap) {
  160. corners -= 1;
  161. }
  162. if (southCap) {
  163. corners -= 1;
  164. }
  165. const indicesSize = (positions.length / 3 + corners) * 2;
  166. const indices = IndexDatatype.IndexDatatype.createTypedArray(
  167. positions.length / 3,
  168. indicesSize
  169. );
  170. length = positions.length / 6;
  171. let index = 0;
  172. for (let i = 0; i < length - 1; i++) {
  173. indices[index++] = i;
  174. indices[index++] = i + 1;
  175. indices[index++] = i + length;
  176. indices[index++] = i + length + 1;
  177. }
  178. indices[index++] = length - 1;
  179. indices[index++] = 0;
  180. indices[index++] = length + length - 1;
  181. indices[index++] = length;
  182. indices[index++] = 0;
  183. indices[index++] = length;
  184. let bottomCorner;
  185. if (northCap) {
  186. bottomCorner = height - 1;
  187. } else {
  188. const topRightCorner = width - 1;
  189. indices[index++] = topRightCorner;
  190. indices[index++] = topRightCorner + length;
  191. bottomCorner = width + height - 2;
  192. }
  193. indices[index++] = bottomCorner;
  194. indices[index++] = bottomCorner + length;
  195. if (!southCap) {
  196. const bottomLeftCorner = width + bottomCorner - 1;
  197. indices[index++] = bottomLeftCorner;
  198. indices[index] = bottomLeftCorner + length;
  199. }
  200. geo.indices = indices;
  201. return geo;
  202. }
  203. /**
  204. * A description of the outline of a a cartographic rectangle on an ellipsoid centered at the origin.
  205. *
  206. * @alias RectangleOutlineGeometry
  207. * @constructor
  208. *
  209. * @param {Object} options Object with the following properties:
  210. * @param {Rectangle} options.rectangle A cartographic rectangle with north, south, east and west properties in radians.
  211. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the rectangle lies.
  212. * @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.
  213. * @param {Number} [options.height=0.0] The distance in meters between the rectangle and the ellipsoid surface.
  214. * @param {Number} [options.rotation=0.0] The rotation of the rectangle, in radians. A positive rotation is counter-clockwise.
  215. * @param {Number} [options.extrudedHeight] The distance in meters between the rectangle's extruded face and the ellipsoid surface.
  216. *
  217. * @exception {DeveloperError} <code>options.rectangle.north</code> must be in the interval [<code>-Pi/2</code>, <code>Pi/2</code>].
  218. * @exception {DeveloperError} <code>options.rectangle.south</code> must be in the interval [<code>-Pi/2</code>, <code>Pi/2</code>].
  219. * @exception {DeveloperError} <code>options.rectangle.east</code> must be in the interval [<code>-Pi</code>, <code>Pi</code>].
  220. * @exception {DeveloperError} <code>options.rectangle.west</code> must be in the interval [<code>-Pi</code>, <code>Pi</code>].
  221. * @exception {DeveloperError} <code>options.rectangle.north</code> must be greater than <code>rectangle.south</code>.
  222. *
  223. * @see RectangleOutlineGeometry#createGeometry
  224. *
  225. * @example
  226. * const rectangle = new Cesium.RectangleOutlineGeometry({
  227. * ellipsoid : Cesium.Ellipsoid.WGS84,
  228. * rectangle : Cesium.Rectangle.fromDegrees(-80.0, 39.0, -74.0, 42.0),
  229. * height : 10000.0
  230. * });
  231. * const geometry = Cesium.RectangleOutlineGeometry.createGeometry(rectangle);
  232. */
  233. function RectangleOutlineGeometry(options) {
  234. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  235. const rectangle = options.rectangle;
  236. const granularity = defaultValue.defaultValue(
  237. options.granularity,
  238. ComponentDatatype.CesiumMath.RADIANS_PER_DEGREE
  239. );
  240. const ellipsoid = defaultValue.defaultValue(options.ellipsoid, Matrix2.Ellipsoid.WGS84);
  241. const rotation = defaultValue.defaultValue(options.rotation, 0.0);
  242. //>>includeStart('debug', pragmas.debug);
  243. if (!defaultValue.defined(rectangle)) {
  244. throw new RuntimeError.DeveloperError("rectangle is required.");
  245. }
  246. Matrix2.Rectangle.validate(rectangle);
  247. if (rectangle.north < rectangle.south) {
  248. throw new RuntimeError.DeveloperError(
  249. "options.rectangle.north must be greater than options.rectangle.south"
  250. );
  251. }
  252. //>>includeEnd('debug');
  253. const height = defaultValue.defaultValue(options.height, 0.0);
  254. const extrudedHeight = defaultValue.defaultValue(options.extrudedHeight, height);
  255. this._rectangle = Matrix2.Rectangle.clone(rectangle);
  256. this._granularity = granularity;
  257. this._ellipsoid = ellipsoid;
  258. this._surfaceHeight = Math.max(height, extrudedHeight);
  259. this._rotation = rotation;
  260. this._extrudedHeight = Math.min(height, extrudedHeight);
  261. this._offsetAttribute = options.offsetAttribute;
  262. this._workerName = "createRectangleOutlineGeometry";
  263. }
  264. /**
  265. * The number of elements used to pack the object into an array.
  266. * @type {Number}
  267. */
  268. RectangleOutlineGeometry.packedLength =
  269. Matrix2.Rectangle.packedLength + Matrix2.Ellipsoid.packedLength + 5;
  270. /**
  271. * Stores the provided instance into the provided array.
  272. *
  273. * @param {RectangleOutlineGeometry} value The value to pack.
  274. * @param {Number[]} array The array to pack into.
  275. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  276. *
  277. * @returns {Number[]} The array that was packed into
  278. */
  279. RectangleOutlineGeometry.pack = function (value, array, startingIndex) {
  280. //>>includeStart('debug', pragmas.debug);
  281. if (!defaultValue.defined(value)) {
  282. throw new RuntimeError.DeveloperError("value is required");
  283. }
  284. if (!defaultValue.defined(array)) {
  285. throw new RuntimeError.DeveloperError("array is required");
  286. }
  287. //>>includeEnd('debug');
  288. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  289. Matrix2.Rectangle.pack(value._rectangle, array, startingIndex);
  290. startingIndex += Matrix2.Rectangle.packedLength;
  291. Matrix2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  292. startingIndex += Matrix2.Ellipsoid.packedLength;
  293. array[startingIndex++] = value._granularity;
  294. array[startingIndex++] = value._surfaceHeight;
  295. array[startingIndex++] = value._rotation;
  296. array[startingIndex++] = value._extrudedHeight;
  297. array[startingIndex] = defaultValue.defaultValue(value._offsetAttribute, -1);
  298. return array;
  299. };
  300. const scratchRectangle = new Matrix2.Rectangle();
  301. const scratchEllipsoid = Matrix2.Ellipsoid.clone(Matrix2.Ellipsoid.UNIT_SPHERE);
  302. const scratchOptions = {
  303. rectangle: scratchRectangle,
  304. ellipsoid: scratchEllipsoid,
  305. granularity: undefined,
  306. height: undefined,
  307. rotation: undefined,
  308. extrudedHeight: undefined,
  309. offsetAttribute: undefined,
  310. };
  311. /**
  312. * Retrieves an instance from a packed array.
  313. *
  314. * @param {Number[]} array The packed array.
  315. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  316. * @param {RectangleOutlineGeometry} [result] The object into which to store the result.
  317. * @returns {RectangleOutlineGeometry} The modified result parameter or a new Quaternion instance if one was not provided.
  318. */
  319. RectangleOutlineGeometry.unpack = function (array, startingIndex, result) {
  320. //>>includeStart('debug', pragmas.debug);
  321. if (!defaultValue.defined(array)) {
  322. throw new RuntimeError.DeveloperError("array is required");
  323. }
  324. //>>includeEnd('debug');
  325. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  326. const rectangle = Matrix2.Rectangle.unpack(array, startingIndex, scratchRectangle);
  327. startingIndex += Matrix2.Rectangle.packedLength;
  328. const ellipsoid = Matrix2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  329. startingIndex += Matrix2.Ellipsoid.packedLength;
  330. const granularity = array[startingIndex++];
  331. const height = array[startingIndex++];
  332. const rotation = array[startingIndex++];
  333. const extrudedHeight = array[startingIndex++];
  334. const offsetAttribute = array[startingIndex];
  335. if (!defaultValue.defined(result)) {
  336. scratchOptions.granularity = granularity;
  337. scratchOptions.height = height;
  338. scratchOptions.rotation = rotation;
  339. scratchOptions.extrudedHeight = extrudedHeight;
  340. scratchOptions.offsetAttribute =
  341. offsetAttribute === -1 ? undefined : offsetAttribute;
  342. return new RectangleOutlineGeometry(scratchOptions);
  343. }
  344. result._rectangle = Matrix2.Rectangle.clone(rectangle, result._rectangle);
  345. result._ellipsoid = Matrix2.Ellipsoid.clone(ellipsoid, result._ellipsoid);
  346. result._surfaceHeight = height;
  347. result._rotation = rotation;
  348. result._extrudedHeight = extrudedHeight;
  349. result._offsetAttribute =
  350. offsetAttribute === -1 ? undefined : offsetAttribute;
  351. return result;
  352. };
  353. const nwScratch = new Matrix2.Cartographic();
  354. /**
  355. * Computes the geometric representation of an outline of a rectangle, including its vertices, indices, and a bounding sphere.
  356. *
  357. * @param {RectangleOutlineGeometry} rectangleGeometry A description of the rectangle outline.
  358. * @returns {Geometry|undefined} The computed vertices and indices.
  359. *
  360. * @exception {DeveloperError} Rotated rectangle is invalid.
  361. */
  362. RectangleOutlineGeometry.createGeometry = function (rectangleGeometry) {
  363. const rectangle = rectangleGeometry._rectangle;
  364. const ellipsoid = rectangleGeometry._ellipsoid;
  365. const computedOptions = RectangleGeometryLibrary.RectangleGeometryLibrary.computeOptions(
  366. rectangle,
  367. rectangleGeometry._granularity,
  368. rectangleGeometry._rotation,
  369. 0,
  370. rectangleScratch,
  371. nwScratch
  372. );
  373. let geometry;
  374. let boundingSphere;
  375. if (
  376. ComponentDatatype.CesiumMath.equalsEpsilon(
  377. rectangle.north,
  378. rectangle.south,
  379. ComponentDatatype.CesiumMath.EPSILON10
  380. ) ||
  381. ComponentDatatype.CesiumMath.equalsEpsilon(
  382. rectangle.east,
  383. rectangle.west,
  384. ComponentDatatype.CesiumMath.EPSILON10
  385. )
  386. ) {
  387. return undefined;
  388. }
  389. const surfaceHeight = rectangleGeometry._surfaceHeight;
  390. const extrudedHeight = rectangleGeometry._extrudedHeight;
  391. const extrude = !ComponentDatatype.CesiumMath.equalsEpsilon(
  392. surfaceHeight,
  393. extrudedHeight,
  394. 0,
  395. ComponentDatatype.CesiumMath.EPSILON2
  396. );
  397. let offsetValue;
  398. if (extrude) {
  399. geometry = constructExtrudedRectangle(rectangleGeometry, computedOptions);
  400. if (defaultValue.defined(rectangleGeometry._offsetAttribute)) {
  401. const size = geometry.attributes.position.values.length / 3;
  402. let offsetAttribute = new Uint8Array(size);
  403. if (rectangleGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.TOP) {
  404. offsetAttribute = GeometryOffsetAttribute.arrayFill(offsetAttribute, 1, 0, size / 2);
  405. } else {
  406. offsetValue =
  407. rectangleGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE
  408. ? 0
  409. : 1;
  410. offsetAttribute = GeometryOffsetAttribute.arrayFill(offsetAttribute, offsetValue);
  411. }
  412. geometry.attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  413. componentDatatype: ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  414. componentsPerAttribute: 1,
  415. values: offsetAttribute,
  416. });
  417. }
  418. const topBS = Transforms.BoundingSphere.fromRectangle3D(
  419. rectangle,
  420. ellipsoid,
  421. surfaceHeight,
  422. topBoundingSphere
  423. );
  424. const bottomBS = Transforms.BoundingSphere.fromRectangle3D(
  425. rectangle,
  426. ellipsoid,
  427. extrudedHeight,
  428. bottomBoundingSphere
  429. );
  430. boundingSphere = Transforms.BoundingSphere.union(topBS, bottomBS);
  431. } else {
  432. geometry = constructRectangle(rectangleGeometry, computedOptions);
  433. geometry.attributes.position.values = PolygonPipeline.PolygonPipeline.scaleToGeodeticHeight(
  434. geometry.attributes.position.values,
  435. surfaceHeight,
  436. ellipsoid,
  437. false
  438. );
  439. if (defaultValue.defined(rectangleGeometry._offsetAttribute)) {
  440. const length = geometry.attributes.position.values.length;
  441. const applyOffset = new Uint8Array(length / 3);
  442. offsetValue =
  443. rectangleGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE
  444. ? 0
  445. : 1;
  446. GeometryOffsetAttribute.arrayFill(applyOffset, offsetValue);
  447. geometry.attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  448. componentDatatype: ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  449. componentsPerAttribute: 1,
  450. values: applyOffset,
  451. });
  452. }
  453. boundingSphere = Transforms.BoundingSphere.fromRectangle3D(
  454. rectangle,
  455. ellipsoid,
  456. surfaceHeight
  457. );
  458. }
  459. return new GeometryAttribute.Geometry({
  460. attributes: geometry.attributes,
  461. indices: geometry.indices,
  462. primitiveType: GeometryAttribute.PrimitiveType.LINES,
  463. boundingSphere: boundingSphere,
  464. offsetAttribute: rectangleGeometry._offsetAttribute,
  465. });
  466. };
  467. function createRectangleOutlineGeometry(rectangleGeometry, offset) {
  468. if (defaultValue.defined(offset)) {
  469. rectangleGeometry = RectangleOutlineGeometry.unpack(
  470. rectangleGeometry,
  471. offset
  472. );
  473. }
  474. rectangleGeometry._ellipsoid = Matrix2.Ellipsoid.clone(rectangleGeometry._ellipsoid);
  475. rectangleGeometry._rectangle = Matrix2.Rectangle.clone(rectangleGeometry._rectangle);
  476. return RectangleOutlineGeometry.createGeometry(rectangleGeometry);
  477. }
  478. return createRectangleOutlineGeometry;
  479. }));