EllipsoidGeometry-592b342c.js 28 KB

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