createCircleGeometry.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./defined-26bd4a03', './Check-da037458', './freezeObject-2d83f591', './defaultValue-f2e68450', './Math-fa6e45cb', './Cartesian2-2a723276', './defineProperties-6f7a50f2', './Transforms-65aba0a4', './RuntimeError-ad75c885', './WebGLConstants-497deb20', './ComponentDatatype-69643096', './GeometryAttribute-ed359d71', './when-ee12a2cb', './GeometryAttributes-eecc9f43', './AttributeCompression-87682214', './GeometryPipeline-f0b16df6', './EncodedCartesian3-8b2b90d0', './IndexDatatype-3de60176', './IntersectionTests-c2360ffa', './Plane-a1a3fd52', './GeometryOffsetAttribute-cb30cd97', './VertexFormat-fbb91dc7', './EllipseGeometryLibrary-ff991705', './GeometryInstance-72fd4e35', './EllipseGeometry-f50f832c'], function (defined, Check, freezeObject, defaultValue, _Math, Cartesian2, defineProperties, Transforms, RuntimeError, WebGLConstants, ComponentDatatype, GeometryAttribute, when, GeometryAttributes, AttributeCompression, GeometryPipeline, EncodedCartesian3, IndexDatatype, IntersectionTests, Plane, GeometryOffsetAttribute, VertexFormat, EllipseGeometryLibrary, GeometryInstance, EllipseGeometry) { '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. * var circle = new Cesium.CircleGeometry({
  28. * center : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
  29. * radius : 100000.0
  30. * });
  31. * var geometry = Cesium.CircleGeometry.createGeometry(circle);
  32. */
  33. function CircleGeometry(options) {
  34. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  35. var radius = options.radius;
  36. //>>includeStart('debug', pragmas.debug);
  37. Check.Check.typeOf.number('radius', radius);
  38. //>>includeEnd('debug');
  39. var 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. Check.Check.typeOf.object('value', value);
  71. //>>includeEnd('debug');
  72. return EllipseGeometry.EllipseGeometry.pack(value._ellipseGeometry, array, startingIndex);
  73. };
  74. var scratchEllipseGeometry = new EllipseGeometry.EllipseGeometry({
  75. center : new Cartesian2.Cartesian3(),
  76. semiMajorAxis : 1.0,
  77. semiMinorAxis : 1.0
  78. });
  79. var scratchOptions = {
  80. center : new Cartesian2.Cartesian3(),
  81. radius : undefined,
  82. ellipsoid : Cartesian2.Ellipsoid.clone(Cartesian2.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. var ellipseGeometry = EllipseGeometry.EllipseGeometry.unpack(array, startingIndex, scratchEllipseGeometry);
  102. scratchOptions.center = Cartesian2.Cartesian3.clone(ellipseGeometry._center, scratchOptions.center);
  103. scratchOptions.ellipsoid = Cartesian2.Ellipsoid.clone(ellipseGeometry._ellipsoid, scratchOptions.ellipsoid);
  104. scratchOptions.height = ellipseGeometry._height;
  105. scratchOptions.extrudedHeight = ellipseGeometry._extrudedHeight;
  106. scratchOptions.granularity = ellipseGeometry._granularity;
  107. scratchOptions.vertexFormat = VertexFormat.VertexFormat.clone(ellipseGeometry._vertexFormat, scratchOptions.vertexFormat);
  108. scratchOptions.stRotation = ellipseGeometry._stRotation;
  109. scratchOptions.shadowVolume = ellipseGeometry._shadowVolume;
  110. if (!defined.defined(result)) {
  111. scratchOptions.radius = ellipseGeometry._semiMajorAxis;
  112. return new CircleGeometry(scratchOptions);
  113. }
  114. scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis;
  115. scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis;
  116. result._ellipseGeometry = new EllipseGeometry.EllipseGeometry(scratchOptions);
  117. return result;
  118. };
  119. /**
  120. * Computes the geometric representation of a circle on an ellipsoid, including its vertices, indices, and a bounding sphere.
  121. *
  122. * @param {CircleGeometry} circleGeometry A description of the circle.
  123. * @returns {Geometry|undefined} The computed vertices and indices.
  124. */
  125. CircleGeometry.createGeometry = function(circleGeometry) {
  126. return EllipseGeometry.EllipseGeometry.createGeometry(circleGeometry._ellipseGeometry);
  127. };
  128. /**
  129. * @private
  130. */
  131. CircleGeometry.createShadowVolume = function(circleGeometry, minHeightFunc, maxHeightFunc) {
  132. var granularity = circleGeometry._ellipseGeometry._granularity;
  133. var ellipsoid = circleGeometry._ellipseGeometry._ellipsoid;
  134. var minHeight = minHeightFunc(granularity, ellipsoid);
  135. var maxHeight = maxHeightFunc(granularity, ellipsoid);
  136. return new CircleGeometry({
  137. center : circleGeometry._ellipseGeometry._center,
  138. radius : circleGeometry._ellipseGeometry._semiMajorAxis,
  139. ellipsoid : ellipsoid,
  140. stRotation : circleGeometry._ellipseGeometry._stRotation,
  141. granularity : granularity,
  142. extrudedHeight : minHeight,
  143. height : maxHeight,
  144. vertexFormat : VertexFormat.VertexFormat.POSITION_ONLY,
  145. shadowVolume: true
  146. });
  147. };
  148. defineProperties.defineProperties(CircleGeometry.prototype, {
  149. /**
  150. * @private
  151. */
  152. rectangle : {
  153. get : function() {
  154. return this._ellipseGeometry.rectangle;
  155. }
  156. },
  157. /**
  158. * For remapping texture coordinates when rendering CircleGeometries as GroundPrimitives.
  159. * @private
  160. */
  161. textureCoordinateRotationPoints : {
  162. get : function() {
  163. return this._ellipseGeometry.textureCoordinateRotationPoints;
  164. }
  165. }
  166. });
  167. function createCircleGeometry(circleGeometry, offset) {
  168. if (defined.defined(offset)) {
  169. circleGeometry = CircleGeometry.unpack(circleGeometry, offset);
  170. }
  171. circleGeometry._ellipseGeometry._center = Cartesian2.Cartesian3.clone(circleGeometry._ellipseGeometry._center);
  172. circleGeometry._ellipseGeometry._ellipsoid = Cartesian2.Ellipsoid.clone(circleGeometry._ellipseGeometry._ellipsoid);
  173. return CircleGeometry.createGeometry(circleGeometry);
  174. }
  175. return createCircleGeometry;
  176. });