createCircleGeometry.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /**
  2. * Cesium - https://github.com/AnalyticalGraphicsInc/cesium
  3. *
  4. * Copyright 2011-2017 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/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md for full licensing details.
  22. */
  23. define(['./when-8d13db60', './Check-70bec281', './Math-61ede240', './Cartographic-fe4be337', './Cartesian2-85064f09', './BoundingSphere-775c5788', './Cartesian4-5af5bb24', './RuntimeError-ba10bc3e', './WebGLConstants-4c11ee5f', './ComponentDatatype-5862616f', './GeometryAttribute-91704ebb', './PrimitiveType-97893bc7', './FeatureDetection-7bd32c34', './Transforms-b2e71640', './buildModuleUrl-14bfe498', './GeometryAttributes-aacecde6', './AttributeCompression-84a90a13', './GeometryPipeline-f95a0a6f', './EncodedCartesian3-a569cba8', './IndexDatatype-9435b55f', './IntersectionTests-397d9494', './Plane-8390418f', './GeometryOffsetAttribute-ca302482', './VertexFormat-fe4db402', './EllipseGeometryLibrary-08dbcdef', './GeometryInstance-93a01b5d', './EllipseGeometry-3bedc35b'], function (when, Check, _Math, Cartographic, Cartesian2, BoundingSphere, Cartesian4, RuntimeError, WebGLConstants, ComponentDatatype, GeometryAttribute, PrimitiveType, FeatureDetection, Transforms, buildModuleUrl, GeometryAttributes, AttributeCompression, GeometryPipeline, EncodedCartesian3, IndexDatatype, IntersectionTests, Plane, GeometryOffsetAttribute, VertexFormat, EllipseGeometryLibrary, GeometryInstance, EllipseGeometry) { '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. * var circle = new Cesium.CircleGeometry({
  49. * center : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
  50. * radius : 100000.0
  51. * });
  52. * var geometry = Cesium.CircleGeometry.createGeometry(circle);
  53. */
  54. function CircleGeometry(options) {
  55. options = when.defaultValue(options, when.defaultValue.EMPTY_OBJECT);
  56. var radius = options.radius;
  57. //>>includeStart('debug', pragmas.debug);
  58. Check.Check.typeOf.number('radius', radius);
  59. //>>includeEnd('debug');
  60. var 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. Check.Check.typeOf.object('value', value);
  92. //>>includeEnd('debug');
  93. return EllipseGeometry.EllipseGeometry.pack(value._ellipseGeometry, array, startingIndex);
  94. };
  95. var scratchEllipseGeometry = new EllipseGeometry.EllipseGeometry({
  96. center : new Cartographic.Cartesian3(),
  97. semiMajorAxis : 1.0,
  98. semiMinorAxis : 1.0
  99. });
  100. var scratchOptions = {
  101. center : new Cartographic.Cartesian3(),
  102. radius : undefined,
  103. ellipsoid : Cartesian2.Ellipsoid.clone(Cartesian2.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. var ellipseGeometry = EllipseGeometry.EllipseGeometry.unpack(array, startingIndex, scratchEllipseGeometry);
  123. scratchOptions.center = Cartographic.Cartesian3.clone(ellipseGeometry._center, scratchOptions.center);
  124. scratchOptions.ellipsoid = Cartesian2.Ellipsoid.clone(ellipseGeometry._ellipsoid, scratchOptions.ellipsoid);
  125. scratchOptions.height = ellipseGeometry._height;
  126. scratchOptions.extrudedHeight = ellipseGeometry._extrudedHeight;
  127. scratchOptions.granularity = ellipseGeometry._granularity;
  128. scratchOptions.vertexFormat = VertexFormat.VertexFormat.clone(ellipseGeometry._vertexFormat, scratchOptions.vertexFormat);
  129. scratchOptions.stRotation = ellipseGeometry._stRotation;
  130. scratchOptions.shadowVolume = ellipseGeometry._shadowVolume;
  131. if (!when.defined(result)) {
  132. scratchOptions.radius = ellipseGeometry._semiMajorAxis;
  133. return new CircleGeometry(scratchOptions);
  134. }
  135. scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis;
  136. scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis;
  137. result._ellipseGeometry = new EllipseGeometry.EllipseGeometry(scratchOptions);
  138. return result;
  139. };
  140. /**
  141. * Computes the geometric representation of a circle on an ellipsoid, including its vertices, indices, and a bounding sphere.
  142. *
  143. * @param {CircleGeometry} circleGeometry A description of the circle.
  144. * @returns {Geometry|undefined} The computed vertices and indices.
  145. */
  146. CircleGeometry.createGeometry = function(circleGeometry) {
  147. return EllipseGeometry.EllipseGeometry.createGeometry(circleGeometry._ellipseGeometry);
  148. };
  149. /**
  150. * @private
  151. */
  152. CircleGeometry.createShadowVolume = function(circleGeometry, minHeightFunc, maxHeightFunc) {
  153. var granularity = circleGeometry._ellipseGeometry._granularity;
  154. var ellipsoid = circleGeometry._ellipseGeometry._ellipsoid;
  155. var minHeight = minHeightFunc(granularity, ellipsoid);
  156. var maxHeight = maxHeightFunc(granularity, ellipsoid);
  157. return new CircleGeometry({
  158. center : circleGeometry._ellipseGeometry._center,
  159. radius : circleGeometry._ellipseGeometry._semiMajorAxis,
  160. ellipsoid : ellipsoid,
  161. stRotation : circleGeometry._ellipseGeometry._stRotation,
  162. granularity : granularity,
  163. extrudedHeight : minHeight,
  164. height : maxHeight,
  165. vertexFormat : VertexFormat.VertexFormat.POSITION_ONLY,
  166. shadowVolume: true
  167. });
  168. };
  169. Object.defineProperties(CircleGeometry.prototype, {
  170. /**
  171. * @private
  172. */
  173. rectangle : {
  174. get : function() {
  175. return this._ellipseGeometry.rectangle;
  176. }
  177. },
  178. /**
  179. * For remapping texture coordinates when rendering CircleGeometries as GroundPrimitives.
  180. * @private
  181. */
  182. textureCoordinateRotationPoints : {
  183. get : function() {
  184. return this._ellipseGeometry.textureCoordinateRotationPoints;
  185. }
  186. }
  187. });
  188. function createCircleGeometry(circleGeometry, offset) {
  189. if (when.defined(offset)) {
  190. circleGeometry = CircleGeometry.unpack(circleGeometry, offset);
  191. }
  192. circleGeometry._ellipseGeometry._center = Cartographic.Cartesian3.clone(circleGeometry._ellipseGeometry._center);
  193. circleGeometry._ellipseGeometry._ellipsoid = Cartesian2.Ellipsoid.clone(circleGeometry._ellipseGeometry._ellipsoid);
  194. return CircleGeometry.createGeometry(circleGeometry);
  195. }
  196. return createCircleGeometry;
  197. });