createWallGeometry.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./defaultValue-94c3e563', './Matrix2-69c32d33', './Transforms-323408fe', './ComponentDatatype-b1ea011a', './RuntimeError-c581ca93', './GeometryAttribute-cb73bb3f', './GeometryAttributes-7df9bef6', './IndexDatatype-c4099fe9', './VertexFormat-e46f29d6', './WallGeometryLibrary-0e30fce7', './_commonjsHelpers-3aae1032-f55dc0c4', './combine-761d9c3f', './WebGLConstants-7dccdc96', './arrayRemoveDuplicates-87160c89', './PolylinePipeline-aa50e501', './EllipsoidGeodesic-98096082', './EllipsoidRhumbLine-5cb6da82', './IntersectionTests-d5d945ac', './Plane-069b6800'], (function (defaultValue, Matrix2, Transforms, ComponentDatatype, RuntimeError, GeometryAttribute, GeometryAttributes, IndexDatatype, VertexFormat, WallGeometryLibrary, _commonjsHelpers3aae1032, combine, WebGLConstants, arrayRemoveDuplicates, PolylinePipeline, EllipsoidGeodesic, EllipsoidRhumbLine, IntersectionTests, Plane) { 'use strict';
  3. const scratchCartesian3Position1 = new Matrix2.Cartesian3();
  4. const scratchCartesian3Position2 = new Matrix2.Cartesian3();
  5. const scratchCartesian3Position4 = new Matrix2.Cartesian3();
  6. const scratchCartesian3Position5 = new Matrix2.Cartesian3();
  7. const scratchBitangent = new Matrix2.Cartesian3();
  8. const scratchTangent = new Matrix2.Cartesian3();
  9. const scratchNormal = new Matrix2.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. * const 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. * const geometry = Cesium.WallGeometry.createGeometry(wall);
  48. */
  49. function WallGeometry(options) {
  50. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  51. const wallPositions = options.positions;
  52. const maximumHeights = options.maximumHeights;
  53. const minimumHeights = options.minimumHeights;
  54. //>>includeStart('debug', pragmas.debug);
  55. if (!defaultValue.defined(wallPositions)) {
  56. throw new RuntimeError.DeveloperError("options.positions is required.");
  57. }
  58. if (
  59. defaultValue.defined(maximumHeights) &&
  60. maximumHeights.length !== wallPositions.length
  61. ) {
  62. throw new RuntimeError.DeveloperError(
  63. "options.positions and options.maximumHeights must have the same length."
  64. );
  65. }
  66. if (
  67. defaultValue.defined(minimumHeights) &&
  68. minimumHeights.length !== wallPositions.length
  69. ) {
  70. throw new RuntimeError.DeveloperError(
  71. "options.positions and options.minimumHeights must have the same length."
  72. );
  73. }
  74. //>>includeEnd('debug');
  75. const vertexFormat = defaultValue.defaultValue(options.vertexFormat, VertexFormat.VertexFormat.DEFAULT);
  76. const granularity = defaultValue.defaultValue(
  77. options.granularity,
  78. ComponentDatatype.CesiumMath.RADIANS_PER_DEGREE
  79. );
  80. const ellipsoid = defaultValue.defaultValue(options.ellipsoid, Matrix2.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 = Matrix2.Ellipsoid.clone(ellipsoid);
  87. this._workerName = "createWallGeometry";
  88. let numComponents = 1 + wallPositions.length * Matrix2.Cartesian3.packedLength + 2;
  89. if (defaultValue.defined(minimumHeights)) {
  90. numComponents += minimumHeights.length;
  91. }
  92. if (defaultValue.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 + Matrix2.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 (!defaultValue.defined(value)) {
  114. throw new RuntimeError.DeveloperError("value is required");
  115. }
  116. if (!defaultValue.defined(array)) {
  117. throw new RuntimeError.DeveloperError("array is required");
  118. }
  119. //>>includeEnd('debug');
  120. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  121. let i;
  122. const positions = value._positions;
  123. let length = positions.length;
  124. array[startingIndex++] = length;
  125. for (i = 0; i < length; ++i, startingIndex += Matrix2.Cartesian3.packedLength) {
  126. Matrix2.Cartesian3.pack(positions[i], array, startingIndex);
  127. }
  128. const minimumHeights = value._minimumHeights;
  129. length = defaultValue.defined(minimumHeights) ? minimumHeights.length : 0;
  130. array[startingIndex++] = length;
  131. if (defaultValue.defined(minimumHeights)) {
  132. for (i = 0; i < length; ++i) {
  133. array[startingIndex++] = minimumHeights[i];
  134. }
  135. }
  136. const maximumHeights = value._maximumHeights;
  137. length = defaultValue.defined(maximumHeights) ? maximumHeights.length : 0;
  138. array[startingIndex++] = length;
  139. if (defaultValue.defined(maximumHeights)) {
  140. for (i = 0; i < length; ++i) {
  141. array[startingIndex++] = maximumHeights[i];
  142. }
  143. }
  144. Matrix2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  145. startingIndex += Matrix2.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. const scratchEllipsoid = Matrix2.Ellipsoid.clone(Matrix2.Ellipsoid.UNIT_SPHERE);
  152. const scratchVertexFormat = new VertexFormat.VertexFormat();
  153. const 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 (!defaultValue.defined(array)) {
  172. throw new RuntimeError.DeveloperError("array is required");
  173. }
  174. //>>includeEnd('debug');
  175. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  176. let i;
  177. let length = array[startingIndex++];
  178. const positions = new Array(length);
  179. for (i = 0; i < length; ++i, startingIndex += Matrix2.Cartesian3.packedLength) {
  180. positions[i] = Matrix2.Cartesian3.unpack(array, startingIndex);
  181. }
  182. length = array[startingIndex++];
  183. let 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. let 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. const ellipsoid = Matrix2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  199. startingIndex += Matrix2.Ellipsoid.packedLength;
  200. const vertexFormat = VertexFormat.VertexFormat.unpack(
  201. array,
  202. startingIndex,
  203. scratchVertexFormat
  204. );
  205. startingIndex += VertexFormat.VertexFormat.packedLength;
  206. const granularity = array[startingIndex];
  207. if (!defaultValue.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 = Matrix2.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. * const 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. * const geometry = Cesium.WallGeometry.createGeometry(wall);
  251. *
  252. * @see WallGeometry#createGeometry
  253. */
  254. WallGeometry.fromConstantHeights = function (options) {
  255. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  256. const positions = options.positions;
  257. //>>includeStart('debug', pragmas.debug);
  258. if (!defaultValue.defined(positions)) {
  259. throw new RuntimeError.DeveloperError("options.positions is required.");
  260. }
  261. //>>includeEnd('debug');
  262. let minHeights;
  263. let maxHeights;
  264. const min = options.minimumHeight;
  265. const max = options.maximumHeight;
  266. const doMin = defaultValue.defined(min);
  267. const doMax = defaultValue.defined(max);
  268. if (doMin || doMax) {
  269. const length = positions.length;
  270. minHeights = doMin ? new Array(length) : undefined;
  271. maxHeights = doMax ? new Array(length) : undefined;
  272. for (let i = 0; i < length; ++i) {
  273. if (doMin) {
  274. minHeights[i] = min;
  275. }
  276. if (doMax) {
  277. maxHeights[i] = max;
  278. }
  279. }
  280. }
  281. const 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. const wallPositions = wallGeometry._positions;
  298. const minimumHeights = wallGeometry._minimumHeights;
  299. const maximumHeights = wallGeometry._maximumHeights;
  300. const vertexFormat = wallGeometry._vertexFormat;
  301. const granularity = wallGeometry._granularity;
  302. const ellipsoid = wallGeometry._ellipsoid;
  303. const pos = WallGeometryLibrary.WallGeometryLibrary.computePositions(
  304. ellipsoid,
  305. wallPositions,
  306. maximumHeights,
  307. minimumHeights,
  308. granularity,
  309. true
  310. );
  311. if (!defaultValue.defined(pos)) {
  312. return;
  313. }
  314. const bottomPositions = pos.bottomPositions;
  315. const topPositions = pos.topPositions;
  316. const numCorners = pos.numCorners;
  317. let length = topPositions.length;
  318. let size = length * 2;
  319. const positions = vertexFormat.position ? new Float64Array(size) : undefined;
  320. const normals = vertexFormat.normal ? new Float32Array(size) : undefined;
  321. const tangents = vertexFormat.tangent ? new Float32Array(size) : undefined;
  322. const bitangents = vertexFormat.bitangent
  323. ? new Float32Array(size)
  324. : undefined;
  325. const textureCoordinates = vertexFormat.st
  326. ? new Float32Array((size / 3) * 2)
  327. : undefined;
  328. let positionIndex = 0;
  329. let normalIndex = 0;
  330. let bitangentIndex = 0;
  331. let tangentIndex = 0;
  332. let stIndex = 0;
  333. // add lower and upper points one after the other, lower
  334. // points being even and upper points being odd
  335. let normal = scratchNormal;
  336. let tangent = scratchTangent;
  337. let bitangent = scratchBitangent;
  338. let recomputeNormal = true;
  339. length /= 3;
  340. let i;
  341. let s = 0;
  342. const ds = 1 / (length - numCorners - 1);
  343. for (i = 0; i < length; ++i) {
  344. const i3 = i * 3;
  345. const topPosition = Matrix2.Cartesian3.fromArray(
  346. topPositions,
  347. i3,
  348. scratchCartesian3Position1
  349. );
  350. const bottomPosition = Matrix2.Cartesian3.fromArray(
  351. bottomPositions,
  352. i3,
  353. scratchCartesian3Position2
  354. );
  355. if (vertexFormat.position) {
  356. // insert the lower point
  357. positions[positionIndex++] = bottomPosition.x;
  358. positions[positionIndex++] = bottomPosition.y;
  359. positions[positionIndex++] = bottomPosition.z;
  360. // insert the upper point
  361. positions[positionIndex++] = topPosition.x;
  362. positions[positionIndex++] = topPosition.y;
  363. positions[positionIndex++] = topPosition.z;
  364. }
  365. if (vertexFormat.st) {
  366. textureCoordinates[stIndex++] = s;
  367. textureCoordinates[stIndex++] = 0.0;
  368. textureCoordinates[stIndex++] = s;
  369. textureCoordinates[stIndex++] = 1.0;
  370. }
  371. if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.bitangent) {
  372. let nextTop = Matrix2.Cartesian3.clone(
  373. Matrix2.Cartesian3.ZERO,
  374. scratchCartesian3Position5
  375. );
  376. const groundPosition = Matrix2.Cartesian3.subtract(
  377. topPosition,
  378. ellipsoid.geodeticSurfaceNormal(
  379. topPosition,
  380. scratchCartesian3Position2
  381. ),
  382. scratchCartesian3Position2
  383. );
  384. if (i + 1 < length) {
  385. nextTop = Matrix2.Cartesian3.fromArray(
  386. topPositions,
  387. i3 + 3,
  388. scratchCartesian3Position5
  389. );
  390. }
  391. if (recomputeNormal) {
  392. const scalednextPosition = Matrix2.Cartesian3.subtract(
  393. nextTop,
  394. topPosition,
  395. scratchCartesian3Position4
  396. );
  397. const scaledGroundPosition = Matrix2.Cartesian3.subtract(
  398. groundPosition,
  399. topPosition,
  400. scratchCartesian3Position1
  401. );
  402. normal = Matrix2.Cartesian3.normalize(
  403. Matrix2.Cartesian3.cross(scaledGroundPosition, scalednextPosition, normal),
  404. normal
  405. );
  406. recomputeNormal = false;
  407. }
  408. if (
  409. Matrix2.Cartesian3.equalsEpsilon(topPosition, nextTop, ComponentDatatype.CesiumMath.EPSILON10)
  410. ) {
  411. recomputeNormal = true;
  412. } else {
  413. s += ds;
  414. if (vertexFormat.tangent) {
  415. tangent = Matrix2.Cartesian3.normalize(
  416. Matrix2.Cartesian3.subtract(nextTop, topPosition, tangent),
  417. tangent
  418. );
  419. }
  420. if (vertexFormat.bitangent) {
  421. bitangent = Matrix2.Cartesian3.normalize(
  422. Matrix2.Cartesian3.cross(normal, tangent, bitangent),
  423. bitangent
  424. );
  425. }
  426. }
  427. if (vertexFormat.normal) {
  428. normals[normalIndex++] = normal.x;
  429. normals[normalIndex++] = normal.y;
  430. normals[normalIndex++] = normal.z;
  431. normals[normalIndex++] = normal.x;
  432. normals[normalIndex++] = normal.y;
  433. normals[normalIndex++] = normal.z;
  434. }
  435. if (vertexFormat.tangent) {
  436. tangents[tangentIndex++] = tangent.x;
  437. tangents[tangentIndex++] = tangent.y;
  438. tangents[tangentIndex++] = tangent.z;
  439. tangents[tangentIndex++] = tangent.x;
  440. tangents[tangentIndex++] = tangent.y;
  441. tangents[tangentIndex++] = tangent.z;
  442. }
  443. if (vertexFormat.bitangent) {
  444. bitangents[bitangentIndex++] = bitangent.x;
  445. bitangents[bitangentIndex++] = bitangent.y;
  446. bitangents[bitangentIndex++] = bitangent.z;
  447. bitangents[bitangentIndex++] = bitangent.x;
  448. bitangents[bitangentIndex++] = bitangent.y;
  449. bitangents[bitangentIndex++] = bitangent.z;
  450. }
  451. }
  452. }
  453. const attributes = new GeometryAttributes.GeometryAttributes();
  454. if (vertexFormat.position) {
  455. attributes.position = new GeometryAttribute.GeometryAttribute({
  456. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  457. componentsPerAttribute: 3,
  458. values: positions,
  459. });
  460. }
  461. if (vertexFormat.normal) {
  462. attributes.normal = new GeometryAttribute.GeometryAttribute({
  463. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  464. componentsPerAttribute: 3,
  465. values: normals,
  466. });
  467. }
  468. if (vertexFormat.tangent) {
  469. attributes.tangent = new GeometryAttribute.GeometryAttribute({
  470. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  471. componentsPerAttribute: 3,
  472. values: tangents,
  473. });
  474. }
  475. if (vertexFormat.bitangent) {
  476. attributes.bitangent = new GeometryAttribute.GeometryAttribute({
  477. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  478. componentsPerAttribute: 3,
  479. values: bitangents,
  480. });
  481. }
  482. if (vertexFormat.st) {
  483. attributes.st = new GeometryAttribute.GeometryAttribute({
  484. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  485. componentsPerAttribute: 2,
  486. values: textureCoordinates,
  487. });
  488. }
  489. // prepare the side walls, two triangles for each wall
  490. //
  491. // A (i+1) B (i+3) E
  492. // +--------+-------+
  493. // | / | /| triangles: A C B
  494. // | / | / | B C D
  495. // | / | / |
  496. // | / | / |
  497. // | / | / |
  498. // | / | / |
  499. // +--------+-------+
  500. // C (i) D (i+2) F
  501. //
  502. const numVertices = size / 3;
  503. size -= 6 * (numCorners + 1);
  504. const indices = IndexDatatype.IndexDatatype.createTypedArray(numVertices, size);
  505. let edgeIndex = 0;
  506. for (i = 0; i < numVertices - 2; i += 2) {
  507. const LL = i;
  508. const LR = i + 2;
  509. const pl = Matrix2.Cartesian3.fromArray(
  510. positions,
  511. LL * 3,
  512. scratchCartesian3Position1
  513. );
  514. const pr = Matrix2.Cartesian3.fromArray(
  515. positions,
  516. LR * 3,
  517. scratchCartesian3Position2
  518. );
  519. if (Matrix2.Cartesian3.equalsEpsilon(pl, pr, ComponentDatatype.CesiumMath.EPSILON10)) {
  520. continue;
  521. }
  522. const UL = i + 1;
  523. const UR = i + 3;
  524. indices[edgeIndex++] = UL;
  525. indices[edgeIndex++] = LL;
  526. indices[edgeIndex++] = UR;
  527. indices[edgeIndex++] = UR;
  528. indices[edgeIndex++] = LL;
  529. indices[edgeIndex++] = LR;
  530. }
  531. return new GeometryAttribute.Geometry({
  532. attributes: attributes,
  533. indices: indices,
  534. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  535. boundingSphere: new Transforms.BoundingSphere.fromVertices(positions),
  536. });
  537. };
  538. function createWallGeometry(wallGeometry, offset) {
  539. if (defaultValue.defined(offset)) {
  540. wallGeometry = WallGeometry.unpack(wallGeometry, offset);
  541. }
  542. wallGeometry._ellipsoid = Matrix2.Ellipsoid.clone(wallGeometry._ellipsoid);
  543. return WallGeometry.createGeometry(wallGeometry);
  544. }
  545. return createWallGeometry;
  546. }));