@buley/hexgrid-3d 3.2.0 → 3.2.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FluidSimulation3DGPU.d.ts","sourceRoot":"","sources":["../../src/algorithms/FluidSimulation3DGPU.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"FluidSimulation3DGPU.d.ts","sourceRoot":"","sources":["../../src/algorithms/FluidSimulation3DGPU.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAiJzD,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,IAAI,CAAS;IAErB,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,MAAM,CAA0B;IAGxC,OAAO,CAAC,eAAe,CAAyC;IAChE,OAAO,CAAC,gBAAgB,CAAyC;IACjE,OAAO,CAAC,gBAAgB,CAAyC;IACjE,OAAO,CAAC,iBAAiB,CAA2B;IAGpD,OAAO,CAAC,cAAc,CAAmC;IACzD,OAAO,CAAC,eAAe,CAAmC;IAC1D,OAAO,CAAC,kBAAkB,CAAmC;IAC7D,OAAO,CAAC,wBAAwB,CAAmC;IAEnE,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,aAAa,CAA0B;IAC/C,OAAO,CAAC,YAAY,CAA0B;IAE9C,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAS;gBAEf,MAAM,EAAE,aAAa;IAY3B,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAuE9B,IAAI,CAAC,EAAE,EAAE,MAAM;IAsCrB,OAAO,CAAC,cAAc;IA6BtB,OAAO,CAAC,eAAe;IAkDvB,OAAO,CAAC,kBAAkB;IAkB1B,OAAO,CAAC,gBAAgB;IAgExB,OAAO,CAAC,wBAAwB;IA2BhC,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAyB1E,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM;IAsBrD,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM;IAKlC,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO;IAIpC,KAAK;CAGN"}
|
|
@@ -3,8 +3,148 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Vector3 } from '../math/Vector3';
|
|
5
5
|
import { WebGPUContext } from '../webgpu/WebGPUContext';
|
|
6
|
-
//
|
|
7
|
-
|
|
6
|
+
// Inlined WGSL shader source (fluid_sim.wgsl)
|
|
7
|
+
const shaderSource = `// fluid_sim.wgsl
|
|
8
|
+
// 3D Fluid Simulation Compute Shaders
|
|
9
|
+
|
|
10
|
+
struct FluidUniforms {
|
|
11
|
+
dt: f32,
|
|
12
|
+
width: f32,
|
|
13
|
+
height: f32,
|
|
14
|
+
depth: f32,
|
|
15
|
+
decay: f32,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
@group(0) @binding(0) var<uniform> uniforms: FluidUniforms;
|
|
19
|
+
|
|
20
|
+
// Bindings for Double-Buffering (Read -> Write)
|
|
21
|
+
// Group 1: Velocity / Density
|
|
22
|
+
@group(1) @binding(0) var field_in: texture_3d<f32>;
|
|
23
|
+
@group(1) @binding(1) var field_out: texture_storage_3d<rgba16float, write>;
|
|
24
|
+
|
|
25
|
+
// Sampler for linear interpolation
|
|
26
|
+
@group(1) @binding(2) var field_sampler: sampler;
|
|
27
|
+
|
|
28
|
+
// ----------------------------------------------------------------------------
|
|
29
|
+
// ADVECTION
|
|
30
|
+
// Moves quantities along the velocity field
|
|
31
|
+
// ----------------------------------------------------------------------------
|
|
32
|
+
@group(2) @binding(0) var velocity_field: texture_3d<f32>;
|
|
33
|
+
|
|
34
|
+
@compute @workgroup_size(8, 8, 8)
|
|
35
|
+
fn advect(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
|
36
|
+
let dims = vec3<f32>(uniforms.width, uniforms.height, uniforms.depth);
|
|
37
|
+
let coords = vec3<f32>(global_id);
|
|
38
|
+
|
|
39
|
+
if (any(coords >= dims)) { return; }
|
|
40
|
+
|
|
41
|
+
// 1. Sample velocity at current position
|
|
42
|
+
// Note: textureSampleLevel requires normalized coordinates [0, 1]
|
|
43
|
+
let uvw = (coords + 0.5) / dims;
|
|
44
|
+
let vel = textureSampleLevel(velocity_field, field_sampler, uvw, 0.0).xyz;
|
|
45
|
+
|
|
46
|
+
// 2. Trace back in time
|
|
47
|
+
let dt = uniforms.dt;
|
|
48
|
+
// Scale velocity back to grid units?
|
|
49
|
+
// Uniforms velocity tends to be in grid-units per second.
|
|
50
|
+
// Backtrace coordinate:
|
|
51
|
+
let back_pos = coords - vel * dt;
|
|
52
|
+
|
|
53
|
+
// 3. Sample field at previous position
|
|
54
|
+
let back_uvw = (back_pos + 0.5) / dims;
|
|
55
|
+
let new_val = textureSampleLevel(field_in, field_sampler, back_uvw, 0.0);
|
|
56
|
+
|
|
57
|
+
// 4. Apply decay
|
|
58
|
+
let decayed = new_val * uniforms.decay;
|
|
59
|
+
|
|
60
|
+
textureStore(field_out, global_id, decayed);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ----------------------------------------------------------------------------
|
|
64
|
+
// DIFFUSION (Jacobi Iteration)
|
|
65
|
+
// ----------------------------------------------------------------------------
|
|
66
|
+
// x_new = (x_old + alpha * neighbor_sum) * inverse_beta
|
|
67
|
+
struct JacobiUniforms {
|
|
68
|
+
alpha: f32,
|
|
69
|
+
rBeta: f32,
|
|
70
|
+
};
|
|
71
|
+
@group(3) @binding(0) var<uniform> jacobi: JacobiUniforms;
|
|
72
|
+
@group(3) @binding(1) var b_field: texture_3d<f32>; // The 'b' vector in Ax=b (usually previous state or inputs)
|
|
73
|
+
@group(3) @binding(2) var x_field: texture_3d<f32>; // The 'x' vector (current guess)
|
|
74
|
+
|
|
75
|
+
@compute @workgroup_size(8, 8, 8)
|
|
76
|
+
fn diffuse(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
|
77
|
+
let dims = vec3<i32>(uniforms.width, uniforms.height, uniforms.depth);
|
|
78
|
+
let pos = vec3<i32>(global_id);
|
|
79
|
+
|
|
80
|
+
if (any(pos >= dims)) { return; }
|
|
81
|
+
|
|
82
|
+
// Neighbors
|
|
83
|
+
let left = textureLoad(x_field, pos + vec3<i32>(-1, 0, 0), 0);
|
|
84
|
+
let right = textureLoad(x_field, pos + vec3<i32>(1, 0, 0), 0);
|
|
85
|
+
let down = textureLoad(x_field, pos + vec3<i32>(0, -1, 0), 0);
|
|
86
|
+
let up = textureLoad(x_field, pos + vec3<i32>(0, 1, 0), 0);
|
|
87
|
+
let back = textureLoad(x_field, pos + vec3<i32>(0, 0, -1), 0);
|
|
88
|
+
let front = textureLoad(x_field, pos + vec3<i32>(0, 0, 1), 0);
|
|
89
|
+
|
|
90
|
+
let bC = textureLoad(b_field, pos, 0);
|
|
91
|
+
|
|
92
|
+
// Jacobi step
|
|
93
|
+
let result = (left + right + down + up + back + front) * jacobi.alpha + bC;
|
|
94
|
+
let next_val = result * jacobi.rBeta;
|
|
95
|
+
|
|
96
|
+
textureStore(field_out, global_id, next_val);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ----------------------------------------------------------------------------
|
|
100
|
+
// DIVERGENCE
|
|
101
|
+
// ----------------------------------------------------------------------------
|
|
102
|
+
@compute @workgroup_size(8, 8, 8)
|
|
103
|
+
fn divergence(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
|
104
|
+
let dims = vec3<i32>(uniforms.width, uniforms.height, uniforms.depth);
|
|
105
|
+
let pos = vec3<i32>(global_id);
|
|
106
|
+
|
|
107
|
+
if (any(pos >= dims)) { return; }
|
|
108
|
+
|
|
109
|
+
let left = textureLoad(field_in, pos + vec3<i32>(-1, 0, 0), 0).x;
|
|
110
|
+
let right = textureLoad(field_in, pos + vec3<i32>(1, 0, 0), 0).x;
|
|
111
|
+
let down = textureLoad(field_in, pos + vec3<i32>(0, -1, 0), 0).y;
|
|
112
|
+
let up = textureLoad(field_in, pos + vec3<i32>(0, 1, 0), 0).y;
|
|
113
|
+
let back = textureLoad(field_in, pos + vec3<i32>(0, 0, -1), 0).z;
|
|
114
|
+
let front = textureLoad(field_in, pos + vec3<i32>(0, 0, 1), 0).z;
|
|
115
|
+
|
|
116
|
+
let div = 0.5 * ((right - left) + (up - down) + (front - back));
|
|
117
|
+
|
|
118
|
+
textureStore(field_out, global_id, vec4<f32>(div, 0.0, 0.0, 1.0));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ----------------------------------------------------------------------------
|
|
122
|
+
// GRADIENT SUBTRACTION
|
|
123
|
+
// u_new = u_old - gradient(p)
|
|
124
|
+
// ----------------------------------------------------------------------------
|
|
125
|
+
@group(4) @binding(0) var pressure_field: texture_3d<f32>;
|
|
126
|
+
|
|
127
|
+
@compute @workgroup_size(8, 8, 8)
|
|
128
|
+
fn subtract_gradient(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
|
129
|
+
let dims = vec3<i32>(uniforms.width, uniforms.height, uniforms.depth);
|
|
130
|
+
let pos = vec3<i32>(global_id);
|
|
131
|
+
|
|
132
|
+
if (any(pos >= dims)) { return; }
|
|
133
|
+
|
|
134
|
+
let pLeft = textureLoad(pressure_field, pos + vec3<i32>(-1, 0, 0), 0).x;
|
|
135
|
+
let pRight = textureLoad(pressure_field, pos + vec3<i32>(1, 0, 0), 0).x;
|
|
136
|
+
let pDown = textureLoad(pressure_field, pos + vec3<i32>(0, -1, 0), 0).x;
|
|
137
|
+
let pUp = textureLoad(pressure_field, pos + vec3<i32>(0, 1, 0), 0).x;
|
|
138
|
+
let pBack = textureLoad(pressure_field, pos + vec3<i32>(0, 0, -1), 0).x;
|
|
139
|
+
let pFront = textureLoad(pressure_field, pos + vec3<i32>(0, 0, 1), 0).x;
|
|
140
|
+
|
|
141
|
+
let old_vel = textureLoad(field_in, pos, 0).xyz;
|
|
142
|
+
let grad = vec3<f32>(pRight - pLeft, pUp - pDown, pFront - pBack) * 0.5;
|
|
143
|
+
let new_vel = old_vel - grad;
|
|
144
|
+
|
|
145
|
+
textureStore(field_out, global_id, vec4<f32>(new_vel, 1.0));
|
|
146
|
+
}
|
|
147
|
+
`;
|
|
8
148
|
export class FluidSimulation3DGPU {
|
|
9
149
|
constructor(config) {
|
|
10
150
|
this.device = null;
|
|
@@ -13,4 +13,7 @@ export * from './OutlierDetection';
|
|
|
13
13
|
export * from './FluidSimulation3D';
|
|
14
14
|
export * from './ParticleSystem3D';
|
|
15
15
|
export * from './FlowField3D';
|
|
16
|
+
export * from './FluidSimulation3DGPU';
|
|
17
|
+
export * from './FluidSimulationWebNN';
|
|
18
|
+
export * from './FluidEngineFactory';
|
|
16
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/algorithms/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/algorithms/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAG9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC"}
|
package/dist/algorithms/index.js
CHANGED
|
@@ -15,3 +15,7 @@ export * from './OutlierDetection';
|
|
|
15
15
|
export * from './FluidSimulation3D';
|
|
16
16
|
export * from './ParticleSystem3D';
|
|
17
17
|
export * from './FlowField3D';
|
|
18
|
+
// GPU/WebNN accelerated implementations
|
|
19
|
+
export * from './FluidSimulation3DGPU';
|
|
20
|
+
export * from './FluidSimulationWebNN';
|
|
21
|
+
export * from './FluidEngineFactory';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buley/hexgrid-3d",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "3D hexagonal grid visualization component for React",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"./stores": {
|
|
30
30
|
"types": "./dist/stores/index.d.ts",
|
|
31
31
|
"import": "./dist/stores/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./algorithms": {
|
|
34
|
+
"types": "./dist/algorithms/index.d.ts",
|
|
35
|
+
"import": "./dist/algorithms/index.js"
|
|
32
36
|
}
|
|
33
37
|
},
|
|
34
38
|
"scripts": {
|