createSphereOutlineGeometry.js 6.2 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', './EllipsoidOutlineGeometry-96f1f311'], function (defined, Check, freezeObject, defaultValue, _Math, Cartesian2, defineProperties, Transforms, RuntimeError, WebGLConstants, ComponentDatatype, GeometryAttribute, when, GeometryAttributes, IndexDatatype, GeometryOffsetAttribute, EllipsoidOutlineGeometry) { '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. * var sphere = new Cesium.SphereOutlineGeometry({
  21. * radius : 100.0,
  22. * stackPartitions : 6,
  23. * slicePartitions: 5
  24. * });
  25. * var geometry = Cesium.SphereOutlineGeometry.createGeometry(sphere);
  26. */
  27. function SphereOutlineGeometry(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. 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. Check.Check.typeOf.object('value', value);
  56. //>>includeEnd('debug');
  57. return EllipsoidOutlineGeometry.EllipsoidOutlineGeometry.pack(value._ellipsoidGeometry, array, startingIndex);
  58. };
  59. var scratchEllipsoidGeometry = new EllipsoidOutlineGeometry.EllipsoidOutlineGeometry();
  60. var scratchOptions = {
  61. radius : undefined,
  62. radii : new Cartesian2.Cartesian3(),
  63. stackPartitions : undefined,
  64. slicePartitions : undefined,
  65. subdivisions : 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 {SphereOutlineGeometry} [result] The object into which to store the result.
  73. * @returns {SphereOutlineGeometry} The modified result parameter or a new SphereOutlineGeometry instance if one was not provided.
  74. */
  75. SphereOutlineGeometry.unpack = function(array, startingIndex, result) {
  76. var ellipsoidGeometry = EllipsoidOutlineGeometry.EllipsoidOutlineGeometry.unpack(array, startingIndex, scratchEllipsoidGeometry);
  77. scratchOptions.stackPartitions = ellipsoidGeometry._stackPartitions;
  78. scratchOptions.slicePartitions = ellipsoidGeometry._slicePartitions;
  79. scratchOptions.subdivisions = ellipsoidGeometry._subdivisions;
  80. if (!defined.defined(result)) {
  81. scratchOptions.radius = ellipsoidGeometry._radii.x;
  82. return new SphereOutlineGeometry(scratchOptions);
  83. }
  84. Cartesian2.Cartesian3.clone(ellipsoidGeometry._radii, scratchOptions.radii);
  85. result._ellipsoidGeometry = new EllipsoidOutlineGeometry.EllipsoidOutlineGeometry(scratchOptions);
  86. return result;
  87. };
  88. /**
  89. * Computes the geometric representation of an outline of a sphere, including its vertices, indices, and a bounding sphere.
  90. *
  91. * @param {SphereOutlineGeometry} sphereGeometry A description of the sphere outline.
  92. * @returns {Geometry} The computed vertices and indices.
  93. */
  94. SphereOutlineGeometry.createGeometry = function(sphereGeometry) {
  95. return EllipsoidOutlineGeometry.EllipsoidOutlineGeometry.createGeometry(sphereGeometry._ellipsoidGeometry);
  96. };
  97. function createSphereOutlineGeometry(sphereGeometry, offset) {
  98. if (defined.defined(offset)) {
  99. sphereGeometry = SphereOutlineGeometry.unpack(sphereGeometry, offset);
  100. }
  101. return SphereOutlineGeometry.createGeometry(sphereGeometry);
  102. }
  103. return createSphereOutlineGeometry;
  104. });