@woosh/meep-engine 2.48.11 → 2.48.13
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/package.json +1 -1
- package/src/core/collection/HashMap.js +2 -2
- package/src/core/collection/HashMap.spec.js +24 -1
- package/src/core/collection/queue/Deque.d.ts +9 -0
- package/src/core/collection/queue/Deque.js +3 -0
- package/src/core/collection/queue/Deque.spec.js +51 -0
- package/src/core/debug/matchers/matchers.js +10 -0
- package/src/core/math/noise/create_noise_2d.js +193 -0
- package/src/engine/Engine.js +9 -5
- package/src/engine/asset/AssetManager.d.ts +10 -5
- package/src/engine/asset/AssetManager.js +22 -9
- package/src/engine/asset/PendingAsset.js +6 -6
- package/src/engine/asset/loaders/AssetLoader.d.ts +7 -2
- package/src/engine/asset/loaders/AssetLoader.js +17 -15
- package/src/engine/asset/loaders/GLTFAssetLoader.js +1 -1
- package/src/engine/asset/loaders/SoundAssetLoader.js +3 -5
- package/src/engine/development/performance/MetricStatistics.js +7 -5
- package/src/engine/development/performance/RingBufferMetric.js +2 -2
- package/src/engine/ecs/foliage/ecs/InstancedMeshUtils.js +14 -1
- package/src/engine/ecs/gui/GUIElementSystem.d.ts +1 -1
- package/src/engine/ecs/terrain/ecs/cling/ClingToTerrainSystem.js +3 -21
- package/src/engine/graphics/ecs/camera/pp/PerfectPanner.js +4 -2
- package/src/engine/graphics/texture/3d/SingleChannelSampler3D.js +146 -0
- package/src/engine/graphics/texture/3d/scs3d_read_2d_slice.js +26 -0
- package/src/engine/graphics/texture/sampler/Sampler2D.js +2 -2
- package/src/engine/physics/fluid/FluidField.js +153 -1
- package/src/engine/physics/fluid/prototype.js +201 -0
- package/src/engine/physics/fluid/solver/v3_grid_apply_diffusion.js +67 -0
- package/src/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +17 -12
- package/src/generation/filtering/numeric/complex/CellFilterSimplexNoise.js +14 -10
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {Float32Array} output
|
|
4
|
+
* @param {Float32Array} input
|
|
5
|
+
* @param {number[]} resolution
|
|
6
|
+
*/
|
|
7
|
+
export function v3_grid_apply_diffusion(output, input, resolution) {
|
|
8
|
+
const res_x = resolution[0];
|
|
9
|
+
const res_y = resolution[1];
|
|
10
|
+
const res_z = resolution[2];
|
|
11
|
+
|
|
12
|
+
const factor = 1 / 7;
|
|
13
|
+
|
|
14
|
+
let sum = 0;
|
|
15
|
+
|
|
16
|
+
const slice_size = res_y * res_x;
|
|
17
|
+
|
|
18
|
+
for (let z = 0; z < res_z; z++) {
|
|
19
|
+
for (let y = 0; y < res_y; y++) {
|
|
20
|
+
for (let x = 0; x < res_x; x++) {
|
|
21
|
+
|
|
22
|
+
let sample_count = 1;
|
|
23
|
+
|
|
24
|
+
sum = 0;
|
|
25
|
+
|
|
26
|
+
// sample cells around
|
|
27
|
+
if (z > 0) {
|
|
28
|
+
sample_count++;
|
|
29
|
+
sum += input[(z - 1) * slice_size + y * res_x + x]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (y > 0) {
|
|
33
|
+
sample_count++;
|
|
34
|
+
sum += input[z * slice_size + (y - 1) * res_x + x]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (x > 0) {
|
|
38
|
+
sample_count++;
|
|
39
|
+
sum += input[z * slice_size + y * res_x + (x - 1)]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
const current = z * slice_size + y * res_x + x;
|
|
44
|
+
|
|
45
|
+
sum += input[current];
|
|
46
|
+
|
|
47
|
+
if (x < res_x - 1) {
|
|
48
|
+
sample_count++;
|
|
49
|
+
sum += input[z * slice_size + y * res_x + (x + 1)]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (y < res_y - 1) {
|
|
53
|
+
sample_count++;
|
|
54
|
+
sum += input[z * slice_size + (y + 1) * res_x + x]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (z < res_z - 1) {
|
|
58
|
+
sample_count++;
|
|
59
|
+
sum += input[(z + 1) * slice_size + y * res_x + x]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
output[current] = sum / sample_count;
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -72,12 +72,20 @@ export class CellFilterGaussianBlur extends CellFilter {
|
|
|
72
72
|
* @private
|
|
73
73
|
*/
|
|
74
74
|
this.__kernel = [];
|
|
75
|
+
|
|
75
76
|
/**
|
|
76
77
|
*
|
|
77
78
|
* @type {number}
|
|
78
79
|
* @private
|
|
79
80
|
*/
|
|
80
81
|
this.__kernel_total_power = 0;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* @type {number}
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
this.__inv_kernel_total_power = 0;
|
|
81
89
|
}
|
|
82
90
|
|
|
83
91
|
initialize(grid, seed) {
|
|
@@ -94,6 +102,9 @@ export class CellFilterGaussianBlur extends CellFilter {
|
|
|
94
102
|
// initialize kernel
|
|
95
103
|
this.__kernel_total_power = buildKernel(this.__kernel, this.samples_x, this.samples_y, this.sigma_x, this.sigma_y);
|
|
96
104
|
|
|
105
|
+
// store inverse, to be able to use multiply instead of division in execution
|
|
106
|
+
this.__inv_kernel_total_power = 1 / this.__kernel_total_power;
|
|
107
|
+
|
|
97
108
|
super.initialize(grid, seed);
|
|
98
109
|
}
|
|
99
110
|
|
|
@@ -132,8 +143,8 @@ export class CellFilterGaussianBlur extends CellFilter {
|
|
|
132
143
|
const sizeX = this.size_x;
|
|
133
144
|
const sizeY = this.size_y;
|
|
134
145
|
|
|
135
|
-
const local_u_scale =
|
|
136
|
-
const local_v_scale =
|
|
146
|
+
const local_u_scale = sizeX / (samplesX - 1);
|
|
147
|
+
const local_v_scale = sizeY / (samplesY - 1);
|
|
137
148
|
|
|
138
149
|
let sum = 0;
|
|
139
150
|
let ix, iy = 0;
|
|
@@ -146,9 +157,7 @@ export class CellFilterGaussianBlur extends CellFilter {
|
|
|
146
157
|
for (; iy < samplesY; iy++) {
|
|
147
158
|
const local_y = iy - half_samples_y;
|
|
148
159
|
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
const offset_y = sizeY * ny;
|
|
160
|
+
const offset_y = y + local_y * local_v_scale;
|
|
152
161
|
|
|
153
162
|
const row_address = iy * i_samples_x;
|
|
154
163
|
|
|
@@ -156,13 +165,11 @@ export class CellFilterGaussianBlur extends CellFilter {
|
|
|
156
165
|
|
|
157
166
|
const local_x = ix - half_samples_x;
|
|
158
167
|
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
const offset_x = sizeX * nx;
|
|
168
|
+
const offset_x = local_x * local_u_scale;
|
|
162
169
|
|
|
163
170
|
const power = kernel[row_address + ix];
|
|
164
171
|
|
|
165
|
-
const sourceValue = source.execute(grid, x + offset_x,
|
|
172
|
+
const sourceValue = source.execute(grid, x + offset_x, offset_y, 0);
|
|
166
173
|
|
|
167
174
|
const sample_contribution = sourceValue * power;
|
|
168
175
|
|
|
@@ -171,8 +178,6 @@ export class CellFilterGaussianBlur extends CellFilter {
|
|
|
171
178
|
}
|
|
172
179
|
}
|
|
173
180
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return result;
|
|
181
|
+
return sum * this.__inv_kernel_total_power;
|
|
177
182
|
}
|
|
178
183
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { seededRandom } from "../../../../core/math/random/seededRandom.js";
|
|
2
2
|
import { CellFilter } from "../../CellFilter.js";
|
|
3
|
-
import SimplexNoise from "simplex-noise";
|
|
4
3
|
import { CellFilterAdd } from "../math/algebra/CellFilterAdd.js";
|
|
5
4
|
import { CellFilterMultiply } from "../math/algebra/CellFilterMultiply.js";
|
|
6
5
|
import { CellFilterLiteralFloat } from "../CellFilterLiteralFloat.js";
|
|
7
6
|
import { CellFilterDivide } from "../math/algebra/CellFilterDivide.js";
|
|
7
|
+
import { createNoise2D } from "../../../../core/math/noise/create_noise_2d.js";
|
|
8
8
|
|
|
9
9
|
export class CellFilterSimplexNoise extends CellFilter {
|
|
10
10
|
constructor() {
|
|
@@ -12,7 +12,7 @@ export class CellFilterSimplexNoise extends CellFilter {
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @private
|
|
15
|
-
* @type {
|
|
15
|
+
* @type {function(x:number,y:number):number}
|
|
16
16
|
*/
|
|
17
17
|
this.noise = null;
|
|
18
18
|
|
|
@@ -25,6 +25,9 @@ export class CellFilterSimplexNoise extends CellFilter {
|
|
|
25
25
|
this.scale_x = 1;
|
|
26
26
|
this.scale_y = 1;
|
|
27
27
|
|
|
28
|
+
this.inv_scale_x = 1;
|
|
29
|
+
this.inv_scale_y = 1;
|
|
30
|
+
|
|
28
31
|
/**
|
|
29
32
|
* RNG Seed offset
|
|
30
33
|
* @type {number}
|
|
@@ -50,6 +53,8 @@ export class CellFilterSimplexNoise extends CellFilter {
|
|
|
50
53
|
let amplitude = 1;
|
|
51
54
|
let totalAmplitude = 0;
|
|
52
55
|
|
|
56
|
+
const G = Math.pow(2, -persistence);
|
|
57
|
+
|
|
53
58
|
for (let i = 0; i < octaves; i++) {
|
|
54
59
|
const noise = CellFilterSimplexNoise.from(scale * frequency, scale * frequency, s);
|
|
55
60
|
|
|
@@ -63,7 +68,7 @@ export class CellFilterSimplexNoise extends CellFilter {
|
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
totalAmplitude += amplitude;
|
|
66
|
-
amplitude *=
|
|
71
|
+
amplitude *= G;
|
|
67
72
|
frequency *= lacunarity;
|
|
68
73
|
|
|
69
74
|
s = (s + 1) * 31;
|
|
@@ -95,25 +100,24 @@ export class CellFilterSimplexNoise extends CellFilter {
|
|
|
95
100
|
r.scale_y = scale_y;
|
|
96
101
|
r.__seed = seed;
|
|
97
102
|
|
|
103
|
+
r.inv_scale_x = 1 / scale_x;
|
|
104
|
+
r.inv_scale_y = 1 / scale_y;
|
|
105
|
+
|
|
98
106
|
return r;
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
initialize(grid, seed) {
|
|
102
110
|
this.random.setCurrentSeed(seed + this.__seed);
|
|
103
111
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this.noise = noise;
|
|
112
|
+
this.noise = createNoise2D(this.random);
|
|
107
113
|
|
|
108
114
|
super.initialize(grid, seed);
|
|
109
115
|
}
|
|
110
116
|
|
|
111
117
|
execute(grid, x, y, rotation) {
|
|
112
|
-
const noiseValue = this.noise
|
|
118
|
+
const noiseValue = this.noise(x * this.inv_scale_x, y * this.inv_scale_y);
|
|
113
119
|
|
|
114
120
|
//noise function returns values in range [-1,1] we need to scale that to [0,1] range
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return normalizedValue;
|
|
121
|
+
return (noiseValue + 1) * 0.5;
|
|
118
122
|
}
|
|
119
123
|
}
|