createWallGeometry.js 22 KB

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