createWallGeometry.js 23 KB

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