EllipseGeometry-37014da4.js 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. define(['exports', './Transforms-bc45e707', './Matrix2-e1298525', './Matrix3-41c58dde', './Check-6ede7e26', './ComponentDatatype-cf1fa08e', './defaultValue-fe22d8c0', './EllipseGeometryLibrary-92ab6b1e', './GeometryAttribute-a466e9c7', './GeometryAttributes-ad136444', './GeometryInstance-34d9e21e', './GeometryOffsetAttribute-9ad0019c', './GeometryPipeline-dcf79306', './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. }));