EllipseGeometry-83f433c5.js 46 KB

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