createSphereOutlineGeometry.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./defaultValue-94c3e563', './Matrix2-fc7e9822', './RuntimeError-c581ca93', './EllipsoidOutlineGeometry-34b199b4', './ComponentDatatype-4a60b8d6', './WebGLConstants-7dccdc96', './GeometryOffsetAttribute-3e8c299c', './Transforms-a076dbe6', './_commonjsHelpers-3aae1032-f55dc0c4', './combine-761d9c3f', './GeometryAttribute-2ecf73f6', './GeometryAttributes-7df9bef6', './IndexDatatype-db156785'], (function (defaultValue, Matrix2, RuntimeError, EllipsoidOutlineGeometry, ComponentDatatype, WebGLConstants, GeometryOffsetAttribute, Transforms, _commonjsHelpers3aae1032, combine, GeometryAttribute, GeometryAttributes, IndexDatatype) { 'use strict';
  3. /**
  4. * A description of the outline of a sphere.
  5. *
  6. * @alias SphereOutlineGeometry
  7. * @constructor
  8. *
  9. * @param {Object} [options] Object with the following properties:
  10. * @param {Number} [options.radius=1.0] The radius of the sphere.
  11. * @param {Number} [options.stackPartitions=10] The count of stacks for the sphere (1 greater than the number of parallel lines).
  12. * @param {Number} [options.slicePartitions=8] The count of slices for the sphere (Equal to the number of radial lines).
  13. * @param {Number} [options.subdivisions=200] The number of points per line, determining the granularity of the curvature .
  14. *
  15. * @exception {DeveloperError} options.stackPartitions must be greater than or equal to one.
  16. * @exception {DeveloperError} options.slicePartitions must be greater than or equal to zero.
  17. * @exception {DeveloperError} options.subdivisions must be greater than or equal to zero.
  18. *
  19. * @example
  20. * const sphere = new Cesium.SphereOutlineGeometry({
  21. * radius : 100.0,
  22. * stackPartitions : 6,
  23. * slicePartitions: 5
  24. * });
  25. * const geometry = Cesium.SphereOutlineGeometry.createGeometry(sphere);
  26. */
  27. function SphereOutlineGeometry(options) {
  28. const radius = defaultValue.defaultValue(options.radius, 1.0);
  29. const radii = new Matrix2.Cartesian3(radius, radius, radius);
  30. const ellipsoidOptions = {
  31. radii: radii,
  32. stackPartitions: options.stackPartitions,
  33. slicePartitions: options.slicePartitions,
  34. subdivisions: options.subdivisions,
  35. };
  36. this._ellipsoidGeometry = new EllipsoidOutlineGeometry.EllipsoidOutlineGeometry(ellipsoidOptions);
  37. this._workerName = "createSphereOutlineGeometry";
  38. }
  39. /**
  40. * The number of elements used to pack the object into an array.
  41. * @type {Number}
  42. */
  43. SphereOutlineGeometry.packedLength = EllipsoidOutlineGeometry.EllipsoidOutlineGeometry.packedLength;
  44. /**
  45. * Stores the provided instance into the provided array.
  46. *
  47. * @param {SphereOutlineGeometry} value The value to pack.
  48. * @param {Number[]} array The array to pack into.
  49. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  50. *
  51. * @returns {Number[]} The array that was packed into
  52. */
  53. SphereOutlineGeometry.pack = function (value, array, startingIndex) {
  54. //>>includeStart('debug', pragmas.debug);
  55. RuntimeError.Check.typeOf.object("value", value);
  56. //>>includeEnd('debug');
  57. return EllipsoidOutlineGeometry.EllipsoidOutlineGeometry.pack(
  58. value._ellipsoidGeometry,
  59. array,
  60. startingIndex
  61. );
  62. };
  63. const scratchEllipsoidGeometry = new EllipsoidOutlineGeometry.EllipsoidOutlineGeometry();
  64. const scratchOptions = {
  65. radius: undefined,
  66. radii: new Matrix2.Cartesian3(),
  67. stackPartitions: undefined,
  68. slicePartitions: undefined,
  69. subdivisions: undefined,
  70. };
  71. /**
  72. * Retrieves an instance from a packed array.
  73. *
  74. * @param {Number[]} array The packed array.
  75. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  76. * @param {SphereOutlineGeometry} [result] The object into which to store the result.
  77. * @returns {SphereOutlineGeometry} The modified result parameter or a new SphereOutlineGeometry instance if one was not provided.
  78. */
  79. SphereOutlineGeometry.unpack = function (array, startingIndex, result) {
  80. const ellipsoidGeometry = EllipsoidOutlineGeometry.EllipsoidOutlineGeometry.unpack(
  81. array,
  82. startingIndex,
  83. scratchEllipsoidGeometry
  84. );
  85. scratchOptions.stackPartitions = ellipsoidGeometry._stackPartitions;
  86. scratchOptions.slicePartitions = ellipsoidGeometry._slicePartitions;
  87. scratchOptions.subdivisions = ellipsoidGeometry._subdivisions;
  88. if (!defaultValue.defined(result)) {
  89. scratchOptions.radius = ellipsoidGeometry._radii.x;
  90. return new SphereOutlineGeometry(scratchOptions);
  91. }
  92. Matrix2.Cartesian3.clone(ellipsoidGeometry._radii, scratchOptions.radii);
  93. result._ellipsoidGeometry = new EllipsoidOutlineGeometry.EllipsoidOutlineGeometry(scratchOptions);
  94. return result;
  95. };
  96. /**
  97. * Computes the geometric representation of an outline of a sphere, including its vertices, indices, and a bounding sphere.
  98. *
  99. * @param {SphereOutlineGeometry} sphereGeometry A description of the sphere outline.
  100. * @returns {Geometry|undefined} The computed vertices and indices.
  101. */
  102. SphereOutlineGeometry.createGeometry = function (sphereGeometry) {
  103. return EllipsoidOutlineGeometry.EllipsoidOutlineGeometry.createGeometry(
  104. sphereGeometry._ellipsoidGeometry
  105. );
  106. };
  107. function createSphereOutlineGeometry(sphereGeometry, offset) {
  108. if (defaultValue.defined(offset)) {
  109. sphereGeometry = SphereOutlineGeometry.unpack(sphereGeometry, offset);
  110. }
  111. return SphereOutlineGeometry.createGeometry(sphereGeometry);
  112. }
  113. return createSphereOutlineGeometry;
  114. }));