@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
63 lines (48 loc) • 1.93 kB
JavaScript
import { scs3d_sample_linear } from "../../../graphics/texture/3d/scs3d_sample_linear.js";
/**
*
* @param {Float32Array[]} outputs
* @param {Float32Array[]} inputs
* @param {number[]} resolution
* @param {number} time_delta
*/
export function v3_grid_apply_advection_forward(outputs, inputs, resolution, time_delta) {
const res_x = resolution[0];
const res_y = resolution[1];
const res_z = resolution[2];
const input_x = inputs[0];
const input_y = inputs[1];
const input_z = inputs[2];
const slice_size = res_y * res_x;
for (
let z = 0;
z < res_z - 1;
z++
) {
const current_z_slice_offset = z * slice_size;
for (
let y = 0;
y < res_y;
y++
) {
const current_y_line_offset = y * res_x;
for (let x = 0; x < res_x; x++) {
const current_index = current_z_slice_offset + current_y_line_offset + x;
const v_x = input_x[current_index]
const v_y = input_y[current_index]
const v_z = input_z[current_index]
// compute previous position of the particle
const s_x = x - v_x * time_delta;
const s_y = y - v_y * time_delta;
const s_z = z - v_z * time_delta;
// sample values at previous position
const new_x = scs3d_sample_linear(input_x, res_x, res_y, res_z, s_x, s_y, s_z);
const new_y = scs3d_sample_linear(input_y, res_x, res_y, res_z, s_x, s_y, s_z);
const new_z = scs3d_sample_linear(input_z, res_x, res_y, res_z, s_x, s_y, s_z);
outputs[0][current_index] = new_x;
outputs[1][current_index] = new_y;
outputs[2][current_index] = new_z;
}
}
}
}