@woosh/meep-engine 2.97.0 → 2.98.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +861 -670
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +861 -670
  5. package/package.json +1 -1
  6. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +1 -1
  7. package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +1 -1
  8. package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray.d.ts.map +1 -1
  9. package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray.js +3 -2
  10. package/src/core/collection/array/arrayQuickSort.js +2 -2
  11. package/src/core/collection/array/array_compute_max.d.ts +9 -0
  12. package/src/core/collection/array/array_compute_max.d.ts.map +1 -0
  13. package/src/core/collection/array/{computeArrayMax.js → array_compute_max.js} +1 -1
  14. package/src/core/collection/array/array_compute_min.d.ts +9 -0
  15. package/src/core/collection/array/array_compute_min.d.ts.map +1 -0
  16. package/src/core/collection/array/{computeArrayMin.js → array_compute_min.js} +1 -1
  17. package/src/core/collection/array/array_compute_min_max.d.ts.map +1 -1
  18. package/src/core/collection/array/array_compute_min_max.js +1 -0
  19. package/src/core/collection/array/array_swap.d.ts.map +1 -1
  20. package/src/core/collection/array/array_swap.js +11 -8
  21. package/src/core/collection/array/array_swap_one.d.ts +8 -0
  22. package/src/core/collection/array/array_swap_one.d.ts.map +1 -0
  23. package/src/core/collection/array/{arraySwapElements.js → array_swap_one.js} +1 -1
  24. package/src/core/collection/array/iterator/AbstractArrayIterator.d.ts.map +1 -0
  25. package/src/core/collection/array/iterator/ArrayIteratorRandom.d.ts.map +1 -0
  26. package/src/core/collection/array/{ArrayIteratorRandom.js → iterator/ArrayIteratorRandom.js} +2 -2
  27. package/src/core/collection/array/iterator/ArrayIteratorSequential.d.ts.map +1 -0
  28. package/src/core/collection/array/randomizeArrayElementOrder.js +2 -2
  29. package/src/core/collection/map/HashMap.js +10 -10
  30. package/src/core/collection/map/ObservedMap.d.ts +7 -4
  31. package/src/core/collection/map/ObservedMap.d.ts.map +1 -1
  32. package/src/core/collection/map/ObservedMap.js +4 -1
  33. package/src/core/collection/queue/Deque.d.ts.map +1 -1
  34. package/src/core/collection/queue/Deque.js +82 -36
  35. package/src/core/collection/set/compute_set_difference.d.ts.map +1 -1
  36. package/src/core/collection/set/compute_set_difference.js +8 -0
  37. package/src/core/collection/set/compute_set_difference.spec.d.ts +2 -0
  38. package/src/core/collection/set/compute_set_difference.spec.d.ts.map +1 -0
  39. package/src/core/collection/set/compute_set_difference.spec.js +45 -0
  40. package/src/core/collection/set/compute_set_intersection.d.ts +1 -0
  41. package/src/core/collection/set/compute_set_intersection.d.ts.map +1 -1
  42. package/src/core/collection/set/compute_set_intersection.js +9 -0
  43. package/src/core/collection/set/compute_set_intersection.spec.d.ts +2 -0
  44. package/src/core/collection/set/compute_set_intersection.spec.d.ts.map +1 -0
  45. package/src/core/collection/set/compute_set_intersection.spec.js +45 -0
  46. package/src/core/collection/set/set_remove.d.ts +2 -0
  47. package/src/core/collection/set/set_remove.d.ts.map +1 -1
  48. package/src/core/collection/set/set_remove.js +2 -0
  49. package/src/core/color/oklab/XYZ.spec.d.ts +2 -0
  50. package/src/core/color/oklab/XYZ.spec.d.ts.map +1 -0
  51. package/src/core/color/oklab/XYZ.spec.js +17 -0
  52. package/src/core/color/oklab/oklab_to_xyz.d.ts +9 -0
  53. package/src/core/color/oklab/oklab_to_xyz.d.ts.map +1 -0
  54. package/src/core/color/oklab/oklab_to_xyz.js +32 -0
  55. package/src/core/color/oklab/oklab_to_xyz.spec.d.ts +2 -0
  56. package/src/core/color/oklab/oklab_to_xyz.spec.d.ts.map +1 -0
  57. package/src/core/color/oklab/oklab_to_xyz.spec.js +31 -0
  58. package/src/core/color/oklab/xyz_to_oklab.d.ts +8 -0
  59. package/src/core/color/oklab/xyz_to_oklab.d.ts.map +1 -0
  60. package/src/core/color/oklab/xyz_to_oklab.js +29 -0
  61. package/src/core/color/oklab/xyz_to_oklab.spec.d.ts +2 -0
  62. package/src/core/color/oklab/xyz_to_oklab.spec.d.ts.map +1 -0
  63. package/src/core/color/oklab/xyz_to_oklab.spec.js +31 -0
  64. package/src/core/color/sRGB/linear_to_sRGB.d.ts.map +1 -1
  65. package/src/core/color/sRGB/linear_to_sRGB.js +16 -5
  66. package/src/core/color/sRGB/sRGB_to_linear.d.ts.map +1 -1
  67. package/src/core/color/sRGB/sRGB_to_linear.js +17 -5
  68. package/src/core/color/xyz/rgb_to_xyz.d.ts +1 -0
  69. package/src/core/color/xyz/rgb_to_xyz.d.ts.map +1 -1
  70. package/src/core/color/xyz/rgb_to_xyz.js +4 -3
  71. package/src/core/color/xyz/xyz_to_rgb.d.ts +1 -1
  72. package/src/core/color/xyz/xyz_to_rgb.js +4 -4
  73. package/src/core/geom/3d/aabb/aabb3_intersects_ray.js +10 -10
  74. package/src/core/parser/simple/ParserError.d.ts +11 -6
  75. package/src/core/parser/simple/ParserError.d.ts.map +1 -1
  76. package/src/core/parser/simple/ParserError.js +51 -4
  77. package/src/core/parser/simple/Token.d.ts.map +1 -1
  78. package/src/core/parser/simple/Token.js +8 -2
  79. package/src/core/parser/simple/TokenType.d.ts +1 -5
  80. package/src/core/parser/simple/TokenType.d.ts.map +1 -1
  81. package/src/core/parser/simple/TokenType.js +1 -1
  82. package/src/core/parser/simple/readBooleanToken.d.ts.map +1 -1
  83. package/src/core/parser/simple/readBooleanToken.js +6 -1
  84. package/src/core/parser/simple/readHexToken.d.ts.map +1 -1
  85. package/src/core/parser/simple/readHexToken.js +7 -2
  86. package/src/core/parser/simple/readIdentifierToken.d.ts.map +1 -1
  87. package/src/core/parser/simple/readIdentifierToken.js +6 -1
  88. package/src/core/parser/simple/readLiteralToken.d.ts.map +1 -1
  89. package/src/core/parser/simple/readLiteralToken.js +8 -3
  90. package/src/core/parser/simple/readNumberToken.d.ts.map +1 -1
  91. package/src/core/parser/simple/readNumberToken.js +7 -2
  92. package/src/core/parser/simple/readReferenceToken.d.ts.map +1 -1
  93. package/src/core/parser/simple/readReferenceToken.js +6 -1
  94. package/src/core/parser/simple/readStringToken.d.ts.map +1 -1
  95. package/src/core/parser/simple/readStringToken.js +6 -1
  96. package/src/core/parser/simple/readUnsignedIntegerToken.d.ts.map +1 -1
  97. package/src/core/parser/simple/readUnsignedIntegerToken.js +7 -2
  98. package/src/core/parser/simple/skipWhitespace.d.ts.map +1 -1
  99. package/src/core/parser/simple/skipWhitespace.js +8 -0
  100. package/src/core/primitives/strings/string_repeat.d.ts +9 -0
  101. package/src/core/primitives/strings/string_repeat.d.ts.map +1 -0
  102. package/src/core/primitives/strings/string_repeat.js +26 -0
  103. package/src/engine/asset/AssetManager.d.ts.map +1 -1
  104. package/src/engine/development/performance/RingBufferMetric.d.ts.map +1 -1
  105. package/src/engine/development/performance/RingBufferMetric.js +5 -5
  106. package/src/engine/ecs/terrain/ecs/BuildLightTexture.d.ts.map +1 -1
  107. package/src/engine/ecs/terrain/ecs/BuildLightTexture.js +15 -22
  108. package/src/engine/graphics/ecs/camera/Camera.d.ts.map +1 -1
  109. package/src/engine/graphics/ecs/camera/Camera.js +23 -16
  110. package/src/engine/graphics/filter/ImageFilter.d.ts +2 -2
  111. package/src/engine/graphics/filter/ImageFilter.d.ts.map +1 -1
  112. package/src/engine/graphics/filter/ImageFilter.js +3 -3
  113. package/src/engine/graphics/render/RendererPool.d.ts +14 -1
  114. package/src/engine/graphics/render/RendererPool.d.ts.map +1 -1
  115. package/src/engine/graphics/render/RendererPool.js +43 -1
  116. package/src/engine/graphics/render/forward_plus/LightManager.js +2 -2
  117. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +2 -1
  118. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
  119. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +23 -50
  120. package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.d.ts +9 -0
  121. package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.d.ts.map +1 -1
  122. package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.js +53 -3
  123. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +3 -3
  124. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts +1 -1
  125. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts.map +1 -1
  126. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +42 -36
  127. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.d.ts +3 -0
  128. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.d.ts.map +1 -0
  129. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.js +34 -0
  130. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.d.ts +10 -0
  131. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.d.ts.map +1 -0
  132. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.js +89 -0
  133. package/src/engine/graphics/texture/sampler/debug/prototypeSamplerFiltering.d.ts.map +1 -0
  134. package/src/engine/graphics/texture/sampler/{prototypeSamplerFiltering.js → debug/prototypeSamplerFiltering.js} +105 -113
  135. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.d.ts.map +1 -1
  136. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.js +8 -8
  137. package/src/generation/markers/GridActionRuleSet.d.ts.map +1 -1
  138. package/src/generation/markers/GridActionRuleSet.js +5 -5
  139. package/src/core/binary/byteArrayToString.d.ts +0 -9
  140. package/src/core/binary/byteArrayToString.d.ts.map +0 -1
  141. package/src/core/binary/byteArrayToString.js +0 -28
  142. package/src/core/collection/array/AbstractArrayIterator.d.ts.map +0 -1
  143. package/src/core/collection/array/ArrayIteratorRandom.d.ts.map +0 -1
  144. package/src/core/collection/array/ArrayIteratorSequential.d.ts.map +0 -1
  145. package/src/core/collection/array/arrayPickMinElement.d.ts +0 -8
  146. package/src/core/collection/array/arrayPickMinElement.d.ts.map +0 -1
  147. package/src/core/collection/array/arrayPickMinElement.js +0 -43
  148. package/src/core/collection/array/arraySwapElements.d.ts +0 -8
  149. package/src/core/collection/array/arraySwapElements.d.ts.map +0 -1
  150. package/src/core/collection/array/computeArrayMax.d.ts +0 -9
  151. package/src/core/collection/array/computeArrayMax.d.ts.map +0 -1
  152. package/src/core/collection/array/computeArrayMin.d.ts +0 -9
  153. package/src/core/collection/array/computeArrayMin.d.ts.map +0 -1
  154. package/src/core/color/hsluv/HSLuv.d.ts +0 -13
  155. package/src/core/color/hsluv/HSLuv.d.ts.map +0 -1
  156. package/src/core/color/hsluv/HSLuv.js +0 -187
  157. package/src/engine/graphics/texture/sampler/prototypeSamplerFiltering.d.ts.map +0 -1
  158. /package/src/core/collection/array/{AbstractArrayIterator.d.ts → iterator/AbstractArrayIterator.d.ts} +0 -0
  159. /package/src/core/collection/array/{AbstractArrayIterator.js → iterator/AbstractArrayIterator.js} +0 -0
  160. /package/src/core/collection/array/{ArrayIteratorRandom.d.ts → iterator/ArrayIteratorRandom.d.ts} +0 -0
  161. /package/src/core/collection/array/{ArrayIteratorSequential.d.ts → iterator/ArrayIteratorSequential.d.ts} +0 -0
  162. /package/src/core/collection/array/{ArrayIteratorSequential.js → iterator/ArrayIteratorSequential.js} +0 -0
  163. /package/src/engine/graphics/texture/sampler/{prototypeSamplerFiltering.d.ts → debug/prototypeSamplerFiltering.d.ts} +0 -0
