createVectorTilePoints.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./AttributeCompression-3cfab808', './Matrix2-69c32d33', './ComponentDatatype-b1ea011a', './createTaskProcessorWorker', './RuntimeError-c581ca93', './defaultValue-94c3e563', './WebGLConstants-7dccdc96'], (function (AttributeCompression, Matrix2, ComponentDatatype, createTaskProcessorWorker, RuntimeError, defaultValue, WebGLConstants) { 'use strict';
  3. const maxShort = 32767;
  4. const scratchBVCartographic = new Matrix2.Cartographic();
  5. const scratchEncodedPosition = new Matrix2.Cartesian3();
  6. const scratchRectangle = new Matrix2.Rectangle();
  7. const scratchEllipsoid = new Matrix2.Ellipsoid();
  8. const scratchMinMaxHeights = {
  9. min: undefined,
  10. max: undefined,
  11. };
  12. function unpackBuffer(packedBuffer) {
  13. packedBuffer = new Float64Array(packedBuffer);
  14. let offset = 0;
  15. scratchMinMaxHeights.min = packedBuffer[offset++];
  16. scratchMinMaxHeights.max = packedBuffer[offset++];
  17. Matrix2.Rectangle.unpack(packedBuffer, offset, scratchRectangle);
  18. offset += Matrix2.Rectangle.packedLength;
  19. Matrix2.Ellipsoid.unpack(packedBuffer, offset, scratchEllipsoid);
  20. }
  21. function createVectorTilePoints(parameters, transferableObjects) {
  22. const positions = new Uint16Array(parameters.positions);
  23. unpackBuffer(parameters.packedBuffer);
  24. const rectangle = scratchRectangle;
  25. const ellipsoid = scratchEllipsoid;
  26. const minimumHeight = scratchMinMaxHeights.min;
  27. const maximumHeight = scratchMinMaxHeights.max;
  28. const positionsLength = positions.length / 3;
  29. const uBuffer = positions.subarray(0, positionsLength);
  30. const vBuffer = positions.subarray(positionsLength, 2 * positionsLength);
  31. const heightBuffer = positions.subarray(
  32. 2 * positionsLength,
  33. 3 * positionsLength
  34. );
  35. AttributeCompression.AttributeCompression.zigZagDeltaDecode(uBuffer, vBuffer, heightBuffer);
  36. const decoded = new Float64Array(positions.length);
  37. for (let i = 0; i < positionsLength; ++i) {
  38. const u = uBuffer[i];
  39. const v = vBuffer[i];
  40. const h = heightBuffer[i];
  41. const lon = ComponentDatatype.CesiumMath.lerp(rectangle.west, rectangle.east, u / maxShort);
  42. const lat = ComponentDatatype.CesiumMath.lerp(rectangle.south, rectangle.north, v / maxShort);
  43. const alt = ComponentDatatype.CesiumMath.lerp(minimumHeight, maximumHeight, h / maxShort);
  44. const cartographic = Matrix2.Cartographic.fromRadians(
  45. lon,
  46. lat,
  47. alt,
  48. scratchBVCartographic
  49. );
  50. const decodedPosition = ellipsoid.cartographicToCartesian(
  51. cartographic,
  52. scratchEncodedPosition
  53. );
  54. Matrix2.Cartesian3.pack(decodedPosition, decoded, i * 3);
  55. }
  56. transferableObjects.push(decoded.buffer);
  57. return {
  58. positions: decoded.buffer,
  59. };
  60. }
  61. var createVectorTilePoints$1 = createTaskProcessorWorker(createVectorTilePoints);
  62. return createVectorTilePoints$1;
  63. }));