EllipseGeometry-0698d637.js 46 KB

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