EllipsoidGeometry.js 25 KB

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