forked from mirror/ObjToSchematic
Added uncompressed-json exporter
This commit is contained in:
parent
ffb2b78876
commit
97ea5146b0
@ -1,11 +1,16 @@
|
||||
import { ASSERT } from '../util/error_util';
|
||||
import { IExporter } from './base_exporter';
|
||||
import { Litematic } from './litematic_exporter';
|
||||
import { NBTExporter } from './nbt_exporter';
|
||||
import { SchemExporter } from './schem_exporter';
|
||||
import { Schematic } from './schematic_exporter';
|
||||
import { UncompressedJSONExporter } from './uncompressed_json_exporter';
|
||||
|
||||
export type TExporters = 'schematic' | 'litematic' | 'schem' | 'nbt';
|
||||
export type TExporters =
|
||||
'schematic' |
|
||||
'litematic' |
|
||||
'schem' |
|
||||
'nbt' |
|
||||
'uncompressed_json';
|
||||
|
||||
export class ExporterFactory {
|
||||
public static GetExporter(voxeliser: TExporters): IExporter {
|
||||
@ -18,8 +23,8 @@ export class ExporterFactory {
|
||||
return new SchemExporter();
|
||||
case 'nbt':
|
||||
return new NBTExporter();
|
||||
default:
|
||||
ASSERT(false);
|
||||
case 'uncompressed_json':
|
||||
return new UncompressedJSONExporter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
38
src/exporters/uncompressed_json_exporter.ts
Normal file
38
src/exporters/uncompressed_json_exporter.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { BlockMesh } from '../block_mesh';
|
||||
import { IExporter } from './base_exporter';
|
||||
|
||||
export class UncompressedJSONExporter extends IExporter {
|
||||
public override getFormatFilter() {
|
||||
return {
|
||||
name: 'Uncompressed JSON',
|
||||
extension: 'json',
|
||||
};
|
||||
}
|
||||
|
||||
public override export(blockMesh: BlockMesh): Buffer {
|
||||
const blocks = blockMesh.getBlocks();
|
||||
|
||||
const lines = new Array<string>();
|
||||
lines.push('[');
|
||||
|
||||
// Serialise all block except for the last one.
|
||||
for (let i = 0; i < blocks.length - 1; ++i) {
|
||||
const block = blocks[i];
|
||||
const pos = block.voxel.position;
|
||||
lines.push(`{ "x": ${pos.x}, "y": ${pos.y}, "z": ${pos.z}, "block_name": "${block.blockInfo.name}" },`);
|
||||
}
|
||||
|
||||
// Serialise the last block but don't include the comma at the end.
|
||||
{
|
||||
const block = blocks[blocks.length - 1];
|
||||
const pos = block.voxel.position;
|
||||
lines.push(`{ "x": ${pos.x}, "y": ${pos.y}, "z": ${pos.z}, "block_name": "${block.blockInfo.name}" }`);
|
||||
}
|
||||
|
||||
lines.push(']');
|
||||
|
||||
const json = lines.join('');
|
||||
|
||||
return Buffer.from(json);
|
||||
}
|
||||
}
|
@ -280,6 +280,10 @@ export class UI {
|
||||
displayText: 'Structure blocks (.nbt)',
|
||||
payload: 'nbt',
|
||||
},
|
||||
{
|
||||
displayText: 'Uncompressed JSON (.json)',
|
||||
payload: 'uncompressed_json',
|
||||
},
|
||||
])
|
||||
.setLabel('Exporter'),
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user