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 Visualize furniture placement slots
AssetDataStrings work AssetDataStrings work
Invert rotation calculation for fab cursor 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.File;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer; import java.nio.ShortBuffer;
import org.joml.Vector3i; import org.joml.Vector3i;
@ -23,7 +22,7 @@ public class BlockFab implements BlockMeshgenData {
/** /**
* File version format * 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 * 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); ByteBuffer buff = ByteBuffer.allocate(HEADER_SIZE + blockCount * BlockChunkData.BYTES_PER_BLOCK + serializedMetadataBytes.length);
IntBuffer intView = buff.asIntBuffer(); buff.putInt(FILE_VER);
intView.put(FILE_VER); buff.putInt(dimensions.x);
intView.put(dimensions.x); buff.putInt(dimensions.y);
intView.put(dimensions.y); buff.putInt(dimensions.z);
intView.put(dimensions.z);
buff.position(HEADER_SIZE);
ShortBuffer shortView = buff.asShortBuffer(); ShortBuffer shortView = buff.asShortBuffer();
@ -116,21 +113,19 @@ public class BlockFab implements BlockMeshgenData {
ByteBuffer buff; ByteBuffer buff;
try { try {
buff = FileUtils.readBufferFromCompressedFile(file); buff = FileUtils.readBufferFromCompressedFile(file);
IntBuffer intView = buff.asIntBuffer(); int fileVer = buff.getInt();
int fileVer = intView.get();
LoggerInterface.loggerFileIO.DEBUG("Read fab file with ver " + fileVer); LoggerInterface.loggerFileIO.DEBUG("Read fab file with ver " + fileVer);
if(fileVer != FILE_VER){ if(fileVer != FILE_VER){
LoggerInterface.loggerFileIO.WARNING("Reading unsupported fab file with version: " + fileVer); LoggerInterface.loggerFileIO.WARNING("Reading unsupported fab file with version: " + fileVer);
} }
int dimX = intView.get(); int dimX = buff.getInt();
int dimY = intView.get(); int dimY = buff.getInt();
int dimZ = intView.get(); int dimZ = buff.getInt();
Vector3i dims = new Vector3i(dimX, dimY, dimZ); Vector3i dims = new Vector3i(dimX, dimY, dimZ);
buff.position(HEADER_SIZE); buff.position(HEADER_SIZE);
ShortBuffer shortView = buff.asShortBuffer();
int blockCount = dims.x * dims.y * dims.z; int blockCount = dims.x * dims.y * dims.z;
short[] types = new short[blockCount]; short[] types = new short[blockCount];
short[] metadata = 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 x = 0; x < dims.x; x++){
for(int y = 0; y < dims.y; y++){ for(int y = 0; y < dims.y; y++){
for(int z = 0; z < dims.z; z++){ for(int z = 0; z < dims.z; z++){
types[i] = shortView.get(); types[i] = buff.getShort();
i++; i++;
} }
} }
@ -147,14 +142,13 @@ public class BlockFab implements BlockMeshgenData {
for(int x = 0; x < dims.x; x++){ for(int x = 0; x < dims.x; x++){
for(int y = 0; y < dims.y; y++){ for(int y = 0; y < dims.y; y++){
for(int z = 0; z < dims.z; z++){ for(int z = 0; z < dims.z; z++){
metadata[i] = shortView.get(); metadata[i] = buff.getShort();
i++; i++;
} }
} }
} }
//read the fab metadata //read the fab metadata
buff.position(HEADER_SIZE + blockCount * 2 + blockCount * 2);
BlockFabMetadata fabMetadata = new BlockFabMetadata(); BlockFabMetadata fabMetadata = new BlockFabMetadata();
if(buff.remaining() > 0){ if(buff.remaining() > 0){
byte[] fabMetadataBytes = new byte[buff.remaining()]; byte[] fabMetadataBytes = new byte[buff.remaining()];