createVectorTilePolylines.js 7.5 KB

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