EllipsoidGeometry-c9dbbf37.js 24 KB

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