2022-03-23 05:15:09 +08:00
|
|
|
import { headlessConfig } from './headless-config';
|
2022-09-12 00:38:22 +08:00
|
|
|
import { AssignParams, ExportParams, ImportParams, VoxeliseParams } from '../src/worker_types';
|
|
|
|
import { WorkerClient } from '../src/worker_client';
|
|
|
|
import { StatusHandler } from '../src/status';
|
2022-09-12 01:04:31 +08:00
|
|
|
import { Logger, LOG_MAJOR } from '../src/util/log_util';
|
2022-07-09 08:42:42 +08:00
|
|
|
|
|
|
|
export type THeadlessConfig = {
|
2022-09-12 00:38:22 +08:00
|
|
|
import: ImportParams.Input,
|
|
|
|
voxelise: VoxeliseParams.Input,
|
|
|
|
assign: AssignParams.Input,
|
|
|
|
export: ExportParams.Input,
|
|
|
|
debug: {
|
2022-09-12 01:04:31 +08:00
|
|
|
showLogs: boolean,
|
|
|
|
showWarnings: boolean,
|
2022-09-12 00:38:22 +08:00
|
|
|
}
|
2022-07-09 08:42:42 +08:00
|
|
|
}
|
2022-03-23 05:15:09 +08:00
|
|
|
|
2022-09-12 00:57:21 +08:00
|
|
|
export function runHeadless() {
|
2022-09-12 01:04:31 +08:00
|
|
|
if (headlessConfig.debug.showLogs) {
|
|
|
|
Logger.Get.enableLOGMAJOR();
|
|
|
|
}
|
|
|
|
if (headlessConfig.debug.showWarnings) {
|
|
|
|
Logger.Get.enableLOGWARN();
|
|
|
|
}
|
|
|
|
|
2022-09-12 00:38:22 +08:00
|
|
|
const worker = WorkerClient.Get;
|
|
|
|
{
|
|
|
|
LOG_MAJOR('Importing...');
|
|
|
|
worker.import(headlessConfig.import);
|
|
|
|
StatusHandler.Get.dump().clear();
|
2022-08-25 04:22:49 +08:00
|
|
|
}
|
2022-09-12 00:38:22 +08:00
|
|
|
{
|
|
|
|
LOG_MAJOR('Voxelising...');
|
|
|
|
worker.voxelise(headlessConfig.voxelise);
|
|
|
|
StatusHandler.Get.dump().clear();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
LOG_MAJOR('Assigning...');
|
|
|
|
worker.assign(headlessConfig.assign);
|
|
|
|
StatusHandler.Get.dump().clear();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
LOG_MAJOR('Exporting...');
|
|
|
|
/**
|
|
|
|
* The OBJExporter is unique in that it uses the actual render buffer used by WebGL
|
|
|
|
* to create its data, in headless mode this render buffer is not created so we must
|
|
|
|
* generate it manually
|
|
|
|
*/
|
|
|
|
if (headlessConfig.export.exporter === 'obj') {
|
|
|
|
worker.renderVoxelMesh({
|
|
|
|
enableAmbientOcclusion: headlessConfig.voxelise.enableAmbientOcclusion,
|
|
|
|
desiredHeight: headlessConfig.voxelise.desiredHeight,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
worker.export(headlessConfig.export);
|
|
|
|
StatusHandler.Get.dump().clear();
|
|
|
|
}
|
2022-09-12 00:57:21 +08:00
|
|
|
}
|