EllipseGeometry-421cd94d.js 53 KB

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