createCoplanarPolygonOutlineGeometry.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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', './AttributeCompression-87682214', './GeometryPipeline-f0b16df6', './EncodedCartesian3-8b2b90d0', './IndexDatatype-3de60176', './IntersectionTests-c2360ffa', './Plane-a1a3fd52', './GeometryInstance-72fd4e35', './arrayRemoveDuplicates-dd708d81', './EllipsoidTangentPlane-10c6053a', './OrientedBoundingBox-a786ab5d', './CoplanarPolygonGeometryLibrary-602752f0', './ArcType-d521909b', './EllipsoidRhumbLine-c6cdbfd3', './PolygonPipeline-e486c11c', './PolygonGeometryLibrary-7f7b74b5'], function (defined, Check, freezeObject, defaultValue, _Math, Cartesian2, defineProperties, Transforms, RuntimeError, WebGLConstants, ComponentDatatype, GeometryAttribute, when, GeometryAttributes, AttributeCompression, GeometryPipeline, EncodedCartesian3, IndexDatatype, IntersectionTests, Plane, GeometryInstance, arrayRemoveDuplicates, EllipsoidTangentPlane, OrientedBoundingBox, CoplanarPolygonGeometryLibrary, ArcType, EllipsoidRhumbLine, PolygonPipeline, PolygonGeometryLibrary) { 'use strict';
  3. function createGeometryFromPositions(positions){
  4. var length = positions.length;
  5. var flatPositions = new Float64Array(length * 3);
  6. var indices = IndexDatatype.IndexDatatype.createTypedArray(length, length * 2);
  7. var positionIndex = 0;
  8. var index = 0;
  9. for (var i = 0; i < length; i++) {
  10. var position = positions[i];
  11. flatPositions[positionIndex++] = position.x;
  12. flatPositions[positionIndex++] = position.y;
  13. flatPositions[positionIndex++] = position.z;
  14. indices[index++] = i;
  15. indices[index++] = (i + 1) % length;
  16. }
  17. var attributes = new GeometryAttributes.GeometryAttributes({
  18. position: new GeometryAttribute.GeometryAttribute({
  19. componentDatatype : ComponentDatatype.ComponentDatatype.DOUBLE,
  20. componentsPerAttribute : 3,
  21. values : flatPositions
  22. })
  23. });
  24. return new GeometryAttribute.Geometry({
  25. attributes : attributes,
  26. indices : indices,
  27. primitiveType : GeometryAttribute.PrimitiveType.LINES
  28. });
  29. }
  30. /**
  31. * A description of the outline of a polygon composed of arbitrary coplanar positions.
  32. *
  33. * @alias CoplanarPolygonOutlineGeometry
  34. * @constructor
  35. *
  36. * @param {Object} options Object with the following properties:
  37. * @param {PolygonHierarchy} options.polygonHierarchy A polygon hierarchy that can include holes.
  38. *
  39. * @see CoplanarPolygonOutlineGeometry.createGeometry
  40. *
  41. * @example
  42. * var polygonOutline = new Cesium.CoplanarPolygonOutlineGeometry({
  43. * positions : Cesium.Cartesian3.fromDegreesArrayHeights([
  44. * -90.0, 30.0, 0.0,
  45. * -90.0, 30.0, 1000.0,
  46. * -80.0, 30.0, 1000.0,
  47. * -80.0, 30.0, 0.0
  48. * ])
  49. * });
  50. * var geometry = Cesium.CoplanarPolygonOutlineGeometry.createGeometry(polygonOutline);
  51. */
  52. function CoplanarPolygonOutlineGeometry(options) {
  53. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  54. var polygonHierarchy = options.polygonHierarchy;
  55. //>>includeStart('debug', pragmas.debug);
  56. Check.Check.defined('options.polygonHierarchy', polygonHierarchy);
  57. //>>includeEnd('debug');
  58. this._polygonHierarchy = polygonHierarchy;
  59. this._workerName = 'createCoplanarPolygonOutlineGeometry';
  60. /**
  61. * The number of elements used to pack the object into an array.
  62. * @type {Number}
  63. */
  64. this.packedLength = PolygonGeometryLibrary.PolygonGeometryLibrary.computeHierarchyPackedLength(polygonHierarchy) + 1;
  65. }
  66. /**
  67. * A description of a coplanar polygon outline from an array of positions.
  68. *
  69. * @param {Object} options Object with the following properties:
  70. * @param {Cartesian3[]} options.positions An array of positions that defined the corner points of the polygon.
  71. * @returns {CoplanarPolygonOutlineGeometry}
  72. */
  73. CoplanarPolygonOutlineGeometry.fromPositions = function(options) {
  74. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  75. //>>includeStart('debug', pragmas.debug);
  76. Check.Check.defined('options.positions', options.positions);
  77. //>>includeEnd('debug');
  78. var newOptions = {
  79. polygonHierarchy : {
  80. positions : options.positions
  81. }
  82. };
  83. return new CoplanarPolygonOutlineGeometry(newOptions);
  84. };
  85. /**
  86. * Stores the provided instance into the provided array.
  87. *
  88. * @param {CoplanarPolygonOutlineGeometry} value The value to pack.
  89. * @param {Number[]} array The array to pack into.
  90. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  91. *
  92. * @returns {Number[]} The array that was packed into
  93. */
  94. CoplanarPolygonOutlineGeometry.pack = function(value, array, startingIndex) {
  95. //>>includeStart('debug', pragmas.debug);
  96. Check.Check.typeOf.object('value', value);
  97. Check.Check.defined('array', array);
  98. //>>includeEnd('debug');
  99. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  100. startingIndex = PolygonGeometryLibrary.PolygonGeometryLibrary.packPolygonHierarchy(value._polygonHierarchy, array, startingIndex);
  101. array[startingIndex] = value.packedLength;
  102. return array;
  103. };
  104. var scratchOptions = {
  105. polygonHierarchy : {}
  106. };
  107. /**
  108. * Retrieves an instance from a packed array.
  109. *
  110. * @param {Number[]} array The packed array.
  111. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  112. * @param {CoplanarPolygonOutlineGeometry} [result] The object into which to store the result.
  113. * @returns {CoplanarPolygonOutlineGeometry} The modified result parameter or a new CoplanarPolygonOutlineGeometry instance if one was not provided.
  114. */
  115. CoplanarPolygonOutlineGeometry.unpack = function(array, startingIndex, result) {
  116. //>>includeStart('debug', pragmas.debug);
  117. Check.Check.defined('array', array);
  118. //>>includeEnd('debug');
  119. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  120. var polygonHierarchy = PolygonGeometryLibrary.PolygonGeometryLibrary.unpackPolygonHierarchy(array, startingIndex);
  121. startingIndex = polygonHierarchy.startingIndex;
  122. delete polygonHierarchy.startingIndex;
  123. var packedLength = array[startingIndex];
  124. if (!defined.defined(result)) {
  125. result = new CoplanarPolygonOutlineGeometry(scratchOptions);
  126. }
  127. result._polygonHierarchy = polygonHierarchy;
  128. result.packedLength = packedLength;
  129. return result;
  130. };
  131. /**
  132. * Computes the geometric representation of an arbitrary coplanar polygon, including its vertices, indices, and a bounding sphere.
  133. *
  134. * @param {CoplanarPolygonOutlineGeometry} polygonGeometry A description of the polygon.
  135. * @returns {Geometry|undefined} The computed vertices and indices.
  136. */
  137. CoplanarPolygonOutlineGeometry.createGeometry = function(polygonGeometry) {
  138. var polygonHierarchy = polygonGeometry._polygonHierarchy;
  139. var outerPositions = polygonHierarchy.positions;
  140. outerPositions = arrayRemoveDuplicates.arrayRemoveDuplicates(outerPositions, Cartesian2.Cartesian3.equalsEpsilon, true);
  141. if (outerPositions.length < 3) {
  142. return;
  143. }
  144. var isValid = CoplanarPolygonGeometryLibrary.CoplanarPolygonGeometryLibrary.validOutline(outerPositions);
  145. if (!isValid) {
  146. return undefined;
  147. }
  148. var polygons = PolygonGeometryLibrary.PolygonGeometryLibrary.polygonOutlinesFromHierarchy(polygonHierarchy, false);
  149. if (polygons.length === 0) {
  150. return undefined;
  151. }
  152. var geometries = [];
  153. for (var i = 0; i < polygons.length; i++) {
  154. var geometryInstance = new GeometryInstance.GeometryInstance({
  155. geometry : createGeometryFromPositions(polygons[i])
  156. });
  157. geometries.push(geometryInstance);
  158. }
  159. var geometry = GeometryPipeline.GeometryPipeline.combineInstances(geometries)[0];
  160. var boundingSphere = Transforms.BoundingSphere.fromPoints(polygonHierarchy.positions);
  161. return new GeometryAttribute.Geometry({
  162. attributes : geometry.attributes,
  163. indices : geometry.indices,
  164. primitiveType : geometry.primitiveType,
  165. boundingSphere : boundingSphere
  166. });
  167. };
  168. function createCoplanarPolygonOutlineGeometry(polygonGeometry, offset) {
  169. if (defined.defined(offset)) {
  170. polygonGeometry = CoplanarPolygonOutlineGeometry.unpack(polygonGeometry, offset);
  171. }
  172. polygonGeometry._ellipsoid = Cartesian2.Ellipsoid.clone(polygonGeometry._ellipsoid);
  173. return CoplanarPolygonOutlineGeometry.createGeometry(polygonGeometry);
  174. }
  175. return createCoplanarPolygonOutlineGeometry;
  176. });