createWallGeometry.js 28 KB

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