support multichunk select all blocks
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-18 20:13:54 -04:00
parent 3323e16971
commit 3ef6f88758
4 changed files with 38 additions and 25 deletions

View File

@ -1882,6 +1882,8 @@ Macro data is injected into voxel chunk generators
Close macro objects injected into voxel chunk gen instead of all data
Fix spline3d mat storing calculations when getting positions
Roads applied to terrain voxel gen
Support lack of macro data for chunk gens
Support multichunk select all blocks

View File

@ -13,6 +13,7 @@ import electrosphere.client.interact.select.AreaSelection.AreaSelectionType;
import electrosphere.client.scene.ClientWorldData;
import electrosphere.data.block.fab.BlockFab;
import electrosphere.engine.Globals;
import electrosphere.server.datacell.ServerWorldData;
import electrosphere.util.math.HashUtils;
/**
@ -96,38 +97,42 @@ public class ClientBlockSelection {
*/
public static BlockFab convertSelectionToFab(){
AreaSelection selection = Globals.cursorState.getAreaSelection();
Vector3i startChunk = Globals.clientState.clientWorldData.convertRealToWorldSpace(selection.getRectStart());
Vector3i endChunk = Globals.clientState.clientWorldData.convertRealToWorldSpace(selection.getRectEnd());
if(!startChunk.equals(endChunk)){
throw new Error("Unsupported case! Selected are coverts multiple chunks.. " + startChunk + " " + endChunk);
}
Vector3i blockStart = ClientWorldData.convertRealToLocalBlockSpace(selection.getRectStart());
Vector3i blockEnd = ClientWorldData.convertRealToLocalBlockSpace(selection.getRectEnd());
BlockChunkData chunk = Globals.clientState.clientBlockManager.getChunkDataAtWorldPoint(startChunk, 0);
if(chunk == null){
throw new Error("Failed to grab chunk at " + startChunk);
}
//get dims
int dimX = (int)((selection.getRectEnd().x - selection.getRectStart().x) * BlockChunkData.BLOCKS_PER_UNIT_DISTANCE);
int dimY = (int)((selection.getRectEnd().y - selection.getRectStart().y) * BlockChunkData.BLOCKS_PER_UNIT_DISTANCE);
int dimZ = (int)((selection.getRectEnd().z - selection.getRectStart().z) * BlockChunkData.BLOCKS_PER_UNIT_DISTANCE);
int blockCount = (blockEnd.x - blockStart.x) * (blockEnd.y - blockStart.y) * (blockEnd.z - blockStart.z);
Vector3d posCurr = new Vector3d();
Vector3i chunkPos = null;
Vector3i blockPos = null;
int blockCount = dimX * dimY * dimZ;
short[] types = new short[blockCount];
short[] metadata = new short[blockCount];
int i = 0;
for(int x = blockStart.x; x < blockEnd.x; x++){
for(int y = blockStart.y; y < blockEnd.y; y++){
for(int z = blockStart.z; z < blockEnd.z; z++){
types[i] = chunk.getType(x, y, z);
metadata[i] = chunk.getMetadata(x, y, z);
for(int x = 0; x < dimX; x++){
for(int y = 0; y < dimY; y++){
for(int z = 0; z < dimZ; z++){
posCurr.set(selection.getRectStart()).add(
x * BlockChunkData.BLOCK_SIZE_MULTIPLIER,
y * BlockChunkData.BLOCK_SIZE_MULTIPLIER,
z * BlockChunkData.BLOCK_SIZE_MULTIPLIER
);
chunkPos = ServerWorldData.convertRealToChunkSpace(posCurr);
BlockChunkData chunk = Globals.clientState.clientBlockManager.getChunkDataAtWorldPoint(chunkPos, 0);
if(chunk == null){
throw new Error("Failed to grab chunk at " + chunkPos);
}
blockPos = ServerWorldData.convertRealToLocalBlockSpace(posCurr);
types[i] = chunk.getType(blockPos.x, blockPos.y, blockPos.z);
metadata[i] = chunk.getMetadata(blockPos.x, blockPos.y, blockPos.z);
i++;
}
}
}
Vector3i dimensions = new Vector3i(
(blockEnd.x - blockStart.x),
(blockEnd.y - blockStart.y),
(blockEnd.z - blockStart.z)
);
Vector3i dimensions = new Vector3i(dimX, dimY, dimZ);
BlockFab fab = BlockFab.create(dimensions, types, metadata);
return fab;

View File

@ -217,7 +217,7 @@ public class ProceduralChunkGenerator implements ChunkGenerator {
values[x][y][z] = voxel.type;
}
//apply macro data
if(this.applyMacroData(macroData, realX, realY, realZ, voxel)){
if(macroData != null && this.applyMacroData(macroData, realX, realY, realZ, voxel)){
weights[x][y][z] = voxel.weight;
values[x][y][z] = voxel.type;
}

View File

@ -306,7 +306,10 @@ public class ServerTerrainManager {
}
//generate if it does not exist
if(returnedChunk == null){
List<MacroObject> objects = this.macroData.getNearbyObjects(ServerWorldData.convertChunkToRealSpace(worldX, worldY, worldZ));
List<MacroObject> objects = null;
if(macroData != null){
objects = this.macroData.getNearbyObjects(ServerWorldData.convertChunkToRealSpace(worldX, worldY, worldZ));
}
returnedChunk = chunkGenerator.generateChunk(objects, worldX, worldY, worldZ, ChunkData.NO_STRIDE);
}
this.chunkCache.add(worldX, worldY, worldZ, ChunkData.NO_STRIDE, returnedChunk);
@ -354,7 +357,10 @@ public class ServerTerrainManager {
*/
public void getChunkAsync(int worldX, int worldY, int worldZ, int stride, Consumer<ServerTerrainChunk> onLoad){
Globals.profiler.beginAggregateCpuSample("ServerTerrainManager.getChunkAsync");
List<MacroObject> objects = this.macroData.getNearbyObjects(ServerWorldData.convertChunkToRealSpace(worldX, worldY, worldZ));
List<MacroObject> objects = null;
if(this.macroData != null){
objects = this.macroData.getNearbyObjects(ServerWorldData.convertChunkToRealSpace(worldX, worldY, worldZ));
}
chunkExecutorService.submit(new ChunkGenerationThread(objects, chunkDiskMap, chunkCache, chunkGenerator, worldX, worldY, worldZ, stride, onLoad));
Globals.profiler.endCpuSample();
}