block meshgen work

This commit is contained in:
austin 2025-03-27 18:10:14 -04:00
parent ccde488b23
commit 097c23ef28
4 changed files with 214 additions and 4 deletions

View File

@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file
#Wed Mar 26 17:14:44 EDT 2025
buildNumber=606
#Thu Mar 27 17:44:45 EDT 2025
buildNumber=607

View File

@ -1342,6 +1342,7 @@ Filter select-able saves on singleplayer screen to full game saves
Increase number of invalid openAL IDs
Fix audio engine not cleaning up audio sources
More accurate block test types
Block meshgen work

View File

@ -553,9 +553,9 @@ public class BlockMeshgen {
return this.x - other.x;
}
if(this.w != other.w){
return this.w - other.w;
return other.w - this.w;
}
return this.h - other.h;
return other.h - this.h;
}
}

View File

@ -1192,4 +1192,213 @@ public class BlockMeshgenTests {
}
}
@UnitTest
public void test_rasterize_12(){
//expected data
float[] expectedData = new float[]{
//block 1
1,1,1,
2,1,1,
1,5,1,
2,5,1,
1,1,1,
1,1,2,
1,5,1,
1,5,2,
1,1,1,
1,1,2,
2,1,1,
2,1,2,
1,1,2,
2,1,2,
1,5,2,
2,5,2,
2,1,1,
2,1,2,
2,5,1,
2,5,2,
1,5,1,
1,5,2,
2,5,1,
2,5,2,
//block 2
2,4,1,
3,4,1,
2,5,1,
3,5,1,
2,4,1,
2,4,2,
2,5,1,
2,5,2,
2,4,1,
2,4,2,
3,4,1,
3,4,2,
2,4,2,
3,4,2,
2,5,2,
3,5,2,
3,4,1,
3,4,2,
3,5,1,
3,5,2,
2,5,1,
2,5,2,
3,5,1,
3,5,2,
};
for(int i = 0; i < expectedData.length; i++){
expectedData[i] = expectedData[i] * BlockChunkData.BLOCK_SIZE_MULTIPLIER;
}
//setup data
BlockChunkData chunkData = new BlockChunkData();
short[] types = new short[BlockChunkData.CHUNK_DATA_WIDTH * BlockChunkData.CHUNK_DATA_WIDTH * BlockChunkData.CHUNK_DATA_WIDTH];
chunkData.setType(types);
//block 1
chunkData.setType(1, 1, 1, (short)1);
chunkData.setType(1, 2, 1, (short)1);
chunkData.setType(1, 3, 1, (short)1);
chunkData.setType(1, 4, 1, (short)1);
//block 2
chunkData.setType(2, 4, 1, (short)1);
//call
BlockMeshData meshData = BlockMeshgen.rasterize(chunkData);
//error check result
assertEquals(expectedData.length, meshData.vertices.length);
for(int i = 0; i < expectedData.length; i++){
if(expectedData[i] != meshData.vertices[i]){
System.err.println("Vertex was incorrect! " + i);
String message = "Vertex was incorrect!\n" +
"index: " + i + "\n" +
"expected: " + expectedData[i] + "\n" +
"actual: " + meshData.vertices[i] + "\n";
assertDoesNotThrow(() -> {
throw new Error(message);
});
}
}
}
@UnitTest
public void test_rasterize_13(){
//expected data
float[] expectedData = new float[]{
//block 1
1,1,1,
2,1,1,
1,5,1,
2,5,1,
1,1,1,
1,1,2,
1,5,1,
1,5,2,
1,1,1,
1,1,2,
2,1,1,
2,1,2,
1,1,2,
2,1,2,
1,5,2,
2,5,2,
2,1,1,
2,1,2,
2,5,1,
2,5,2,
1,5,1,
1,5,2,
2,5,1,
2,5,2,
//block 2
2,4,1,
4,4,1,
2,5,1,
4,5,1,
2,4,1,
2,4,2,
2,5,1,
2,5,2,
2,4,1,
2,4,2,
4,4,1,
4,4,2,
2,4,2,
4,4,2,
2,5,2,
4,5,2,
4,4,1,
4,4,2,
4,5,1,
4,5,2,
2,5,1,
2,5,2,
4,5,1,
4,5,2,
};
for(int i = 0; i < expectedData.length; i++){
expectedData[i] = expectedData[i] * BlockChunkData.BLOCK_SIZE_MULTIPLIER;
}
//setup data
BlockChunkData chunkData = new BlockChunkData();
short[] types = new short[BlockChunkData.CHUNK_DATA_WIDTH * BlockChunkData.CHUNK_DATA_WIDTH * BlockChunkData.CHUNK_DATA_WIDTH];
chunkData.setType(types);
//block 1
chunkData.setType(1, 1, 1, (short)1);
chunkData.setType(1, 2, 1, (short)1);
chunkData.setType(1, 3, 1, (short)1);
chunkData.setType(1, 4, 1, (short)1);
//block 2
chunkData.setType(2, 4, 1, (short)1);
chunkData.setType(3, 4, 1, (short)1);
//call
BlockMeshData meshData = BlockMeshgen.rasterize(chunkData);
//error check result
assertEquals(expectedData.length, meshData.vertices.length);
for(int i = 0; i < expectedData.length; i++){
if(expectedData[i] != meshData.vertices[i]){
System.err.println("Vertex was incorrect! " + i);
String message = "Vertex was incorrect!\n" +
"index: " + i + "\n" +
"expected: " + expectedData[i] + "\n" +
"actual: " + meshData.vertices[i] + "\n";
assertDoesNotThrow(() -> {
throw new Error(message);
});
}
}
}
}