createSphereGeometry.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./defined-26bd4a03', './Check-da037458', './freezeObject-2d83f591', './defaultValue-f2e68450', './Math-fa6e45cb', './Cartesian2-2a723276', './defineProperties-6f7a50f2', './Transforms-65aba0a4', './RuntimeError-ad75c885', './WebGLConstants-497deb20', './ComponentDatatype-69643096', './GeometryAttribute-ed359d71', './when-ee12a2cb', './GeometryAttributes-eecc9f43', './IndexDatatype-3de60176', './GeometryOffsetAttribute-cb30cd97', './VertexFormat-fbb91dc7', './EllipsoidGeometry-592b342c'], function (defined, Check, freezeObject, defaultValue, _Math, Cartesian2, defineProperties, Transforms, RuntimeError, WebGLConstants, ComponentDatatype, GeometryAttribute, when, GeometryAttributes, IndexDatatype, GeometryOffsetAttribute, VertexFormat, EllipsoidGeometry) { '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. * var sphere = new Cesium.SphereGeometry({
  22. * radius : 100.0,
  23. * vertexFormat : Cesium.VertexFormat.POSITION_ONLY
  24. * });
  25. * var geometry = Cesium.SphereGeometry.createGeometry(sphere);
  26. */
  27. function SphereGeometry(options) {
  28. var radius = defaultValue.defaultValue(options.radius, 1.0);
  29. var radii = new Cartesian2.Cartesian3(radius, radius, radius);
  30. var 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. Check.Check.typeOf.object('value', value);
  56. //>>includeEnd('debug');
  57. return EllipsoidGeometry.EllipsoidGeometry.pack(value._ellipsoidGeometry, array, startingIndex);
  58. };
  59. var scratchEllipsoidGeometry = new EllipsoidGeometry.EllipsoidGeometry();
  60. var scratchOptions = {
  61. radius : undefined,
  62. radii : new Cartesian2.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. var ellipsoidGeometry = EllipsoidGeometry.EllipsoidGeometry.unpack(array, startingIndex, scratchEllipsoidGeometry);
  77. scratchOptions.vertexFormat = VertexFormat.VertexFormat.clone(ellipsoidGeometry._vertexFormat, scratchOptions.vertexFormat);
  78. scratchOptions.stackPartitions = ellipsoidGeometry._stackPartitions;
  79. scratchOptions.slicePartitions = ellipsoidGeometry._slicePartitions;
  80. if (!defined.defined(result)) {
  81. scratchOptions.radius = ellipsoidGeometry._radii.x;
  82. return new SphereGeometry(scratchOptions);
  83. }
  84. Cartesian2.Cartesian3.clone(ellipsoidGeometry._radii, scratchOptions.radii);
  85. result._ellipsoidGeometry = new EllipsoidGeometry.EllipsoidGeometry(scratchOptions);
  86. return result;
  87. };
  88. /**
  89. * Computes the geometric representation of a sphere, including its vertices, indices, and a bounding sphere.
  90. *
  91. * @param {SphereGeometry} sphereGeometry A description of the sphere.
  92. * @returns {Geometry} The computed vertices and indices.
  93. */
  94. SphereGeometry.createGeometry = function(sphereGeometry) {
  95. return EllipsoidGeometry.EllipsoidGeometry.createGeometry(sphereGeometry._ellipsoidGeometry);
  96. };
  97. function createSphereGeometry(sphereGeometry, offset) {
  98. if (defined.defined(offset)) {
  99. sphereGeometry = SphereGeometry.unpack(sphereGeometry, offset);
  100. }
  101. return SphereGeometry.createGeometry(sphereGeometry);
  102. }
  103. return createSphereGeometry;
  104. });