createVectorTilePoints.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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(['./AttributeCompression-d0b97a83', './Matrix2-d35cf4b5', './ComponentDatatype-9e86ac8f', './createTaskProcessorWorker', './RuntimeError-8952249c', './defaultValue-81eec7ed', './WebGLConstants-508b9636'], (function (AttributeCompression, Matrix2, ComponentDatatype, createTaskProcessorWorker, RuntimeError, defaultValue, WebGLConstants) { 'use strict';
  24. const maxShort = 32767;
  25. const scratchBVCartographic = new Matrix2.Cartographic();
  26. const scratchEncodedPosition = new Matrix2.Cartesian3();
  27. const scratchRectangle = new Matrix2.Rectangle();
  28. const scratchEllipsoid = new Matrix2.Ellipsoid();
  29. const scratchMinMaxHeights = {
  30. min: undefined,
  31. max: undefined,
  32. };
  33. function unpackBuffer(packedBuffer) {
  34. packedBuffer = new Float64Array(packedBuffer);
  35. let offset = 0;
  36. scratchMinMaxHeights.min = packedBuffer[offset++];
  37. scratchMinMaxHeights.max = packedBuffer[offset++];
  38. Matrix2.Rectangle.unpack(packedBuffer, offset, scratchRectangle);
  39. offset += Matrix2.Rectangle.packedLength;
  40. Matrix2.Ellipsoid.unpack(packedBuffer, offset, scratchEllipsoid);
  41. }
  42. function createVectorTilePoints(parameters, transferableObjects) {
  43. const positions = new Uint16Array(parameters.positions);
  44. unpackBuffer(parameters.packedBuffer);
  45. const rectangle = scratchRectangle;
  46. const ellipsoid = scratchEllipsoid;
  47. const minimumHeight = scratchMinMaxHeights.min;
  48. const maximumHeight = scratchMinMaxHeights.max;
  49. const positionsLength = positions.length / 3;
  50. const uBuffer = positions.subarray(0, positionsLength);
  51. const vBuffer = positions.subarray(positionsLength, 2 * positionsLength);
  52. const heightBuffer = positions.subarray(
  53. 2 * positionsLength,
  54. 3 * positionsLength
  55. );
  56. AttributeCompression.AttributeCompression.zigZagDeltaDecode(uBuffer, vBuffer, heightBuffer);
  57. const decoded = new Float64Array(positions.length);
  58. for (let i = 0; i < positionsLength; ++i) {
  59. const u = uBuffer[i];
  60. const v = vBuffer[i];
  61. const h = heightBuffer[i];
  62. const lon = ComponentDatatype.CesiumMath.lerp(rectangle.west, rectangle.east, u / maxShort);
  63. const lat = ComponentDatatype.CesiumMath.lerp(rectangle.south, rectangle.north, v / maxShort);
  64. const alt = ComponentDatatype.CesiumMath.lerp(minimumHeight, maximumHeight, h / maxShort);
  65. const cartographic = Matrix2.Cartographic.fromRadians(
  66. lon,
  67. lat,
  68. alt,
  69. scratchBVCartographic
  70. );
  71. const decodedPosition = ellipsoid.cartographicToCartesian(
  72. cartographic,
  73. scratchEncodedPosition
  74. );
  75. Matrix2.Cartesian3.pack(decodedPosition, decoded, i * 3);
  76. }
  77. transferableObjects.push(decoded.buffer);
  78. return {
  79. positions: decoded.buffer,
  80. };
  81. }
  82. var createVectorTilePoints$1 = createTaskProcessorWorker(createVectorTilePoints);
  83. return createVectorTilePoints$1;
  84. }));
  85. //# sourceMappingURL=createVectorTilePoints.js.map