createWallGeometry.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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/master/LICENSE.md for full licensing details.
  22. */
  23. define(['./when-54c2dc71', './Check-6c0211bc', './Math-1124a290', './Cartesian2-33d2657c', './Transforms-8be64844', './RuntimeError-2109023a', './WebGLConstants-76bb35d1', './ComponentDatatype-a26dd044', './GeometryAttribute-e9a8b203', './GeometryAttributes-4fcfcf40', './IndexDatatype-25023891', './IntersectionTests-afc38163', './Plane-fa30fc46', './VertexFormat-4d8b817a', './arrayRemoveDuplicates-0263f42c', './EllipsoidRhumbLine-5f1492e5', './EllipsoidGeodesic-0f41968b', './PolylinePipeline-25d1e129', './WallGeometryLibrary-1431b81f'], function (when, Check, _Math, Cartesian2, Transforms, RuntimeError, WebGLConstants, ComponentDatatype, GeometryAttribute, GeometryAttributes, IndexDatatype, IntersectionTests, Plane, VertexFormat, arrayRemoveDuplicates, EllipsoidRhumbLine, EllipsoidGeodesic, PolylinePipeline, WallGeometryLibrary) { 'use strict';
  24. var scratchCartesian3Position1 = new Cartesian2.Cartesian3();
  25. var scratchCartesian3Position2 = new Cartesian2.Cartesian3();
  26. var scratchCartesian3Position4 = new Cartesian2.Cartesian3();
  27. var scratchCartesian3Position5 = new Cartesian2.Cartesian3();
  28. var scratchBitangent = new Cartesian2.Cartesian3();
  29. var scratchTangent = new Cartesian2.Cartesian3();
  30. var scratchNormal = new Cartesian2.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. * var 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. * var geometry = Cesium.WallGeometry.createGeometry(wall);
  69. */
  70. function WallGeometry(options) {
  71. options = when.defaultValue(options, when.defaultValue.EMPTY_OBJECT);
  72. var wallPositions = options.positions;
  73. var maximumHeights = options.maximumHeights;
  74. var minimumHeights = options.minimumHeights;
  75. //>>includeStart('debug', pragmas.debug);
  76. if (!when.defined(wallPositions)) {
  77. throw new Check.DeveloperError("options.positions is required.");
  78. }
  79. if (
  80. when.defined(maximumHeights) &&
  81. maximumHeights.length !== wallPositions.length
  82. ) {
  83. throw new Check.DeveloperError(
  84. "options.positions and options.maximumHeights must have the same length."
  85. );
  86. }
  87. if (
  88. when.defined(minimumHeights) &&
  89. minimumHeights.length !== wallPositions.length
  90. ) {
  91. throw new Check.DeveloperError(
  92. "options.positions and options.minimumHeights must have the same length."
  93. );
  94. }
  95. //>>includeEnd('debug');
  96. var vertexFormat = when.defaultValue(options.vertexFormat, VertexFormat.VertexFormat.DEFAULT);
  97. var granularity = when.defaultValue(
  98. options.granularity,
  99. _Math.CesiumMath.RADIANS_PER_DEGREE
  100. );
  101. var ellipsoid = when.defaultValue(options.ellipsoid, Cartesian2.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 = Cartesian2.Ellipsoid.clone(ellipsoid);
  108. this._workerName = "createWallGeometry";
  109. var numComponents = 1 + wallPositions.length * Cartesian2.Cartesian3.packedLength + 2;
  110. if (when.defined(minimumHeights)) {
  111. numComponents += minimumHeights.length;
  112. }
  113. if (when.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 + Cartesian2.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 (!when.defined(value)) {
  135. throw new Check.DeveloperError("value is required");
  136. }
  137. if (!when.defined(array)) {
  138. throw new Check.DeveloperError("array is required");
  139. }
  140. //>>includeEnd('debug');
  141. startingIndex = when.defaultValue(startingIndex, 0);
  142. var i;
  143. var positions = value._positions;
  144. var length = positions.length;
  145. array[startingIndex++] = length;
  146. for (i = 0; i < length; ++i, startingIndex += Cartesian2.Cartesian3.packedLength) {
  147. Cartesian2.Cartesian3.pack(positions[i], array, startingIndex);
  148. }
  149. var minimumHeights = value._minimumHeights;
  150. length = when.defined(minimumHeights) ? minimumHeights.length : 0;
  151. array[startingIndex++] = length;
  152. if (when.defined(minimumHeights)) {
  153. for (i = 0; i < length; ++i) {
  154. array[startingIndex++] = minimumHeights[i];
  155. }
  156. }
  157. var maximumHeights = value._maximumHeights;
  158. length = when.defined(maximumHeights) ? maximumHeights.length : 0;
  159. array[startingIndex++] = length;
  160. if (when.defined(maximumHeights)) {
  161. for (i = 0; i < length; ++i) {
  162. array[startingIndex++] = maximumHeights[i];
  163. }
  164. }
  165. Cartesian2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  166. startingIndex += Cartesian2.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. var scratchEllipsoid = Cartesian2.Ellipsoid.clone(Cartesian2.Ellipsoid.UNIT_SPHERE);
  173. var scratchVertexFormat = new VertexFormat.VertexFormat();
  174. var 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 (!when.defined(array)) {
  193. throw new Check.DeveloperError("array is required");
  194. }
  195. //>>includeEnd('debug');
  196. startingIndex = when.defaultValue(startingIndex, 0);
  197. var i;
  198. var length = array[startingIndex++];
  199. var positions = new Array(length);
  200. for (i = 0; i < length; ++i, startingIndex += Cartesian2.Cartesian3.packedLength) {
  201. positions[i] = Cartesian2.Cartesian3.unpack(array, startingIndex);
  202. }
  203. length = array[startingIndex++];
  204. var 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. var 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. var ellipsoid = Cartesian2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  220. startingIndex += Cartesian2.Ellipsoid.packedLength;
  221. var vertexFormat = VertexFormat.VertexFormat.unpack(
  222. array,
  223. startingIndex,
  224. scratchVertexFormat
  225. );
  226. startingIndex += VertexFormat.VertexFormat.packedLength;
  227. var granularity = array[startingIndex];
  228. if (!when.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 = Cartesian2.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. * var 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. * var geometry = Cesium.WallGeometry.createGeometry(wall);
  272. *
  273. * @see WallGeometry#createGeometry
  274. */
  275. WallGeometry.fromConstantHeights = function (options) {
  276. options = when.defaultValue(options, when.defaultValue.EMPTY_OBJECT);
  277. var positions = options.positions;
  278. //>>includeStart('debug', pragmas.debug);
  279. if (!when.defined(positions)) {
  280. throw new Check.DeveloperError("options.positions is required.");
  281. }
  282. //>>includeEnd('debug');
  283. var minHeights;
  284. var maxHeights;
  285. var min = options.minimumHeight;
  286. var max = options.maximumHeight;
  287. var doMin = when.defined(min);
  288. var doMax = when.defined(max);
  289. if (doMin || doMax) {
  290. var length = positions.length;
  291. minHeights = doMin ? new Array(length) : undefined;
  292. maxHeights = doMax ? new Array(length) : undefined;
  293. for (var i = 0; i < length; ++i) {
  294. if (doMin) {
  295. minHeights[i] = min;
  296. }
  297. if (doMax) {
  298. maxHeights[i] = max;
  299. }
  300. }
  301. }
  302. var 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. var wallPositions = wallGeometry._positions;
  319. var minimumHeights = wallGeometry._minimumHeights;
  320. var maximumHeights = wallGeometry._maximumHeights;
  321. var vertexFormat = wallGeometry._vertexFormat;
  322. var granularity = wallGeometry._granularity;
  323. var ellipsoid = wallGeometry._ellipsoid;
  324. var pos = WallGeometryLibrary.WallGeometryLibrary.computePositions(
  325. ellipsoid,
  326. wallPositions,
  327. maximumHeights,
  328. minimumHeights,
  329. granularity,
  330. true
  331. );
  332. if (!when.defined(pos)) {
  333. return;
  334. }
  335. var bottomPositions = pos.bottomPositions;
  336. var topPositions = pos.topPositions;
  337. var numCorners = pos.numCorners;
  338. var length = topPositions.length;
  339. var size = length * 2;
  340. var positions = vertexFormat.position ? new Float64Array(size) : undefined;
  341. var normals = vertexFormat.normal ? new Float32Array(size) : undefined;
  342. var tangents = vertexFormat.tangent ? new Float32Array(size) : undefined;
  343. var bitangents = vertexFormat.bitangent ? new Float32Array(size) : undefined;
  344. var textureCoordinates = vertexFormat.st
  345. ? new Float32Array((size / 3) * 2)
  346. : undefined;
  347. var positionIndex = 0;
  348. var normalIndex = 0;
  349. var bitangentIndex = 0;
  350. var tangentIndex = 0;
  351. var stIndex = 0;
  352. // add lower and upper points one after the other, lower
  353. // points being even and upper points being odd
  354. var normal = scratchNormal;
  355. var tangent = scratchTangent;
  356. var bitangent = scratchBitangent;
  357. var recomputeNormal = true;
  358. length /= 3;
  359. var i;
  360. var s = 0;
  361. var ds = 1 / (length - numCorners - 1);
  362. for (i = 0; i < length; ++i) {
  363. var i3 = i * 3;
  364. var topPosition = Cartesian2.Cartesian3.fromArray(
  365. topPositions,
  366. i3,
  367. scratchCartesian3Position1
  368. );
  369. var bottomPosition = Cartesian2.Cartesian3.fromArray(
  370. bottomPositions,
  371. i3,
  372. scratchCartesian3Position2
  373. );
  374. if (vertexFormat.position) {
  375. // insert the lower point
  376. positions[positionIndex++] = bottomPosition.x;
  377. positions[positionIndex++] = bottomPosition.y;
  378. positions[positionIndex++] = bottomPosition.z;
  379. // insert the upper point
  380. positions[positionIndex++] = topPosition.x;
  381. positions[positionIndex++] = topPosition.y;
  382. positions[positionIndex++] = topPosition.z;
  383. }
  384. if (vertexFormat.st) {
  385. textureCoordinates[stIndex++] = s;
  386. textureCoordinates[stIndex++] = 0.0;
  387. textureCoordinates[stIndex++] = s;
  388. textureCoordinates[stIndex++] = 1.0;
  389. }
  390. if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.bitangent) {
  391. var nextTop = Cartesian2.Cartesian3.clone(
  392. Cartesian2.Cartesian3.ZERO,
  393. scratchCartesian3Position5
  394. );
  395. var groundPosition = Cartesian2.Cartesian3.subtract(
  396. topPosition,
  397. ellipsoid.geodeticSurfaceNormal(
  398. topPosition,
  399. scratchCartesian3Position2
  400. ),
  401. scratchCartesian3Position2
  402. );
  403. if (i + 1 < length) {
  404. nextTop = Cartesian2.Cartesian3.fromArray(
  405. topPositions,
  406. i3 + 3,
  407. scratchCartesian3Position5
  408. );
  409. }
  410. if (recomputeNormal) {
  411. var scalednextPosition = Cartesian2.Cartesian3.subtract(
  412. nextTop,
  413. topPosition,
  414. scratchCartesian3Position4
  415. );
  416. var scaledGroundPosition = Cartesian2.Cartesian3.subtract(
  417. groundPosition,
  418. topPosition,
  419. scratchCartesian3Position1
  420. );
  421. normal = Cartesian2.Cartesian3.normalize(
  422. Cartesian2.Cartesian3.cross(scaledGroundPosition, scalednextPosition, normal),
  423. normal
  424. );
  425. recomputeNormal = false;
  426. }
  427. if (
  428. Cartesian2.Cartesian3.equalsEpsilon(topPosition, nextTop, _Math.CesiumMath.EPSILON10)
  429. ) {
  430. recomputeNormal = true;
  431. } else {
  432. s += ds;
  433. if (vertexFormat.tangent) {
  434. tangent = Cartesian2.Cartesian3.normalize(
  435. Cartesian2.Cartesian3.subtract(nextTop, topPosition, tangent),
  436. tangent
  437. );
  438. }
  439. if (vertexFormat.bitangent) {
  440. bitangent = Cartesian2.Cartesian3.normalize(
  441. Cartesian2.Cartesian3.cross(normal, tangent, bitangent),
  442. bitangent
  443. );
  444. }
  445. }
  446. if (vertexFormat.normal) {
  447. normals[normalIndex++] = normal.x;
  448. normals[normalIndex++] = normal.y;
  449. normals[normalIndex++] = normal.z;
  450. normals[normalIndex++] = normal.x;
  451. normals[normalIndex++] = normal.y;
  452. normals[normalIndex++] = normal.z;
  453. }
  454. if (vertexFormat.tangent) {
  455. tangents[tangentIndex++] = tangent.x;
  456. tangents[tangentIndex++] = tangent.y;
  457. tangents[tangentIndex++] = tangent.z;
  458. tangents[tangentIndex++] = tangent.x;
  459. tangents[tangentIndex++] = tangent.y;
  460. tangents[tangentIndex++] = tangent.z;
  461. }
  462. if (vertexFormat.bitangent) {
  463. bitangents[bitangentIndex++] = bitangent.x;
  464. bitangents[bitangentIndex++] = bitangent.y;
  465. bitangents[bitangentIndex++] = bitangent.z;
  466. bitangents[bitangentIndex++] = bitangent.x;
  467. bitangents[bitangentIndex++] = bitangent.y;
  468. bitangents[bitangentIndex++] = bitangent.z;
  469. }
  470. }
  471. }
  472. var attributes = new GeometryAttributes.GeometryAttributes();
  473. if (vertexFormat.position) {
  474. attributes.position = new GeometryAttribute.GeometryAttribute({
  475. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  476. componentsPerAttribute: 3,
  477. values: positions,
  478. });
  479. }
  480. if (vertexFormat.normal) {
  481. attributes.normal = new GeometryAttribute.GeometryAttribute({
  482. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  483. componentsPerAttribute: 3,
  484. values: normals,
  485. });
  486. }
  487. if (vertexFormat.tangent) {
  488. attributes.tangent = new GeometryAttribute.GeometryAttribute({
  489. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  490. componentsPerAttribute: 3,
  491. values: tangents,
  492. });
  493. }
  494. if (vertexFormat.bitangent) {
  495. attributes.bitangent = new GeometryAttribute.GeometryAttribute({
  496. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  497. componentsPerAttribute: 3,
  498. values: bitangents,
  499. });
  500. }
  501. if (vertexFormat.st) {
  502. attributes.st = new GeometryAttribute.GeometryAttribute({
  503. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  504. componentsPerAttribute: 2,
  505. values: textureCoordinates,
  506. });
  507. }
  508. // prepare the side walls, two triangles for each wall
  509. //
  510. // A (i+1) B (i+3) E
  511. // +--------+-------+
  512. // | / | /| triangles: A C B
  513. // | / | / | B C D
  514. // | / | / |
  515. // | / | / |
  516. // | / | / |
  517. // | / | / |
  518. // +--------+-------+
  519. // C (i) D (i+2) F
  520. //
  521. var numVertices = size / 3;
  522. size -= 6 * (numCorners + 1);
  523. var indices = IndexDatatype.IndexDatatype.createTypedArray(numVertices, size);
  524. var edgeIndex = 0;
  525. for (i = 0; i < numVertices - 2; i += 2) {
  526. var LL = i;
  527. var LR = i + 2;
  528. var pl = Cartesian2.Cartesian3.fromArray(
  529. positions,
  530. LL * 3,
  531. scratchCartesian3Position1
  532. );
  533. var pr = Cartesian2.Cartesian3.fromArray(
  534. positions,
  535. LR * 3,
  536. scratchCartesian3Position2
  537. );
  538. if (Cartesian2.Cartesian3.equalsEpsilon(pl, pr, _Math.CesiumMath.EPSILON10)) {
  539. continue;
  540. }
  541. var UL = i + 1;
  542. var UR = i + 3;
  543. indices[edgeIndex++] = UL;
  544. indices[edgeIndex++] = LL;
  545. indices[edgeIndex++] = UR;
  546. indices[edgeIndex++] = UR;
  547. indices[edgeIndex++] = LL;
  548. indices[edgeIndex++] = LR;
  549. }
  550. return new GeometryAttribute.Geometry({
  551. attributes: attributes,
  552. indices: indices,
  553. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  554. boundingSphere: new Transforms.BoundingSphere.fromVertices(positions),
  555. });
  556. };
  557. function createWallGeometry(wallGeometry, offset) {
  558. if (when.defined(offset)) {
  559. wallGeometry = WallGeometry.unpack(wallGeometry, offset);
  560. }
  561. wallGeometry._ellipsoid = Cartesian2.Ellipsoid.clone(wallGeometry._ellipsoid);
  562. return WallGeometry.createGeometry(wallGeometry);
  563. }
  564. return createWallGeometry;
  565. });
  566. //# sourceMappingURL=createWallGeometry.js.map