EllipseGeometry-f8925bca.js 47 KB

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