Merge pull request #165 from HannesGitH/main

add full model export alongside chunks for nbt
This commit is contained in:
Lucas Dower 2025-04-28 21:18:58 +01:00 committed by GitHub
commit 7497d13e39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,18 +19,25 @@ export class NBTExporter extends IExporter {
}; };
} }
private _processChunk(blockMesh: BlockMesh, min: Vector3, blockNameToIndex: Map<string, number>, palette: any): Buffer { private _processChunk(blockMesh: BlockMesh, minOr: Vector3 | "doNotConstrain", blockNameToIndex: Map<string, number>, palette: any) : Buffer {
const constrainToChunkSize = minOr !== "doNotConstrain";
const totalBounds = blockMesh.getVoxelMesh().getBounds();
const min = constrainToChunkSize ? minOr as Vector3 : totalBounds.min;
const blocks: any[] = []; const blocks: any[] = [];
for (const block of blockMesh.getBlocks()) { for (const block of blockMesh.getBlocks()) {
const pos = block.voxel.position; const pos = block.voxel.position;
const blockIndex = blockNameToIndex.get(block.blockInfo.name); const blockIndex = blockNameToIndex.get(block.blockInfo.name);
if (blockIndex !== undefined) { if (blockIndex !== undefined) {
if (pos.x >= min.x && pos.x < min.x + 48 && pos.y >= min.y && pos.y < min.y + 48 && pos.z >= min.z && pos.z < min.z + 48) { if (!constrainToChunkSize || pos.x >= min.x && pos.x < min.x + 48 && pos.y >= min.y && pos.y < min.y + 48 && pos.z >= min.z && pos.z < min.z + 48) {
const translatedPos = Vector3.sub(block.voxel.position, min); const translatedPos = Vector3.sub(block.voxel.position, min);
ASSERT(translatedPos.x >= 0 && translatedPos.x < 48);
ASSERT(translatedPos.y >= 0 && translatedPos.y < 48); if (constrainToChunkSize) {
ASSERT(translatedPos.z >= 0 && translatedPos.z < 48); ASSERT(translatedPos.x >= 0 && translatedPos.x < 48);
ASSERT(translatedPos.y >= 0 && translatedPos.y < 48);
ASSERT(translatedPos.z >= 0 && translatedPos.z < 48);
}
blocks.push({ blocks.push({
pos: { pos: {
@ -48,7 +55,7 @@ export class NBTExporter extends IExporter {
} }
} }
} }
ASSERT(blocks.length < 48 * 48 * 48); ASSERT(!constrainToChunkSize || blocks.length < 48 * 48 * 48);
const nbt: NBT = { const nbt: NBT = {
type: TagType.Compound, type: TagType.Compound,
@ -62,7 +69,7 @@ export class NBTExporter extends IExporter {
type: TagType.List, type: TagType.List,
value: { value: {
type: TagType.Int, type: TagType.Int,
value: [48, 48, 48], value: constrainToChunkSize ? [48, 48, 48] : totalBounds.getDimensions().add(1).toArray(),
}, },
}, },
palette: { palette: {
@ -119,6 +126,10 @@ export class NBTExporter extends IExporter {
} }
} }
const full_region_buffer = this._processChunk(blockMesh, "doNotConstrain", blockNameToIndex, palette);
regions.push({ content: full_region_buffer, name: `full` });
const out: TStructureExport = { const out: TStructureExport = {
type: 'multiple', type: 'multiple',
extension: '.nbt', extension: '.nbt',