createSphereGeometry.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./defaultValue-94c3e563', './Matrix2-fc7e9822', './RuntimeError-c581ca93', './EllipsoidGeometry-00501f3d', './VertexFormat-e46f29d6', './ComponentDatatype-4a60b8d6', './WebGLConstants-7dccdc96', './GeometryOffsetAttribute-3e8c299c', './Transforms-a076dbe6', './_commonjsHelpers-3aae1032-f55dc0c4', './combine-761d9c3f', './GeometryAttribute-2ecf73f6', './GeometryAttributes-7df9bef6', './IndexDatatype-db156785'], (function (defaultValue, Matrix2, RuntimeError, EllipsoidGeometry, VertexFormat, ComponentDatatype, WebGLConstants, GeometryOffsetAttribute, Transforms, _commonjsHelpers3aae1032, combine, GeometryAttribute, GeometryAttributes, IndexDatatype) { 'use strict';
  3. /**
  4. * A description of a sphere centered at the origin.
  5. *
  6. * @alias SphereGeometry
  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=64] The number of times to partition the ellipsoid into stacks.
  12. * @param {Number} [options.slicePartitions=64] The number of times to partition the ellipsoid into radial slices.
  13. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  14. *
  15. * @exception {DeveloperError} options.slicePartitions cannot be less than three.
  16. * @exception {DeveloperError} options.stackPartitions cannot be less than three.
  17. *
  18. * @see SphereGeometry#createGeometry
  19. *
  20. * @example
  21. * const sphere = new Cesium.SphereGeometry({
  22. * radius : 100.0,
  23. * vertexFormat : Cesium.VertexFormat.POSITION_ONLY
  24. * });
  25. * const geometry = Cesium.SphereGeometry.createGeometry(sphere);
  26. */
  27. function SphereGeometry(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. vertexFormat: options.vertexFormat,
  35. };
  36. this._ellipsoidGeometry = new EllipsoidGeometry.EllipsoidGeometry(ellipsoidOptions);
  37. this._workerName = "createSphereGeometry";
  38. }
  39. /**
  40. * The number of elements used to pack the object into an array.
  41. * @type {Number}
  42. */
  43. SphereGeometry.packedLength = EllipsoidGeometry.EllipsoidGeometry.packedLength;
  44. /**
  45. * Stores the provided instance into the provided array.
  46. *
  47. * @param {SphereGeometry} 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. SphereGeometry.pack = function (value, array, startingIndex) {
  54. //>>includeStart('debug', pragmas.debug);
  55. RuntimeError.Check.typeOf.object("value", value);
  56. //>>includeEnd('debug');
  57. return EllipsoidGeometry.EllipsoidGeometry.pack(value._ellipsoidGeometry, array, startingIndex);
  58. };
  59. const scratchEllipsoidGeometry = new EllipsoidGeometry.EllipsoidGeometry();
  60. const scratchOptions = {
  61. radius: undefined,
  62. radii: new Matrix2.Cartesian3(),
  63. vertexFormat: new VertexFormat.VertexFormat(),
  64. stackPartitions: undefined,
  65. slicePartitions: undefined,
  66. };
  67. /**
  68. * Retrieves an instance from a packed array.
  69. *
  70. * @param {Number[]} array The packed array.
  71. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  72. * @param {SphereGeometry} [result] The object into which to store the result.
  73. * @returns {SphereGeometry} The modified result parameter or a new SphereGeometry instance if one was not provided.
  74. */
  75. SphereGeometry.unpack = function (array, startingIndex, result) {
  76. const ellipsoidGeometry = EllipsoidGeometry.EllipsoidGeometry.unpack(
  77. array,
  78. startingIndex,
  79. scratchEllipsoidGeometry
  80. );
  81. scratchOptions.vertexFormat = VertexFormat.VertexFormat.clone(
  82. ellipsoidGeometry._vertexFormat,
  83. scratchOptions.vertexFormat
  84. );
  85. scratchOptions.stackPartitions = ellipsoidGeometry._stackPartitions;
  86. scratchOptions.slicePartitions = ellipsoidGeometry._slicePartitions;
  87. if (!defaultValue.defined(result)) {
  88. scratchOptions.radius = ellipsoidGeometry._radii.x;
  89. return new SphereGeometry(scratchOptions);
  90. }
  91. Matrix2.Cartesian3.clone(ellipsoidGeometry._radii, scratchOptions.radii);
  92. result._ellipsoidGeometry = new EllipsoidGeometry.EllipsoidGeometry(scratchOptions);
  93. return result;
  94. };
  95. /**
  96. * Computes the geometric representation of a sphere, including its vertices, indices, and a bounding sphere.
  97. *
  98. * @param {SphereGeometry} sphereGeometry A description of the sphere.
  99. * @returns {Geometry|undefined} The computed vertices and indices.
  100. */
  101. SphereGeometry.createGeometry = function (sphereGeometry) {
  102. return EllipsoidGeometry.EllipsoidGeometry.createGeometry(sphereGeometry._ellipsoidGeometry);
  103. };
  104. function createSphereGeometry(sphereGeometry, offset) {
  105. if (defaultValue.defined(offset)) {
  106. sphereGeometry = SphereGeometry.unpack(sphereGeometry, offset);
  107. }
  108. return SphereGeometry.createGeometry(sphereGeometry);
  109. }
  110. return createSphereGeometry;
  111. }));