createSphereOutlineGeometry.js 7.0 KB

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