createVerticesFromHeightmap.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import Ellipsoid from '../Core/Ellipsoid.js';
  2. import HeightmapEncoding from '../Core/HeightmapEncoding.js';
  3. import HeightmapTessellator from '../Core/HeightmapTessellator.js';
  4. import Rectangle from '../Core/Rectangle.js';
  5. import RuntimeError from '../Core/RuntimeError.js';
  6. import Lerc from '../ThirdParty/LercDecode.js';
  7. import createTaskProcessorWorker from './createTaskProcessorWorker.js';
  8. function createVerticesFromHeightmap(parameters, transferableObjects) {
  9. // LERC encoded buffers must be decoded, then we can process them like normal
  10. if (parameters.encoding === HeightmapEncoding.LERC) {
  11. var result;
  12. try {
  13. result = Lerc.decode(parameters.heightmap);
  14. } catch (error) {
  15. throw new RuntimeError(error);
  16. }
  17. var lercStatistics = result.statistics[0];
  18. if (lercStatistics.minValue === Number.MAX_VALUE) {
  19. throw new RuntimeError('Invalid tile data');
  20. }
  21. parameters.heightmap = result.pixels[0];
  22. parameters.width = result.width;
  23. parameters.height = result.height;
  24. }
  25. var arrayWidth = parameters.width;
  26. var arrayHeight = parameters.height;
  27. if (parameters.skirtHeight > 0.0) {
  28. arrayWidth += 2;
  29. arrayHeight += 2;
  30. }
  31. parameters.ellipsoid = Ellipsoid.clone(parameters.ellipsoid);
  32. parameters.rectangle = Rectangle.clone(parameters.rectangle);
  33. var statistics = HeightmapTessellator.computeVertices(parameters);
  34. var vertices = statistics.vertices;
  35. transferableObjects.push(vertices.buffer);
  36. return {
  37. vertices : vertices.buffer,
  38. numberOfAttributes : statistics.encoding.getStride(),
  39. minimumHeight : statistics.minimumHeight,
  40. maximumHeight : statistics.maximumHeight,
  41. gridWidth : arrayWidth,
  42. gridHeight : arrayHeight,
  43. boundingSphere3D : statistics.boundingSphere3D,
  44. orientedBoundingBox : statistics.orientedBoundingBox,
  45. occludeePointInScaledSpace : statistics.occludeePointInScaledSpace,
  46. encoding : statistics.encoding,
  47. westIndicesSouthToNorth : statistics.westIndicesSouthToNorth,
  48. southIndicesEastToWest : statistics.southIndicesEastToWest,
  49. eastIndicesNorthToSouth : statistics.eastIndicesNorthToSouth,
  50. northIndicesWestToEast : statistics.northIndicesWestToEast
  51. };
  52. }
  53. export default createTaskProcessorWorker(createVerticesFromHeightmap);