block fab work
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-18 11:52:13 -04:00
parent 1ee23aa115
commit 7e7c91e6d5
2 changed files with 13 additions and 18 deletions

View File

@ -1862,6 +1862,7 @@ Solve for furniture placement inside rectangular rooms
Visualize furniture placement slots
AssetDataStrings work
Invert rotation calculation for fab cursor
BlockFab io work

View File

@ -3,7 +3,6 @@ package electrosphere.data.block.fab;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import org.joml.Vector3i;
@ -23,7 +22,7 @@ public class BlockFab implements BlockMeshgenData {
/**
* File version format
*/
public static final int FILE_VER = 2;
public static final int FILE_VER = 3;
/**
* Size of the header for a block fab file
@ -84,12 +83,10 @@ public class BlockFab implements BlockMeshgenData {
ByteBuffer buff = ByteBuffer.allocate(HEADER_SIZE + blockCount * BlockChunkData.BYTES_PER_BLOCK + serializedMetadataBytes.length);
IntBuffer intView = buff.asIntBuffer();
intView.put(FILE_VER);
intView.put(dimensions.x);
intView.put(dimensions.y);
intView.put(dimensions.z);
buff.position(HEADER_SIZE);
buff.putInt(FILE_VER);
buff.putInt(dimensions.x);
buff.putInt(dimensions.y);
buff.putInt(dimensions.z);
ShortBuffer shortView = buff.asShortBuffer();
@ -116,21 +113,19 @@ public class BlockFab implements BlockMeshgenData {
ByteBuffer buff;
try {
buff = FileUtils.readBufferFromCompressedFile(file);
IntBuffer intView = buff.asIntBuffer();
int fileVer = intView.get();
int fileVer = buff.getInt();
LoggerInterface.loggerFileIO.DEBUG("Read fab file with ver " + fileVer);
if(fileVer != FILE_VER){
LoggerInterface.loggerFileIO.WARNING("Reading unsupported fab file with version: " + fileVer);
}
int dimX = intView.get();
int dimY = intView.get();
int dimZ = intView.get();
int dimX = buff.getInt();
int dimY = buff.getInt();
int dimZ = buff.getInt();
Vector3i dims = new Vector3i(dimX, dimY, dimZ);
buff.position(HEADER_SIZE);
ShortBuffer shortView = buff.asShortBuffer();
int blockCount = dims.x * dims.y * dims.z;
short[] types = new short[blockCount];
short[] metadata = new short[blockCount];
@ -138,7 +133,7 @@ public class BlockFab implements BlockMeshgenData {
for(int x = 0; x < dims.x; x++){
for(int y = 0; y < dims.y; y++){
for(int z = 0; z < dims.z; z++){
types[i] = shortView.get();
types[i] = buff.getShort();
i++;
}
}
@ -147,14 +142,13 @@ public class BlockFab implements BlockMeshgenData {
for(int x = 0; x < dims.x; x++){
for(int y = 0; y < dims.y; y++){
for(int z = 0; z < dims.z; z++){
metadata[i] = shortView.get();
metadata[i] = buff.getShort();
i++;
}
}
}
//read the fab metadata
buff.position(HEADER_SIZE + blockCount * 2 + blockCount * 2);
BlockFabMetadata fabMetadata = new BlockFabMetadata();
if(buff.remaining() > 0){
byte[] fabMetadataBytes = new byte[buff.remaining()];