createSphereOutlineGeometry.js 5.5 KB

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