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,12 +21,69 @@ 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];
FluidSim[][][] simArray = initFluidSim(dim,1,1);
Mesh[][][] meshArray = initMeshes(dim,1,1,simArray);
while(true){
try {
TimeUnit.MILLISECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
//
//Transfer data
//
lastTime = System.currentTimeMillis();
//
//Simulate
//
FluidSim.simChunks(simArray,i,0.001f);
time = time + (System.currentTimeMillis() - lastTime);
//
//Remesh
//
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].remesh();
}
}
}
//redraw
GLFWContext.redraw(meshArray);
i++;
if(i == 1000){
System.out.println(time / 1000.0);
}
if(i > 3){
// scan.next();
}
}
} catch(Throwable ex){
ex.printStackTrace(System.err);
}
}
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++){
@ -61,9 +118,11 @@ public class Main {
}
}
}
// FluidSim sim = new FluidSim();
// sim.setup();
Mesh[][][] meshArray = new Mesh[dim][1][1];
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++){
@ -72,63 +131,7 @@ public class Main {
}
}
}
// Mesh mesh = new Mesh(sim);
// mesh.meshInitially();
int i = 0;
long time = 0;
long lastTime = 0;
Scanner scan = new Scanner(System.in);
while(true){
try {
TimeUnit.MILLISECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
//
//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);
}
}
}
time = time + (System.currentTimeMillis() - lastTime);
//
//Remesh
//
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].remesh();
}
}
}
//redraw
GLFWContext.redraw(meshArray);
i++;
if(i == 1000){
System.out.println(time / 1000.0);
}
if(i > 3){
// scan.next();
}
}
} catch(Throwable ex){
ex.printStackTrace(System.err);
}
return meshArray;
}
}