createCircleGeometry.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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/main/LICENSE.md for full licensing details.
  22. */
  23. define(['./Matrix2-d35cf4b5', './RuntimeError-8952249c', './defaultValue-81eec7ed', './EllipseGeometry-f8925bca', './VertexFormat-7df34ea5', './ComponentDatatype-9e86ac8f', './WebGLConstants-508b9636', './GeometryOffsetAttribute-2bff0974', './Transforms-f0a54c7b', './_commonjsHelpers-3aae1032-26891ab7', './combine-3c023bda', './EllipseGeometryLibrary-de9b1bfe', './GeometryAttribute-eeb38987', './GeometryAttributes-32b29525', './GeometryInstance-d60d0ef4', './GeometryPipeline-55e02a41', './AttributeCompression-d0b97a83', './EncodedCartesian3-530d5328', './IndexDatatype-bed3935d', './IntersectionTests-a25e058d', './Plane-24f22488'], (function (Matrix2, RuntimeError, defaultValue, EllipseGeometry, VertexFormat, ComponentDatatype, WebGLConstants, GeometryOffsetAttribute, Transforms, _commonjsHelpers3aae1032, combine, EllipseGeometryLibrary, GeometryAttribute, GeometryAttributes, GeometryInstance, GeometryPipeline, AttributeCompression, EncodedCartesian3, IndexDatatype, IntersectionTests, Plane) { 'use strict';
  24. /**
  25. * A description of a circle on the ellipsoid. Circle geometry can be rendered with both {@link Primitive} and {@link GroundPrimitive}.
  26. *
  27. * @alias CircleGeometry
  28. * @constructor
  29. *
  30. * @param {Object} options Object with the following properties:
  31. * @param {Cartesian3} options.center The circle's center point in the fixed frame.
  32. * @param {Number} options.radius The radius in meters.
  33. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid the circle will be on.
  34. * @param {Number} [options.height=0.0] The distance in meters between the circle and the ellipsoid surface.
  35. * @param {Number} [options.granularity=0.02] The angular distance between points on the circle in radians.
  36. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  37. * @param {Number} [options.extrudedHeight=0.0] The distance in meters between the circle's extruded face and the ellipsoid surface.
  38. * @param {Number} [options.stRotation=0.0] The rotation of the texture coordinates, in radians. A positive rotation is counter-clockwise.
  39. *
  40. * @exception {DeveloperError} radius must be greater than zero.
  41. * @exception {DeveloperError} granularity must be greater than zero.
  42. *
  43. * @see CircleGeometry.createGeometry
  44. * @see Packable
  45. *
  46. * @example
  47. * // Create a circle.
  48. * const circle = new Cesium.CircleGeometry({
  49. * center : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
  50. * radius : 100000.0
  51. * });
  52. * const geometry = Cesium.CircleGeometry.createGeometry(circle);
  53. */
  54. function CircleGeometry(options) {
  55. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  56. const radius = options.radius;
  57. //>>includeStart('debug', pragmas.debug);
  58. RuntimeError.Check.typeOf.number("radius", radius);
  59. //>>includeEnd('debug');
  60. const ellipseGeometryOptions = {
  61. center: options.center,
  62. semiMajorAxis: radius,
  63. semiMinorAxis: radius,
  64. ellipsoid: options.ellipsoid,
  65. height: options.height,
  66. extrudedHeight: options.extrudedHeight,
  67. granularity: options.granularity,
  68. vertexFormat: options.vertexFormat,
  69. stRotation: options.stRotation,
  70. shadowVolume: options.shadowVolume,
  71. };
  72. this._ellipseGeometry = new EllipseGeometry.EllipseGeometry(ellipseGeometryOptions);
  73. this._workerName = "createCircleGeometry";
  74. }
  75. /**
  76. * The number of elements used to pack the object into an array.
  77. * @type {Number}
  78. */
  79. CircleGeometry.packedLength = EllipseGeometry.EllipseGeometry.packedLength;
  80. /**
  81. * Stores the provided instance into the provided array.
  82. *
  83. * @param {CircleGeometry} value The value to pack.
  84. * @param {Number[]} array The array to pack into.
  85. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  86. *
  87. * @returns {Number[]} The array that was packed into
  88. */
  89. CircleGeometry.pack = function (value, array, startingIndex) {
  90. //>>includeStart('debug', pragmas.debug);
  91. RuntimeError.Check.typeOf.object("value", value);
  92. //>>includeEnd('debug');
  93. return EllipseGeometry.EllipseGeometry.pack(value._ellipseGeometry, array, startingIndex);
  94. };
  95. const scratchEllipseGeometry = new EllipseGeometry.EllipseGeometry({
  96. center: new Matrix2.Cartesian3(),
  97. semiMajorAxis: 1.0,
  98. semiMinorAxis: 1.0,
  99. });
  100. const scratchOptions = {
  101. center: new Matrix2.Cartesian3(),
  102. radius: undefined,
  103. ellipsoid: Matrix2.Ellipsoid.clone(Matrix2.Ellipsoid.UNIT_SPHERE),
  104. height: undefined,
  105. extrudedHeight: undefined,
  106. granularity: undefined,
  107. vertexFormat: new VertexFormat.VertexFormat(),
  108. stRotation: undefined,
  109. semiMajorAxis: undefined,
  110. semiMinorAxis: undefined,
  111. shadowVolume: undefined,
  112. };
  113. /**
  114. * Retrieves an instance from a packed array.
  115. *
  116. * @param {Number[]} array The packed array.
  117. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  118. * @param {CircleGeometry} [result] The object into which to store the result.
  119. * @returns {CircleGeometry} The modified result parameter or a new CircleGeometry instance if one was not provided.
  120. */
  121. CircleGeometry.unpack = function (array, startingIndex, result) {
  122. const ellipseGeometry = EllipseGeometry.EllipseGeometry.unpack(
  123. array,
  124. startingIndex,
  125. scratchEllipseGeometry
  126. );
  127. scratchOptions.center = Matrix2.Cartesian3.clone(
  128. ellipseGeometry._center,
  129. scratchOptions.center
  130. );
  131. scratchOptions.ellipsoid = Matrix2.Ellipsoid.clone(
  132. ellipseGeometry._ellipsoid,
  133. scratchOptions.ellipsoid
  134. );
  135. scratchOptions.height = ellipseGeometry._height;
  136. scratchOptions.extrudedHeight = ellipseGeometry._extrudedHeight;
  137. scratchOptions.granularity = ellipseGeometry._granularity;
  138. scratchOptions.vertexFormat = VertexFormat.VertexFormat.clone(
  139. ellipseGeometry._vertexFormat,
  140. scratchOptions.vertexFormat
  141. );
  142. scratchOptions.stRotation = ellipseGeometry._stRotation;
  143. scratchOptions.shadowVolume = ellipseGeometry._shadowVolume;
  144. if (!defaultValue.defined(result)) {
  145. scratchOptions.radius = ellipseGeometry._semiMajorAxis;
  146. return new CircleGeometry(scratchOptions);
  147. }
  148. scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis;
  149. scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis;
  150. result._ellipseGeometry = new EllipseGeometry.EllipseGeometry(scratchOptions);
  151. return result;
  152. };
  153. /**
  154. * Computes the geometric representation of a circle on an ellipsoid, including its vertices, indices, and a bounding sphere.
  155. *
  156. * @param {CircleGeometry} circleGeometry A description of the circle.
  157. * @returns {Geometry|undefined} The computed vertices and indices.
  158. */
  159. CircleGeometry.createGeometry = function (circleGeometry) {
  160. return EllipseGeometry.EllipseGeometry.createGeometry(circleGeometry._ellipseGeometry);
  161. };
  162. /**
  163. * @private
  164. */
  165. CircleGeometry.createShadowVolume = function (
  166. circleGeometry,
  167. minHeightFunc,
  168. maxHeightFunc
  169. ) {
  170. const granularity = circleGeometry._ellipseGeometry._granularity;
  171. const ellipsoid = circleGeometry._ellipseGeometry._ellipsoid;
  172. const minHeight = minHeightFunc(granularity, ellipsoid);
  173. const maxHeight = maxHeightFunc(granularity, ellipsoid);
  174. return new CircleGeometry({
  175. center: circleGeometry._ellipseGeometry._center,
  176. radius: circleGeometry._ellipseGeometry._semiMajorAxis,
  177. ellipsoid: ellipsoid,
  178. stRotation: circleGeometry._ellipseGeometry._stRotation,
  179. granularity: granularity,
  180. extrudedHeight: minHeight,
  181. height: maxHeight,
  182. vertexFormat: VertexFormat.VertexFormat.POSITION_ONLY,
  183. shadowVolume: true,
  184. });
  185. };
  186. Object.defineProperties(CircleGeometry.prototype, {
  187. /**
  188. * @private
  189. */
  190. rectangle: {
  191. get: function () {
  192. return this._ellipseGeometry.rectangle;
  193. },
  194. },
  195. /**
  196. * For remapping texture coordinates when rendering CircleGeometries as GroundPrimitives.
  197. * @private
  198. */
  199. textureCoordinateRotationPoints: {
  200. get: function () {
  201. return this._ellipseGeometry.textureCoordinateRotationPoints;
  202. },
  203. },
  204. });
  205. function createCircleGeometry(circleGeometry, offset) {
  206. if (defaultValue.defined(offset)) {
  207. circleGeometry = CircleGeometry.unpack(circleGeometry, offset);
  208. }
  209. circleGeometry._ellipseGeometry._center = Matrix2.Cartesian3.clone(
  210. circleGeometry._ellipseGeometry._center
  211. );
  212. circleGeometry._ellipseGeometry._ellipsoid = Matrix2.Ellipsoid.clone(
  213. circleGeometry._ellipseGeometry._ellipsoid
  214. );
  215. return CircleGeometry.createGeometry(circleGeometry);
  216. }
  217. return createCircleGeometry;
  218. }));
  219. //# sourceMappingURL=createCircleGeometry.js.map