mirror of
https://github.com/LucasDower/ObjToSchematic.git
synced 2025-04-12 15:00:22 +08:00
Added /examples/
directory
This commit is contained in:
parent
b72de9b439
commit
2fb092f835
71
Core/examples/pipeline.ts
Normal file
71
Core/examples/pipeline.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { ObjImporter } from "../src/importers/obj_importer";
|
||||
import { OtS_VoxelMesh_Converter } from '../src/ots_voxel_mesh_converter';
|
||||
import { BlockMesh } from '../src/block_mesh';
|
||||
import { PALETTE_ALL_RELEASE } from '../../Editor/res/palettes/all'; // TODO: Disallowed import
|
||||
import { ExporterFactory } from '../src/exporters/exporters';
|
||||
import { ASSERT } from '../src/util/error_util';
|
||||
import { createReadableStream, createOtSTexture } from '../tools/util'; // TODO: Disallowed import
|
||||
|
||||
(async () => {
|
||||
// 1. Import a mesh
|
||||
const pathModel = path.join(__dirname, '../res/samples/skull.obj');
|
||||
const readableStream = createReadableStream(pathModel);
|
||||
|
||||
const loader = new ObjImporter();
|
||||
const mesh = await loader.import(readableStream);
|
||||
|
||||
// 2. Assign materials
|
||||
const pathTexture = path.join(__dirname, '../res/samples/skull.jpg');
|
||||
const texture = createOtSTexture(pathTexture);
|
||||
ASSERT(texture !== undefined, `Could not parse ${pathTexture}`);
|
||||
|
||||
// Update the 'skull' material
|
||||
const success = mesh.setMaterial({
|
||||
type: 'textured',
|
||||
name: 'skull',
|
||||
texture: texture,
|
||||
});
|
||||
ASSERT(success, 'Could not update skull material');
|
||||
|
||||
// 3. Construct a voxel mesh from the mesh
|
||||
const converter = new OtS_VoxelMesh_Converter();
|
||||
converter.setConfig({
|
||||
constraintAxis: 'y',
|
||||
size: 380,
|
||||
multisampling: false,
|
||||
replaceMode: 'keep',
|
||||
});
|
||||
|
||||
const voxelMesh = converter.process(mesh);
|
||||
|
||||
// 4. Construct a block mesh from the block
|
||||
// NOTE: This will be placeholder and will be changed
|
||||
const blockMesh = BlockMesh.createFromVoxelMesh(voxelMesh, {
|
||||
atlasJSON: JSON.parse(fs.readFileSync(path.join(__dirname, '../res/atlases/vanilla.atlas'), 'utf8')),
|
||||
blockPalette: new Set(PALETTE_ALL_RELEASE),
|
||||
calculateLighting: false,
|
||||
contextualAveraging: true,
|
||||
dithering: 'off',
|
||||
ditheringMagnitude: 0,
|
||||
errorWeight: 0.02,
|
||||
resolution: 16,
|
||||
fallable: 'do-nothing',
|
||||
lightThreshold: 0,
|
||||
});
|
||||
|
||||
// 5. Export the block mesh to a file
|
||||
// NOTE: This will be placeholder and will be changed
|
||||
const exporter = ExporterFactory.GetExporter('litematic');
|
||||
const exportData = exporter.export(blockMesh.blockMesh);
|
||||
|
||||
if (exportData.type === 'single') {
|
||||
fs.writeFileSync('export' + exportData.extension, exportData.content);
|
||||
} else {
|
||||
exportData.regions.forEach((region) => {
|
||||
fs.writeFileSync(region.name + exportData.extension, region.content);
|
||||
});
|
||||
}
|
||||
})();
|
@ -1,9 +1,9 @@
|
||||
import { BlockMesh } from '../block_mesh';
|
||||
|
||||
export type TStructureRegion = { name: string, content: ArrayBuffer };
|
||||
export type TStructureRegion = { name: string, content: Uint8Array };
|
||||
|
||||
export type TStructureExport =
|
||||
| { type: 'single', extension: string, content: ArrayBuffer }
|
||||
| { type: 'single', extension: string, content: Uint8Array }
|
||||
| { type: 'multiple', extension: string, regions: TStructureRegion[] }
|
||||
|
||||
export abstract class IExporter {
|
||||
|
@ -16,7 +16,7 @@ export class NBTExporter extends IExporter {
|
||||
};
|
||||
}
|
||||
|
||||
private _processChunk(blockMesh: BlockMesh, min: Vector3, blockNameToIndex: Map<string, number>, palette: any): ArrayBuffer {
|
||||
private _processChunk(blockMesh: BlockMesh, min: Vector3, blockNameToIndex: Map<string, number>, palette: any): Uint8Array {
|
||||
const blocks: any[] = [];
|
||||
for (const block of blockMesh.getBlocks()) {
|
||||
const pos = block.voxel.position;
|
||||
|
Loading…
x
Reference in New Issue
Block a user