@woosh/meep-engine 2.61.0 → 2.62.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/meep.cjs +234 -212
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +234 -212
- package/package.json +1 -1
- package/src/core/bvh2/BinaryNode.js +16 -13
- package/src/core/bvh2/LeafNode.js +6 -3
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_sphere.js +81 -0
- package/src/core/geom/3d/aabb/AABB3.js +24 -36
- package/src/core/geom/3d/aabb/aabb3_array_compute_from_sphere.js +22 -0
- package/src/core/geom/3d/aabb/aabb3_array_intersects_sphere.js +22 -0
- package/src/core/geom/3d/aabb/aabb3_array_intersects_sphere_array.js +11 -0
- package/src/core/geom/3d/aabb/aabb3_signed_distance_to_aabb3.js +28 -0
- package/src/core/geom/3d/aabb/serializeAABB3Quantized16Uint.js +19 -10
- package/src/core/geom/3d/tetrahedra/delaunay/Cavity.js +3 -4
- package/src/engine/ecs/foliage/ecs/Foliage2System.js +3 -0
- package/src/engine/ecs/foliage/ecs/InstancedMeshComponent.js +4 -1
- package/src/engine/ecs/foliage/ecs/convertInstancedMeshComponents2Entities.js +64 -0
- package/src/engine/ecs/foliage/ecs/{InstancedMeshUtils.js → optimizeIndividualMeshesEntitiesToInstances.js} +11 -70
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +25 -27
- package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +49 -52
- package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +40 -42
- package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +43 -25
- package/src/engine/graphics/particles/particular/engine/ParticularEngine.js +10 -6
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +37 -41
- package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +44 -46
- package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +24 -26
- package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +40 -42
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +36 -38
- package/src/engine/graphics/shadows/testShadowMapRendering.js +19 -19
- package/src/engine/sound/dB2Volume.js +8 -0
- package/src/engine/sound/ecs/emitter/SoundEmitter.js +125 -99
- package/src/engine/sound/ecs/emitter/SoundEmitterComponentContext.js +4 -42
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +31 -121
- package/src/engine/sound/volume2dB.js +8 -0
- package/src/generation/theme/ThemeEngine.js +19 -53
- package/src/engine/graphics/geometry/bvh/buffered/BVHFromBufferGeometry.js +0 -133
package/build/meep.module.js
CHANGED
|
@@ -49814,6 +49814,95 @@ function array_quick_sort_by_comparator(
|
|
|
49814
49814
|
}
|
|
49815
49815
|
}
|
|
49816
49816
|
|
|
49817
|
+
/**
|
|
49818
|
+
*
|
|
49819
|
+
* @param {number} x0
|
|
49820
|
+
* @param {number} y0
|
|
49821
|
+
* @param {number} z0
|
|
49822
|
+
* @param {number} x1
|
|
49823
|
+
* @param {number} y1
|
|
49824
|
+
* @param {number} z1
|
|
49825
|
+
* @returns {number}
|
|
49826
|
+
*/
|
|
49827
|
+
function aabb3_compute_half_surface_area(x0, y0, z0, x1, y1, z1) {
|
|
49828
|
+
const dx = x1 - x0;
|
|
49829
|
+
const dy = y1 - y0;
|
|
49830
|
+
const dz = z1 - z0;
|
|
49831
|
+
return dy * (dx + dz) + dz * dx; //1 side, since it's a heuristic only
|
|
49832
|
+
}
|
|
49833
|
+
|
|
49834
|
+
/**
|
|
49835
|
+
*
|
|
49836
|
+
* @param {AABB3} node
|
|
49837
|
+
* @returns {number}
|
|
49838
|
+
*/
|
|
49839
|
+
function aabb3_box_surface_area_2(node) {
|
|
49840
|
+
return aabb3_compute_half_surface_area(node.x0, node.y0, node.z0, node.x1, node.y1, node.z1);
|
|
49841
|
+
}
|
|
49842
|
+
|
|
49843
|
+
/**
|
|
49844
|
+
*
|
|
49845
|
+
* @param {AABB3} a
|
|
49846
|
+
* @param {AABB3} b
|
|
49847
|
+
* @returns {number}
|
|
49848
|
+
*/
|
|
49849
|
+
function aabb3_combined_surface_area(a, b) {
|
|
49850
|
+
const x0 = min2(a.x0, b.x0);
|
|
49851
|
+
const y0 = min2(a.y0, b.y0);
|
|
49852
|
+
const z0 = min2(a.z0, b.z0);
|
|
49853
|
+
|
|
49854
|
+
const x1 = max2(a.x1, b.x1);
|
|
49855
|
+
const y1 = max2(a.y1, b.y1);
|
|
49856
|
+
const z1 = max2(a.z1, b.z1);
|
|
49857
|
+
|
|
49858
|
+
return aabb3_compute_half_surface_area(x0, y0, z0, x1, y1, z1);
|
|
49859
|
+
}
|
|
49860
|
+
|
|
49861
|
+
/**
|
|
49862
|
+
* Returns true if two 1D lines intersect, touch is treated as intersection
|
|
49863
|
+
* Parameters are assumed to be ordered, a1 >= a0, b1 >= b0
|
|
49864
|
+
* @param {Number} a0
|
|
49865
|
+
* @param {Number} a1
|
|
49866
|
+
* @param {Number} b0
|
|
49867
|
+
* @param {Number} b1
|
|
49868
|
+
* @returns {boolean}
|
|
49869
|
+
*/
|
|
49870
|
+
function intersects1D(a0, a1, b0, b1) {
|
|
49871
|
+
assert.isNumber(a0, "a0");
|
|
49872
|
+
assert.isNumber(a1, "a1");
|
|
49873
|
+
assert.isNumber(b0, "b0");
|
|
49874
|
+
assert.isNumber(b1, "b1");
|
|
49875
|
+
|
|
49876
|
+
return a1 >= b0 && b1 >= a0;
|
|
49877
|
+
}
|
|
49878
|
+
|
|
49879
|
+
/**
|
|
49880
|
+
*
|
|
49881
|
+
* @param {number} ax0
|
|
49882
|
+
* @param {number} ay0
|
|
49883
|
+
* @param {number} az0
|
|
49884
|
+
* @param {number} ax1
|
|
49885
|
+
* @param {number} ay1
|
|
49886
|
+
* @param {number} az1
|
|
49887
|
+
* @param {number} bx0
|
|
49888
|
+
* @param {number} by0
|
|
49889
|
+
* @param {number} bz0
|
|
49890
|
+
* @param {number} bx1
|
|
49891
|
+
* @param {number} by1
|
|
49892
|
+
* @param {number} bz1
|
|
49893
|
+
* @returns {boolean}
|
|
49894
|
+
*/
|
|
49895
|
+
function aabb3_intersects_aabb3(
|
|
49896
|
+
ax0, ay0, az0,
|
|
49897
|
+
ax1, ay1, az1,
|
|
49898
|
+
bx0, by0, bz0,
|
|
49899
|
+
bx1, by1, bz1
|
|
49900
|
+
) {
|
|
49901
|
+
return intersects1D(ax0, ax1, bx0, bx1)
|
|
49902
|
+
&& intersects1D(ay0, ay1, by0, by1)
|
|
49903
|
+
&& intersects1D(az0, az1, bz0, bz1);
|
|
49904
|
+
}
|
|
49905
|
+
|
|
49817
49906
|
/**
|
|
49818
49907
|
*
|
|
49819
49908
|
* @param {number[]} values
|
|
@@ -49900,6 +49989,73 @@ function mortonEncode_magicbits(x, y, z) {
|
|
|
49900
49989
|
return x_bits | y_bits | z_bits;
|
|
49901
49990
|
}
|
|
49902
49991
|
|
|
49992
|
+
//
|
|
49993
|
+
|
|
49994
|
+
/**
|
|
49995
|
+
*
|
|
49996
|
+
* @param {ArrayLike<number>|number[]|AABB3} aabb
|
|
49997
|
+
* @param {number} x
|
|
49998
|
+
* @param {number} y
|
|
49999
|
+
* @param {number} z
|
|
50000
|
+
* @return {boolean}
|
|
50001
|
+
*/
|
|
50002
|
+
function aabb3_array_intersects_point(
|
|
50003
|
+
aabb,
|
|
50004
|
+
x, y, z
|
|
50005
|
+
) {
|
|
50006
|
+
return x >= aabb[0]
|
|
50007
|
+
&& x <= aabb[3]
|
|
50008
|
+
&& y >= aabb[1]
|
|
50009
|
+
&& y <= aabb[4]
|
|
50010
|
+
&& z >= aabb[2]
|
|
50011
|
+
&& z <= aabb[5];
|
|
50012
|
+
}
|
|
50013
|
+
|
|
50014
|
+
/**
|
|
50015
|
+
*
|
|
50016
|
+
* @param {number[]|Float32Array|Float64Array} destination
|
|
50017
|
+
* @param {number} destination_offset
|
|
50018
|
+
* @param {number} x0
|
|
50019
|
+
* @param {number} y0
|
|
50020
|
+
* @param {number} z0
|
|
50021
|
+
* @param {number} x1
|
|
50022
|
+
* @param {number} y1
|
|
50023
|
+
* @param {number} z1
|
|
50024
|
+
*/
|
|
50025
|
+
function aabb3_build_corners(destination, destination_offset, x0, y0, z0, x1, y1, z1) {
|
|
50026
|
+
destination[destination_offset] = x0;
|
|
50027
|
+
destination[destination_offset + 1] = y0;
|
|
50028
|
+
destination[destination_offset + 2] = z0;
|
|
50029
|
+
|
|
50030
|
+
destination[destination_offset + 3] = x1;
|
|
50031
|
+
destination[destination_offset + 4] = y0;
|
|
50032
|
+
destination[destination_offset + 5] = z0;
|
|
50033
|
+
|
|
50034
|
+
destination[destination_offset + 6] = x0;
|
|
50035
|
+
destination[destination_offset + 7] = y1;
|
|
50036
|
+
destination[destination_offset + 8] = z0;
|
|
50037
|
+
|
|
50038
|
+
destination[destination_offset + 9] = x1;
|
|
50039
|
+
destination[destination_offset + 10] = y1;
|
|
50040
|
+
destination[destination_offset + 11] = z0;
|
|
50041
|
+
|
|
50042
|
+
destination[destination_offset + 12] = x0;
|
|
50043
|
+
destination[destination_offset + 13] = y0;
|
|
50044
|
+
destination[destination_offset + 14] = z1;
|
|
50045
|
+
|
|
50046
|
+
destination[destination_offset + 15] = x1;
|
|
50047
|
+
destination[destination_offset + 16] = y0;
|
|
50048
|
+
destination[destination_offset + 17] = z1;
|
|
50049
|
+
|
|
50050
|
+
destination[destination_offset + 18] = x0;
|
|
50051
|
+
destination[destination_offset + 19] = y1;
|
|
50052
|
+
destination[destination_offset + 20] = z1;
|
|
50053
|
+
|
|
50054
|
+
destination[destination_offset + 21] = x1;
|
|
50055
|
+
destination[destination_offset + 22] = y1;
|
|
50056
|
+
destination[destination_offset + 23] = z1;
|
|
50057
|
+
}
|
|
50058
|
+
|
|
49903
50059
|
/**
|
|
49904
50060
|
* Distance of the farthest point along the plane normal from the plane. If the result is >= 0, at least a portion of AABB pokes above the plane
|
|
49905
50061
|
* @param {number} plane_normal_x
|
|
@@ -50014,47 +50170,53 @@ function aabb3_compute_plane_side(
|
|
|
50014
50170
|
|
|
50015
50171
|
/**
|
|
50016
50172
|
*
|
|
50017
|
-
* @param {number[]|Float32Array|Float64Array} destination
|
|
50018
|
-
* @param {number} destination_offset
|
|
50019
50173
|
* @param {number} x0
|
|
50020
50174
|
* @param {number} y0
|
|
50021
50175
|
* @param {number} z0
|
|
50022
50176
|
* @param {number} x1
|
|
50023
50177
|
* @param {number} y1
|
|
50024
50178
|
* @param {number} z1
|
|
50179
|
+
* @returns {number}
|
|
50025
50180
|
*/
|
|
50026
|
-
function
|
|
50027
|
-
|
|
50028
|
-
|
|
50029
|
-
|
|
50030
|
-
|
|
50031
|
-
|
|
50032
|
-
|
|
50033
|
-
|
|
50034
|
-
|
|
50035
|
-
|
|
50036
|
-
|
|
50037
|
-
|
|
50181
|
+
function aabb3_compute_surface_area(x0, y0, z0, x1, y1, z1) {
|
|
50182
|
+
const dx = x1 - x0;
|
|
50183
|
+
const dy = y1 - y0;
|
|
50184
|
+
const dz = z1 - z0;
|
|
50185
|
+
return (dy * (dx + dz) + dz * dx) * 2; //2 of each side
|
|
50186
|
+
}
|
|
50187
|
+
|
|
50188
|
+
/**
|
|
50189
|
+
*
|
|
50190
|
+
* @param {number} x0
|
|
50191
|
+
* @param {number} y0
|
|
50192
|
+
* @param {number} z0
|
|
50193
|
+
* @param {number} x1
|
|
50194
|
+
* @param {number} y1
|
|
50195
|
+
* @param {number} z1
|
|
50196
|
+
* @param {ArrayLike<number>|number[]|Float32Array|Float64Array} frustum
|
|
50197
|
+
* @return {boolean}
|
|
50198
|
+
*/
|
|
50199
|
+
function aabb3_intersects_frustum_array(x0, y0, z0, x1, y1, z1, frustum) {
|
|
50200
|
+
for (let i = 0; i < 24; i += 4) {
|
|
50038
50201
|
|
|
50039
|
-
|
|
50040
|
-
|
|
50041
|
-
|
|
50202
|
+
const plane_x = frustum[i];
|
|
50203
|
+
const plane_y = frustum[i + 1];
|
|
50204
|
+
const plane_z = frustum[i + 2];
|
|
50205
|
+
const plane_w = frustum[i + 3];
|
|
50042
50206
|
|
|
50043
|
-
|
|
50044
|
-
|
|
50045
|
-
|
|
50207
|
+
const plane_distance = aabb3_compute_distance_above_plane_max(
|
|
50208
|
+
plane_x, plane_y, plane_z, plane_w,
|
|
50209
|
+
x0, y0, z0,
|
|
50210
|
+
x1, y1, z1
|
|
50211
|
+
);
|
|
50046
50212
|
|
|
50047
|
-
|
|
50048
|
-
|
|
50049
|
-
|
|
50213
|
+
if (plane_distance < 0) {
|
|
50214
|
+
return false;
|
|
50215
|
+
}
|
|
50050
50216
|
|
|
50051
|
-
|
|
50052
|
-
destination[destination_offset + 19] = y1;
|
|
50053
|
-
destination[destination_offset + 20] = z1;
|
|
50217
|
+
}
|
|
50054
50218
|
|
|
50055
|
-
|
|
50056
|
-
destination[destination_offset + 22] = y1;
|
|
50057
|
-
destination[destination_offset + 23] = z1;
|
|
50219
|
+
return true;
|
|
50058
50220
|
}
|
|
50059
50221
|
|
|
50060
50222
|
//
|
|
@@ -50274,57 +50436,6 @@ function aabb3_intersects_ray(
|
|
|
50274
50436
|
return f2 <= extents_x * abs_direction_y + extents_y * abs_direction_x;
|
|
50275
50437
|
}
|
|
50276
50438
|
|
|
50277
|
-
/**
|
|
50278
|
-
*
|
|
50279
|
-
* @param {number} x0
|
|
50280
|
-
* @param {number} y0
|
|
50281
|
-
* @param {number} z0
|
|
50282
|
-
* @param {number} x1
|
|
50283
|
-
* @param {number} y1
|
|
50284
|
-
* @param {number} z1
|
|
50285
|
-
* @returns {number}
|
|
50286
|
-
*/
|
|
50287
|
-
function aabb3_compute_surface_area(x0, y0, z0, x1, y1, z1) {
|
|
50288
|
-
const dx = x1 - x0;
|
|
50289
|
-
const dy = y1 - y0;
|
|
50290
|
-
const dz = z1 - z0;
|
|
50291
|
-
return (dy * (dx + dz) + dz * dx) * 2; //2 of each side
|
|
50292
|
-
}
|
|
50293
|
-
|
|
50294
|
-
/**
|
|
50295
|
-
*
|
|
50296
|
-
* @param {number} x0
|
|
50297
|
-
* @param {number} y0
|
|
50298
|
-
* @param {number} z0
|
|
50299
|
-
* @param {number} x1
|
|
50300
|
-
* @param {number} y1
|
|
50301
|
-
* @param {number} z1
|
|
50302
|
-
* @param {ArrayLike<number>|number[]|Float32Array|Float64Array} frustum
|
|
50303
|
-
* @return {boolean}
|
|
50304
|
-
*/
|
|
50305
|
-
function aabb3_intersects_frustum_array(x0, y0, z0, x1, y1, z1, frustum) {
|
|
50306
|
-
for (let i = 0; i < 24; i += 4) {
|
|
50307
|
-
|
|
50308
|
-
const plane_x = frustum[i];
|
|
50309
|
-
const plane_y = frustum[i + 1];
|
|
50310
|
-
const plane_z = frustum[i + 2];
|
|
50311
|
-
const plane_w = frustum[i + 3];
|
|
50312
|
-
|
|
50313
|
-
const plane_distance = aabb3_compute_distance_above_plane_max(
|
|
50314
|
-
plane_x, plane_y, plane_z, plane_w,
|
|
50315
|
-
x0, y0, z0,
|
|
50316
|
-
x1, y1, z1
|
|
50317
|
-
);
|
|
50318
|
-
|
|
50319
|
-
if (plane_distance < 0) {
|
|
50320
|
-
return false;
|
|
50321
|
-
}
|
|
50322
|
-
|
|
50323
|
-
}
|
|
50324
|
-
|
|
50325
|
-
return true;
|
|
50326
|
-
}
|
|
50327
|
-
|
|
50328
50439
|
/**
|
|
50329
50440
|
* NOTE: Based on Transforming Axis-Aligned Bounding Boxes by Jim Arvo from "Graphics Gems", Academic Press, 1990
|
|
50330
50441
|
* NOTE: {@link result} and {@link aabb} must be different objects
|
|
@@ -50407,26 +50518,33 @@ function aabb3_signed_distance_sqr_to_point(
|
|
|
50407
50518
|
}
|
|
50408
50519
|
}
|
|
50409
50520
|
|
|
50410
|
-
|
|
50521
|
+
function aabb3_signed_distance_to_aabb3(
|
|
50522
|
+
ax0,ay0,az0,ax1,ay1,az1,
|
|
50523
|
+
bx0,by0,bz0, bx1,by1,bz1
|
|
50524
|
+
){
|
|
50411
50525
|
|
|
50412
|
-
|
|
50413
|
-
|
|
50414
|
-
|
|
50415
|
-
|
|
50416
|
-
|
|
50417
|
-
|
|
50418
|
-
|
|
50419
|
-
|
|
50420
|
-
|
|
50421
|
-
|
|
50422
|
-
|
|
50423
|
-
)
|
|
50424
|
-
|
|
50425
|
-
|
|
50426
|
-
|
|
50427
|
-
|
|
50428
|
-
|
|
50429
|
-
|
|
50526
|
+
//do projection
|
|
50527
|
+
const xp0 = bx0 - ax1;
|
|
50528
|
+
const xp1 = ax0 - bx1;
|
|
50529
|
+
const yp0 = by0 - ay1;
|
|
50530
|
+
const yp1 = ay0 - by1;
|
|
50531
|
+
const zp0 = bz0 - az1;
|
|
50532
|
+
const zp1 = az0 - bz1;
|
|
50533
|
+
|
|
50534
|
+
//calculate separation in each axis
|
|
50535
|
+
const dx = Math.max(xp0, xp1);
|
|
50536
|
+
const dy = Math.max(yp0, yp1);
|
|
50537
|
+
const dz = Math.max(zp0, zp1);
|
|
50538
|
+
|
|
50539
|
+
//straight-line distance
|
|
50540
|
+
let distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
50541
|
+
|
|
50542
|
+
if (dx < 0 && dy < 0 && dz < 0) {
|
|
50543
|
+
//penetration
|
|
50544
|
+
return -distance;
|
|
50545
|
+
} else {
|
|
50546
|
+
return distance;
|
|
50547
|
+
}
|
|
50430
50548
|
}
|
|
50431
50549
|
|
|
50432
50550
|
/**
|
|
@@ -50435,6 +50553,7 @@ function aabb3_array_intersects_point(
|
|
|
50435
50553
|
|
|
50436
50554
|
/**
|
|
50437
50555
|
* Axis-Aligned bounding box in 3D
|
|
50556
|
+
* NOTE: In cases where all you want is raw performance - prefer to use typed arrays instead along with `aabb3_` functions
|
|
50438
50557
|
*/
|
|
50439
50558
|
class AABB3 {
|
|
50440
50559
|
/**
|
|
@@ -50654,7 +50773,12 @@ class AABB3 {
|
|
|
50654
50773
|
* @returns {boolean}
|
|
50655
50774
|
*/
|
|
50656
50775
|
_equals(x0, y0, z0, x1, y1, z1) {
|
|
50657
|
-
return this.x0 === x0
|
|
50776
|
+
return this.x0 === x0
|
|
50777
|
+
&& this.y0 === y0
|
|
50778
|
+
&& this.z0 === z0
|
|
50779
|
+
&& this.x1 === x1
|
|
50780
|
+
&& this.y1 === y1
|
|
50781
|
+
&& this.z1 === z1;
|
|
50658
50782
|
}
|
|
50659
50783
|
|
|
50660
50784
|
/**
|
|
@@ -50748,28 +50872,10 @@ class AABB3 {
|
|
|
50748
50872
|
const _y1 = this.y1;
|
|
50749
50873
|
const _z1 = this.z1;
|
|
50750
50874
|
|
|
50751
|
-
|
|
50752
|
-
|
|
50753
|
-
|
|
50754
|
-
|
|
50755
|
-
const yp1 = y0 - _y1;
|
|
50756
|
-
const zp0 = _z0 - z1;
|
|
50757
|
-
const zp1 = z0 - _z1;
|
|
50758
|
-
|
|
50759
|
-
//calculate separation in each axis
|
|
50760
|
-
const dx = Math.max(xp0, xp1);
|
|
50761
|
-
const dy = Math.max(yp0, yp1);
|
|
50762
|
-
const dz = Math.max(zp0, zp1);
|
|
50763
|
-
|
|
50764
|
-
//straight-line distance
|
|
50765
|
-
let distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
50766
|
-
|
|
50767
|
-
if (dx < 0 && dy < 0 && dz < 0) {
|
|
50768
|
-
//penetration
|
|
50769
|
-
return -distance;
|
|
50770
|
-
} else {
|
|
50771
|
-
return distance;
|
|
50772
|
-
}
|
|
50875
|
+
return aabb3_signed_distance_to_aabb3(
|
|
50876
|
+
_x0, _y0, _z0, _x1, _y1, _z1,
|
|
50877
|
+
x0, y0, z0, x1, y1, z1
|
|
50878
|
+
);
|
|
50773
50879
|
}
|
|
50774
50880
|
|
|
50775
50881
|
/**
|
|
@@ -51194,7 +51300,6 @@ class AABB3 {
|
|
|
51194
51300
|
}
|
|
51195
51301
|
|
|
51196
51302
|
/**
|
|
51197
|
-
*
|
|
51198
51303
|
* @param {Plane[]} clippingPlanes
|
|
51199
51304
|
* @returns {boolean}
|
|
51200
51305
|
*/
|
|
@@ -51489,6 +51594,9 @@ function isLeaf(node) {
|
|
|
51489
51594
|
return node.isLeafNode;
|
|
51490
51595
|
}
|
|
51491
51596
|
|
|
51597
|
+
/**
|
|
51598
|
+
* @deprecated use {@link ExplicitBinaryBoundingVolumeHierarchy} and {@link EBBVHLeafProxy} respectively
|
|
51599
|
+
*/
|
|
51492
51600
|
class LeafNode extends Node {
|
|
51493
51601
|
/**
|
|
51494
51602
|
*
|
|
@@ -51699,95 +51807,6 @@ function traverseBinaryNodeUsingVisitor(node, visitor) {
|
|
|
51699
51807
|
stackPointer$3 = stackOffset;
|
|
51700
51808
|
}
|
|
51701
51809
|
|
|
51702
|
-
/**
|
|
51703
|
-
* Returns true if two 1D lines intersect, touch is treated as intersection
|
|
51704
|
-
* Parameters are assumed to be ordered, a1 >= a0, b1 >= b0
|
|
51705
|
-
* @param {Number} a0
|
|
51706
|
-
* @param {Number} a1
|
|
51707
|
-
* @param {Number} b0
|
|
51708
|
-
* @param {Number} b1
|
|
51709
|
-
* @returns {boolean}
|
|
51710
|
-
*/
|
|
51711
|
-
function intersects1D(a0, a1, b0, b1) {
|
|
51712
|
-
assert.isNumber(a0, "a0");
|
|
51713
|
-
assert.isNumber(a1, "a1");
|
|
51714
|
-
assert.isNumber(b0, "b0");
|
|
51715
|
-
assert.isNumber(b1, "b1");
|
|
51716
|
-
|
|
51717
|
-
return a1 >= b0 && b1 >= a0;
|
|
51718
|
-
}
|
|
51719
|
-
|
|
51720
|
-
/**
|
|
51721
|
-
*
|
|
51722
|
-
* @param {number} ax0
|
|
51723
|
-
* @param {number} ay0
|
|
51724
|
-
* @param {number} az0
|
|
51725
|
-
* @param {number} ax1
|
|
51726
|
-
* @param {number} ay1
|
|
51727
|
-
* @param {number} az1
|
|
51728
|
-
* @param {number} bx0
|
|
51729
|
-
* @param {number} by0
|
|
51730
|
-
* @param {number} bz0
|
|
51731
|
-
* @param {number} bx1
|
|
51732
|
-
* @param {number} by1
|
|
51733
|
-
* @param {number} bz1
|
|
51734
|
-
* @returns {boolean}
|
|
51735
|
-
*/
|
|
51736
|
-
function aabb3_intersects_aabb3(
|
|
51737
|
-
ax0, ay0, az0,
|
|
51738
|
-
ax1, ay1, az1,
|
|
51739
|
-
bx0, by0, bz0,
|
|
51740
|
-
bx1, by1, bz1
|
|
51741
|
-
) {
|
|
51742
|
-
return intersects1D(ax0, ax1, bx0, bx1)
|
|
51743
|
-
&& intersects1D(ay0, ay1, by0, by1)
|
|
51744
|
-
&& intersects1D(az0, az1, bz0, bz1);
|
|
51745
|
-
}
|
|
51746
|
-
|
|
51747
|
-
/**
|
|
51748
|
-
*
|
|
51749
|
-
* @param {number} x0
|
|
51750
|
-
* @param {number} y0
|
|
51751
|
-
* @param {number} z0
|
|
51752
|
-
* @param {number} x1
|
|
51753
|
-
* @param {number} y1
|
|
51754
|
-
* @param {number} z1
|
|
51755
|
-
* @returns {number}
|
|
51756
|
-
*/
|
|
51757
|
-
function aabb3_compute_half_surface_area(x0, y0, z0, x1, y1, z1) {
|
|
51758
|
-
const dx = x1 - x0;
|
|
51759
|
-
const dy = y1 - y0;
|
|
51760
|
-
const dz = z1 - z0;
|
|
51761
|
-
return dy * (dx + dz) + dz * dx; //1 side, since it's a heuristic only
|
|
51762
|
-
}
|
|
51763
|
-
|
|
51764
|
-
/**
|
|
51765
|
-
*
|
|
51766
|
-
* @param {AABB3} node
|
|
51767
|
-
* @returns {number}
|
|
51768
|
-
*/
|
|
51769
|
-
function aabb3_box_surface_area_2(node) {
|
|
51770
|
-
return aabb3_compute_half_surface_area(node.x0, node.y0, node.z0, node.x1, node.y1, node.z1);
|
|
51771
|
-
}
|
|
51772
|
-
|
|
51773
|
-
/**
|
|
51774
|
-
*
|
|
51775
|
-
* @param {AABB3} a
|
|
51776
|
-
* @param {AABB3} b
|
|
51777
|
-
* @returns {number}
|
|
51778
|
-
*/
|
|
51779
|
-
function aabb3_combined_surface_area(a, b) {
|
|
51780
|
-
const x0 = min2(a.x0, b.x0);
|
|
51781
|
-
const y0 = min2(a.y0, b.y0);
|
|
51782
|
-
const z0 = min2(a.z0, b.z0);
|
|
51783
|
-
|
|
51784
|
-
const x1 = max2(a.x1, b.x1);
|
|
51785
|
-
const y1 = max2(a.y1, b.y1);
|
|
51786
|
-
const z1 = max2(a.z1, b.z1);
|
|
51787
|
-
|
|
51788
|
-
return aabb3_compute_half_surface_area(x0, y0, z0, x1, y1, z1);
|
|
51789
|
-
}
|
|
51790
|
-
|
|
51791
51810
|
/**
|
|
51792
51811
|
* Created by Alex on 17/11/2014.
|
|
51793
51812
|
*/
|
|
@@ -51811,6 +51830,9 @@ let stackPointer$2 = 0;
|
|
|
51811
51830
|
*/
|
|
51812
51831
|
const stack$9 = [];
|
|
51813
51832
|
|
|
51833
|
+
/**
|
|
51834
|
+
* @deprecated use {@link ExplicitBinaryBoundingVolumeHierarchy} instead
|
|
51835
|
+
*/
|
|
51814
51836
|
class BinaryNode extends Node {
|
|
51815
51837
|
constructor() {
|
|
51816
51838
|
super();
|
package/package.json
CHANGED
|
@@ -3,19 +3,19 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
6
|
+
import {assert} from "../assert.js";
|
|
7
|
+
import {arrayQuickSort} from "../collection/array/arrayQuickSort.js";
|
|
8
|
+
import {aabb3_box_surface_area_2} from "../geom/3d/aabb/aabb3_box_surface_area_2.js";
|
|
9
|
+
import {aabb3_combined_surface_area} from "../geom/3d/aabb/aabb3_combined_surface_area.js";
|
|
10
|
+
import {aabb3_intersects_aabb3} from "../geom/3d/aabb/aabb3_intersects_aabb3.js";
|
|
11
|
+
import {max2} from "../math/max2.js";
|
|
12
|
+
import {min2} from "../math/min2.js";
|
|
13
|
+
import {computeSampleStandardDeviation} from "../math/statistics/computeSampleStandardDeviation.js";
|
|
14
|
+
import {isLeaf, LeafNode} from "./LeafNode.js";
|
|
15
|
+
import {Node} from "./Node.js";
|
|
16
|
+
import {surfaceAreaHeuristic} from "./sah/surfaceAreaHeuristic.js";
|
|
17
|
+
import {BVHVisitor} from "./traversal/BVHVisitor.js";
|
|
18
|
+
import {traverseBinaryNodeUsingVisitor} from "./traversal/traverseBinaryNodeUsingVisitor.js";
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -36,6 +36,9 @@ let stackPointer = 0;
|
|
|
36
36
|
*/
|
|
37
37
|
const stack = [];
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated use {@link ExplicitBinaryBoundingVolumeHierarchy} instead
|
|
41
|
+
*/
|
|
39
42
|
export class BinaryNode extends Node {
|
|
40
43
|
constructor() {
|
|
41
44
|
super();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Created by Alex on 17/11/2014.
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import {deserializeAABB3} from "../geom/3d/aabb/deserializeAABB3.js";
|
|
5
|
+
import {serializeAABB3} from "../geom/3d/aabb/serializeAABB3.js";
|
|
6
|
+
import {Node} from "./Node.js";
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -15,6 +15,9 @@ function isLeaf(node) {
|
|
|
15
15
|
return node.isLeafNode;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated use {@link ExplicitBinaryBoundingVolumeHierarchy} and {@link EBBVHLeafProxy} respectively
|
|
20
|
+
*/
|
|
18
21
|
export class LeafNode extends Node {
|
|
19
22
|
/**
|
|
20
23
|
*
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {SCRATCH_UINT32_TRAVERSAL_STACK} from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
|
|
2
|
+
import {aabb3_array_intersects_sphere_array} from "../../../geom/3d/aabb/aabb3_array_intersects_sphere_array.js";
|
|
3
|
+
import {NULL_NODE} from "../ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
4
|
+
import {bvh_collect_user_data} from "./bvh_collect_user_data.js";
|
|
5
|
+
|
|
6
|
+
const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
|
|
7
|
+
|
|
8
|
+
const scratch_aabb = new Float32Array(6);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param {number[]} result
|
|
13
|
+
* @param {number} result_offset
|
|
14
|
+
* @param {ExplicitBinaryBoundingVolumeHierarchy} bvh
|
|
15
|
+
* @param {number[]|Float32Array} sphere
|
|
16
|
+
*/
|
|
17
|
+
export function bvh_query_user_data_overlaps_sphere(
|
|
18
|
+
result,
|
|
19
|
+
result_offset,
|
|
20
|
+
bvh,
|
|
21
|
+
sphere
|
|
22
|
+
) {
|
|
23
|
+
const root = bvh.root;
|
|
24
|
+
|
|
25
|
+
if (root === NULL_NODE) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @type {number}
|
|
32
|
+
*/
|
|
33
|
+
const stack_top = stack.pointer++;
|
|
34
|
+
|
|
35
|
+
stack[stack_top] = root;
|
|
36
|
+
|
|
37
|
+
let result_cursor = result_offset;
|
|
38
|
+
|
|
39
|
+
while (stack.pointer > stack_top) {
|
|
40
|
+
stack.pointer--;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @type {number}
|
|
45
|
+
*/
|
|
46
|
+
const node = stack[stack.pointer];
|
|
47
|
+
|
|
48
|
+
// test node against the ray
|
|
49
|
+
bvh.node_get_aabb(node, scratch_aabb);
|
|
50
|
+
const intersection = aabb3_array_intersects_sphere_array(scratch_aabb, sphere);
|
|
51
|
+
|
|
52
|
+
if (intersection === 0) {
|
|
53
|
+
// fully outside
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const node_is_leaf = bvh.node_is_leaf(node);
|
|
58
|
+
|
|
59
|
+
if (node_is_leaf) {
|
|
60
|
+
// leaf node
|
|
61
|
+
result[result_cursor++] = bvh.node_get_user_data(node);
|
|
62
|
+
|
|
63
|
+
} else if (intersection === 2) {
|
|
64
|
+
// fully inside, fast collection path
|
|
65
|
+
result_cursor += bvh_collect_user_data(result, result_cursor, bvh, node);
|
|
66
|
+
} else {
|
|
67
|
+
// partially inside
|
|
68
|
+
// read in-order
|
|
69
|
+
const child1 = bvh.node_get_child1(node);
|
|
70
|
+
const child2 = bvh.node_get_child2(node);
|
|
71
|
+
|
|
72
|
+
// write to stack in reverse order, so that fist child ends up being visited first
|
|
73
|
+
stack[stack.pointer++] = child1;
|
|
74
|
+
stack[stack.pointer++] = child2;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// drop stack frame
|
|
79
|
+
|
|
80
|
+
return result_cursor - result_offset;
|
|
81
|
+
}
|