SphereOutlineGeometry.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import Cartesian3 from './Cartesian3.js';
  2. import Check from './Check.js';
  3. import defaultValue from './defaultValue.js';
  4. import defined from './defined.js';
  5. import EllipsoidOutlineGeometry from './EllipsoidOutlineGeometry.js';
  6. /**
  7. * A description of the outline of a sphere.
  8. *
  9. * @alias SphereOutlineGeometry
  10. * @constructor
  11. *
  12. * @param {Object} [options] Object with the following properties:
  13. * @param {Number} [options.radius=1.0] The radius of the sphere.
  14. * @param {Number} [options.stackPartitions=10] The count of stacks for the sphere (1 greater than the number of parallel lines).
  15. * @param {Number} [options.slicePartitions=8] The count of slices for the sphere (Equal to the number of radial lines).
  16. * @param {Number} [options.subdivisions=200] The number of points per line, determining the granularity of the curvature .
  17. *
  18. * @exception {DeveloperError} options.stackPartitions must be greater than or equal to one.
  19. * @exception {DeveloperError} options.slicePartitions must be greater than or equal to zero.
  20. * @exception {DeveloperError} options.subdivisions must be greater than or equal to zero.
  21. *
  22. * @example
  23. * var sphere = new Cesium.SphereOutlineGeometry({
  24. * radius : 100.0,
  25. * stackPartitions : 6,
  26. * slicePartitions: 5
  27. * });
  28. * var geometry = Cesium.SphereOutlineGeometry.createGeometry(sphere);
  29. */
  30. function SphereOutlineGeometry(options) {
  31. var radius = defaultValue(options.radius, 1.0);
  32. var radii = new Cartesian3(radius, radius, radius);
  33. var ellipsoidOptions = {
  34. radii: radii,
  35. stackPartitions: options.stackPartitions,
  36. slicePartitions: options.slicePartitions,
  37. subdivisions: options.subdivisions
  38. };
  39. this._ellipsoidGeometry = new EllipsoidOutlineGeometry(ellipsoidOptions);
  40. this._workerName = 'createSphereOutlineGeometry';
  41. }
  42. /**
  43. * The number of elements used to pack the object into an array.
  44. * @type {Number}
  45. */
  46. SphereOutlineGeometry.packedLength = EllipsoidOutlineGeometry.packedLength;
  47. /**
  48. * Stores the provided instance into the provided array.
  49. *
  50. * @param {SphereOutlineGeometry} value The value to pack.
  51. * @param {Number[]} array The array to pack into.
  52. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  53. *
  54. * @returns {Number[]} The array that was packed into
  55. */
  56. SphereOutlineGeometry.pack = function(value, array, startingIndex) {
  57. //>>includeStart('debug', pragmas.debug);
  58. Check.typeOf.object('value', value);
  59. //>>includeEnd('debug');
  60. return EllipsoidOutlineGeometry.pack(value._ellipsoidGeometry, array, startingIndex);
  61. };
  62. var scratchEllipsoidGeometry = new EllipsoidOutlineGeometry();
  63. var scratchOptions = {
  64. radius : undefined,
  65. radii : new Cartesian3(),
  66. stackPartitions : undefined,
  67. slicePartitions : undefined,
  68. subdivisions : undefined
  69. };
  70. /**
  71. * Retrieves an instance from a packed array.
  72. *
  73. * @param {Number[]} array The packed array.
  74. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  75. * @param {SphereOutlineGeometry} [result] The object into which to store the result.
  76. * @returns {SphereOutlineGeometry} The modified result parameter or a new SphereOutlineGeometry instance if one was not provided.
  77. */
  78. SphereOutlineGeometry.unpack = function(array, startingIndex, result) {
  79. var ellipsoidGeometry = EllipsoidOutlineGeometry.unpack(array, startingIndex, scratchEllipsoidGeometry);
  80. scratchOptions.stackPartitions = ellipsoidGeometry._stackPartitions;
  81. scratchOptions.slicePartitions = ellipsoidGeometry._slicePartitions;
  82. scratchOptions.subdivisions = ellipsoidGeometry._subdivisions;
  83. if (!defined(result)) {
  84. scratchOptions.radius = ellipsoidGeometry._radii.x;
  85. return new SphereOutlineGeometry(scratchOptions);
  86. }
  87. Cartesian3.clone(ellipsoidGeometry._radii, scratchOptions.radii);
  88. result._ellipsoidGeometry = new EllipsoidOutlineGeometry(scratchOptions);
  89. return result;
  90. };
  91. /**
  92. * Computes the geometric representation of an outline of a sphere, including its vertices, indices, and a bounding sphere.
  93. *
  94. * @param {SphereOutlineGeometry} sphereGeometry A description of the sphere outline.
  95. * @returns {Geometry} The computed vertices and indices.
  96. */
  97. SphereOutlineGeometry.createGeometry = function(sphereGeometry) {
  98. return EllipsoidOutlineGeometry.createGeometry(sphereGeometry._ellipsoidGeometry);
  99. };
  100. export default SphereOutlineGeometry;