createVectorTilePolylines.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./defined-26bd4a03', './Check-da037458', './freezeObject-2d83f591', './defaultValue-f2e68450', './Math-fa6e45cb', './Cartesian2-2a723276', './defineProperties-6f7a50f2', './WebGLConstants-497deb20', './when-ee12a2cb', './AttributeCompression-87682214', './IndexDatatype-3de60176', './createTaskProcessorWorker'], function (defined, Check, freezeObject, defaultValue, _Math, Cartesian2, defineProperties, WebGLConstants, when, AttributeCompression, IndexDatatype, createTaskProcessorWorker) { 'use strict';
  3. var maxShort = 32767;
  4. var scratchBVCartographic = new Cartesian2.Cartographic();
  5. var scratchEncodedPosition = new Cartesian2.Cartesian3();
  6. function decodePositions(positions, rectangle, minimumHeight, maximumHeight, ellipsoid) {
  7. var positionsLength = positions.length / 3;
  8. var uBuffer = positions.subarray(0, positionsLength);
  9. var vBuffer = positions.subarray(positionsLength, 2 * positionsLength);
  10. var heightBuffer = positions.subarray(2 * positionsLength, 3 * positionsLength);
  11. AttributeCompression.AttributeCompression.zigZagDeltaDecode(uBuffer, vBuffer, heightBuffer);
  12. var decoded = new Float32Array(positions.length);
  13. for (var i = 0; i < positionsLength; ++i) {
  14. var u = uBuffer[i];
  15. var v = vBuffer[i];
  16. var h = heightBuffer[i];
  17. var lon = _Math.CesiumMath.lerp(rectangle.west, rectangle.east, u / maxShort);
  18. var lat = _Math.CesiumMath.lerp(rectangle.south, rectangle.north, v / maxShort);
  19. var alt = _Math.CesiumMath.lerp(minimumHeight, maximumHeight, h / maxShort);
  20. var cartographic = Cartesian2.Cartographic.fromRadians(lon, lat, alt, scratchBVCartographic);
  21. var decodedPosition = ellipsoid.cartographicToCartesian(cartographic, scratchEncodedPosition);
  22. Cartesian2.Cartesian3.pack(decodedPosition, decoded, i * 3);
  23. }
  24. return decoded;
  25. }
  26. var scratchRectangle = new Cartesian2.Rectangle();
  27. var scratchEllipsoid = new Cartesian2.Ellipsoid();
  28. var scratchCenter = new Cartesian2.Cartesian3();
  29. var scratchMinMaxHeights = {
  30. min : undefined,
  31. max : undefined
  32. };
  33. function unpackBuffer(packedBuffer) {
  34. packedBuffer = new Float64Array(packedBuffer);
  35. var offset = 0;
  36. scratchMinMaxHeights.min = packedBuffer[offset++];
  37. scratchMinMaxHeights.max = packedBuffer[offset++];
  38. Cartesian2.Rectangle.unpack(packedBuffer, offset, scratchRectangle);
  39. offset += Cartesian2.Rectangle.packedLength;
  40. Cartesian2.Ellipsoid.unpack(packedBuffer, offset, scratchEllipsoid);
  41. offset += Cartesian2.Ellipsoid.packedLength;
  42. Cartesian2.Cartesian3.unpack(packedBuffer, offset, scratchCenter);
  43. }
  44. var scratchP0 = new Cartesian2.Cartesian3();
  45. var scratchP1 = new Cartesian2.Cartesian3();
  46. var scratchPrev = new Cartesian2.Cartesian3();
  47. var scratchCur = new Cartesian2.Cartesian3();
  48. var scratchNext = new Cartesian2.Cartesian3();
  49. function createVectorTilePolylines(parameters, transferableObjects) {
  50. var encodedPositions = new Uint16Array(parameters.positions);
  51. var widths = new Uint16Array(parameters.widths);
  52. var counts = new Uint32Array(parameters.counts);
  53. var batchIds = new Uint16Array(parameters.batchIds);
  54. unpackBuffer(parameters.packedBuffer);
  55. var rectangle = scratchRectangle;
  56. var ellipsoid = scratchEllipsoid;
  57. var center = scratchCenter;
  58. var minimumHeight = scratchMinMaxHeights.min;
  59. var maximumHeight = scratchMinMaxHeights.max;
  60. var positions = decodePositions(encodedPositions, rectangle, minimumHeight, maximumHeight, ellipsoid);
  61. var positionsLength = positions.length / 3;
  62. var size = positionsLength * 4 - 4;
  63. var curPositions = new Float32Array(size * 3);
  64. var prevPositions = new Float32Array(size * 3);
  65. var nextPositions = new Float32Array(size * 3);
  66. var expandAndWidth = new Float32Array(size * 2);
  67. var vertexBatchIds = new Uint16Array(size);
  68. var positionIndex = 0;
  69. var expandAndWidthIndex = 0;
  70. var batchIdIndex = 0;
  71. var i;
  72. var offset = 0;
  73. var length = counts.length;
  74. for (i = 0; i < length; ++i) {
  75. var count = counts [i];
  76. var width = widths[i];
  77. var batchId = batchIds[i];
  78. for (var j = 0; j < count; ++j) {
  79. var previous;
  80. if (j === 0) {
  81. var p0 = Cartesian2.Cartesian3.unpack(positions, offset * 3, scratchP0);
  82. var p1 = Cartesian2.Cartesian3.unpack(positions, (offset + 1) * 3, scratchP1);
  83. previous = Cartesian2.Cartesian3.subtract(p0, p1, scratchPrev);
  84. Cartesian2.Cartesian3.add(p0, previous, previous);
  85. } else {
  86. previous = Cartesian2.Cartesian3.unpack(positions, (offset + j - 1) * 3, scratchPrev);
  87. }
  88. var current = Cartesian2.Cartesian3.unpack(positions, (offset + j) * 3, scratchCur);
  89. var next;
  90. if (j === count - 1) {
  91. var p2 = Cartesian2.Cartesian3.unpack(positions, (offset + count - 1) * 3, scratchP0);
  92. var p3 = Cartesian2.Cartesian3.unpack(positions, (offset + count - 2) * 3, scratchP1);
  93. next = Cartesian2.Cartesian3.subtract(p2, p3, scratchNext);
  94. Cartesian2.Cartesian3.add(p2, next, next);
  95. } else {
  96. next = Cartesian2.Cartesian3.unpack(positions, (offset + j + 1) * 3, scratchNext);
  97. }
  98. Cartesian2.Cartesian3.subtract(previous, center, previous);
  99. Cartesian2.Cartesian3.subtract(current, center, current);
  100. Cartesian2.Cartesian3.subtract(next, center, next);
  101. var startK = j === 0 ? 2 : 0;
  102. var endK = j === count - 1 ? 2 : 4;
  103. for (var k = startK; k < endK; ++k) {
  104. Cartesian2.Cartesian3.pack(current, curPositions, positionIndex);
  105. Cartesian2.Cartesian3.pack(previous, prevPositions, positionIndex);
  106. Cartesian2.Cartesian3.pack(next, nextPositions, positionIndex);
  107. positionIndex += 3;
  108. var direction = (k - 2 < 0) ? -1.0 : 1.0;
  109. expandAndWidth[expandAndWidthIndex++] = 2 * (k % 2) - 1;
  110. expandAndWidth[expandAndWidthIndex++] = direction * width;
  111. vertexBatchIds[batchIdIndex++] = batchId;
  112. }
  113. }
  114. offset += count;
  115. }
  116. var indices = IndexDatatype.IndexDatatype.createTypedArray(size, positionsLength * 6 - 6);
  117. var index = 0;
  118. var indicesIndex = 0;
  119. length = positionsLength - 1;
  120. for (i = 0; i < length; ++i) {
  121. indices[indicesIndex++] = index;
  122. indices[indicesIndex++] = index + 2;
  123. indices[indicesIndex++] = index + 1;
  124. indices[indicesIndex++] = index + 1;
  125. indices[indicesIndex++] = index + 2;
  126. indices[indicesIndex++] = index + 3;
  127. index += 4;
  128. }
  129. transferableObjects.push(curPositions.buffer, prevPositions.buffer, nextPositions.buffer);
  130. transferableObjects.push(expandAndWidth.buffer, vertexBatchIds.buffer, indices.buffer);
  131. return {
  132. indexDatatype : (indices.BYTES_PER_ELEMENT === 2) ? IndexDatatype.IndexDatatype.UNSIGNED_SHORT : IndexDatatype.IndexDatatype.UNSIGNED_INT,
  133. currentPositions : curPositions.buffer,
  134. previousPositions : prevPositions.buffer,
  135. nextPositions : nextPositions.buffer,
  136. expandAndWidth : expandAndWidth.buffer,
  137. batchIds : vertexBatchIds.buffer,
  138. indices : indices.buffer
  139. };
  140. }
  141. var createVectorTilePolylines$1 = createTaskProcessorWorker(createVectorTilePolylines);
  142. return createVectorTilePolylines$1;
  143. });