EllipsoidOutlineGeometry-96f1f311.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './defined-26bd4a03', './Check-da037458', './defaultValue-f2e68450', './Math-fa6e45cb', './Cartesian2-2a723276', './Transforms-65aba0a4', './ComponentDatatype-69643096', './GeometryAttribute-ed359d71', './GeometryAttributes-eecc9f43', './IndexDatatype-3de60176', './GeometryOffsetAttribute-cb30cd97'], function (exports, defined, Check, defaultValue, _Math, Cartesian2, Transforms, ComponentDatatype, GeometryAttribute, GeometryAttributes, IndexDatatype, GeometryOffsetAttribute) { 'use strict';
  3. var defaultRadii = new Cartesian2.Cartesian3(1.0, 1.0, 1.0);
  4. var cos = Math.cos;
  5. var sin = Math.sin;
  6. /**
  7. * A description of the outline of an ellipsoid centered at the origin.
  8. *
  9. * @alias EllipsoidOutlineGeometry
  10. * @constructor
  11. *
  12. * @param {Object} [options] Object with the following properties:
  13. * @param {Cartesian3} [options.radii=Cartesian3(1.0, 1.0, 1.0)] The radii of the ellipsoid in the x, y, and z directions.
  14. * @param {Cartesian3} [options.innerRadii=options.radii] The inner radii of the ellipsoid in the x, y, and z directions.
  15. * @param {Number} [options.minimumClock=0.0] The minimum angle lying in the xy-plane measured from the positive x-axis and toward the positive y-axis.
  16. * @param {Number} [options.maximumClock=2*PI] The maximum angle lying in the xy-plane measured from the positive x-axis and toward the positive y-axis.
  17. * @param {Number} [options.minimumCone=0.0] The minimum angle measured from the positive z-axis and toward the negative z-axis.
  18. * @param {Number} [options.maximumCone=PI] The maximum angle measured from the positive z-axis and toward the negative z-axis.
  19. * @param {Number} [options.stackPartitions=10] The count of stacks for the ellipsoid (1 greater than the number of parallel lines).
  20. * @param {Number} [options.slicePartitions=8] The count of slices for the ellipsoid (Equal to the number of radial lines).
  21. * @param {Number} [options.subdivisions=128] The number of points per line, determining the granularity of the curvature.
  22. *
  23. * @exception {DeveloperError} options.stackPartitions must be greater than or equal to one.
  24. * @exception {DeveloperError} options.slicePartitions must be greater than or equal to zero.
  25. * @exception {DeveloperError} options.subdivisions must be greater than or equal to zero.
  26. *
  27. * @example
  28. * var ellipsoid = new Cesium.EllipsoidOutlineGeometry({
  29. * radii : new Cesium.Cartesian3(1000000.0, 500000.0, 500000.0),
  30. * stackPartitions: 6,
  31. * slicePartitions: 5
  32. * });
  33. * var geometry = Cesium.EllipsoidOutlineGeometry.createGeometry(ellipsoid);
  34. */
  35. function EllipsoidOutlineGeometry(options) {
  36. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  37. var radii = defaultValue.defaultValue(options.radii, defaultRadii);
  38. var innerRadii = defaultValue.defaultValue(options.innerRadii, radii);
  39. var minimumClock = defaultValue.defaultValue(options.minimumClock, 0.0);
  40. var maximumClock = defaultValue.defaultValue(options.maximumClock, _Math.CesiumMath.TWO_PI);
  41. var minimumCone = defaultValue.defaultValue(options.minimumCone, 0.0);
  42. var maximumCone = defaultValue.defaultValue(options.maximumCone, _Math.CesiumMath.PI);
  43. var stackPartitions = Math.round(defaultValue.defaultValue(options.stackPartitions, 10));
  44. var slicePartitions = Math.round(defaultValue.defaultValue(options.slicePartitions, 8));
  45. var subdivisions = Math.round(defaultValue.defaultValue(options.subdivisions, 128));
  46. //>>includeStart('debug', pragmas.debug);
  47. if (stackPartitions < 1) {
  48. throw new Check.DeveloperError('options.stackPartitions cannot be less than 1');
  49. }
  50. if (slicePartitions < 0) {
  51. throw new Check.DeveloperError('options.slicePartitions cannot be less than 0');
  52. }
  53. if (subdivisions < 0) {
  54. throw new Check.DeveloperError('options.subdivisions must be greater than or equal to zero.');
  55. }
  56. if (defined.defined(options.offsetAttribute) && options.offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.TOP) {
  57. throw new Check.DeveloperError('GeometryOffsetAttribute.TOP is not a supported options.offsetAttribute for this geometry.');
  58. }
  59. //>>includeEnd('debug');
  60. this._radii = Cartesian2.Cartesian3.clone(radii);
  61. this._innerRadii = Cartesian2.Cartesian3.clone(innerRadii);
  62. this._minimumClock = minimumClock;
  63. this._maximumClock = maximumClock;
  64. this._minimumCone = minimumCone;
  65. this._maximumCone = maximumCone;
  66. this._stackPartitions = stackPartitions;
  67. this._slicePartitions = slicePartitions;
  68. this._subdivisions = subdivisions;
  69. this._offsetAttribute = options.offsetAttribute;
  70. this._workerName = 'createEllipsoidOutlineGeometry';
  71. }
  72. /**
  73. * The number of elements used to pack the object into an array.
  74. * @type {Number}
  75. */
  76. EllipsoidOutlineGeometry.packedLength = 2 * (Cartesian2.Cartesian3.packedLength) + 8;
  77. /**
  78. * Stores the provided instance into the provided array.
  79. *
  80. * @param {EllipsoidOutlineGeometry} value The value to pack.
  81. * @param {Number[]} array The array to pack into.
  82. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  83. *
  84. * @returns {Number[]} The array that was packed into
  85. */
  86. EllipsoidOutlineGeometry.pack = function(value, array, startingIndex) {
  87. //>>includeStart('debug', pragmas.debug);
  88. if (!defined.defined(value)) {
  89. throw new Check.DeveloperError('value is required');
  90. }
  91. if (!defined.defined(array)) {
  92. throw new Check.DeveloperError('array is required');
  93. }
  94. //>>includeEnd('debug');
  95. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  96. Cartesian2.Cartesian3.pack(value._radii, array, startingIndex);
  97. startingIndex += Cartesian2.Cartesian3.packedLength;
  98. Cartesian2.Cartesian3.pack(value._innerRadii, array, startingIndex);
  99. startingIndex += Cartesian2.Cartesian3.packedLength;
  100. array[startingIndex++] = value._minimumClock;
  101. array[startingIndex++] = value._maximumClock;
  102. array[startingIndex++] = value._minimumCone;
  103. array[startingIndex++] = value._maximumCone;
  104. array[startingIndex++] = value._stackPartitions;
  105. array[startingIndex++] = value._slicePartitions;
  106. array[startingIndex++] = value._subdivisions;
  107. array[startingIndex] = defaultValue.defaultValue(value._offsetAttribute, -1);
  108. return array;
  109. };
  110. var scratchRadii = new Cartesian2.Cartesian3();
  111. var scratchInnerRadii = new Cartesian2.Cartesian3();
  112. var scratchOptions = {
  113. radii : scratchRadii,
  114. innerRadii : scratchInnerRadii,
  115. minimumClock : undefined,
  116. maximumClock : undefined,
  117. minimumCone : undefined,
  118. maximumCone : undefined,
  119. stackPartitions : undefined,
  120. slicePartitions : undefined,
  121. subdivisions : undefined,
  122. offsetAttribute : undefined
  123. };
  124. /**
  125. * Retrieves an instance from a packed array.
  126. *
  127. * @param {Number[]} array The packed array.
  128. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  129. * @param {EllipsoidOutlineGeometry} [result] The object into which to store the result.
  130. * @returns {EllipsoidOutlineGeometry} The modified result parameter or a new EllipsoidOutlineGeometry instance if one was not provided.
  131. */
  132. EllipsoidOutlineGeometry.unpack = function(array, startingIndex, result) {
  133. //>>includeStart('debug', pragmas.debug);
  134. if (!defined.defined(array)) {
  135. throw new Check.DeveloperError('array is required');
  136. }
  137. //>>includeEnd('debug');
  138. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  139. var radii = Cartesian2.Cartesian3.unpack(array, startingIndex, scratchRadii);
  140. startingIndex += Cartesian2.Cartesian3.packedLength;
  141. var innerRadii = Cartesian2.Cartesian3.unpack(array, startingIndex, scratchInnerRadii);
  142. startingIndex += Cartesian2.Cartesian3.packedLength;
  143. var minimumClock = array[startingIndex++];
  144. var maximumClock = array[startingIndex++];
  145. var minimumCone = array[startingIndex++];
  146. var maximumCone = array[startingIndex++];
  147. var stackPartitions = array[startingIndex++];
  148. var slicePartitions = array[startingIndex++];
  149. var subdivisions = array[startingIndex++];
  150. var offsetAttribute = array[startingIndex];
  151. if (!defined.defined(result)) {
  152. scratchOptions.minimumClock = minimumClock;
  153. scratchOptions.maximumClock = maximumClock;
  154. scratchOptions.minimumCone = minimumCone;
  155. scratchOptions.maximumCone = maximumCone;
  156. scratchOptions.stackPartitions = stackPartitions;
  157. scratchOptions.slicePartitions = slicePartitions;
  158. scratchOptions.subdivisions = subdivisions;
  159. scratchOptions.offsetAttribute = offsetAttribute === -1 ? undefined : offsetAttribute;
  160. return new EllipsoidOutlineGeometry(scratchOptions);
  161. }
  162. result._radii = Cartesian2.Cartesian3.clone(radii, result._radii);
  163. result._innerRadii = Cartesian2.Cartesian3.clone(innerRadii, result._innerRadii);
  164. result._minimumClock = minimumClock;
  165. result._maximumClock = maximumClock;
  166. result._minimumCone = minimumCone;
  167. result._maximumCone = maximumCone;
  168. result._stackPartitions = stackPartitions;
  169. result._slicePartitions = slicePartitions;
  170. result._subdivisions = subdivisions;
  171. result._offsetAttribute = offsetAttribute === -1 ? undefined : offsetAttribute;
  172. return result;
  173. };
  174. /**
  175. * Computes the geometric representation of an outline of an ellipsoid, including its vertices, indices, and a bounding sphere.
  176. *
  177. * @param {EllipsoidOutlineGeometry} ellipsoidGeometry A description of the ellipsoid outline.
  178. * @returns {Geometry|undefined} The computed vertices and indices.
  179. */
  180. EllipsoidOutlineGeometry.createGeometry = function(ellipsoidGeometry) {
  181. var radii = ellipsoidGeometry._radii;
  182. if ((radii.x <= 0) || (radii.y <= 0) || (radii.z <= 0)) {
  183. return;
  184. }
  185. var innerRadii = ellipsoidGeometry._innerRadii;
  186. if ((innerRadii.x <= 0) || (innerRadii.y <= 0) || (innerRadii.z <= 0)) {
  187. return;
  188. }
  189. var minimumClock = ellipsoidGeometry._minimumClock;
  190. var maximumClock = ellipsoidGeometry._maximumClock;
  191. var minimumCone = ellipsoidGeometry._minimumCone;
  192. var maximumCone = ellipsoidGeometry._maximumCone;
  193. var subdivisions = ellipsoidGeometry._subdivisions;
  194. var ellipsoid = Cartesian2.Ellipsoid.fromCartesian3(radii);
  195. // Add an extra slice and stack to remain consistent with EllipsoidGeometry
  196. var slicePartitions = ellipsoidGeometry._slicePartitions + 1;
  197. var stackPartitions = ellipsoidGeometry._stackPartitions + 1;
  198. slicePartitions = Math.round(slicePartitions * Math.abs(maximumClock - minimumClock) / _Math.CesiumMath.TWO_PI);
  199. stackPartitions = Math.round(stackPartitions * Math.abs(maximumCone - minimumCone) / _Math.CesiumMath.PI);
  200. if (slicePartitions < 2) {
  201. slicePartitions = 2;
  202. }
  203. if (stackPartitions < 2) {
  204. stackPartitions = 2;
  205. }
  206. var extraIndices = 0;
  207. var vertexMultiplier = 1.0;
  208. var hasInnerSurface = ((innerRadii.x !== radii.x) || (innerRadii.y !== radii.y) || innerRadii.z !== radii.z);
  209. var isTopOpen = false;
  210. var isBotOpen = false;
  211. if (hasInnerSurface) {
  212. vertexMultiplier = 2.0;
  213. // Add 2x slicePartitions to connect the top/bottom of the outer to
  214. // the top/bottom of the inner
  215. if (minimumCone > 0.0) {
  216. isTopOpen = true;
  217. extraIndices += slicePartitions;
  218. }
  219. if (maximumCone < Math.PI) {
  220. isBotOpen = true;
  221. extraIndices += slicePartitions;
  222. }
  223. }
  224. var vertexCount = subdivisions * vertexMultiplier * (stackPartitions + slicePartitions);
  225. var positions = new Float64Array(vertexCount * 3);
  226. // Multiply by two because two points define each line segment
  227. var numIndices = 2 * (vertexCount + extraIndices - (slicePartitions + stackPartitions) * vertexMultiplier);
  228. var indices = IndexDatatype.IndexDatatype.createTypedArray(vertexCount, numIndices);
  229. var i;
  230. var j;
  231. var theta;
  232. var phi;
  233. var index = 0;
  234. // Calculate sin/cos phi
  235. var sinPhi = new Array(stackPartitions);
  236. var cosPhi = new Array(stackPartitions);
  237. for (i = 0; i < stackPartitions; i++) {
  238. phi = minimumCone + i * (maximumCone - minimumCone) / (stackPartitions - 1);
  239. sinPhi[i] = sin(phi);
  240. cosPhi[i] = cos(phi);
  241. }
  242. // Calculate sin/cos theta
  243. var sinTheta = new Array(subdivisions);
  244. var cosTheta = new Array(subdivisions);
  245. for (i = 0; i < subdivisions; i++) {
  246. theta = minimumClock + i * (maximumClock - minimumClock) / (subdivisions - 1);
  247. sinTheta[i] = sin(theta);
  248. cosTheta[i] = cos(theta);
  249. }
  250. // Calculate the latitude lines on the outer surface
  251. for (i = 0; i < stackPartitions; i++) {
  252. for (j = 0; j < subdivisions; j++) {
  253. positions[index++] = radii.x * sinPhi[i] * cosTheta[j];
  254. positions[index++] = radii.y * sinPhi[i] * sinTheta[j];
  255. positions[index++] = radii.z * cosPhi[i];
  256. }
  257. }
  258. // Calculate the latitude lines on the inner surface
  259. if (hasInnerSurface) {
  260. for (i = 0; i < stackPartitions; i++) {
  261. for (j = 0; j < subdivisions; j++) {
  262. positions[index++] = innerRadii.x * sinPhi[i] * cosTheta[j];
  263. positions[index++] = innerRadii.y * sinPhi[i] * sinTheta[j];
  264. positions[index++] = innerRadii.z * cosPhi[i];
  265. }
  266. }
  267. }
  268. // Calculate sin/cos phi
  269. sinPhi.length = subdivisions;
  270. cosPhi.length = subdivisions;
  271. for (i = 0; i < subdivisions; i++) {
  272. phi = minimumCone + i * (maximumCone - minimumCone) / (subdivisions - 1);
  273. sinPhi[i] = sin(phi);
  274. cosPhi[i] = cos(phi);
  275. }
  276. // Calculate sin/cos theta for each slice partition
  277. sinTheta.length = slicePartitions;
  278. cosTheta.length = slicePartitions;
  279. for (i = 0; i < slicePartitions; i++) {
  280. theta = minimumClock + i * (maximumClock - minimumClock) / (slicePartitions - 1);
  281. sinTheta[i] = sin(theta);
  282. cosTheta[i] = cos(theta);
  283. }
  284. // Calculate the longitude lines on the outer surface
  285. for (i = 0; i < subdivisions; i++) {
  286. for (j = 0; j < slicePartitions; j++) {
  287. positions[index++] = radii.x * sinPhi[i] * cosTheta[j];
  288. positions[index++] = radii.y * sinPhi[i] * sinTheta[j];
  289. positions[index++] = radii.z * cosPhi[i];
  290. }
  291. }
  292. // Calculate the longitude lines on the inner surface
  293. if (hasInnerSurface) {
  294. for (i = 0; i < subdivisions; i++) {
  295. for (j = 0; j < slicePartitions; j++) {
  296. positions[index++] = innerRadii.x * sinPhi[i] * cosTheta[j];
  297. positions[index++] = innerRadii.y * sinPhi[i] * sinTheta[j];
  298. positions[index++] = innerRadii.z * cosPhi[i];
  299. }
  300. }
  301. }
  302. // Create indices for the latitude lines
  303. index = 0;
  304. for (i = 0; i < stackPartitions * vertexMultiplier; i++) {
  305. var topOffset = i * subdivisions;
  306. for (j = 0; j < subdivisions - 1; j++) {
  307. indices[index++] = topOffset + j;
  308. indices[index++] = topOffset + j + 1;
  309. }
  310. }
  311. // Create indices for the outer longitude lines
  312. var offset = stackPartitions * subdivisions * vertexMultiplier;
  313. for (i = 0; i < slicePartitions; i++) {
  314. for (j = 0; j < subdivisions - 1; j++) {
  315. indices[index++] = offset + i + (j * slicePartitions);
  316. indices[index++] = offset + i + (j + 1) * slicePartitions;
  317. }
  318. }
  319. // Create indices for the inner longitude lines
  320. if (hasInnerSurface) {
  321. offset = stackPartitions * subdivisions * vertexMultiplier + slicePartitions * subdivisions;
  322. for (i = 0; i < slicePartitions; i++) {
  323. for (j = 0; j < subdivisions - 1; j++) {
  324. indices[index++] = offset + i + (j * slicePartitions);
  325. indices[index++] = offset + i + (j + 1) * slicePartitions;
  326. }
  327. }
  328. }
  329. if (hasInnerSurface) {
  330. var outerOffset = stackPartitions * subdivisions * vertexMultiplier;
  331. var innerOffset = outerOffset + (subdivisions * slicePartitions);
  332. if (isTopOpen) {
  333. // Draw lines from the top of the inner surface to the top of the outer surface
  334. for (i = 0; i < slicePartitions; i++) {
  335. indices[index++] = outerOffset + i;
  336. indices[index++] = innerOffset + i;
  337. }
  338. }
  339. if (isBotOpen) {
  340. // Draw lines from the top of the inner surface to the top of the outer surface
  341. outerOffset += (subdivisions * slicePartitions) - slicePartitions;
  342. innerOffset += (subdivisions * slicePartitions) - slicePartitions;
  343. for (i = 0; i < slicePartitions; i++) {
  344. indices[index++] = outerOffset + i;
  345. indices[index++] = innerOffset + i;
  346. }
  347. }
  348. }
  349. var attributes = new GeometryAttributes.GeometryAttributes({
  350. position : new GeometryAttribute.GeometryAttribute({
  351. componentDatatype : ComponentDatatype.ComponentDatatype.DOUBLE,
  352. componentsPerAttribute : 3,
  353. values : positions
  354. })
  355. });
  356. if (defined.defined(ellipsoidGeometry._offsetAttribute)) {
  357. var length = positions.length;
  358. var applyOffset = new Uint8Array(length / 3);
  359. var offsetValue = ellipsoidGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE ? 0 : 1;
  360. GeometryOffsetAttribute.arrayFill(applyOffset, offsetValue);
  361. attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  362. componentDatatype : ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  363. componentsPerAttribute : 1,
  364. values : applyOffset
  365. });
  366. }
  367. return new GeometryAttribute.Geometry({
  368. attributes : attributes,
  369. indices : indices,
  370. primitiveType : GeometryAttribute.PrimitiveType.LINES,
  371. boundingSphere : Transforms.BoundingSphere.fromEllipsoid(ellipsoid),
  372. offsetAttribute : ellipsoidGeometry._offsetAttribute
  373. });
  374. };
  375. exports.EllipsoidOutlineGeometry = EllipsoidOutlineGeometry;
  376. });