EllipsoidGeometry-f21a3e38.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './GeometryOffsetAttribute-3e8c299c', './Transforms-323408fe', './Matrix2-69c32d33', './ComponentDatatype-b1ea011a', './defaultValue-94c3e563', './RuntimeError-c581ca93', './GeometryAttribute-cb73bb3f', './GeometryAttributes-7df9bef6', './IndexDatatype-c4099fe9', './VertexFormat-e46f29d6'], (function (exports, GeometryOffsetAttribute, Transforms, Matrix2, ComponentDatatype, defaultValue, RuntimeError, GeometryAttribute, GeometryAttributes, IndexDatatype, VertexFormat) { 'use strict';
  3. const scratchPosition = new Matrix2.Cartesian3();
  4. const scratchNormal = new Matrix2.Cartesian3();
  5. const scratchTangent = new Matrix2.Cartesian3();
  6. const scratchBitangent = new Matrix2.Cartesian3();
  7. const scratchNormalST = new Matrix2.Cartesian3();
  8. const defaultRadii = new Matrix2.Cartesian3(1.0, 1.0, 1.0);
  9. const cos = Math.cos;
  10. const sin = Math.sin;
  11. /**
  12. * A description of an ellipsoid centered at the origin.
  13. *
  14. * @alias EllipsoidGeometry
  15. * @constructor
  16. *
  17. * @param {Object} [options] Object with the following properties:
  18. * @param {Cartesian3} [options.radii=Cartesian3(1.0, 1.0, 1.0)] The radii of the ellipsoid in the x, y, and z directions.
  19. * @param {Cartesian3} [options.innerRadii=options.radii] The inner radii of the ellipsoid in the x, y, and z directions.
  20. * @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.
  21. * @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.
  22. * @param {Number} [options.minimumCone=0.0] The minimum angle measured from the positive z-axis and toward the negative z-axis.
  23. * @param {Number} [options.maximumCone=PI] The maximum angle measured from the positive z-axis and toward the negative z-axis.
  24. * @param {Number} [options.stackPartitions=64] The number of times to partition the ellipsoid into stacks.
  25. * @param {Number} [options.slicePartitions=64] The number of times to partition the ellipsoid into radial slices.
  26. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  27. *
  28. * @exception {DeveloperError} options.slicePartitions cannot be less than three.
  29. * @exception {DeveloperError} options.stackPartitions cannot be less than three.
  30. *
  31. * @see EllipsoidGeometry#createGeometry
  32. *
  33. * @example
  34. * const ellipsoid = new Cesium.EllipsoidGeometry({
  35. * vertexFormat : Cesium.VertexFormat.POSITION_ONLY,
  36. * radii : new Cesium.Cartesian3(1000000.0, 500000.0, 500000.0)
  37. * });
  38. * const geometry = Cesium.EllipsoidGeometry.createGeometry(ellipsoid);
  39. */
  40. function EllipsoidGeometry(options) {
  41. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  42. const radii = defaultValue.defaultValue(options.radii, defaultRadii);
  43. const innerRadii = defaultValue.defaultValue(options.innerRadii, radii);
  44. const minimumClock = defaultValue.defaultValue(options.minimumClock, 0.0);
  45. const maximumClock = defaultValue.defaultValue(options.maximumClock, ComponentDatatype.CesiumMath.TWO_PI);
  46. const minimumCone = defaultValue.defaultValue(options.minimumCone, 0.0);
  47. const maximumCone = defaultValue.defaultValue(options.maximumCone, ComponentDatatype.CesiumMath.PI);
  48. const stackPartitions = Math.round(defaultValue.defaultValue(options.stackPartitions, 64));
  49. const slicePartitions = Math.round(defaultValue.defaultValue(options.slicePartitions, 64));
  50. const vertexFormat = defaultValue.defaultValue(options.vertexFormat, VertexFormat.VertexFormat.DEFAULT);
  51. //>>includeStart('debug', pragmas.debug);
  52. if (slicePartitions < 3) {
  53. throw new RuntimeError.DeveloperError(
  54. "options.slicePartitions cannot be less than three."
  55. );
  56. }
  57. if (stackPartitions < 3) {
  58. throw new RuntimeError.DeveloperError(
  59. "options.stackPartitions cannot be less than three."
  60. );
  61. }
  62. //>>includeEnd('debug');
  63. this._radii = Matrix2.Cartesian3.clone(radii);
  64. this._innerRadii = Matrix2.Cartesian3.clone(innerRadii);
  65. this._minimumClock = minimumClock;
  66. this._maximumClock = maximumClock;
  67. this._minimumCone = minimumCone;
  68. this._maximumCone = maximumCone;
  69. this._stackPartitions = stackPartitions;
  70. this._slicePartitions = slicePartitions;
  71. this._vertexFormat = VertexFormat.VertexFormat.clone(vertexFormat);
  72. this._offsetAttribute = options.offsetAttribute;
  73. this._workerName = "createEllipsoidGeometry";
  74. }
  75. /**
  76. * The number of elements used to pack the object into an array.
  77. * @type {Number}
  78. */
  79. EllipsoidGeometry.packedLength =
  80. 2 * Matrix2.Cartesian3.packedLength + VertexFormat.VertexFormat.packedLength + 7;
  81. /**
  82. * Stores the provided instance into the provided array.
  83. *
  84. * @param {EllipsoidGeometry} value The value to pack.
  85. * @param {Number[]} array The array to pack into.
  86. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  87. *
  88. * @returns {Number[]} The array that was packed into
  89. */
  90. EllipsoidGeometry.pack = function (value, array, startingIndex) {
  91. //>>includeStart('debug', pragmas.debug);
  92. if (!defaultValue.defined(value)) {
  93. throw new RuntimeError.DeveloperError("value is required");
  94. }
  95. if (!defaultValue.defined(array)) {
  96. throw new RuntimeError.DeveloperError("array is required");
  97. }
  98. //>>includeEnd('debug');
  99. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  100. Matrix2.Cartesian3.pack(value._radii, array, startingIndex);
  101. startingIndex += Matrix2.Cartesian3.packedLength;
  102. Matrix2.Cartesian3.pack(value._innerRadii, array, startingIndex);
  103. startingIndex += Matrix2.Cartesian3.packedLength;
  104. VertexFormat.VertexFormat.pack(value._vertexFormat, array, startingIndex);
  105. startingIndex += VertexFormat.VertexFormat.packedLength;
  106. array[startingIndex++] = value._minimumClock;
  107. array[startingIndex++] = value._maximumClock;
  108. array[startingIndex++] = value._minimumCone;
  109. array[startingIndex++] = value._maximumCone;
  110. array[startingIndex++] = value._stackPartitions;
  111. array[startingIndex++] = value._slicePartitions;
  112. array[startingIndex] = defaultValue.defaultValue(value._offsetAttribute, -1);
  113. return array;
  114. };
  115. const scratchRadii = new Matrix2.Cartesian3();
  116. const scratchInnerRadii = new Matrix2.Cartesian3();
  117. const scratchVertexFormat = new VertexFormat.VertexFormat();
  118. const scratchOptions = {
  119. radii: scratchRadii,
  120. innerRadii: scratchInnerRadii,
  121. vertexFormat: scratchVertexFormat,
  122. minimumClock: undefined,
  123. maximumClock: undefined,
  124. minimumCone: undefined,
  125. maximumCone: undefined,
  126. stackPartitions: undefined,
  127. slicePartitions: undefined,
  128. offsetAttribute: undefined,
  129. };
  130. /**
  131. * Retrieves an instance from a packed array.
  132. *
  133. * @param {Number[]} array The packed array.
  134. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  135. * @param {EllipsoidGeometry} [result] The object into which to store the result.
  136. * @returns {EllipsoidGeometry} The modified result parameter or a new EllipsoidGeometry instance if one was not provided.
  137. */
  138. EllipsoidGeometry.unpack = function (array, startingIndex, result) {
  139. //>>includeStart('debug', pragmas.debug);
  140. if (!defaultValue.defined(array)) {
  141. throw new RuntimeError.DeveloperError("array is required");
  142. }
  143. //>>includeEnd('debug');
  144. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  145. const radii = Matrix2.Cartesian3.unpack(array, startingIndex, scratchRadii);
  146. startingIndex += Matrix2.Cartesian3.packedLength;
  147. const innerRadii = Matrix2.Cartesian3.unpack(array, startingIndex, scratchInnerRadii);
  148. startingIndex += Matrix2.Cartesian3.packedLength;
  149. const vertexFormat = VertexFormat.VertexFormat.unpack(
  150. array,
  151. startingIndex,
  152. scratchVertexFormat
  153. );
  154. startingIndex += VertexFormat.VertexFormat.packedLength;
  155. const minimumClock = array[startingIndex++];
  156. const maximumClock = array[startingIndex++];
  157. const minimumCone = array[startingIndex++];
  158. const maximumCone = array[startingIndex++];
  159. const stackPartitions = array[startingIndex++];
  160. const slicePartitions = array[startingIndex++];
  161. const offsetAttribute = array[startingIndex];
  162. if (!defaultValue.defined(result)) {
  163. scratchOptions.minimumClock = minimumClock;
  164. scratchOptions.maximumClock = maximumClock;
  165. scratchOptions.minimumCone = minimumCone;
  166. scratchOptions.maximumCone = maximumCone;
  167. scratchOptions.stackPartitions = stackPartitions;
  168. scratchOptions.slicePartitions = slicePartitions;
  169. scratchOptions.offsetAttribute =
  170. offsetAttribute === -1 ? undefined : offsetAttribute;
  171. return new EllipsoidGeometry(scratchOptions);
  172. }
  173. result._radii = Matrix2.Cartesian3.clone(radii, result._radii);
  174. result._innerRadii = Matrix2.Cartesian3.clone(innerRadii, result._innerRadii);
  175. result._vertexFormat = VertexFormat.VertexFormat.clone(vertexFormat, result._vertexFormat);
  176. result._minimumClock = minimumClock;
  177. result._maximumClock = maximumClock;
  178. result._minimumCone = minimumCone;
  179. result._maximumCone = maximumCone;
  180. result._stackPartitions = stackPartitions;
  181. result._slicePartitions = slicePartitions;
  182. result._offsetAttribute =
  183. offsetAttribute === -1 ? undefined : offsetAttribute;
  184. return result;
  185. };
  186. /**
  187. * Computes the geometric representation of an ellipsoid, including its vertices, indices, and a bounding sphere.
  188. *
  189. * @param {EllipsoidGeometry} ellipsoidGeometry A description of the ellipsoid.
  190. * @returns {Geometry|undefined} The computed vertices and indices.
  191. */
  192. EllipsoidGeometry.createGeometry = function (ellipsoidGeometry) {
  193. const radii = ellipsoidGeometry._radii;
  194. if (radii.x <= 0 || radii.y <= 0 || radii.z <= 0) {
  195. return;
  196. }
  197. const innerRadii = ellipsoidGeometry._innerRadii;
  198. if (innerRadii.x <= 0 || innerRadii.y <= 0 || innerRadii.z <= 0) {
  199. return;
  200. }
  201. const minimumClock = ellipsoidGeometry._minimumClock;
  202. const maximumClock = ellipsoidGeometry._maximumClock;
  203. const minimumCone = ellipsoidGeometry._minimumCone;
  204. const maximumCone = ellipsoidGeometry._maximumCone;
  205. const vertexFormat = ellipsoidGeometry._vertexFormat;
  206. // Add an extra slice and stack so that the number of partitions is the
  207. // number of surfaces rather than the number of joints
  208. let slicePartitions = ellipsoidGeometry._slicePartitions + 1;
  209. let stackPartitions = ellipsoidGeometry._stackPartitions + 1;
  210. slicePartitions = Math.round(
  211. (slicePartitions * Math.abs(maximumClock - minimumClock)) /
  212. ComponentDatatype.CesiumMath.TWO_PI
  213. );
  214. stackPartitions = Math.round(
  215. (stackPartitions * Math.abs(maximumCone - minimumCone)) / ComponentDatatype.CesiumMath.PI
  216. );
  217. if (slicePartitions < 2) {
  218. slicePartitions = 2;
  219. }
  220. if (stackPartitions < 2) {
  221. stackPartitions = 2;
  222. }
  223. let i;
  224. let j;
  225. let index = 0;
  226. // Create arrays for theta and phi. Duplicate first and last angle to
  227. // allow different normals at the intersections.
  228. const phis = [minimumCone];
  229. const thetas = [minimumClock];
  230. for (i = 0; i < stackPartitions; i++) {
  231. phis.push(
  232. minimumCone + (i * (maximumCone - minimumCone)) / (stackPartitions - 1)
  233. );
  234. }
  235. phis.push(maximumCone);
  236. for (j = 0; j < slicePartitions; j++) {
  237. thetas.push(
  238. minimumClock + (j * (maximumClock - minimumClock)) / (slicePartitions - 1)
  239. );
  240. }
  241. thetas.push(maximumClock);
  242. const numPhis = phis.length;
  243. const numThetas = thetas.length;
  244. // Allow for extra indices if there is an inner surface and if we need
  245. // to close the sides if the clock range is not a full circle
  246. let extraIndices = 0;
  247. let vertexMultiplier = 1.0;
  248. const hasInnerSurface =
  249. innerRadii.x !== radii.x ||
  250. innerRadii.y !== radii.y ||
  251. innerRadii.z !== radii.z;
  252. let isTopOpen = false;
  253. let isBotOpen = false;
  254. let isClockOpen = false;
  255. if (hasInnerSurface) {
  256. vertexMultiplier = 2.0;
  257. if (minimumCone > 0.0) {
  258. isTopOpen = true;
  259. extraIndices += slicePartitions - 1;
  260. }
  261. if (maximumCone < Math.PI) {
  262. isBotOpen = true;
  263. extraIndices += slicePartitions - 1;
  264. }
  265. if ((maximumClock - minimumClock) % ComponentDatatype.CesiumMath.TWO_PI) {
  266. isClockOpen = true;
  267. extraIndices += (stackPartitions - 1) * 2 + 1;
  268. } else {
  269. extraIndices += 1;
  270. }
  271. }
  272. const vertexCount = numThetas * numPhis * vertexMultiplier;
  273. const positions = new Float64Array(vertexCount * 3);
  274. const isInner = GeometryOffsetAttribute.arrayFill(new Array(vertexCount), false);
  275. const negateNormal = GeometryOffsetAttribute.arrayFill(new Array(vertexCount), false);
  276. // Multiply by 6 because there are two triangles per sector
  277. const indexCount = slicePartitions * stackPartitions * vertexMultiplier;
  278. const numIndices =
  279. 6 *
  280. (indexCount +
  281. extraIndices +
  282. 1 -
  283. (slicePartitions + stackPartitions) * vertexMultiplier);
  284. const indices = IndexDatatype.IndexDatatype.createTypedArray(indexCount, numIndices);
  285. const normals = vertexFormat.normal
  286. ? new Float32Array(vertexCount * 3)
  287. : undefined;
  288. const tangents = vertexFormat.tangent
  289. ? new Float32Array(vertexCount * 3)
  290. : undefined;
  291. const bitangents = vertexFormat.bitangent
  292. ? new Float32Array(vertexCount * 3)
  293. : undefined;
  294. const st = vertexFormat.st ? new Float32Array(vertexCount * 2) : undefined;
  295. // Calculate sin/cos phi
  296. const sinPhi = new Array(numPhis);
  297. const cosPhi = new Array(numPhis);
  298. for (i = 0; i < numPhis; i++) {
  299. sinPhi[i] = sin(phis[i]);
  300. cosPhi[i] = cos(phis[i]);
  301. }
  302. // Calculate sin/cos theta
  303. const sinTheta = new Array(numThetas);
  304. const cosTheta = new Array(numThetas);
  305. for (j = 0; j < numThetas; j++) {
  306. cosTheta[j] = cos(thetas[j]);
  307. sinTheta[j] = sin(thetas[j]);
  308. }
  309. // Create outer surface
  310. for (i = 0; i < numPhis; i++) {
  311. for (j = 0; j < numThetas; j++) {
  312. positions[index++] = radii.x * sinPhi[i] * cosTheta[j];
  313. positions[index++] = radii.y * sinPhi[i] * sinTheta[j];
  314. positions[index++] = radii.z * cosPhi[i];
  315. }
  316. }
  317. // Create inner surface
  318. let vertexIndex = vertexCount / 2.0;
  319. if (hasInnerSurface) {
  320. for (i = 0; i < numPhis; i++) {
  321. for (j = 0; j < numThetas; j++) {
  322. positions[index++] = innerRadii.x * sinPhi[i] * cosTheta[j];
  323. positions[index++] = innerRadii.y * sinPhi[i] * sinTheta[j];
  324. positions[index++] = innerRadii.z * cosPhi[i];
  325. // Keep track of which vertices are the inner and which ones
  326. // need the normal to be negated
  327. isInner[vertexIndex] = true;
  328. if (i > 0 && i !== numPhis - 1 && j !== 0 && j !== numThetas - 1) {
  329. negateNormal[vertexIndex] = true;
  330. }
  331. vertexIndex++;
  332. }
  333. }
  334. }
  335. // Create indices for outer surface
  336. index = 0;
  337. let topOffset;
  338. let bottomOffset;
  339. for (i = 1; i < numPhis - 2; i++) {
  340. topOffset = i * numThetas;
  341. bottomOffset = (i + 1) * numThetas;
  342. for (j = 1; j < numThetas - 2; j++) {
  343. indices[index++] = bottomOffset + j;
  344. indices[index++] = bottomOffset + j + 1;
  345. indices[index++] = topOffset + j + 1;
  346. indices[index++] = bottomOffset + j;
  347. indices[index++] = topOffset + j + 1;
  348. indices[index++] = topOffset + j;
  349. }
  350. }
  351. // Create indices for inner surface
  352. if (hasInnerSurface) {
  353. const offset = numPhis * numThetas;
  354. for (i = 1; i < numPhis - 2; i++) {
  355. topOffset = offset + i * numThetas;
  356. bottomOffset = offset + (i + 1) * numThetas;
  357. for (j = 1; j < numThetas - 2; j++) {
  358. indices[index++] = bottomOffset + j;
  359. indices[index++] = topOffset + j;
  360. indices[index++] = topOffset + j + 1;
  361. indices[index++] = bottomOffset + j;
  362. indices[index++] = topOffset + j + 1;
  363. indices[index++] = bottomOffset + j + 1;
  364. }
  365. }
  366. }
  367. let outerOffset;
  368. let innerOffset;
  369. if (hasInnerSurface) {
  370. if (isTopOpen) {
  371. // Connect the top of the inner surface to the top of the outer surface
  372. innerOffset = numPhis * numThetas;
  373. for (i = 1; i < numThetas - 2; i++) {
  374. indices[index++] = i;
  375. indices[index++] = i + 1;
  376. indices[index++] = innerOffset + i + 1;
  377. indices[index++] = i;
  378. indices[index++] = innerOffset + i + 1;
  379. indices[index++] = innerOffset + i;
  380. }
  381. }
  382. if (isBotOpen) {
  383. // Connect the bottom of the inner surface to the bottom of the outer surface
  384. outerOffset = numPhis * numThetas - numThetas;
  385. innerOffset = numPhis * numThetas * vertexMultiplier - numThetas;
  386. for (i = 1; i < numThetas - 2; i++) {
  387. indices[index++] = outerOffset + i + 1;
  388. indices[index++] = outerOffset + i;
  389. indices[index++] = innerOffset + i;
  390. indices[index++] = outerOffset + i + 1;
  391. indices[index++] = innerOffset + i;
  392. indices[index++] = innerOffset + i + 1;
  393. }
  394. }
  395. }
  396. // Connect the edges if clock is not closed
  397. if (isClockOpen) {
  398. for (i = 1; i < numPhis - 2; i++) {
  399. innerOffset = numThetas * numPhis + numThetas * i;
  400. outerOffset = numThetas * i;
  401. indices[index++] = innerOffset;
  402. indices[index++] = outerOffset + numThetas;
  403. indices[index++] = outerOffset;
  404. indices[index++] = innerOffset;
  405. indices[index++] = innerOffset + numThetas;
  406. indices[index++] = outerOffset + numThetas;
  407. }
  408. for (i = 1; i < numPhis - 2; i++) {
  409. innerOffset = numThetas * numPhis + numThetas * (i + 1) - 1;
  410. outerOffset = numThetas * (i + 1) - 1;
  411. indices[index++] = outerOffset + numThetas;
  412. indices[index++] = innerOffset;
  413. indices[index++] = outerOffset;
  414. indices[index++] = outerOffset + numThetas;
  415. indices[index++] = innerOffset + numThetas;
  416. indices[index++] = innerOffset;
  417. }
  418. }
  419. const attributes = new GeometryAttributes.GeometryAttributes();
  420. if (vertexFormat.position) {
  421. attributes.position = new GeometryAttribute.GeometryAttribute({
  422. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  423. componentsPerAttribute: 3,
  424. values: positions,
  425. });
  426. }
  427. let stIndex = 0;
  428. let normalIndex = 0;
  429. let tangentIndex = 0;
  430. let bitangentIndex = 0;
  431. const vertexCountHalf = vertexCount / 2.0;
  432. let ellipsoid;
  433. const ellipsoidOuter = Matrix2.Ellipsoid.fromCartesian3(radii);
  434. const ellipsoidInner = Matrix2.Ellipsoid.fromCartesian3(innerRadii);
  435. if (
  436. vertexFormat.st ||
  437. vertexFormat.normal ||
  438. vertexFormat.tangent ||
  439. vertexFormat.bitangent
  440. ) {
  441. for (i = 0; i < vertexCount; i++) {
  442. ellipsoid = isInner[i] ? ellipsoidInner : ellipsoidOuter;
  443. const position = Matrix2.Cartesian3.fromArray(positions, i * 3, scratchPosition);
  444. const normal = ellipsoid.geodeticSurfaceNormal(position, scratchNormal);
  445. if (negateNormal[i]) {
  446. Matrix2.Cartesian3.negate(normal, normal);
  447. }
  448. if (vertexFormat.st) {
  449. const normalST = Matrix2.Cartesian2.negate(normal, scratchNormalST);
  450. st[stIndex++] =
  451. Math.atan2(normalST.y, normalST.x) / ComponentDatatype.CesiumMath.TWO_PI + 0.5;
  452. st[stIndex++] = Math.asin(normal.z) / Math.PI + 0.5;
  453. }
  454. if (vertexFormat.normal) {
  455. normals[normalIndex++] = normal.x;
  456. normals[normalIndex++] = normal.y;
  457. normals[normalIndex++] = normal.z;
  458. }
  459. if (vertexFormat.tangent || vertexFormat.bitangent) {
  460. const tangent = scratchTangent;
  461. // Use UNIT_X for the poles
  462. let tangetOffset = 0;
  463. let unit;
  464. if (isInner[i]) {
  465. tangetOffset = vertexCountHalf;
  466. }
  467. if (
  468. !isTopOpen &&
  469. i >= tangetOffset &&
  470. i < tangetOffset + numThetas * 2
  471. ) {
  472. unit = Matrix2.Cartesian3.UNIT_X;
  473. } else {
  474. unit = Matrix2.Cartesian3.UNIT_Z;
  475. }
  476. Matrix2.Cartesian3.cross(unit, normal, tangent);
  477. Matrix2.Cartesian3.normalize(tangent, tangent);
  478. if (vertexFormat.tangent) {
  479. tangents[tangentIndex++] = tangent.x;
  480. tangents[tangentIndex++] = tangent.y;
  481. tangents[tangentIndex++] = tangent.z;
  482. }
  483. if (vertexFormat.bitangent) {
  484. const bitangent = Matrix2.Cartesian3.cross(normal, tangent, scratchBitangent);
  485. Matrix2.Cartesian3.normalize(bitangent, bitangent);
  486. bitangents[bitangentIndex++] = bitangent.x;
  487. bitangents[bitangentIndex++] = bitangent.y;
  488. bitangents[bitangentIndex++] = bitangent.z;
  489. }
  490. }
  491. }
  492. if (vertexFormat.st) {
  493. attributes.st = new GeometryAttribute.GeometryAttribute({
  494. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  495. componentsPerAttribute: 2,
  496. values: st,
  497. });
  498. }
  499. if (vertexFormat.normal) {
  500. attributes.normal = new GeometryAttribute.GeometryAttribute({
  501. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  502. componentsPerAttribute: 3,
  503. values: normals,
  504. });
  505. }
  506. if (vertexFormat.tangent) {
  507. attributes.tangent = new GeometryAttribute.GeometryAttribute({
  508. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  509. componentsPerAttribute: 3,
  510. values: tangents,
  511. });
  512. }
  513. if (vertexFormat.bitangent) {
  514. attributes.bitangent = new GeometryAttribute.GeometryAttribute({
  515. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  516. componentsPerAttribute: 3,
  517. values: bitangents,
  518. });
  519. }
  520. }
  521. if (defaultValue.defined(ellipsoidGeometry._offsetAttribute)) {
  522. const length = positions.length;
  523. const applyOffset = new Uint8Array(length / 3);
  524. const offsetValue =
  525. ellipsoidGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE
  526. ? 0
  527. : 1;
  528. GeometryOffsetAttribute.arrayFill(applyOffset, offsetValue);
  529. attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  530. componentDatatype: ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  531. componentsPerAttribute: 1,
  532. values: applyOffset,
  533. });
  534. }
  535. return new GeometryAttribute.Geometry({
  536. attributes: attributes,
  537. indices: indices,
  538. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  539. boundingSphere: Transforms.BoundingSphere.fromEllipsoid(ellipsoidOuter),
  540. offsetAttribute: ellipsoidGeometry._offsetAttribute,
  541. });
  542. };
  543. let unitEllipsoidGeometry;
  544. /**
  545. * Returns the geometric representation of a unit ellipsoid, including its vertices, indices, and a bounding sphere.
  546. * @returns {Geometry} The computed vertices and indices.
  547. *
  548. * @private
  549. */
  550. EllipsoidGeometry.getUnitEllipsoid = function () {
  551. if (!defaultValue.defined(unitEllipsoidGeometry)) {
  552. unitEllipsoidGeometry = EllipsoidGeometry.createGeometry(
  553. new EllipsoidGeometry({
  554. radii: new Matrix2.Cartesian3(1.0, 1.0, 1.0),
  555. vertexFormat: VertexFormat.VertexFormat.POSITION_ONLY,
  556. })
  557. );
  558. }
  559. return unitEllipsoidGeometry;
  560. };
  561. exports.EllipsoidGeometry = EllipsoidGeometry;
  562. }));