createVectorTilePoints.js 2.9 KB

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