createWallOutlineGeometry.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./defined-26bd4a03', './Check-da037458', './freezeObject-2d83f591', './defaultValue-f2e68450', './Math-fa6e45cb', './Cartesian2-2a723276', './defineProperties-6f7a50f2', './Transforms-65aba0a4', './RuntimeError-ad75c885', './WebGLConstants-497deb20', './ComponentDatatype-69643096', './GeometryAttribute-ed359d71', './when-ee12a2cb', './GeometryAttributes-eecc9f43', './IndexDatatype-3de60176', './IntersectionTests-c2360ffa', './Plane-a1a3fd52', './EllipsoidTangentPlane-10c6053a', './EllipsoidRhumbLine-c6cdbfd3', './PolygonPipeline-e486c11c', './EllipsoidGeodesic-53e988a6', './PolylinePipeline-b4161aaf', './WallGeometryLibrary-f30761f4'], function (defined, Check, freezeObject, defaultValue, _Math, Cartesian2, defineProperties, Transforms, RuntimeError, WebGLConstants, ComponentDatatype, GeometryAttribute, when, GeometryAttributes, IndexDatatype, IntersectionTests, Plane, EllipsoidTangentPlane, EllipsoidRhumbLine, PolygonPipeline, EllipsoidGeodesic, PolylinePipeline, WallGeometryLibrary) { 'use strict';
  3. var scratchCartesian3Position1 = new Cartesian2.Cartesian3();
  4. var scratchCartesian3Position2 = new Cartesian2.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. * var 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. * var geometry = Cesium.WallOutlineGeometry.createGeometry(wall);
  40. */
  41. function WallOutlineGeometry(options) {
  42. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  43. var wallPositions = options.positions;
  44. var maximumHeights = options.maximumHeights;
  45. var minimumHeights = options.minimumHeights;
  46. //>>includeStart('debug', pragmas.debug);
  47. if (!defined.defined(wallPositions)) {
  48. throw new Check.DeveloperError('options.positions is required.');
  49. }
  50. if (defined.defined(maximumHeights) && maximumHeights.length !== wallPositions.length) {
  51. throw new Check.DeveloperError('options.positions and options.maximumHeights must have the same length.');
  52. }
  53. if (defined.defined(minimumHeights) && minimumHeights.length !== wallPositions.length) {
  54. throw new Check.DeveloperError('options.positions and options.minimumHeights must have the same length.');
  55. }
  56. //>>includeEnd('debug');
  57. var granularity = defaultValue.defaultValue(options.granularity, _Math.CesiumMath.RADIANS_PER_DEGREE);
  58. var ellipsoid = defaultValue.defaultValue(options.ellipsoid, Cartesian2.Ellipsoid.WGS84);
  59. this._positions = wallPositions;
  60. this._minimumHeights = minimumHeights;
  61. this._maximumHeights = maximumHeights;
  62. this._granularity = granularity;
  63. this._ellipsoid = Cartesian2.Ellipsoid.clone(ellipsoid);
  64. this._workerName = 'createWallOutlineGeometry';
  65. var numComponents = 1 + wallPositions.length * Cartesian2.Cartesian3.packedLength + 2;
  66. if (defined.defined(minimumHeights)) {
  67. numComponents += minimumHeights.length;
  68. }
  69. if (defined.defined(maximumHeights)) {
  70. numComponents += maximumHeights.length;
  71. }
  72. /**
  73. * The number of elements used to pack the object into an array.
  74. * @type {Number}
  75. */
  76. this.packedLength = numComponents + Cartesian2.Ellipsoid.packedLength + 1;
  77. }
  78. /**
  79. * Stores the provided instance into the provided array.
  80. *
  81. * @param {WallOutlineGeometry} value The value to pack.
  82. * @param {Number[]} array The array to pack into.
  83. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  84. *
  85. * @returns {Number[]} The array that was packed into
  86. */
  87. WallOutlineGeometry.pack = function(value, array, startingIndex) {
  88. //>>includeStart('debug', pragmas.debug);
  89. if (!defined.defined(value)) {
  90. throw new Check.DeveloperError('value is required');
  91. }
  92. if (!defined.defined(array)) {
  93. throw new Check.DeveloperError('array is required');
  94. }
  95. //>>includeEnd('debug');
  96. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  97. var i;
  98. var positions = value._positions;
  99. var length = positions.length;
  100. array[startingIndex++] = length;
  101. for (i = 0; i < length; ++i, startingIndex += Cartesian2.Cartesian3.packedLength) {
  102. Cartesian2.Cartesian3.pack(positions[i], array, startingIndex);
  103. }
  104. var minimumHeights = value._minimumHeights;
  105. length = defined.defined(minimumHeights) ? minimumHeights.length : 0;
  106. array[startingIndex++] = length;
  107. if (defined.defined(minimumHeights)) {
  108. for (i = 0; i < length; ++i) {
  109. array[startingIndex++] = minimumHeights[i];
  110. }
  111. }
  112. var maximumHeights = value._maximumHeights;
  113. length = defined.defined(maximumHeights) ? maximumHeights.length : 0;
  114. array[startingIndex++] = length;
  115. if (defined.defined(maximumHeights)) {
  116. for (i = 0; i < length; ++i) {
  117. array[startingIndex++] = maximumHeights[i];
  118. }
  119. }
  120. Cartesian2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  121. startingIndex += Cartesian2.Ellipsoid.packedLength;
  122. array[startingIndex] = value._granularity;
  123. return array;
  124. };
  125. var scratchEllipsoid = Cartesian2.Ellipsoid.clone(Cartesian2.Ellipsoid.UNIT_SPHERE);
  126. var scratchOptions = {
  127. positions : undefined,
  128. minimumHeights : undefined,
  129. maximumHeights : undefined,
  130. ellipsoid : scratchEllipsoid,
  131. granularity : undefined
  132. };
  133. /**
  134. * Retrieves an instance from a packed array.
  135. *
  136. * @param {Number[]} array The packed array.
  137. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  138. * @param {WallOutlineGeometry} [result] The object into which to store the result.
  139. * @returns {WallOutlineGeometry} The modified result parameter or a new WallOutlineGeometry instance if one was not provided.
  140. */
  141. WallOutlineGeometry.unpack = function(array, startingIndex, result) {
  142. //>>includeStart('debug', pragmas.debug);
  143. if (!defined.defined(array)) {
  144. throw new Check.DeveloperError('array is required');
  145. }
  146. //>>includeEnd('debug');
  147. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  148. var i;
  149. var length = array[startingIndex++];
  150. var positions = new Array(length);
  151. for (i = 0; i < length; ++i, startingIndex += Cartesian2.Cartesian3.packedLength) {
  152. positions[i] = Cartesian2.Cartesian3.unpack(array, startingIndex);
  153. }
  154. length = array[startingIndex++];
  155. var minimumHeights;
  156. if (length > 0) {
  157. minimumHeights = new Array(length);
  158. for (i = 0; i < length; ++i) {
  159. minimumHeights[i] = array[startingIndex++];
  160. }
  161. }
  162. length = array[startingIndex++];
  163. var maximumHeights;
  164. if (length > 0) {
  165. maximumHeights = new Array(length);
  166. for (i = 0; i < length; ++i) {
  167. maximumHeights[i] = array[startingIndex++];
  168. }
  169. }
  170. var ellipsoid = Cartesian2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  171. startingIndex += Cartesian2.Ellipsoid.packedLength;
  172. var granularity = array[startingIndex];
  173. if (!defined.defined(result)) {
  174. scratchOptions.positions = positions;
  175. scratchOptions.minimumHeights = minimumHeights;
  176. scratchOptions.maximumHeights = maximumHeights;
  177. scratchOptions.granularity = granularity;
  178. return new WallOutlineGeometry(scratchOptions);
  179. }
  180. result._positions = positions;
  181. result._minimumHeights = minimumHeights;
  182. result._maximumHeights = maximumHeights;
  183. result._ellipsoid = Cartesian2.Ellipsoid.clone(ellipsoid, result._ellipsoid);
  184. result._granularity = granularity;
  185. return result;
  186. };
  187. /**
  188. * A description of a walloutline. A wall is defined by a series of points,
  189. * which extrude down to the ground. Optionally, they can extrude downwards to a specified height.
  190. *
  191. * @param {Object} options Object with the following properties:
  192. * @param {Cartesian3[]} options.positions An array of Cartesian objects, which are the points of the wall.
  193. * @param {Number} [options.maximumHeight] A constant that defines the maximum height of the
  194. * wall at <code>positions</code>. If undefined, the height of each position in used.
  195. * @param {Number} [options.minimumHeight] A constant that defines the minimum height of the
  196. * wall at <code>positions</code>. If undefined, the height at each position is 0.0.
  197. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for coordinate manipulation
  198. * @returns {WallOutlineGeometry}
  199. *
  200. *
  201. * @example
  202. * // create a wall that spans from 10000 meters to 20000 meters
  203. * var wall = Cesium.WallOutlineGeometry.fromConstantHeights({
  204. * positions : Cesium.Cartesian3.fromDegreesArray([
  205. * 19.0, 47.0,
  206. * 19.0, 48.0,
  207. * 20.0, 48.0,
  208. * 20.0, 47.0,
  209. * 19.0, 47.0,
  210. * ]),
  211. * minimumHeight : 20000.0,
  212. * maximumHeight : 10000.0
  213. * });
  214. * var geometry = Cesium.WallOutlineGeometry.createGeometry(wall);
  215. *
  216. * @see WallOutlineGeometry#createGeometry
  217. */
  218. WallOutlineGeometry.fromConstantHeights = function(options) {
  219. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  220. var positions = options.positions;
  221. //>>includeStart('debug', pragmas.debug);
  222. if (!defined.defined(positions)) {
  223. throw new Check.DeveloperError('options.positions is required.');
  224. }
  225. //>>includeEnd('debug');
  226. var minHeights;
  227. var maxHeights;
  228. var min = options.minimumHeight;
  229. var max = options.maximumHeight;
  230. var doMin = defined.defined(min);
  231. var doMax = defined.defined(max);
  232. if (doMin || doMax) {
  233. var length = positions.length;
  234. minHeights = (doMin) ? new Array(length) : undefined;
  235. maxHeights = (doMax) ? new Array(length) : undefined;
  236. for (var i = 0; i < length; ++i) {
  237. if (doMin) {
  238. minHeights[i] = min;
  239. }
  240. if (doMax) {
  241. maxHeights[i] = max;
  242. }
  243. }
  244. }
  245. var newOptions = {
  246. positions : positions,
  247. maximumHeights : maxHeights,
  248. minimumHeights : minHeights,
  249. ellipsoid : options.ellipsoid
  250. };
  251. return new WallOutlineGeometry(newOptions);
  252. };
  253. /**
  254. * Computes the geometric representation of a wall outline, including its vertices, indices, and a bounding sphere.
  255. *
  256. * @param {WallOutlineGeometry} wallGeometry A description of the wall outline.
  257. * @returns {Geometry|undefined} The computed vertices and indices.
  258. */
  259. WallOutlineGeometry.createGeometry = function(wallGeometry) {
  260. var wallPositions = wallGeometry._positions;
  261. var minimumHeights = wallGeometry._minimumHeights;
  262. var maximumHeights = wallGeometry._maximumHeights;
  263. var granularity = wallGeometry._granularity;
  264. var ellipsoid = wallGeometry._ellipsoid;
  265. var pos = WallGeometryLibrary.WallGeometryLibrary.computePositions(ellipsoid, wallPositions, maximumHeights, minimumHeights, granularity, false);
  266. if (!defined.defined(pos)) {
  267. return;
  268. }
  269. var bottomPositions = pos.bottomPositions;
  270. var topPositions = pos.topPositions;
  271. var length = topPositions.length;
  272. var size = length * 2;
  273. var positions = new Float64Array(size);
  274. var positionIndex = 0;
  275. // add lower and upper points one after the other, lower
  276. // points being even and upper points being odd
  277. length /= 3;
  278. var i;
  279. for (i = 0; i < length; ++i) {
  280. var i3 = i * 3;
  281. var topPosition = Cartesian2.Cartesian3.fromArray(topPositions, i3, scratchCartesian3Position1);
  282. var bottomPosition = Cartesian2.Cartesian3.fromArray(bottomPositions, i3, scratchCartesian3Position2);
  283. // insert the lower point
  284. positions[positionIndex++] = bottomPosition.x;
  285. positions[positionIndex++] = bottomPosition.y;
  286. positions[positionIndex++] = bottomPosition.z;
  287. // insert the upper point
  288. positions[positionIndex++] = topPosition.x;
  289. positions[positionIndex++] = topPosition.y;
  290. positions[positionIndex++] = topPosition.z;
  291. }
  292. var attributes = new GeometryAttributes.GeometryAttributes({
  293. position : new GeometryAttribute.GeometryAttribute({
  294. componentDatatype : ComponentDatatype.ComponentDatatype.DOUBLE,
  295. componentsPerAttribute : 3,
  296. values : positions
  297. })
  298. });
  299. var numVertices = size / 3;
  300. size = 2 * numVertices - 4 + numVertices;
  301. var indices = IndexDatatype.IndexDatatype.createTypedArray(numVertices, size);
  302. var edgeIndex = 0;
  303. for (i = 0; i < numVertices - 2; i += 2) {
  304. var LL = i;
  305. var LR = i + 2;
  306. var pl = Cartesian2.Cartesian3.fromArray(positions, LL * 3, scratchCartesian3Position1);
  307. var pr = Cartesian2.Cartesian3.fromArray(positions, LR * 3, scratchCartesian3Position2);
  308. if (Cartesian2.Cartesian3.equalsEpsilon(pl, pr, _Math.CesiumMath.EPSILON10)) {
  309. continue;
  310. }
  311. var UL = i + 1;
  312. var UR = i + 3;
  313. indices[edgeIndex++] = UL;
  314. indices[edgeIndex++] = LL;
  315. indices[edgeIndex++] = UL;
  316. indices[edgeIndex++] = UR;
  317. indices[edgeIndex++] = LL;
  318. indices[edgeIndex++] = LR;
  319. }
  320. indices[edgeIndex++] = numVertices - 2;
  321. indices[edgeIndex++] = numVertices - 1;
  322. return new GeometryAttribute.Geometry({
  323. attributes : attributes,
  324. indices : indices,
  325. primitiveType : GeometryAttribute.PrimitiveType.LINES,
  326. boundingSphere : new Transforms.BoundingSphere.fromVertices(positions)
  327. });
  328. };
  329. function createWallOutlineGeometry(wallGeometry, offset) {
  330. if (defined.defined(offset)) {
  331. wallGeometry = WallOutlineGeometry.unpack(wallGeometry, offset);
  332. }
  333. wallGeometry._ellipsoid = Cartesian2.Ellipsoid.clone(wallGeometry._ellipsoid);
  334. return WallOutlineGeometry.createGeometry(wallGeometry);
  335. }
  336. return createWallOutlineGeometry;
  337. });