createSphereOutlineGeometry.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**
  2. * @license
  3. * Cesium - https://github.com/CesiumGS/cesium
  4. * Version 1.97
  5. *
  6. * Copyright 2011-2022 Cesium Contributors
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * Columbus View (Pat. Pend.)
  21. *
  22. * Portions licensed separately.
  23. * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
  24. */
  25. define(['./defaultValue-a6eb9f34', './Matrix2-ab676047', './RuntimeError-1088cc64', './EllipsoidOutlineGeometry-f7ea6ffd', './ComponentDatatype-e06f4e16', './WebGLConstants-d81b330d', './Transforms-c78c4637', './_commonjsHelpers-89c9b271', './combine-7cf28d88', './GeometryAttribute-4f02e2ad', './GeometryAttributes-aff51037', './GeometryOffsetAttribute-102da468', './IndexDatatype-c2232ebd'], (function (defaultValue, Matrix2, RuntimeError, EllipsoidOutlineGeometry, ComponentDatatype, WebGLConstants, Transforms, _commonjsHelpers, combine, GeometryAttribute, GeometryAttributes, GeometryOffsetAttribute, IndexDatatype) { 'use strict';
  26. /**
  27. * A description of the outline of a sphere.
  28. *
  29. * @alias SphereOutlineGeometry
  30. * @constructor
  31. *
  32. * @param {Object} [options] Object with the following properties:
  33. * @param {Number} [options.radius=1.0] The radius of the sphere.
  34. * @param {Number} [options.stackPartitions=10] The count of stacks for the sphere (1 greater than the number of parallel lines).
  35. * @param {Number} [options.slicePartitions=8] The count of slices for the sphere (Equal to the number of radial lines).
  36. * @param {Number} [options.subdivisions=200] The number of points per line, determining the granularity of the curvature .
  37. *
  38. * @exception {DeveloperError} options.stackPartitions must be greater than or equal to one.
  39. * @exception {DeveloperError} options.slicePartitions must be greater than or equal to zero.
  40. * @exception {DeveloperError} options.subdivisions must be greater than or equal to zero.
  41. *
  42. * @example
  43. * const sphere = new Cesium.SphereOutlineGeometry({
  44. * radius : 100.0,
  45. * stackPartitions : 6,
  46. * slicePartitions: 5
  47. * });
  48. * const geometry = Cesium.SphereOutlineGeometry.createGeometry(sphere);
  49. */
  50. function SphereOutlineGeometry(options) {
  51. const radius = defaultValue.defaultValue(options.radius, 1.0);
  52. const radii = new Matrix2.Cartesian3(radius, radius, radius);
  53. const ellipsoidOptions = {
  54. radii: radii,
  55. stackPartitions: options.stackPartitions,
  56. slicePartitions: options.slicePartitions,
  57. subdivisions: options.subdivisions,
  58. };
  59. this._ellipsoidGeometry = new EllipsoidOutlineGeometry.EllipsoidOutlineGeometry(ellipsoidOptions);
  60. this._workerName = "createSphereOutlineGeometry";
  61. }
  62. /**
  63. * The number of elements used to pack the object into an array.
  64. * @type {Number}
  65. */
  66. SphereOutlineGeometry.packedLength = EllipsoidOutlineGeometry.EllipsoidOutlineGeometry.packedLength;
  67. /**
  68. * Stores the provided instance into the provided array.
  69. *
  70. * @param {SphereOutlineGeometry} value The value to pack.
  71. * @param {Number[]} array The array to pack into.
  72. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  73. *
  74. * @returns {Number[]} The array that was packed into
  75. */
  76. SphereOutlineGeometry.pack = function (value, array, startingIndex) {
  77. //>>includeStart('debug', pragmas.debug);
  78. RuntimeError.Check.typeOf.object("value", value);
  79. //>>includeEnd('debug');
  80. return EllipsoidOutlineGeometry.EllipsoidOutlineGeometry.pack(
  81. value._ellipsoidGeometry,
  82. array,
  83. startingIndex
  84. );
  85. };
  86. const scratchEllipsoidGeometry = new EllipsoidOutlineGeometry.EllipsoidOutlineGeometry();
  87. const scratchOptions = {
  88. radius: undefined,
  89. radii: new Matrix2.Cartesian3(),
  90. stackPartitions: undefined,
  91. slicePartitions: undefined,
  92. subdivisions: undefined,
  93. };
  94. /**
  95. * Retrieves an instance from a packed array.
  96. *
  97. * @param {Number[]} array The packed array.
  98. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  99. * @param {SphereOutlineGeometry} [result] The object into which to store the result.
  100. * @returns {SphereOutlineGeometry} The modified result parameter or a new SphereOutlineGeometry instance if one was not provided.
  101. */
  102. SphereOutlineGeometry.unpack = function (array, startingIndex, result) {
  103. const ellipsoidGeometry = EllipsoidOutlineGeometry.EllipsoidOutlineGeometry.unpack(
  104. array,
  105. startingIndex,
  106. scratchEllipsoidGeometry
  107. );
  108. scratchOptions.stackPartitions = ellipsoidGeometry._stackPartitions;
  109. scratchOptions.slicePartitions = ellipsoidGeometry._slicePartitions;
  110. scratchOptions.subdivisions = ellipsoidGeometry._subdivisions;
  111. if (!defaultValue.defined(result)) {
  112. scratchOptions.radius = ellipsoidGeometry._radii.x;
  113. return new SphereOutlineGeometry(scratchOptions);
  114. }
  115. Matrix2.Cartesian3.clone(ellipsoidGeometry._radii, scratchOptions.radii);
  116. result._ellipsoidGeometry = new EllipsoidOutlineGeometry.EllipsoidOutlineGeometry(scratchOptions);
  117. return result;
  118. };
  119. /**
  120. * Computes the geometric representation of an outline of a sphere, including its vertices, indices, and a bounding sphere.
  121. *
  122. * @param {SphereOutlineGeometry} sphereGeometry A description of the sphere outline.
  123. * @returns {Geometry|undefined} The computed vertices and indices.
  124. */
  125. SphereOutlineGeometry.createGeometry = function (sphereGeometry) {
  126. return EllipsoidOutlineGeometry.EllipsoidOutlineGeometry.createGeometry(
  127. sphereGeometry._ellipsoidGeometry
  128. );
  129. };
  130. function createSphereOutlineGeometry(sphereGeometry, offset) {
  131. if (defaultValue.defined(offset)) {
  132. sphereGeometry = SphereOutlineGeometry.unpack(sphereGeometry, offset);
  133. }
  134. return SphereOutlineGeometry.createGeometry(sphereGeometry);
  135. }
  136. return createSphereOutlineGeometry;
  137. }));