createVerticesFromGoogleEarthEnterpriseBuffer.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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(['./AxisAlignedBoundingBox-7b93960a', './Transforms-f0a54c7b', './Matrix2-d35cf4b5', './defaultValue-81eec7ed', './TerrainEncoding-a8a1f120', './ComponentDatatype-9e86ac8f', './OrientedBoundingBox-0b41570b', './RuntimeError-8952249c', './WebMercatorProjection-2d464b74', './createTaskProcessorWorker', './_commonjsHelpers-3aae1032-26891ab7', './combine-3c023bda', './AttributeCompression-d0b97a83', './WebGLConstants-508b9636', './EllipsoidTangentPlane-2abe082d', './IntersectionTests-a25e058d', './Plane-24f22488'], (function (AxisAlignedBoundingBox, Transforms, Matrix2, defaultValue, TerrainEncoding, ComponentDatatype, OrientedBoundingBox, RuntimeError, WebMercatorProjection, createTaskProcessorWorker, _commonjsHelpers3aae1032, combine, AttributeCompression, WebGLConstants, EllipsoidTangentPlane, IntersectionTests, Plane) { 'use strict';
  24. const sizeOfUint16 = Uint16Array.BYTES_PER_ELEMENT;
  25. const sizeOfInt32 = Int32Array.BYTES_PER_ELEMENT;
  26. const sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT;
  27. const sizeOfFloat = Float32Array.BYTES_PER_ELEMENT;
  28. const sizeOfDouble = Float64Array.BYTES_PER_ELEMENT;
  29. function indexOfEpsilon(arr, elem, elemType) {
  30. elemType = defaultValue.defaultValue(elemType, ComponentDatatype.CesiumMath);
  31. const count = arr.length;
  32. for (let i = 0; i < count; ++i) {
  33. if (elemType.equalsEpsilon(arr[i], elem, ComponentDatatype.CesiumMath.EPSILON12)) {
  34. return i;
  35. }
  36. }
  37. return -1;
  38. }
  39. function createVerticesFromGoogleEarthEnterpriseBuffer(
  40. parameters,
  41. transferableObjects
  42. ) {
  43. parameters.ellipsoid = Matrix2.Ellipsoid.clone(parameters.ellipsoid);
  44. parameters.rectangle = Matrix2.Rectangle.clone(parameters.rectangle);
  45. const statistics = processBuffer(
  46. parameters.buffer,
  47. parameters.relativeToCenter,
  48. parameters.ellipsoid,
  49. parameters.rectangle,
  50. parameters.nativeRectangle,
  51. parameters.exaggeration,
  52. parameters.exaggerationRelativeHeight,
  53. parameters.skirtHeight,
  54. parameters.includeWebMercatorT,
  55. parameters.negativeAltitudeExponentBias,
  56. parameters.negativeElevationThreshold
  57. );
  58. const vertices = statistics.vertices;
  59. transferableObjects.push(vertices.buffer);
  60. const indices = statistics.indices;
  61. transferableObjects.push(indices.buffer);
  62. return {
  63. vertices: vertices.buffer,
  64. indices: indices.buffer,
  65. numberOfAttributes: statistics.encoding.stride,
  66. minimumHeight: statistics.minimumHeight,
  67. maximumHeight: statistics.maximumHeight,
  68. boundingSphere3D: statistics.boundingSphere3D,
  69. orientedBoundingBox: statistics.orientedBoundingBox,
  70. occludeePointInScaledSpace: statistics.occludeePointInScaledSpace,
  71. encoding: statistics.encoding,
  72. vertexCountWithoutSkirts: statistics.vertexCountWithoutSkirts,
  73. indexCountWithoutSkirts: statistics.indexCountWithoutSkirts,
  74. westIndicesSouthToNorth: statistics.westIndicesSouthToNorth,
  75. southIndicesEastToWest: statistics.southIndicesEastToWest,
  76. eastIndicesNorthToSouth: statistics.eastIndicesNorthToSouth,
  77. northIndicesWestToEast: statistics.northIndicesWestToEast,
  78. };
  79. }
  80. const scratchCartographic = new Matrix2.Cartographic();
  81. const scratchCartesian = new Matrix2.Cartesian3();
  82. const minimumScratch = new Matrix2.Cartesian3();
  83. const maximumScratch = new Matrix2.Cartesian3();
  84. const matrix4Scratch = new Matrix2.Matrix4();
  85. function processBuffer(
  86. buffer,
  87. relativeToCenter,
  88. ellipsoid,
  89. rectangle,
  90. nativeRectangle,
  91. exaggeration,
  92. exaggerationRelativeHeight,
  93. skirtHeight,
  94. includeWebMercatorT,
  95. negativeAltitudeExponentBias,
  96. negativeElevationThreshold
  97. ) {
  98. let geographicWest;
  99. let geographicSouth;
  100. let geographicEast;
  101. let geographicNorth;
  102. let rectangleWidth, rectangleHeight;
  103. if (!defaultValue.defined(rectangle)) {
  104. geographicWest = ComponentDatatype.CesiumMath.toRadians(nativeRectangle.west);
  105. geographicSouth = ComponentDatatype.CesiumMath.toRadians(nativeRectangle.south);
  106. geographicEast = ComponentDatatype.CesiumMath.toRadians(nativeRectangle.east);
  107. geographicNorth = ComponentDatatype.CesiumMath.toRadians(nativeRectangle.north);
  108. rectangleWidth = ComponentDatatype.CesiumMath.toRadians(rectangle.width);
  109. rectangleHeight = ComponentDatatype.CesiumMath.toRadians(rectangle.height);
  110. } else {
  111. geographicWest = rectangle.west;
  112. geographicSouth = rectangle.south;
  113. geographicEast = rectangle.east;
  114. geographicNorth = rectangle.north;
  115. rectangleWidth = rectangle.width;
  116. rectangleHeight = rectangle.height;
  117. }
  118. // Keep track of quad borders so we can remove duplicates around the borders
  119. const quadBorderLatitudes = [geographicSouth, geographicNorth];
  120. const quadBorderLongitudes = [geographicWest, geographicEast];
  121. const fromENU = Transforms.Transforms.eastNorthUpToFixedFrame(
  122. relativeToCenter,
  123. ellipsoid
  124. );
  125. const toENU = Matrix2.Matrix4.inverseTransformation(fromENU, matrix4Scratch);
  126. let southMercatorY;
  127. let oneOverMercatorHeight;
  128. if (includeWebMercatorT) {
  129. southMercatorY = WebMercatorProjection.WebMercatorProjection.geodeticLatitudeToMercatorAngle(
  130. geographicSouth
  131. );
  132. oneOverMercatorHeight =
  133. 1.0 /
  134. (WebMercatorProjection.WebMercatorProjection.geodeticLatitudeToMercatorAngle(geographicNorth) -
  135. southMercatorY);
  136. }
  137. const hasExaggeration = exaggeration !== 1.0;
  138. const includeGeodeticSurfaceNormals = hasExaggeration;
  139. const dv = new DataView(buffer);
  140. let minHeight = Number.POSITIVE_INFINITY;
  141. let maxHeight = Number.NEGATIVE_INFINITY;
  142. const minimum = minimumScratch;
  143. minimum.x = Number.POSITIVE_INFINITY;
  144. minimum.y = Number.POSITIVE_INFINITY;
  145. minimum.z = Number.POSITIVE_INFINITY;
  146. const maximum = maximumScratch;
  147. maximum.x = Number.NEGATIVE_INFINITY;
  148. maximum.y = Number.NEGATIVE_INFINITY;
  149. maximum.z = Number.NEGATIVE_INFINITY;
  150. // Compute sizes
  151. let offset = 0;
  152. let size = 0;
  153. let indicesSize = 0;
  154. let quadSize;
  155. let quad;
  156. for (quad = 0; quad < 4; ++quad) {
  157. let o = offset;
  158. quadSize = dv.getUint32(o, true);
  159. o += sizeOfUint32;
  160. const x = ComponentDatatype.CesiumMath.toRadians(dv.getFloat64(o, true) * 180.0);
  161. o += sizeOfDouble;
  162. if (indexOfEpsilon(quadBorderLongitudes, x) === -1) {
  163. quadBorderLongitudes.push(x);
  164. }
  165. const y = ComponentDatatype.CesiumMath.toRadians(dv.getFloat64(o, true) * 180.0);
  166. o += sizeOfDouble;
  167. if (indexOfEpsilon(quadBorderLatitudes, y) === -1) {
  168. quadBorderLatitudes.push(y);
  169. }
  170. o += 2 * sizeOfDouble; // stepX + stepY
  171. let c = dv.getInt32(o, true); // Read point count
  172. o += sizeOfInt32;
  173. size += c;
  174. c = dv.getInt32(o, true); // Read index count
  175. indicesSize += c * 3;
  176. offset += quadSize + sizeOfUint32; // Jump to next quad
  177. }
  178. // Quad Border points to remove duplicates
  179. const quadBorderPoints = [];
  180. const quadBorderIndices = [];
  181. // Create arrays
  182. const positions = new Array(size);
  183. const uvs = new Array(size);
  184. const heights = new Array(size);
  185. const webMercatorTs = includeWebMercatorT ? new Array(size) : [];
  186. const geodeticSurfaceNormals = includeGeodeticSurfaceNormals
  187. ? new Array(size)
  188. : [];
  189. const indices = new Array(indicesSize);
  190. // Points are laid out in rows starting at SW, so storing border points as we
  191. // come across them all points will be adjacent.
  192. const westBorder = [];
  193. const southBorder = [];
  194. const eastBorder = [];
  195. const northBorder = [];
  196. // Each tile is split into 4 parts
  197. let pointOffset = 0;
  198. let indicesOffset = 0;
  199. offset = 0;
  200. for (quad = 0; quad < 4; ++quad) {
  201. quadSize = dv.getUint32(offset, true);
  202. offset += sizeOfUint32;
  203. const startQuad = offset;
  204. const originX = ComponentDatatype.CesiumMath.toRadians(dv.getFloat64(offset, true) * 180.0);
  205. offset += sizeOfDouble;
  206. const originY = ComponentDatatype.CesiumMath.toRadians(dv.getFloat64(offset, true) * 180.0);
  207. offset += sizeOfDouble;
  208. const stepX = ComponentDatatype.CesiumMath.toRadians(dv.getFloat64(offset, true) * 180.0);
  209. const halfStepX = stepX * 0.5;
  210. offset += sizeOfDouble;
  211. const stepY = ComponentDatatype.CesiumMath.toRadians(dv.getFloat64(offset, true) * 180.0);
  212. const halfStepY = stepY * 0.5;
  213. offset += sizeOfDouble;
  214. const numPoints = dv.getInt32(offset, true);
  215. offset += sizeOfInt32;
  216. const numFaces = dv.getInt32(offset, true);
  217. offset += sizeOfInt32;
  218. //const level = dv.getInt32(offset, true);
  219. offset += sizeOfInt32;
  220. // Keep track of quad indices to overall tile indices
  221. const indicesMapping = new Array(numPoints);
  222. for (let i = 0; i < numPoints; ++i) {
  223. const longitude = originX + dv.getUint8(offset++) * stepX;
  224. scratchCartographic.longitude = longitude;
  225. const latitude = originY + dv.getUint8(offset++) * stepY;
  226. scratchCartographic.latitude = latitude;
  227. let height = dv.getFloat32(offset, true);
  228. offset += sizeOfFloat;
  229. // In order to support old clients, negative altitude values are stored as
  230. // height/-2^32. Old clients see the value as really close to 0 but new clients multiply
  231. // by -2^32 to get the real negative altitude value.
  232. if (height !== 0 && height < negativeElevationThreshold) {
  233. height *= -Math.pow(2, negativeAltitudeExponentBias);
  234. }
  235. // Height is stored in units of (1/EarthRadius) or (1/6371010.0)
  236. height *= 6371010.0;
  237. scratchCartographic.height = height;
  238. // Is it along a quad border - if so check if already exists and use that index
  239. if (
  240. indexOfEpsilon(quadBorderLongitudes, longitude) !== -1 ||
  241. indexOfEpsilon(quadBorderLatitudes, latitude) !== -1
  242. ) {
  243. const index = indexOfEpsilon(
  244. quadBorderPoints,
  245. scratchCartographic,
  246. Matrix2.Cartographic
  247. );
  248. if (index === -1) {
  249. quadBorderPoints.push(Matrix2.Cartographic.clone(scratchCartographic));
  250. quadBorderIndices.push(pointOffset);
  251. } else {
  252. indicesMapping[i] = quadBorderIndices[index];
  253. continue;
  254. }
  255. }
  256. indicesMapping[i] = pointOffset;
  257. if (Math.abs(longitude - geographicWest) < halfStepX) {
  258. westBorder.push({
  259. index: pointOffset,
  260. cartographic: Matrix2.Cartographic.clone(scratchCartographic),
  261. });
  262. } else if (Math.abs(longitude - geographicEast) < halfStepX) {
  263. eastBorder.push({
  264. index: pointOffset,
  265. cartographic: Matrix2.Cartographic.clone(scratchCartographic),
  266. });
  267. } else if (Math.abs(latitude - geographicSouth) < halfStepY) {
  268. southBorder.push({
  269. index: pointOffset,
  270. cartographic: Matrix2.Cartographic.clone(scratchCartographic),
  271. });
  272. } else if (Math.abs(latitude - geographicNorth) < halfStepY) {
  273. northBorder.push({
  274. index: pointOffset,
  275. cartographic: Matrix2.Cartographic.clone(scratchCartographic),
  276. });
  277. }
  278. minHeight = Math.min(height, minHeight);
  279. maxHeight = Math.max(height, maxHeight);
  280. heights[pointOffset] = height;
  281. const pos = ellipsoid.cartographicToCartesian(scratchCartographic);
  282. positions[pointOffset] = pos;
  283. if (includeWebMercatorT) {
  284. webMercatorTs[pointOffset] =
  285. (WebMercatorProjection.WebMercatorProjection.geodeticLatitudeToMercatorAngle(latitude) -
  286. southMercatorY) *
  287. oneOverMercatorHeight;
  288. }
  289. if (includeGeodeticSurfaceNormals) {
  290. const normal = ellipsoid.geodeticSurfaceNormal(pos);
  291. geodeticSurfaceNormals[pointOffset] = normal;
  292. }
  293. Matrix2.Matrix4.multiplyByPoint(toENU, pos, scratchCartesian);
  294. Matrix2.Cartesian3.minimumByComponent(scratchCartesian, minimum, minimum);
  295. Matrix2.Cartesian3.maximumByComponent(scratchCartesian, maximum, maximum);
  296. let u = (longitude - geographicWest) / (geographicEast - geographicWest);
  297. u = ComponentDatatype.CesiumMath.clamp(u, 0.0, 1.0);
  298. let v =
  299. (latitude - geographicSouth) / (geographicNorth - geographicSouth);
  300. v = ComponentDatatype.CesiumMath.clamp(v, 0.0, 1.0);
  301. uvs[pointOffset] = new Matrix2.Cartesian2(u, v);
  302. ++pointOffset;
  303. }
  304. const facesElementCount = numFaces * 3;
  305. for (let j = 0; j < facesElementCount; ++j, ++indicesOffset) {
  306. indices[indicesOffset] = indicesMapping[dv.getUint16(offset, true)];
  307. offset += sizeOfUint16;
  308. }
  309. if (quadSize !== offset - startQuad) {
  310. throw new RuntimeError.RuntimeError("Invalid terrain tile.");
  311. }
  312. }
  313. positions.length = pointOffset;
  314. uvs.length = pointOffset;
  315. heights.length = pointOffset;
  316. if (includeWebMercatorT) {
  317. webMercatorTs.length = pointOffset;
  318. }
  319. if (includeGeodeticSurfaceNormals) {
  320. geodeticSurfaceNormals.length = pointOffset;
  321. }
  322. const vertexCountWithoutSkirts = pointOffset;
  323. const indexCountWithoutSkirts = indicesOffset;
  324. // Add skirt points
  325. const skirtOptions = {
  326. hMin: minHeight,
  327. lastBorderPoint: undefined,
  328. skirtHeight: skirtHeight,
  329. toENU: toENU,
  330. ellipsoid: ellipsoid,
  331. minimum: minimum,
  332. maximum: maximum,
  333. };
  334. // Sort counter clockwise from NW corner
  335. // Corner points are in the east/west arrays
  336. westBorder.sort(function (a, b) {
  337. return b.cartographic.latitude - a.cartographic.latitude;
  338. });
  339. southBorder.sort(function (a, b) {
  340. return a.cartographic.longitude - b.cartographic.longitude;
  341. });
  342. eastBorder.sort(function (a, b) {
  343. return a.cartographic.latitude - b.cartographic.latitude;
  344. });
  345. northBorder.sort(function (a, b) {
  346. return b.cartographic.longitude - a.cartographic.longitude;
  347. });
  348. const percentage = 0.00001;
  349. addSkirt(
  350. positions,
  351. heights,
  352. uvs,
  353. webMercatorTs,
  354. geodeticSurfaceNormals,
  355. indices,
  356. skirtOptions,
  357. westBorder,
  358. -percentage * rectangleWidth,
  359. true,
  360. -percentage * rectangleHeight
  361. );
  362. addSkirt(
  363. positions,
  364. heights,
  365. uvs,
  366. webMercatorTs,
  367. geodeticSurfaceNormals,
  368. indices,
  369. skirtOptions,
  370. southBorder,
  371. -percentage * rectangleHeight,
  372. false
  373. );
  374. addSkirt(
  375. positions,
  376. heights,
  377. uvs,
  378. webMercatorTs,
  379. geodeticSurfaceNormals,
  380. indices,
  381. skirtOptions,
  382. eastBorder,
  383. percentage * rectangleWidth,
  384. true,
  385. percentage * rectangleHeight
  386. );
  387. addSkirt(
  388. positions,
  389. heights,
  390. uvs,
  391. webMercatorTs,
  392. geodeticSurfaceNormals,
  393. indices,
  394. skirtOptions,
  395. northBorder,
  396. percentage * rectangleHeight,
  397. false
  398. );
  399. // Since the corner between the north and west sides is in the west array, generate the last
  400. // two triangles between the last north vertex and the first west vertex
  401. if (westBorder.length > 0 && northBorder.length > 0) {
  402. const firstBorderIndex = westBorder[0].index;
  403. const firstSkirtIndex = vertexCountWithoutSkirts;
  404. const lastBorderIndex = northBorder[northBorder.length - 1].index;
  405. const lastSkirtIndex = positions.length - 1;
  406. indices.push(
  407. lastBorderIndex,
  408. lastSkirtIndex,
  409. firstSkirtIndex,
  410. firstSkirtIndex,
  411. firstBorderIndex,
  412. lastBorderIndex
  413. );
  414. }
  415. size = positions.length; // Get new size with skirt vertices
  416. const boundingSphere3D = Transforms.BoundingSphere.fromPoints(positions);
  417. let orientedBoundingBox;
  418. if (defaultValue.defined(rectangle)) {
  419. orientedBoundingBox = OrientedBoundingBox.OrientedBoundingBox.fromRectangle(
  420. rectangle,
  421. minHeight,
  422. maxHeight,
  423. ellipsoid
  424. );
  425. }
  426. const occluder = new TerrainEncoding.EllipsoidalOccluder(ellipsoid);
  427. const occludeePointInScaledSpace = occluder.computeHorizonCullingPointPossiblyUnderEllipsoid(
  428. relativeToCenter,
  429. positions,
  430. minHeight
  431. );
  432. const aaBox = new AxisAlignedBoundingBox.AxisAlignedBoundingBox(minimum, maximum, relativeToCenter);
  433. const encoding = new TerrainEncoding.TerrainEncoding(
  434. relativeToCenter,
  435. aaBox,
  436. skirtOptions.hMin,
  437. maxHeight,
  438. fromENU,
  439. false,
  440. includeWebMercatorT,
  441. includeGeodeticSurfaceNormals,
  442. exaggeration,
  443. exaggerationRelativeHeight
  444. );
  445. const vertices = new Float32Array(size * encoding.stride);
  446. let bufferIndex = 0;
  447. for (let k = 0; k < size; ++k) {
  448. bufferIndex = encoding.encode(
  449. vertices,
  450. bufferIndex,
  451. positions[k],
  452. uvs[k],
  453. heights[k],
  454. undefined,
  455. webMercatorTs[k],
  456. geodeticSurfaceNormals[k]
  457. );
  458. }
  459. const westIndicesSouthToNorth = westBorder
  460. .map(function (vertex) {
  461. return vertex.index;
  462. })
  463. .reverse();
  464. const southIndicesEastToWest = southBorder
  465. .map(function (vertex) {
  466. return vertex.index;
  467. })
  468. .reverse();
  469. const eastIndicesNorthToSouth = eastBorder
  470. .map(function (vertex) {
  471. return vertex.index;
  472. })
  473. .reverse();
  474. const northIndicesWestToEast = northBorder
  475. .map(function (vertex) {
  476. return vertex.index;
  477. })
  478. .reverse();
  479. southIndicesEastToWest.unshift(
  480. eastIndicesNorthToSouth[eastIndicesNorthToSouth.length - 1]
  481. );
  482. southIndicesEastToWest.push(westIndicesSouthToNorth[0]);
  483. northIndicesWestToEast.unshift(
  484. westIndicesSouthToNorth[westIndicesSouthToNorth.length - 1]
  485. );
  486. northIndicesWestToEast.push(eastIndicesNorthToSouth[0]);
  487. return {
  488. vertices: vertices,
  489. indices: new Uint16Array(indices),
  490. maximumHeight: maxHeight,
  491. minimumHeight: minHeight,
  492. encoding: encoding,
  493. boundingSphere3D: boundingSphere3D,
  494. orientedBoundingBox: orientedBoundingBox,
  495. occludeePointInScaledSpace: occludeePointInScaledSpace,
  496. vertexCountWithoutSkirts: vertexCountWithoutSkirts,
  497. indexCountWithoutSkirts: indexCountWithoutSkirts,
  498. westIndicesSouthToNorth: westIndicesSouthToNorth,
  499. southIndicesEastToWest: southIndicesEastToWest,
  500. eastIndicesNorthToSouth: eastIndicesNorthToSouth,
  501. northIndicesWestToEast: northIndicesWestToEast,
  502. };
  503. }
  504. function addSkirt(
  505. positions,
  506. heights,
  507. uvs,
  508. webMercatorTs,
  509. geodeticSurfaceNormals,
  510. indices,
  511. skirtOptions,
  512. borderPoints,
  513. fudgeFactor,
  514. eastOrWest,
  515. cornerFudge
  516. ) {
  517. const count = borderPoints.length;
  518. for (let j = 0; j < count; ++j) {
  519. const borderPoint = borderPoints[j];
  520. const borderCartographic = borderPoint.cartographic;
  521. const borderIndex = borderPoint.index;
  522. const currentIndex = positions.length;
  523. const longitude = borderCartographic.longitude;
  524. let latitude = borderCartographic.latitude;
  525. latitude = ComponentDatatype.CesiumMath.clamp(
  526. latitude,
  527. -ComponentDatatype.CesiumMath.PI_OVER_TWO,
  528. ComponentDatatype.CesiumMath.PI_OVER_TWO
  529. ); // Don't go over the poles
  530. const height = borderCartographic.height - skirtOptions.skirtHeight;
  531. skirtOptions.hMin = Math.min(skirtOptions.hMin, height);
  532. Matrix2.Cartographic.fromRadians(longitude, latitude, height, scratchCartographic);
  533. // Adjust sides to angle out
  534. if (eastOrWest) {
  535. scratchCartographic.longitude += fudgeFactor;
  536. }
  537. // Adjust top or bottom to angle out
  538. // Since corners are in the east/west arrays angle the first and last points as well
  539. if (!eastOrWest) {
  540. scratchCartographic.latitude += fudgeFactor;
  541. } else if (j === count - 1) {
  542. scratchCartographic.latitude += cornerFudge;
  543. } else if (j === 0) {
  544. scratchCartographic.latitude -= cornerFudge;
  545. }
  546. const pos = skirtOptions.ellipsoid.cartographicToCartesian(
  547. scratchCartographic
  548. );
  549. positions.push(pos);
  550. heights.push(height);
  551. uvs.push(Matrix2.Cartesian2.clone(uvs[borderIndex])); // Copy UVs from border point
  552. if (webMercatorTs.length > 0) {
  553. webMercatorTs.push(webMercatorTs[borderIndex]);
  554. }
  555. if (geodeticSurfaceNormals.length > 0) {
  556. geodeticSurfaceNormals.push(geodeticSurfaceNormals[borderIndex]);
  557. }
  558. Matrix2.Matrix4.multiplyByPoint(skirtOptions.toENU, pos, scratchCartesian);
  559. const minimum = skirtOptions.minimum;
  560. const maximum = skirtOptions.maximum;
  561. Matrix2.Cartesian3.minimumByComponent(scratchCartesian, minimum, minimum);
  562. Matrix2.Cartesian3.maximumByComponent(scratchCartesian, maximum, maximum);
  563. const lastBorderPoint = skirtOptions.lastBorderPoint;
  564. if (defaultValue.defined(lastBorderPoint)) {
  565. const lastBorderIndex = lastBorderPoint.index;
  566. indices.push(
  567. lastBorderIndex,
  568. currentIndex - 1,
  569. currentIndex,
  570. currentIndex,
  571. borderIndex,
  572. lastBorderIndex
  573. );
  574. }
  575. skirtOptions.lastBorderPoint = borderPoint;
  576. }
  577. }
  578. var createVerticesFromGoogleEarthEnterpriseBuffer$1 = createTaskProcessorWorker(
  579. createVerticesFromGoogleEarthEnterpriseBuffer
  580. );
  581. return createVerticesFromGoogleEarthEnterpriseBuffer$1;
  582. }));
  583. //# sourceMappingURL=createVerticesFromGoogleEarthEnterpriseBuffer.js.map