影像解译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EllipseGeometry-6508b78b.js 45KB

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