CircleGeometry.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import Cartesian3 from './Cartesian3.js';
  2. import Check from './Check.js';
  3. import defaultValue from './defaultValue.js';
  4. import defined from './defined.js';
  5. import defineProperties from './defineProperties.js';
  6. import EllipseGeometry from './EllipseGeometry.js';
  7. import Ellipsoid from './Ellipsoid.js';
  8. import VertexFormat from './VertexFormat.js';
  9. /**
  10. * A description of a circle on the ellipsoid. Circle geometry can be rendered with both {@link Primitive} and {@link GroundPrimitive}.
  11. *
  12. * @alias CircleGeometry
  13. * @constructor
  14. *
  15. * @param {Object} options Object with the following properties:
  16. * @param {Cartesian3} options.center The circle's center point in the fixed frame.
  17. * @param {Number} options.radius The radius in meters.
  18. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid the circle will be on.
  19. * @param {Number} [options.height=0.0] The distance in meters between the circle and the ellipsoid surface.
  20. * @param {Number} [options.granularity=0.02] The angular distance between points on the circle in radians.
  21. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  22. * @param {Number} [options.extrudedHeight=0.0] The distance in meters between the circle's extruded face and the ellipsoid surface.
  23. * @param {Number} [options.stRotation=0.0] The rotation of the texture coordinates, in radians. A positive rotation is counter-clockwise.
  24. *
  25. * @exception {DeveloperError} radius must be greater than zero.
  26. * @exception {DeveloperError} granularity must be greater than zero.
  27. *
  28. * @see CircleGeometry.createGeometry
  29. * @see Packable
  30. *
  31. * @example
  32. * // Create a circle.
  33. * var circle = new Cesium.CircleGeometry({
  34. * center : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
  35. * radius : 100000.0
  36. * });
  37. * var geometry = Cesium.CircleGeometry.createGeometry(circle);
  38. */
  39. function CircleGeometry(options) {
  40. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  41. var radius = options.radius;
  42. //>>includeStart('debug', pragmas.debug);
  43. Check.typeOf.number('radius', radius);
  44. //>>includeEnd('debug');
  45. var ellipseGeometryOptions = {
  46. center : options.center,
  47. semiMajorAxis : radius,
  48. semiMinorAxis : radius,
  49. ellipsoid : options.ellipsoid,
  50. height : options.height,
  51. extrudedHeight : options.extrudedHeight,
  52. granularity : options.granularity,
  53. vertexFormat : options.vertexFormat,
  54. stRotation : options.stRotation,
  55. shadowVolume: options.shadowVolume
  56. };
  57. this._ellipseGeometry = new EllipseGeometry(ellipseGeometryOptions);
  58. this._workerName = 'createCircleGeometry';
  59. }
  60. /**
  61. * The number of elements used to pack the object into an array.
  62. * @type {Number}
  63. */
  64. CircleGeometry.packedLength = EllipseGeometry.packedLength;
  65. /**
  66. * Stores the provided instance into the provided array.
  67. *
  68. * @param {CircleGeometry} value The value to pack.
  69. * @param {Number[]} array The array to pack into.
  70. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  71. *
  72. * @returns {Number[]} The array that was packed into
  73. */
  74. CircleGeometry.pack = function(value, array, startingIndex) {
  75. //>>includeStart('debug', pragmas.debug);
  76. Check.typeOf.object('value', value);
  77. //>>includeEnd('debug');
  78. return EllipseGeometry.pack(value._ellipseGeometry, array, startingIndex);
  79. };
  80. var scratchEllipseGeometry = new EllipseGeometry({
  81. center : new Cartesian3(),
  82. semiMajorAxis : 1.0,
  83. semiMinorAxis : 1.0
  84. });
  85. var scratchOptions = {
  86. center : new Cartesian3(),
  87. radius : undefined,
  88. ellipsoid : Ellipsoid.clone(Ellipsoid.UNIT_SPHERE),
  89. height : undefined,
  90. extrudedHeight : undefined,
  91. granularity : undefined,
  92. vertexFormat : new VertexFormat(),
  93. stRotation : undefined,
  94. semiMajorAxis : undefined,
  95. semiMinorAxis : undefined,
  96. shadowVolume: undefined
  97. };
  98. /**
  99. * Retrieves an instance from a packed array.
  100. *
  101. * @param {Number[]} array The packed array.
  102. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  103. * @param {CircleGeometry} [result] The object into which to store the result.
  104. * @returns {CircleGeometry} The modified result parameter or a new CircleGeometry instance if one was not provided.
  105. */
  106. CircleGeometry.unpack = function(array, startingIndex, result) {
  107. var ellipseGeometry = EllipseGeometry.unpack(array, startingIndex, scratchEllipseGeometry);
  108. scratchOptions.center = Cartesian3.clone(ellipseGeometry._center, scratchOptions.center);
  109. scratchOptions.ellipsoid = Ellipsoid.clone(ellipseGeometry._ellipsoid, scratchOptions.ellipsoid);
  110. scratchOptions.height = ellipseGeometry._height;
  111. scratchOptions.extrudedHeight = ellipseGeometry._extrudedHeight;
  112. scratchOptions.granularity = ellipseGeometry._granularity;
  113. scratchOptions.vertexFormat = VertexFormat.clone(ellipseGeometry._vertexFormat, scratchOptions.vertexFormat);
  114. scratchOptions.stRotation = ellipseGeometry._stRotation;
  115. scratchOptions.shadowVolume = ellipseGeometry._shadowVolume;
  116. if (!defined(result)) {
  117. scratchOptions.radius = ellipseGeometry._semiMajorAxis;
  118. return new CircleGeometry(scratchOptions);
  119. }
  120. scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis;
  121. scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis;
  122. result._ellipseGeometry = new EllipseGeometry(scratchOptions);
  123. return result;
  124. };
  125. /**
  126. * Computes the geometric representation of a circle on an ellipsoid, including its vertices, indices, and a bounding sphere.
  127. *
  128. * @param {CircleGeometry} circleGeometry A description of the circle.
  129. * @returns {Geometry|undefined} The computed vertices and indices.
  130. */
  131. CircleGeometry.createGeometry = function(circleGeometry) {
  132. return EllipseGeometry.createGeometry(circleGeometry._ellipseGeometry);
  133. };
  134. /**
  135. * @private
  136. */
  137. CircleGeometry.createShadowVolume = function(circleGeometry, minHeightFunc, maxHeightFunc) {
  138. var granularity = circleGeometry._ellipseGeometry._granularity;
  139. var ellipsoid = circleGeometry._ellipseGeometry._ellipsoid;
  140. var minHeight = minHeightFunc(granularity, ellipsoid);
  141. var maxHeight = maxHeightFunc(granularity, ellipsoid);
  142. return new CircleGeometry({
  143. center : circleGeometry._ellipseGeometry._center,
  144. radius : circleGeometry._ellipseGeometry._semiMajorAxis,
  145. ellipsoid : ellipsoid,
  146. stRotation : circleGeometry._ellipseGeometry._stRotation,
  147. granularity : granularity,
  148. extrudedHeight : minHeight,
  149. height : maxHeight,
  150. vertexFormat : VertexFormat.POSITION_ONLY,
  151. shadowVolume: true
  152. });
  153. };
  154. defineProperties(CircleGeometry.prototype, {
  155. /**
  156. * @private
  157. */
  158. rectangle : {
  159. get : function() {
  160. return this._ellipseGeometry.rectangle;
  161. }
  162. },
  163. /**
  164. * For remapping texture coordinates when rendering CircleGeometries as GroundPrimitives.
  165. * @private
  166. */
  167. textureCoordinateRotationPoints : {
  168. get : function() {
  169. return this._ellipseGeometry.textureCoordinateRotationPoints;
  170. }
  171. }
  172. });
  173. export default CircleGeometry;