EllipseGeometry.js 46 KB

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