SphereOutlineGeometry.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. * const sphere = new Cesium.SphereOutlineGeometry({
  24. * radius : 100.0,
  25. * stackPartitions : 6,
  26. * slicePartitions: 5
  27. * });
  28. * const geometry = Cesium.SphereOutlineGeometry.createGeometry(sphere);
  29. */
  30. function SphereOutlineGeometry(options) {
  31. const radius = defaultValue(options.radius, 1.0);
  32. const radii = new Cartesian3(radius, radius, radius);
  33. const 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(
  61. value._ellipsoidGeometry,
  62. array,
  63. startingIndex
  64. );
  65. };
  66. const scratchEllipsoidGeometry = new EllipsoidOutlineGeometry();
  67. const scratchOptions = {
  68. radius: undefined,
  69. radii: new Cartesian3(),
  70. stackPartitions: undefined,
  71. slicePartitions: undefined,
  72. subdivisions: undefined,
  73. };
  74. /**
  75. * Retrieves an instance from a packed array.
  76. *
  77. * @param {Number[]} array The packed array.
  78. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  79. * @param {SphereOutlineGeometry} [result] The object into which to store the result.
  80. * @returns {SphereOutlineGeometry} The modified result parameter or a new SphereOutlineGeometry instance if one was not provided.
  81. */
  82. SphereOutlineGeometry.unpack = function (array, startingIndex, result) {
  83. const ellipsoidGeometry = EllipsoidOutlineGeometry.unpack(
  84. array,
  85. startingIndex,
  86. scratchEllipsoidGeometry
  87. );
  88. scratchOptions.stackPartitions = ellipsoidGeometry._stackPartitions;
  89. scratchOptions.slicePartitions = ellipsoidGeometry._slicePartitions;
  90. scratchOptions.subdivisions = ellipsoidGeometry._subdivisions;
  91. if (!defined(result)) {
  92. scratchOptions.radius = ellipsoidGeometry._radii.x;
  93. return new SphereOutlineGeometry(scratchOptions);
  94. }
  95. Cartesian3.clone(ellipsoidGeometry._radii, scratchOptions.radii);
  96. result._ellipsoidGeometry = new EllipsoidOutlineGeometry(scratchOptions);
  97. return result;
  98. };
  99. /**
  100. * Computes the geometric representation of an outline of a sphere, including its vertices, indices, and a bounding sphere.
  101. *
  102. * @param {SphereOutlineGeometry} sphereGeometry A description of the sphere outline.
  103. * @returns {Geometry|undefined} The computed vertices and indices.
  104. */
  105. SphereOutlineGeometry.createGeometry = function (sphereGeometry) {
  106. return EllipsoidOutlineGeometry.createGeometry(
  107. sphereGeometry._ellipsoidGeometry
  108. );
  109. };
  110. export default SphereOutlineGeometry;