Added headless script, updated README

This commit is contained in:
Lucas Dower 2022-03-22 21:15:09 +00:00
parent a5a31e462c
commit 1116e6b34b
4 changed files with 117 additions and 1 deletions

View File

@ -35,7 +35,10 @@ You can either download the [latest release](https://github.com/LucasDower/ObjTo
You can create your own block palettes to fit the build you desire. When you select this palette, the generated structure will only use the blocks defined in your palette. To create a palette, list every block you want to use in `/tools/new-palette-blocks`. A list of every supported block can be found in `/tools/all-supported-blocks`. When your list is complete, run `npm run palette`, (make sure you run `run run build` before the first time you do this). If everything is successful, the next time you run the program you'll be able to select your new palette in the 'Block palette' dropdown.
#### Texture Atlases
If you play Minecraft with a resource pack, you will probably want to build your own texture atlas. This way the program will use the same resource pack for its visualisation and more accurate colour-to-block conversions can be made. To do this, run `npm run atlas` (make sure you run `run run build` before the first time you do this) and follow the instructions. If everything is successful, the next time you run the program you'll be able to select your resource pack in the 'Texture atlas' dropdown.
If you play Minecraft with a resource pack, you will probably want to build your own texture atlas. This way the program will use the same resource pack for its visualisation and more accurate colour-to-block conversions can be made. To do this, run `npm run atlas` (make sure you run `npm run build` before the first time you do this) and follow the instructions. If everything is successful, the next time you run the program you'll be able to select your resource pack in the 'Texture atlas' dropdown.
#### Headless
If you want to use the program without using the GUI, you can edit `/tools/headless-config.ts` and run `npm run headless` (make sure to run `npm run build` after **each time** you edit the `headless-config.ts`).
## Progress
[0.1](https://github.com/LucasDower/ObjToSchematic/releases/tag/v0.1-alpha)

View File

@ -14,6 +14,7 @@
"start": "npm run build && electron ./dist/src/main.js --enable-logging",
"atlas": "node ./dist/tools/build-atlas.js",
"palette": "node ./dist/tools/build-palette.js",
"headless": "node ./dist/tools/headless.js",
"export": "electron-packager . ObjToSchematic --platform=win32 --arch=x64"
},
"repository": {

25
tools/headless-config.ts Normal file
View File

@ -0,0 +1,25 @@
export const headlessConfig = {
import: {
absoluteFilePathLoad: 'C:/Users/<Username>/Desktop/MyModel.obj', // Must be an absolute path to the file (can be anywhere)
},
voxelise: {
voxeliser: 'rb', // 'raybased' / 'ncrb'
voxelMeshParams: {
desiredHeight: 105, // 5-320 inclusive
useMultisampleColouring: false,
textureFiltering: 'linear', // 'linear' / 'nearest'
},
},
palette: {
blockMeshParams: {
textureAtlas: 'vanilla', // Must be an atlas name that exists in /resources/atlases
blockPalette: 'all-supported', // Must be a palette name that exists in /resources/palettes
ditheringEnabled: true,
colourSpace: 'rgb', // 'rgb' / 'lab';
},
},
export: {
absoluteFilePathSave: 'C://Users//<Username>//AppData//Roaming//.minecraft//schematics', // Must be an absolute path to the file (can be anywhere)
exporter: 'schematic', // 'schematic' / 'litematic',
},
};

87
tools/headless.ts Normal file
View File

@ -0,0 +1,87 @@
import { Mesh } from '../src/mesh';
import { ObjImporter } from '../src/importers/obj_importer';
import { IVoxeliser } from '../src/voxelisers/base-voxeliser';
import { VoxelMesh, VoxelMeshParams } from '../src/voxel_mesh';
import { BlockMesh, BlockMeshParams } from '../src/block_mesh';
import { Exporter, Litematic, Schematic } from '../src/schematic';
import { NormalCorrectedRayVoxeliser } from '../src/voxelisers/normal-corrected-ray-voxeliser';
import { TextureFiltering } from '../src/texture';
import { ColourSpace } from '../src/util';
import { log, LogStyle } from './logging';
import { headlessConfig } from './headless-config';
import fs from 'fs';
void async function main() {
const mesh = _import({
absoluteFilePathLoad: headlessConfig.import.absoluteFilePathLoad,
});
const voxelMesh = _voxelise(mesh, {
voxeliser: new NormalCorrectedRayVoxeliser(),
voxelMeshParams: {
desiredHeight: headlessConfig.voxelise.voxelMeshParams.desiredHeight,
useMultisampleColouring: headlessConfig.voxelise.voxelMeshParams.useMultisampleColouring,
textureFiltering: headlessConfig.voxelise.voxelMeshParams.textureFiltering === 'linear' ? TextureFiltering.Linear : TextureFiltering.Nearest,
ambientOcclusionEnabled: false,
},
});
const blockMesh = _palette(voxelMesh, {
blockMeshParams: {
textureAtlas: headlessConfig.palette.blockMeshParams.textureAtlas,
blockPalette: headlessConfig.palette.blockMeshParams.blockPalette,
ditheringEnabled: headlessConfig.palette.blockMeshParams.ditheringEnabled,
colourSpace: headlessConfig.palette.blockMeshParams.colourSpace === 'rgb' ? ColourSpace.RGB : ColourSpace.LAB,
},
});
_export(blockMesh, {
absoluteFilePathSave: headlessConfig.export.absoluteFilePathSave,
exporter: headlessConfig.export.exporter === 'schematic' ? new Schematic() : new Litematic(),
});
log(LogStyle.Success, 'Finished!');
}();
interface ImportParams {
absoluteFilePathLoad: string;
}
interface VoxeliseParams {
voxeliser: IVoxeliser;
voxelMeshParams: VoxelMeshParams;
}
interface PaletteParams {
blockMeshParams: BlockMeshParams;
}
interface ExportParams {
absoluteFilePathSave: string;
exporter: Exporter;
}
function _import(params: ImportParams): Mesh {
log(LogStyle.Info, 'Importing...');
const importer = new ObjImporter();
importer.parseFile(params.absoluteFilePathLoad);
for (const warning of importer.getWarnings()) {
log(LogStyle.Warning, warning);
}
const mesh = importer.toMesh();
mesh.processMesh();
return mesh;
}
function _voxelise(mesh: Mesh, params: VoxeliseParams): VoxelMesh {
log(LogStyle.Info, 'Voxelising...');
const voxeliser: IVoxeliser = params.voxeliser;
return voxeliser.voxelise(mesh, params.voxelMeshParams);
}
function _palette(voxelMesh: VoxelMesh, params: PaletteParams): BlockMesh {
log(LogStyle.Info, 'Assigning blocks...');
return BlockMesh.createFromVoxelMesh(voxelMesh, params.blockMeshParams);
}
function _export(blockMesh: BlockMesh, params: ExportParams) {
log(LogStyle.Info, 'Exporting...');
params.exporter.export(blockMesh, params.absoluteFilePathSave);
}