createWallGeometry.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./when-e6985d2a', './Check-24cae389', './Math-392d0035', './Cartesian2-a5d6dde9', './Transforms-81680c41', './RuntimeError-61701d3e', './WebGLConstants-34c08bc0', './ComponentDatatype-cb08e294', './GeometryAttribute-6d403cd9', './GeometryAttributes-d6ea8c2b', './IndexDatatype-1be7d1f8', './IntersectionTests-f17c84f0', './Plane-ac6a1d3e', './VertexFormat-2df57ea4', './arrayRemoveDuplicates-1ded18d8', './EllipsoidRhumbLine-5f1ab81f', './EllipsoidGeodesic-2a1a77d2', './PolylinePipeline-0b5c8621', './WallGeometryLibrary-98d10a0a'], function (when, Check, _Math, Cartesian2, Transforms, RuntimeError, WebGLConstants, ComponentDatatype, GeometryAttribute, GeometryAttributes, IndexDatatype, IntersectionTests, Plane, VertexFormat, arrayRemoveDuplicates, EllipsoidRhumbLine, EllipsoidGeodesic, PolylinePipeline, WallGeometryLibrary) { 'use strict';
  3. var scratchCartesian3Position1 = new Cartesian2.Cartesian3();
  4. var scratchCartesian3Position2 = new Cartesian2.Cartesian3();
  5. var scratchCartesian3Position4 = new Cartesian2.Cartesian3();
  6. var scratchCartesian3Position5 = new Cartesian2.Cartesian3();
  7. var scratchBitangent = new Cartesian2.Cartesian3();
  8. var scratchTangent = new Cartesian2.Cartesian3();
  9. var scratchNormal = new Cartesian2.Cartesian3();
  10. /**
  11. * A description of a wall, which is similar to a KML line string. A wall is defined by a series of points,
  12. * which extrude down to the ground. Optionally, they can extrude downwards to a specified height.
  13. *
  14. * @alias WallGeometry
  15. * @constructor
  16. *
  17. * @param {Object} options Object with the following properties:
  18. * @param {Cartesian3[]} options.positions An array of Cartesian objects, which are the points of the wall.
  19. * @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.
  20. * @param {Number[]} [options.maximumHeights] An array parallel to <code>positions</code> that give the maximum height of the
  21. * wall at <code>positions</code>. If undefined, the height of each position in used.
  22. * @param {Number[]} [options.minimumHeights] An array parallel to <code>positions</code> that give the minimum height of the
  23. * wall at <code>positions</code>. If undefined, the height at each position is 0.0.
  24. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for coordinate manipulation
  25. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  26. *
  27. * @exception {DeveloperError} positions length must be greater than or equal to 2.
  28. * @exception {DeveloperError} positions and maximumHeights must have the same length.
  29. * @exception {DeveloperError} positions and minimumHeights must have the same length.
  30. *
  31. * @see WallGeometry#createGeometry
  32. * @see WallGeometry#fromConstantHeight
  33. *
  34. * @demo {@link https://sandcastle.cesium.com/index.html?src=Wall.html|Cesium Sandcastle Wall Demo}
  35. *
  36. * @example
  37. * // create a wall that spans from ground level to 10000 meters
  38. * var wall = new Cesium.WallGeometry({
  39. * positions : Cesium.Cartesian3.fromDegreesArrayHeights([
  40. * 19.0, 47.0, 10000.0,
  41. * 19.0, 48.0, 10000.0,
  42. * 20.0, 48.0, 10000.0,
  43. * 20.0, 47.0, 10000.0,
  44. * 19.0, 47.0, 10000.0
  45. * ])
  46. * });
  47. * var geometry = Cesium.WallGeometry.createGeometry(wall);
  48. */
  49. function WallGeometry(options) {
  50. options = when.defaultValue(options, when.defaultValue.EMPTY_OBJECT);
  51. var wallPositions = options.positions;
  52. var maximumHeights = options.maximumHeights;
  53. var minimumHeights = options.minimumHeights;
  54. //>>includeStart('debug', pragmas.debug);
  55. if (!when.defined(wallPositions)) {
  56. throw new Check.DeveloperError("options.positions is required.");
  57. }
  58. if (
  59. when.defined(maximumHeights) &&
  60. maximumHeights.length !== wallPositions.length
  61. ) {
  62. throw new Check.DeveloperError(
  63. "options.positions and options.maximumHeights must have the same length."
  64. );
  65. }
  66. if (
  67. when.defined(minimumHeights) &&
  68. minimumHeights.length !== wallPositions.length
  69. ) {
  70. throw new Check.DeveloperError(
  71. "options.positions and options.minimumHeights must have the same length."
  72. );
  73. }
  74. //>>includeEnd('debug');
  75. var vertexFormat = when.defaultValue(options.vertexFormat, VertexFormat.VertexFormat.DEFAULT);
  76. var granularity = when.defaultValue(
  77. options.granularity,
  78. _Math.CesiumMath.RADIANS_PER_DEGREE
  79. );
  80. var ellipsoid = when.defaultValue(options.ellipsoid, Cartesian2.Ellipsoid.WGS84);
  81. this._positions = wallPositions;
  82. this._minimumHeights = minimumHeights;
  83. this._maximumHeights = maximumHeights;
  84. this._vertexFormat = VertexFormat.VertexFormat.clone(vertexFormat);
  85. this._granularity = granularity;
  86. this._ellipsoid = Cartesian2.Ellipsoid.clone(ellipsoid);
  87. this._workerName = "createWallGeometry";
  88. var numComponents = 1 + wallPositions.length * Cartesian2.Cartesian3.packedLength + 2;
  89. if (when.defined(minimumHeights)) {
  90. numComponents += minimumHeights.length;
  91. }
  92. if (when.defined(maximumHeights)) {
  93. numComponents += maximumHeights.length;
  94. }
  95. /**
  96. * The number of elements used to pack the object into an array.
  97. * @type {Number}
  98. */
  99. this.packedLength =
  100. numComponents + Cartesian2.Ellipsoid.packedLength + VertexFormat.VertexFormat.packedLength + 1;
  101. }
  102. /**
  103. * Stores the provided instance into the provided array.
  104. *
  105. * @param {WallGeometry} value The value to pack.
  106. * @param {Number[]} array The array to pack into.
  107. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  108. *
  109. * @returns {Number[]} The array that was packed into
  110. */
  111. WallGeometry.pack = function (value, array, startingIndex) {
  112. //>>includeStart('debug', pragmas.debug);
  113. if (!when.defined(value)) {
  114. throw new Check.DeveloperError("value is required");
  115. }
  116. if (!when.defined(array)) {
  117. throw new Check.DeveloperError("array is required");
  118. }
  119. //>>includeEnd('debug');
  120. startingIndex = when.defaultValue(startingIndex, 0);
  121. var i;
  122. var positions = value._positions;
  123. var length = positions.length;
  124. array[startingIndex++] = length;
  125. for (i = 0; i < length; ++i, startingIndex += Cartesian2.Cartesian3.packedLength) {
  126. Cartesian2.Cartesian3.pack(positions[i], array, startingIndex);
  127. }
  128. var minimumHeights = value._minimumHeights;
  129. length = when.defined(minimumHeights) ? minimumHeights.length : 0;
  130. array[startingIndex++] = length;
  131. if (when.defined(minimumHeights)) {
  132. for (i = 0; i < length; ++i) {
  133. array[startingIndex++] = minimumHeights[i];
  134. }
  135. }
  136. var maximumHeights = value._maximumHeights;
  137. length = when.defined(maximumHeights) ? maximumHeights.length : 0;
  138. array[startingIndex++] = length;
  139. if (when.defined(maximumHeights)) {
  140. for (i = 0; i < length; ++i) {
  141. array[startingIndex++] = maximumHeights[i];
  142. }
  143. }
  144. Cartesian2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  145. startingIndex += Cartesian2.Ellipsoid.packedLength;
  146. VertexFormat.VertexFormat.pack(value._vertexFormat, array, startingIndex);
  147. startingIndex += VertexFormat.VertexFormat.packedLength;
  148. array[startingIndex] = value._granularity;
  149. return array;
  150. };
  151. var scratchEllipsoid = Cartesian2.Ellipsoid.clone(Cartesian2.Ellipsoid.UNIT_SPHERE);
  152. var scratchVertexFormat = new VertexFormat.VertexFormat();
  153. var scratchOptions = {
  154. positions: undefined,
  155. minimumHeights: undefined,
  156. maximumHeights: undefined,
  157. ellipsoid: scratchEllipsoid,
  158. vertexFormat: scratchVertexFormat,
  159. granularity: undefined,
  160. };
  161. /**
  162. * Retrieves an instance from a packed array.
  163. *
  164. * @param {Number[]} array The packed array.
  165. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  166. * @param {WallGeometry} [result] The object into which to store the result.
  167. * @returns {WallGeometry} The modified result parameter or a new WallGeometry instance if one was not provided.
  168. */
  169. WallGeometry.unpack = function (array, startingIndex, result) {
  170. //>>includeStart('debug', pragmas.debug);
  171. if (!when.defined(array)) {
  172. throw new Check.DeveloperError("array is required");
  173. }
  174. //>>includeEnd('debug');
  175. startingIndex = when.defaultValue(startingIndex, 0);
  176. var i;
  177. var length = array[startingIndex++];
  178. var positions = new Array(length);
  179. for (i = 0; i < length; ++i, startingIndex += Cartesian2.Cartesian3.packedLength) {
  180. positions[i] = Cartesian2.Cartesian3.unpack(array, startingIndex);
  181. }
  182. length = array[startingIndex++];
  183. var minimumHeights;
  184. if (length > 0) {
  185. minimumHeights = new Array(length);
  186. for (i = 0; i < length; ++i) {
  187. minimumHeights[i] = array[startingIndex++];
  188. }
  189. }
  190. length = array[startingIndex++];
  191. var maximumHeights;
  192. if (length > 0) {
  193. maximumHeights = new Array(length);
  194. for (i = 0; i < length; ++i) {
  195. maximumHeights[i] = array[startingIndex++];
  196. }
  197. }
  198. var ellipsoid = Cartesian2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  199. startingIndex += Cartesian2.Ellipsoid.packedLength;
  200. var vertexFormat = VertexFormat.VertexFormat.unpack(
  201. array,
  202. startingIndex,
  203. scratchVertexFormat
  204. );
  205. startingIndex += VertexFormat.VertexFormat.packedLength;
  206. var granularity = array[startingIndex];
  207. if (!when.defined(result)) {
  208. scratchOptions.positions = positions;
  209. scratchOptions.minimumHeights = minimumHeights;
  210. scratchOptions.maximumHeights = maximumHeights;
  211. scratchOptions.granularity = granularity;
  212. return new WallGeometry(scratchOptions);
  213. }
  214. result._positions = positions;
  215. result._minimumHeights = minimumHeights;
  216. result._maximumHeights = maximumHeights;
  217. result._ellipsoid = Cartesian2.Ellipsoid.clone(ellipsoid, result._ellipsoid);
  218. result._vertexFormat = VertexFormat.VertexFormat.clone(vertexFormat, result._vertexFormat);
  219. result._granularity = granularity;
  220. return result;
  221. };
  222. /**
  223. * A description of a wall, which is similar to a KML line string. A wall is defined by a series of points,
  224. * which extrude down to the ground. Optionally, they can extrude downwards to a specified height.
  225. *
  226. * @param {Object} options Object with the following properties:
  227. * @param {Cartesian3[]} options.positions An array of Cartesian objects, which are the points of the wall.
  228. * @param {Number} [options.maximumHeight] A constant that defines the maximum height of the
  229. * wall at <code>positions</code>. If undefined, the height of each position in used.
  230. * @param {Number} [options.minimumHeight] A constant that defines the minimum height of the
  231. * wall at <code>positions</code>. If undefined, the height at each position is 0.0.
  232. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for coordinate manipulation
  233. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  234. * @returns {WallGeometry}
  235. *
  236. *
  237. * @example
  238. * // create a wall that spans from 10000 meters to 20000 meters
  239. * var wall = Cesium.WallGeometry.fromConstantHeights({
  240. * positions : Cesium.Cartesian3.fromDegreesArray([
  241. * 19.0, 47.0,
  242. * 19.0, 48.0,
  243. * 20.0, 48.0,
  244. * 20.0, 47.0,
  245. * 19.0, 47.0,
  246. * ]),
  247. * minimumHeight : 20000.0,
  248. * maximumHeight : 10000.0
  249. * });
  250. * var geometry = Cesium.WallGeometry.createGeometry(wall);
  251. *
  252. * @see WallGeometry#createGeometry
  253. */
  254. WallGeometry.fromConstantHeights = function (options) {
  255. options = when.defaultValue(options, when.defaultValue.EMPTY_OBJECT);
  256. var positions = options.positions;
  257. //>>includeStart('debug', pragmas.debug);
  258. if (!when.defined(positions)) {
  259. throw new Check.DeveloperError("options.positions is required.");
  260. }
  261. //>>includeEnd('debug');
  262. var minHeights;
  263. var maxHeights;
  264. var min = options.minimumHeight;
  265. var max = options.maximumHeight;
  266. var doMin = when.defined(min);
  267. var doMax = when.defined(max);
  268. if (doMin || doMax) {
  269. var length = positions.length;
  270. minHeights = doMin ? new Array(length) : undefined;
  271. maxHeights = doMax ? new Array(length) : undefined;
  272. for (var i = 0; i < length; ++i) {
  273. if (doMin) {
  274. minHeights[i] = min;
  275. }
  276. if (doMax) {
  277. maxHeights[i] = max;
  278. }
  279. }
  280. }
  281. var newOptions = {
  282. positions: positions,
  283. maximumHeights: maxHeights,
  284. minimumHeights: minHeights,
  285. ellipsoid: options.ellipsoid,
  286. vertexFormat: options.vertexFormat,
  287. };
  288. return new WallGeometry(newOptions);
  289. };
  290. /**
  291. * Computes the geometric representation of a wall, including its vertices, indices, and a bounding sphere.
  292. *
  293. * @param {WallGeometry} wallGeometry A description of the wall.
  294. * @returns {Geometry|undefined} The computed vertices and indices.
  295. */
  296. WallGeometry.createGeometry = function (wallGeometry) {
  297. var wallPositions = wallGeometry._positions;
  298. var minimumHeights = wallGeometry._minimumHeights;
  299. var maximumHeights = wallGeometry._maximumHeights;
  300. var vertexFormat = wallGeometry._vertexFormat;
  301. var granularity = wallGeometry._granularity;
  302. var ellipsoid = wallGeometry._ellipsoid;
  303. var pos = WallGeometryLibrary.WallGeometryLibrary.computePositions(
  304. ellipsoid,
  305. wallPositions,
  306. maximumHeights,
  307. minimumHeights,
  308. granularity,
  309. true
  310. );
  311. if (!when.defined(pos)) {
  312. return;
  313. }
  314. var bottomPositions = pos.bottomPositions;
  315. var topPositions = pos.topPositions;
  316. var numCorners = pos.numCorners;
  317. var length = topPositions.length;
  318. var size = length * 2;
  319. var positions = vertexFormat.position ? new Float64Array(size) : undefined;
  320. var normals = vertexFormat.normal ? new Float32Array(size) : undefined;
  321. var tangents = vertexFormat.tangent ? new Float32Array(size) : undefined;
  322. var bitangents = vertexFormat.bitangent ? new Float32Array(size) : undefined;
  323. var textureCoordinates = vertexFormat.st
  324. ? new Float32Array((size / 3) * 2)
  325. : undefined;
  326. var positionIndex = 0;
  327. var normalIndex = 0;
  328. var bitangentIndex = 0;
  329. var tangentIndex = 0;
  330. var stIndex = 0;
  331. // add lower and upper points one after the other, lower
  332. // points being even and upper points being odd
  333. var normal = scratchNormal;
  334. var tangent = scratchTangent;
  335. var bitangent = scratchBitangent;
  336. var recomputeNormal = true;
  337. length /= 3;
  338. var i;
  339. var s = 0;
  340. var ds = 1 / (length - numCorners - 1);
  341. for (i = 0; i < length; ++i) {
  342. var i3 = i * 3;
  343. var topPosition = Cartesian2.Cartesian3.fromArray(
  344. topPositions,
  345. i3,
  346. scratchCartesian3Position1
  347. );
  348. var bottomPosition = Cartesian2.Cartesian3.fromArray(
  349. bottomPositions,
  350. i3,
  351. scratchCartesian3Position2
  352. );
  353. if (vertexFormat.position) {
  354. // insert the lower point
  355. positions[positionIndex++] = bottomPosition.x;
  356. positions[positionIndex++] = bottomPosition.y;
  357. positions[positionIndex++] = bottomPosition.z;
  358. // insert the upper point
  359. positions[positionIndex++] = topPosition.x;
  360. positions[positionIndex++] = topPosition.y;
  361. positions[positionIndex++] = topPosition.z;
  362. }
  363. if (vertexFormat.st) {
  364. textureCoordinates[stIndex++] = s;
  365. textureCoordinates[stIndex++] = 0.0;
  366. textureCoordinates[stIndex++] = s;
  367. textureCoordinates[stIndex++] = 1.0;
  368. }
  369. if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.bitangent) {
  370. var nextTop = Cartesian2.Cartesian3.clone(
  371. Cartesian2.Cartesian3.ZERO,
  372. scratchCartesian3Position5
  373. );
  374. var groundPosition = Cartesian2.Cartesian3.subtract(
  375. topPosition,
  376. ellipsoid.geodeticSurfaceNormal(
  377. topPosition,
  378. scratchCartesian3Position2
  379. ),
  380. scratchCartesian3Position2
  381. );
  382. if (i + 1 < length) {
  383. nextTop = Cartesian2.Cartesian3.fromArray(
  384. topPositions,
  385. i3 + 3,
  386. scratchCartesian3Position5
  387. );
  388. }
  389. if (recomputeNormal) {
  390. var scalednextPosition = Cartesian2.Cartesian3.subtract(
  391. nextTop,
  392. topPosition,
  393. scratchCartesian3Position4
  394. );
  395. var scaledGroundPosition = Cartesian2.Cartesian3.subtract(
  396. groundPosition,
  397. topPosition,
  398. scratchCartesian3Position1
  399. );
  400. normal = Cartesian2.Cartesian3.normalize(
  401. Cartesian2.Cartesian3.cross(scaledGroundPosition, scalednextPosition, normal),
  402. normal
  403. );
  404. recomputeNormal = false;
  405. }
  406. if (
  407. Cartesian2.Cartesian3.equalsEpsilon(topPosition, nextTop, _Math.CesiumMath.EPSILON10)
  408. ) {
  409. recomputeNormal = true;
  410. } else {
  411. s += ds;
  412. if (vertexFormat.tangent) {
  413. tangent = Cartesian2.Cartesian3.normalize(
  414. Cartesian2.Cartesian3.subtract(nextTop, topPosition, tangent),
  415. tangent
  416. );
  417. }
  418. if (vertexFormat.bitangent) {
  419. bitangent = Cartesian2.Cartesian3.normalize(
  420. Cartesian2.Cartesian3.cross(normal, tangent, bitangent),
  421. bitangent
  422. );
  423. }
  424. }
  425. if (vertexFormat.normal) {
  426. normals[normalIndex++] = normal.x;
  427. normals[normalIndex++] = normal.y;
  428. normals[normalIndex++] = normal.z;
  429. normals[normalIndex++] = normal.x;
  430. normals[normalIndex++] = normal.y;
  431. normals[normalIndex++] = normal.z;
  432. }
  433. if (vertexFormat.tangent) {
  434. tangents[tangentIndex++] = tangent.x;
  435. tangents[tangentIndex++] = tangent.y;
  436. tangents[tangentIndex++] = tangent.z;
  437. tangents[tangentIndex++] = tangent.x;
  438. tangents[tangentIndex++] = tangent.y;
  439. tangents[tangentIndex++] = tangent.z;
  440. }
  441. if (vertexFormat.bitangent) {
  442. bitangents[bitangentIndex++] = bitangent.x;
  443. bitangents[bitangentIndex++] = bitangent.y;
  444. bitangents[bitangentIndex++] = bitangent.z;
  445. bitangents[bitangentIndex++] = bitangent.x;
  446. bitangents[bitangentIndex++] = bitangent.y;
  447. bitangents[bitangentIndex++] = bitangent.z;
  448. }
  449. }
  450. }
  451. var attributes = new GeometryAttributes.GeometryAttributes();
  452. if (vertexFormat.position) {
  453. attributes.position = new GeometryAttribute.GeometryAttribute({
  454. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  455. componentsPerAttribute: 3,
  456. values: positions,
  457. });
  458. }
  459. if (vertexFormat.normal) {
  460. attributes.normal = new GeometryAttribute.GeometryAttribute({
  461. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  462. componentsPerAttribute: 3,
  463. values: normals,
  464. });
  465. }
  466. if (vertexFormat.tangent) {
  467. attributes.tangent = new GeometryAttribute.GeometryAttribute({
  468. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  469. componentsPerAttribute: 3,
  470. values: tangents,
  471. });
  472. }
  473. if (vertexFormat.bitangent) {
  474. attributes.bitangent = new GeometryAttribute.GeometryAttribute({
  475. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  476. componentsPerAttribute: 3,
  477. values: bitangents,
  478. });
  479. }
  480. if (vertexFormat.st) {
  481. attributes.st = new GeometryAttribute.GeometryAttribute({
  482. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  483. componentsPerAttribute: 2,
  484. values: textureCoordinates,
  485. });
  486. }
  487. // prepare the side walls, two triangles for each wall
  488. //
  489. // A (i+1) B (i+3) E
  490. // +--------+-------+
  491. // | / | /| triangles: A C B
  492. // | / | / | B C D
  493. // | / | / |
  494. // | / | / |
  495. // | / | / |
  496. // | / | / |
  497. // +--------+-------+
  498. // C (i) D (i+2) F
  499. //
  500. var numVertices = size / 3;
  501. size -= 6 * (numCorners + 1);
  502. var indices = IndexDatatype.IndexDatatype.createTypedArray(numVertices, size);
  503. var edgeIndex = 0;
  504. for (i = 0; i < numVertices - 2; i += 2) {
  505. var LL = i;
  506. var LR = i + 2;
  507. var pl = Cartesian2.Cartesian3.fromArray(
  508. positions,
  509. LL * 3,
  510. scratchCartesian3Position1
  511. );
  512. var pr = Cartesian2.Cartesian3.fromArray(
  513. positions,
  514. LR * 3,
  515. scratchCartesian3Position2
  516. );
  517. if (Cartesian2.Cartesian3.equalsEpsilon(pl, pr, _Math.CesiumMath.EPSILON10)) {
  518. continue;
  519. }
  520. var UL = i + 1;
  521. var UR = i + 3;
  522. indices[edgeIndex++] = UL;
  523. indices[edgeIndex++] = LL;
  524. indices[edgeIndex++] = UR;
  525. indices[edgeIndex++] = UR;
  526. indices[edgeIndex++] = LL;
  527. indices[edgeIndex++] = LR;
  528. }
  529. return new GeometryAttribute.Geometry({
  530. attributes: attributes,
  531. indices: indices,
  532. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  533. boundingSphere: new Transforms.BoundingSphere.fromVertices(positions),
  534. });
  535. };
  536. function createWallGeometry(wallGeometry, offset) {
  537. if (when.defined(offset)) {
  538. wallGeometry = WallGeometry.unpack(wallGeometry, offset);
  539. }
  540. wallGeometry._ellipsoid = Cartesian2.Ellipsoid.clone(wallGeometry._ellipsoid);
  541. return WallGeometry.createGeometry(wallGeometry);
  542. }
  543. return createWallGeometry;
  544. });