@woosh/meep-engine 2.97.0 → 2.98.0

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 (122) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +828 -660
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +828 -660
  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/geom/3d/aabb/aabb3_intersects_ray.js +10 -10
  36. package/src/core/parser/simple/ParserError.d.ts +11 -6
  37. package/src/core/parser/simple/ParserError.d.ts.map +1 -1
  38. package/src/core/parser/simple/ParserError.js +51 -4
  39. package/src/core/parser/simple/Token.d.ts.map +1 -1
  40. package/src/core/parser/simple/Token.js +8 -2
  41. package/src/core/parser/simple/TokenType.d.ts +1 -5
  42. package/src/core/parser/simple/TokenType.d.ts.map +1 -1
  43. package/src/core/parser/simple/TokenType.js +1 -1
  44. package/src/core/parser/simple/readBooleanToken.d.ts.map +1 -1
  45. package/src/core/parser/simple/readBooleanToken.js +6 -1
  46. package/src/core/parser/simple/readHexToken.d.ts.map +1 -1
  47. package/src/core/parser/simple/readHexToken.js +7 -2
  48. package/src/core/parser/simple/readIdentifierToken.d.ts.map +1 -1
  49. package/src/core/parser/simple/readIdentifierToken.js +6 -1
  50. package/src/core/parser/simple/readLiteralToken.d.ts.map +1 -1
  51. package/src/core/parser/simple/readLiteralToken.js +8 -3
  52. package/src/core/parser/simple/readNumberToken.d.ts.map +1 -1
  53. package/src/core/parser/simple/readNumberToken.js +7 -2
  54. package/src/core/parser/simple/readReferenceToken.d.ts.map +1 -1
  55. package/src/core/parser/simple/readReferenceToken.js +6 -1
  56. package/src/core/parser/simple/readStringToken.d.ts.map +1 -1
  57. package/src/core/parser/simple/readStringToken.js +6 -1
  58. package/src/core/parser/simple/readUnsignedIntegerToken.d.ts.map +1 -1
  59. package/src/core/parser/simple/readUnsignedIntegerToken.js +7 -2
  60. package/src/core/parser/simple/skipWhitespace.d.ts.map +1 -1
  61. package/src/core/parser/simple/skipWhitespace.js +8 -0
  62. package/src/core/primitives/strings/string_repeat.d.ts +9 -0
  63. package/src/core/primitives/strings/string_repeat.d.ts.map +1 -0
  64. package/src/core/primitives/strings/string_repeat.js +26 -0
  65. package/src/engine/asset/AssetManager.d.ts.map +1 -1
  66. package/src/engine/development/performance/RingBufferMetric.d.ts.map +1 -1
  67. package/src/engine/development/performance/RingBufferMetric.js +5 -5
  68. package/src/engine/ecs/terrain/ecs/BuildLightTexture.d.ts.map +1 -1
  69. package/src/engine/ecs/terrain/ecs/BuildLightTexture.js +15 -22
  70. package/src/engine/graphics/ecs/camera/Camera.d.ts.map +1 -1
  71. package/src/engine/graphics/ecs/camera/Camera.js +23 -16
  72. package/src/engine/graphics/filter/ImageFilter.d.ts +2 -2
  73. package/src/engine/graphics/filter/ImageFilter.d.ts.map +1 -1
  74. package/src/engine/graphics/filter/ImageFilter.js +3 -3
  75. package/src/engine/graphics/render/RendererPool.d.ts +14 -1
  76. package/src/engine/graphics/render/RendererPool.d.ts.map +1 -1
  77. package/src/engine/graphics/render/RendererPool.js +43 -1
  78. package/src/engine/graphics/render/forward_plus/LightManager.js +2 -2
  79. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +2 -1
  80. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
  81. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +23 -50
  82. package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.d.ts +9 -0
  83. package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.d.ts.map +1 -1
  84. package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.js +53 -3
  85. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +3 -3
  86. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts +1 -1
  87. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts.map +1 -1
  88. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +42 -36
  89. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.d.ts +3 -0
  90. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.d.ts.map +1 -0
  91. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.js +34 -0
  92. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.d.ts +10 -0
  93. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.d.ts.map +1 -0
  94. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.js +89 -0
  95. package/src/engine/graphics/texture/sampler/debug/prototypeSamplerFiltering.d.ts.map +1 -0
  96. package/src/engine/graphics/texture/sampler/{prototypeSamplerFiltering.js → debug/prototypeSamplerFiltering.js} +105 -113
  97. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.d.ts.map +1 -1
  98. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.js +8 -8
  99. package/src/generation/markers/GridActionRuleSet.d.ts.map +1 -1
  100. package/src/generation/markers/GridActionRuleSet.js +5 -5
  101. package/src/core/binary/byteArrayToString.d.ts +0 -9
  102. package/src/core/binary/byteArrayToString.d.ts.map +0 -1
  103. package/src/core/binary/byteArrayToString.js +0 -28
  104. package/src/core/collection/array/AbstractArrayIterator.d.ts.map +0 -1
  105. package/src/core/collection/array/ArrayIteratorRandom.d.ts.map +0 -1
  106. package/src/core/collection/array/ArrayIteratorSequential.d.ts.map +0 -1
  107. package/src/core/collection/array/arrayPickMinElement.d.ts +0 -8
  108. package/src/core/collection/array/arrayPickMinElement.d.ts.map +0 -1
  109. package/src/core/collection/array/arrayPickMinElement.js +0 -43
  110. package/src/core/collection/array/arraySwapElements.d.ts +0 -8
  111. package/src/core/collection/array/arraySwapElements.d.ts.map +0 -1
  112. package/src/core/collection/array/computeArrayMax.d.ts +0 -9
  113. package/src/core/collection/array/computeArrayMax.d.ts.map +0 -1
  114. package/src/core/collection/array/computeArrayMin.d.ts +0 -9
  115. package/src/core/collection/array/computeArrayMin.d.ts.map +0 -1
  116. package/src/engine/graphics/texture/sampler/prototypeSamplerFiltering.d.ts.map +0 -1
  117. /package/src/core/collection/array/{AbstractArrayIterator.d.ts → iterator/AbstractArrayIterator.d.ts} +0 -0
  118. /package/src/core/collection/array/{AbstractArrayIterator.js → iterator/AbstractArrayIterator.js} +0 -0
  119. /package/src/core/collection/array/{ArrayIteratorRandom.d.ts → iterator/ArrayIteratorRandom.d.ts} +0 -0
  120. /package/src/core/collection/array/{ArrayIteratorSequential.d.ts → iterator/ArrayIteratorSequential.d.ts} +0 -0
  121. /package/src/core/collection/array/{ArrayIteratorSequential.js → iterator/ArrayIteratorSequential.js} +0 -0
  122. /package/src/engine/graphics/texture/sampler/{prototypeSamplerFiltering.d.ts → debug/prototypeSamplerFiltering.d.ts} +0 -0
@@ -53175,7 +53175,7 @@ const SCRATCH_UINT32_TRAVERSAL_STACK = new Uint32Array(781250);
53175
53175
  */
53176
53176
  SCRATCH_UINT32_TRAVERSAL_STACK.pointer = 0;
53177
53177
 
53178
- const fabsf$1 = Math.abs;
53178
+ const abs = Math.abs;
53179
53179
 
53180
53180
  /**
53181
53181
  * NOTES:
@@ -53212,7 +53212,7 @@ function aabb3_intersects_ray(
53212
53212
  const diff_x = origin_x - center_x;
53213
53213
 
53214
53214
 
53215
- if (diff_x * direction_x >= 0.0 && fabsf$1(diff_x) > extents_x) {
53215
+ if (diff_x * direction_x >= 0.0 && abs(diff_x) > extents_x) {
53216
53216
  return false;
53217
53217
  }
53218
53218
 
@@ -53224,7 +53224,7 @@ function aabb3_intersects_ray(
53224
53224
  const diff_y = origin_y - center_y;
53225
53225
 
53226
53226
 
53227
- if (diff_y * direction_y >= 0.0 && fabsf$1(diff_y) > extents_y) {
53227
+ if (diff_y * direction_y >= 0.0 && abs(diff_y) > extents_y) {
53228
53228
  return false;
53229
53229
  }
53230
53230
 
@@ -53236,28 +53236,28 @@ function aabb3_intersects_ray(
53236
53236
  const diff_z = origin_z - center_z;
53237
53237
 
53238
53238
 
53239
- if (diff_z * direction_z >= 0.0 && fabsf$1(diff_z) > extents_z) {
53239
+ if (diff_z * direction_z >= 0.0 && abs(diff_z) > extents_z) {
53240
53240
  return false;
53241
53241
  }
53242
53242
 
53243
- const abs_direction_y = fabsf$1(direction_y);
53244
- const abs_direction_z = fabsf$1(direction_z);
53243
+ const abs_direction_y = abs(direction_y);
53244
+ const abs_direction_z = abs(direction_z);
53245
53245
 
53246
- const f0 = fabsf$1(direction_y * diff_z - direction_z * diff_y);
53246
+ const f0 = abs(direction_y * diff_z - direction_z * diff_y);
53247
53247
 
53248
53248
  if (f0 > extents_y * abs_direction_z + extents_z * abs_direction_y) {
53249
53249
  return false;
53250
53250
  }
53251
53251
 
53252
- const abs_direction_x = fabsf$1(direction_x);
53252
+ const abs_direction_x = abs(direction_x);
53253
53253
 
53254
- const f1 = fabsf$1(direction_z * diff_x - direction_x * diff_z);
53254
+ const f1 = abs(direction_z * diff_x - direction_x * diff_z);
53255
53255
 
53256
53256
  if (f1 > extents_x * abs_direction_z + extents_z * abs_direction_x) {
53257
53257
  return false;
53258
53258
  }
53259
53259
 
53260
- const f2 = fabsf$1(direction_x * diff_y - direction_y * diff_x);
53260
+ const f2 = abs(direction_x * diff_y - direction_y * diff_x);
53261
53261
 
53262
53262
  return f2 <= extents_x * abs_direction_y + extents_y * abs_direction_x;
53263
53263
  }
@@ -53336,8 +53336,8 @@ function bvh_query_leaves_ray(
53336
53336
  if (child_1 !== NULL_NODE) {
53337
53337
 
53338
53338
  // this is not a leaf node, push children onto traversal stack
53339
- stack$9[stack$9.pointer++] = child_1;
53340
53339
  stack$9[stack$9.pointer++] = uint32[address + COLUMN_CHILD_2];
53340
+ stack$9[stack$9.pointer++] = child_1;
53341
53341
 
53342
53342
  } else {
53343
53343
  // leaf node
@@ -54951,19 +54951,22 @@ function ceilPowerOfTwo(v) {
54951
54951
  * @param {number} b_offset
54952
54952
  * @param {number} length How many elements should be moved
54953
54953
  */