package/build/meep.cjs CHANGED
@@ -53177,7 +53177,7 @@ const SCRATCH_UINT32_TRAVERSAL_STACK = new Uint32Array(781250);
53177
53177
  */
53178
53178
  SCRATCH_UINT32_TRAVERSAL_STACK.pointer = 0;
53179
53179
 
53180
- const fabsf$1 = Math.abs;
53180
+ const abs = Math.abs;
53181
53181
 
53182
53182
  /**
53183
53183
  * NOTES:
@@ -53214,7 +53214,7 @@ function aabb3_intersects_ray(
53214
53214
  const diff_x = origin_x - center_x;
53215
53215
 
53216
53216
 
53217
- if (diff_x * direction_x >= 0.0 && fabsf$1(diff_x) > extents_x) {
53217
+ if (diff_x * direction_x >= 0.0 && abs(diff_x) > extents_x) {
53218
53218
  return false;
53219
53219
  }
53220
53220
 
@@ -53226,7 +53226,7 @@ function aabb3_intersects_ray(
53226
53226
  const diff_y = origin_y - center_y;
53227
53227
 
53228
53228
 
53229
- if (diff_y * direction_y >= 0.0 && fabsf$1(diff_y) > extents_y) {
53229
+ if (diff_y * direction_y >= 0.0 && abs(diff_y) > extents_y) {
53230
53230
  return false;
53231
53231
  }
53232
53232
 
@@ -53238,28 +53238,28 @@ function aabb3_intersects_ray(
53238
53238
  const diff_z = origin_z - center_z;
53239
53239
 
53240
53240
 
53241
- if (diff_z * direction_z >= 0.0 && fabsf$1(diff_z) > extents_z) {
53241
+ if (diff_z * direction_z >= 0.0 && abs(diff_z) > extents_z) {
53242
53242
  return false;
53243
53243
  }
53244
53244
 
53245
- const abs_direction_y = fabsf$1(direction_y);
53246
- const abs_direction_z = fabsf$1(direction_z);
53245
+ const abs_direction_y = abs(direction_y);
53246
+ const abs_direction_z = abs(direction_z);
53247
53247
 
53248
- const f0 = fabsf$1(direction_y * diff_z - direction_z * diff_y);
53248
+ const f0 = abs(direction_y * diff_z - direction_z * diff_y);
53249
53249
 
53250
53250
  if (f0 > extents_y * abs_direction_z + extents_z * abs_direction_y) {
53251
53251
  return false;
53252
53252
  }
53253
53253
 
53254
- const abs_direction_x = fabsf$1(direction_x);
53254
+ const abs_direction_x = abs(direction_x);
53255
53255
 
53256
- const f1 = fabsf$1(direction_z * diff_x - direction_x * diff_z);
53256
+ const f1 = abs(direction_z * diff_x - direction_x * diff_z);
53257
53257
 
53258
53258
  if (f1 > extents_x * abs_direction_z + extents_z * abs_direction_x) {
53259
53259
  return false;
53260
53260
  }
53261
53261
 
53262
- const f2 = fabsf$1(direction_x * diff_y - direction_y * diff_x);
53262
+ const f2 = abs(direction_x * diff_y - direction_y * diff_x);
53263
53263
 
53264
53264
  return f2 <= extents_x * abs_direction_y + extents_y * abs_direction_x;
53265
53265
  }
@@ -53338,8 +53338,8 @@ function bvh_query_leaves_ray(
53338
53338
  if (child_1 !== NULL_NODE) {
53339
53339
 
53340
53340
  // this is not a leaf node, push children onto traversal stack
53341
- stack$9[stack$9.pointer++] = child_1;
53342
53341
  stack$9[stack$9.pointer++] = uint32[address + COLUMN_CHILD_2];
53342
+ stack$9[stack$9.pointer++] = child_1;
53343
53343
 
53344
53344
  } else {
53345
53345
  // leaf node
@@ -53633,7 +53633,11 @@ function rgb2uint24(r, g, b) {
53633
53633
  }
53634
53634
 
53635
53635
  function convert(c) {
53636
- return (c < 0.0031308) ? c * 12.92 : 1.055 * (Math.pow(c, 0.41666)) - 0.055;
53636
+ if (c < 0.0031308) {
53637
+ return c * 12.92;
53638
+ } else {
53639
+ return 1.055 * (Math.pow(c, 0.4166666666666667)) - 0.055;
53640
+ }
53637
53641
  }
53638
53642
 
53639
53643
  /**
@@ -53643,10 +53647,17 @@ function convert(c) {
53643
53647
  * @param {number[]|ArrayLike<number>} input
53644
53648
  * @param {number} input_offset
53645
53649
  */
