EllipsoidGeometry-508da15c.js 23 KB

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