diff --git a/src/exporters/exporters.ts b/src/exporters/exporters.ts index 0449af6..6ca3911 100644 --- a/src/exporters/exporters.ts +++ b/src/exporters/exporters.ts @@ -1,4 +1,5 @@ import { IExporter } from './base_exporter'; +import { IndexedJSONExporter } from './indexed_json_exporter '; import { Litematic } from './litematic_exporter'; import { NBTExporter } from './nbt_exporter'; import { SchemExporter } from './schem_exporter'; @@ -10,7 +11,8 @@ export type TExporters = 'litematic' | 'schem' | 'nbt' | - 'uncompressed_json'; + 'uncompressed_json' | + 'indexed_json'; export class ExporterFactory { public static GetExporter(voxeliser: TExporters): IExporter { @@ -25,6 +27,8 @@ export class ExporterFactory { return new NBTExporter(); case 'uncompressed_json': return new UncompressedJSONExporter(); + case 'indexed_json': + return new IndexedJSONExporter(); } } } diff --git a/src/exporters/indexed_json_exporter .ts b/src/exporters/indexed_json_exporter .ts new file mode 100644 index 0000000..94edcaf --- /dev/null +++ b/src/exporters/indexed_json_exporter .ts @@ -0,0 +1,39 @@ +import { BlockMesh } from '../block_mesh'; +import { IExporter } from './base_exporter'; + +export class IndexedJSONExporter extends IExporter { + public override getFormatFilter() { + return { + name: 'Indexed JSON', + extension: 'json', + }; + } + + public override export(blockMesh: BlockMesh): Buffer { + const blocks = blockMesh.getBlocks(); + + const blocksUsed = blockMesh.getBlockPalette(); + const blockToIndex = new Map(); + const indexToBlock = new Map(); + for (let i = 0; i < blocksUsed.length; ++i) { + blockToIndex.set(blocksUsed[i], i); + indexToBlock.set(i, blocksUsed[i]); + } + + const blockArray = new Array>(); + + // Serialise all block except for the last one. + for (let i = 0; i < blocks.length; ++i) { + const block = blocks[i]; + const pos = block.voxel.position; + blockArray.push([pos.x, pos.y, pos.z, blockToIndex.get(block.blockInfo.name)!]); + } + + const json = JSON.stringify({ + blocks: Object.fromEntries(indexToBlock), + xyzi: blockArray, + }); + + return Buffer.from(json); + } +} diff --git a/src/importers/gltf_loader.ts b/src/importers/gltf_loader.ts index 5a36080..0428ade 100644 --- a/src/importers/gltf_loader.ts +++ b/src/importers/gltf_loader.ts @@ -85,12 +85,31 @@ export class GltfLoader extends IImporter { canBeTextured: true, }); + materialNameToUse = materialName; + materialMade = true; + } else { + const diffuseColour: (number[] | undefined) = pbr.baseColorFactor; + + if (diffuseColour !== undefined) { + meshMaterials.set(materialName, { + type: MaterialType.solid, + colour: { + r: diffuseColour[0], + g: diffuseColour[1], + b: diffuseColour[2], + a: diffuseColour[3], + }, + needsAttention: false, + canBeTextured: false, + }); + } + materialNameToUse = materialName; materialMade = true; } } - const emissiveColour: (number[] | undefined) = primitive.material.emissiveFactor; + const emissiveColour: (number[] | undefined) = primitive.material.pbr; if (!materialMade && emissiveColour !== undefined) { meshMaterials.set(materialName, { type: MaterialType.solid, diff --git a/src/ui/components/vector.ts b/src/ui/components/vector.ts index 5a1d847..d768f68 100644 --- a/src/ui/components/vector.ts +++ b/src/ui/components/vector.ts @@ -76,6 +76,15 @@ export class VectorComponent extends ConfigComponent { this._registerAxis('y'); } this._registerAxis('z'); + + const elementX = UIUtil.getElementById(this._getValueId('x')) as HTMLInputElement; + const elementY = UIUtil.getElementById(this._getValueId('y')) as HTMLInputElement; + const elementZ = UIUtil.getElementById(this._getValueId('z')) as HTMLInputElement; + elementX.addEventListener('change', () => { + this.getValue().x = parseInt(elementX.value); + this.getValue().y = parseInt(elementY.value); + this.getValue().z = parseInt(elementZ.value); + }); } private _updateValue(e: MouseEvent) { diff --git a/src/ui/layout.ts b/src/ui/layout.ts index 70d8c4c..813b3b5 100644 --- a/src/ui/layout.ts +++ b/src/ui/layout.ts @@ -293,6 +293,10 @@ export class UI { displayText: 'Structure blocks (.nbt)', payload: 'nbt', }, + { + displayText: 'Indexed JSON (.json)', + payload: 'indexed_json', + }, { displayText: 'Uncompressed JSON (.json)', payload: 'uncompressed_json', @@ -565,7 +569,6 @@ export class UI { private _forEachComponent(action: EAction, functor: (component: ConfigComponent) => void) { const group = this._getGroup(action); - console.log(group); for (const elementName of group.componentOrder) { const element = group.components[elementName];