53646
- function linear_to_sRGB(output, output_offset, input, input_offset) {
53647
- output[output_offset] = convert(input[input_offset]);
53648
- output[output_offset + 1] = convert(input[input_offset + 1]);
53649
- output[output_offset + 2] = convert(input[input_offset + 2]);
53650
+ function linear_to_sRGB(
53651
+ output, output_offset,
53652
+ input, input_offset
53653
+ ) {
53654
+ const r = input[input_offset];
53655
+ const g = input[input_offset + 1];
53656
+ const b = input[input_offset + 2];
53657
+
53658
+ output[output_offset] = convert(r);
53659
+ output[output_offset + 1] = convert(g);
53660
+ output[output_offset + 2] = convert(b);
53650
53661
  }
53651
53662
 
53652
53663
  /**
@@ -53655,7 +53666,11 @@ function linear_to_sRGB(output, output_offset, input, input_offset) {
53655
53666
  * @return {number|number}
53656
53667
  */
53657
53668
  function convert_channel_sRGB_to_linear(c) {
53658
- return (c < 0.04045) ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
53669
+ if (c < 0.04045) {
53670
+ return c * 0.0773993808;
53671
+ } else {
53672
+ return Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
53673
+ }
53659
53674
  }
53660
53675
 
53661
53676
  /**
@@ -53665,10 +53680,18 @@ function convert_channel_sRGB_to_linear(c) {
53665
53680
  * @param {number[]} input
53666
53681
  * @param {number} input_offset
53667
53682
  */
53668
- function sRGB_to_linear(output, output_offset, input, input_offset) {
53669
- output[output_offset] = convert_channel_sRGB_to_linear(input[input_offset]);
53670
- output[output_offset + 1] = convert_channel_sRGB_to_linear(input[input_offset + 1]);
53671
- output[output_offset + 2] = convert_channel_sRGB_to_linear(input[input_offset + 2]);
53683
+ function sRGB_to_linear(
53684
+ output, output_offset,
53685
+ input, input_offset
53686
+ ) {
53687
+
53688
+ const sR = input[input_offset];
53689
+ const sG = input[input_offset + 1];
53690
+ const sB = input[input_offset + 2];
53691
+
53692
+ output[output_offset] = convert_channel_sRGB_to_linear(sR);
53693
+ output[output_offset + 1] = convert_channel_sRGB_to_linear(sG);
53694
+ output[output_offset + 2] = convert_channel_sRGB_to_linear(sB);
53672
53695
  }
53673
53696
 
53674
53697
  /**
@@ -54953,19 +54976,22 @@ function ceilPowerOfTwo(v) {
54953
54976
  * @param {number} b_offset
54954
54977
  * @param {number} length How many elements should be moved
54955
54978
  */
54956
- function array_swap(a, a_offset, b, b_offset, length) {
54957
-
54958
- let i, j, k;
54979
+ function array_swap(
54980
+ a, a_offset,
54981
+ b, b_offset,
54982
+ length
54983
+ ) {
54959
54984
 
54960
- for (k = 0; k < length; k++) {
54961
- i = a_offset + k;
54962
- j = b_offset + k;
54985
+ for (let k = 0; k < length; k++) {
54986
+ const i = a_offset + k;
54987
+ const j = b_offset + k;
54963
54988
 
54964
- const t = b[j];
54989
+ const swap = b[j];
54965
54990
 
54966
54991
  b[j] = a[i];
54967
- a[i] = t;
54992
+ a[i] = swap;
54968
54993
  }
54994
+
54969
54995
  }
54970
54996
 
54971
54997
  //
@@ -58825,25 +58851,138 @@ class TerrainTileManager {
58825
58851
  }
58826
58852
  }
58827
58853
 
58854
+ class WebGLRendererPool {
58855
+
58856
+ used = new Set();
58857
+
58858
+ get() {
58859
+ const canvas = document.createElement('canvas');
58860
+ const context = canvas.getContext('webgl2', { antialias: true });
58861
+
58862
+ const renderer = new WebGLRenderer({
58863
+ alpha: true,
58864
+ context,
58865
+ canvas
58866
+ });
58867
+
58868
+ this.used.add(renderer);
58869
+ return renderer;
58870
+ }
58871
+
58872
+ /**
58873
+ *
58874
+ * @param {THREE.WebGLRenderer} renderer
58875
+ * @returns {boolean}
58876
+ */
58877
+ release(renderer) {
58878
+ if (!this.used.has(renderer)) {
58879
+ //not from this pool
58880
+ return false;
58881
+ }
58882
+ this.used.delete(renderer);
58883
+
58884
+ renderer.forceContextLoss();
58885
+ renderer.dispose();
58886
+ renderer.domElement = null;
58887
+
58888
+ return true;
58889
+ }
58890
+
58891
+ /**
58892
+ * After callback returns, renderer is released back into the pool
58893
+ * @template T
58894
+ * @param {function(renderer:WebGLRenderer):T} callback
58895
+ * @param {*} [thisArg]
58896
+ */
58897
+ use(callback, thisArg) {
58898
+
58899
+ const renderer = this.get();
58900
+
58901
+ try {
58902
+ const result = callback.call(thisArg, renderer);
58903
+
58904
+ if (result instanceof Promise) {
58905
+ }
58906
+
58907
+ return result;
58908
+
58909
+ } finally {
58910
+
58911
+ this.release(renderer);
58912
+ }
58913
+
58914
+ }
58915
+
58916
+ /**
58917
+ * @template T
58918
+ * @param {function(renderer:WebGLRenderer):Promise<T>} callback
58919
+ * @param {*} [thisArg]
58920
+ */
58921
+ async useAsync(callback, thisArg) {
58922
+
58923
+ const renderer = this.get();
58924
+
58925
+ try {
58926
+ await callback.call(thisArg, renderer);
58927
+ } finally {
58928
+ this.release(renderer);
58929
+ }
58930
+ }
58931
+
58932
+ static global = new WebGLRendererPool();
58933
+ }
58934
+
58935
+ /**
58936
+ *
58937
+ * @param {Sampler2D} sampler
58938
+ * @param {THREE.DataTexture} texture
58939
+ */
58940
+ function writeSample2DDataToDataTexture(sampler, texture) {
58941
+ if (sampler.itemSize === 1) {
58942
+ if (texture.format !== RedFormat && texture.format !== LuminanceFormat) {
58943
+ throw new Error('itemSize is 1 and texture.format is not RedFormat');
58944
+ }
58945
+ } else if (sampler.itemSize === 2) {
58946
+ if (texture.format !== RGFormat) {
58947
+ throw new Error('itemSize is 2 and texture.format is not RGFormat');
58948
+ }
58949
+ } else if (sampler.itemSize === 3) {
58950
+ if (texture.format !== RGBFormat) {
58951
+ throw new Error('itemSize is 2 and texture.format is not RGBFormat');
58952
+ }
58953
+ } else if (sampler.itemSize === 4) {
58954
+ if (texture.format !== RGBAFormat) {
58955
+ throw new Error('itemSize is 2 and texture.format is not RGBAFormat');
58956
+ }
58957
+ } else {
58958
+ throw new Error('Unsupported itemSize');
58959
+ }
58960
+
58961
+ if (texture.image.data !== sampler.data) {
58962
+ // dispose of previous texture data
58963
+ texture.dispose();
58964
+ }
58965
+
58966
+ texture.image.data = sampler.data;
58967
+ texture.image.width = sampler.width;
58968
+ texture.image.height = sampler.height;
58969
+
58970
+ texture.needsUpdate = true;
58971
+ }
58972
+
58828
58973
  /**
58829
58974
  * Created by Alex on 10/11/2014.
58830
58975
  */
58831
58976
 
58832
- const AmbientOcclusionShader = function () {
58977
+
58978
+ const NormalMapShader = function () {
58833
58979
  return {
58834
58980
 
58835
58981
  uniforms: {
58836
58982
 
58837
- "normalMap": { type: "t", value: null },
58838
58983
  "heightMap": { type: "t", value: null },
58839
- "world_size": { type: "v2", value: new Vector2$1(512, 512) },
58840
- "rayLength": { type: 'f', value: 17 }
58841
-
58842
- },
58984
+ "resolution": { type: "v2", value: new Vector2$1(512, 512) }
58843
58985
 
58844
- defines: {
58845
- 'NUM_SAMPLES': 64,
58846
- 'NUM_RINGS': 7,
58847
58986
  },
58848
58987
 
58849
58988
  vertexShader: [
@@ -58859,102 +58998,53 @@ const AmbientOcclusionShader = function () {
58859
58998
 
58860
58999
  ].join("\n"),
58861
59000
 
59001
+ /**
59002
+ * Reference: https://stackoverflow.com/questions/49640250/calculate-normals-from-heightmap
59003
+ */
58862
59004
  fragmentShader: [
58863
- `
58864
- uniform sampler2D normalMap;
58865
- uniform sampler2D heightMap;
58866
- uniform float rayLength;
58867
- uniform vec2 world_size;
59005
+ "uniform vec2 resolution;",
59006
+ "uniform sampler2D heightMap;",
58868
59007
 
58869
- varying vec2 vUv;
59008
+ "#define sqrt2 1.41421356237;",
59009
+
59010
+ "varying vec2 vUv;",
59011
+
59012
+ "void main() {",
59013
+ " float uStep = 1.0/resolution.x;",
59014
+ " float vStep = 1.0/resolution.y;",
59015
+ //
59016
+ //
59017
+ " float top = texture2D( heightMap, vUv + vec2(0, -vStep)).x;",
59018
+ " float bottom = texture2D( heightMap, vUv + vec2(0, +vStep)).x;",
59019
+ " float left = texture2D( heightMap, vUv + vec2(-uStep, 0)).x;",
59020
+ " float right = texture2D( heightMap, vUv + vec2(+uStep, 0)).x;",
59021
+ //
59022
+
59023
+ " float dX = (right ) - ( left);",
59024
+ " float dY = ( bottom ) - ( top);",
59025
+ " float dZ = 2.0;",
59026
+ " vec3 n = normalize(vec3(dX, dY, dZ));",
59027
+
59028
+ " gl_FragColor = vec4( n*0.5+0.5, 1.0 );",
59029
+
59030
+ "}"
58870
59031
 
58871
- vec3 get(float x, float y){
58872
- vec2 _uv = vUv.xy + vec2(x,y) / world_size;
58873
- float h = texture2D(heightMap, _uv).x;
58874
- return vec3( _uv.x * world_size.x, h, _uv.y * world_size.y );
58875
- }
58876
-
58877
- float hash1( float n )
58878
- {
58879
- return fract( n*17.0*fract( n*0.3183099 ) );
58880
- }
58881
-
58882
- float hash1( vec2 p )
58883
- {
58884
- p = 50.0*fract( p*0.3183099 );
58885
- return fract( p.x*p.y*(p.x+p.y) );
58886
- }
58887
-
58888
- // Non-sin based hash function, fast and has good randomness
58889
- float hash12(vec2 p){
58890
- vec3 p3 = fract(vec3(p.xyx) * .1031);
58891
- p3 += dot(p3, p3.yzx + 33.33);
58892
- return fract((p3.x + p3.y) * p3.z);
58893
- }
58894
-
58895
- const float bias = 0.001;
58896
-
58897
- float pow2(float x){
58898
- return x*x;
58899
- }
58900
-
58901
- float getOcclusion(vec3 origin, vec3 normal, vec3 hit_position){
58902
- vec3 viewDelta = hit_position - origin;
58903
-
58904
- float viewDistance = length( viewDelta );
58905
-
58906
- float vn = dot( normal, viewDelta );
58907
- float a2 = (vn) / viewDistance - bias;
58908
- float a1 = (1.0 + pow2( viewDistance ) );
58909
-
58910
- return max(0.0, a2) / a1;
58911
- }
58912
-
58913
- const float PI2 = 6.28318530717958;
58914
- const float kernelRadius = 100.0;
58915
-
58916
- const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );
58917
- const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );
58918
-
58919
- float getAmbientOcclusion(vec3 world_position, vec3 world_normal){
58920
- // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/
58921
- float angle = hash12( vUv ) * PI2;
58922
- vec2 radius = vec2( rayLength * INV_NUM_SAMPLES );
58923
-
58924
- float occlusionSum = 0.0;
58925
- float weightSum = 0.0;
58926
-
58927
- for( int i = 0; i < NUM_SAMPLES; i ++ ) {
58928
- vec2 sampleUv = vec2( cos( angle ), sin( angle ) ) * radius * float(i+1);
58929
-
58930
- angle += ANGLE_STEP;
58931
-
58932
- vec3 sample_pos = get(sampleUv.x, sampleUv.y);
58933
-
58934
- occlusionSum += getOcclusion(world_position, world_normal, sample_pos);
58935
- weightSum += 1.0;
58936
- }
58937
-
58938
- return occlusionSum/weightSum;
58939
- }
58940
-
58941
- void main() {
58942
- vec3 pos = get(0.0, 0.0);
58943
-
58944
- vec3 normal = texture2D( normalMap, vUv ).xzy;
58945
-
58946
- float occlusion = getAmbientOcclusion(pos, normal);
58947
-
58948
- float incident = 1.0 - occlusion;
58949
-
58950
- gl_FragColor = vec4(pow(incident,10.0), 0.0, 0.0, 1.0);
58951
- }
58952
- `
58953
59032
  ].join('\n')
58954
59033
 
58955
59034
  }
58956
59035
  };
58957
59036
 
59037
+ const FULL_SCREEN_QUAD_VERTEX_SHADER = `
59038
+ varying vec2 vUv;
59039
+
59040
+ void main() {
59041
+
59042
+ vUv = uv;
59043
+
59044
+ gl_Position = vec4( (uv - 0.5)*2.0, 0.0, 1.0 );
59045
+
59046
+ }`;
59047
+
58958
59048
  const FULL_SCREEN_TRIANGLE_GEOMETRY = new BufferGeometry();
58959
59049
  FULL_SCREEN_TRIANGLE_GEOMETRY.setAttribute(
58960
59050
  'position',
@@ -58972,17 +59062,6 @@ FULL_SCREEN_TRIANGLE_GEOMETRY.setAttribute(
58972
59062
  )
58973
59063
  );
58974
59064
 
58975
- const FULL_SCREEN_QUAD_VERTEX_SHADER = `
58976
- varying vec2 vUv;
58977
-
58978
- void main() {
58979
-
58980
- vUv = uv;
58981
-
58982
- gl_Position = vec4( (uv - 0.5)*2.0, 0.0, 1.0 );
58983
-
58984
- }`;
58985
-
58986
59065
  /**
58987
59066
  * Created by Alex on 09/11/2014.
58988
59067
  */
@@ -58994,7 +59073,7 @@ const FULL_SCREEN_QUAD_VERTEX_SHADER = `
58994
59073
  * @param {number} width
58995
59074
  * @param {number} height
58996
59075
  * @param {{vertexShader?:string,fragmentShader:string, uniforms?:Object, defines?:Object}} processShader
58997
- * @param {Uint8Array} [destination]
59076
+ * @param {Uint8Array|Uint8ClampedArray} [destination]
58998
59077
  * @return {{array: Uint8Array, renderer: WebGLRenderer}}
58999
59078
  */
59000
59079
  function processTexture(
@@ -59005,7 +59084,7 @@ function processTexture(
59005
59084
  destination
59006
59085
  ) {
59007
59086
  if (destination === undefined) {
59008
- destination = new Uint8Array(width * height * 4);
59087
+ destination = new Uint8ClampedArray(width * height * 4);
59009
59088
  }
59010
59089
 
59011
59090
  //make a webgl renderer with orthographic camera
@@ -59175,6 +59254,207 @@ function sampler2DtoFloat32Texture(sampler) {
59175
59254
  return texture;
59176
59255
  }
59177
59256
 
59257
+ /**
59258
+ * Created by Alex on 15/11/2014.
59259
+ */
59260
+
59261
+
59262
+
59263
+ function convertChannel(v) {
59264
+ return (v) / 255 - 0.5;
59265
+ }
59266
+
59267
+ /**
59268
+ *
59269
+ * @param {number[]|Uint8Array} source
59270
+ * @returns {Float32Array}
59271
+ */
59272
+ function rgbaArray2RGB(source) {
59273
+ const length = source.length;
59274
+ const numPixels = Math.floor(length / 4);
59275
+ const target = new Float32Array(numPixels * 3);
59276
+ //
59277
+ let h;
59278
+ for (let i = 0; i < numPixels; i++) {
59279
+ const j = i * 4;
59280
+ const k = i * 3;
59281
+ //normalize source to normal vectors
59282
+ let x = convertChannel(source[j]);
59283
+ let y = convertChannel(source[j + 1]);
59284
+ let z = convertChannel(source[j + 2]);
59285
+ //
59286
+ h = Math.sqrt(x * x + y * y + z * z);
59287
+
59288
+ x /= h;
59289
+ y /= h;
59290
+ z /= h;
59291
+ //
59292
+ target[k] = x;
59293
+ target[k + 1] = y;
59294
+ target[k + 2] = z;
59295
+ }
59296
+ return target;
59297
+ }
59298
+
59299
+ /**
59300
+ *
59301
+ * @param {WebGLRenderer} renderer
59302
+ * @param {Sampler2D} sampler
59303
+ * @returns {Sampler2D}
59304
+ */
59305
+ function heightMap2NormalMap(renderer, sampler) {
59306
+
59307
+ const width = sampler.width;
59308
+ const height = sampler.height;
59309
+
59310
+ const texture = sampler2DtoFloat32Texture(sampler);
59311
+
59312
+ //construct shader
59313
+ const shader = new NormalMapShader();
59314
+ shader.uniforms.heightMap.value = texture;
59315
+ shader.uniforms.resolution.value.set(width, height);
59316
+
59317
+ //perform filtering
59318
+ const result = processTexture(renderer, width, height, shader);
59319
+
59320
+ //create the sampler
59321
+ const array = result.array;
59322
+ const rgb = rgbaArray2RGB(array);
59323
+
59324
+ //reduce array's alpha component
59325
+ return new Sampler2D(rgb, 3, width, height);
59326
+ }
59327
+
59328
+ /**
59329
+ * Created by Alex on 10/11/2014.
59330
+ */
59331
+
59332
+ const AmbientOcclusionShader = function () {
59333
+ return {
59334
+
59335
+ uniforms: {
59336
+
59337
+ "normalMap": { type: "t", value: null },
59338
+ "heightMap": { type: "t", value: null },
59339
+ "world_size": { type: "v2", value: new Vector2$1(512, 512) },
59340
+ "rayLength": { type: 'f', value: 17 }
59341
+
59342
+ },
59343
+
59344
+ defines: {
59345
+ 'NUM_SAMPLES': 64,
59346
+ 'NUM_RINGS': 7,
59347
+ },
59348
+
59349
+ vertexShader: [
59350
+
59351
+ "varying vec2 vUv;",
59352
+
59353
+ "void main() {",
59354
+
59355
+ "vUv = uv;",
59356
+ "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
59357
+
59358
+ "}"
59359
+
59360
+ ].join("\n"),
59361
+
59362
+ fragmentShader: [
59363
+ `
59364
+ uniform sampler2D normalMap;
59365
+ uniform sampler2D heightMap;
59366
+ uniform float rayLength;
59367
+ uniform vec2 world_size;
59368
+
59369
+ varying vec2 vUv;
59370
+
59371
+ vec3 get(float x, float y){
59372
+ vec2 _uv = vUv.xy + vec2(x,y) / world_size;
59373
+ float h = texture2D(heightMap, _uv).x;
59374
+ return vec3( _uv.x * world_size.x, h, _uv.y * world_size.y );
59375
+ }
59376
+
59377
+ float hash1( float n )
59378
+ {
59379
+ return fract( n*17.0*fract( n*0.3183099 ) );
59380
+ }
59381
+
59382
+ float hash1( vec2 p )
59383
+ {
59384
+ p = 50.0*fract( p*0.3183099 );
59385
+ return fract( p.x*p.y*(p.x+p.y) );
59386
+ }
59387
+
59388
+ // Non-sin based hash function, fast and has good randomness
59389
+ float hash12(vec2 p){
59390
+ vec3 p3 = fract(vec3(p.xyx) * .1031);
59391
+ p3 += dot(p3, p3.yzx + 33.33);
59392
+ return fract((p3.x + p3.y) * p3.z);
59393
+ }
59394
+
59395
+ const float bias = 0.001;
59396
+
59397
+ float pow2(float x){
59398
+ return x*x;
59399
+ }
59400
+
59401
+ float getOcclusion(vec3 origin, vec3 normal, vec3 hit_position){
59402
+ vec3 viewDelta = hit_position - origin;
59403
+
59404
+ float viewDistance = length( viewDelta );
59405
+
59406
+ float vn = dot( normal, viewDelta );
59407
+ float a2 = (vn) / viewDistance - bias;
59408
+ float a1 = (1.0 + pow2( viewDistance ) );
59409
+
59410
+ return max(0.0, a2) / a1;
59411
+ }
59412
+
59413
+ const float PI2 = 6.28318530717958;
59414
+ const float kernelRadius = 100.0;
59415
+
59416
+ const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );
59417
+ const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );
59418
+
59419
+ float getAmbientOcclusion(vec3 world_position, vec3 world_normal){
59420
+ // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/
59421
+ float angle = hash12( vUv ) * PI2;
59422
+ vec2 radius = vec2( rayLength * INV_NUM_SAMPLES );
59423
+
59424
+ float occlusionSum = 0.0;
59425
+ float weightSum = 0.0;
59426
+
59427
+ for( int i = 0; i < NUM_SAMPLES; i ++ ) {
59428
+ vec2 sampleUv = vec2( cos( angle ), sin( angle ) ) * radius * float(i+1);
59429
+
59430
+ angle += ANGLE_STEP;
59431
+
59432
+ vec3 sample_pos = get(sampleUv.x, sampleUv.y);
59433
+
59434
+ occlusionSum += getOcclusion(world_position, world_normal, sample_pos);
59435
+ weightSum += 1.0;
59436
+ }
59437
+
59438
+ return occlusionSum/weightSum;
59439
+ }
59440
+
59441
+ void main() {
59442
+ vec3 pos = get(0.0, 0.0);
59443
+
59444
+ vec3 normal = texture2D( normalMap, vUv ).xzy;
59445
+
59446
+ float occlusion = getAmbientOcclusion(pos, normal);
59447
+
59448
+ float incident = 1.0 - occlusion;
59449
+
59450
+ gl_FragColor = vec4(pow(incident,10.0), 0.0, 0.0, 1.0);
59451
+ }
59452
+ `
59453
+ ].join('\n')
59454
+
59455
+ }
59456
+ };
59457
+
59178
59458
  const KERNEL_SIZE = 15;
59179
59459
 
59180
59460
  const fragment$1 = `
@@ -59372,219 +59652,6 @@ function normalMap2OcclusionMap(
59372
59652
  return result;
59373
59653
  }
59374
59654
 
59375
- /**
59376
- * Created by Alex on 10/11/2014.
59377
- */
59378
-
59379
-
59380
- const NormalMapShader = function () {
59381
- return {
59382
-
59383
- uniforms: {
59384
-
59385
- "heightMap": { type: "t", value: null },
59386
- "resolution": { type: "v2", value: new Vector2$1(512, 512) }
59387
-
59388
- },
59389
-
59390
- vertexShader: [
59391
-
59392
- "varying vec2 vUv;",
59393
-
59394
- "void main() {",
59395
-
59396
- "vUv = uv;",
59397
- "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
59398
-
59399
- "}"
59400
-
59401
- ].join("\n"),
59402
-
59403
- /**
59404
- * Reference: https://stackoverflow.com/questions/49640250/calculate-normals-from-heightmap
59405
- */
59406
- fragmentShader: [
59407
- "uniform vec2 resolution;",
59408
- "uniform sampler2D heightMap;",
59409
-
59410
- "#define sqrt2 1.41421356237;",
59411
-
59412
- "varying vec2 vUv;",
59413
-
59414
- "void main() {",
59415
- " float uStep = 1.0/resolution.x;",
59416
- " float vStep = 1.0/resolution.y;",
59417
- //
59418
- //
59419
- " float top = texture2D( heightMap, vUv + vec2(0, -vStep)).x;",
59420
- " float bottom = texture2D( heightMap, vUv + vec2(0, +vStep)).x;",
59421
- " float left = texture2D( heightMap, vUv + vec2(-uStep, 0)).x;",
59422
- " float right = texture2D( heightMap, vUv + vec2(+uStep, 0)).x;",
59423
- //
59424
-
59425
- " float dX = (right ) - ( left);",
59426
- " float dY = ( bottom ) - ( top);",
59427
- " float dZ = 2.0;",
59428
- " vec3 n = normalize(vec3(dX, dY, dZ));",
59429
-
59430
- " gl_FragColor = vec4( n*0.5+0.5, 1.0 );",
59431
-
59432
- "}"
59433
-
59434
- ].join('\n')
59435
-
59436
- }
59437
- };
59438
-
59439
- /**
59440
- * Created by Alex on 15/11/2014.
59441
- */
59442
-
59443
-
59444
-
59445
- function convertChannel(v) {
59446
- return (v) / 255 - 0.5;
59447
- }
59448
-
59449
- /**
59450
- *
59451
- * @param {number[]|Uint8Array} source
59452
- * @returns {Float32Array}
59453
- */
59454
- function rgbaArray2RGB(source) {
59455
- const length = source.length;
59456
- const numPixels = Math.floor(length / 4);
59457
- const target = new Float32Array(numPixels * 3);
59458
- //
59459
- let h;
59460
- for (let i = 0; i < numPixels; i++) {
59461
- const j = i * 4;
59462
- const k = i * 3;
59463
- //normalize source to normal vectors
59464
- let x = convertChannel(source[j]);
59465
- let y = convertChannel(source[j + 1]);
59466
- let z = convertChannel(source[j + 2]);
59467
- //
59468
- h = Math.sqrt(x * x + y * y + z * z);
59469
-
59470
- x /= h;
59471
- y /= h;
59472
- z /= h;
59473
- //
59474
- target[k] = x;
59475
- target[k + 1] = y;
59476
- target[k + 2] = z;
59477
- }
59478
- return target;
59479
- }
59480
-
59481
- /**
59482
- *
59483
- * @param {WebGLRenderer} renderer
59484
- * @param {Sampler2D} sampler
59485
- * @returns {Sampler2D}
59486
- */
59487
- function heightMap2NormalMap(renderer, sampler) {
59488
-
59489
- const width = sampler.width;
59490
- const height = sampler.height;
59491
-
59492
- const texture = sampler2DtoFloat32Texture(sampler);
59493
-
59494
- //construct shader
59495
- const shader = new NormalMapShader();
59496
- shader.uniforms.heightMap.value = texture;
59497
- shader.uniforms.resolution.value.set(width, height);
59498
-
59499
- //perform filtering
59500
- const result = processTexture(renderer, width, height, shader);
59501
-
59502
- //create the sampler
59503
- const array = result.array;
59504
- const rgb = rgbaArray2RGB(array);
59505
-
59506
- //reduce array's alpha component
59507
- return new Sampler2D(rgb, 3, width, height);
59508
- }
59509
-
59510
- class WebGLRendererPool {
59511
-
59512
- used = new Set();
59513
-
59514
- get(options) {
59515
- const canvas = document.createElement('canvas');
59516
- const context = canvas.getContext('webgl2', { antialias: true });
59517
-
59518
- const renderer = new WebGLRenderer({
59519
- alpha: true,
59520
- context,
59521
- canvas
59522
- });
59523
-
59524
- this.used.add(renderer);
59525
- return renderer;
59526
- }
59527
-
59528
- /**
59529
- *
59530
- * @param {THREE.WebGLRenderer} renderer
59531
- * @returns {boolean}
59532
- */
59533
- release(renderer) {
59534
- if (!this.used.has(renderer)) {
59535
- //not from this pool
59536
- return false;
59537
- }
59538
- this.used.delete(renderer);
59539
-
59540
- renderer.forceContextLoss();
59541
- renderer.dispose();
59542
- renderer.domElement = null;
59543
-
59544
- return true;
59545
- }
59546
-
59547
- static global = new WebGLRendererPool();
59548
- }
59549
-
59550
- /**
59551
- *
59552
- * @param {Sampler2D} sampler
59553
- * @param {THREE.DataTexture} texture
59554
- */
59555
- function writeSample2DDataToDataTexture(sampler, texture) {
59556
- if (sampler.itemSize === 1) {
59557
- if (texture.format !== RedFormat && texture.format !== LuminanceFormat) {
59558
- throw new Error('itemSize is 1 and texture.format is not RedFormat');
59559
- }
59560
- } else if (sampler.itemSize === 2) {
59561
- if (texture.format !== RGFormat) {
59562
- throw new Error('itemSize is 2 and texture.format is not RGFormat');
59563
- }
59564
- } else if (sampler.itemSize === 3) {
59565
- if (texture.format !== RGBFormat) {
59566
- throw new Error('itemSize is 2 and texture.format is not RGBFormat');
59567
- }
59568
- } else if (sampler.itemSize === 4) {
59569
- if (texture.format !== RGBAFormat) {
59570
- throw new Error('itemSize is 2 and texture.format is not RGBAFormat');
59571
- }
59572
- } else {
59573
- throw new Error('Unsupported itemSize');
59574
- }
59575
-
59576
- if (texture.image.data !== sampler.data) {
59577
- // dispose of previous texture data
59578
- texture.dispose();
59579
- }
59580
-
59581
- texture.image.data = sampler.data;
59582
- texture.image.width = sampler.width;
59583
- texture.image.height = sampler.height;
59584
-
59585
- texture.needsUpdate = true;
59586
- }
59587
-
59588
59655
  /**
59589
59656
  *
59590
59657
  * @param {WebGLRenderer} renderer
@@ -59653,32 +59720,25 @@ function promiseSamplerAO(
59653
59720
  function buildLightTexture({
59654
59721
  texture,
59655
59722
  heightSampler,
59656
- resolution= new Vector2(texture.image.width, texture.image.height),
59723
+ resolution = new Vector2(texture.image.width, texture.image.height),
59657
59724
  rayLength = 11,
59658
59725
  worldSize = resolution
59659
59726
  }) {
59660
59727
 
59661
- const renderer = WebGLRendererPool.global.get();
59728
+ return WebGLRendererPool.global.useAsync(async renderer => {
59729
+ const normal = promiseSamplerNormal(renderer, heightSampler);
59662
59730
 
59663
- const normal = promiseSamplerNormal(renderer, heightSampler);
59664
- const ao = promiseSamplerAO({
59665
- renderer: renderer,
59666
- pSamplerNormal: normal,
59667
- samplerHeight: heightSampler,
59668
- resolution: resolution,
59669
- rayLength: rayLength,
59670
- worldSize
59671
- });
59672
-
59673
- const promise = ao.then(sampler => {
59674
- writeSample2DDataToDataTexture(sampler, texture);
59675
- });
59731
+ const ao = await promiseSamplerAO({
59732
+ renderer: renderer,
59733
+ pSamplerNormal: normal,
59734
+ samplerHeight: heightSampler,
59735
+ resolution: resolution,
59736
+ rayLength: rayLength,
59737
+ worldSize
59738
+ });
59676
59739
 
59677
- Promise.all([normal, ao]).finally(() => {
59678
- WebGLRendererPool.global.release(renderer);
59740
+ writeSample2DDataToDataTexture(ao, texture);
59679
59741
  });
59680
-
59681
- return promise;
59682
59742
  }
59683
59743
 
59684
59744
  const GridTransformKind = {
@@ -59767,7 +59827,7 @@ function invokeObjectHash(object) {
59767
59827
  * @param {number} index0
59768
59828
  * @param {number} index1
59769
59829
  */
59770
- function arraySwapElements(array, index0, index1) {
59830
+ function array_swap_one(array, index0, index1) {
59771
59831
  const t = array[index0];
59772
59832
 
59773
59833
  array[index0] = array[index1];
@@ -59821,7 +59881,7 @@ function generate_next_linear_congruential_index(index, mask) {
59821
59881
  /**
59822
59882
  * @template K,V
59823
59883
  */
59824
- class MapEntry {
59884
+ class HashMapEntry {
59825
59885
  /**
59826
59886
  *
59827
59887
  * @param {K} key
@@ -59909,7 +59969,7 @@ const UNDEFINED_BIN_INDEX = ~0;
59909
59969
 
59910
59970
  /**
59911
59971
  * @template K,V
59912
- * @param {MapEntry<K,V>} record
59972
+ * @param {HashMapEntry<K,V>} record
59913
59973
  * @param {number} hash
59914
59974
  * @param {K} key
59915
59975
  * @param {function(a:K,b:K):boolean} equality_op
@@ -59949,7 +60009,7 @@ class HashMap {
59949
60009
 
59950
60010
  /**
59951
60011
  * Note that dead entries are marked as such with a special reserved hash values, so records can be reused for new entries
59952
- * @type {Array<MapEntry<K,V>>}
60012
+ * @type {Array<HashMapEntry<K,V>>}
59953
60013
  */
59954
60014
  #entries = new Array(0);
59955
60015
 
@@ -60127,7 +60187,7 @@ class HashMap {
60127
60187
  entry.key = k;
60128
60188
  entry.value = v;
60129
60189
  } else {
60130
- this.#entries[i] = new MapEntry(k, v, hash);
60190
+ this.#entries[i] = new HashMapEntry(k, v, hash);
60131
60191
  }
60132
60192
 
60133
60193
  return i;
@@ -60135,7 +60195,7 @@ class HashMap {
60135
60195
 
60136
60196
  /**
60137
60197
  *
60138
- * @param {MapEntry<K,V>} entry
60198
+ * @param {HashMapEntry<K,V>} entry
60139
60199
  */
60140
60200
  #deallocate(entry) {
60141
60201
 
@@ -60392,7 +60452,7 @@ class HashMap {
60392
60452
  }
60393
60453
 
60394
60454
  /**
60395
- * @type {MapEntry<K,V>}
60455
+ * @type {HashMapEntry<K,V>}
60396
60456
  */
60397
60457
  const entry = this.#entries[bin - ENTRY_BASE];
60398
60458
 
@@ -60443,7 +60503,7 @@ class HashMap {
60443
60503
 
60444
60504
  if (new_index !== existing_entry_index) {
60445
60505
  // move entries to the new position, compacting holes
60446
- arraySwapElements(entries, new_index, existing_entry_index);
60506
+ array_swap_one(entries, new_index, existing_entry_index);
60447
60507
  }
60448
60508
 
60449
60509
  let bin_index = this.#compute_bin_index(hash);
@@ -60497,7 +60557,7 @@ class HashMap {
60497
60557
  }
60498
60558
 
60499
60559
  /**
60500
- * @type {MapEntry<K,V>}
60560
+ * @type {HashMapEntry<K,V>}
60501
60561
  */
60502
60562
  const entry = entries[bin - ENTRY_BASE];
60503
60563
 
@@ -60568,7 +60628,7 @@ class HashMap {
60568
60628
  }
60569
60629
 
60570
60630
  /**
60571
- * @type {MapEntry<K,V>}
60631
+ * @type {HashMapEntry<K,V>}
60572
60632
  */
60573
60633
  const entry = entries[bin - ENTRY_BASE];
60574
60634
 
@@ -67266,6 +67326,37 @@ function computeFileExtension(path) {
67266
67326
  }
67267
67327
  }
67268
67328
 
67329
+ /**
67330
+ * @param {Uint8Array} input
67331
+ * @param {number} width
67332
+ * @param {number} height
67333
+ * @param {number} channel_count
67334
+ */
67335
+ function flipArrayInPlace(input, width, height, channel_count = 4) {
67336
+ const row_size = width * channel_count;
67337
+ let t, x0, x1;
67338
+ let i = 0;
67339
+ const column_count = height >> 1;
67340
+
67341
+ for (; i < column_count; i++) {
67342
+
67343
+ //swap lines
67344
+ const k = (height - i - 1) * row_size;
67345
+ const m = i * row_size;
67346
+
67347
+ for (let j = 0; j < row_size; j++) {
67348
+ x0 = m + j;
67349
+ x1 = k + j;
67350
+
67351
+ t = input[x0];
67352
+
67353
+ input[x0] = input[x1];
67354
+ input[x1] = t;
67355
+ }
67356
+
67357
+ }
67358
+ }
67359
+
67269
67360
  /**
67270
67361
  * @author alteredq / http://alteredqualia.com/
67271
67362
  *
@@ -67312,37 +67403,6 @@ const CopyShader = {
67312
67403
 
67313
67404
  };
67314
67405
 
67315
- /**
67316
- * @param {Uint8Array} input
67317
- * @param {number} width
67318
- * @param {number} height
67319
- * @param {number} channel_count
67320
- */
67321
- function flipArrayInPlace(input, width, height, channel_count = 4) {
67322
- const row_size = width * channel_count;
67323
- let t, x0, x1;
67324
- let i = 0;
67325
- const column_count = height >> 1;
67326
-
67327
- for (; i < column_count; i++) {
67328
-
67329
- //swap lines
67330
- const k = (height - i - 1) * row_size;
67331
- const m = i * row_size;
67332
-
67333
- for (let j = 0; j < row_size; j++) {
67334
- x0 = m + j;
67335
- x1 = k + j;
67336
-
67337
- t = input[x0];
67338
-
67339
- input[x0] = input[x1];
67340
- input[x1] = t;
67341
- }
67342
-
67343
- }
67344
- }
67345
-
67346
67406
  const DEFAULT_TEXTURE_WIDTH = 512;
67347
67407
  const DEFAULT_TEXTURE_HEIGHT = 512;
67348
67408
 
@@ -67351,39 +67411,47 @@ const DEFAULT_TEXTURE_HEIGHT = 512;
67351
67411
  * @param {Texture} texture
67352
67412
  * @param {number} [width]
67353
67413
  * @param {number} [height]
67354
- * @param {boolean} flipY
67414
+ * @param {boolean} [flipY]
67355
67415
  * @return {Sampler2D}
67356
67416
  */
67357
- function convertTexture2Sampler2D(texture, width, height, flipY = true) {
67417
+ function convertTexture2Sampler2D(
67418
+ texture,
67419
+ width,
67420
+ height,
67421
+ flipY = true
67422
+ ) {
67423
+ let _height = height;
67424
+ let _width = width;
67425
+
67358
67426
  // TODO take channel count into account
67359
67427
 
67360
- if (width === undefined || height === undefined) {
67428
+ if (_width === undefined || _height === undefined) {
67361
67429
 
67362
67430
  //figure out texture size
67363
67431
  const image = texture.image;
67364
67432
 
67365
67433
  if (image !== undefined && image !== null) {
67366
- if (width === undefined) {
67434
+ if (_width === undefined) {
67367
67435
  if (typeof image.width === "number") {
67368
- width = image.width;
67436
+ _width = image.width;
67369
67437
  } else {
67370
- width = DEFAULT_TEXTURE_WIDTH;
67438
+ _width = DEFAULT_TEXTURE_WIDTH;
67371
67439
  }
67372
67440
  }
67373
- if (height === undefined) {
67441
+ if (_height === undefined) {
67374
67442
  if (typeof image.height === "number") {
67375
- height = image.height;
67443
+ _height = image.height;
67376
67444
  } else {
67377
- height = DEFAULT_TEXTURE_HEIGHT;
67445
+ _height = DEFAULT_TEXTURE_HEIGHT;
67378
67446
  }
67379
67447
  }
67380
67448
  } else {
67381
- if (width === undefined) {
67382
- width = DEFAULT_TEXTURE_WIDTH;
67449
+ if (_width === undefined) {
67450
+ _width = DEFAULT_TEXTURE_WIDTH;
67383
67451
  }
67384
67452
 
67385
- if (height === undefined) {
67386
- height = DEFAULT_TEXTURE_HEIGHT;
67453
+ if (_height === undefined) {
67454
+ _height = DEFAULT_TEXTURE_HEIGHT;
67387
67455
  }
67388
67456
  }
67389
67457
 
@@ -67391,34 +67459,32 @@ function convertTexture2Sampler2D(texture, width, height, flipY = true) {
67391
67459
 
67392
67460
  // TODO add special case for DataTexture
67393
67461
 
67394
- const renderer = WebGLRendererPool.global.get({});
67462
+ const built = WebGLRendererPool.global.use(renderer => {
67395
67463
 
67396
- const ctx = renderer.getContext();
67464
+ const ctx = renderer.getContext();
67397
67465
 
67398
- //support for compressed textures
67399
- ctx.getExtension("WEBGL_compressed_texture_s3tc");
67466
+ //support for compressed textures
67467
+ ctx.getExtension("WEBGL_compressed_texture_s3tc");
67400
67468
 
67401
- const built = processTexture(renderer, width, height, {
67402
- vertexShader: CopyShader.vertexShader,
67403
- fragmentShader: CopyShader.fragmentShader,
67404
- uniforms: {
67405
- tDiffuse: {
67406
- value: texture,
67407
- type: 't'
67408
- },
67409
- opacity: { value: 1.0 }
67410
- }
67411
- });
67469
+ return processTexture(renderer, _width, _height, {
67470
+ vertexShader: CopyShader.vertexShader,
67471
+ fragmentShader: CopyShader.fragmentShader,
67472
+ uniforms: {
67473
+ tDiffuse: {
67474
+ value: texture,
67475
+ type: 't'
67476
+ },
67477
+ opacity: { value: 1.0 }
67478
+ }
67479
+ });
67412
67480
 
67413
- WebGLRendererPool.global.release(renderer);
67481
+ });
67414
67482
 
67415
67483
  if (flipY) {
67416
- flipArrayInPlace(built.array, width, height);
67484
+ flipArrayInPlace(built.array, _width, _height);
67417
67485
  }
67418
67486
 
67419
- const sampler = new Sampler2D(built.array, 4, width, height);
67420
-
67421
- return sampler;
67487
+ return new Sampler2D(built.array, 4, _width, _height);
67422
67488
  }
67423
67489
 
67424
67490
  /**
@@ -69049,10 +69115,14 @@ class Camera {
69049
69115
  * @param {Camera|THREE.PerspectiveCamera|THREE.OrthographicCamera} camera
69050
69116
  * @param {number} x
69051
69117
  * @param {number} y
69052
- * @param {Vector3} source
69053
- * @param {Vector3} direction
69118
+ * @param {Vector3} out_source
69119
+ * @param {Vector3} out_direction
69054
69120
  */
69055
- static projectRay(camera, x, y, source, direction) {
69121
+ static projectRay(
69122
+ camera,
69123
+ x, y,
69124
+ out_source, out_direction
69125
+ ) {
69056
69126
 
69057
69127
  // assert.ok(x >= -1, `X(=${x}) must be greater than or equal to -1.0, not a clip-space coordinate`);
69058
69128
  // assert.ok(x <= 1, `X(=${x}) must be less than or equal to 1.0, not a clip-space coordinate`);
@@ -69061,7 +69131,10 @@ class Camera {
69061
69131
  // assert.ok(y <= 1, `Y(=${y}) must be less than or equal to 1.0, not a clip-space coordinate`);
69062
69132
 
69063
69133
  if (camera.isPerspectiveCamera || camera.isOrthographicCamera) {
69064
- scratch_v3_1.setFromMatrixPosition(camera.matrixWorld.elements);
69134
+ const m4_world = camera.matrixWorld.elements;
69135
+ const m4_projection_inverse = camera.projectionMatrixInverse.elements;
69136
+
69137
+ scratch_v3_1.setFromMatrixPosition(m4_world);
69065
69138
 
69066
69139
  scratch_v3_0.set(x, y, 0.5);
69067
69140
 
@@ -69070,16 +69143,16 @@ class Camera {
69070
69143
  unprojectPoint(
69071
69144
  scratch_v3_0,
69072
69145
  scratch_v3_0,
69073
- camera.projectionMatrixInverse.elements,
69074
- camera.matrixWorld.elements
69146
+ m4_projection_inverse,
69147
+ m4_world
69075
69148
  );
69076
69149
 
69077
69150
  //get direction
69078
69151
  scratch_v3_0.sub(scratch_v3_1);
69079
69152
  scratch_v3_0.normalize();
69080
69153
 
69081
- source.copy(scratch_v3_1);
69082
- direction.copy(scratch_v3_0);
69154
+ out_source.copy(scratch_v3_1);
69155
+ out_direction.copy(scratch_v3_0);
69083
69156
 
69084
69157
  } else {
69085
69158
  throw new Error('Unsupported camera type');
@@ -74590,7 +74663,7 @@ function arrayQuickSort(
74590
74663
  data,
74591
74664
  score_function, score_function_context,
74592
74665
  start, end,
74593
- swap_operator = arraySwapElements, swap_context = undefined
74666
+ swap_operator = array_swap_one, swap_context = undefined
74594
74667
  ) {
74595
74668
  if (start >= end) {
74596
74669
  // section of 0 size, nothing to sort
@@ -81315,6 +81388,7 @@ class Token {
81315
81388
  * @param {T} type
81316
81389
  */
81317
81390
  constructor(value, start, end, name, type) {
81391
+
81318
81392
  /**
81319
81393
  * @readonly
81320
81394
  * @type {V}
@@ -81364,8 +81438,7 @@ class Token {
81364
81438
  * @return {number}
81365
81439
  */
81366
81440
  hash() {
81367
- // TODO make an actual hash
81368
- return 0;
81441
+ return this.start ^ (this.end << 16);
81369
81442
  }
81370
81443
  }
81371
81444
 
@@ -81381,10 +81454,71 @@ const TooltipTokenType = {
81381
81454
  ReferenceValue: 4,
81382
81455
  };
81383
81456
 
81384
- function ParserError(position, message, input) {
81385
- this.position = position;
81386
- this.message = message;
81387
- this.input = input;
81457
+ /**
81458
+ * Repeat a given piece of text a {@link count} times
81459
+ * @example "ABC_" repeated 2 times results in "ABC_ABC_"
81460
+ * @param {string} what
81461
+ * @param {number} count
81462
+ * @return {string}
81463
+ */
81464
+ function string_repeat(what, count) {
81465
+
81466
+ if (count <= 0) {
81467
+ // special case
81468
+ return "";
81469
+ }
81470
+
81471
+ let out = what;
81472
+
81473
+ for (let i = 1; i < count; i++) {
81474
+ out += what;
81475
+ }
81476
+
81477
+ return out;
81478
+ }
81479
+
81480
+ class ParserError extends Error {
81481
+ /**
81482
+ *
81483
+ * @param {number} position
81484
+ * @param {string} message
81485
+ * @param {string} input
81486
+ */
81487
+ constructor(
81488
+ position,
81489
+ message,
81490
+ input
81491
+ ) {
81492
+
81493
+ super();
81494
+
81495
+ this.position = position;
81496
+ this.message = message;
81497
+ this.input = input;
81498
+ }
81499
+
81500
+ getDetails() {
81501
+ const input = this.input;
81502
+ const position = this.position;
81503
+
81504
+ // get snippet around where the problem has occurred
81505
+ const input_start = max2(0, position - 10);
81506
+
81507
+ const input_end = min2(input.length, position + 10);
81508
+
81509
+ const snippet = input.slice(input_start, input_end);
81510
+
81511
+ const offset_into_snippet = position - input_start;
81512
+
81513
+ // a piece of text with marker to show where the error occurs
81514
+ const arrow_text = string_repeat(" ", offset_into_snippet) + "^";
81515
+
81516
+ return snippet + "\n" + arrow_text;
81517
+ }
81518
+
81519
+ toString() {
81520
+ return `[ParseError] ${this.message}. Error at position ${this.position} near:\n${this.getDetails()}`
81521
+ }
81388
81522
  }
81389
81523
 
81390
81524
  /**
@@ -81480,28 +81614,6 @@ class KeyValuePair {
81480
81614
  }
81481
81615
  }
81482
81616
 
81483
- /**
81484
- *
81485
- * @param {string} text
81486
- * @param {number} cursor
81487
- * @param {number} length
81488
- * @returns {number}
81489
- */
81490
- function skipWhitespace(text, cursor, length) {
81491
- let i = cursor;
81492
- let char;
81493
- while (i < length) {
81494
- char = text.charAt(i);
81495
-
81496
- if (char === ' ' || char === '\n' || char === '\t') {
81497
- i++;
81498
- } else {
81499
- break;
81500
- }
81501
- }
81502
- return i;
81503
- }
81504
-
81505
81617
  /**
81506
81618
  *
81507
81619
  * @enum {string}
@@ -81516,7 +81628,7 @@ const DataType = {
81516
81628
  };
81517
81629
 
81518
81630
  /**
81519
- * @enum {{LiteralString: string, LiteralNumber: string, LiteralBoolean: string}}
81631
+ * @enum {string}
81520
81632
  */
81521
81633
  const TokenType = {
81522
81634
  LiteralString: "literal-string",
@@ -81534,6 +81646,7 @@ const TokenType = {
81534
81646
  * @returns {Token}
81535
81647
  */
81536
81648
  function readBooleanToken(text, cursor, length) {
81649
+
81537
81650
  const firstChar = text.charAt(cursor);
81538
81651
 
81539
81652
  let value;
@@ -81560,96 +81673,6 @@ function readBooleanToken(text, cursor, length) {
81560
81673
  return new Token(value, cursor, end, TokenType.LiteralBoolean, DataType.Boolean);
81561
81674
  }
81562
81675
 
81563
- /**
81564
- *
81565
- * @param {string} text
81566
- * @param {number} cursor
81567
- * @returns {string}
81568
- */
81569
- function readQuote(text, cursor) {
81570
- const char = text.charAt(cursor);
81571
-
81572
- if (char !== '"' && char !== '\'') {
81573
- throw new ParserError(cursor, "Expected \", found " + char + " instead", text);
81574
- }
81575
-
81576
- return char;
81577
- }
81578
-
81579
- /**
81580
- *
81581
- * @param {string} text
81582
- * @param {number} cursor
81583
- * @param {number} length
81584
- * @returns {Token}
81585
- */
81586
- function readStringToken(text, cursor, length) {
81587
- let i = cursor;
81588
-
81589
- const openingQuote = readQuote(text, i);
81590
-
81591
- i++;
81592
-
81593
- let char;
81594
-
81595
- let value = '';
81596
- const lastPossibleChar = length - 1;
81597
-
81598
- for (; i < lastPossibleChar; i++) {
81599
- char = text.charAt(i);
81600
-
81601
- if (char === '\\') {
81602
- i++;
81603
- //read escape sequence
81604
- char = text.charAt(i);
81605
-
81606
- switch (char) {
81607
- case 'n':
81608
- value += '\n';
81609
- break;
81610
- case 't':
81611
- value += '\t';
81612
- break;
81613
- case 'r':
81614
- value += '\r';
81615
- break;
81616
- case 'b':
81617
- value += '\b';
81618
- break;
81619
- case 'f':
81620
- value += '\f';
81621
- break;
81622
- case 'v':
81623
- value += '\v';
81624
- break;
81625
- case '0':
81626
- value += '\0';
81627
- break;
81628
- case '\\':
81629
- case "'":
81630
- case '"':
81631
- default:
81632
- value += char;
81633
- break;
81634
- }
81635
- } else if (char !== openingQuote) {
81636
- value += char;
81637
- } else {
81638
- break;
81639
- }
81640
- }
81641
-
81642
- char = text.charAt(i);
81643
-
81644
- if (char !== openingQuote) {
81645
- throw new ParserError(cursor, "Expected string terminator : " + openingQuote + ", but found '" + char + "' instead", text);
81646
- }
81647
-
81648
- i++;
81649
-
81650
- return new Token(value, cursor, i, TokenType.LiteralString, DataType.String);
81651
- }
81652
-
81653
81676
  /**
81654
81677
  *
81655
81678
  * @param {string} text
@@ -81658,6 +81681,7 @@ function readStringToken(text, cursor, length) {
81658
81681
  * @returns {Token}
81659
81682
  */
81660
81683
  function readHexToken(text, cursor, length) {
81684
+
81661
81685
  const c0 = text.charAt(cursor);
81662
81686
  const c1 = text.charAt(cursor + 1);
81663
81687
 
@@ -81739,7 +81763,7 @@ function readHexToken(text, cursor, length) {
81739
81763
  }
81740
81764
 
81741
81765
 
81742
- return new Token(value, cursor, i, null, DataType.Number);
81766
+ return new Token(value, cursor, i, "uint", DataType.Number);
81743
81767
  }
81744
81768
 
81745
81769
  /**
@@ -81750,6 +81774,7 @@ function readHexToken(text, cursor, length) {
81750
81774
  * @returns {Token}
81751
81775
  */
81752
81776
  function readUnsignedIntegerToken(text, cursor, length) {
81777
+
81753
81778
  let i = cursor;
81754
81779
 
81755
81780
  let value = 0;
@@ -81801,7 +81826,32 @@ function readUnsignedIntegerToken(text, cursor, length) {
81801
81826
  }
81802
81827
 
81803
81828
 
81804
- return new Token(value, cursor, i, null, DataType.Number);
81829
+ return new Token(value, cursor, i, "uint", DataType.Number);
81830
+ }
81831
+
81832
+ /**
81833
+ *
81834
+ * @param {string} text
81835
+ * @param {number} cursor
81836
+ * @param {number} length
81837
+ * @returns {number}
81838
+ */
81839
+ function skipWhitespace(text, cursor, length) {
81840
+
81841
+ let i = cursor;
81842
+ let char;
81843
+
81844
+ while (i < length) {
81845
+ char = text.charAt(i);
81846
+
81847
+ if (char === ' ' || char === '\n' || char === '\t') {
81848
+ i++;
81849
+ } else {
81850
+ break;
81851
+ }
81852
+ }
81853
+
81854
+ return i;
81805
81855
  }
81806
81856
 
81807
81857
  /**
@@ -81812,6 +81862,7 @@ function readUnsignedIntegerToken(text, cursor, length) {
81812
81862
  * @returns {Token}
81813
81863
  */
81814
81864
  function readNumberToken(text, cursor, length) {
81865
+
81815
81866
  let i = cursor;
81816
81867
 
81817
81868
  //read optional sign
@@ -81871,6 +81922,97 @@ function readNumberToken(text, cursor, length) {
81871
81922
  return new Token(value, cursor, i, TokenType.LiteralNumber, DataType.Number);
81872
81923
  }
81873
81924
 
81925
+ /**
81926
+ *
81927
+ * @param {string} text
81928
+ * @param {number} cursor
81929
+ * @returns {string}
81930
+ */
81931
+ function readQuote(text, cursor) {
81932
+ const char = text.charAt(cursor);
81933
+
81934
+ if (char !== '"' && char !== '\'') {
81935
+ throw new ParserError(cursor, "Expected \", found " + char + " instead", text);
81936
+ }
81937
+
81938
+ return char;
81939
+ }
81940
+
81941
+ /**
81942
+ *
81943
+ * @param {string} text
81944
+ * @param {number} cursor
81945
+ * @param {number} length
81946
+ * @returns {Token}
81947
+ */
81948
+ function readStringToken(text, cursor, length) {
81949
+
81950
+ let i = cursor;
81951
+
81952
+ const openingQuote = readQuote(text, i);
81953
+
81954
+ i++;
81955
+
81956
+ let char;
81957
+
81958
+ let value = '';
81959
+ const lastPossibleChar = length - 1;
81960
+
81961
+ for (; i < lastPossibleChar; i++) {
81962
+ char = text.charAt(i);
81963
+
81964
+ if (char === '\\') {
81965
+ i++;
81966
+ //read escape sequence
81967
+ char = text.charAt(i);
81968
+
81969
+ switch (char) {
81970
+ case 'n':
81971
+ value += '\n';
81972
+ break;
81973
+ case 't':
81974
+ value += '\t';
81975
+ break;
81976
+ case 'r':
81977
+ value += '\r';
81978
+ break;
81979
+ case 'b':
81980
+ value += '\b';
81981
+ break;
81982
+ case 'f':
81983
+ value += '\f';
81984
+ break;
81985
+ case 'v':
81986
+ value += '\v';
81987
+ break;
81988
+ case '0':
81989
+ value += '\0';
81990
+ break;
81991
+ case '\\':
81992
+ case "'":
81993
+ case '"':
81994
+ default:
81995
+ value += char;
81996
+ break;
81997
+ }
81998
+ } else if (char !== openingQuote) {
81999
+ value += char;
82000
+ } else {
82001
+ break;
82002
+ }
82003
+ }
82004
+
82005
+ char = text.charAt(i);
82006
+
82007
+ if (char !== openingQuote) {
82008
+ throw new ParserError(cursor, "Expected string terminator : " + openingQuote + ", but found '" + char + "' instead", text);
82009
+ }
82010
+
82011
+ i++;
82012
+
82013
+ return new Token(value, cursor, i, TokenType.LiteralString, DataType.String);
82014
+ }
82015
+
81874
82016
  /**
81875
82017
  *
81876
82018
  * @param {string} text
@@ -81929,6 +82071,7 @@ function readArrayLiteral(text, cursor, length) {
81929
82071
  * @returns {Token}
81930
82072
  */
81931
82073
  function readLiteralToken(text, cursor, length) {
82074
+
81932
82075
  const firstChar = text.charAt(cursor);
81933
82076
 
81934
82077
  switch (firstChar) {
@@ -83908,11 +84051,14 @@ class BinaryHeap {
83908
84051
  }
83909
84052
  }
83910
84053
 
84054
+ /**
84055
+ * Decorator that wraps another map and lets you observe mutations
84056
+ * @template K,V
84057
+ */
83911
84058
  class ObservedMap {
83912
84059
  /**
83913
84060
  * @template K,V
83914
84061
  * @constructor
83915
- * @property {number} size
83916
84062
  */
83917
84063
  constructor(source = new Map()) {
83918
84064
  this.on = {
@@ -83995,10 +84141,11 @@ const STATUS_NORMAL = 2;
83995
84141
  class Deque {
83996
84142
  /**
83997
84143
  * @template T
84144
+ * @param {number} [min_size]
83998
84145
  */
83999
- constructor(minSize = DEFAULT_SIZE) {
84146
+ constructor(min_size = DEFAULT_SIZE) {
84000
84147
 
84001
- const size = ceilPowerOfTwo(max2(1, minSize));
84148
+ const size = ceilPowerOfTwo(max2(1, min_size));
84002
84149
 
84003
84150
  /**
84004
84151
  * Using static array allocator to preserve data locality.
@@ -84009,15 +84156,31 @@ class Deque {
84009
84156
  */
84010
84157
  this.__data = new Array(size);
84011
84158
 
84159
+ /**
84160
+ *
84161
+ * @type {number}
84162
+ * @private
84163
+ */
84012
84164
  this.__head = 0;
84165
+ /**
84166
+ *
84167
+ * @type {number}
84168
+ * @private
84169
+ */
84013
84170
  this.__tail = 0;
84014
84171
 
84172
+ /**
84173
+ *
84174
+ * @type {number}
84175
+ * @private
84176
+ */
84015
84177
  this.__status = STATUS_EMPTY;
84016
84178
  }
84017
84179
 
84018
84180
  /**
84019
84181
  *
84020
84182
  * @param {boolean} adding
84183
+ * @private
84021
84184
  */
84022
84185
  resetStatus(adding) {
84023
84186
  const head = this.__head;
@@ -84036,11 +84199,12 @@ class Deque {
84036
84199
  * @returns {number}
84037
84200
  * @private
84038
84201
  */
84039
- __circularBiggerPos(current) {
84040
- // TODO this can be done faster using mod operator (%)
84202
+ __circular_next_position(current) {
84041
84203
  const next = current + 1;
84042
84204
 
84043
- return (next >= this.__data.length) ? 0 : next;
84205
+ const length = this.__data.length;
84206
+
84207
+ return (next >= length) ? 0 : next;
84044
84208
  }
84045
84209
 
84046
84210
  /**
@@ -84049,43 +84213,57 @@ class Deque {
84049
84213
  * @returns {number}
84050
84214
  * @private
84051
84215
  */
84052
- __circularSmallerPos(current) {
84216
+ __circular_previous_position(current) {
84053
84217
  const prev = current - 1;
84054
84218
  return (prev < 0) ? (this.__data.length - 1) : prev;
84055
84219
  }
84056
84220
 
84057
- __checkAndExpand() {
84221
+ __check_and_expand() {
84058
84222
  const status = this.__status;
84223
+
84059
84224
  if (status !== STATUS_FULL) {
84225
+ // queue still has space, we're done
84060
84226
  return;
84061
84227
  }
84228
+
84062
84229
  const length = this.__data.length;
84063
84230
 
84064
- if (Number.MAX_SAFE_INTEGER === length) {
84231
+ if (UINT32_MAX === length) {
84065
84232
  throw new Error('Maximum array size exceeded');
84066
84233
  }
84067
84234
 
84068
- let newLength = length * 2;
84235
+ let new_length = length * 2;
84236
+
84069
84237
  // bigger than Integer.MAX_VALUE
84070
- if (newLength < 0) {
84071
- newLength = Number.MAX_SAFE_INTEGER;
84238
+ if (new_length > UINT32_MAX) {
84239
+ new_length = UINT32_MAX;
84072
84240
  }
84073
84241
 
84074
- const newElements = new Array(newLength);
84242
+ /**
84243
+ *
84244
+ * @type {T[]}
84245
+ */
84246
+ const new_data = new Array(new_length);
84075
84247
 
84076
- // copy front portion of data
84077
84248
  const head = this.__head;
84078
84249
 
84079
- array_copy(this.__data, head, newElements, 0, length - head);
84080
- array_copy(this.__data, 0, newElements, length - head, head);
84250
+ // copy the front portion
84251
+ array_copy(this.__data, head, new_data, 0, length - head);
84252
+ // copy the remainder
84253
+ array_copy(this.__data, 0, new_data, length - head, head);
84081
84254
 
84082
84255
  this.__head = 0;
84083
84256
  this.__tail = length;
84257
+
84084
84258
  this.__status = STATUS_NORMAL;
84085
84259
 
84086
- this.__data = newElements;
84260
+ this.__data = new_data;
84087
84261
  }
84088
84262
 
84263
+ /**
84264
+ *
84265
+ * @return {boolean}
84266
+ */
84089
84267
  isEmpty() {
84090
84268
  return this.size() === 0;
84091
84269
  }
@@ -84097,7 +84275,7 @@ class Deque {
84097
84275
 
84098
84276
  do {
84099
84277
  this.__data[cursor] = undefined;
84100
- cursor = this.__circularBiggerPos(cursor);
84278
+ cursor = this.__circular_next_position(cursor);
84101
84279
  } while (cursor !== tail);
84102
84280
 
84103
84281
  this.__status = STATUS_EMPTY;
@@ -84126,32 +84304,45 @@ class Deque {
84126
84304
  /**
84127
84305
  *
84128
84306
  * @param {number} current
84129
- * @param {boolean} frontShift
84307
+ * @param {boolean} shift_front should we shift elements before the removed element or after?
84130
84308
  * @private
84131
84309
  */
84132
- __removeInternal(current, frontShift) {
84310
+ __remove_internal(current, shift_front) {
84133
84311
  let cursor = current;
84134
- if (frontShift) {
84312
+
84313
+ if (shift_front) {
84314
+
84315
+ // shift towards tail
84316
+
84135
84317
  const head = this.__head;
84318
+
84136
84319
  while (cursor !== head) {
84137
- const next = this.__circularSmallerPos(cursor);
84320
+ const next = this.__circular_previous_position(cursor);
84138
84321
  this.__data[cursor] = this.__data[next];
84139
84322
  cursor = next;
84140
84323
  }
84141
- this.__head = this.__circularBiggerPos(head);
84324
+
84325
+ this.__head = this.__circular_next_position(head);
84326
+
84142
84327
  } else {
84328
+
84329
+ // shift towards head
84330
+
84143
84331
  const tail = this.__tail;
84144
84332
 
84145
84333
  while (cursor !== tail) {
84146
- const next = this.__circularBiggerPos(cursor);
84334
+ const next = this.__circular_next_position(cursor);
84147
84335
  this.__data[cursor] = this.__data[next];
84148
84336
  cursor = next;
84149
84337
  }
84150
84338
 
84151
- this.__tail = this.__circularSmallerPos(tail);
84339
+ this.__tail = this.__circular_previous_position(tail);
84340
+
84152
84341
  }
84153
84342
 
84343
+ // fill in slot of last moved element
84154
84344
  this.__data[cursor] = undefined;
84345
+
84155
84346
  this.resetStatus(false);
84156
84347
  }
84157
84348
 
@@ -84167,7 +84358,7 @@ class Deque {
84167
84358
  return false;
84168
84359
  }
84169
84360
 
84170
- this.__removeInternal(i, true);
84361
+ this.__remove_internal(i, true);
84171
84362
 
84172
84363
  return true;
84173
84364
  }
@@ -84211,20 +84402,20 @@ class Deque {
84211
84402
  * @param {T} e
84212
84403
  */
84213
84404
  addFirst(e) {
84214
- this.__checkAndExpand();
84215
- this.__head = this.__circularSmallerPos(this.__head);
84405
+ this.__check_and_expand();
84406
+ this.__head = this.__circular_previous_position(this.__head);
84216
84407
  this.__data[this.__head] = e;
84217
84408
  this.resetStatus(true);
84218
84409
  }
84219
84410
 
84220
84411
  /**
84221
84412
  * Remove element from the front of the queue
84222
- * @returns {T}
84413
+ * @returns {T|undefined}
84223
84414
  */
84224
84415
  removeFirst() {
84225
84416
  const element = this.__data[this.__head];
84226
84417
  this.__data[this.__head] = undefined;
84227
- this.__head = this.__circularBiggerPos(this.__head);
84418
+ this.__head = this.__circular_next_position(this.__head);
84228
84419
  this.resetStatus(false);
84229
84420
  return element;
84230
84421
  }
@@ -84242,9 +84433,9 @@ class Deque {
84242
84433
  * @param {T} e
84243
84434
  */
84244
84435
  addLast(e) {
84245
- this.__checkAndExpand();
84436
+ this.__check_and_expand();
84246
84437
  this.__data[this.__tail] = e;
84247
- this.__tail = this.__circularBiggerPos(this.__tail);
84438
+ this.__tail = this.__circular_next_position(this.__tail);
84248
84439
  this.resetStatus(true);
84249
84440
  }
84250
84441
 
@@ -84253,7 +84444,7 @@ class Deque {
84253
84444
  * @returns {T}
84254
84445
  */
84255
84446
  removeLast() {
84256
- const last = this.__circularSmallerPos(this.__tail);
84447
+ const last = this.__circular_previous_position(this.__tail);
84257
84448
  const element = this.__data[last];
84258
84449
  this.__data[last] = undefined;
84259
84450
  this.__tail = last;
@@ -84264,10 +84455,10 @@ class Deque {
84264
84455
 
84265
84456
  /**
84266
84457
  * Peek element from the end of the queue without removing it
84267
- * @returns {T}
84458
+ * @returns {T|undefined}
84268
84459
  */
84269
84460
  getLast() {
84270
- const last = this.__circularSmallerPos(this.__tail);
84461
+ const last = this.__circular_previous_position(this.__tail);
84271
84462
  return this.__data[last];
84272
84463
  }
84273
84464
  }
@@ -85975,35 +86166,44 @@ Preloader.prototype.load = function (assetManager) {
85975
86166
  return this;
85976
86167
  };
85977
86168
 
85978
- class AbstractMetric {
85979
- /**
85980
- *
85981
- * @param {number} value
85982
- * @returns {void}
85983
- */
85984
- record(value) {
85985
- throw new Error('Not implemented');
85986
- }
86169
+ /**
86170
+ * @template V
86171
+ * @param {V[]} data
86172
+ * @param {number} [start]
86173
+ * @param {number} [end]
86174
+ * @return {number}
86175
+ */
86176
+ function array_compute_max(data, start = 0, end = data.length) {
86177
+ let result = Number.NEGATIVE_INFINITY;
85987
86178
 
85988
- /**
85989
- * @returns {number|undefined}
85990
- */
85991
- getLastRecord() {
85992
- throw new Error('Not implemented');
86179
+ for (let i = start; i < end; i++) {
86180
+ const value = data[i];
86181
+ if (value > result) {
86182
+ result = value;
86183
+ }
85993
86184
  }
85994
86185
 
85995
- /**
85996
- *
85997
- * @param {MetricStatistics} result
85998
- * @returns {boolean} whether metric was successfully computed or not
85999
- */
86000
- computeStats(result) {
86001
- throw new Error('Not implemented');
86002
- }
86186
+ return result;
86187
+ }
86188
+
86189
+ /**
86190
+ * @template V
86191
+ * @param {V[]} data
86192
+ * @param {number} [start]
86193
+ * @param {number} [end]
86194
+ * @return {number}
86195
+ */
86196
+ function array_compute_min(data, start = 0, end = data.length) {
86197
+ let result = Number.POSITIVE_INFINITY;
86003
86198
 
86004
- clear() {
86005
- throw new Error('Not implemented');
86199
+ for (let i = start; i < end; i++) {
86200
+ const value = data[i];
86201
+ if (value < result) {
86202
+ result = value;
86203
+ }
86006
86204
  }
86205
+
86206
+ return result;
86007
86207
  }
86008
86208
 
86009
86209
  class RingBuffer {
@@ -86273,44 +86473,35 @@ function computeStatisticalPartialMedian(values, start, end) {
86273
86473
  return copy[position];
86274
86474
  }
86275
86475
 
86276
- /**
86277
- * @template V
86278
- * @param {V[]} data
86279
- * @param {number} [start]
86280
- * @param {number} [end]
86281
- * @return {number}
86282
- */
86283
- function computeArrayMax(data, start = 0, end = data.length) {
86284
- let result = Number.NEGATIVE_INFINITY;
86285
-
86286
- for (let i = start; i < end; i++) {
86287
- const value = data[i];
86288
- if (value > result) {
86289
- result = value;
86290
- }
86476
+ class AbstractMetric {
86477
+ /**
86478
+ *
86479
+ * @param {number} value
86480
+ * @returns {void}
86481
+ */
86482
+ record(value) {
86483
+ throw new Error('Not implemented');
86291
86484
  }
86292
86485
 
86293
- return result;
86294
- }
86295
-
86296
- /**
86297
- * @template V
86298
- * @param {V[]} data
86299
- * @param {number} [start]
86300
- * @param {number} [end]
86301
- * @return {number}
86302
- */
86303
- function computeArrayMin(data, start = 0, end = data.length) {
86304
- let result = Number.POSITIVE_INFINITY;
86486
+ /**
86487
+ * @returns {number|undefined}
86488
+ */
86489
+ getLastRecord() {
86490
+ throw new Error('Not implemented');
86491
+ }
86305
86492
 
86306
- for (let i = start; i < end; i++) {
86307
- const value = data[i];
86308
- if (value < result) {
86309
- result = value;
86310
- }
86493
+ /**
86494
+ *
86495
+ * @param {MetricStatistics} result
86496
+ * @returns {boolean} whether metric was successfully computed or not
86497
+ */
86498
+ computeStats(result) {
86499
+ throw new Error('Not implemented');
86311
86500
  }
86312
86501
 
86313
- return result;
86502
+ clear() {
86503
+ throw new Error('Not implemented');
86504
+ }
86314
86505
  }
86315
86506
 
86316
86507
  class RingBufferMetric extends AbstractMetric {
@@ -86367,8 +86558,8 @@ class RingBufferMetric extends AbstractMetric {
86367
86558
 
86368
86559
  result.mean = computeStatisticalMean(array, 0, data_count);
86369
86560
  result.median = computeStatisticalPartialMedian(array, 0, data_count - 1);
86370
- result.max = computeArrayMax(array, 0, data_count);
86371
- result.min = computeArrayMin(array, 0, data_count);
86561
+ result.max = array_compute_max(array, 0, data_count);
86562
+ result.min = array_compute_min(array, 0, data_count);
86372
86563
 
86373
86564
  return true;
86374
86565
 
@@ -110072,7 +110263,7 @@ class LightManager {
110072
110263
  __build_view_frustum(camera) {
110073
110264
  frustum_from_camera(camera, this.__view_frustum, false);
110074
110265
 
110075
- arraySwapElements(this.__view_frustum.planes, 4, 5);
110266
+ array_swap_one(this.__view_frustum.planes, 4, 5);
110076
110267
 
110077
110268
  this.__build_view_frustum_points();
110078
110269
  }