@woosh/meep-engine 2.140.0 → 2.142.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/package.json +1 -1
  2. package/src/core/geom/3d/quaternion/quat3_multiply.d.ts +21 -0
  3. package/src/core/geom/3d/quaternion/quat3_multiply.d.ts.map +1 -0
  4. package/src/core/geom/3d/quaternion/quat3_multiply.js +25 -0
  5. package/src/engine/control/first-person/prototype_first_person_controller.js +5 -0
  6. package/src/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.d.ts.map +1 -1
  7. package/src/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +67 -42
  8. package/src/engine/graphics/render/buffer/simple-fx/ao/SAOShader.d.ts +12 -22
  9. package/src/engine/graphics/render/buffer/simple-fx/ao/SAOShader.d.ts.map +1 -1
  10. package/src/engine/graphics/render/buffer/simple-fx/ao/SAOShader.js +340 -186
  11. package/src/engine/graphics/render/buffer/simple-fx/ao/SAOUpscaleShader.d.ts +44 -0
  12. package/src/engine/graphics/render/buffer/simple-fx/ao/SAOUpscaleShader.d.ts.map +1 -0
  13. package/src/engine/graphics/render/buffer/simple-fx/ao/SAOUpscaleShader.js +151 -0
  14. package/src/engine/graphics/render/buffer/simple-fx/ao/generateHilbertNoiseTexture.d.ts +14 -0
  15. package/src/engine/graphics/render/buffer/simple-fx/ao/generateHilbertNoiseTexture.d.ts.map +1 -0
  16. package/src/engine/graphics/render/buffer/simple-fx/ao/generateHilbertNoiseTexture.js +78 -0
  17. package/src/engine/physics/PLAN.md +705 -461
  18. package/src/engine/physics/REVIEW_002.md +151 -0
  19. package/src/engine/physics/REVIEW_003.md +166 -0
  20. package/src/engine/physics/constraint/DofMode.d.ts +28 -0
  21. package/src/engine/physics/constraint/DofMode.d.ts.map +1 -0
  22. package/src/engine/physics/constraint/DofMode.js +35 -0
  23. package/src/engine/physics/constraint/solve_constraints.d.ts +38 -0
  24. package/src/engine/physics/constraint/solve_constraints.d.ts.map +1 -0
  25. package/src/engine/physics/constraint/solve_constraints.js +673 -0
  26. package/src/engine/physics/ecs/Joint.d.ts +294 -0
  27. package/src/engine/physics/ecs/Joint.d.ts.map +1 -0
  28. package/src/engine/physics/ecs/Joint.js +402 -0
  29. package/src/engine/physics/ecs/PhysicsSystem.d.ts +52 -0
  30. package/src/engine/physics/ecs/PhysicsSystem.d.ts.map +1 -1
  31. package/src/engine/physics/ecs/PhysicsSystem.js +126 -4
  32. package/src/engine/physics/fluid/FluidField.d.ts +14 -10
  33. package/src/engine/physics/fluid/FluidField.d.ts.map +1 -1
  34. package/src/engine/physics/fluid/FluidField.js +14 -10
  35. package/src/engine/physics/fluid/FluidSimulator.d.ts.map +1 -1
  36. package/src/engine/physics/fluid/FluidSimulator.js +0 -1
  37. package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.d.ts +17 -10
  38. package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.d.ts.map +1 -1
  39. package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.js +18 -11
  40. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.d.ts +13 -10
  41. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.d.ts.map +1 -1
  42. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.js +18 -13
  43. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.d.ts +4 -3
  44. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.d.ts.map +1 -1
  45. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.js +15 -11
  46. package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.d.ts +24 -22
  47. package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.d.ts.map +1 -1
  48. package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.js +26 -22
  49. package/src/engine/physics/island/IslandBuilder.d.ts +4 -1
  50. package/src/engine/physics/island/IslandBuilder.d.ts.map +1 -1
  51. package/src/engine/physics/island/IslandBuilder.js +33 -16
  52. package/src/engine/physics/narrowphase/box_box_manifold.d.ts.map +1 -1
  53. package/src/engine/physics/narrowphase/box_box_manifold.js +27 -1
  54. package/src/engine/physics/narrowphase/narrowphase_step.d.ts +33 -0
  55. package/src/engine/physics/narrowphase/narrowphase_step.d.ts.map +1 -1
  56. package/src/engine/physics/narrowphase/narrowphase_step.js +75 -0
  57. package/src/engine/physics/narrowphase/ray_shapes.d.ts +66 -0
  58. package/src/engine/physics/narrowphase/ray_shapes.d.ts.map +1 -0
  59. package/src/engine/physics/narrowphase/ray_shapes.js +187 -0
  60. package/src/engine/physics/narrowphase/refine_ray_concave.d.ts +16 -0
  61. package/src/engine/physics/narrowphase/refine_ray_concave.d.ts.map +1 -0
  62. package/src/engine/physics/narrowphase/refine_ray_concave.js +145 -0
  63. package/src/engine/physics/narrowphase/refine_ray_hit.d.ts +39 -0
  64. package/src/engine/physics/narrowphase/refine_ray_hit.d.ts.map +1 -0
  65. package/src/engine/physics/narrowphase/refine_ray_hit.js +78 -0
  66. package/src/engine/physics/queries/raycast.d.ts +11 -9
  67. package/src/engine/physics/queries/raycast.d.ts.map +1 -1
  68. package/src/engine/physics/queries/raycast.js +108 -159
  69. package/src/engine/physics/solver/solve_contacts.d.ts +28 -0
  70. package/src/engine/physics/solver/solve_contacts.d.ts.map +1 -1
  71. package/src/engine/physics/solver/solve_contacts.js +169 -1
  72. package/src/engine/physics/vehicle/RaycastVehicle.d.ts +114 -0
  73. package/src/engine/physics/vehicle/RaycastVehicle.d.ts.map +1 -0
  74. package/src/engine/physics/vehicle/RaycastVehicle.js +333 -0
