mirror of
https://github.com/LucasDower/ObjToSchematic.git
synced 2025-03-07 14:06:41 +08:00
Refactoring importers, voxelisers, and exporters
This commit is contained in:
parent
48fd386294
commit
86f0bdcd4e
951
package-lock.json
generated
951
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,22 +1,20 @@
|
||||
import { UI } from './ui/layout';
|
||||
import { Schematic } from './exporters/schematic_exporter';
|
||||
import { Litematic } from './exporters/litematic_exporter';
|
||||
import { Renderer } from './renderer';
|
||||
import { Mesh } from './mesh';
|
||||
import { ObjImporter } from './importers/obj_importer';
|
||||
import { ASSERT, ColourSpace, AppError, LOG, LOG_ERROR, LOG_WARN, TIME_START, TIME_END } from './util';
|
||||
import { ASSERT, ColourSpace, AppError, LOG, LOG_ERROR, TIME_START, TIME_END } from './util';
|
||||
|
||||
import { remote } from 'electron';
|
||||
import { VoxelMesh, VoxelMeshParams } from './voxel_mesh';
|
||||
import { BlockMesh, BlockMeshParams, FallableBehaviour } from './block_mesh';
|
||||
import { TextureFiltering } from './texture';
|
||||
import { RayVoxeliser } from './voxelisers/ray-voxeliser';
|
||||
import { IVoxeliser } from './voxelisers/base-voxeliser';
|
||||
import { NormalCorrectedRayVoxeliser } from './voxelisers/normal-corrected-ray-voxeliser';
|
||||
import { BVHRayVoxeliser } from './voxelisers/bvh-ray-voxeliser';
|
||||
import { StatusHandler } from './status';
|
||||
import { UIMessageBuilder } from './ui/misc';
|
||||
import { OutputStyle } from './ui/elements/output';
|
||||
import { IExporter } from './exporters/base_exporter';
|
||||
import { TVoxelisers, VoxeliserFactory } from './voxelisers/voxelisers';
|
||||
import { ExporterFactory, TExporters } from './exporters/exporters';
|
||||
|
||||
/* eslint-disable */
|
||||
export enum EAction {
|
||||
@ -160,16 +158,8 @@ export class AppContext {
|
||||
enableAmbientOcclusion: uiElements.ambientOcclusion.getCachedValue() === 'on',
|
||||
};
|
||||
|
||||
const voxeliserID = uiElements.voxeliser.getCachedValue();
|
||||
let voxeliser: IVoxeliser;
|
||||
if (voxeliserID === 'raybased') {
|
||||
voxeliser = new RayVoxeliser();
|
||||
} else if (voxeliserID === 'bvhraybased') {
|
||||
voxeliser = new BVHRayVoxeliser();
|
||||
} else {
|
||||
ASSERT(voxeliserID === 'normalcorrectedraybased');
|
||||
voxeliser = new NormalCorrectedRayVoxeliser();
|
||||
}
|
||||
const voxeliserID: TVoxelisers = uiElements.voxeliser.getCachedValue();
|
||||
const voxeliser: IVoxeliser = VoxeliserFactory.GetVoxeliser(voxeliserID);
|
||||
|
||||
TIME_START('Voxelising');
|
||||
{
|
||||
@ -201,8 +191,8 @@ export class AppContext {
|
||||
}
|
||||
|
||||
private _export() {
|
||||
const exportFormat = this._ui.layout.export.elements.export.getCachedValue() as string;
|
||||
const exporter = (exportFormat === 'schematic') ? new Schematic() : new Litematic();
|
||||
const exporterID: TExporters = this._ui.layout.export.elements.export.getCachedValue();
|
||||
const exporter: IExporter = ExporterFactory.GetExporter(exporterID);
|
||||
|
||||
let filePath = remote.dialog.showSaveDialogSync({
|
||||
title: 'Save structure',
|
||||
@ -228,8 +218,4 @@ export class AppContext {
|
||||
public getLoadedMesh() {
|
||||
return this._loadedMesh;
|
||||
}
|
||||
|
||||
public addWarning(warning: string) {
|
||||
LOG_WARN(warning);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { BasicBlockAssigner, OrderedDitheringBlockAssigner } from './block_assigner';
|
||||
import { Voxel, VoxelMesh } from './voxel_mesh';
|
||||
import { BlockAtlas, BlockInfo } from './block_atlas';
|
||||
import { ColourSpace, AppError, ASSERT, RESOURCES_DIR, LOG } from './util';
|
||||
import { ColourSpace, AppError, ASSERT, RESOURCES_DIR } from './util';
|
||||
import { Renderer } from './renderer';
|
||||
import { AppConstants } from './constants';
|
||||
|
||||
|
19
src/exporters/exporters.ts
Normal file
19
src/exporters/exporters.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { IExporter } from './base_exporter';
|
||||
import { Schematic } from './schematic_exporter';
|
||||
import { Litematic } from './litematic_exporter';
|
||||
import { ASSERT } from '../util';
|
||||
|
||||
export type TExporters = 'schematic' | 'litematic';
|
||||
|
||||
export class ExporterFactory {
|
||||
public static GetExporter(voxeliser: TExporters): IExporter {
|
||||
switch (voxeliser) {
|
||||
case 'schematic':
|
||||
return new Schematic();
|
||||
case 'litematic':
|
||||
return new Litematic();
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { Mesh } from './mesh';
|
||||
import { Mesh } from '../mesh';
|
||||
|
||||
export abstract class IImporter {
|
||||
abstract parseFile(filePath: string): void;
|
16
src/importers/importers.ts
Normal file
16
src/importers/importers.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { ASSERT } from '../util';
|
||||
import { IImporter } from './base_importer';
|
||||
import { ObjImporter } from './obj_importer';
|
||||
|
||||
export type TImporters = 'obj';
|
||||
|
||||
export class ImporterFactor {
|
||||
public static GetImporter(importer: TImporters): IImporter {
|
||||
switch (importer) {
|
||||
case 'obj':
|
||||
return new ObjImporter();
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
import { IImporter } from '../importer';
|
||||
import { MaterialType, Mesh, SolidMaterial, TexturedMaterial, Tri } from '../mesh';
|
||||
import { Vector3 } from '../vector';
|
||||
import { UV, ASSERT, RGB, AppError, REGEX_NUMBER, RegExpBuilder, REGEX_NZ_ANY, LOG_ERROR } from '../util';
|
||||
@ -7,6 +6,7 @@ import { checkFractional, checkNaN } from '../math';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { StatusHandler } from '../status';
|
||||
import { IImporter } from './base_importer';
|
||||
|
||||
export class ObjImporter extends IImporter {
|
||||
private _vertices: Vector3[] = [];
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { UV, ASSERT, AppError, LOG } from './util';
|
||||
import { UV, ASSERT, AppError } from './util';
|
||||
import { RGB } from './util';
|
||||
|
||||
import * as fs from 'fs';
|
||||
|
@ -1,16 +1,16 @@
|
||||
import { LabelledElement } from './labelled_element';
|
||||
import { ASSERT } from '../../util';
|
||||
|
||||
export interface ComboBoxItem {
|
||||
id: string;
|
||||
export type ComboBoxItem<T> = {
|
||||
id: T;
|
||||
displayText: string;
|
||||
tooltip?: string;
|
||||
}
|
||||
|
||||
export class ComboBoxElement extends LabelledElement<string> {
|
||||
private _items: ComboBoxItem[];
|
||||
export class ComboBoxElement<T> extends LabelledElement<T> {
|
||||
private _items: ComboBoxItem<T>[];
|
||||
|
||||
public constructor(id: string, items: ComboBoxItem[]) {
|
||||
public constructor(id: string, items: ComboBoxItem<T>[]) {
|
||||
super(id);
|
||||
this._items = items;
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ import { ToolbarItemElement } from './elements/toolbar_item';
|
||||
import { EAppEvent } from '../event';
|
||||
import { MeshType, Renderer } from '../renderer';
|
||||
import { ArcballCamera } from '../camera';
|
||||
import { TVoxelisers } from '../voxelisers/voxelisers';
|
||||
import { TExporters } from '../exporters/exporters';
|
||||
|
||||
export interface Group {
|
||||
label: string;
|
||||
@ -57,10 +59,10 @@ export class UI {
|
||||
label: 'Build',
|
||||
elements: {
|
||||
'height': new SliderElement('Desired height', 3, 320, 0, 80, 1),
|
||||
'voxeliser': new ComboBoxElement('Algorithm', [
|
||||
{ id: 'bvhraybased', displayText: 'BVH Ray-based' },
|
||||
{ id: 'normalcorrectedraybased', displayText: 'NCRB' },
|
||||
{ id: 'raybased', displayText: 'Ray-based (legacy)' },
|
||||
'voxeliser': new ComboBoxElement<TVoxelisers>('Algorithm', [
|
||||
{ id: 'bvh-ray', displayText: 'BVH Ray-based' },
|
||||
{ id: 'ncrb', displayText: 'NCRB' },
|
||||
{ id: 'ray-based', displayText: 'Ray-based (legacy)' },
|
||||
]),
|
||||
'ambientOcclusion': new ComboBoxElement('Ambient occlusion', [
|
||||
{ id: 'on', displayText: 'On (recommended)' },
|
||||
@ -128,7 +130,7 @@ export class UI {
|
||||
'export': {
|
||||
label: 'Export',
|
||||
elements: {
|
||||
'export': new ComboBoxElement('File format', [
|
||||
'export': new ComboBoxElement<TExporters>('File format', [
|
||||
{ id: 'litematic', displayText: 'Litematic' },
|
||||
{ id: 'schematic', displayText: 'Schematic' },
|
||||
]),
|
||||
@ -483,8 +485,8 @@ export class UI {
|
||||
return this._uiDull[key];
|
||||
}
|
||||
|
||||
private _getTextureAtlases(): ComboBoxItem[] {
|
||||
const textureAtlases: ComboBoxItem[] = [];
|
||||
private _getTextureAtlases(): ComboBoxItem<string>[] {
|
||||
const textureAtlases: ComboBoxItem<string>[] = [];
|
||||
|
||||
fs.readdirSync(ATLASES_DIR).forEach((file) => {
|
||||
if (file.endsWith('.atlas')) {
|
||||
@ -498,8 +500,8 @@ export class UI {
|
||||
return textureAtlases;
|
||||
}
|
||||
|
||||
private _getBlockPalettes(): ComboBoxItem[] {
|
||||
const blockPalettes: ComboBoxItem[] = [];
|
||||
private _getBlockPalettes(): ComboBoxItem<string>[] {
|
||||
const blockPalettes: ComboBoxItem<string>[] = [];
|
||||
|
||||
fs.readdirSync(PALETTES_DIR).forEach((file) => {
|
||||
if (file.endsWith('.palette')) {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { UVTriangle, Triangle } from '../triangle';
|
||||
import { ASSERT, RGB, UV } from '../util';
|
||||
import { RGB, UV } from '../util';
|
||||
import { Vector3 } from '../vector';
|
||||
import { Mesh } from '../mesh';
|
||||
import { VoxelMesh, VoxelMeshParams} from '../voxel_mesh';
|
||||
import { VoxelMesh, VoxelMeshParams } from '../voxel_mesh';
|
||||
import { TextureFiltering } from '../texture';
|
||||
import { StatusHandler } from '../status';
|
||||
|
||||
|
22
src/voxelisers/voxelisers.ts
Normal file
22
src/voxelisers/voxelisers.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { IVoxeliser } from './base-voxeliser';
|
||||
import { BVHRayVoxeliser } from './bvh-ray-voxeliser';
|
||||
import { NormalCorrectedRayVoxeliser } from './normal-corrected-ray-voxeliser';
|
||||
import { RayVoxeliser } from './ray-voxeliser';
|
||||
import { ASSERT } from '../util';
|
||||
|
||||
export type TVoxelisers = 'bvh-ray' | 'ncrb' | 'ray-based';
|
||||
|
||||
export class VoxeliserFactory {
|
||||
public static GetVoxeliser(voxeliser: TVoxelisers): IVoxeliser {
|
||||
switch (voxeliser) {
|
||||
case 'bvh-ray':
|
||||
return new BVHRayVoxeliser();
|
||||
case 'ncrb':
|
||||
return new NormalCorrectedRayVoxeliser();
|
||||
case 'ray-based':
|
||||
return new RayVoxeliser();
|
||||
default:
|
||||
ASSERT(false, 'Unreachable');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user