EllipseGeometry-f3165ab0.js 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './GeometryOffsetAttribute-3e8c299c', './Transforms-a076dbe6', './Matrix2-fc7e9822', './RuntimeError-c581ca93', './ComponentDatatype-4a60b8d6', './defaultValue-94c3e563', './EllipseGeometryLibrary-4199bc89', './GeometryAttribute-2ecf73f6', './GeometryAttributes-7df9bef6', './GeometryInstance-97bd792f', './GeometryPipeline-b4816e69', './IndexDatatype-db156785', './VertexFormat-e46f29d6'], (function (exports, GeometryOffsetAttribute, Transforms, Matrix2, RuntimeError, ComponentDatatype, defaultValue, EllipseGeometryLibrary, GeometryAttribute, GeometryAttributes, GeometryInstance, GeometryPipeline, IndexDatatype, VertexFormat) { 'use strict';
  3. const scratchCartesian1 = new Matrix2.Cartesian3();
  4. const scratchCartesian2 = new Matrix2.Cartesian3();
  5. const scratchCartesian3 = new Matrix2.Cartesian3();
  6. const scratchCartesian4 = new Matrix2.Cartesian3();
  7. const texCoordScratch = new Matrix2.Cartesian2();
  8. const textureMatrixScratch = new Matrix2.Matrix3();
  9. const tangentMatrixScratch = new Matrix2.Matrix3();
  10. const quaternionScratch = new Transforms.Quaternion();
  11. const scratchNormal = new Matrix2.Cartesian3();
  12. const scratchTangent = new Matrix2.Cartesian3();
  13. const scratchBitangent = new Matrix2.Cartesian3();
  14. const scratchCartographic = new Matrix2.Cartographic();
  15. const projectedCenterScratch = new Matrix2.Cartesian3();
  16. const scratchMinTexCoord = new Matrix2.Cartesian2();
  17. const scratchMaxTexCoord = new Matrix2.Cartesian2();
  18. function computeTopBottomAttributes(positions, options, extrude) {
  19. const vertexFormat = options.vertexFormat;
  20. const center = options.center;
  21. const semiMajorAxis = options.semiMajorAxis;
  22. const semiMinorAxis = options.semiMinorAxis;
  23. const ellipsoid = options.ellipsoid;
  24. const stRotation = options.stRotation;
  25. const size = extrude ? (positions.length / 3) * 2 : positions.length / 3;
  26. const shadowVolume = options.shadowVolume;
  27. const textureCoordinates = vertexFormat.st
  28. ? new Float32Array(size * 2)
  29. : undefined;
  30. const normals = vertexFormat.normal ? new Float32Array(size * 3) : undefined;
  31. const tangents = vertexFormat.tangent
  32. ? new Float32Array(size * 3)
  33. : undefined;
  34. const bitangents = vertexFormat.bitangent
  35. ? new Float32Array(size * 3)
  36. : undefined;
  37. const extrudeNormals = shadowVolume ? new Float32Array(size * 3) : undefined;
  38. let textureCoordIndex = 0;
  39. // Raise positions to a height above the ellipsoid and compute the
  40. // texture coordinates, normals, tangents, and bitangents.
  41. let normal = scratchNormal;
  42. let tangent = scratchTangent;
  43. let bitangent = scratchBitangent;
  44. const projection = new Transforms.GeographicProjection(ellipsoid);
  45. const projectedCenter = projection.project(
  46. ellipsoid.cartesianToCartographic(center, scratchCartographic),
  47. projectedCenterScratch
  48. );
  49. const geodeticNormal = ellipsoid.scaleToGeodeticSurface(
  50. center,
  51. scratchCartesian1
  52. );
  53. ellipsoid.geodeticSurfaceNormal(geodeticNormal, geodeticNormal);
  54. let textureMatrix = textureMatrixScratch;
  55. let tangentMatrix = tangentMatrixScratch;
  56. if (stRotation !== 0) {
  57. let rotation = Transforms.Quaternion.fromAxisAngle(
  58. geodeticNormal,
  59. stRotation,
  60. quaternionScratch
  61. );
  62. textureMatrix = Matrix2.Matrix3.fromQuaternion(rotation, textureMatrix);
  63. rotation = Transforms.Quaternion.fromAxisAngle(
  64. geodeticNormal,
  65. -stRotation,
  66. quaternionScratch
  67. );
  68. tangentMatrix = Matrix2.Matrix3.fromQuaternion(rotation, tangentMatrix);
  69. } else {
  70. textureMatrix = Matrix2.Matrix3.clone(Matrix2.Matrix3.IDENTITY, textureMatrix);
  71. tangentMatrix = Matrix2.Matrix3.clone(Matrix2.Matrix3.IDENTITY, tangentMatrix);
  72. }
  73. const minTexCoord = Matrix2.Cartesian2.fromElements(
  74. Number.POSITIVE_INFINITY,
  75. Number.POSITIVE_INFINITY,
  76. scratchMinTexCoord
  77. );
  78. const maxTexCoord = Matrix2.Cartesian2.fromElements(
  79. Number.NEGATIVE_INFINITY,
  80. Number.NEGATIVE_INFINITY,
  81. scratchMaxTexCoord
  82. );
  83. let length = positions.length;
  84. const bottomOffset = extrude ? length : 0;
  85. const stOffset = (bottomOffset / 3) * 2;
  86. for (let i = 0; i < length; i += 3) {
  87. const i1 = i + 1;
  88. const i2 = i + 2;
  89. const position = Matrix2.Cartesian3.fromArray(positions, i, scratchCartesian1);
  90. if (vertexFormat.st) {
  91. const rotatedPoint = Matrix2.Matrix3.multiplyByVector(
  92. textureMatrix,
  93. position,
  94. scratchCartesian2
  95. );
  96. const projectedPoint = projection.project(
  97. ellipsoid.cartesianToCartographic(rotatedPoint, scratchCartographic),
  98. scratchCartesian3
  99. );
  100. Matrix2.Cartesian3.subtract(projectedPoint, projectedCenter, projectedPoint);
  101. texCoordScratch.x =
  102. (projectedPoint.x + semiMajorAxis) / (2.0 * semiMajorAxis);
  103. texCoordScratch.y =
  104. (projectedPoint.y + semiMinorAxis) / (2.0 * semiMinorAxis);
  105. minTexCoord.x = Math.min(texCoordScratch.x, minTexCoord.x);
  106. minTexCoord.y = Math.min(texCoordScratch.y, minTexCoord.y);
  107. maxTexCoord.x = Math.max(texCoordScratch.x, maxTexCoord.x);
  108. maxTexCoord.y = Math.max(texCoordScratch.y, maxTexCoord.y);
  109. if (extrude) {
  110. textureCoordinates[textureCoordIndex + stOffset] = texCoordScratch.x;
  111. textureCoordinates[textureCoordIndex + 1 + stOffset] =
  112. texCoordScratch.y;
  113. }
  114. textureCoordinates[textureCoordIndex++] = texCoordScratch.x;
  115. textureCoordinates[textureCoordIndex++] = texCoordScratch.y;
  116. }
  117. if (
  118. vertexFormat.normal ||
  119. vertexFormat.tangent ||
  120. vertexFormat.bitangent ||
  121. shadowVolume
  122. ) {
  123. normal = ellipsoid.geodeticSurfaceNormal(position, normal);
  124. if (shadowVolume) {
  125. extrudeNormals[i + bottomOffset] = -normal.x;
  126. extrudeNormals[i1 + bottomOffset] = -normal.y;
  127. extrudeNormals[i2 + bottomOffset] = -normal.z;
  128. }
  129. if (
  130. vertexFormat.normal ||
  131. vertexFormat.tangent ||
  132. vertexFormat.bitangent
  133. ) {
  134. if (vertexFormat.tangent || vertexFormat.bitangent) {
  135. tangent = Matrix2.Cartesian3.normalize(
  136. Matrix2.Cartesian3.cross(Matrix2.Cartesian3.UNIT_Z, normal, tangent),
  137. tangent
  138. );
  139. Matrix2.Matrix3.multiplyByVector(tangentMatrix, tangent, tangent);
  140. }
  141. if (vertexFormat.normal) {
  142. normals[i] = normal.x;
  143. normals[i1] = normal.y;
  144. normals[i2] = normal.z;
  145. if (extrude) {
  146. normals[i + bottomOffset] = -normal.x;
  147. normals[i1 + bottomOffset] = -normal.y;
  148. normals[i2 + bottomOffset] = -normal.z;
  149. }
  150. }
  151. if (vertexFormat.tangent) {
  152. tangents[i] = tangent.x;
  153. tangents[i1] = tangent.y;
  154. tangents[i2] = tangent.z;
  155. if (extrude) {
  156. tangents[i + bottomOffset] = -tangent.x;
  157. tangents[i1 + bottomOffset] = -tangent.y;
  158. tangents[i2 + bottomOffset] = -tangent.z;
  159. }
  160. }
  161. if (vertexFormat.bitangent) {
  162. bitangent = Matrix2.Cartesian3.normalize(
  163. Matrix2.Cartesian3.cross(normal, tangent, bitangent),
  164. bitangent
  165. );
  166. bitangents[i] = bitangent.x;
  167. bitangents[i1] = bitangent.y;
  168. bitangents[i2] = bitangent.z;
  169. if (extrude) {
  170. bitangents[i + bottomOffset] = bitangent.x;
  171. bitangents[i1 + bottomOffset] = bitangent.y;
  172. bitangents[i2 + bottomOffset] = bitangent.z;
  173. }
  174. }
  175. }
  176. }
  177. }
  178. if (vertexFormat.st) {
  179. length = textureCoordinates.length;
  180. for (let k = 0; k < length; k += 2) {
  181. textureCoordinates[k] =
  182. (textureCoordinates[k] - minTexCoord.x) /
  183. (maxTexCoord.x - minTexCoord.x);
  184. textureCoordinates[k + 1] =
  185. (textureCoordinates[k + 1] - minTexCoord.y) /
  186. (maxTexCoord.y - minTexCoord.y);
  187. }
  188. }
  189. const attributes = new GeometryAttributes.GeometryAttributes();
  190. if (vertexFormat.position) {
  191. const finalPositions = EllipseGeometryLibrary.EllipseGeometryLibrary.raisePositionsToHeight(
  192. positions,
  193. options,
  194. extrude
  195. );
  196. attributes.position = new GeometryAttribute.GeometryAttribute({
  197. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  198. componentsPerAttribute: 3,
  199. values: finalPositions,
  200. });
  201. }
  202. if (vertexFormat.st) {
  203. attributes.st = new GeometryAttribute.GeometryAttribute({
  204. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  205. componentsPerAttribute: 2,
  206. values: textureCoordinates,
  207. });
  208. }
  209. if (vertexFormat.normal) {
  210. attributes.normal = new GeometryAttribute.GeometryAttribute({
  211. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  212. componentsPerAttribute: 3,
  213. values: normals,
  214. });
  215. }
  216. if (vertexFormat.tangent) {
  217. attributes.tangent = new GeometryAttribute.GeometryAttribute({
  218. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  219. componentsPerAttribute: 3,
  220. values: tangents,
  221. });
  222. }
  223. if (vertexFormat.bitangent) {
  224. attributes.bitangent = new GeometryAttribute.GeometryAttribute({
  225. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  226. componentsPerAttribute: 3,
  227. values: bitangents,
  228. });
  229. }
  230. if (shadowVolume) {
  231. attributes.extrudeDirection = new GeometryAttribute.GeometryAttribute({
  232. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  233. componentsPerAttribute: 3,
  234. values: extrudeNormals,
  235. });
  236. }
  237. if (extrude && defaultValue.defined(options.offsetAttribute)) {
  238. let offsetAttribute = new Uint8Array(size);
  239. if (options.offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.TOP) {
  240. offsetAttribute = GeometryOffsetAttribute.arrayFill(offsetAttribute, 1, 0, size / 2);
  241. } else {
  242. const offsetValue =
  243. options.offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE ? 0 : 1;
  244. offsetAttribute = GeometryOffsetAttribute.arrayFill(offsetAttribute, offsetValue);
  245. }
  246. attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  247. componentDatatype: ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  248. componentsPerAttribute: 1,
  249. values: offsetAttribute,
  250. });
  251. }
  252. return attributes;
  253. }
  254. function topIndices(numPts) {
  255. // numTriangles in half = 3 + 8 + 12 + ... = -1 + 4 + (4 + 4) + (4 + 4 + 4) + ... = -1 + 4 * (1 + 2 + 3 + ...)
  256. // = -1 + 4 * ((n * ( n + 1)) / 2)
  257. // total triangles = 2 * numTrangles in half
  258. // indices = total triangles * 3;
  259. // Substitute numPts for n above
  260. const indices = new Array(12 * (numPts * (numPts + 1)) - 6);
  261. let indicesIndex = 0;
  262. let prevIndex;
  263. let numInterior;
  264. let positionIndex;
  265. let i;
  266. let j;
  267. // Indices triangles to the 'right' of the north vector
  268. prevIndex = 0;
  269. positionIndex = 1;
  270. for (i = 0; i < 3; i++) {
  271. indices[indicesIndex++] = positionIndex++;
  272. indices[indicesIndex++] = prevIndex;
  273. indices[indicesIndex++] = positionIndex;
  274. }
  275. for (i = 2; i < numPts + 1; ++i) {
  276. positionIndex = i * (i + 1) - 1;
  277. prevIndex = (i - 1) * i - 1;
  278. indices[indicesIndex++] = positionIndex++;
  279. indices[indicesIndex++] = prevIndex;
  280. indices[indicesIndex++] = positionIndex;
  281. numInterior = 2 * i;
  282. for (j = 0; j < numInterior - 1; ++j) {
  283. indices[indicesIndex++] = positionIndex;
  284. indices[indicesIndex++] = prevIndex++;
  285. indices[indicesIndex++] = prevIndex;
  286. indices[indicesIndex++] = positionIndex++;
  287. indices[indicesIndex++] = prevIndex;
  288. indices[indicesIndex++] = positionIndex;
  289. }
  290. indices[indicesIndex++] = positionIndex++;
  291. indices[indicesIndex++] = prevIndex;
  292. indices[indicesIndex++] = positionIndex;
  293. }
  294. // Indices for center column of triangles
  295. numInterior = numPts * 2;
  296. ++positionIndex;
  297. ++prevIndex;
  298. for (i = 0; i < numInterior - 1; ++i) {
  299. indices[indicesIndex++] = positionIndex;
  300. indices[indicesIndex++] = prevIndex++;
  301. indices[indicesIndex++] = prevIndex;
  302. indices[indicesIndex++] = positionIndex++;
  303. indices[indicesIndex++] = prevIndex;
  304. indices[indicesIndex++] = positionIndex;
  305. }
  306. indices[indicesIndex++] = positionIndex;
  307. indices[indicesIndex++] = prevIndex++;
  308. indices[indicesIndex++] = prevIndex;
  309. indices[indicesIndex++] = positionIndex++;
  310. indices[indicesIndex++] = prevIndex++;
  311. indices[indicesIndex++] = prevIndex;
  312. // Reverse the process creating indices to the 'left' of the north vector
  313. ++prevIndex;
  314. for (i = numPts - 1; i > 1; --i) {
  315. indices[indicesIndex++] = prevIndex++;
  316. indices[indicesIndex++] = prevIndex;
  317. indices[indicesIndex++] = positionIndex;
  318. numInterior = 2 * i;
  319. for (j = 0; j < numInterior - 1; ++j) {
  320. indices[indicesIndex++] = positionIndex;
  321. indices[indicesIndex++] = prevIndex++;
  322. indices[indicesIndex++] = prevIndex;
  323. indices[indicesIndex++] = positionIndex++;
  324. indices[indicesIndex++] = prevIndex;
  325. indices[indicesIndex++] = positionIndex;
  326. }
  327. indices[indicesIndex++] = prevIndex++;
  328. indices[indicesIndex++] = prevIndex++;
  329. indices[indicesIndex++] = positionIndex++;
  330. }
  331. for (i = 0; i < 3; i++) {
  332. indices[indicesIndex++] = prevIndex++;
  333. indices[indicesIndex++] = prevIndex;
  334. indices[indicesIndex++] = positionIndex;
  335. }
  336. return indices;
  337. }
  338. let boundingSphereCenter = new Matrix2.Cartesian3();
  339. function computeEllipse(options) {
  340. const center = options.center;
  341. boundingSphereCenter = Matrix2.Cartesian3.multiplyByScalar(
  342. options.ellipsoid.geodeticSurfaceNormal(center, boundingSphereCenter),
  343. options.height,
  344. boundingSphereCenter
  345. );
  346. boundingSphereCenter = Matrix2.Cartesian3.add(
  347. center,
  348. boundingSphereCenter,
  349. boundingSphereCenter
  350. );
  351. const boundingSphere = new Transforms.BoundingSphere(
  352. boundingSphereCenter,
  353. options.semiMajorAxis
  354. );
  355. const cep = EllipseGeometryLibrary.EllipseGeometryLibrary.computeEllipsePositions(
  356. options,
  357. true,
  358. false
  359. );
  360. const positions = cep.positions;
  361. const numPts = cep.numPts;
  362. const attributes = computeTopBottomAttributes(positions, options, false);
  363. let indices = topIndices(numPts);
  364. indices = IndexDatatype.IndexDatatype.createTypedArray(positions.length / 3, indices);
  365. return {
  366. boundingSphere: boundingSphere,
  367. attributes: attributes,
  368. indices: indices,
  369. };
  370. }
  371. function computeWallAttributes(positions, options) {
  372. const vertexFormat = options.vertexFormat;
  373. const center = options.center;
  374. const semiMajorAxis = options.semiMajorAxis;
  375. const semiMinorAxis = options.semiMinorAxis;
  376. const ellipsoid = options.ellipsoid;
  377. const height = options.height;
  378. const extrudedHeight = options.extrudedHeight;
  379. const stRotation = options.stRotation;
  380. const size = (positions.length / 3) * 2;
  381. const finalPositions = new Float64Array(size * 3);
  382. const textureCoordinates = vertexFormat.st
  383. ? new Float32Array(size * 2)
  384. : undefined;
  385. const normals = vertexFormat.normal ? new Float32Array(size * 3) : undefined;
  386. const tangents = vertexFormat.tangent
  387. ? new Float32Array(size * 3)
  388. : undefined;
  389. const bitangents = vertexFormat.bitangent
  390. ? new Float32Array(size * 3)
  391. : undefined;
  392. const shadowVolume = options.shadowVolume;
  393. const extrudeNormals = shadowVolume ? new Float32Array(size * 3) : undefined;
  394. let textureCoordIndex = 0;
  395. // Raise positions to a height above the ellipsoid and compute the
  396. // texture coordinates, normals, tangents, and bitangents.
  397. let normal = scratchNormal;
  398. let tangent = scratchTangent;
  399. let bitangent = scratchBitangent;
  400. const projection = new Transforms.GeographicProjection(ellipsoid);
  401. const projectedCenter = projection.project(
  402. ellipsoid.cartesianToCartographic(center, scratchCartographic),
  403. projectedCenterScratch
  404. );
  405. const geodeticNormal = ellipsoid.scaleToGeodeticSurface(
  406. center,
  407. scratchCartesian1
  408. );
  409. ellipsoid.geodeticSurfaceNormal(geodeticNormal, geodeticNormal);
  410. const rotation = Transforms.Quaternion.fromAxisAngle(
  411. geodeticNormal,
  412. stRotation,
  413. quaternionScratch
  414. );
  415. const textureMatrix = Matrix2.Matrix3.fromQuaternion(rotation, textureMatrixScratch);
  416. const minTexCoord = Matrix2.Cartesian2.fromElements(
  417. Number.POSITIVE_INFINITY,
  418. Number.POSITIVE_INFINITY,
  419. scratchMinTexCoord
  420. );
  421. const maxTexCoord = Matrix2.Cartesian2.fromElements(
  422. Number.NEGATIVE_INFINITY,
  423. Number.NEGATIVE_INFINITY,
  424. scratchMaxTexCoord
  425. );
  426. let length = positions.length;
  427. const stOffset = (length / 3) * 2;
  428. for (let i = 0; i < length; i += 3) {
  429. const i1 = i + 1;
  430. const i2 = i + 2;
  431. let position = Matrix2.Cartesian3.fromArray(positions, i, scratchCartesian1);
  432. let extrudedPosition;
  433. if (vertexFormat.st) {
  434. const rotatedPoint = Matrix2.Matrix3.multiplyByVector(
  435. textureMatrix,
  436. position,
  437. scratchCartesian2
  438. );
  439. const projectedPoint = projection.project(
  440. ellipsoid.cartesianToCartographic(rotatedPoint, scratchCartographic),
  441. scratchCartesian3
  442. );
  443. Matrix2.Cartesian3.subtract(projectedPoint, projectedCenter, projectedPoint);
  444. texCoordScratch.x =
  445. (projectedPoint.x + semiMajorAxis) / (2.0 * semiMajorAxis);
  446. texCoordScratch.y =
  447. (projectedPoint.y + semiMinorAxis) / (2.0 * semiMinorAxis);
  448. minTexCoord.x = Math.min(texCoordScratch.x, minTexCoord.x);
  449. minTexCoord.y = Math.min(texCoordScratch.y, minTexCoord.y);
  450. maxTexCoord.x = Math.max(texCoordScratch.x, maxTexCoord.x);
  451. maxTexCoord.y = Math.max(texCoordScratch.y, maxTexCoord.y);
  452. textureCoordinates[textureCoordIndex + stOffset] = texCoordScratch.x;
  453. textureCoordinates[textureCoordIndex + 1 + stOffset] = texCoordScratch.y;
  454. textureCoordinates[textureCoordIndex++] = texCoordScratch.x;
  455. textureCoordinates[textureCoordIndex++] = texCoordScratch.y;
  456. }
  457. position = ellipsoid.scaleToGeodeticSurface(position, position);
  458. extrudedPosition = Matrix2.Cartesian3.clone(position, scratchCartesian2);
  459. normal = ellipsoid.geodeticSurfaceNormal(position, normal);
  460. if (shadowVolume) {
  461. extrudeNormals[i + length] = -normal.x;
  462. extrudeNormals[i1 + length] = -normal.y;
  463. extrudeNormals[i2 + length] = -normal.z;
  464. }
  465. let scaledNormal = Matrix2.Cartesian3.multiplyByScalar(
  466. normal,
  467. height,
  468. scratchCartesian4
  469. );
  470. position = Matrix2.Cartesian3.add(position, scaledNormal, position);
  471. scaledNormal = Matrix2.Cartesian3.multiplyByScalar(
  472. normal,
  473. extrudedHeight,
  474. scaledNormal
  475. );
  476. extrudedPosition = Matrix2.Cartesian3.add(
  477. extrudedPosition,
  478. scaledNormal,
  479. extrudedPosition
  480. );
  481. if (vertexFormat.position) {
  482. finalPositions[i + length] = extrudedPosition.x;
  483. finalPositions[i1 + length] = extrudedPosition.y;
  484. finalPositions[i2 + length] = extrudedPosition.z;
  485. finalPositions[i] = position.x;
  486. finalPositions[i1] = position.y;
  487. finalPositions[i2] = position.z;
  488. }
  489. if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.bitangent) {
  490. bitangent = Matrix2.Cartesian3.clone(normal, bitangent);
  491. const next = Matrix2.Cartesian3.fromArray(
  492. positions,
  493. (i + 3) % length,
  494. scratchCartesian4
  495. );
  496. Matrix2.Cartesian3.subtract(next, position, next);
  497. const bottom = Matrix2.Cartesian3.subtract(
  498. extrudedPosition,
  499. position,
  500. scratchCartesian3
  501. );
  502. normal = Matrix2.Cartesian3.normalize(
  503. Matrix2.Cartesian3.cross(bottom, next, normal),
  504. normal
  505. );
  506. if (vertexFormat.normal) {
  507. normals[i] = normal.x;
  508. normals[i1] = normal.y;
  509. normals[i2] = normal.z;
  510. normals[i + length] = normal.x;
  511. normals[i1 + length] = normal.y;
  512. normals[i2 + length] = normal.z;
  513. }
  514. if (vertexFormat.tangent) {
  515. tangent = Matrix2.Cartesian3.normalize(
  516. Matrix2.Cartesian3.cross(bitangent, normal, tangent),
  517. tangent
  518. );
  519. tangents[i] = tangent.x;
  520. tangents[i1] = tangent.y;
  521. tangents[i2] = tangent.z;
  522. tangents[i + length] = tangent.x;
  523. tangents[i + 1 + length] = tangent.y;
  524. tangents[i + 2 + length] = tangent.z;
  525. }
  526. if (vertexFormat.bitangent) {
  527. bitangents[i] = bitangent.x;
  528. bitangents[i1] = bitangent.y;
  529. bitangents[i2] = bitangent.z;
  530. bitangents[i + length] = bitangent.x;
  531. bitangents[i1 + length] = bitangent.y;
  532. bitangents[i2 + length] = bitangent.z;
  533. }
  534. }
  535. }
  536. if (vertexFormat.st) {
  537. length = textureCoordinates.length;
  538. for (let k = 0; k < length; k += 2) {
  539. textureCoordinates[k] =
  540. (textureCoordinates[k] - minTexCoord.x) /
  541. (maxTexCoord.x - minTexCoord.x);
  542. textureCoordinates[k + 1] =
  543. (textureCoordinates[k + 1] - minTexCoord.y) /
  544. (maxTexCoord.y - minTexCoord.y);
  545. }
  546. }
  547. const attributes = new GeometryAttributes.GeometryAttributes();
  548. if (vertexFormat.position) {
  549. attributes.position = new GeometryAttribute.GeometryAttribute({
  550. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  551. componentsPerAttribute: 3,
  552. values: finalPositions,
  553. });
  554. }
  555. if (vertexFormat.st) {
  556. attributes.st = new GeometryAttribute.GeometryAttribute({
  557. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  558. componentsPerAttribute: 2,
  559. values: textureCoordinates,
  560. });
  561. }
  562. if (vertexFormat.normal) {
  563. attributes.normal = new GeometryAttribute.GeometryAttribute({
  564. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  565. componentsPerAttribute: 3,
  566. values: normals,
  567. });
  568. }
  569. if (vertexFormat.tangent) {
  570. attributes.tangent = new GeometryAttribute.GeometryAttribute({
  571. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  572. componentsPerAttribute: 3,
  573. values: tangents,
  574. });
  575. }
  576. if (vertexFormat.bitangent) {
  577. attributes.bitangent = new GeometryAttribute.GeometryAttribute({
  578. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  579. componentsPerAttribute: 3,
  580. values: bitangents,
  581. });
  582. }
  583. if (shadowVolume) {
  584. attributes.extrudeDirection = new GeometryAttribute.GeometryAttribute({
  585. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  586. componentsPerAttribute: 3,
  587. values: extrudeNormals,
  588. });
  589. }
  590. if (defaultValue.defined(options.offsetAttribute)) {
  591. let offsetAttribute = new Uint8Array(size);
  592. if (options.offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.TOP) {
  593. offsetAttribute = GeometryOffsetAttribute.arrayFill(offsetAttribute, 1, 0, size / 2);
  594. } else {
  595. const offsetValue =
  596. options.offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE ? 0 : 1;
  597. offsetAttribute = GeometryOffsetAttribute.arrayFill(offsetAttribute, offsetValue);
  598. }
  599. attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  600. componentDatatype: ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  601. componentsPerAttribute: 1,
  602. values: offsetAttribute,
  603. });
  604. }
  605. return attributes;
  606. }
  607. function computeWallIndices(positions) {
  608. const length = positions.length / 3;
  609. const indices = IndexDatatype.IndexDatatype.createTypedArray(length, length * 6);
  610. let index = 0;
  611. for (let i = 0; i < length; i++) {
  612. const UL = i;
  613. const LL = i + length;
  614. const UR = (UL + 1) % length;
  615. const LR = UR + length;
  616. indices[index++] = UL;
  617. indices[index++] = LL;
  618. indices[index++] = UR;
  619. indices[index++] = UR;
  620. indices[index++] = LL;
  621. indices[index++] = LR;
  622. }
  623. return indices;
  624. }
  625. const topBoundingSphere = new Transforms.BoundingSphere();
  626. const bottomBoundingSphere = new Transforms.BoundingSphere();
  627. function computeExtrudedEllipse(options) {
  628. const center = options.center;
  629. const ellipsoid = options.ellipsoid;
  630. const semiMajorAxis = options.semiMajorAxis;
  631. let scaledNormal = Matrix2.Cartesian3.multiplyByScalar(
  632. ellipsoid.geodeticSurfaceNormal(center, scratchCartesian1),
  633. options.height,
  634. scratchCartesian1
  635. );
  636. topBoundingSphere.center = Matrix2.Cartesian3.add(
  637. center,
  638. scaledNormal,
  639. topBoundingSphere.center
  640. );
  641. topBoundingSphere.radius = semiMajorAxis;
  642. scaledNormal = Matrix2.Cartesian3.multiplyByScalar(
  643. ellipsoid.geodeticSurfaceNormal(center, scaledNormal),
  644. options.extrudedHeight,
  645. scaledNormal
  646. );
  647. bottomBoundingSphere.center = Matrix2.Cartesian3.add(
  648. center,
  649. scaledNormal,
  650. bottomBoundingSphere.center
  651. );
  652. bottomBoundingSphere.radius = semiMajorAxis;
  653. const cep = EllipseGeometryLibrary.EllipseGeometryLibrary.computeEllipsePositions(
  654. options,
  655. true,
  656. true
  657. );
  658. const positions = cep.positions;
  659. const numPts = cep.numPts;
  660. const outerPositions = cep.outerPositions;
  661. const boundingSphere = Transforms.BoundingSphere.union(
  662. topBoundingSphere,
  663. bottomBoundingSphere
  664. );
  665. const topBottomAttributes = computeTopBottomAttributes(
  666. positions,
  667. options,
  668. true
  669. );
  670. let indices = topIndices(numPts);
  671. const length = indices.length;
  672. indices.length = length * 2;
  673. const posLength = positions.length / 3;
  674. for (let i = 0; i < length; i += 3) {
  675. indices[i + length] = indices[i + 2] + posLength;
  676. indices[i + 1 + length] = indices[i + 1] + posLength;
  677. indices[i + 2 + length] = indices[i] + posLength;
  678. }
  679. const topBottomIndices = IndexDatatype.IndexDatatype.createTypedArray(
  680. (posLength * 2) / 3,
  681. indices
  682. );
  683. const topBottomGeo = new GeometryAttribute.Geometry({
  684. attributes: topBottomAttributes,
  685. indices: topBottomIndices,
  686. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  687. });
  688. const wallAttributes = computeWallAttributes(outerPositions, options);
  689. indices = computeWallIndices(outerPositions);
  690. const wallIndices = IndexDatatype.IndexDatatype.createTypedArray(
  691. (outerPositions.length * 2) / 3,
  692. indices
  693. );
  694. const wallGeo = new GeometryAttribute.Geometry({
  695. attributes: wallAttributes,
  696. indices: wallIndices,
  697. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  698. });
  699. const geo = GeometryPipeline.GeometryPipeline.combineInstances([
  700. new GeometryInstance.GeometryInstance({
  701. geometry: topBottomGeo,
  702. }),
  703. new GeometryInstance.GeometryInstance({
  704. geometry: wallGeo,
  705. }),
  706. ]);
  707. return {
  708. boundingSphere: boundingSphere,
  709. attributes: geo[0].attributes,
  710. indices: geo[0].indices,
  711. };
  712. }
  713. function computeRectangle(
  714. center,
  715. semiMajorAxis,
  716. semiMinorAxis,
  717. rotation,
  718. granularity,
  719. ellipsoid,
  720. result
  721. ) {
  722. const cep = EllipseGeometryLibrary.EllipseGeometryLibrary.computeEllipsePositions(
  723. {
  724. center: center,
  725. semiMajorAxis: semiMajorAxis,
  726. semiMinorAxis: semiMinorAxis,
  727. rotation: rotation,
  728. granularity: granularity,
  729. },
  730. false,
  731. true
  732. );
  733. const positionsFlat = cep.outerPositions;
  734. const positionsCount = positionsFlat.length / 3;
  735. const positions = new Array(positionsCount);
  736. for (let i = 0; i < positionsCount; ++i) {
  737. positions[i] = Matrix2.Cartesian3.fromArray(positionsFlat, i * 3);
  738. }
  739. const rectangle = Matrix2.Rectangle.fromCartesianArray(positions, ellipsoid, result);
  740. // Rectangle width goes beyond 180 degrees when the ellipse crosses a pole.
  741. // When this happens, make the rectangle into a "circle" around the pole
  742. if (rectangle.width > ComponentDatatype.CesiumMath.PI) {
  743. rectangle.north =
  744. rectangle.north > 0.0
  745. ? ComponentDatatype.CesiumMath.PI_OVER_TWO - ComponentDatatype.CesiumMath.EPSILON7
  746. : rectangle.north;
  747. rectangle.south =
  748. rectangle.south < 0.0
  749. ? ComponentDatatype.CesiumMath.EPSILON7 - ComponentDatatype.CesiumMath.PI_OVER_TWO
  750. : rectangle.south;
  751. rectangle.east = ComponentDatatype.CesiumMath.PI;
  752. rectangle.west = -ComponentDatatype.CesiumMath.PI;
  753. }
  754. return rectangle;
  755. }
  756. /**
  757. * A description of an ellipse on an ellipsoid. Ellipse geometry can be rendered with both {@link Primitive} and {@link GroundPrimitive}.
  758. *
  759. * @alias EllipseGeometry
  760. * @constructor
  761. *
  762. * @param {Object} options Object with the following properties:
  763. * @param {Cartesian3} options.center The ellipse's center point in the fixed frame.
  764. * @param {Number} options.semiMajorAxis The length of the ellipse's semi-major axis in meters.
  765. * @param {Number} options.semiMinorAxis The length of the ellipse's semi-minor axis in meters.
  766. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid the ellipse will be on.
  767. * @param {Number} [options.height=0.0] The distance in meters between the ellipse and the ellipsoid surface.
  768. * @param {Number} [options.extrudedHeight] The distance in meters between the ellipse's extruded face and the ellipsoid surface.
  769. * @param {Number} [options.rotation=0.0] The angle of rotation counter-clockwise from north.
  770. * @param {Number} [options.stRotation=0.0] The rotation of the texture coordinates counter-clockwise from north.
  771. * @param {Number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The angular distance between points on the ellipse in radians.
  772. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  773. *
  774. * @exception {DeveloperError} semiMajorAxis and semiMinorAxis must be greater than zero.
  775. * @exception {DeveloperError} semiMajorAxis must be greater than or equal to the semiMinorAxis.
  776. * @exception {DeveloperError} granularity must be greater than zero.
  777. *
  778. *
  779. * @example
  780. * // Create an ellipse.
  781. * const ellipse = new Cesium.EllipseGeometry({
  782. * center : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
  783. * semiMajorAxis : 500000.0,
  784. * semiMinorAxis : 300000.0,
  785. * rotation : Cesium.Math.toRadians(60.0)
  786. * });
  787. * const geometry = Cesium.EllipseGeometry.createGeometry(ellipse);
  788. *
  789. * @see EllipseGeometry.createGeometry
  790. */
  791. function EllipseGeometry(options) {
  792. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  793. const center = options.center;
  794. const ellipsoid = defaultValue.defaultValue(options.ellipsoid, Matrix2.Ellipsoid.WGS84);
  795. const semiMajorAxis = options.semiMajorAxis;
  796. const semiMinorAxis = options.semiMinorAxis;
  797. const granularity = defaultValue.defaultValue(
  798. options.granularity,
  799. ComponentDatatype.CesiumMath.RADIANS_PER_DEGREE
  800. );
  801. const vertexFormat = defaultValue.defaultValue(options.vertexFormat, VertexFormat.VertexFormat.DEFAULT);
  802. //>>includeStart('debug', pragmas.debug);
  803. RuntimeError.Check.defined("options.center", center);
  804. RuntimeError.Check.typeOf.number("options.semiMajorAxis", semiMajorAxis);
  805. RuntimeError.Check.typeOf.number("options.semiMinorAxis", semiMinorAxis);
  806. if (semiMajorAxis < semiMinorAxis) {
  807. throw new RuntimeError.DeveloperError(
  808. "semiMajorAxis must be greater than or equal to the semiMinorAxis."
  809. );
  810. }
  811. if (granularity <= 0.0) {
  812. throw new RuntimeError.DeveloperError("granularity must be greater than zero.");
  813. }
  814. //>>includeEnd('debug');
  815. const height = defaultValue.defaultValue(options.height, 0.0);
  816. const extrudedHeight = defaultValue.defaultValue(options.extrudedHeight, height);
  817. this._center = Matrix2.Cartesian3.clone(center);
  818. this._semiMajorAxis = semiMajorAxis;
  819. this._semiMinorAxis = semiMinorAxis;
  820. this._ellipsoid = Matrix2.Ellipsoid.clone(ellipsoid);
  821. this._rotation = defaultValue.defaultValue(options.rotation, 0.0);
  822. this._stRotation = defaultValue.defaultValue(options.stRotation, 0.0);
  823. this._height = Math.max(extrudedHeight, height);
  824. this._granularity = granularity;
  825. this._vertexFormat = VertexFormat.VertexFormat.clone(vertexFormat);
  826. this._extrudedHeight = Math.min(extrudedHeight, height);
  827. this._shadowVolume = defaultValue.defaultValue(options.shadowVolume, false);
  828. this._workerName = "createEllipseGeometry";
  829. this._offsetAttribute = options.offsetAttribute;
  830. this._rectangle = undefined;
  831. this._textureCoordinateRotationPoints = undefined;
  832. }
  833. /**
  834. * The number of elements used to pack the object into an array.
  835. * @type {Number}
  836. */
  837. EllipseGeometry.packedLength =
  838. Matrix2.Cartesian3.packedLength +
  839. Matrix2.Ellipsoid.packedLength +
  840. VertexFormat.VertexFormat.packedLength +
  841. 9;
  842. /**
  843. * Stores the provided instance into the provided array.
  844. *
  845. * @param {EllipseGeometry} value The value to pack.
  846. * @param {Number[]} array The array to pack into.
  847. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  848. *
  849. * @returns {Number[]} The array that was packed into
  850. */
  851. EllipseGeometry.pack = function (value, array, startingIndex) {
  852. //>>includeStart('debug', pragmas.debug);
  853. RuntimeError.Check.defined("value", value);
  854. RuntimeError.Check.defined("array", array);
  855. //>>includeEnd('debug');
  856. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  857. Matrix2.Cartesian3.pack(value._center, array, startingIndex);
  858. startingIndex += Matrix2.Cartesian3.packedLength;
  859. Matrix2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  860. startingIndex += Matrix2.Ellipsoid.packedLength;
  861. VertexFormat.VertexFormat.pack(value._vertexFormat, array, startingIndex);
  862. startingIndex += VertexFormat.VertexFormat.packedLength;
  863. array[startingIndex++] = value._semiMajorAxis;
  864. array[startingIndex++] = value._semiMinorAxis;
  865. array[startingIndex++] = value._rotation;
  866. array[startingIndex++] = value._stRotation;
  867. array[startingIndex++] = value._height;
  868. array[startingIndex++] = value._granularity;
  869. array[startingIndex++] = value._extrudedHeight;
  870. array[startingIndex++] = value._shadowVolume ? 1.0 : 0.0;
  871. array[startingIndex] = defaultValue.defaultValue(value._offsetAttribute, -1);
  872. return array;
  873. };
  874. const scratchCenter = new Matrix2.Cartesian3();
  875. const scratchEllipsoid = new Matrix2.Ellipsoid();
  876. const scratchVertexFormat = new VertexFormat.VertexFormat();
  877. const scratchOptions = {
  878. center: scratchCenter,
  879. ellipsoid: scratchEllipsoid,
  880. vertexFormat: scratchVertexFormat,
  881. semiMajorAxis: undefined,
  882. semiMinorAxis: undefined,
  883. rotation: undefined,
  884. stRotation: undefined,
  885. height: undefined,
  886. granularity: undefined,
  887. extrudedHeight: undefined,
  888. shadowVolume: undefined,
  889. offsetAttribute: undefined,
  890. };
  891. /**
  892. * Retrieves an instance from a packed array.
  893. *
  894. * @param {Number[]} array The packed array.
  895. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  896. * @param {EllipseGeometry} [result] The object into which to store the result.
  897. * @returns {EllipseGeometry} The modified result parameter or a new EllipseGeometry instance if one was not provided.
  898. */
  899. EllipseGeometry.unpack = function (array, startingIndex, result) {
  900. //>>includeStart('debug', pragmas.debug);
  901. RuntimeError.Check.defined("array", array);
  902. //>>includeEnd('debug');
  903. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  904. const center = Matrix2.Cartesian3.unpack(array, startingIndex, scratchCenter);
  905. startingIndex += Matrix2.Cartesian3.packedLength;
  906. const ellipsoid = Matrix2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  907. startingIndex += Matrix2.Ellipsoid.packedLength;
  908. const vertexFormat = VertexFormat.VertexFormat.unpack(
  909. array,
  910. startingIndex,
  911. scratchVertexFormat
  912. );
  913. startingIndex += VertexFormat.VertexFormat.packedLength;
  914. const semiMajorAxis = array[startingIndex++];
  915. const semiMinorAxis = array[startingIndex++];
  916. const rotation = array[startingIndex++];
  917. const stRotation = array[startingIndex++];
  918. const height = array[startingIndex++];
  919. const granularity = array[startingIndex++];
  920. const extrudedHeight = array[startingIndex++];
  921. const shadowVolume = array[startingIndex++] === 1.0;
  922. const offsetAttribute = array[startingIndex];
  923. if (!defaultValue.defined(result)) {
  924. scratchOptions.height = height;
  925. scratchOptions.extrudedHeight = extrudedHeight;
  926. scratchOptions.granularity = granularity;
  927. scratchOptions.stRotation = stRotation;
  928. scratchOptions.rotation = rotation;
  929. scratchOptions.semiMajorAxis = semiMajorAxis;
  930. scratchOptions.semiMinorAxis = semiMinorAxis;
  931. scratchOptions.shadowVolume = shadowVolume;
  932. scratchOptions.offsetAttribute =
  933. offsetAttribute === -1 ? undefined : offsetAttribute;
  934. return new EllipseGeometry(scratchOptions);
  935. }
  936. result._center = Matrix2.Cartesian3.clone(center, result._center);
  937. result._ellipsoid = Matrix2.Ellipsoid.clone(ellipsoid, result._ellipsoid);
  938. result._vertexFormat = VertexFormat.VertexFormat.clone(vertexFormat, result._vertexFormat);
  939. result._semiMajorAxis = semiMajorAxis;
  940. result._semiMinorAxis = semiMinorAxis;
  941. result._rotation = rotation;
  942. result._stRotation = stRotation;
  943. result._height = height;
  944. result._granularity = granularity;
  945. result._extrudedHeight = extrudedHeight;
  946. result._shadowVolume = shadowVolume;
  947. result._offsetAttribute =
  948. offsetAttribute === -1 ? undefined : offsetAttribute;
  949. return result;
  950. };
  951. /**
  952. * Computes the bounding rectangle based on the provided options
  953. *
  954. * @param {Object} options Object with the following properties:
  955. * @param {Cartesian3} options.center The ellipse's center point in the fixed frame.
  956. * @param {Number} options.semiMajorAxis The length of the ellipse's semi-major axis in meters.
  957. * @param {Number} options.semiMinorAxis The length of the ellipse's semi-minor axis in meters.
  958. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid the ellipse will be on.
  959. * @param {Number} [options.rotation=0.0] The angle of rotation counter-clockwise from north.
  960. * @param {Number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The angular distance between points on the ellipse in radians.
  961. * @param {Rectangle} [result] An object in which to store the result
  962. *
  963. * @returns {Rectangle} The result rectangle
  964. */
  965. EllipseGeometry.computeRectangle = function (options, result) {
  966. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  967. const center = options.center;
  968. const ellipsoid = defaultValue.defaultValue(options.ellipsoid, Matrix2.Ellipsoid.WGS84);
  969. const semiMajorAxis = options.semiMajorAxis;
  970. const semiMinorAxis = options.semiMinorAxis;
  971. const granularity = defaultValue.defaultValue(
  972. options.granularity,
  973. ComponentDatatype.CesiumMath.RADIANS_PER_DEGREE
  974. );
  975. const rotation = defaultValue.defaultValue(options.rotation, 0.0);
  976. //>>includeStart('debug', pragmas.debug);
  977. RuntimeError.Check.defined("options.center", center);
  978. RuntimeError.Check.typeOf.number("options.semiMajorAxis", semiMajorAxis);
  979. RuntimeError.Check.typeOf.number("options.semiMinorAxis", semiMinorAxis);
  980. if (semiMajorAxis < semiMinorAxis) {
  981. throw new RuntimeError.DeveloperError(
  982. "semiMajorAxis must be greater than or equal to the semiMinorAxis."
  983. );
  984. }
  985. if (granularity <= 0.0) {
  986. throw new RuntimeError.DeveloperError("granularity must be greater than zero.");
  987. }
  988. //>>includeEnd('debug');
  989. return computeRectangle(
  990. center,
  991. semiMajorAxis,
  992. semiMinorAxis,
  993. rotation,
  994. granularity,
  995. ellipsoid,
  996. result
  997. );
  998. };
  999. /**
  1000. * Computes the geometric representation of a ellipse on an ellipsoid, including its vertices, indices, and a bounding sphere.
  1001. *
  1002. * @param {EllipseGeometry} ellipseGeometry A description of the ellipse.
  1003. * @returns {Geometry|undefined} The computed vertices and indices.
  1004. */
  1005. EllipseGeometry.createGeometry = function (ellipseGeometry) {
  1006. if (
  1007. ellipseGeometry._semiMajorAxis <= 0.0 ||
  1008. ellipseGeometry._semiMinorAxis <= 0.0
  1009. ) {
  1010. return;
  1011. }
  1012. const height = ellipseGeometry._height;
  1013. const extrudedHeight = ellipseGeometry._extrudedHeight;
  1014. const extrude = !ComponentDatatype.CesiumMath.equalsEpsilon(
  1015. height,
  1016. extrudedHeight,
  1017. 0,
  1018. ComponentDatatype.CesiumMath.EPSILON2
  1019. );
  1020. ellipseGeometry._center = ellipseGeometry._ellipsoid.scaleToGeodeticSurface(
  1021. ellipseGeometry._center,
  1022. ellipseGeometry._center
  1023. );
  1024. const options = {
  1025. center: ellipseGeometry._center,
  1026. semiMajorAxis: ellipseGeometry._semiMajorAxis,
  1027. semiMinorAxis: ellipseGeometry._semiMinorAxis,
  1028. ellipsoid: ellipseGeometry._ellipsoid,
  1029. rotation: ellipseGeometry._rotation,
  1030. height: height,
  1031. granularity: ellipseGeometry._granularity,
  1032. vertexFormat: ellipseGeometry._vertexFormat,
  1033. stRotation: ellipseGeometry._stRotation,
  1034. };
  1035. let geometry;
  1036. if (extrude) {
  1037. options.extrudedHeight = extrudedHeight;
  1038. options.shadowVolume = ellipseGeometry._shadowVolume;
  1039. options.offsetAttribute = ellipseGeometry._offsetAttribute;
  1040. geometry = computeExtrudedEllipse(options);
  1041. } else {
  1042. geometry = computeEllipse(options);
  1043. if (defaultValue.defined(ellipseGeometry._offsetAttribute)) {
  1044. const length = geometry.attributes.position.values.length;
  1045. const applyOffset = new Uint8Array(length / 3);
  1046. const offsetValue =
  1047. ellipseGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE
  1048. ? 0
  1049. : 1;
  1050. GeometryOffsetAttribute.arrayFill(applyOffset, offsetValue);
  1051. geometry.attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  1052. componentDatatype: ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  1053. componentsPerAttribute: 1,
  1054. values: applyOffset,
  1055. });
  1056. }
  1057. }
  1058. return new GeometryAttribute.Geometry({
  1059. attributes: geometry.attributes,
  1060. indices: geometry.indices,
  1061. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  1062. boundingSphere: geometry.boundingSphere,
  1063. offsetAttribute: ellipseGeometry._offsetAttribute,
  1064. });
  1065. };
  1066. /**
  1067. * @private
  1068. */
  1069. EllipseGeometry.createShadowVolume = function (
  1070. ellipseGeometry,
  1071. minHeightFunc,
  1072. maxHeightFunc
  1073. ) {
  1074. const granularity = ellipseGeometry._granularity;
  1075. const ellipsoid = ellipseGeometry._ellipsoid;
  1076. const minHeight = minHeightFunc(granularity, ellipsoid);
  1077. const maxHeight = maxHeightFunc(granularity, ellipsoid);
  1078. return new EllipseGeometry({
  1079. center: ellipseGeometry._center,
  1080. semiMajorAxis: ellipseGeometry._semiMajorAxis,
  1081. semiMinorAxis: ellipseGeometry._semiMinorAxis,
  1082. ellipsoid: ellipsoid,
  1083. rotation: ellipseGeometry._rotation,
  1084. stRotation: ellipseGeometry._stRotation,
  1085. granularity: granularity,
  1086. extrudedHeight: minHeight,
  1087. height: maxHeight,
  1088. vertexFormat: VertexFormat.VertexFormat.POSITION_ONLY,
  1089. shadowVolume: true,
  1090. });
  1091. };
  1092. function textureCoordinateRotationPoints(ellipseGeometry) {
  1093. const stRotation = -ellipseGeometry._stRotation;
  1094. if (stRotation === 0.0) {
  1095. return [0, 0, 0, 1, 1, 0];
  1096. }
  1097. const cep = EllipseGeometryLibrary.EllipseGeometryLibrary.computeEllipsePositions(
  1098. {
  1099. center: ellipseGeometry._center,
  1100. semiMajorAxis: ellipseGeometry._semiMajorAxis,
  1101. semiMinorAxis: ellipseGeometry._semiMinorAxis,
  1102. rotation: ellipseGeometry._rotation,
  1103. granularity: ellipseGeometry._granularity,
  1104. },
  1105. false,
  1106. true
  1107. );
  1108. const positionsFlat = cep.outerPositions;
  1109. const positionsCount = positionsFlat.length / 3;
  1110. const positions = new Array(positionsCount);
  1111. for (let i = 0; i < positionsCount; ++i) {
  1112. positions[i] = Matrix2.Cartesian3.fromArray(positionsFlat, i * 3);
  1113. }
  1114. const ellipsoid = ellipseGeometry._ellipsoid;
  1115. const boundingRectangle = ellipseGeometry.rectangle;
  1116. return GeometryAttribute.Geometry._textureCoordinateRotationPoints(
  1117. positions,
  1118. stRotation,
  1119. ellipsoid,
  1120. boundingRectangle
  1121. );
  1122. }
  1123. Object.defineProperties(EllipseGeometry.prototype, {
  1124. /**
  1125. * @private
  1126. */
  1127. rectangle: {
  1128. get: function () {
  1129. if (!defaultValue.defined(this._rectangle)) {
  1130. this._rectangle = computeRectangle(
  1131. this._center,
  1132. this._semiMajorAxis,
  1133. this._semiMinorAxis,
  1134. this._rotation,
  1135. this._granularity,
  1136. this._ellipsoid
  1137. );
  1138. }
  1139. return this._rectangle;
  1140. },
  1141. },
  1142. /**
  1143. * For remapping texture coordinates when rendering EllipseGeometries as GroundPrimitives.
  1144. * @private
  1145. */
  1146. textureCoordinateRotationPoints: {
  1147. get: function () {
  1148. if (!defaultValue.defined(this._textureCoordinateRotationPoints)) {
  1149. this._textureCoordinateRotationPoints = textureCoordinateRotationPoints(
  1150. this
  1151. );
  1152. }
  1153. return this._textureCoordinateRotationPoints;
  1154. },
  1155. },
  1156. });
  1157. exports.EllipseGeometry = EllipseGeometry;
  1158. }));