createCircleGeometry.js 8.7 KB

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