EllipseGeometry-f50f832c.js 52 KB

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