createPolygonOutlineGeometry.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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', './GeometryOffsetAttribute-cb30cd97', './GeometryInstance-72fd4e35', './arrayRemoveDuplicates-dd708d81', './EllipsoidTangentPlane-10c6053a', './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, GeometryOffsetAttribute, GeometryInstance, arrayRemoveDuplicates, EllipsoidTangentPlane, ArcType, EllipsoidRhumbLine, PolygonPipeline, PolygonGeometryLibrary) { 'use strict';
  3. var createGeometryFromPositionsPositions = [];
  4. var createGeometryFromPositionsSubdivided = [];
  5. function createGeometryFromPositions(ellipsoid, positions, minDistance, perPositionHeight, arcType) {
  6. var tangentPlane = EllipsoidTangentPlane.EllipsoidTangentPlane.fromPoints(positions, ellipsoid);
  7. var positions2D = tangentPlane.projectPointsOntoPlane(positions, createGeometryFromPositionsPositions);
  8. var originalWindingOrder = PolygonPipeline.PolygonPipeline.computeWindingOrder2D(positions2D);
  9. if (originalWindingOrder === PolygonPipeline.WindingOrder.CLOCKWISE) {
  10. positions2D.reverse();
  11. positions = positions.slice().reverse();
  12. }
  13. var subdividedPositions;
  14. var i;
  15. var length = positions.length;
  16. var index = 0;
  17. if (!perPositionHeight) {
  18. var numVertices = 0;
  19. if (arcType === ArcType.ArcType.GEODESIC) {
  20. for (i = 0; i < length; i++) {
  21. numVertices += PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideLineCount(positions[i], positions[(i + 1) % length], minDistance);
  22. }
  23. } else if (arcType === ArcType.ArcType.RHUMB) {
  24. for (i = 0; i < length; i++) {
  25. numVertices += PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideRhumbLineCount(ellipsoid, positions[i], positions[(i + 1) % length], minDistance);
  26. }
  27. }
  28. subdividedPositions = new Float64Array(numVertices * 3);
  29. for (i = 0; i < length; i++) {
  30. var tempPositions;
  31. if (arcType === ArcType.ArcType.GEODESIC) {
  32. tempPositions = PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideLine(positions[i], positions[(i + 1) % length], minDistance, createGeometryFromPositionsSubdivided);
  33. } else if (arcType === ArcType.ArcType.RHUMB) {
  34. tempPositions = PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideRhumbLine(ellipsoid, positions[i], positions[(i + 1) % length], minDistance, createGeometryFromPositionsSubdivided);
  35. }
  36. var tempPositionsLength = tempPositions.length;
  37. for (var j = 0; j < tempPositionsLength; ++j) {
  38. subdividedPositions[index++] = tempPositions[j];
  39. }
  40. }
  41. } else {
  42. subdividedPositions = new Float64Array(length * 2 * 3);
  43. for (i = 0; i < length; i++) {
  44. var p0 = positions[i];
  45. var p1 = positions[(i + 1) % length];
  46. subdividedPositions[index++] = p0.x;
  47. subdividedPositions[index++] = p0.y;
  48. subdividedPositions[index++] = p0.z;
  49. subdividedPositions[index++] = p1.x;
  50. subdividedPositions[index++] = p1.y;
  51. subdividedPositions[index++] = p1.z;
  52. }
  53. }
  54. length = subdividedPositions.length / 3;
  55. var indicesSize = length * 2;
  56. var indices = IndexDatatype.IndexDatatype.createTypedArray(length, indicesSize);
  57. index = 0;
  58. for (i = 0; i < length - 1; i++) {
  59. indices[index++] = i;
  60. indices[index++] = i + 1;
  61. }
  62. indices[index++] = length - 1;
  63. indices[index++] = 0;
  64. return new GeometryInstance.GeometryInstance({
  65. geometry : new GeometryAttribute.Geometry({
  66. attributes : new GeometryAttributes.GeometryAttributes({
  67. position : new GeometryAttribute.GeometryAttribute({
  68. componentDatatype : ComponentDatatype.ComponentDatatype.DOUBLE,
  69. componentsPerAttribute : 3,
  70. values : subdividedPositions
  71. })
  72. }),
  73. indices : indices,
  74. primitiveType : GeometryAttribute.PrimitiveType.LINES
  75. })
  76. });
  77. }
  78. function createGeometryFromPositionsExtruded(ellipsoid, positions, minDistance, perPositionHeight, arcType) {
  79. var tangentPlane = EllipsoidTangentPlane.EllipsoidTangentPlane.fromPoints(positions, ellipsoid);
  80. var positions2D = tangentPlane.projectPointsOntoPlane(positions, createGeometryFromPositionsPositions);
  81. var originalWindingOrder = PolygonPipeline.PolygonPipeline.computeWindingOrder2D(positions2D);
  82. if (originalWindingOrder === PolygonPipeline.WindingOrder.CLOCKWISE) {
  83. positions2D.reverse();
  84. positions = positions.slice().reverse();
  85. }
  86. var subdividedPositions;
  87. var i;
  88. var length = positions.length;
  89. var corners = new Array(length);
  90. var index = 0;
  91. if (!perPositionHeight) {
  92. var numVertices = 0;
  93. if (arcType === ArcType.ArcType.GEODESIC) {
  94. for (i = 0; i < length; i++) {
  95. numVertices += PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideLineCount(positions[i], positions[(i + 1) % length], minDistance);
  96. }
  97. } else if (arcType === ArcType.ArcType.RHUMB) {
  98. for (i = 0; i < length; i++) {
  99. numVertices += PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideRhumbLineCount(ellipsoid, positions[i], positions[(i + 1) % length], minDistance);
  100. }
  101. }
  102. subdividedPositions = new Float64Array(numVertices * 3 * 2);
  103. for (i = 0; i < length; ++i) {
  104. corners[i] = index / 3;
  105. var tempPositions;
  106. if (arcType === ArcType.ArcType.GEODESIC) {
  107. tempPositions = PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideLine(positions[i], positions[(i + 1) % length], minDistance, createGeometryFromPositionsSubdivided);
  108. } else if (arcType === ArcType.ArcType.RHUMB) {
  109. tempPositions = PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideRhumbLine(ellipsoid, positions[i], positions[(i + 1) % length], minDistance, createGeometryFromPositionsSubdivided);
  110. }
  111. var tempPositionsLength = tempPositions.length;
  112. for (var j = 0; j < tempPositionsLength; ++j) {
  113. subdividedPositions[index++] = tempPositions[j];
  114. }
  115. }
  116. } else {
  117. subdividedPositions = new Float64Array(length * 2 * 3 * 2);
  118. for (i = 0; i < length; ++i) {
  119. corners[i] = index / 3;
  120. var p0 = positions[i];
  121. var p1 = positions[(i + 1) % length];
  122. subdividedPositions[index++] = p0.x;
  123. subdividedPositions[index++] = p0.y;
  124. subdividedPositions[index++] = p0.z;
  125. subdividedPositions[index++] = p1.x;
  126. subdividedPositions[index++] = p1.y;
  127. subdividedPositions[index++] = p1.z;
  128. }
  129. }
  130. length = subdividedPositions.length / (3 * 2);
  131. var cornersLength = corners.length;
  132. var indicesSize = ((length * 2) + cornersLength) * 2;
  133. var indices = IndexDatatype.IndexDatatype.createTypedArray(length + cornersLength, indicesSize);
  134. index = 0;
  135. for (i = 0; i < length; ++i) {
  136. indices[index++] = i;
  137. indices[index++] = (i + 1) % length;
  138. indices[index++] = i + length;
  139. indices[index++] = ((i + 1) % length) + length;
  140. }
  141. for (i = 0; i < cornersLength; i++) {
  142. var corner = corners[i];
  143. indices[index++] = corner;
  144. indices[index++] = corner + length;
  145. }
  146. return new GeometryInstance.GeometryInstance({
  147. geometry : new GeometryAttribute.Geometry({
  148. attributes : new GeometryAttributes.GeometryAttributes({
  149. position : new GeometryAttribute.GeometryAttribute({
  150. componentDatatype : ComponentDatatype.ComponentDatatype.DOUBLE,
  151. componentsPerAttribute : 3,
  152. values : subdividedPositions
  153. })
  154. }),
  155. indices : indices,
  156. primitiveType : GeometryAttribute.PrimitiveType.LINES
  157. })
  158. });
  159. }
  160. /**
  161. * A description of the outline of a polygon on the ellipsoid. The polygon is defined by a polygon hierarchy.
  162. *
  163. * @alias PolygonOutlineGeometry
  164. * @constructor
  165. *
  166. * @param {Object} options Object with the following properties:
  167. * @param {PolygonHierarchy} options.polygonHierarchy A polygon hierarchy that can include holes.
  168. * @param {Number} [options.height=0.0] The distance in meters between the polygon and the ellipsoid surface.
  169. * @param {Number} [options.extrudedHeight] The distance in meters between the polygon's extruded face and the ellipsoid surface.
  170. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  171. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.
  172. * @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.
  173. * @param {Boolean} [options.perPositionHeight=false] Use the height of options.positions for each position instead of using options.height to determine the height.
  174. * @param {ArcType} [options.arcType=ArcType.GEODESIC] The type of path the outline must follow. Valid options are {@link ArcType.GEODESIC} and {@link ArcType.RHUMB}.
  175. *
  176. * @see PolygonOutlineGeometry#createGeometry
  177. * @see PolygonOutlineGeometry#fromPositions
  178. *
  179. * @example
  180. * // 1. create a polygon outline from points
  181. * var polygon = new Cesium.PolygonOutlineGeometry({
  182. * polygonHierarchy : new Cesium.PolygonHierarchy(
  183. * Cesium.Cartesian3.fromDegreesArray([
  184. * -72.0, 40.0,
  185. * -70.0, 35.0,
  186. * -75.0, 30.0,
  187. * -70.0, 30.0,
  188. * -68.0, 40.0
  189. * ])
  190. * )
  191. * });
  192. * var geometry = Cesium.PolygonOutlineGeometry.createGeometry(polygon);
  193. *
  194. * // 2. create a nested polygon with holes outline
  195. * var polygonWithHole = new Cesium.PolygonOutlineGeometry({
  196. * polygonHierarchy : new Cesium.PolygonHierarchy(
  197. * Cesium.Cartesian3.fromDegreesArray([
  198. * -109.0, 30.0,
  199. * -95.0, 30.0,
  200. * -95.0, 40.0,
  201. * -109.0, 40.0
  202. * ]),
  203. * [new Cesium.PolygonHierarchy(
  204. * Cesium.Cartesian3.fromDegreesArray([
  205. * -107.0, 31.0,
  206. * -107.0, 39.0,
  207. * -97.0, 39.0,
  208. * -97.0, 31.0
  209. * ]),
  210. * [new Cesium.PolygonHierarchy(
  211. * Cesium.Cartesian3.fromDegreesArray([
  212. * -105.0, 33.0,
  213. * -99.0, 33.0,
  214. * -99.0, 37.0,
  215. * -105.0, 37.0
  216. * ]),
  217. * [new Cesium.PolygonHierarchy(
  218. * Cesium.Cartesian3.fromDegreesArray([
  219. * -103.0, 34.0,
  220. * -101.0, 34.0,
  221. * -101.0, 36.0,
  222. * -103.0, 36.0
  223. * ])
  224. * )]
  225. * )]
  226. * )]
  227. * )
  228. * });
  229. * var geometry = Cesium.PolygonOutlineGeometry.createGeometry(polygonWithHole);
  230. *
  231. * // 3. create extruded polygon outline
  232. * var extrudedPolygon = new Cesium.PolygonOutlineGeometry({
  233. * polygonHierarchy : new Cesium.PolygonHierarchy(
  234. * Cesium.Cartesian3.fromDegreesArray([
  235. * -72.0, 40.0,
  236. * -70.0, 35.0,
  237. * -75.0, 30.0,
  238. * -70.0, 30.0,
  239. * -68.0, 40.0
  240. * ])
  241. * ),
  242. * extrudedHeight: 300000
  243. * });
  244. * var geometry = Cesium.PolygonOutlineGeometry.createGeometry(extrudedPolygon);
  245. */
  246. function PolygonOutlineGeometry(options) {
  247. //>>includeStart('debug', pragmas.debug);
  248. Check.Check.typeOf.object('options', options);
  249. Check.Check.typeOf.object('options.polygonHierarchy', options.polygonHierarchy);
  250. if (options.perPositionHeight && defined.defined(options.height)) {
  251. throw new Check.DeveloperError('Cannot use both options.perPositionHeight and options.height');
  252. }
  253. if (defined.defined(options.arcType) && options.arcType !== ArcType.ArcType.GEODESIC && options.arcType !== ArcType.ArcType.RHUMB) {
  254. throw new Check.DeveloperError('Invalid arcType. Valid options are ArcType.GEODESIC and ArcType.RHUMB.');
  255. }
  256. //>>includeEnd('debug');
  257. var polygonHierarchy = options.polygonHierarchy;
  258. var ellipsoid = defaultValue.defaultValue(options.ellipsoid, Cartesian2.Ellipsoid.WGS84);
  259. var granularity = defaultValue.defaultValue(options.granularity, _Math.CesiumMath.RADIANS_PER_DEGREE);
  260. var perPositionHeight = defaultValue.defaultValue(options.perPositionHeight, false);
  261. var perPositionHeightExtrude = perPositionHeight && defined.defined(options.extrudedHeight);
  262. var arcType = defaultValue.defaultValue(options.arcType, ArcType.ArcType.GEODESIC);
  263. var height = defaultValue.defaultValue(options.height, 0.0);
  264. var extrudedHeight = defaultValue.defaultValue(options.extrudedHeight, height);
  265. if (!perPositionHeightExtrude) {
  266. var h = Math.max(height, extrudedHeight);
  267. extrudedHeight = Math.min(height, extrudedHeight);
  268. height = h;
  269. }
  270. this._ellipsoid = Cartesian2.Ellipsoid.clone(ellipsoid);
  271. this._granularity = granularity;
  272. this._height = height;
  273. this._extrudedHeight = extrudedHeight;
  274. this._arcType = arcType;
  275. this._polygonHierarchy = polygonHierarchy;
  276. this._perPositionHeight = perPositionHeight;
  277. this._perPositionHeightExtrude = perPositionHeightExtrude;
  278. this._offsetAttribute = options.offsetAttribute;
  279. this._workerName = 'createPolygonOutlineGeometry';
  280. /**
  281. * The number of elements used to pack the object into an array.
  282. * @type {Number}
  283. */
  284. this.packedLength = PolygonGeometryLibrary.PolygonGeometryLibrary.computeHierarchyPackedLength(polygonHierarchy) + Cartesian2.Ellipsoid.packedLength + 8;
  285. }
  286. /**
  287. * Stores the provided instance into the provided array.
  288. *
  289. * @param {PolygonOutlineGeometry} value The value to pack.
  290. * @param {Number[]} array The array to pack into.
  291. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  292. *
  293. * @returns {Number[]} The array that was packed into
  294. */
  295. PolygonOutlineGeometry.pack = function(value, array, startingIndex) {
  296. //>>includeStart('debug', pragmas.debug);
  297. Check.Check.typeOf.object('value', value);
  298. Check.Check.defined('array', array);
  299. //>>includeEnd('debug');
  300. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  301. startingIndex = PolygonGeometryLibrary.PolygonGeometryLibrary.packPolygonHierarchy(value._polygonHierarchy, array, startingIndex);
  302. Cartesian2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  303. startingIndex += Cartesian2.Ellipsoid.packedLength;
  304. array[startingIndex++] = value._height;
  305. array[startingIndex++] = value._extrudedHeight;
  306. array[startingIndex++] = value._granularity;
  307. array[startingIndex++] = value._perPositionHeightExtrude ? 1.0 : 0.0;
  308. array[startingIndex++] = value._perPositionHeight ? 1.0 : 0.0;
  309. array[startingIndex++] = value._arcType;
  310. array[startingIndex++] = defaultValue.defaultValue(value._offsetAttribute, -1);
  311. array[startingIndex] = value.packedLength;
  312. return array;
  313. };
  314. var scratchEllipsoid = Cartesian2.Ellipsoid.clone(Cartesian2.Ellipsoid.UNIT_SPHERE);
  315. var dummyOptions = {
  316. polygonHierarchy : {}
  317. };
  318. /**
  319. * Retrieves an instance from a packed array.
  320. *
  321. * @param {Number[]} array The packed array.
  322. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  323. * @param {PolygonOutlineGeometry} [result] The object into which to store the result.
  324. * @returns {PolygonOutlineGeometry} The modified result parameter or a new PolygonOutlineGeometry instance if one was not provided.
  325. */
  326. PolygonOutlineGeometry.unpack = function(array, startingIndex, result) {
  327. //>>includeStart('debug', pragmas.debug);
  328. Check.Check.defined('array', array);
  329. //>>includeEnd('debug');
  330. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  331. var polygonHierarchy = PolygonGeometryLibrary.PolygonGeometryLibrary.unpackPolygonHierarchy(array, startingIndex);
  332. startingIndex = polygonHierarchy.startingIndex;
  333. delete polygonHierarchy.startingIndex;
  334. var ellipsoid = Cartesian2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  335. startingIndex += Cartesian2.Ellipsoid.packedLength;
  336. var height = array[startingIndex++];
  337. var extrudedHeight = array[startingIndex++];
  338. var granularity = array[startingIndex++];
  339. var perPositionHeightExtrude = array[startingIndex++] === 1.0;
  340. var perPositionHeight = array[startingIndex++] === 1.0;
  341. var arcType = array[startingIndex++];
  342. var offsetAttribute = array[startingIndex++];
  343. var packedLength = array[startingIndex];
  344. if (!defined.defined(result)) {
  345. result = new PolygonOutlineGeometry(dummyOptions);
  346. }
  347. result._polygonHierarchy = polygonHierarchy;
  348. result._ellipsoid = Cartesian2.Ellipsoid.clone(ellipsoid, result._ellipsoid);
  349. result._height = height;
  350. result._extrudedHeight = extrudedHeight;
  351. result._granularity = granularity;
  352. result._perPositionHeight = perPositionHeight;
  353. result._perPositionHeightExtrude = perPositionHeightExtrude;
  354. result._arcType = arcType;
  355. result._offsetAttribute = offsetAttribute === -1 ? undefined : offsetAttribute;
  356. result.packedLength = packedLength;
  357. return result;
  358. };
  359. /**
  360. * A description of a polygon outline from an array of positions.
  361. *
  362. * @param {Object} options Object with the following properties:
  363. * @param {Cartesian3[]} options.positions An array of positions that defined the corner points of the polygon.
  364. * @param {Number} [options.height=0.0] The height of the polygon.
  365. * @param {Number} [options.extrudedHeight] The height of the polygon extrusion.
  366. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.
  367. * @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.
  368. * @param {Boolean} [options.perPositionHeight=false] Use the height of options.positions for each position instead of using options.height to determine the height.
  369. * @param {ArcType} [options.arcType=ArcType.GEODESIC] The type of path the outline must follow. Valid options are {@link LinkType.GEODESIC} and {@link ArcType.RHUMB}.
  370. * @returns {PolygonOutlineGeometry}
  371. *
  372. *
  373. * @example
  374. * // create a polygon from points
  375. * var polygon = Cesium.PolygonOutlineGeometry.fromPositions({
  376. * positions : Cesium.Cartesian3.fromDegreesArray([
  377. * -72.0, 40.0,
  378. * -70.0, 35.0,
  379. * -75.0, 30.0,
  380. * -70.0, 30.0,
  381. * -68.0, 40.0
  382. * ])
  383. * });
  384. * var geometry = Cesium.PolygonOutlineGeometry.createGeometry(polygon);
  385. *
  386. * @see PolygonOutlineGeometry#createGeometry
  387. */
  388. PolygonOutlineGeometry.fromPositions = function(options) {
  389. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  390. //>>includeStart('debug', pragmas.debug);
  391. Check.Check.defined('options.positions', options.positions);
  392. //>>includeEnd('debug');
  393. var newOptions = {
  394. polygonHierarchy : {
  395. positions : options.positions
  396. },
  397. height : options.height,
  398. extrudedHeight : options.extrudedHeight,
  399. ellipsoid : options.ellipsoid,
  400. granularity : options.granularity,
  401. perPositionHeight : options.perPositionHeight,
  402. arcType: options.arcType,
  403. offsetAttribute : options.offsetAttribute
  404. };
  405. return new PolygonOutlineGeometry(newOptions);
  406. };
  407. /**
  408. * Computes the geometric representation of a polygon outline, including its vertices, indices, and a bounding sphere.
  409. *
  410. * @param {PolygonOutlineGeometry} polygonGeometry A description of the polygon outline.
  411. * @returns {Geometry|undefined} The computed vertices and indices.
  412. */
  413. PolygonOutlineGeometry.createGeometry = function(polygonGeometry) {
  414. var ellipsoid = polygonGeometry._ellipsoid;
  415. var granularity = polygonGeometry._granularity;
  416. var polygonHierarchy = polygonGeometry._polygonHierarchy;
  417. var perPositionHeight = polygonGeometry._perPositionHeight;
  418. var arcType = polygonGeometry._arcType;
  419. var polygons = PolygonGeometryLibrary.PolygonGeometryLibrary.polygonOutlinesFromHierarchy(polygonHierarchy, !perPositionHeight, ellipsoid);
  420. if (polygons.length === 0) {
  421. return undefined;
  422. }
  423. var geometryInstance;
  424. var geometries = [];
  425. var minDistance = _Math.CesiumMath.chordLength(granularity, ellipsoid.maximumRadius);
  426. var height = polygonGeometry._height;
  427. var extrudedHeight = polygonGeometry._extrudedHeight;
  428. var extrude = polygonGeometry._perPositionHeightExtrude || !_Math.CesiumMath.equalsEpsilon(height, extrudedHeight, 0, _Math.CesiumMath.EPSILON2);
  429. var offsetValue;
  430. var i;
  431. if (extrude) {
  432. for (i = 0; i < polygons.length; i++) {
  433. geometryInstance = createGeometryFromPositionsExtruded(ellipsoid, polygons[i], minDistance, perPositionHeight, arcType);
  434. geometryInstance.geometry = PolygonGeometryLibrary.PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(geometryInstance.geometry, height, extrudedHeight, ellipsoid, perPositionHeight);
  435. if (defined.defined(polygonGeometry._offsetAttribute)) {
  436. var size = geometryInstance.geometry.attributes.position.values.length / 3;
  437. var offsetAttribute = new Uint8Array(size);
  438. if (polygonGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.TOP) {
  439. offsetAttribute = GeometryOffsetAttribute.arrayFill(offsetAttribute, 1, 0, size / 2);
  440. } else {
  441. offsetValue = polygonGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE ? 0 : 1;
  442. offsetAttribute = GeometryOffsetAttribute.arrayFill(offsetAttribute, offsetValue);
  443. }
  444. geometryInstance.geometry.attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  445. componentDatatype : ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  446. componentsPerAttribute : 1,
  447. values : offsetAttribute
  448. });
  449. }
  450. geometries.push(geometryInstance);
  451. }
  452. } else {
  453. for (i = 0; i < polygons.length; i++) {
  454. geometryInstance = createGeometryFromPositions(ellipsoid, polygons[i], minDistance, perPositionHeight, arcType);
  455. geometryInstance.geometry.attributes.position.values = PolygonPipeline.PolygonPipeline.scaleToGeodeticHeight(geometryInstance.geometry.attributes.position.values, height, ellipsoid, !perPositionHeight);
  456. if (defined.defined(polygonGeometry._offsetAttribute)) {
  457. var length = geometryInstance.geometry.attributes.position.values.length;
  458. var applyOffset = new Uint8Array(length / 3);
  459. offsetValue = polygonGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE ? 0 : 1;
  460. GeometryOffsetAttribute.arrayFill(applyOffset, offsetValue);
  461. geometryInstance.geometry.attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  462. componentDatatype : ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  463. componentsPerAttribute : 1,
  464. values: applyOffset
  465. });
  466. }
  467. geometries.push(geometryInstance);
  468. }
  469. }
  470. var geometry = GeometryPipeline.GeometryPipeline.combineInstances(geometries)[0];
  471. var boundingSphere = Transforms.BoundingSphere.fromVertices(geometry.attributes.position.values);
  472. return new GeometryAttribute.Geometry({
  473. attributes : geometry.attributes,
  474. indices : geometry.indices,
  475. primitiveType : geometry.primitiveType,
  476. boundingSphere : boundingSphere,
  477. offsetAttribute : polygonGeometry._offsetAttribute
  478. });
  479. };
  480. function createPolygonOutlineGeometry(polygonGeometry, offset) {
  481. if (defined.defined(offset)) {
  482. polygonGeometry = PolygonOutlineGeometry.unpack(polygonGeometry, offset);
  483. }
  484. polygonGeometry._ellipsoid = Cartesian2.Ellipsoid.clone(polygonGeometry._ellipsoid);
  485. return PolygonOutlineGeometry.createGeometry(polygonGeometry);
  486. }
  487. return createPolygonOutlineGeometry;
  488. });