Clean up java side

This commit is contained in:
unknown 2023-07-23 12:40:41 -04:00
parent ad95b64b88
commit 2eeb45b1e9
2 changed files with 79 additions and 99 deletions

View File

@ -56,15 +56,6 @@ public class FluidSim {
//Buffers that contain w vector directions to add to the simulation
ByteBuffer wAdditionVector;
// ByteBuffer x = ByteBuffer.allocateDirect(DIM * DIM * DIM * 4);
// ByteBuffer x0 = ByteBuffer.allocateDirect(DIM * DIM * DIM * 4);
// ByteBuffer u = ByteBuffer.allocateDirect(DIM * DIM * DIM * 4);
// ByteBuffer v = ByteBuffer.allocateDirect(DIM * DIM * DIM * 4);
// ByteBuffer w = ByteBuffer.allocateDirect(DIM * DIM * DIM * 4);
// ByteBuffer u0 = ByteBuffer.allocateDirect(DIM * DIM * DIM * 4);
// ByteBuffer v0 = ByteBuffer.allocateDirect(DIM * DIM * DIM * 4);
// ByteBuffer w0 = ByteBuffer.allocateDirect(DIM * DIM * DIM * 4);
//The densities for every voxel for the current frame
float[] densityArrayView = new float[DIM * DIM * DIM];
//Should be set to add water to the current frame
@ -137,10 +128,20 @@ public class FluidSim {
}
}
public static void simChunks(FluidSim[][][] simArray, int step, float timestep){
for(int x = 0; x < simArray.length; x++){
for(int y = 0; y < simArray[0].length; y++){
for(int z = 0; z < simArray[0][0].length; z++){
simArray[x][y][z].simulate(step, timestep);
}
}
}
}
/**
* Runs a frame of the fluid simulation
*/
public void simulate(int step, float timestep){
private void simulate(int step, float timestep){
//
// Add forces and density here
@ -152,30 +153,6 @@ public class FluidSim {
//
writeNewStateIntoBuffers();
// if(x.position() > 0){
// x.position(0);
// }
// if(x0.position() > 0){
// x0.position(0);
// }
// if(u.position() > 0){
// u.position(0);
// }
// if(v.position() > 0){
// v.position(0);
// }
// if(w.position() > 0){
// w.position(0);
// }
// if(u0.position() > 0){
// u0.position(0);
// }
// if(v0.position() > 0){
// v0.position(0);
// }
// if(w0.position() > 0){
// w0.position(0);
// }
simulate(
DIM,
0,

View File

@ -21,63 +21,27 @@ public class Main {
public static void main(String args[]){
int dim = 1;
int i = 0;
long time = 0;
long lastTime = 0;
Scanner scan = new Scanner(System.in);
try {
GLFWContext.init();
//init shader program
Mesh.initShaderProgram();
int dim = 1;
FluidSim[][][] simArray = new FluidSim[dim][1][1];
for(int x = 0; x < simArray.length; x++){
for(int y = 0; y < simArray[0].length; y++){
for(int z = 0; z < simArray[0][0].length; z++){
simArray[x][y][z] = new FluidSim();
simArray[x][y][z].setup(new Vector3i(x,y,z));
}
}
}
//set sim adjacencies
for(int x = 0; x < simArray.length; x++){
for(int y = 0; y < simArray[0].length; y++){
for(int z = 0; z < simArray[0][0].length; z++){
FluidSim current = simArray[x][y][z];
for(int i = -1; i < 2; i++){
for(int j = -1; j < 2; j++){
for(int k = -1; k < 2; k++){
if(i == j && j == k && k == 0){
continue;
}
if(
0 <= x + i && x + i < simArray.length &&
0 <= y + j && y + j < simArray[0].length &&
0 <= z + k && z + k < simArray[0][0].length
){
current.setNeighbor(i+1,j+1,k+1,simArray[x+i][y+j][z+k]);
}
}
}
}
}
}
}
// FluidSim sim = new FluidSim();
// sim.setup();
Mesh[][][] meshArray = new Mesh[dim][1][1];
for(int x = 0; x < simArray.length; x++){
for(int y = 0; y < simArray[0].length; y++){
for(int z = 0; z < simArray[0][0].length; z++){
meshArray[x][y][z] = new Mesh(simArray[x][y][z], new Vector3i(z * 16, y * 16, x * 16));
meshArray[x][y][z].meshInitially();
}
}
}
// Mesh mesh = new Mesh(sim);
// mesh.meshInitially();
int i = 0;
long time = 0;
long lastTime = 0;
Scanner scan = new Scanner(System.in);
FluidSim[][][] simArray = initFluidSim(dim,1,1);
Mesh[][][] meshArray = initMeshes(dim,1,1,simArray);
while(true){
try {
TimeUnit.MILLISECONDS.sleep(2);
@ -88,23 +52,10 @@ public class Main {
//Transfer data
//
lastTime = System.currentTimeMillis();
// for(int x = 0; x < simArray.length; x++){
// for(int y = 0; y < simArray[0].length; y++){
// for(int z = 0; z < simArray[0][0].length; z++){
// simArray[x][y][z].transfer();
// }
// }
// }
//
//Simulate
//
for(int x = 0; x < simArray.length; x++){
for(int y = 0; y < simArray[0].length; y++){
for(int z = 0; z < simArray[0][0].length; z++){
simArray[x][y][z].simulate(i, 0.001f);
}
}
}
FluidSim.simChunks(simArray,i,0.001f);
time = time + (System.currentTimeMillis() - lastTime);
//
//Remesh
@ -131,4 +82,56 @@ public class Main {
}
}
private static FluidSim[][][] initFluidSim(int dimx, int dimy, int dimz){
FluidSim[][][] simArray = new FluidSim[dimx][dimy][dimz];
for(int x = 0; x < simArray.length; x++){
for(int y = 0; y < simArray[0].length; y++){
for(int z = 0; z < simArray[0][0].length; z++){
simArray[x][y][z] = new FluidSim();
simArray[x][y][z].setup(new Vector3i(x,y,z));
}
}
}
//set sim adjacencies
for(int x = 0; x < simArray.length; x++){
for(int y = 0; y < simArray[0].length; y++){
for(int z = 0; z < simArray[0][0].length; z++){
FluidSim current = simArray[x][y][z];
for(int i = -1; i < 2; i++){
for(int j = -1; j < 2; j++){
for(int k = -1; k < 2; k++){
if(i == j && j == k && k == 0){
continue;
}
if(
0 <= x + i && x + i < simArray.length &&
0 <= y + j && y + j < simArray[0].length &&
0 <= z + k && z + k < simArray[0][0].length
){
current.setNeighbor(i+1,j+1,k+1,simArray[x+i][y+j][z+k]);
}
}
}
}
}
}
}
return simArray;
}
private static Mesh[][][] initMeshes(int dimx, int dimy, int dimz, FluidSim[][][] simArray){
Mesh[][][] meshArray = new Mesh[dimx][dimy][dimz];
for(int x = 0; x < simArray.length; x++){
for(int y = 0; y < simArray[0].length; y++){
for(int z = 0; z < simArray[0][0].length; z++){
meshArray[x][y][z] = new Mesh(simArray[x][y][z], new Vector3i(z * 16, y * 16, x * 16));
meshArray[x][y][z].meshInitially();
}
}
}
return meshArray;
}
}