createCircleGeometry.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. * @license
  3. * Cesium - https://github.com/CesiumGS/cesium
  4. * Version 1.97
  5. *
  6. * Copyright 2011-2022 Cesium Contributors
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * Columbus View (Pat. Pend.)
  21. *
  22. * Portions licensed separately.
  23. * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
  24. */
  25. define(['./Matrix2-ab676047', './RuntimeError-1088cc64', './defaultValue-a6eb9f34', './EllipseGeometry-b03cdf06', './VertexFormat-65fd4be5', './ComponentDatatype-e06f4e16', './WebGLConstants-d81b330d', './Transforms-c78c4637', './_commonjsHelpers-89c9b271', './combine-7cf28d88', './EllipseGeometryLibrary-b13c13df', './GeometryAttribute-4f02e2ad', './GeometryAttributes-aff51037', './GeometryInstance-6f541616', './GeometryOffsetAttribute-102da468', './GeometryPipeline-5a61c463', './AttributeCompression-8033f934', './EncodedCartesian3-7959a913', './IndexDatatype-c2232ebd', './IntersectionTests-f96cd46d', './Plane-c985a1d2'], (function (Matrix2, RuntimeError, defaultValue, EllipseGeometry, VertexFormat, ComponentDatatype, WebGLConstants, Transforms, _commonjsHelpers, combine, EllipseGeometryLibrary, GeometryAttribute, GeometryAttributes, GeometryInstance, GeometryOffsetAttribute, GeometryPipeline, AttributeCompression, EncodedCartesian3, IndexDatatype, IntersectionTests, Plane) { 'use strict';
  26. /**
  27. * A description of a circle on the ellipsoid. Circle geometry can be rendered with both {@link Primitive} and {@link GroundPrimitive}.
  28. *
  29. * @alias CircleGeometry
  30. * @constructor
  31. *
  32. * @param {Object} options Object with the following properties:
  33. * @param {Cartesian3} options.center The circle's center point in the fixed frame.
  34. * @param {Number} options.radius The radius in meters.
  35. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid the circle will be on.
  36. * @param {Number} [options.height=0.0] The distance in meters between the circle and the ellipsoid surface.
  37. * @param {Number} [options.granularity=0.02] The angular distance between points on the circle in radians.
  38. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  39. * @param {Number} [options.extrudedHeight=0.0] The distance in meters between the circle's extruded face and the ellipsoid surface.
  40. * @param {Number} [options.stRotation=0.0] The rotation of the texture coordinates, in radians. A positive rotation is counter-clockwise.
  41. *
  42. * @exception {DeveloperError} radius must be greater than zero.
  43. * @exception {DeveloperError} granularity must be greater than zero.
  44. *
  45. * @see CircleGeometry.createGeometry
  46. * @see Packable
  47. *
  48. * @example
  49. * // Create a circle.
  50. * const circle = new Cesium.CircleGeometry({
  51. * center : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
  52. * radius : 100000.0
  53. * });
  54. * const geometry = Cesium.CircleGeometry.createGeometry(circle);
  55. */
  56. function CircleGeometry(options) {
  57. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  58. const radius = options.radius;
  59. //>>includeStart('debug', pragmas.debug);
  60. RuntimeError.Check.typeOf.number("radius", radius);
  61. //>>includeEnd('debug');
  62. const ellipseGeometryOptions = {
  63. center: options.center,
  64. semiMajorAxis: radius,
  65. semiMinorAxis: radius,
  66. ellipsoid: options.ellipsoid,
  67. height: options.height,
  68. extrudedHeight: options.extrudedHeight,
  69. granularity: options.granularity,
  70. vertexFormat: options.vertexFormat,
  71. stRotation: options.stRotation,
  72. shadowVolume: options.shadowVolume,
  73. };
  74. this._ellipseGeometry = new EllipseGeometry.EllipseGeometry(ellipseGeometryOptions);
  75. this._workerName = "createCircleGeometry";
  76. }
  77. /**
  78. * The number of elements used to pack the object into an array.
  79. * @type {Number}
  80. */
  81. CircleGeometry.packedLength = EllipseGeometry.EllipseGeometry.packedLength;
  82. /**
  83. * Stores the provided instance into the provided array.
  84. *
  85. * @param {CircleGeometry} value The value to pack.
  86. * @param {Number[]} array The array to pack into.
  87. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  88. *
  89. * @returns {Number[]} The array that was packed into
  90. */
  91. CircleGeometry.pack = function (value, array, startingIndex) {
  92. //>>includeStart('debug', pragmas.debug);
  93. RuntimeError.Check.typeOf.object("value", value);
  94. //>>includeEnd('debug');
  95. return EllipseGeometry.EllipseGeometry.pack(value._ellipseGeometry, array, startingIndex);
  96. };
  97. const scratchEllipseGeometry = new EllipseGeometry.EllipseGeometry({
  98. center: new Matrix2.Cartesian3(),
  99. semiMajorAxis: 1.0,
  100. semiMinorAxis: 1.0,
  101. });
  102. const scratchOptions = {
  103. center: new Matrix2.Cartesian3(),
  104. radius: undefined,
  105. ellipsoid: Matrix2.Ellipsoid.clone(Matrix2.Ellipsoid.UNIT_SPHERE),
  106. height: undefined,
  107. extrudedHeight: undefined,
  108. granularity: undefined,
  109. vertexFormat: new VertexFormat.VertexFormat(),
  110. stRotation: undefined,
  111. semiMajorAxis: undefined,
  112. semiMinorAxis: undefined,
  113. shadowVolume: undefined,
  114. };
  115. /**
  116. * Retrieves an instance from a packed array.
  117. *
  118. * @param {Number[]} array The packed array.
  119. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  120. * @param {CircleGeometry} [result] The object into which to store the result.
  121. * @returns {CircleGeometry} The modified result parameter or a new CircleGeometry instance if one was not provided.
  122. */
  123. CircleGeometry.unpack = function (array, startingIndex, result) {
  124. const ellipseGeometry = EllipseGeometry.EllipseGeometry.unpack(
  125. array,
  126. startingIndex,
  127. scratchEllipseGeometry
  128. );
  129. scratchOptions.center = Matrix2.Cartesian3.clone(
  130. ellipseGeometry._center,
  131. scratchOptions.center
  132. );
  133. scratchOptions.ellipsoid = Matrix2.Ellipsoid.clone(
  134. ellipseGeometry._ellipsoid,
  135. scratchOptions.ellipsoid
  136. );
  137. scratchOptions.height = ellipseGeometry._height;
  138. scratchOptions.extrudedHeight = ellipseGeometry._extrudedHeight;
  139. scratchOptions.granularity = ellipseGeometry._granularity;
  140. scratchOptions.vertexFormat = VertexFormat.VertexFormat.clone(
  141. ellipseGeometry._vertexFormat,
  142. scratchOptions.vertexFormat
  143. );
  144. scratchOptions.stRotation = ellipseGeometry._stRotation;
  145. scratchOptions.shadowVolume = ellipseGeometry._shadowVolume;
  146. if (!defaultValue.defined(result)) {
  147. scratchOptions.radius = ellipseGeometry._semiMajorAxis;
  148. return new CircleGeometry(scratchOptions);
  149. }
  150. scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis;
  151. scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis;
  152. result._ellipseGeometry = new EllipseGeometry.EllipseGeometry(scratchOptions);
  153. return result;
  154. };
  155. /**
  156. * Computes the geometric representation of a circle on an ellipsoid, including its vertices, indices, and a bounding sphere.
  157. *
  158. * @param {CircleGeometry} circleGeometry A description of the circle.
  159. * @returns {Geometry|undefined} The computed vertices and indices.
  160. */
  161. CircleGeometry.createGeometry = function (circleGeometry) {
  162. return EllipseGeometry.EllipseGeometry.createGeometry(circleGeometry._ellipseGeometry);
  163. };
  164. /**
  165. * @private
  166. */
  167. CircleGeometry.createShadowVolume = function (
  168. circleGeometry,
  169. minHeightFunc,
  170. maxHeightFunc
  171. ) {
  172. const granularity = circleGeometry._ellipseGeometry._granularity;
  173. const ellipsoid = circleGeometry._ellipseGeometry._ellipsoid;
  174. const minHeight = minHeightFunc(granularity, ellipsoid);
  175. const maxHeight = maxHeightFunc(granularity, ellipsoid);
  176. return new CircleGeometry({
  177. center: circleGeometry._ellipseGeometry._center,
  178. radius: circleGeometry._ellipseGeometry._semiMajorAxis,
  179. ellipsoid: ellipsoid,
  180. stRotation: circleGeometry._ellipseGeometry._stRotation,
  181. granularity: granularity,
  182. extrudedHeight: minHeight,
  183. height: maxHeight,
  184. vertexFormat: VertexFormat.VertexFormat.POSITION_ONLY,
  185. shadowVolume: true,
  186. });
  187. };
  188. Object.defineProperties(CircleGeometry.prototype, {
  189. /**
  190. * @private
  191. */
  192. rectangle: {
  193. get: function () {
  194. return this._ellipseGeometry.rectangle;
  195. },
  196. },
  197. /**
  198. * For remapping texture coordinates when rendering CircleGeometries as GroundPrimitives.
  199. * @private
  200. */
  201. textureCoordinateRotationPoints: {
  202. get: function () {
  203. return this._ellipseGeometry.textureCoordinateRotationPoints;
  204. },
  205. },
  206. });
  207. function createCircleGeometry(circleGeometry, offset) {
  208. if (defaultValue.defined(offset)) {
  209. circleGeometry = CircleGeometry.unpack(circleGeometry, offset);
  210. }
  211. circleGeometry._ellipseGeometry._center = Matrix2.Cartesian3.clone(
  212. circleGeometry._ellipseGeometry._center
  213. );
  214. circleGeometry._ellipseGeometry._ellipsoid = Matrix2.Ellipsoid.clone(
  215. circleGeometry._ellipseGeometry._ellipsoid
  216. );
  217. return CircleGeometry.createGeometry(circleGeometry);
  218. }
  219. return createCircleGeometry;
  220. }));