@@ -0,0 +1,151 @@
1
+ import { Vector2 } from 'three';
2
+
3
+ /**
4
+ * Edge-aware upscale + denoise for the half-resolution SAO buffer.
5
+ *
6
+ * A single non-separable pass (separable bilateral filters leak across diagonal silhouettes). Each
7
+ * tap is weighted by its distance to the *plane* of the centre pixel, modelled from the screen-space
8
+ * depth gradient (ReBLUR-style): slanted surfaces are predicted correctly, so only genuine depth
9
+ * discontinuities are rejected -- no normal buffer and no hand-tuned raw-depth tolerance. The
10
+ * geometry tolerance is intentionally tight so background occlusion never bleeds into the foreground
11
+ * or vice versa.
12
+ *
13
+ * Taps follow a Vogel disk rotated per pixel by an R2 blue-noise angle, which both spreads the
14
+ * gather as a dithered (non-grid) pattern and pairs with the R2-rotated sampling kernel in SAOShader.
15
+ */
16
+
17
+ const SAOUpscaleShader = {
18
+ defines: {
19
+ 'NUM_TAPS': 16,
20
+ 'DEPTH_PACKING': 0,
21
+ 'PERSPECTIVE_CAMERA': 1
22
+ },
23
+ uniforms: {
24
+
25
+ 'tAO': { value: null },
26
+ 'tDepth': { value: null },
27
+ 'tHilbert': { value: null },
28
+ 'size': { value: new Vector2(512, 512) },
29
+
30
+ 'cameraNear': { value: 1 },
31
+ 'cameraFar': { value: 100 },
32
+
33
+ // tap-disk radius, in output (full-resolution) pixels
34
+ 'blurRadius': { value: 10.0 },
35
+
36
+ // plane-distance tolerance as a fraction of view depth; smaller = more aggressive fg/bg split
37
+ 'depthSigma': { value: 0.02 }
38
+ },
39
+ vertexShader: /* glsl */`
40
+
41
+ varying vec2 vUv;
42
+
43
+ void main() {
44
+ vUv = uv;
45
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
46
+ }`,
47
+
48
+ fragmentShader: /* glsl */`
49
+
50
+ #include <common>
51
+
52
+ varying vec2 vUv;
53
+
54
+ uniform sampler2D tAO;
55
+ uniform sampler2D tDepth;
56
+ uniform highp usampler2D tHilbert;
57
+ uniform vec2 size;
58
+ uniform float cameraNear;
59
+ uniform float cameraFar;
60
+ uniform float blurRadius;
61
+ uniform float depthSigma;
62
+
63
+ #include <packing>
64
+
65
+ out float out_occlusion;
66
+
67
+ float getDepth( const in vec2 uv ) {
68
+ #if DEPTH_PACKING == 1
69
+ return unpackRGBAToDepth( texture2D( tDepth, uv ) );
70
+ #else
71
+ return texture2D( tDepth, uv ).x;
72
+ #endif
73
+ }
74
+
75
+ float getViewZ( const in float depth ) {
76
+ #if PERSPECTIVE_CAMERA == 1
77
+ return perspectiveDepthToViewZ( depth, cameraNear, cameraFar );
78
+ #else
79
+ return orthographicDepthToViewZ( depth, cameraNear, cameraFar );
80
+ #endif
81
+ }
82
+
83
+ // Marty's R2 low-discrepancy sequence: permutation index -> 2D blue-noise-like point
84
+ vec2 r2_marty( uint index ) {
85
+ return fract( vec2( float( index ) ) * vec2( 0.245122333753, 0.430159709002 ) + 0.5 );
86
+ }
87
+
88
+ void main() {
89
+ float centerDepth = getDepth( vUv );
90
+
91
+ // sky / far plane -> no occlusion
92
+ if ( centerDepth >= ( 1.0 - EPSILON ) ) {
93
+ out_occlusion = 1.0;
94
+ return;
95
+ }
96
+
97
+ float zc = getViewZ( centerDepth );
98
+
99
+ // screen-space depth gradient defines the centre pixel's plane; predicting a tap's depth
100
+ // from it means slanted surfaces are not rejected, only true discontinuities are
101
+ vec2 dz = vec2( dFdx( zc ), dFdy( zc ) );
102
+
103
+ vec2 texel = 1.0 / size;
104
+
105
+ // plane-distance tolerance scales with view depth (footprint and depth precision grow with
106
+ // distance); smaller depthSigma = tighter fg/bg separation
107
+ float invSigma = 1.0 / max( EPSILON, depthSigma * abs( zc ) );
108
+
109
+ // per-pixel rotation of the Vogel tap set -> dithered, non-separable gather. Hilbert-curve
110
+ // permutation index through Marty's R2 sequence (matches the AO sampling dither).
111
+ uint hilbertIndex = texelFetch( tHilbert, ivec2( gl_FragCoord.xy ) & 63, 0 ).x;
112
+ float rot = r2_marty( hilbertIndex ).x * PI2;
113
+
114
+ float spatialSigma = blurRadius * 0.5;
115
+ float invSpatial2 = 1.0 / ( 2.0 * spatialSigma * spatialSigma );
116
+
117
+ // centre tap
118
+ float sum = texture2D( tAO, vUv ).x;
119
+ float wsum = 1.0;
120
+
121
+ for ( int i = 0; i < NUM_TAPS; i ++ ) {
122
+ // Vogel-disk offset in output pixels, rotated per pixel
123
+ float fi = float( i ) + 0.5;
124
+ float r = sqrt( fi / float( NUM_TAPS ) ) * blurRadius;
125
+ float theta = fi * 2.39996323 + rot; // golden angle
126
+ vec2 o = r * vec2( cos( theta ), sin( theta ) );
127
+
128
+ vec2 tapUv = vUv + o * texel;
129
+
130
+ if ( tapUv.x < 0.0 || tapUv.x > 1.0 || tapUv.y < 0.0 || tapUv.y > 1.0 ) continue;
131
+
132
+ float zt = getViewZ( getDepth( tapUv ) );
133
+
134
+ // distance from the tap to the centre pixel's plane
135
+ float planeDist = abs( zt - ( zc + dot( dz, o ) ) );
136
+
137
+ float wGeom = exp( - planeDist * planeDist * invSigma * invSigma );
138
+ float wSpatial = exp( - dot( o, o ) * invSpatial2 );
139
+
140
+ float w = wGeom * wSpatial;
141
+
142
+ sum += w * texture2D( tAO, tapUv ).x;
143
+ wsum += w;
144
+ }
145
+
146
+ out_occlusion = sum / wsum;
147
+ }`
148
+
149
+ };
150
+
151
+ export { SAOUpscaleShader };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Hilbert-curve index lookup texture (ported from Intel's XeGTAO).
3
+ *
4
+ * Each texel holds the Hilbert-curve index of its (x, y) position. Sampling it gives a spatially
5
+ * well-distributed permutation index which, fed into a low-discrepancy sequence (Marty R2), yields a
6
+ * blue-noise-like per-pixel dither. Stored as a single-channel unsigned-integer texture (R32UI), so
7
+ * it is read with a `usampler2D` + `texelFetch`.
8
+ *
9
+ * @param {number} size edge length in texels; must be a power of two
10
+ * @returns {DataTexture}
11
+ */
12
+ export function generateHilbertNoiseTexture(size?: number): DataTexture;
13
+ import { DataTexture } from "three";
14
+ //# sourceMappingURL=generateHilbertNoiseTexture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateHilbertNoiseTexture.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/graphics/render/buffer/simple-fx/ao/generateHilbertNoiseTexture.js"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,mDAHW,MAAM,GACJ,WAAW,CA8BvB;4BAzC6F,OAAO"}
@@ -0,0 +1,78 @@
1
+ import { DataTexture, NearestFilter, RedIntegerFormat, RepeatWrapping, UnsignedIntType } from "three";
2
+
3
+ /**
4
+ * Hilbert-curve index lookup texture (ported from Intel's XeGTAO).
5
+ *
6
+ * Each texel holds the Hilbert-curve index of its (x, y) position. Sampling it gives a spatially
7
+ * well-distributed permutation index which, fed into a low-discrepancy sequence (Marty R2), yields a
8
+ * blue-noise-like per-pixel dither. Stored as a single-channel unsigned-integer texture (R32UI), so
9
+ * it is read with a `usampler2D` + `texelFetch`.
10
+ *
11
+ * @param {number} size edge length in texels; must be a power of two
12
+ * @returns {DataTexture}
13
+ */
14
+ export function generateHilbertNoiseTexture(size = 64) {
15
+ const data = new Uint32Array(size * size);
16
+
17
+ for (let y = 0; y < size; y++) {
18
+ for (let x = 0; x < size; x++) {
19
+ data[y * size + x] = hilbert_index_r2(x, y, size);
20
+ }
21
+ }
22
+
23
+ const texture = new DataTexture(data, size, size);
24
+
25
+ texture.type = UnsignedIntType;
26
+ texture.format = RedIntegerFormat;
27
+ texture.internalFormat = "R32UI";
28
+
29
+ texture.magFilter = NearestFilter;
30
+ texture.minFilter = NearestFilter;
31
+
32
+ texture.wrapS = RepeatWrapping;
33
+ texture.wrapT = RepeatWrapping;
34
+
35
+ texture.flipY = false;
36
+ texture.generateMipmaps = false;
37
+ texture.unpackAlignment = 4;
38
+
39
+ texture.needsUpdate = true;
40
+
41
+ return texture;
42
+ }
43
+
44
+ /**
45
+ * @param {number} x
46
+ * @param {number} y
47
+ * @param {number} width must be a power of two
48
+ * @returns {number}
49
+ */
50
+ function hilbert_index_r2(x, y, width) {
51
+ let index = 0;
52
+
53
+ let posX = x;
54
+ let posY = y;
55
+
56
+ for (let curLevel = width >>> 1; curLevel >= 1; curLevel >>>= 1) {
57
+ const regionX = (posX & curLevel) > 0 ? 1 : 0;
58
+ const regionY = (posY & curLevel) > 0 ? 1 : 0;
59
+
60
+ index += curLevel * curLevel * ((3 * regionX) ^ regionY);
61
+
62
+ if (regionY === 0) {
63
+
64
+ if (regionX === 1) {
65
+ posX = (width - 1) - posX;
66
+ posY = (width - 1) - posY;
67
+ }
68
+
69
+ // swap
70
+ const temp = posX;
71
+
72
+ posX = posY;
73
+ posY = temp;
74
+ }
75
+ }
76
+
77
+ return index;
78
+ }