createPolylineVolumeOutlineGeometry.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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', './IntersectionTests-c2360ffa', './Plane-a1a3fd52', './arrayRemoveDuplicates-dd708d81', './BoundingRectangle-36e6acca', './EllipsoidTangentPlane-10c6053a', './EllipsoidRhumbLine-c6cdbfd3', './PolygonPipeline-e486c11c', './PolylineVolumeGeometryLibrary-57289189', './EllipsoidGeodesic-53e988a6', './PolylinePipeline-b4161aaf'], function (defined, Check, freezeObject, defaultValue, _Math, Cartesian2, defineProperties, Transforms, RuntimeError, WebGLConstants, ComponentDatatype, GeometryAttribute, when, GeometryAttributes, IndexDatatype, IntersectionTests, Plane, arrayRemoveDuplicates, BoundingRectangle, EllipsoidTangentPlane, EllipsoidRhumbLine, PolygonPipeline, PolylineVolumeGeometryLibrary, EllipsoidGeodesic, PolylinePipeline) { 'use strict';
  3. function computeAttributes(positions, shape) {
  4. var attributes = new GeometryAttributes.GeometryAttributes();
  5. attributes.position = new GeometryAttribute.GeometryAttribute({
  6. componentDatatype : ComponentDatatype.ComponentDatatype.DOUBLE,
  7. componentsPerAttribute : 3,
  8. values : positions
  9. });
  10. var shapeLength = shape.length;
  11. var vertexCount = attributes.position.values.length / 3;
  12. var positionLength = positions.length / 3;
  13. var shapeCount = positionLength / shapeLength;
  14. var indices = IndexDatatype.IndexDatatype.createTypedArray(vertexCount, 2 * shapeLength * (shapeCount + 1));
  15. var i, j;
  16. var index = 0;
  17. i = 0;
  18. var offset = i * shapeLength;
  19. for (j = 0; j < shapeLength - 1; j++) {
  20. indices[index++] = j + offset;
  21. indices[index++] = j + offset + 1;
  22. }
  23. indices[index++] = shapeLength - 1 + offset;
  24. indices[index++] = offset;
  25. i = shapeCount - 1;
  26. offset = i * shapeLength;
  27. for (j = 0; j < shapeLength - 1; j++) {
  28. indices[index++] = j + offset;
  29. indices[index++] = j + offset + 1;
  30. }
  31. indices[index++] = shapeLength - 1 + offset;
  32. indices[index++] = offset;
  33. for (i = 0; i < shapeCount - 1; i++) {
  34. var firstOffset = shapeLength * i;
  35. var secondOffset = firstOffset + shapeLength;
  36. for (j = 0; j < shapeLength; j++) {
  37. indices[index++] = j + firstOffset;
  38. indices[index++] = j + secondOffset;
  39. }
  40. }
  41. var geometry = new GeometryAttribute.Geometry({
  42. attributes : attributes,
  43. indices : IndexDatatype.IndexDatatype.createTypedArray(vertexCount, indices),
  44. boundingSphere : Transforms.BoundingSphere.fromVertices(positions),
  45. primitiveType : GeometryAttribute.PrimitiveType.LINES
  46. });
  47. return geometry;
  48. }
  49. /**
  50. * A description of a polyline with a volume (a 2D shape extruded along a polyline).
  51. *
  52. * @alias PolylineVolumeOutlineGeometry
  53. * @constructor
  54. *
  55. * @param {Object} options Object with the following properties:
  56. * @param {Cartesian3[]} options.polylinePositions An array of positions that define the center of the polyline volume.
  57. * @param {Cartesian2[]} options.shapePositions An array of positions that define the shape to be extruded along the polyline
  58. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.
  59. * @param {Number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.
  60. * @param {CornerType} [options.cornerType=CornerType.ROUNDED] Determines the style of the corners.
  61. *
  62. * @see PolylineVolumeOutlineGeometry#createGeometry
  63. *
  64. * @example
  65. * function computeCircle(radius) {
  66. * var positions = [];
  67. * for (var i = 0; i < 360; i++) {
  68. * var radians = Cesium.Math.toRadians(i);
  69. * positions.push(new Cesium.Cartesian2(radius * Math.cos(radians), radius * Math.sin(radians)));
  70. * }
  71. * return positions;
  72. * }
  73. *
  74. * var volumeOutline = new Cesium.PolylineVolumeOutlineGeometry({
  75. * polylinePositions : Cesium.Cartesian3.fromDegreesArray([
  76. * -72.0, 40.0,
  77. * -70.0, 35.0
  78. * ]),
  79. * shapePositions : computeCircle(100000.0)
  80. * });
  81. */
  82. function PolylineVolumeOutlineGeometry(options) {
  83. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  84. var positions = options.polylinePositions;
  85. var shape = options.shapePositions;
  86. //>>includeStart('debug', pragmas.debug);
  87. if (!defined.defined(positions)) {
  88. throw new Check.DeveloperError('options.polylinePositions is required.');
  89. }
  90. if (!defined.defined(shape)) {
  91. throw new Check.DeveloperError('options.shapePositions is required.');
  92. }
  93. //>>includeEnd('debug');
  94. this._positions = positions;
  95. this._shape = shape;
  96. this._ellipsoid = Cartesian2.Ellipsoid.clone(defaultValue.defaultValue(options.ellipsoid, Cartesian2.Ellipsoid.WGS84));
  97. this._cornerType = defaultValue.defaultValue(options.cornerType, PolylineVolumeGeometryLibrary.CornerType.ROUNDED);
  98. this._granularity = defaultValue.defaultValue(options.granularity, _Math.CesiumMath.RADIANS_PER_DEGREE);
  99. this._workerName = 'createPolylineVolumeOutlineGeometry';
  100. var numComponents = 1 + positions.length * Cartesian2.Cartesian3.packedLength;
  101. numComponents += 1 + shape.length * Cartesian2.Cartesian2.packedLength;
  102. /**
  103. * The number of elements used to pack the object into an array.
  104. * @type {Number}
  105. */
  106. this.packedLength = numComponents + Cartesian2.Ellipsoid.packedLength + 2;
  107. }
  108. /**
  109. * Stores the provided instance into the provided array.
  110. *
  111. * @param {PolylineVolumeOutlineGeometry} value The value to pack.
  112. * @param {Number[]} array The array to pack into.
  113. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  114. *
  115. * @returns {Number[]} The array that was packed into
  116. */
  117. PolylineVolumeOutlineGeometry.pack = function(value, array, startingIndex) {
  118. //>>includeStart('debug', pragmas.debug);
  119. if (!defined.defined(value)) {
  120. throw new Check.DeveloperError('value is required');
  121. }
  122. if (!defined.defined(array)) {
  123. throw new Check.DeveloperError('array is required');
  124. }
  125. //>>includeEnd('debug');
  126. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  127. var i;
  128. var positions = value._positions;
  129. var length = positions.length;
  130. array[startingIndex++] = length;
  131. for (i = 0; i < length; ++i, startingIndex += Cartesian2.Cartesian3.packedLength) {
  132. Cartesian2.Cartesian3.pack(positions[i], array, startingIndex);
  133. }
  134. var shape = value._shape;
  135. length = shape.length;
  136. array[startingIndex++] = length;
  137. for (i = 0; i < length; ++i, startingIndex += Cartesian2.Cartesian2.packedLength) {
  138. Cartesian2.Cartesian2.pack(shape[i], array, startingIndex);
  139. }
  140. Cartesian2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  141. startingIndex += Cartesian2.Ellipsoid.packedLength;
  142. array[startingIndex++] = value._cornerType;
  143. array[startingIndex] = value._granularity;
  144. return array;
  145. };
  146. var scratchEllipsoid = Cartesian2.Ellipsoid.clone(Cartesian2.Ellipsoid.UNIT_SPHERE);
  147. var scratchOptions = {
  148. polylinePositions : undefined,
  149. shapePositions : undefined,
  150. ellipsoid : scratchEllipsoid,
  151. height : undefined,
  152. cornerType : undefined,
  153. granularity : undefined
  154. };
  155. /**
  156. * Retrieves an instance from a packed array.
  157. *
  158. * @param {Number[]} array The packed array.
  159. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  160. * @param {PolylineVolumeOutlineGeometry} [result] The object into which to store the result.
  161. * @returns {PolylineVolumeOutlineGeometry} The modified result parameter or a new PolylineVolumeOutlineGeometry instance if one was not provided.
  162. */
  163. PolylineVolumeOutlineGeometry.unpack = function(array, startingIndex, result) {
  164. //>>includeStart('debug', pragmas.debug);
  165. if (!defined.defined(array)) {
  166. throw new Check.DeveloperError('array is required');
  167. }
  168. //>>includeEnd('debug');
  169. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  170. var i;
  171. var length = array[startingIndex++];
  172. var positions = new Array(length);
  173. for (i = 0; i < length; ++i, startingIndex += Cartesian2.Cartesian3.packedLength) {
  174. positions[i] = Cartesian2.Cartesian3.unpack(array, startingIndex);
  175. }
  176. length = array[startingIndex++];
  177. var shape = new Array(length);
  178. for (i = 0; i < length; ++i, startingIndex += Cartesian2.Cartesian2.packedLength) {
  179. shape[i] = Cartesian2.Cartesian2.unpack(array, startingIndex);
  180. }
  181. var ellipsoid = Cartesian2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  182. startingIndex += Cartesian2.Ellipsoid.packedLength;
  183. var cornerType = array[startingIndex++];
  184. var granularity = array[startingIndex];
  185. if (!defined.defined(result)) {
  186. scratchOptions.polylinePositions = positions;
  187. scratchOptions.shapePositions = shape;
  188. scratchOptions.cornerType = cornerType;
  189. scratchOptions.granularity = granularity;
  190. return new PolylineVolumeOutlineGeometry(scratchOptions);
  191. }
  192. result._positions = positions;
  193. result._shape = shape;
  194. result._ellipsoid = Cartesian2.Ellipsoid.clone(ellipsoid, result._ellipsoid);
  195. result._cornerType = cornerType;
  196. result._granularity = granularity;
  197. return result;
  198. };
  199. var brScratch = new BoundingRectangle.BoundingRectangle();
  200. /**
  201. * Computes the geometric representation of the outline of a polyline with a volume, including its vertices, indices, and a bounding sphere.
  202. *
  203. * @param {PolylineVolumeOutlineGeometry} polylineVolumeOutlineGeometry A description of the polyline volume outline.
  204. * @returns {Geometry|undefined} The computed vertices and indices.
  205. */
  206. PolylineVolumeOutlineGeometry.createGeometry = function(polylineVolumeOutlineGeometry) {
  207. var positions = polylineVolumeOutlineGeometry._positions;
  208. var cleanPositions = arrayRemoveDuplicates.arrayRemoveDuplicates(positions, Cartesian2.Cartesian3.equalsEpsilon);
  209. var shape2D = polylineVolumeOutlineGeometry._shape;
  210. shape2D = PolylineVolumeGeometryLibrary.PolylineVolumeGeometryLibrary.removeDuplicatesFromShape(shape2D);
  211. if (cleanPositions.length < 2 || shape2D.length < 3) {
  212. return undefined;
  213. }
  214. if (PolygonPipeline.PolygonPipeline.computeWindingOrder2D(shape2D) === PolygonPipeline.WindingOrder.CLOCKWISE) {
  215. shape2D.reverse();
  216. }
  217. var boundingRectangle = BoundingRectangle.BoundingRectangle.fromPoints(shape2D, brScratch);
  218. var computedPositions = PolylineVolumeGeometryLibrary.PolylineVolumeGeometryLibrary.computePositions(cleanPositions, shape2D, boundingRectangle, polylineVolumeOutlineGeometry, false);
  219. return computeAttributes(computedPositions, shape2D);
  220. };
  221. function createPolylineVolumeOutlineGeometry(polylineVolumeOutlineGeometry, offset) {
  222. if (defined.defined(offset)) {
  223. polylineVolumeOutlineGeometry = PolylineVolumeOutlineGeometry.unpack(polylineVolumeOutlineGeometry, offset);
  224. }
  225. polylineVolumeOutlineGeometry._ellipsoid = Cartesian2.Ellipsoid.clone(polylineVolumeOutlineGeometry._ellipsoid);
  226. return PolylineVolumeOutlineGeometry.createGeometry(polylineVolumeOutlineGeometry);
  227. }
  228. return createPolylineVolumeOutlineGeometry;
  229. });