@woosh/meep-engine 2.96.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.
- package/build/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +892 -687
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +892 -687
- package/package.json +1 -1
- package/src/core/binary/BitSet.d.ts +2 -2
- package/src/core/binary/BitSet.d.ts.map +1 -1
- package/src/core/binary/BitSet.js +8 -5
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +1 -1
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +1 -1
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray.d.ts.map +1 -1
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray.js +3 -2
- package/src/core/collection/array/arrayQuickSort.js +2 -2
- package/src/core/collection/array/array_compute_max.d.ts +9 -0
- package/src/core/collection/array/array_compute_max.d.ts.map +1 -0
- package/src/core/collection/array/{computeArrayMax.js → array_compute_max.js} +1 -1
- package/src/core/collection/array/array_compute_min.d.ts +9 -0
- package/src/core/collection/array/array_compute_min.d.ts.map +1 -0
- package/src/core/collection/array/{computeArrayMin.js → array_compute_min.js} +1 -1
- package/src/core/collection/array/array_compute_min_max.d.ts.map +1 -1
- package/src/core/collection/array/array_compute_min_max.js +1 -0
- package/src/core/collection/array/array_swap.d.ts.map +1 -1
- package/src/core/collection/array/array_swap.js +11 -8
- package/src/core/collection/array/array_swap_one.d.ts +8 -0
- package/src/core/collection/array/array_swap_one.d.ts.map +1 -0
- package/src/core/collection/array/{arraySwapElements.js → array_swap_one.js} +1 -1
- package/src/core/collection/array/iterator/AbstractArrayIterator.d.ts.map +1 -0
- package/src/core/collection/array/iterator/ArrayIteratorRandom.d.ts.map +1 -0
- package/src/core/collection/array/{ArrayIteratorRandom.js → iterator/ArrayIteratorRandom.js} +2 -2
- package/src/core/collection/array/iterator/ArrayIteratorSequential.d.ts.map +1 -0
- package/src/core/collection/array/randomizeArrayElementOrder.js +2 -2
- package/src/core/collection/map/HashMap.js +10 -10
- package/src/core/collection/map/ObservedMap.d.ts +7 -4
- package/src/core/collection/map/ObservedMap.d.ts.map +1 -1
- package/src/core/collection/map/ObservedMap.js +4 -1
- package/src/core/collection/queue/Deque.d.ts.map +1 -1
- package/src/core/collection/queue/Deque.js +82 -36
- package/src/core/geom/3d/aabb/aabb3_intersects_ray.js +10 -10
- package/src/core/graph/v2/Graph.d.ts.map +1 -1
- package/src/core/graph/v2/Graph.js +9 -0
- package/src/core/math/spline/computeNonuniformCaltmullRomSplineDerivative.d.ts +16 -0
- package/src/core/math/spline/computeNonuniformCaltmullRomSplineDerivative.d.ts.map +1 -0
- package/src/core/math/spline/computeNonuniformCaltmullRomSplineDerivative.js +90 -0
- package/src/core/parser/simple/ParserError.d.ts +11 -6
- package/src/core/parser/simple/ParserError.d.ts.map +1 -1
- package/src/core/parser/simple/ParserError.js +51 -4
- package/src/core/parser/simple/Token.d.ts.map +1 -1
- package/src/core/parser/simple/Token.js +8 -2
- package/src/core/parser/simple/TokenType.d.ts +1 -5
- package/src/core/parser/simple/TokenType.d.ts.map +1 -1
- package/src/core/parser/simple/TokenType.js +1 -1
- package/src/core/parser/simple/readBooleanToken.d.ts.map +1 -1
- package/src/core/parser/simple/readBooleanToken.js +6 -1
- package/src/core/parser/simple/readHexToken.d.ts.map +1 -1
- package/src/core/parser/simple/readHexToken.js +7 -2
- package/src/core/parser/simple/readIdentifierToken.d.ts.map +1 -1
- package/src/core/parser/simple/readIdentifierToken.js +6 -1
- package/src/core/parser/simple/readLiteralToken.d.ts.map +1 -1
- package/src/core/parser/simple/readLiteralToken.js +8 -3
- package/src/core/parser/simple/readNumberToken.d.ts.map +1 -1
- package/src/core/parser/simple/readNumberToken.js +7 -2
- package/src/core/parser/simple/readReferenceToken.d.ts.map +1 -1
- package/src/core/parser/simple/readReferenceToken.js +6 -1
- package/src/core/parser/simple/readStringToken.d.ts.map +1 -1
- package/src/core/parser/simple/readStringToken.js +6 -1
- package/src/core/parser/simple/readUnsignedIntegerToken.d.ts.map +1 -1
- package/src/core/parser/simple/readUnsignedIntegerToken.js +7 -2
- package/src/core/parser/simple/skipWhitespace.d.ts.map +1 -1
- package/src/core/parser/simple/skipWhitespace.js +8 -0
- package/src/core/primitives/strings/string_jaro_distance.d.ts +10 -0
- package/src/core/primitives/strings/string_jaro_distance.d.ts.map +1 -0
- package/src/core/primitives/strings/string_jaro_distance.js +127 -0
- package/src/core/primitives/strings/string_jaro_winkler.d.ts.map +1 -1
- package/src/core/primitives/strings/string_jaro_winkler.js +5 -105
- package/src/core/primitives/strings/string_repeat.d.ts +9 -0
- package/src/core/primitives/strings/string_repeat.d.ts.map +1 -0
- package/src/core/primitives/strings/string_repeat.js +26 -0
- package/src/engine/asset/AssetManager.d.ts.map +1 -1
- package/src/engine/development/performance/RingBufferMetric.d.ts.map +1 -1
- package/src/engine/development/performance/RingBufferMetric.js +5 -5
- package/src/engine/ecs/terrain/ecs/BuildLightTexture.d.ts.map +1 -1
- package/src/engine/ecs/terrain/ecs/BuildLightTexture.js +15 -22
- package/src/engine/graphics/ecs/camera/Camera.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/Camera.js +23 -16
- package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +142 -10
- package/src/engine/graphics/ecs/path/tube/build/TubePathBuilder.d.ts.map +1 -1
- package/src/engine/graphics/ecs/path/tube/build/TubePathBuilder.js +9 -9
- package/src/engine/graphics/ecs/path/tube/build/build_geometry_catmullrom.d.ts.map +1 -1
- package/src/engine/graphics/ecs/path/tube/build/build_geometry_catmullrom.js +173 -23
- package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +16 -2
- package/src/engine/graphics/filter/ImageFilter.d.ts +2 -2
- package/src/engine/graphics/filter/ImageFilter.d.ts.map +1 -1
- package/src/engine/graphics/filter/ImageFilter.js +3 -3
- package/src/engine/graphics/render/RendererPool.d.ts +14 -1
- package/src/engine/graphics/render/RendererPool.d.ts.map +1 -1
- package/src/engine/graphics/render/RendererPool.js +43 -1
- package/src/engine/graphics/render/forward_plus/LightManager.js +2 -2
- package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +2 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +23 -50
- package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.d.ts +9 -0
- package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.js +53 -3
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +3 -3
- package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts +1 -1
- package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +42 -36
- package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.d.ts +3 -0
- package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.d.ts.map +1 -0
- package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.js +34 -0
- package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.d.ts +10 -0
- package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.d.ts.map +1 -0
- package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.js +89 -0
- package/src/engine/graphics/texture/sampler/debug/prototypeSamplerFiltering.d.ts.map +1 -0
- package/src/engine/graphics/texture/sampler/{prototypeSamplerFiltering.js → debug/prototypeSamplerFiltering.js} +105 -113
- package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.d.ts.map +1 -1
- package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.js +8 -8
- package/src/generation/markers/GridActionRuleSet.d.ts.map +1 -1
- package/src/generation/markers/GridActionRuleSet.js +5 -5
- package/src/core/binary/byteArrayToString.d.ts +0 -9
- package/src/core/binary/byteArrayToString.d.ts.map +0 -1
- package/src/core/binary/byteArrayToString.js +0 -28
- package/src/core/collection/array/AbstractArrayIterator.d.ts.map +0 -1
- package/src/core/collection/array/ArrayIteratorRandom.d.ts.map +0 -1
- package/src/core/collection/array/ArrayIteratorSequential.d.ts.map +0 -1
- package/src/core/collection/array/arrayPickMinElement.d.ts +0 -8
- package/src/core/collection/array/arrayPickMinElement.d.ts.map +0 -1
- package/src/core/collection/array/arrayPickMinElement.js +0 -43
- package/src/core/collection/array/arraySwapElements.d.ts +0 -8
- package/src/core/collection/array/arraySwapElements.d.ts.map +0 -1
- package/src/core/collection/array/computeArrayMax.d.ts +0 -9
- package/src/core/collection/array/computeArrayMax.d.ts.map +0 -1
- package/src/core/collection/array/computeArrayMin.d.ts +0 -9
- package/src/core/collection/array/computeArrayMin.d.ts.map +0 -1
- package/src/engine/graphics/texture/sampler/prototypeSamplerFiltering.d.ts.map +0 -1
- /package/src/core/collection/array/{AbstractArrayIterator.d.ts → iterator/AbstractArrayIterator.d.ts} +0 -0
- /package/src/core/collection/array/{AbstractArrayIterator.js → iterator/AbstractArrayIterator.js} +0 -0
- /package/src/core/collection/array/{ArrayIteratorRandom.d.ts → iterator/ArrayIteratorRandom.d.ts} +0 -0
- /package/src/core/collection/array/{ArrayIteratorSequential.d.ts → iterator/ArrayIteratorSequential.d.ts} +0 -0
- /package/src/core/collection/array/{ArrayIteratorSequential.js → iterator/ArrayIteratorSequential.js} +0 -0
- /package/src/engine/graphics/texture/sampler/{prototypeSamplerFiltering.d.ts → debug/prototypeSamplerFiltering.d.ts} +0 -0
package/build/meep.module.js
CHANGED
|
@@ -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
|
|
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 &&
|
|
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 &&
|
|
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 &&
|
|
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 =
|
|
53244
|
-
const abs_direction_z =
|
|
53243
|
+
const abs_direction_y = abs(direction_y);
|
|
53244
|
+
const abs_direction_z = abs(direction_z);
|
|
53245
53245
|
|
|
53246
|
-
const f0 =
|
|
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 =
|
|
53252
|
+
const abs_direction_x = abs(direction_x);
|
|
53253
53253
|
|
|
53254
|
-
const f1 =
|
|
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 =
|
|
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(
|
|
54955
|
-
|
|
54956
|
-
|
|
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
|
|
54964
|
+
const swap = b[j];
|
|
54963
54965
|
|
|
54964
54966
|
b[j] = a[i];
|
|
54965
|
-
a[i] =
|
|
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
|
-
|
|
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
|
-
"
|
|
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
|
|
58863
|
-
uniform sampler2D heightMap;
|
|
58864
|
-
uniform float rayLength;
|
|
58865
|
-
uniform vec2 world_size;
|
|
58980
|
+
"uniform vec2 resolution;",
|
|
58981
|
+
"uniform sampler2D heightMap;",
|
|
58866
58982
|
|
|
58867
|
-
|
|
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
|
|
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
|
-
|
|
59660
|
-
|
|
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
|
-
});
|
|
59703
|
+
return WebGLRendererPool.global.useAsync(async renderer => {
|
|
59704
|
+
const normal = promiseSamplerNormal(renderer, heightSampler);
|
|
59670
59705
|
|
|
59671
|
-
|
|
59672
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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 {
|
|
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<
|
|
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
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
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 {
|
|
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 {
|
|
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(
|
|
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 (
|
|
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 (
|
|
67409
|
+
if (_width === undefined) {
|
|
67365
67410
|
if (typeof image.width === "number") {
|
|
67366
|
-
|
|
67411
|
+
_width = image.width;
|
|
67367
67412
|
} else {
|
|
67368
|
-
|
|
67413
|
+
_width = DEFAULT_TEXTURE_WIDTH;
|
|
67369
67414
|
}
|
|
67370
67415
|
}
|
|
67371
|
-
if (
|
|
67416
|
+
if (_height === undefined) {
|
|
67372
67417
|
if (typeof image.height === "number") {
|
|
67373
|
-
|
|
67418
|
+
_height = image.height;
|
|
67374
67419
|
} else {
|
|
67375
|
-
|
|
67420
|
+
_height = DEFAULT_TEXTURE_HEIGHT;
|
|
67376
67421
|
}
|
|
67377
67422
|
}
|
|
67378
67423
|
} else {
|
|
67379
|
-
if (
|
|
67380
|
-
|
|
67424
|
+
if (_width === undefined) {
|
|
67425
|
+
_width = DEFAULT_TEXTURE_WIDTH;
|
|
67381
67426
|
}
|
|
67382
67427
|
|
|
67383
|
-
if (
|
|
67384
|
-
|
|
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
|
|
67437
|
+
const built = WebGLRendererPool.global.use(renderer => {
|
|
67438
|
+
|
|
67439
|
+
const ctx = renderer.getContext();
|
|
67393
67440
|
|
|
67394
|
-
|
|
67441
|
+
//support for compressed textures
|
|
67442
|
+
ctx.getExtension("WEBGL_compressed_texture_s3tc");
|
|
67395
67443
|
|
|
67396
|
-
|
|
67397
|
-
|
|
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
|
+
});
|
|
67398
67455
|
|
|
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
67456
|
});
|
|
67410
67457
|
|
|
67411
|
-
WebGLRendererPool.global.release(renderer);
|
|
67412
|
-
|
|
67413
67458
|
if (flipY) {
|
|
67414
|
-
flipArrayInPlace(built.array,
|
|
67459
|
+
flipArrayInPlace(built.array, _width, _height);
|
|
67415
67460
|
}
|
|
67416
67461
|
|
|
67417
|
-
|
|
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}
|
|
69051
|
-
* @param {Vector3}
|
|
69093
|
+
* @param {Vector3} out_source
|
|
69094
|
+
* @param {Vector3} out_direction
|
|
69052
69095
|
*/
|
|
69053
|
-
static projectRay(
|
|
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
|
-
|
|
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
|
-
|
|
69072
|
-
|
|
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
|
-
|
|
69080
|
-
|
|
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');
|
|
@@ -69972,13 +70022,15 @@ BitSet.prototype.setShrinkFactor = function (x) {
|
|
|
69972
70022
|
|
|
69973
70023
|
/**
|
|
69974
70024
|
*
|
|
69975
|
-
* @param {number}
|
|
70025
|
+
* @param {number} bit_count
|
|
69976
70026
|
*/
|
|
69977
|
-
BitSet.prototype.setCapacity = function (
|
|
69978
|
-
|
|
69979
|
-
|
|
70027
|
+
BitSet.prototype.setCapacity = function (bit_count) {
|
|
70028
|
+
|
|
70029
|
+
if (this.__length > bit_count) {
|
|
70030
|
+
throw new Error(`Current length(=${this.__length}) is greater than requested size(=${bit_count})`);
|
|
69980
70031
|
}
|
|
69981
|
-
|
|
70032
|
+
|
|
70033
|
+
this.__resize(bit_count);
|
|
69982
70034
|
};
|
|
69983
70035
|
|
|
69984
70036
|
/**
|
|
@@ -71490,8 +71542,17 @@ class Graph {
|
|
|
71490
71542
|
*/
|
|
71491
71543
|
findPath(start, goal) {
|
|
71492
71544
|
const start_node_container = this.__nodes.get(start);
|
|
71545
|
+
|
|
71546
|
+
if (start_node_container === undefined) {
|
|
71547
|
+
throw new Error(`Start node not found in the graph '${start}'`);
|
|
71548
|
+
}
|
|
71549
|
+
|
|
71493
71550
|
const goal_node_container = this.__nodes.get(goal);
|
|
71494
71551
|
|
|
71552
|
+
if (goal_node_container === undefined) {
|
|
71553
|
+
throw new Error(`Goal node not found in the graph '${goal}'`);
|
|
71554
|
+
}
|
|
71555
|
+
|
|
71495
71556
|
const open = new Set();
|
|
71496
71557
|
open.add(start_node_container);
|
|
71497
71558
|
|
|
@@ -74577,7 +74638,7 @@ function arrayQuickSort(
|
|
|
74577
74638
|
data,
|
|
74578
74639
|
score_function, score_function_context,
|
|
74579
74640
|
start, end,
|
|
74580
|
-
swap_operator =
|
|
74641
|
+
swap_operator = array_swap_one, swap_context = undefined
|
|
74581
74642
|
) {
|
|
74582
74643
|
if (start >= end) {
|
|
74583
74644
|
// section of 0 size, nothing to sort
|
|
@@ -81302,6 +81363,7 @@ class Token {
|
|
|
81302
81363
|
* @param {T} type
|
|
81303
81364
|
*/
|
|
81304
81365
|
constructor(value, start, end, name, type) {
|
|
81366
|
+
|
|
81305
81367
|
/**
|
|
81306
81368
|
* @readonly
|
|
81307
81369
|
* @type {V}
|
|
@@ -81351,8 +81413,7 @@ class Token {
|
|
|
81351
81413
|
* @return {number}
|
|
81352
81414
|
*/
|
|
81353
81415
|
hash() {
|
|
81354
|
-
|
|
81355
|
-
return 0;
|
|
81416
|
+
return this.start ^ (this.end << 16);
|
|
81356
81417
|
}
|
|
81357
81418
|
}
|
|
81358
81419
|
|
|
@@ -81368,10 +81429,71 @@ const TooltipTokenType = {
|
|
|
81368
81429
|
ReferenceValue: 4,
|
|
81369
81430
|
};
|
|
81370
81431
|
|
|
81371
|
-
|
|
81372
|
-
|
|
81373
|
-
|
|
81374
|
-
|
|
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
|
+
}
|
|
81375
81497
|
}
|
|
81376
81498
|
|
|
81377
81499
|
/**
|
|
@@ -81467,28 +81589,6 @@ class KeyValuePair {
|
|
|
81467
81589
|
}
|
|
81468
81590
|
}
|
|
81469
81591
|
|
|
81470
|
-
/**
|
|
81471
|
-
*
|
|
81472
|
-
* @param {string} text
|
|
81473
|
-
* @param {number} cursor
|
|
81474
|
-
* @param {number} length
|
|
81475
|
-
* @returns {number}
|
|
81476
|
-
*/
|
|
81477
|
-
function skipWhitespace(text, cursor, length) {
|
|
81478
|
-
let i = cursor;
|
|
81479
|
-
let char;
|
|
81480
|
-
while (i < length) {
|
|
81481
|
-
char = text.charAt(i);
|
|
81482
|
-
|
|
81483
|
-
if (char === ' ' || char === '\n' || char === '\t') {
|
|
81484
|
-
i++;
|
|
81485
|
-
} else {
|
|
81486
|
-
break;
|
|
81487
|
-
}
|
|
81488
|
-
}
|
|
81489
|
-
return i;
|
|
81490
|
-
}
|
|
81491
|
-
|
|
81492
81592
|
/**
|
|
81493
81593
|
*
|
|
81494
81594
|
* @enum {string}
|
|
@@ -81503,7 +81603,7 @@ const DataType = {
|
|
|
81503
81603
|
};
|
|
81504
81604
|
|
|
81505
81605
|
/**
|
|
81506
|
-
* @enum {
|
|
81606
|
+
* @enum {string}
|
|
81507
81607
|
*/
|
|
81508
81608
|
const TokenType = {
|
|
81509
81609
|
LiteralString: "literal-string",
|
|
@@ -81521,6 +81621,7 @@ const TokenType = {
|
|
|
81521
81621
|
* @returns {Token}
|
|
81522
81622
|
*/
|
|
81523
81623
|
function readBooleanToken(text, cursor, length) {
|
|
81624
|
+
|
|
81524
81625
|
const firstChar = text.charAt(cursor);
|
|
81525
81626
|
|
|
81526
81627
|
let value;
|
|
@@ -81547,96 +81648,6 @@ function readBooleanToken(text, cursor, length) {
|
|
|
81547
81648
|
return new Token(value, cursor, end, TokenType.LiteralBoolean, DataType.Boolean);
|
|
81548
81649
|
}
|
|
81549
81650
|
|
|
81550
|
-
/**
|
|
81551
|
-
*
|
|
81552
|
-
* @param {string} text
|
|
81553
|
-
* @param {number} cursor
|
|
81554
|
-
* @returns {string}
|
|
81555
|
-
*/
|
|
81556
|
-
function readQuote(text, cursor) {
|
|
81557
|
-
const char = text.charAt(cursor);
|
|
81558
|
-
|
|
81559
|
-
if (char !== '"' && char !== '\'') {
|
|
81560
|
-
throw new ParserError(cursor, "Expected \", found " + char + " instead", text);
|
|
81561
|
-
}
|
|
81562
|
-
|
|
81563
|
-
return char;
|
|
81564
|
-
}
|
|
81565
|
-
|
|
81566
|
-
/**
|
|
81567
|
-
*
|
|
81568
|
-
* @param {string} text
|
|
81569
|
-
* @param {number} cursor
|
|
81570
|
-
* @param {number} length
|
|
81571
|
-
* @returns {Token}
|
|
81572
|
-
*/
|
|
81573
|
-
function readStringToken(text, cursor, length) {
|
|
81574
|
-
let i = cursor;
|
|
81575
|
-
|
|
81576
|
-
const openingQuote = readQuote(text, i);
|
|
81577
|
-
|
|
81578
|
-
i++;
|
|
81579
|
-
|
|
81580
|
-
let char;
|
|
81581
|
-
|
|
81582
|
-
let value = '';
|
|
81583
|
-
const lastPossibleChar = length - 1;
|
|
81584
|
-
|
|
81585
|
-
for (; i < lastPossibleChar; i++) {
|
|
81586
|
-
char = text.charAt(i);
|
|
81587
|
-
|
|
81588
|
-
if (char === '\\') {
|
|
81589
|
-
i++;
|
|
81590
|
-
//read escape sequence
|
|
81591
|
-
char = text.charAt(i);
|
|
81592
|
-
|
|
81593
|
-
switch (char) {
|
|
81594
|
-
case 'n':
|
|
81595
|
-
value += '\n';
|
|
81596
|
-
break;
|
|
81597
|
-
case 't':
|
|
81598
|
-
value += '\t';
|
|
81599
|
-
break;
|
|
81600
|
-
case 'r':
|
|
81601
|
-
value += '\r';
|
|
81602
|
-
break;
|
|
81603
|
-
case 'b':
|
|
81604
|
-
value += '\b';
|
|
81605
|
-
break;
|
|
81606
|
-
case 'f':
|
|
81607
|
-
value += '\f';
|
|
81608
|
-
break;
|
|
81609
|
-
case 'v':
|
|
81610
|
-
value += '\v';
|
|
81611
|
-
break;
|
|
81612
|
-
case '0':
|
|
81613
|
-
value += '\0';
|
|
81614
|
-
break;
|
|
81615
|
-
case '\\':
|
|
81616
|
-
case "'":
|
|
81617
|
-
case '"':
|
|
81618
|
-
default:
|
|
81619
|
-
value += char;
|
|
81620
|
-
break;
|
|
81621
|
-
}
|
|
81622
|
-
} else if (char !== openingQuote) {
|
|
81623
|
-
value += char;
|
|
81624
|
-
} else {
|
|
81625
|
-
break;
|
|
81626
|
-
}
|
|
81627
|
-
}
|
|
81628
|
-
|
|
81629
|
-
char = text.charAt(i);
|
|
81630
|
-
|
|
81631
|
-
if (char !== openingQuote) {
|
|
81632
|
-
throw new ParserError(cursor, "Expected string terminator : " + openingQuote + ", but found '" + char + "' instead", text);
|
|
81633
|
-
}
|
|
81634
|
-
|
|
81635
|
-
i++;
|
|
81636
|
-
|
|
81637
|
-
return new Token(value, cursor, i, TokenType.LiteralString, DataType.String);
|
|
81638
|
-
}
|
|
81639
|
-
|
|
81640
81651
|
/**
|
|
81641
81652
|
*
|
|
81642
81653
|
* @param {string} text
|
|
@@ -81645,6 +81656,7 @@ function readStringToken(text, cursor, length) {
|
|
|
81645
81656
|
* @returns {Token}
|
|
81646
81657
|
*/
|
|
81647
81658
|
function readHexToken(text, cursor, length) {
|
|
81659
|
+
|
|
81648
81660
|
const c0 = text.charAt(cursor);
|
|
81649
81661
|
const c1 = text.charAt(cursor + 1);
|
|
81650
81662
|
|
|
@@ -81726,7 +81738,7 @@ function readHexToken(text, cursor, length) {
|
|
|
81726
81738
|
}
|
|
81727
81739
|
|
|
81728
81740
|
|
|
81729
|
-
return new Token(value, cursor, i,
|
|
81741
|
+
return new Token(value, cursor, i, "uint", DataType.Number);
|
|
81730
81742
|
}
|
|
81731
81743
|
|
|
81732
81744
|
/**
|
|
@@ -81737,6 +81749,7 @@ function readHexToken(text, cursor, length) {
|
|
|
81737
81749
|
* @returns {Token}
|
|
81738
81750
|
*/
|
|
81739
81751
|
function readUnsignedIntegerToken(text, cursor, length) {
|
|
81752
|
+
|
|
81740
81753
|
let i = cursor;
|
|
81741
81754
|
|
|
81742
81755
|
let value = 0;
|
|
@@ -81788,7 +81801,32 @@ function readUnsignedIntegerToken(text, cursor, length) {
|
|
|
81788
81801
|
}
|
|
81789
81802
|
|
|
81790
81803
|
|
|
81791
|
-
return new Token(value, cursor, i,
|
|
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;
|
|
81792
81830
|
}
|
|
81793
81831
|
|
|
81794
81832
|
/**
|
|
@@ -81799,6 +81837,7 @@ function readUnsignedIntegerToken(text, cursor, length) {
|
|
|
81799
81837
|
* @returns {Token}
|
|
81800
81838
|
*/
|
|
81801
81839
|
function readNumberToken(text, cursor, length) {
|
|
81840
|
+
|
|
81802
81841
|
let i = cursor;
|
|
81803
81842
|
|
|
81804
81843
|
//read optional sign
|
|
@@ -81858,6 +81897,97 @@ function readNumberToken(text, cursor, length) {
|
|
|
81858
81897
|
return new Token(value, cursor, i, TokenType.LiteralNumber, DataType.Number);
|
|
81859
81898
|
}
|
|
81860
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
|
+
|
|
81861
81991
|
/**
|
|
81862
81992
|
*
|
|
81863
81993
|
* @param {string} text
|
|
@@ -81916,6 +82046,7 @@ function readArrayLiteral(text, cursor, length) {
|
|
|
81916
82046
|
* @returns {Token}
|
|
81917
82047
|
*/
|
|
81918
82048
|
function readLiteralToken(text, cursor, length) {
|
|
82049
|
+
|
|
81919
82050
|
const firstChar = text.charAt(cursor);
|
|
81920
82051
|
|
|
81921
82052
|
switch (firstChar) {
|
|
@@ -82203,22 +82334,20 @@ function seedVariablesIntoTemplateString(template, seed) {
|
|
|
82203
82334
|
}
|
|
82204
82335
|
|
|
82205
82336
|
/**
|
|
82206
|
-
* Calculate
|
|
82207
|
-
* @param {string} first
|
|
82208
|
-
* @param {string} second
|
|
82209
|
-
* @
|
|
82337
|
+
* Calculate Jaro distance between two strings, this is a measure of string similarity. Higher value means more similarity.
|
|
82338
|
+
* @param {string} first
|
|
82339
|
+
* @param {string} second
|
|
82340
|
+
* @param {number} first_length
|
|
82341
|
+
* @param {number} second_length
|
|
82342
|
+
* @return {number}
|
|
82210
82343
|
*/
|
|
82211
|
-
function
|
|
82212
|
-
|
|
82213
|
-
|
|
82214
|
-
|
|
82215
|
-
if (l1 === 0 && l2 === 0) {
|
|
82216
|
-
// special case for empty string
|
|
82217
|
-
return 1;
|
|
82218
|
-
}
|
|
82344
|
+
function string_jaro_distance(
|
|
82345
|
+
first, second,
|
|
82346
|
+
first_length, second_length
|
|
82347
|
+
) {
|
|
82219
82348
|
|
|
82220
|
-
const matches1 = BitSet.fixedSize(
|
|
82221
|
-
const matches2 = BitSet.fixedSize(
|
|
82349
|
+
const matches1 = BitSet.fixedSize(first_length);
|
|
82350
|
+
const matches2 = BitSet.fixedSize(second_length);
|
|
82222
82351
|
|
|
82223
82352
|
const matches = getMatching(first, second, matches1, matches2);
|
|
82224
82353
|
|
|
@@ -82226,15 +82355,9 @@ function string_jaro_winkler(first, second) {
|
|
|
82226
82355
|
return 0;
|
|
82227
82356
|
}
|
|
82228
82357
|
|
|
82229
|
-
// Calculate the Jaro distance:
|
|
82230
82358
|
const transpositions = getTranspositions(first, second, matches1, matches2);
|
|
82231
|
-
|
|
82359
|
+
return (matches / first_length + matches / second_length + (matches - transpositions) / matches) / 3;
|
|
82232
82360
|
|
|
82233
|
-
// Transform to Jaro-Winkler:
|
|
82234
|
-
// Prefix scale gives more favorable ratings to strings that share common prefixes:
|
|
82235
|
-
const prefix_scale = 0.1;
|
|
82236
|
-
const prefix = getPrefix(first, second, min3(l1, l2, 4));
|
|
82237
|
-
return similarity + prefix * prefix_scale * (1 - similarity);
|
|
82238
82361
|
}
|
|
82239
82362
|
|
|
82240
82363
|
/**
|
|
@@ -82296,8 +82419,12 @@ function getMatching(a1, a2, matches1, matches2) {
|
|
|
82296
82419
|
* @param {string} a2 The second string to compare
|
|
82297
82420
|
* @param {BitSet} matches1
|
|
82298
82421
|
* @param {BitSet} matches2
|
|
82422
|
+
* @returns {number}
|
|
82299
82423
|
*/
|
|
82300
|
-
function getTranspositions(
|
|
82424
|
+
function getTranspositions(
|
|
82425
|
+
a1, a2,
|
|
82426
|
+
matches1, matches2
|
|
82427
|
+
) {
|
|
82301
82428
|
let transpositions = 0;
|
|
82302
82429
|
|
|
82303
82430
|
// Loop to find transpositions:
|
|
@@ -82328,6 +82455,36 @@ function getTranspositions(a1, a2, matches1, matches2) {
|
|
|
82328
82455
|
}
|
|
82329
82456
|
|
|
82330
82457
|
return Math.floor(transpositions * 0.5);
|
|
82458
|
+
}
|
|
82459
|
+
|
|
82460
|
+
/**
|
|
82461
|
+
* Calculate the Jaro-Winkler distance between two strings
|
|
82462
|
+
* @param {string} first The string to compare
|
|
82463
|
+
* @param {string} second The string to compare with
|
|
82464
|
+
* @returns {number} similarity score, higher value means strings are more similar
|
|
82465
|
+
*/
|
|
82466
|
+
function string_jaro_winkler(first, second) {
|
|
82467
|
+
const l1 = first.length;
|
|
82468
|
+
const l2 = second.length;
|
|
82469
|
+
|
|
82470
|
+
if (l1 === 0 && l2 === 0) {
|
|
82471
|
+
// special case for empty string
|
|
82472
|
+
return 1;
|
|
82473
|
+
}
|
|
82474
|
+
|
|
82475
|
+
// Calculate the Jaro distance:
|
|
82476
|
+
const similarity = string_jaro_distance(first, second, l1, l2);
|
|
82477
|
+
|
|
82478
|
+
if (similarity === 0) {
|
|
82479
|
+
// no similarity at all
|
|
82480
|
+
return 0;
|
|
82481
|
+
}
|
|
82482
|
+
|
|
82483
|
+
// Transform to Jaro-Winkler:
|
|
82484
|
+
// Prefix scale gives more favorable ratings to strings that share common prefixes:
|
|
82485
|
+
const prefix_scale = 0.1;
|
|
82486
|
+
const prefix = getPrefix(first, second, min3(l1, l2, 4));
|
|
82487
|
+
return similarity + prefix * prefix_scale * (1 - similarity);
|
|
82331
82488
|
}
|
|
82332
82489
|
|
|
82333
82490
|
/**
|
|
@@ -83869,11 +84026,14 @@ class BinaryHeap {
|
|
|
83869
84026
|
}
|
|
83870
84027
|
}
|
|
83871
84028
|
|
|
84029
|
+
/**
|
|
84030
|
+
* Decorator that wraps another map and lets you observe mutations
|
|
84031
|
+
* @template K,V
|
|
84032
|
+
*/
|
|
83872
84033
|
class ObservedMap {
|
|
83873
84034
|
/**
|
|
83874
84035
|
* @template K,V
|
|
83875
84036
|
* @constructor
|
|
83876
|
-
* @property {number} size
|
|
83877
84037
|
*/
|
|
83878
84038
|
constructor(source = new Map()) {
|
|
83879
84039
|
this.on = {
|
|
@@ -83956,10 +84116,11 @@ const STATUS_NORMAL = 2;
|
|
|
83956
84116
|
class Deque {
|
|
83957
84117
|
/**
|
|
83958
84118
|
* @template T
|
|
84119
|
+
* @param {number} [min_size]
|
|
83959
84120
|
*/
|
|
83960
|
-
constructor(
|
|
84121
|
+
constructor(min_size = DEFAULT_SIZE) {
|
|
83961
84122
|
|
|
83962
|
-
const size = ceilPowerOfTwo(max2(1,
|
|
84123
|
+
const size = ceilPowerOfTwo(max2(1, min_size));
|
|
83963
84124
|
|
|
83964
84125
|
/**
|
|
83965
84126
|
* Using static array allocator to preserve data locality.
|
|
@@ -83970,15 +84131,31 @@ class Deque {
|
|
|
83970
84131
|
*/
|
|
83971
84132
|
this.__data = new Array(size);
|
|
83972
84133
|
|
|
84134
|
+
/**
|
|
84135
|
+
*
|
|
84136
|
+
* @type {number}
|
|
84137
|
+
* @private
|
|
84138
|
+
*/
|
|
83973
84139
|
this.__head = 0;
|
|
84140
|
+
/**
|
|
84141
|
+
*
|
|
84142
|
+
* @type {number}
|
|
84143
|
+
* @private
|
|
84144
|
+
*/
|
|
83974
84145
|
this.__tail = 0;
|
|
83975
84146
|
|
|
84147
|
+
/**
|
|
84148
|
+
*
|
|
84149
|
+
* @type {number}
|
|
84150
|
+
* @private
|
|
84151
|
+
*/
|
|
83976
84152
|
this.__status = STATUS_EMPTY;
|
|
83977
84153
|
}
|
|
83978
84154
|
|
|
83979
84155
|
/**
|
|
83980
84156
|
*
|
|
83981
84157
|
* @param {boolean} adding
|
|
84158
|
+
* @private
|
|
83982
84159
|
*/
|
|
83983
84160
|
resetStatus(adding) {
|
|
83984
84161
|
const head = this.__head;
|
|
@@ -83997,11 +84174,12 @@ class Deque {
|
|
|
83997
84174
|
* @returns {number}
|
|
83998
84175
|
* @private
|
|
83999
84176
|
*/
|
|
84000
|
-
|
|
84001
|
-
// TODO this can be done faster using mod operator (%)
|
|
84177
|
+
__circular_next_position(current) {
|
|
84002
84178
|
const next = current + 1;
|
|
84003
84179
|
|
|
84004
|
-
|
|
84180
|
+
const length = this.__data.length;
|
|
84181
|
+
|
|
84182
|
+
return (next >= length) ? 0 : next;
|
|
84005
84183
|
}
|
|
84006
84184
|
|
|
84007
84185
|
/**
|
|
@@ -84010,43 +84188,57 @@ class Deque {
|
|
|
84010
84188
|
* @returns {number}
|
|
84011
84189
|
* @private
|
|
84012
84190
|
*/
|
|
84013
|
-
|
|
84191
|
+
__circular_previous_position(current) {
|
|
84014
84192
|
const prev = current - 1;
|
|
84015
84193
|
return (prev < 0) ? (this.__data.length - 1) : prev;
|
|
84016
84194
|
}
|
|
84017
84195
|
|
|
84018
|
-
|
|
84196
|
+
__check_and_expand() {
|
|
84019
84197
|
const status = this.__status;
|
|
84198
|
+
|
|
84020
84199
|
if (status !== STATUS_FULL) {
|
|
84200
|
+
// queue still has space, we're done
|
|
84021
84201
|
return;
|
|
84022
84202
|
}
|
|
84203
|
+
|
|
84023
84204
|
const length = this.__data.length;
|
|
84024
84205
|
|
|
84025
|
-
if (
|
|
84206
|
+
if (UINT32_MAX === length) {
|
|
84026
84207
|
throw new Error('Maximum array size exceeded');
|
|
84027
84208
|
}
|
|
84028
84209
|
|
|
84029
|
-
let
|
|
84210
|
+
let new_length = length * 2;
|
|
84211
|
+
|
|
84030
84212
|
// bigger than Integer.MAX_VALUE
|
|
84031
|
-
if (
|
|
84032
|
-
|
|
84213
|
+
if (new_length > UINT32_MAX) {
|
|
84214
|
+
new_length = UINT32_MAX;
|
|
84033
84215
|
}
|
|
84034
84216
|
|
|
84035
|
-
|
|
84217
|
+
/**
|
|
84218
|
+
*
|
|
84219
|
+
* @type {T[]}
|
|
84220
|
+
*/
|
|
84221
|
+
const new_data = new Array(new_length);
|
|
84036
84222
|
|
|
84037
|
-
// copy front portion of data
|
|
84038
84223
|
const head = this.__head;
|
|
84039
84224
|
|
|
84040
|
-
|
|
84041
|
-
array_copy(this.__data,
|
|
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);
|
|
84042
84229
|
|
|
84043
84230
|
this.__head = 0;
|
|
84044
84231
|
this.__tail = length;
|
|
84232
|
+
|
|
84045
84233
|
this.__status = STATUS_NORMAL;
|
|
84046
84234
|
|
|
84047
|
-
this.__data =
|
|
84235
|
+
this.__data = new_data;
|
|
84048
84236
|
}
|
|
84049
84237
|
|
|
84238
|
+
/**
|
|
84239
|
+
*
|
|
84240
|
+
* @return {boolean}
|
|
84241
|
+
*/
|
|
84050
84242
|
isEmpty() {
|
|
84051
84243
|
return this.size() === 0;
|
|
84052
84244
|
}
|
|
@@ -84058,7 +84250,7 @@ class Deque {
|
|
|
84058
84250
|
|
|
84059
84251
|
do {
|
|
84060
84252
|
this.__data[cursor] = undefined;
|
|
84061
|
-
cursor = this.
|
|
84253
|
+
cursor = this.__circular_next_position(cursor);
|
|
84062
84254
|
} while (cursor !== tail);
|
|
84063
84255
|
|
|
84064
84256
|
this.__status = STATUS_EMPTY;
|
|
@@ -84087,32 +84279,45 @@ class Deque {
|
|
|
84087
84279
|
/**
|
|
84088
84280
|
*
|
|
84089
84281
|
* @param {number} current
|
|
84090
|
-
* @param {boolean}
|
|
84282
|
+
* @param {boolean} shift_front should we shift elements before the removed element or after?
|
|
84091
84283
|
* @private
|
|
84092
84284
|
*/
|
|
84093
|
-
|
|
84285
|
+
__remove_internal(current, shift_front) {
|
|
84094
84286
|
let cursor = current;
|
|
84095
|
-
|
|
84287
|
+
|
|
84288
|
+
if (shift_front) {
|
|
84289
|
+
|
|
84290
|
+
// shift towards tail
|
|
84291
|
+
|
|
84096
84292
|
const head = this.__head;
|
|
84293
|
+
|
|
84097
84294
|
while (cursor !== head) {
|
|
84098
|
-
const next = this.
|
|
84295
|
+
const next = this.__circular_previous_position(cursor);
|
|
84099
84296
|
this.__data[cursor] = this.__data[next];
|
|
84100
84297
|
cursor = next;
|
|
84101
84298
|
}
|
|
84102
|
-
|
|
84299
|
+
|
|
84300
|
+
this.__head = this.__circular_next_position(head);
|
|
84301
|
+
|
|
84103
84302
|
} else {
|
|
84303
|
+
|
|
84304
|
+
// shift towards head
|
|
84305
|
+
|
|
84104
84306
|
const tail = this.__tail;
|
|
84105
84307
|
|
|
84106
84308
|
while (cursor !== tail) {
|
|
84107
|
-
const next = this.
|
|
84309
|
+
const next = this.__circular_next_position(cursor);
|
|
84108
84310
|
this.__data[cursor] = this.__data[next];
|
|
84109
84311
|
cursor = next;
|
|
84110
84312
|
}
|
|
84111
84313
|
|
|
84112
|
-
this.__tail = this.
|
|
84314
|
+
this.__tail = this.__circular_previous_position(tail);
|
|
84315
|
+
|
|
84113
84316
|
}
|
|
84114
84317
|
|
|
84318
|
+
// fill in slot of last moved element
|
|
84115
84319
|
this.__data[cursor] = undefined;
|
|
84320
|
+
|
|
84116
84321
|
this.resetStatus(false);
|
|
84117
84322
|
}
|
|
84118
84323
|
|
|
@@ -84128,7 +84333,7 @@ class Deque {
|
|
|
84128
84333
|
return false;
|
|
84129
84334
|
}
|
|
84130
84335
|
|
|
84131
|
-
this.
|
|
84336
|
+
this.__remove_internal(i, true);
|
|
84132
84337
|
|
|
84133
84338
|
return true;
|
|
84134
84339
|
}
|
|
@@ -84172,20 +84377,20 @@ class Deque {
|
|
|
84172
84377
|
* @param {T} e
|
|
84173
84378
|
*/
|
|
84174
84379
|
addFirst(e) {
|
|
84175
|
-
this.
|
|
84176
|
-
this.__head = this.
|
|
84380
|
+
this.__check_and_expand();
|
|
84381
|
+
this.__head = this.__circular_previous_position(this.__head);
|
|
84177
84382
|
this.__data[this.__head] = e;
|
|
84178
84383
|
this.resetStatus(true);
|
|
84179
84384
|
}
|
|
84180
84385
|
|
|
84181
84386
|
/**
|
|
84182
84387
|
* Remove element from the front of the queue
|
|
84183
|
-
* @returns {T}
|
|
84388
|
+
* @returns {T|undefined}
|
|
84184
84389
|
*/
|
|
84185
84390
|
removeFirst() {
|
|
84186
84391
|
const element = this.__data[this.__head];
|
|
84187
84392
|
this.__data[this.__head] = undefined;
|
|
84188
|
-
this.__head = this.
|
|
84393
|
+
this.__head = this.__circular_next_position(this.__head);
|
|
84189
84394
|
this.resetStatus(false);
|
|
84190
84395
|
return element;
|
|
84191
84396
|
}
|
|
@@ -84203,9 +84408,9 @@ class Deque {
|
|
|
84203
84408
|
* @param {T} e
|
|
84204
84409
|
*/
|
|
84205
84410
|
addLast(e) {
|
|
84206
|
-
this.
|
|
84411
|
+
this.__check_and_expand();
|
|
84207
84412
|
this.__data[this.__tail] = e;
|
|
84208
|
-
this.__tail = this.
|
|
84413
|
+
this.__tail = this.__circular_next_position(this.__tail);
|
|
84209
84414
|
this.resetStatus(true);
|
|
84210
84415
|
}
|
|
84211
84416
|
|
|
@@ -84214,7 +84419,7 @@ class Deque {
|
|
|
84214
84419
|
* @returns {T}
|
|
84215
84420
|
*/
|
|
84216
84421
|
removeLast() {
|
|
84217
|
-
const last = this.
|
|
84422
|
+
const last = this.__circular_previous_position(this.__tail);
|
|
84218
84423
|
const element = this.__data[last];
|
|
84219
84424
|
this.__data[last] = undefined;
|
|
84220
84425
|
this.__tail = last;
|
|
@@ -84225,10 +84430,10 @@ class Deque {
|
|
|
84225
84430
|
|
|
84226
84431
|
/**
|
|
84227
84432
|
* Peek element from the end of the queue without removing it
|
|
84228
|
-
* @returns {T}
|
|
84433
|
+
* @returns {T|undefined}
|
|
84229
84434
|
*/
|
|
84230
84435
|
getLast() {
|
|
84231
|
-
const last = this.
|
|
84436
|
+
const last = this.__circular_previous_position(this.__tail);
|
|
84232
84437
|
return this.__data[last];
|
|
84233
84438
|
}
|
|
84234
84439
|
}
|
|
@@ -85936,35 +86141,44 @@ Preloader.prototype.load = function (assetManager) {
|
|
|
85936
86141
|
return this;
|
|
85937
86142
|
};
|
|
85938
86143
|
|
|
85939
|
-
|
|
85940
|
-
|
|
85941
|
-
|
|
85942
|
-
|
|
85943
|
-
|
|
85944
|
-
|
|
85945
|
-
|
|
85946
|
-
|
|
85947
|
-
|
|
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;
|
|
85948
86153
|
|
|
85949
|
-
|
|
85950
|
-
|
|
85951
|
-
|
|
85952
|
-
|
|
85953
|
-
|
|
86154
|
+
for (let i = start; i < end; i++) {
|
|
86155
|
+
const value = data[i];
|
|
86156
|
+
if (value > result) {
|
|
86157
|
+
result = value;
|
|
86158
|
+
}
|
|
85954
86159
|
}
|
|
85955
86160
|
|
|
85956
|
-
|
|
85957
|
-
|
|
85958
|
-
|
|
85959
|
-
|
|
85960
|
-
|
|
85961
|
-
|
|
85962
|
-
|
|
85963
|
-
|
|
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;
|
|
85964
86173
|
|
|
85965
|
-
|
|
85966
|
-
|
|
86174
|
+
for (let i = start; i < end; i++) {
|
|
86175
|
+
const value = data[i];
|
|
86176
|
+
if (value < result) {
|
|
86177
|
+
result = value;
|
|
86178
|
+
}
|
|
85967
86179
|
}
|
|
86180
|
+
|
|
86181
|
+
return result;
|
|
85968
86182
|
}
|
|
85969
86183
|
|
|
85970
86184
|
class RingBuffer {
|
|
@@ -86234,44 +86448,35 @@ function computeStatisticalPartialMedian(values, start, end) {
|
|
|
86234
86448
|
return copy[position];
|
|
86235
86449
|
}
|
|
86236
86450
|
|
|
86237
|
-
|
|
86238
|
-
|
|
86239
|
-
|
|
86240
|
-
|
|
86241
|
-
|
|
86242
|
-
|
|
86243
|
-
|
|
86244
|
-
|
|
86245
|
-
let result = Number.NEGATIVE_INFINITY;
|
|
86246
|
-
|
|
86247
|
-
for (let i = start; i < end; i++) {
|
|
86248
|
-
const value = data[i];
|
|
86249
|
-
if (value > result) {
|
|
86250
|
-
result = value;
|
|
86251
|
-
}
|
|
86451
|
+
class AbstractMetric {
|
|
86452
|
+
/**
|
|
86453
|
+
*
|
|
86454
|
+
* @param {number} value
|
|
86455
|
+
* @returns {void}
|
|
86456
|
+
*/
|
|
86457
|
+
record(value) {
|
|
86458
|
+
throw new Error('Not implemented');
|
|
86252
86459
|
}
|
|
86253
86460
|
|
|
86254
|
-
|
|
86255
|
-
}
|
|
86256
|
-
|
|
86257
|
-
|
|
86258
|
-
|
|
86259
|
-
|
|
86260
|
-
* @param {number} [start]
|
|
86261
|
-
* @param {number} [end]
|
|
86262
|
-
* @return {number}
|
|
86263
|
-
*/
|
|
86264
|
-
function computeArrayMin(data, start = 0, end = data.length) {
|
|
86265
|
-
let result = Number.POSITIVE_INFINITY;
|
|
86461
|
+
/**
|
|
86462
|
+
* @returns {number|undefined}
|
|
86463
|
+
*/
|
|
86464
|
+
getLastRecord() {
|
|
86465
|
+
throw new Error('Not implemented');
|
|
86466
|
+
}
|
|
86266
86467
|
|
|
86267
|
-
|
|
86268
|
-
|
|
86269
|
-
|
|
86270
|
-
|
|
86271
|
-
|
|
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');
|
|
86272
86475
|
}
|
|
86273
86476
|
|
|
86274
|
-
|
|
86477
|
+
clear() {
|
|
86478
|
+
throw new Error('Not implemented');
|
|
86479
|
+
}
|
|
86275
86480
|
}
|
|
86276
86481
|
|
|
86277
86482
|
class RingBufferMetric extends AbstractMetric {
|
|
@@ -86328,8 +86533,8 @@ class RingBufferMetric extends AbstractMetric {
|
|
|
86328
86533
|
|
|
86329
86534
|
result.mean = computeStatisticalMean(array, 0, data_count);
|
|
86330
86535
|
result.median = computeStatisticalPartialMedian(array, 0, data_count - 1);
|
|
86331
|
-
result.max =
|
|
86332
|
-
result.min =
|
|
86536
|
+
result.max = array_compute_max(array, 0, data_count);
|
|
86537
|
+
result.min = array_compute_min(array, 0, data_count);
|
|
86333
86538
|
|
|
86334
86539
|
return true;
|
|
86335
86540
|
|
|
@@ -110033,7 +110238,7 @@ class LightManager {
|
|
|
110033
110238
|
__build_view_frustum(camera) {
|
|
110034
110239
|
frustum_from_camera(camera, this.__view_frustum, false);
|
|
110035
110240
|
|
|
110036
|
-
|
|
110241
|
+
array_swap_one(this.__view_frustum.planes, 4, 5);
|
|
110037
110242
|
|
|
110038
110243
|
this.__build_view_frustum_points();
|
|
110039
110244
|
}
|