fab file loading
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
383a3b6ac3
commit
ca9282d2e6
@ -1543,6 +1543,7 @@ Block area selection
|
|||||||
Exporting block prefabs to compressed files
|
Exporting block prefabs to compressed files
|
||||||
Minor block fab improvements
|
Minor block fab improvements
|
||||||
Fab selection tool
|
Fab selection tool
|
||||||
|
Fab selection tool actually loads fab files
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,8 @@ import electrosphere.client.ui.menu.WindowUtils;
|
|||||||
import electrosphere.controls.ControlHandler.ControlsState;
|
import electrosphere.controls.ControlHandler.ControlsState;
|
||||||
import electrosphere.engine.Globals;
|
import electrosphere.engine.Globals;
|
||||||
import electrosphere.engine.signal.Signal.SignalType;
|
import electrosphere.engine.signal.Signal.SignalType;
|
||||||
|
import electrosphere.game.data.block.BlockFab;
|
||||||
|
import electrosphere.logger.LoggerInterface;
|
||||||
import electrosphere.renderer.ui.elements.Window;
|
import electrosphere.renderer.ui.elements.Window;
|
||||||
import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment;
|
import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment;
|
||||||
import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaFlexDirection;
|
import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaFlexDirection;
|
||||||
@ -54,7 +56,8 @@ public class FabMenus {
|
|||||||
|
|
||||||
//attach scrollable after search input for organzation purposes
|
//attach scrollable after search input for organzation purposes
|
||||||
fabSelectionPanelWindow.addChild(FabSelectionPanel.createFabSelectionPanel((File selectedFile) -> {
|
fabSelectionPanelWindow.addChild(FabSelectionPanel.createFabSelectionPanel((File selectedFile) -> {
|
||||||
System.out.println(selectedFile);
|
BlockFab fab = BlockFab.read(selectedFile);
|
||||||
|
LoggerInterface.loggerEngine.WARNING("" + fab.getDimensions());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Globals.signalSystem.post(SignalType.YOGA_APPLY,fabSelectionPanelWindow);
|
Globals.signalSystem.post(SignalType.YOGA_APPLY,fabSelectionPanelWindow);
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import java.nio.ShortBuffer;
|
|||||||
import org.joml.Vector3i;
|
import org.joml.Vector3i;
|
||||||
|
|
||||||
import electrosphere.client.block.BlockChunkData;
|
import electrosphere.client.block.BlockChunkData;
|
||||||
|
import electrosphere.logger.LoggerInterface;
|
||||||
import electrosphere.util.FileUtils;
|
import electrosphere.util.FileUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,4 +92,75 @@ public class BlockFab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a BlockFab from a specified file
|
||||||
|
* @param file The file
|
||||||
|
* @return The BlockFab
|
||||||
|
*/
|
||||||
|
public static BlockFab read(File file){
|
||||||
|
BlockFab rVal = null;
|
||||||
|
ByteBuffer buff;
|
||||||
|
try {
|
||||||
|
buff = FileUtils.readBufferFromCompressedFile(file);
|
||||||
|
IntBuffer intView = buff.asIntBuffer();
|
||||||
|
int fileVer = intView.get();
|
||||||
|
LoggerInterface.loggerFileIO.DEBUG("Read fab file with ver " + fileVer);
|
||||||
|
|
||||||
|
int dimX = intView.get();
|
||||||
|
int dimY = intView.get();
|
||||||
|
int dimZ = intView.get();
|
||||||
|
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];
|
||||||
|
int i = 0;
|
||||||
|
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();
|
||||||
|
metadata[i] = shortView.get();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rVal = new BlockFab();
|
||||||
|
rVal.dimensions = dims;
|
||||||
|
rVal.types = types;
|
||||||
|
rVal.metadata = metadata;
|
||||||
|
} catch (IOException e) {
|
||||||
|
LoggerInterface.loggerFileIO.ERROR(e);
|
||||||
|
throw new Error("Failed to read BlockFab " + file);
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the dimensions of the fab
|
||||||
|
* @return The dimensions of the fab
|
||||||
|
*/
|
||||||
|
public Vector3i getDimensions() {
|
||||||
|
return dimensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the type data of the fab
|
||||||
|
* @return The type data
|
||||||
|
*/
|
||||||
|
public short[] getTypes() {
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the metadata of the fab
|
||||||
|
* @return The metadata
|
||||||
|
*/
|
||||||
|
public short[] getMetadata() {
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user