54954
- function array_swap(a, a_offset, b, b_offset, length) {
54955
-
54956
- let i, j, k;
54954
+ function array_swap(
54955
+ a, a_offset,
54956
+ b, b_offset,
54957
+ length
54958
+ ) {
54957
54959
 
54958
- for (k = 0; k < length; k++) {
54959
- i = a_offset + k;
54960
- j = b_offset + k;
54960
+ for (let k = 0; k < length; k++) {
54961
+ const i = a_offset + k;
54962
+ const j = b_offset + k;
54961
54963
 
54962
- const t = b[j];
54964
+ const swap = b[j];
54963
54965
 
54964
54966
  b[j] = a[i];
54965
- a[i] = t;
54967
+ a[i] = swap;
54966
54968
  }
54969
+
54967
54970
  }
54968
54971
 
54969
54972
  //
@@ -58823,25 +58826,138 @@ class TerrainTileManager {
58823
58826
  }
58824
58827
  }
58825
58828
 
58829
+ class WebGLRendererPool {
58830
+
58831
+ used = new Set();
58832
+
58833
+ get() {
58834
+ const canvas = document.createElement('canvas');
58835
+ const context = canvas.getContext('webgl2', { antialias: true });
58836
+
58837
+ const renderer = new WebGLRenderer({
58838
+ alpha: true,
58839
+ context,
58840
+ canvas
58841
+ });
58842
+
58843
+ this.used.add(renderer);
58844
+ return renderer;
58845
+ }
58846
+
58847
+ /**
58848
+ *
58849
+ * @param {THREE.WebGLRenderer} renderer
58850
+ * @returns {boolean}
58851
+ */
58852
+ release(renderer) {
58853
+ if (!this.used.has(renderer)) {
58854
+ //not from this pool
58855
+ return false;
58856
+ }
58857
+ this.used.delete(renderer);
58858
+
58859
+ renderer.forceContextLoss();
58860
+ renderer.dispose();
58861
+ renderer.domElement = null;
58862
+
58863
+ return true;
58864
+ }
58865
+
58866
+ /**
58867
+ * After callback returns, renderer is released back into the pool
58868
+ * @template T
58869
+ * @param {function(renderer:WebGLRenderer):T} callback
58870
+ * @param {*} [thisArg]
58871
+ */
58872
+ use(callback, thisArg) {
58873
+
58874
+ const renderer = this.get();
58875
+
58876
+ try {
58877
+ const result = callback.call(thisArg, renderer);
58878
+
58879
+ if (result instanceof Promise) {
58880
+ }
58881
+
58882
+ return result;
58883
+
58884
+ } finally {
58885
+
58886
+ this.release(renderer);
58887
+ }
58888
+
58889
+ }
58890
+
58891
+ /**
58892
+ * @template T
58893
+ * @param {function(renderer:WebGLRenderer):Promise<T>} callback
58894
+ * @param {*} [thisArg]
58895
+ */
58896
+ async useAsync(callback, thisArg) {
58897
+
58898
+ const renderer = this.get();
58899
+
58900
+ try {
58901
+ await callback.call(thisArg, renderer);
58902
+ } finally {
58903
+ this.release(renderer);
58904
+ }
58905
+ }
58906
+
58907
+ static global = new WebGLRendererPool();
58908
+ }
58909
+
58910
+ /**
58911
+ *
58912
+ * @param {Sampler2D} sampler
58913
+ * @param {THREE.DataTexture} texture
58914
+ */
58915
+ function writeSample2DDataToDataTexture(sampler, texture) {
58916
+ if (sampler.itemSize === 1) {
58917
+ if (texture.format !== RedFormat && texture.format !== LuminanceFormat) {
58918
+ throw new Error('itemSize is 1 and texture.format is not RedFormat');
58919
+ }
58920
+ } else if (sampler.itemSize === 2) {
58921
+ if (texture.format !== RGFormat) {
58922
+ throw new Error('itemSize is 2 and texture.format is not RGFormat');
58923
+ }
58924
+ } else if (sampler.itemSize === 3) {
58925
+ if (texture.format !== RGBFormat) {
58926
+ throw new Error('itemSize is 2 and texture.format is not RGBFormat');
58927
+ }
58928
+ } else if (sampler.itemSize === 4) {
58929
+ if (texture.format !== RGBAFormat) {
58930
+ throw new Error('itemSize is 2 and texture.format is not RGBAFormat');
58931
+ }
58932
+ } else {
58933
+ throw new Error('Unsupported itemSize');
58934
+ }
58935
+
58936
+ if (texture.image.data !== sampler.data) {
58937
+ // dispose of previous texture data
58938
+ texture.dispose();
58939
+ }
58940
+
58941
+ texture.image.data = sampler.data;
58942
+ texture.image.width = sampler.width;
58943
+ texture.image.height = sampler.height;
58944
+
58945
+ texture.needsUpdate = true;
58946
+ }
58947
+
58826
58948
  /**
58827
58949
  * Created by Alex on 10/11/2014.
58828
58950
  */
58829
58951
 
58830
- const AmbientOcclusionShader = function () {
58952
+
58953
+ const NormalMapShader = function () {
58831
58954
  return {
58832
58955
 
58833
58956
  uniforms: {
58834
58957
 
58835
- "normalMap": { type: "t", value: null },
58836
58958
  "heightMap": { type: "t", value: null },
58837
- "world_size": { type: "v2", value: new Vector2$1(512, 512) },
58838
- "rayLength": { type: 'f', value: 17 }
58839
-
58840
- },
58959
+ "resolution": { type: "v2", value: new Vector2$1(512, 512) }
58841
58960
 
58842
- defines: {
58843
- 'NUM_SAMPLES': 64,
58844
- 'NUM_RINGS': 7,
58845
58961
  },
58846
58962
 
58847
58963
  vertexShader: [
@@ -58857,102 +58973,53 @@ const AmbientOcclusionShader = function () {
58857
58973
 
58858
58974
  ].join("\n"),
58859
58975
 
58976
+ /**
58977
+ * Reference: https://stackoverflow.com/questions/49640250/calculate-normals-from-heightmap
58978
+ */
58860
58979
  fragmentShader: [
58861
- `
58862
- uniform sampler2D normalMap;
58863
- uniform sampler2D heightMap;
58864
- uniform float rayLength;
58865
- uniform vec2 world_size;
58980
+ "uniform vec2 resolution;",
58981
+ "uniform sampler2D heightMap;",
58866
58982
 
58867
- varying vec2 vUv;
58983
+ "#define sqrt2 1.41421356237;",
58984
+
58985
+ "varying vec2 vUv;",
58986
+
58987
+ "void main() {",
58988
+ " float uStep = 1.0/resolution.x;",
58989
+ " float vStep = 1.0/resolution.y;",
58990
+ //
58991
+ //
58992
+ " float top = texture2D( heightMap, vUv + vec2(0, -vStep)).x;",
58993
+ " float bottom = texture2D( heightMap, vUv + vec2(0, +vStep)).x;",
58994
+ " float left = texture2D( heightMap, vUv + vec2(-uStep, 0)).x;",
58995
+ " float right = texture2D( heightMap, vUv + vec2(+uStep, 0)).x;",
58996
+ //
58997
+
58998
+ " float dX = (right ) - ( left);",
58999
+ " float dY = ( bottom ) - ( top);",
59000
+ " float dZ = 2.0;",
59001
+ " vec3 n = normalize(vec3(dX, dY, dZ));",
59002
+
59003
+ " gl_FragColor = vec4( n*0.5+0.5, 1.0 );",
59004
+
59005
+ "}"
58868
59006
 
58869
- vec3 get(float x, float y){
58870
- vec2 _uv = vUv.xy + vec2(x,y) / world_size;
58871
- float h = texture2D(heightMap, _uv).x;
58872
- return vec3( _uv.x * world_size.x, h, _uv.y * world_size.y );
58873
- }
58874
-
58875
- float hash1( float n )
58876
- {
58877
- return fract( n*17.0*fract( n*0.3183099 ) );
58878
- }
58879
-
58880
- float hash1( vec2 p )
58881
- {
58882
- p = 50.0*fract( p*0.3183099 );
58883
- return fract( p.x*p.y*(p.x+p.y) );
58884
- }
58885
-
58886
- // Non-sin based hash function, fast and has good randomness
58887
- float hash12(vec2 p){
58888
- vec3 p3 = fract(vec3(p.xyx) * .1031);
58889
- p3 += dot(p3, p3.yzx + 33.33);
58890
- return fract((p3.x + p3.y) * p3.z);
58891
- }
58892
-
58893
- const float bias = 0.001;
58894
-
58895
- float pow2(float x){
58896
- return x*x;
58897
- }
58898
-
58899
- float getOcclusion(vec3 origin, vec3 normal, vec3 hit_position){
58900
- vec3 viewDelta = hit_position - origin;
58901
-
58902
- float viewDistance = length( viewDelta );
58903
-
58904
- float vn = dot( normal, viewDelta );
58905
- float a2 = (vn) / viewDistance - bias;
58906
- float a1 = (1.0 + pow2( viewDistance ) );
58907
-
58908
- return max(0.0, a2) / a1;
58909
- }
58910
-
58911
- const float PI2 = 6.28318530717958;
58912
- const float kernelRadius = 100.0;
58913
-
58914
- const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );
58915
- const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );
58916
-
58917
- float getAmbientOcclusion(vec3 world_position, vec3 world_normal){
58918
- // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/
58919
- float angle = hash12( vUv ) * PI2;
58920
- vec2 radius = vec2( rayLength * INV_NUM_SAMPLES );
58921
-
58922
- float occlusionSum = 0.0;
58923
- float weightSum = 0.0;
58924
-
58925
- for( int i = 0; i < NUM_SAMPLES; i ++ ) {
58926
- vec2 sampleUv = vec2( cos( angle ), sin( angle ) ) * radius * float(i+1);
58927
-
58928
- angle += ANGLE_STEP;
58929
-
58930
- vec3 sample_pos = get(sampleUv.x, sampleUv.y);
58931
-
58932
- occlusionSum += getOcclusion(world_position, world_normal, sample_pos);
58933
- weightSum += 1.0;
58934
- }
58935
-
58936
- return occlusionSum/weightSum;
58937
- }
58938
-
58939
- void main() {
58940
- vec3 pos = get(0.0, 0.0);
58941
-
58942
- vec3 normal = texture2D( normalMap, vUv ).xzy;
58943
-
58944
- float occlusion = getAmbientOcclusion(pos, normal);
58945
-
58946
- float incident = 1.0 - occlusion;
58947
-
58948
- gl_FragColor = vec4(pow(incident,10.0), 0.0, 0.0, 1.0);
58949
- }
58950
- `
58951
59007
  ].join('\n')
58952
59008
 
58953
59009
  }
58954
59010
  };
58955
59011
 
59012
+ const FULL_SCREEN_QUAD_VERTEX_SHADER = `
59013
+ varying vec2 vUv;
59014
+
59015
+ void main() {
59016
+
59017
+ vUv = uv;
59018
+
59019
+ gl_Position = vec4( (uv - 0.5)*2.0, 0.0, 1.0 );
59020
+
59021
+ }`;
59022
+
58956
59023
  const FULL_SCREEN_TRIANGLE_GEOMETRY = new BufferGeometry();
58957
59024
  FULL_SCREEN_TRIANGLE_GEOMETRY.setAttribute(
58958
59025
  'position',
@@ -58970,17 +59037,6 @@ FULL_SCREEN_TRIANGLE_GEOMETRY.setAttribute(
58970
59037
  )
58971
59038
  );
58972
59039
 
58973
- const FULL_SCREEN_QUAD_VERTEX_SHADER = `
58974
- varying vec2 vUv;
58975
-
58976
- void main() {
58977
-
58978
- vUv = uv;
58979
-
58980
- gl_Position = vec4( (uv - 0.5)*2.0, 0.0, 1.0 );
58981
-
58982
- }`;
58983
-
58984
59040
  /**
58985
59041
  * Created by Alex on 09/11/2014.
58986
59042
  */
@@ -58992,7 +59048,7 @@ const FULL_SCREEN_QUAD_VERTEX_SHADER = `
58992
59048
  * @param {number} width
58993
59049
  * @param {number} height
58994
59050
  * @param {{vertexShader?:string,fragmentShader:string, uniforms?:Object, defines?:Object}} processShader
58995
- * @param {Uint8Array} [destination]
59051
+ * @param {Uint8Array|Uint8ClampedArray} [destination]
58996
59052
  * @return {{array: Uint8Array, renderer: WebGLRenderer}}
58997
59053
  */
58998
59054
  function processTexture(
@@ -59003,7 +59059,7 @@ function processTexture(
59003
59059
  destination
59004
59060
  ) {
59005
59061
  if (destination === undefined) {
59006
- destination = new Uint8Array(width * height * 4);
59062
+ destination = new Uint8ClampedArray(width * height * 4);
59007
59063
  }
59008
59064
 
59009
59065
  //make a webgl renderer with orthographic camera
@@ -59173,6 +59229,207 @@ function sampler2DtoFloat32Texture(sampler) {
59173
59229
  return texture;
59174
59230
  }
59175
59231
 
59232
+ /**
59233
+ * Created by Alex on 15/11/2014.
59234
+ */
59235
+
59236
+
59237
+
59238
+ function convertChannel(v) {
59239
+ return (v) / 255 - 0.5;
59240
+ }
59241
+
59242
+ /**
59243
+ *
59244
+ * @param {number[]|Uint8Array} source
59245
+ * @returns {Float32Array}
59246
+ */
59247
+ function rgbaArray2RGB(source) {
59248
+ const length = source.length;
59249
+ const numPixels = Math.floor(length / 4);
59250
+ const target = new Float32Array(numPixels * 3);
59251
+ //
59252
+ let h;
59253
+ for (let i = 0; i < numPixels; i++) {
59254
+ const j = i * 4;
59255
+ const k = i * 3;
59256
+ //normalize source to normal vectors
59257
+ let x = convertChannel(source[j]);
59258
+ let y = convertChannel(source[j + 1]);
59259
+ let z = convertChannel(source[j + 2]);
59260
+ //
59261
+ h = Math.sqrt(x * x + y * y + z * z);
59262
+
59263
+ x /= h;
59264
+ y /= h;
59265
+ z /= h;
59266
+ //
59267
+ target[k] = x;
59268
+ target[k + 1] = y;
59269
+ target[k + 2] = z;
59270
+ }
59271
+ return target;
59272
+ }
59273
+
59274
+ /**
59275
+ *
59276
+ * @param {WebGLRenderer} renderer
59277
+ * @param {Sampler2D} sampler
59278
+ * @returns {Sampler2D}
59279
+ */
59280
+ function heightMap2NormalMap(renderer, sampler) {
59281
+
59282
+ const width = sampler.width;
59283
+ const height = sampler.height;
59284
+
59285
+ const texture = sampler2DtoFloat32Texture(sampler);
59286
+
59287
+ //construct shader
59288
+ const shader = new NormalMapShader();
59289
+ shader.uniforms.heightMap.value = texture;
59290
+ shader.uniforms.resolution.value.set(width, height);
59291
+
59292
+ //perform filtering
59293
+ const result = processTexture(renderer, width, height, shader);
59294
+
59295
+ //create the sampler
59296
+ const array = result.array;
59297
+ const rgb = rgbaArray2RGB(array);
59298
+
59299
+ //reduce array's alpha component
59300
+ return new Sampler2D(rgb, 3, width, height);
59301
+ }
59302
+
59303
+ /**
59304
+ * Created by Alex on 10/11/2014.
59305
+ */
59306
+
59307
+ const AmbientOcclusionShader = function () {
59308
+ return {
59309
+
59310
+ uniforms: {
59311
+
59312
+ "normalMap": { type: "t", value: null },
59313
+ "heightMap": { type: "t", value: null },
59314
+ "world_size": { type: "v2", value: new Vector2$1(512, 512) },
59315
+ "rayLength": { type: 'f', value: 17 }
59316
+
59317
+ },
59318
+
59319
+ defines: {
59320
+ 'NUM_SAMPLES': 64,
59321
+ 'NUM_RINGS': 7,
59322
+ },
59323
+
59324
+ vertexShader: [
59325
+
59326
+ "varying vec2 vUv;",
59327
+
59328
+ "void main() {",
59329
+
59330
+ "vUv = uv;",
59331
+ "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
59332
+
59333
+ "}"
59334
+
59335
+ ].join("\n"),
59336
+
59337
+ fragmentShader: [
59338
+ `
59339
+ uniform sampler2D normalMap;
59340
+ uniform sampler2D heightMap;
59341
+ uniform float rayLength;
59342
+ uniform vec2 world_size;
59343
+
59344
+ varying vec2 vUv;
59345
+
59346
+ vec3 get(float x, float y){
59347
+ vec2 _uv = vUv.xy + vec2(x,y) / world_size;
59348
+ float h = texture2D(heightMap, _uv).x;
59349
+ return vec3( _uv.x * world_size.x, h, _uv.y * world_size.y );
59350
+ }
59351
+
59352
+ float hash1( float n )
59353
+ {
59354
+ return fract( n*17.0*fract( n*0.3183099 ) );
59355
+ }
59356
+
59357
+ float hash1( vec2 p )
59358
+ {
59359
+ p = 50.0*fract( p*0.3183099 );
59360
+ return fract( p.x*p.y*(p.x+p.y) );
59361
+ }
59362
+
59363
+ // Non-sin based hash function, fast and has good randomness
59364
+ float hash12(vec2 p){
59365
+ vec3 p3 = fract(vec3(p.xyx) * .1031);
59366
+ p3 += dot(p3, p3.yzx + 33.33);
59367
+ return fract((p3.x + p3.y) * p3.z);
59368
+ }
59369
+
59370
+ const float bias = 0.001;
59371
+
59372
+ float pow2(float x){
59373
+ return x*x;
59374
+ }
59375
+
59376
+ float getOcclusion(vec3 origin, vec3 normal, vec3 hit_position){
59377
+ vec3 viewDelta = hit_position - origin;
59378
+
59379
+ float viewDistance = length( viewDelta );
59380
+
59381
+ float vn = dot( normal, viewDelta );
59382
+ float a2 = (vn) / viewDistance - bias;
59383
+ float a1 = (1.0 + pow2( viewDistance ) );
59384
+
59385
+ return max(0.0, a2) / a1;
59386
+ }
59387
+
59388
+ const float PI2 = 6.28318530717958;
59389
+ const float kernelRadius = 100.0;
59390
+
59391
+ const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );
59392
+ const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );
59393
+
59394
+ float getAmbientOcclusion(vec3 world_position, vec3 world_normal){
59395
+ // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/
59396
+ float angle = hash12( vUv ) * PI2;
59397
+ vec2 radius = vec2( rayLength * INV_NUM_SAMPLES );
59398
+
59399
+ float occlusionSum = 0.0;
59400
+ float weightSum = 0.0;
59401
+
59402
+ for( int i = 0; i < NUM_SAMPLES; i ++ ) {
59403
+ vec2 sampleUv = vec2( cos( angle ), sin( angle ) ) * radius * float(i+1);
59404
+
59405
+ angle += ANGLE_STEP;
59406
+
59407
+ vec3 sample_pos = get(sampleUv.x, sampleUv.y);
59408
+
59409
+ occlusionSum += getOcclusion(world_position, world_normal, sample_pos);
59410
+ weightSum += 1.0;
59411
+ }
59412
+
59413
+ return occlusionSum/weightSum;
59414
+ }
59415
+
59416
+ void main() {
59417
+ vec3 pos = get(0.0, 0.0);
59418
+
59419
+ vec3 normal = texture2D( normalMap, vUv ).xzy;
59420
+
59421
+ float occlusion = getAmbientOcclusion(pos, normal);
59422
+
59423
+ float incident = 1.0 - occlusion;
59424
+
59425
+ gl_FragColor = vec4(pow(incident,10.0), 0.0, 0.0, 1.0);
59426
+ }
59427
+ `
59428
+ ].join('\n')
59429
+
59430
+ }
59431
+ };
59432
+
59176
59433
  const KERNEL_SIZE = 15;
59177
59434
 
59178
59435
  const fragment$1 = `
@@ -59370,219 +59627,6 @@ function normalMap2OcclusionMap(
59370
59627
  return result;
59371
59628
  }
59372
59629
 
59373
- /**
59374
- * Created by Alex on 10/11/2014.
59375
- */
59376
-
59377
-
59378
- const NormalMapShader = function () {
59379
- return {
59380
-
59381
- uniforms: {
59382
-
59383
- "heightMap": { type: "t", value: null },
59384
- "resolution": { type: "v2", value: new Vector2$1(512, 512) }
59385
-
59386
- },
59387
-
59388
- vertexShader: [
59389
-
59390
- "varying vec2 vUv;",
59391
-
59392
- "void main() {",
59393
-
59394
- "vUv = uv;",
59395
- "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
59396
-
59397
- "}"
59398
-
59399
- ].join("\n"),
59400
-
59401
- /**
59402
- * Reference: https://stackoverflow.com/questions/49640250/calculate-normals-from-heightmap
59403
- */
59404
- fragmentShader: [
59405
- "uniform vec2 resolution;",
59406
- "uniform sampler2D heightMap;",
59407
-
59408
- "#define sqrt2 1.41421356237;",
59409
-
59410
- "varying vec2 vUv;",
59411
-
59412
- "void main() {",
59413
- " float uStep = 1.0/resolution.x;",
59414
- " float vStep = 1.0/resolution.y;",
59415
- //
59416
- //
59417
- " float top = texture2D( heightMap, vUv + vec2(0, -vStep)).x;",
59418
- " float bottom = texture2D( heightMap, vUv + vec2(0, +vStep)).x;",
59419
- " float left = texture2D( heightMap, vUv + vec2(-uStep, 0)).x;",
59420
- " float right = texture2D( heightMap, vUv + vec2(+uStep, 0)).x;",
59421
- //
59422
-
59423
- " float dX = (right ) - ( left);",
59424
- " float dY = ( bottom ) - ( top);",
59425
- " float dZ = 2.0;",
59426
- " vec3 n = normalize(vec3(dX, dY, dZ));",
59427
-
59428
- " gl_FragColor = vec4( n*0.5+0.5, 1.0 );",
59429
-
59430
- "}"
59431
-
59432
- ].join('\n')
59433
-
59434
- }
59435
- };
59436
-
59437
- /**
59438
- * Created by Alex on 15/11/2014.
59439
- */
59440
-
59441
-
59442
-
59443
- function convertChannel(v) {
59444
- return (v) / 255 - 0.5;
59445
- }
59446
-
59447
- /**
59448
- *
59449
- * @param {number[]|Uint8Array} source
59450
- * @returns {Float32Array}
59451
- */
59452
- function rgbaArray2RGB(source) {
59453
- const length = source.length;
59454
- const numPixels = Math.floor(length / 4);
59455
- const target = new Float32Array(numPixels * 3);
59456
- //
59457
- let h;
59458
- for (let i = 0; i < numPixels; i++) {
59459
- const j = i * 4;
59460
- const k = i * 3;
59461
- //normalize source to normal vectors
59462
- let x = convertChannel(source[j]);
59463
- let y = convertChannel(source[j + 1]);
59464
- let z = convertChannel(source[j + 2]);
59465
- //
59466
- h = Math.sqrt(x * x + y * y + z * z);
59467
-
59468
- x /= h;
59469
- y /= h;
59470
- z /= h;
59471
- //
59472
- target[k] = x;
59473
- target[k + 1] = y;
59474
- target[k + 2] = z;
59475
- }
59476
- return target;
59477
- }
59478
-
59479
- /**
59480
- *
59481
- * @param {WebGLRenderer} renderer
59482
- * @param {Sampler2D} sampler
59483
- * @returns {Sampler2D}
59484
- */
59485
- function heightMap2NormalMap(renderer, sampler) {
59486
-
59487
- const width = sampler.width;
59488
- const height = sampler.height;
59489
-
59490
- const texture = sampler2DtoFloat32Texture(sampler);
59491
-
59492
- //construct shader
59493
- const shader = new NormalMapShader();
59494
- shader.uniforms.heightMap.value = texture;
59495
- shader.uniforms.resolution.value.set(width, height);
59496
-
59497
- //perform filtering
59498
- const result = processTexture(renderer, width, height, shader);
59499
-
59500
- //create the sampler
59501
- const array = result.array;
59502
- const rgb = rgbaArray2RGB(array);
59503
-
59504
- //reduce array's alpha component
59505
- return new Sampler2D(rgb, 3, width, height);
59506
- }
59507
-
59508
- class WebGLRendererPool {
59509
-
59510
- used = new Set();
59511
-
59512
- get(options) {
59513
- const canvas = document.createElement('canvas');
59514
- const context = canvas.getContext('webgl2', { antialias: true });
59515
-
59516
- const renderer = new WebGLRenderer({
59517
- alpha: true,
59518
- context,
59519
- canvas
59520
- });
59521
-
59522
- this.used.add(renderer);
59523
- return renderer;
59524
- }
59525
-
59526
- /**
59527
- *
59528
- * @param {THREE.WebGLRenderer} renderer
59529
- * @returns {boolean}
59530
- */
59531
- release(renderer) {
59532
- if (!this.used.has(renderer)) {
59533
- //not from this pool
59534
- return false;
59535
- }
59536
- this.used.delete(renderer);
59537
-
59538
- renderer.forceContextLoss();
59539
- renderer.dispose();
59540
- renderer.domElement = null;
59541
-
59542
- return true;
59543
- }
59544
-
59545
- static global = new WebGLRendererPool();
59546
- }
59547
-
59548
- /**
59549
- *
59550
- * @param {Sampler2D} sampler
59551
- * @param {THREE.DataTexture} texture
59552
- */
59553
- function writeSample2DDataToDataTexture(sampler, texture) {
59554
- if (sampler.itemSize === 1) {
59555
- if (texture.format !== RedFormat && texture.format !== LuminanceFormat) {
59556
- throw new Error('itemSize is 1 and texture.format is not RedFormat');
59557
- }
59558
- } else if (sampler.itemSize === 2) {
59559
- if (texture.format !== RGFormat) {
59560
- throw new Error('itemSize is 2 and texture.format is not RGFormat');
59561
- }
59562
- } else if (sampler.itemSize === 3) {
59563
- if (texture.format !== RGBFormat) {
59564
- throw new Error('itemSize is 2 and texture.format is not RGBFormat');
59565
- }
59566
- } else if (sampler.itemSize === 4) {
59567
- if (texture.format !== RGBAFormat) {
59568
- throw new Error('itemSize is 2 and texture.format is not RGBAFormat');
59569
- }
59570
- } else {
59571
- throw new Error('Unsupported itemSize');
59572
- }
59573
-
59574
- if (texture.image.data !== sampler.data) {
59575
- // dispose of previous texture data
59576
- texture.dispose();
59577
- }
59578
-
59579
- texture.image.data = sampler.data;
59580
- texture.image.width = sampler.width;
59581
- texture.image.height = sampler.height;
59582
-
59583
- texture.needsUpdate = true;
59584
- }
59585
-
59586
59630
  /**
59587
59631
  *
59588
59632
  * @param {WebGLRenderer} renderer
@@ -59651,32 +59695,25 @@ function promiseSamplerAO(
59651
59695
  function buildLightTexture({
59652
59696
  texture,
59653
59697
  heightSampler,
59654
- resolution= new Vector2(texture.image.width, texture.image.height),
59698
+ resolution = new Vector2(texture.image.width, texture.image.height),
59655
59699
  rayLength = 11,
59656
59700
  worldSize = resolution
59657
59701
  }) {
59658
59702
 
59659
- const renderer = WebGLRendererPool.global.get();
59703
+ return WebGLRendererPool.global.useAsync(async renderer => {
59704
+ const normal = promiseSamplerNormal(renderer, heightSampler);
59660
59705
 
59661
- const normal = promiseSamplerNormal(renderer, heightSampler);
59662
- const ao = promiseSamplerAO({
59663
- renderer: renderer,
59664
- pSamplerNormal: normal,
59665
- samplerHeight: heightSampler,
59666
- resolution: resolution,
59667
- rayLength: rayLength,
59668
- worldSize
59669
- });
59670
-
59671
- const promise = ao.then(sampler => {
59672
- writeSample2DDataToDataTexture(sampler, texture);
59673
- });
59706
+ const ao = await promiseSamplerAO({
59707
+ renderer: renderer,
59708
+ pSamplerNormal: normal,
59709
+ samplerHeight: heightSampler,
59710
+ resolution: resolution,
59711
+ rayLength: rayLength,
59712
+ worldSize
59713
+ });
59674
59714
 
59675
- Promise.all([normal, ao]).finally(() => {
59676
- WebGLRendererPool.global.release(renderer);
59715
+ writeSample2DDataToDataTexture(ao, texture);
59677
59716
  });
59678
-
59679
- return promise;
59680
59717
  }
59681
59718
 
59682
59719
  const GridTransformKind = {
@@ -59765,7 +59802,7 @@ function invokeObjectHash(object) {
59765
59802
  * @param {number} index0
59766
59803
  * @param {number} index1
59767
59804
  */
59768
- function arraySwapElements(array, index0, index1) {
59805
+ function array_swap_one(array, index0, index1) {
59769
59806
  const t = array[index0];
59770
59807
 
59771
59808
  array[index0] = array[index1];
@@ -59819,7 +59856,7 @@ function generate_next_linear_congruential_index(index, mask) {
59819
59856
  /**
59820
59857
  * @template K,V
59821
59858
  */
59822
- class MapEntry {
59859
+ class HashMapEntry {
59823
59860
  /**
59824
59861
  *
59825
59862
  * @param {K} key
@@ -59907,7 +59944,7 @@ const UNDEFINED_BIN_INDEX = ~0;
59907
59944
 
59908
59945
  /**
59909
59946
  * @template K,V
59910
- * @param {MapEntry<K,V>} record
59947
+ * @param {HashMapEntry<K,V>} record
59911
59948
  * @param {number} hash
59912
59949
  * @param {K} key
59913
59950
  * @param {function(a:K,b:K):boolean} equality_op
@@ -59947,7 +59984,7 @@ class HashMap {
59947
59984
 
59948
59985
  /**
59949
59986
  * Note that dead entries are marked as such with a special reserved hash values, so records can be reused for new entries
59950
- * @type {Array<MapEntry<K,V>>}
59987
+ * @type {Array<HashMapEntry<K,V>>}
59951
59988
  */
59952
59989
  #entries = new Array(0);
59953
59990
 
@@ -60125,7 +60162,7 @@ class HashMap {
60125
60162
  entry.key = k;
60126
60163
  entry.value = v;
60127
60164
  } else {
60128
- this.#entries[i] = new MapEntry(k, v, hash);
60165
+ this.#entries[i] = new HashMapEntry(k, v, hash);
60129
60166
  }
60130
60167
 
60131
60168
  return i;
@@ -60133,7 +60170,7 @@ class HashMap {
60133
60170
 
60134
60171
  /**
60135
60172
  *
60136
- * @param {MapEntry<K,V>} entry
60173
+ * @param {HashMapEntry<K,V>} entry
60137
60174
  */
60138
60175
  #deallocate(entry) {
60139
60176
 
@@ -60390,7 +60427,7 @@ class HashMap {
60390
60427
  }
60391
60428
 
60392
60429
  /**
60393
- * @type {MapEntry<K,V>}
60430
+ * @type {HashMapEntry<K,V>}
60394
60431
  */
60395
60432
  const entry = this.#entries[bin - ENTRY_BASE];
60396
60433
 
@@ -60441,7 +60478,7 @@ class HashMap {
60441
60478
 
60442
60479
  if (new_index !== existing_entry_index) {
60443
60480
  // move entries to the new position, compacting holes
60444
- arraySwapElements(entries, new_index, existing_entry_index);
60481
+ array_swap_one(entries, new_index, existing_entry_index);
60445
60482
  }
60446
60483
 
60447
60484
  let bin_index = this.#compute_bin_index(hash);
@@ -60495,7 +60532,7 @@ class HashMap {
60495
60532
  }
60496
60533
 
60497
60534
  /**
60498
- * @type {MapEntry<K,V>}
60535
+ * @type {HashMapEntry<K,V>}
60499
60536
  */
60500
60537
  const entry = entries[bin - ENTRY_BASE];
60501
60538
 
@@ -60566,7 +60603,7 @@ class HashMap {
60566
60603
  }
60567
60604
 
60568
60605
  /**
60569
- * @type {MapEntry<K,V>}
60606
+ * @type {HashMapEntry<K,V>}
60570
60607
  */
60571
60608
  const entry = entries[bin - ENTRY_BASE];
60572
60609
 
@@ -67264,6 +67301,37 @@ function computeFileExtension(path) {
67264
67301
  }
67265
67302
  }
67266
67303
 
67304
+ /**
67305
+ * @param {Uint8Array} input
67306
+ * @param {number} width
67307
+ * @param {number} height
67308
+ * @param {number} channel_count
67309
+ */
67310
+ function flipArrayInPlace(input, width, height, channel_count = 4) {
67311
+ const row_size = width * channel_count;
67312
+ let t, x0, x1;
67313
+ let i = 0;
67314
+ const column_count = height >> 1;
67315
+
67316
+ for (; i < column_count; i++) {
67317
+
67318
+ //swap lines
67319
+ const k = (height - i - 1) * row_size;
67320
+ const m = i * row_size;
67321
+
67322
+ for (let j = 0; j < row_size; j++) {
67323
+ x0 = m + j;
67324
+ x1 = k + j;
67325
+
67326
+ t = input[x0];
67327
+
67328
+ input[x0] = input[x1];
67329
+ input[x1] = t;
67330
+ }
67331
+
67332
+ }
67333
+ }
67334
+
67267
67335
  /**
67268
67336
  * @author alteredq / http://alteredqualia.com/
67269
67337
  *
@@ -67310,37 +67378,6 @@ const CopyShader = {
67310
67378
 
67311
67379
  };
67312
67380
 
67313
- /**
67314
- * @param {Uint8Array} input
67315
- * @param {number} width
67316
- * @param {number} height
67317
- * @param {number} channel_count
67318
- */
67319
- function flipArrayInPlace(input, width, height, channel_count = 4) {
67320
- const row_size = width * channel_count;
67321
- let t, x0, x1;
67322
- let i = 0;
67323
- const column_count = height >> 1;
67324
-
67325
- for (; i < column_count; i++) {
67326
-
67327
- //swap lines
67328
- const k = (height - i - 1) * row_size;
67329
- const m = i * row_size;
67330
-
67331
- for (let j = 0; j < row_size; j++) {
67332
- x0 = m + j;
67333
- x1 = k + j;
67334
-
67335
- t = input[x0];
67336
-
67337
- input[x0] = input[x1];
67338
- input[x1] = t;
67339
- }
67340
-
67341
- }
67342
- }
67343
-
67344
67381
  const DEFAULT_TEXTURE_WIDTH = 512;
67345
67382
  const DEFAULT_TEXTURE_HEIGHT = 512;
67346
67383
 
@@ -67349,39 +67386,47 @@ const DEFAULT_TEXTURE_HEIGHT = 512;
67349
67386
  * @param {Texture} texture
67350
67387
  * @param {number} [width]
67351
67388
  * @param {number} [height]
67352
- * @param {boolean} flipY
67389
+ * @param {boolean} [flipY]
67353
67390
  * @return {Sampler2D}
67354
67391
  */
67355
- function convertTexture2Sampler2D(texture, width, height, flipY = true) {
67392
+ function convertTexture2Sampler2D(
67393
+ texture,
67394
+ width,
67395
+ height,
67396
+ flipY = true
67397
+ ) {
67398
+ let _height = height;
67399
+ let _width = width;
67400
+
67356
67401
  // TODO take channel count into account
67357
67402
 
67358
- if (width === undefined || height === undefined) {
67403
+ if (_width === undefined || _height === undefined) {
67359
67404
 
67360
67405
  //figure out texture size
67361
67406
  const image = texture.image;
67362
67407
 
67363
67408
  if (image !== undefined && image !== null) {
67364
- if (width === undefined) {
67409
+ if (_width === undefined) {
67365
67410
  if (typeof image.width === "number") {
67366
- width = image.width;
67411
+ _width = image.width;
67367
67412
  } else {
67368
- width = DEFAULT_TEXTURE_WIDTH;
67413
+ _width = DEFAULT_TEXTURE_WIDTH;
67369
67414
  }
67370
67415
  }
67371
- if (height === undefined) {
67416
+ if (_height === undefined) {
67372
67417
  if (typeof image.height === "number") {
67373
- height = image.height;
67418
+ _height = image.height;
67374
67419
  } else {
67375
- height = DEFAULT_TEXTURE_HEIGHT;
67420
+ _height = DEFAULT_TEXTURE_HEIGHT;
67376
67421
  }
67377
67422
  }
67378
67423
  } else {
67379
- if (width === undefined) {
67380
- width = DEFAULT_TEXTURE_WIDTH;
67424
+ if (_width === undefined) {
67425
+ _width = DEFAULT_TEXTURE_WIDTH;
67381
67426
  }
67382
67427
 
67383
- if (height === undefined) {
67384
- height = DEFAULT_TEXTURE_HEIGHT;
67428
+ if (_height === undefined) {
67429
+ _height = DEFAULT_TEXTURE_HEIGHT;
67385
67430
  }
67386
67431
  }
67387
67432
 
@@ -67389,34 +67434,32 @@ function convertTexture2Sampler2D(texture, width, height, flipY = true) {
67389
67434
 
67390
67435
  // TODO add special case for DataTexture
67391
67436
 
67392
- const renderer = WebGLRendererPool.global.get({});
67437
+ const built = WebGLRendererPool.global.use(renderer => {
67393
67438
 
67394
- const ctx = renderer.getContext();
67439
+ const ctx = renderer.getContext();
67395
67440
 
67396
- //support for compressed textures
67397
- ctx.getExtension("WEBGL_compressed_texture_s3tc");
67441
+ //support for compressed textures
67442
+ ctx.getExtension("WEBGL_compressed_texture_s3tc");
67398
67443
 
67399
- const built = processTexture(renderer, width, height, {
67400
- vertexShader: CopyShader.vertexShader,
67401
- fragmentShader: CopyShader.fragmentShader,
67402
- uniforms: {
67403
- tDiffuse: {
67404
- value: texture,
67405
- type: 't'
67406
- },
67407
- opacity: { value: 1.0 }
67408
- }
67409
- });
67444
+ return processTexture(renderer, _width, _height, {
67445
+ vertexShader: CopyShader.vertexShader,
67446
+ fragmentShader: CopyShader.fragmentShader,
67447
+ uniforms: {
67448
+ tDiffuse: {
67449
+ value: texture,
67450
+ type: 't'
67451
+ },
67452
+ opacity: { value: 1.0 }
67453
+ }
67454
+ });
67410
67455
 
67411
- WebGLRendererPool.global.release(renderer);
67456
+ });
67412
67457
 
67413
67458
  if (flipY) {
67414
- flipArrayInPlace(built.array, width, height);
67459
+ flipArrayInPlace(built.array, _width, _height);
67415
67460
  }
67416
67461
 
67417
- const sampler = new Sampler2D(built.array, 4, width, height);
67418
-
67419
- return sampler;
67462
+ return new Sampler2D(built.array, 4, _width, _height);
67420
67463
  }
67421
67464
 
67422
67465
  /**
@@ -69047,10 +69090,14 @@ class Camera {
69047
69090
  * @param {Camera|THREE.PerspectiveCamera|THREE.OrthographicCamera} camera
69048
69091
  * @param {number} x
69049
69092
  * @param {number} y
69050
- * @param {Vector3} source
69051
- * @param {Vector3} direction
69093
+ * @param {Vector3} out_source
69094
+ * @param {Vector3} out_direction
69052
69095
  */
69053
- static projectRay(camera, x, y, source, direction) {
69096
+ static projectRay(
69097
+ camera,
69098
+ x, y,
69099
+ out_source, out_direction
69100
+ ) {
69054
69101
 
69055
69102
  // assert.ok(x >= -1, `X(=${x}) must be greater than or equal to -1.0, not a clip-space coordinate`);
69056
69103
  // assert.ok(x <= 1, `X(=${x}) must be less than or equal to 1.0, not a clip-space coordinate`);
@@ -69059,7 +69106,10 @@ class Camera {
69059
69106
  // assert.ok(y <= 1, `Y(=${y}) must be less than or equal to 1.0, not a clip-space coordinate`);
69060
69107
 
69061
69108
  if (camera.isPerspectiveCamera || camera.isOrthographicCamera) {
69062
- scratch_v3_1.setFromMatrixPosition(camera.matrixWorld.elements);
69109
+ const m4_world = camera.matrixWorld.elements;
69110
+ const m4_projection_inverse = camera.projectionMatrixInverse.elements;
69111
+
69112
+ scratch_v3_1.setFromMatrixPosition(m4_world);
69063
69113
 
69064
69114
  scratch_v3_0.set(x, y, 0.5);
69065
69115
 
@@ -69068,16 +69118,16 @@ class Camera {
69068
69118
  unprojectPoint(
69069
69119
  scratch_v3_0,
69070
69120
  scratch_v3_0,
69071
- camera.projectionMatrixInverse.elements,
69072
- camera.matrixWorld.elements
69121
+ m4_projection_inverse,
69122
+ m4_world
69073
69123
  );
69074
69124
 
69075
69125
  //get direction
69076
69126
  scratch_v3_0.sub(scratch_v3_1);
69077
69127
  scratch_v3_0.normalize();
69078
69128
 
69079
- source.copy(scratch_v3_1);
69080
- direction.copy(scratch_v3_0);
69129
+ out_source.copy(scratch_v3_1);
69130
+ out_direction.copy(scratch_v3_0);
69081
69131
 
69082
69132
  } else {
69083
69133
  throw new Error('Unsupported camera type');
@@ -74588,7 +74638,7 @@ function arrayQuickSort(
74588
74638
  data,
74589
74639
  score_function, score_function_context,
74590
74640
  start, end,
74591
- swap_operator = arraySwapElements, swap_context = undefined
74641
+ swap_operator = array_swap_one, swap_context = undefined
74592
74642
  ) {
74593
74643
  if (start >= end) {
74594
74644
  // section of 0 size, nothing to sort
@@ -81313,6 +81363,7 @@ class Token {
81313
81363
  * @param {T} type
81314
81364
  */
81315
81365
  constructor(value, start, end, name, type) {
81366
+
81316
81367
  /**
81317
81368
  * @readonly
81318
81369
  * @type {V}
@@ -81362,8 +81413,7 @@ class Token {
81362
81413
  * @return {number}
81363
81414
  */
81364
81415
  hash() {
81365
- // TODO make an actual hash
81366
- return 0;
81416
+ return this.start ^ (this.end << 16);
81367
81417
  }
81368
81418
  }
81369
81419
 
@@ -81379,10 +81429,71 @@ const TooltipTokenType = {
81379
81429
  ReferenceValue: 4,
81380
81430
  };
81381
81431
 
81382
- function ParserError(position, message, input) {
81383
- this.position = position;
81384
- this.message = message;
81385
- this.input = input;
81432
+ /**
81433
+ * Repeat a given piece of text a {@link count} times
81434
+ * @example "ABC_" repeated 2 times results in "ABC_ABC_"
81435
+ * @param {string} what
81436
+ * @param {number} count
81437
+ * @return {string}
81438
+ */
81439
+ function string_repeat(what, count) {
81440
+
81441
+ if (count <= 0) {
81442
+ // special case
81443
+ return "";
81444
+ }
81445
+
81446
+ let out = what;
81447
+
81448
+ for (let i = 1; i < count; i++) {
81449
+ out += what;
81450
+ }
81451
+
81452
+ return out;
81453
+ }
81454
+
81455
+ class ParserError extends Error {
81456
+ /**
81457
+ *
81458
+ * @param {number} position
81459
+ * @param {string} message
81460
+ * @param {string} input
81461
+ */
81462
+ constructor(
81463
+ position,
81464
+ message,
81465
+ input
81466
+ ) {
81467
+
81468
+ super();
81469
+
81470
+ this.position = position;
81471
+ this.message = message;
81472
+ this.input = input;
81473
+ }
81474
+
81475
+ getDetails() {
81476
+ const input = this.input;
81477
+ const position = this.position;
81478
+
81479
+ // get snippet around where the problem has occurred
81480
+ const input_start = max2(0, position - 10);
81481
+
81482
+ const input_end = min2(input.length, position + 10);
81483
+
81484
+ const snippet = input.slice(input_start, input_end);
81485
+
81486
+ const offset_into_snippet = position - input_start;
81487
+
81488
+ // a piece of text with marker to show where the error occurs
81489
+ const arrow_text = string_repeat(" ", offset_into_snippet) + "^";
81490
+
81491
+ return snippet + "\n" + arrow_text;
81492
+ }
81493
+
81494
+ toString() {
81495
+ return `[ParseError] ${this.message}. Error at position ${this.position} near:\n${this.getDetails()}`
81496
+ }
81386
81497
  }
81387
81498
 
81388
81499
  /**
@@ -81478,28 +81589,6 @@ class KeyValuePair {
81478
81589
  }
81479
81590
  }
81480
81591
 
81481
- /**
81482
- *
81483
- * @param {string} text
81484
- * @param {number} cursor
81485
- * @param {number} length
81486
- * @returns {number}
81487
- */
81488
- function skipWhitespace(text, cursor, length) {
81489
- let i = cursor;
81490
- let char;
81491
- while (i < length) {
81492
- char = text.charAt(i);
81493
-
81494
- if (char === ' ' || char === '\n' || char === '\t') {
81495
- i++;
81496
- } else {
81497
- break;
81498
- }
81499
- }
81500
- return i;
81501
- }
81502
-
81503
81592
  /**
81504
81593
  *
81505
81594
  * @enum {string}
@@ -81514,7 +81603,7 @@ const DataType = {
81514
81603
  };
81515
81604
 
81516
81605
  /**
81517
- * @enum {{LiteralString: string, LiteralNumber: string, LiteralBoolean: string}}
81606
+ * @enum {string}
81518
81607
  */
81519
81608
  const TokenType = {
81520
81609
  LiteralString: "literal-string",
@@ -81532,6 +81621,7 @@ const TokenType = {
81532
81621
  * @returns {Token}
81533
81622
  */
81534
81623
  function readBooleanToken(text, cursor, length) {
81624
+
81535
81625
  const firstChar = text.charAt(cursor);
81536
81626
 
81537
81627
  let value;
@@ -81558,96 +81648,6 @@ function readBooleanToken(text, cursor, length) {
81558
81648
  return new Token(value, cursor, end, TokenType.LiteralBoolean, DataType.Boolean);
81559
81649
  }
81560
81650
 
81561
- /**
81562
- *
81563
- * @param {string} text
81564
- * @param {number} cursor
81565
- * @returns {string}
81566
- */
81567
- function readQuote(text, cursor) {
81568
- const char = text.charAt(cursor);
81569
-
81570
- if (char !== '"' && char !== '\'') {
81571
- throw new ParserError(cursor, "Expected \", found " + char + " instead", text);
81572
- }
81573
-
81574
- return char;
81575
- }
81576
-
81577
- /**
81578
- *
81579
- * @param {string} text
81580
- * @param {number} cursor
81581
- * @param {number} length
81582
- * @returns {Token}
81583
- */
81584
- function readStringToken(text, cursor, length) {
81585
- let i = cursor;
81586
-
81587
- const openingQuote = readQuote(text, i);
81588
-
81589
- i++;
81590
-
81591
- let char;
81592
-
81593
- let value = '';
81594
- const lastPossibleChar = length - 1;
81595
-
81596
- for (; i < lastPossibleChar; i++) {
81597
- char = text.charAt(i);
81598
-
81599
- if (char === '\\') {
81600
- i++;
81601
- //read escape sequence
81602
- char = text.charAt(i);
81603
-
81604
- switch (char) {
81605
- case 'n':
81606
- value += '\n';
81607
- break;
81608
- case 't':
81609
- value += '\t';
81610
- break;
81611
- case 'r':
81612
- value += '\r';
81613
- break;
81614
- case 'b':
81615
- value += '\b';
81616
- break;
81617
- case 'f':
81618
- value += '\f';
81619
- break;
81620
- case 'v':
81621
- value += '\v';
81622
- break;
81623
- case '0':
81624
- value += '\0';
81625
- break;
81626
- case '\\':
81627
- case "'":
81628
- case '"':
81629
- default:
81630
- value += char;
81631
- break;
81632
- }
81633
- } else if (char !== openingQuote) {
81634
- value += char;
81635
- } else {
81636
- break;
81637
- }
81638
- }
81639
-
81640
- char = text.charAt(i);
81641
-
81642
- if (char !== openingQuote) {
81643
- throw new ParserError(cursor, "Expected string terminator : " + openingQuote + ", but found '" + char + "' instead", text);
81644
- }
81645
-
81646
- i++;
81647
-
81648
- return new Token(value, cursor, i, TokenType.LiteralString, DataType.String);
81649
- }
81650
-
81651
81651
  /**
81652
81652
  *
81653
81653
  * @param {string} text
@@ -81656,6 +81656,7 @@ function readStringToken(text, cursor, length) {
81656
81656
  * @returns {Token}
81657
81657
  */
81658
81658
  function readHexToken(text, cursor, length) {
81659
+
81659
81660
  const c0 = text.charAt(cursor);
81660
81661
  const c1 = text.charAt(cursor + 1);
81661
81662
 
@@ -81737,7 +81738,7 @@ function readHexToken(text, cursor, length) {
81737
81738
  }
81738
81739
 
81739
81740
 
81740
- return new Token(value, cursor, i, null, DataType.Number);
81741
+ return new Token(value, cursor, i, "uint", DataType.Number);
81741
81742
  }
81742
81743
 
81743
81744
  /**
@@ -81748,6 +81749,7 @@ function readHexToken(text, cursor, length) {
81748
81749
  * @returns {Token}
81749
81750
  */
81750
81751
  function readUnsignedIntegerToken(text, cursor, length) {
81752
+
81751
81753
  let i = cursor;
81752
81754
 
81753
81755
  let value = 0;
@@ -81799,7 +81801,32 @@ function readUnsignedIntegerToken(text, cursor, length) {
81799
81801
  }
81800
81802
 
81801
81803
 
81802
- return new Token(value, cursor, i, null, DataType.Number);
81804
+ return new Token(value, cursor, i, "uint", DataType.Number);
81805
+ }
81806
+
81807
+ /**
81808
+ *
81809
+ * @param {string} text
81810
+ * @param {number} cursor
81811
+ * @param {number} length
81812
+ * @returns {number}
81813
+ */
81814
+ function skipWhitespace(text, cursor, length) {
81815
+
81816
+ let i = cursor;
81817
+ let char;
81818
+
81819
+ while (i < length) {
81820
+ char = text.charAt(i);
81821
+
81822
+ if (char === ' ' || char === '\n' || char === '\t') {
81823
+ i++;
81824
+ } else {
81825
+ break;
81826
+ }
81827
+ }
81828
+
81829
+ return i;
81803
81830
  }
81804
81831
 
81805
81832
  /**
@@ -81810,6 +81837,7 @@ function readUnsignedIntegerToken(text, cursor, length) {
81810
81837
  * @returns {Token}
81811
81838
  */
81812
81839
  function readNumberToken(text, cursor, length) {
81840
+
81813
81841
  let i = cursor;
81814
81842
 
81815
81843
  //read optional sign
@@ -81869,6 +81897,97 @@ function readNumberToken(text, cursor, length) {
81869
81897
  return new Token(value, cursor, i, TokenType.LiteralNumber, DataType.Number);
81870
81898
  }
81871
81899
 
81900
+ /**
81901
+ *
81902
+ * @param {string} text
81903
+ * @param {number} cursor
81904
+ * @returns {string}
81905
+ */
81906
+ function readQuote(text, cursor) {
81907
+ const char = text.charAt(cursor);
81908
+
81909
+ if (char !== '"' && char !== '\'') {
81910
+ throw new ParserError(cursor, "Expected \", found " + char + " instead", text);
81911
+ }
81912
+
81913
+ return char;
81914
+ }
81915
+
81916
+ /**
81917
+ *
81918
+ * @param {string} text
81919
+ * @param {number} cursor
81920
+ * @param {number} length
81921
+ * @returns {Token}
81922
+ */
81923
+ function readStringToken(text, cursor, length) {
81924
+
81925
+ let i = cursor;
81926
+
81927
+ const openingQuote = readQuote(text, i);
81928
+
81929
+ i++;
81930
+
81931
+ let char;
81932
+
81933
+ let value = '';
81934
+ const lastPossibleChar = length - 1;
81935
+
81936
+ for (; i < lastPossibleChar; i++) {
81937
+ char = text.charAt(i);
81938
+
81939
+ if (char === '\\') {
81940
+ i++;
81941
+ //read escape sequence
81942
+ char = text.charAt(i);
81943
+
81944
+ switch (char) {
81945
+ case 'n':
81946
+ value += '\n';
81947
+ break;
81948
+ case 't':
81949
+ value += '\t';
81950
+ break;
81951
+ case 'r':
81952
+ value += '\r';
81953
+ break;
81954
+ case 'b':
81955
+ value += '\b';
81956
+ break;
81957
+ case 'f':
81958
+ value += '\f';
81959
+ break;
81960
+ case 'v':
81961
+ value += '\v';
81962
+ break;
81963
+ case '0':
81964
+ value += '\0';
81965
+ break;
81966
+ case '\\':
81967
+ case "'":
81968
+ case '"':
81969
+ default:
81970
+ value += char;
81971
+ break;
81972
+ }
81973
+ } else if (char !== openingQuote) {
81974
+ value += char;
81975
+ } else {
81976
+ break;
81977
+ }
81978
+ }
81979
+
81980
+ char = text.charAt(i);
81981
+
81982
+ if (char !== openingQuote) {
81983
+ throw new ParserError(cursor, "Expected string terminator : " + openingQuote + ", but found '" + char + "' instead", text);
81984
+ }
81985
+
81986
+ i++;
81987
+
81988
+ return new Token(value, cursor, i, TokenType.LiteralString, DataType.String);
81989
+ }
81990
+
81872
81991
  /**
81873
81992
  *
81874
81993
  * @param {string} text
@@ -81927,6 +82046,7 @@ function readArrayLiteral(text, cursor, length) {
81927
82046
  * @returns {Token}
81928
82047
  */
81929
82048
  function readLiteralToken(text, cursor, length) {
82049
+
81930
82050
  const firstChar = text.charAt(cursor);
81931
82051
 
81932
82052
  switch (firstChar) {
@@ -83906,11 +84026,14 @@ class BinaryHeap {
83906
84026
  }
83907
84027
  }
83908
84028
 
84029
+ /**
84030
+ * Decorator that wraps another map and lets you observe mutations
84031
+ * @template K,V
84032
+ */
83909
84033
  class ObservedMap {
83910
84034
  /**
83911
84035
  * @template K,V
83912
84036
  * @constructor
83913
- * @property {number} size
83914
84037
  */
83915
84038
  constructor(source = new Map()) {
83916
84039
  this.on = {
@@ -83993,10 +84116,11 @@ const STATUS_NORMAL = 2;
83993
84116
  class Deque {
83994
84117
  /**
83995
84118
  * @template T
84119
+ * @param {number} [min_size]
83996
84120
  */
83997
- constructor(minSize = DEFAULT_SIZE) {
84121
+ constructor(min_size = DEFAULT_SIZE) {
83998
84122
 
83999
- const size = ceilPowerOfTwo(max2(1, minSize));
84123
+ const size = ceilPowerOfTwo(max2(1, min_size));
84000
84124
 
84001
84125
  /**
84002
84126
  * Using static array allocator to preserve data locality.
@@ -84007,15 +84131,31 @@ class Deque {
84007
84131
  */
84008
84132
  this.__data = new Array(size);
84009
84133
 
84134
+ /**
84135
+ *
84136
+ * @type {number}
84137
+ * @private
84138
+ */
84010
84139
  this.__head = 0;
84140
+ /**
84141
+ *
84142
+ * @type {number}
84143
+ * @private
84144
+ */
84011
84145
  this.__tail = 0;
84012
84146
 
84147
+ /**
84148
+ *
84149
+ * @type {number}
84150
+ * @private
84151
+ */
84013
84152
  this.__status = STATUS_EMPTY;
84014
84153
  }
84015
84154
 
84016
84155
  /**
84017
84156
  *
84018
84157
  * @param {boolean} adding
84158
+ * @private
84019
84159
  */
84020
84160
  resetStatus(adding) {
84021
84161
  const head = this.__head;
@@ -84034,11 +84174,12 @@ class Deque {
84034
84174
  * @returns {number}
84035
84175
  * @private
84036
84176
  */
84037
- __circularBiggerPos(current) {
84038
- // TODO this can be done faster using mod operator (%)
84177
+ __circular_next_position(current) {
84039
84178
  const next = current + 1;
84040
84179
 
84041
- return (next >= this.__data.length) ? 0 : next;
84180
+ const length = this.__data.length;
84181
+
84182
+ return (next >= length) ? 0 : next;
84042
84183
  }
84043
84184
 
84044
84185
  /**
@@ -84047,43 +84188,57 @@ class Deque {
84047
84188
  * @returns {number}
84048
84189
  * @private
84049
84190
  */
84050
- __circularSmallerPos(current) {
84191
+ __circular_previous_position(current) {
84051
84192
  const prev = current - 1;
84052
84193
  return (prev < 0) ? (this.__data.length - 1) : prev;
84053
84194
  }
84054
84195
 
84055
- __checkAndExpand() {
84196
+ __check_and_expand() {
84056
84197
  const status = this.__status;
84198
+
84057
84199
  if (status !== STATUS_FULL) {
84200
+ // queue still has space, we're done
84058
84201
  return;
84059
84202
  }
84203
+
84060
84204
  const length = this.__data.length;
84061
84205
 
84062
- if (Number.MAX_SAFE_INTEGER === length) {
84206
+ if (UINT32_MAX === length) {
84063
84207
  throw new Error('Maximum array size exceeded');
84064
84208
  }
84065
84209
 
84066
- let newLength = length * 2;
84210
+ let new_length = length * 2;
84211
+
84067
84212
  // bigger than Integer.MAX_VALUE
84068
- if (newLength < 0) {
84069
- newLength = Number.MAX_SAFE_INTEGER;
84213
+ if (new_length > UINT32_MAX) {
84214
+ new_length = UINT32_MAX;
84070
84215
  }
84071
84216
 
84072
- const newElements = new Array(newLength);
84217
+ /**
84218
+ *
84219
+ * @type {T[]}
84220
+ */
84221
+ const new_data = new Array(new_length);
84073
84222
 
84074
- // copy front portion of data
84075
84223
  const head = this.__head;
84076
84224
 
84077
- array_copy(this.__data, head, newElements, 0, length - head);
84078
- array_copy(this.__data, 0, newElements, length - head, head);
84225
+ // copy the front portion
84226
+ array_copy(this.__data, head, new_data, 0, length - head);
84227
+ // copy the remainder
84228
+ array_copy(this.__data, 0, new_data, length - head, head);
84079
84229
 
84080
84230
  this.__head = 0;
84081
84231
  this.__tail = length;
84232
+
84082
84233
  this.__status = STATUS_NORMAL;
84083
84234
 
84084
- this.__data = newElements;
84235
+ this.__data = new_data;
84085
84236
  }
84086
84237
 
84238
+ /**
84239
+ *
84240
+ * @return {boolean}
84241
+ */
84087
84242
  isEmpty() {
84088
84243
  return this.size() === 0;
84089
84244
  }
@@ -84095,7 +84250,7 @@ class Deque {
84095
84250
 
84096
84251
  do {
84097
84252
  this.__data[cursor] = undefined;
84098
- cursor = this.__circularBiggerPos(cursor);
84253
+ cursor = this.__circular_next_position(cursor);
84099
84254
  } while (cursor !== tail);
84100
84255
 
84101
84256
  this.__status = STATUS_EMPTY;
@@ -84124,32 +84279,45 @@ class Deque {
84124
84279
  /**
84125
84280
  *
84126
84281
  * @param {number} current
84127
- * @param {boolean} frontShift
84282
+ * @param {boolean} shift_front should we shift elements before the removed element or after?
84128
84283
  * @private
84129
84284
  */
84130
- __removeInternal(current, frontShift) {
84285
+ __remove_internal(current, shift_front) {
84131
84286
  let cursor = current;
84132
- if (frontShift) {
84287
+
84288
+ if (shift_front) {
84289
+
84290
+ // shift towards tail
84291
+
84133
84292
  const head = this.__head;
84293
+
84134
84294
  while (cursor !== head) {
84135
- const next = this.__circularSmallerPos(cursor);
84295
+ const next = this.__circular_previous_position(cursor);
84136
84296
  this.__data[cursor] = this.__data[next];
84137
84297
  cursor = next;
84138
84298
  }
84139
- this.__head = this.__circularBiggerPos(head);
84299
+
84300
+ this.__head = this.__circular_next_position(head);
84301
+
84140
84302
  } else {
84303
+
84304
+ // shift towards head
84305
+
84141
84306
  const tail = this.__tail;
84142
84307
 
84143
84308
  while (cursor !== tail) {
84144
- const next = this.__circularBiggerPos(cursor);
84309
+ const next = this.__circular_next_position(cursor);
84145
84310
  this.__data[cursor] = this.__data[next];
84146
84311
  cursor = next;
84147
84312
  }
84148
84313
 
84149
- this.__tail = this.__circularSmallerPos(tail);
84314
+ this.__tail = this.__circular_previous_position(tail);
84315
+
84150
84316
  }
84151
84317
 
84318
+ // fill in slot of last moved element
84152
84319
  this.__data[cursor] = undefined;
84320
+
84153
84321
  this.resetStatus(false);
84154
84322
  }
84155
84323
 
@@ -84165,7 +84333,7 @@ class Deque {
84165
84333
  return false;
84166
84334
  }
84167
84335
 
84168
- this.__removeInternal(i, true);
84336
+ this.__remove_internal(i, true);
84169
84337
 
84170
84338
  return true;
84171
84339
  }
@@ -84209,20 +84377,20 @@ class Deque {
84209
84377
  * @param {T} e
84210
84378
  */
84211
84379
  addFirst(e) {
84212
- this.__checkAndExpand();
84213
- this.__head = this.__circularSmallerPos(this.__head);
84380
+ this.__check_and_expand();
84381
+ this.__head = this.__circular_previous_position(this.__head);
84214
84382
  this.__data[this.__head] = e;
84215
84383
  this.resetStatus(true);
84216
84384
  }
84217
84385
 
84218
84386
  /**
84219
84387
  * Remove element from the front of the queue
84220
- * @returns {T}
84388
+ * @returns {T|undefined}
84221
84389
  */
84222
84390
  removeFirst() {
84223
84391
  const element = this.__data[this.__head];
84224
84392
  this.__data[this.__head] = undefined;
84225
- this.__head = this.__circularBiggerPos(this.__head);
84393
+ this.__head = this.__circular_next_position(this.__head);
84226
84394
  this.resetStatus(false);
84227
84395
  return element;
84228
84396
  }
@@ -84240,9 +84408,9 @@ class Deque {
84240
84408
  * @param {T} e
84241
84409
  */
84242
84410
  addLast(e) {
84243
- this.__checkAndExpand();
84411
+ this.__check_and_expand();
84244
84412
  this.__data[this.__tail] = e;
84245
- this.__tail = this.__circularBiggerPos(this.__tail);
84413
+ this.__tail = this.__circular_next_position(this.__tail);
84246
84414
  this.resetStatus(true);
84247
84415
  }
84248
84416
 
@@ -84251,7 +84419,7 @@ class Deque {
84251
84419
  * @returns {T}
84252
84420
  */
84253
84421
  removeLast() {
84254
- const last = this.__circularSmallerPos(this.__tail);
84422
+ const last = this.__circular_previous_position(this.__tail);
84255
84423
  const element = this.__data[last];
84256
84424
  this.__data[last] = undefined;
84257
84425
  this.__tail = last;
@@ -84262,10 +84430,10 @@ class Deque {
84262
84430
 
84263
84431
  /**
84264
84432
  * Peek element from the end of the queue without removing it
84265
- * @returns {T}
84433
+ * @returns {T|undefined}
84266
84434
  */
84267
84435
  getLast() {
84268
- const last = this.__circularSmallerPos(this.__tail);
84436
+ const last = this.__circular_previous_position(this.__tail);
84269
84437
  return this.__data[last];
84270
84438
  }
84271
84439
  }
@@ -85973,35 +86141,44 @@ Preloader.prototype.load = function (assetManager) {
85973
86141
  return this;
85974
86142
  };
85975
86143
 
85976
- class AbstractMetric {
85977
- /**
85978
- *
85979
- * @param {number} value
85980
- * @returns {void}
85981
- */
85982
- record(value) {
85983
- throw new Error('Not implemented');
85984
- }
86144
+ /**
86145
+ * @template V
86146
+ * @param {V[]} data
86147
+ * @param {number} [start]
86148
+ * @param {number} [end]
86149
+ * @return {number}
86150
+ */
86151
+ function array_compute_max(data, start = 0, end = data.length) {
86152
+ let result = Number.NEGATIVE_INFINITY;
85985
86153
 
85986
- /**
85987
- * @returns {number|undefined}
85988
- */
85989
- getLastRecord() {
85990
- throw new Error('Not implemented');
86154
+ for (let i = start; i < end; i++) {
86155
+ const value = data[i];
86156
+ if (value > result) {
86157
+ result = value;
86158
+ }
85991
86159
  }
85992
86160
 
85993
- /**
85994
- *
85995
- * @param {MetricStatistics} result
85996
- * @returns {boolean} whether metric was successfully computed or not
85997
- */
85998
- computeStats(result) {
85999
- throw new Error('Not implemented');
86000
- }
86161
+ return result;
86162
+ }
86163
+
86164
+ /**
86165
+ * @template V
86166
+ * @param {V[]} data
86167
+ * @param {number} [start]
86168
+ * @param {number} [end]
86169
+ * @return {number}
86170
+ */
86171
+ function array_compute_min(data, start = 0, end = data.length) {
86172
+ let result = Number.POSITIVE_INFINITY;
86001
86173
 
86002
- clear() {
86003
- throw new Error('Not implemented');
86174
+ for (let i = start; i < end; i++) {
86175
+ const value = data[i];
86176
+ if (value < result) {
86177
+ result = value;
86178
+ }
86004
86179
  }
86180
+
86181
+ return result;
86005
86182
  }
86006
86183
 
86007
86184
  class RingBuffer {
@@ -86271,44 +86448,35 @@ function computeStatisticalPartialMedian(values, start, end) {
86271
86448
  return copy[position];
86272
86449
  }
86273
86450
 
86274
- /**
86275
- * @template V
86276
- * @param {V[]} data
86277
- * @param {number} [start]
86278
- * @param {number} [end]
86279
- * @return {number}
86280
- */
86281
- function computeArrayMax(data, start = 0, end = data.length) {
86282
- let result = Number.NEGATIVE_INFINITY;
86283
-
86284
- for (let i = start; i < end; i++) {
86285
- const value = data[i];
86286
- if (value > result) {
86287
- result = value;
86288
- }
86451
+ class AbstractMetric {
86452
+ /**
86453
+ *
86454
+ * @param {number} value
86455
+ * @returns {void}
86456
+ */
86457
+ record(value) {
86458
+ throw new Error('Not implemented');
86289
86459
  }
86290
86460
 
86291
- return result;
86292
- }
86293
-
86294
- /**
86295
- * @template V
86296
- * @param {V[]} data
86297
- * @param {number} [start]
86298
- * @param {number} [end]
86299
- * @return {number}
86300
- */
86301
- function computeArrayMin(data, start = 0, end = data.length) {
86302
- let result = Number.POSITIVE_INFINITY;
86461
+ /**
86462
+ * @returns {number|undefined}
86463
+ */
86464
+ getLastRecord() {
86465
+ throw new Error('Not implemented');
86466
+ }
86303
86467
 
86304
- for (let i = start; i < end; i++) {
86305
- const value = data[i];
86306
- if (value < result) {
86307
- result = value;
86308
- }
86468
+ /**
86469
+ *
86470
+ * @param {MetricStatistics} result
86471
+ * @returns {boolean} whether metric was successfully computed or not
86472
+ */
86473
+ computeStats(result) {
86474
+ throw new Error('Not implemented');
86309
86475
  }
86310
86476
 
86311
- return result;
86477
+ clear() {
86478
+ throw new Error('Not implemented');
86479
+ }
86312
86480
  }
86313
86481
 
86314
86482
  class RingBufferMetric extends AbstractMetric {
@@ -86365,8 +86533,8 @@ class RingBufferMetric extends AbstractMetric {
86365
86533
 
86366
86534
  result.mean = computeStatisticalMean(array, 0, data_count);
86367
86535
  result.median = computeStatisticalPartialMedian(array, 0, data_count - 1);
86368
- result.max = computeArrayMax(array, 0, data_count);
86369
- result.min = computeArrayMin(array, 0, data_count);
86536
+ result.max = array_compute_max(array, 0, data_count);
86537
+ result.min = array_compute_min(array, 0, data_count);
86370
86538
 
86371
86539
  return true;
86372
86540
 
@@ -110070,7 +110238,7 @@ class LightManager {
110070
110238
  __build_view_frustum(camera) {
110071
110239
  frustum_from_camera(camera, this.__view_frustum, false);
110072
110240
 
110073
- arraySwapElements(this.__view_frustum.planes, 4, 5);
110241
+ array_swap_one(this.__view_frustum.planes, 4, 5);
110074
110242
 
110075
110243
  this.__build_view_frustum_points();
110076
110244
  }