mirror of
https://github.com/LucasDower/ObjToSchematic.git
synced 2025-12-11 20:15:30 +01:00
Move benchmark.ts from Core to Sandbox
This commit is contained in:
parent
b2155aab78
commit
1b612d66ee
@ -1,64 +0,0 @@
|
||||
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';
|
||||
import { createReadableStream, createOtSTexture } from './util';
|
||||
import { TexturedMaterial } from 'Core/src/materials';
|
||||
import { ASSERT } from 'Core/src/util/error_util';
|
||||
|
||||
(async () => {
|
||||
const pathModel = path.join(__dirname, '../res/samples/skull.obj');
|
||||
const readableStream = createReadableStream(pathModel);
|
||||
|
||||
console.time('Mesh');
|
||||
const loader = new ObjImporter();
|
||||
const mesh = await loader.import(readableStream);
|
||||
console.timeEnd('Mesh');
|
||||
|
||||
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');
|
||||
|
||||
console.time('VoxelMesh');
|
||||
const converter = new OtS_VoxelMesh_Converter();
|
||||
converter.setConfig({
|
||||
constraintAxis: 'y',
|
||||
size: 380,
|
||||
multisampling: false,
|
||||
replaceMode: 'keep',
|
||||
});
|
||||
|
||||
const voxelMesh = converter.process(mesh);
|
||||
console.timeEnd('VoxelMesh');
|
||||
|
||||
|
||||
console.time('BlockMesh');
|
||||
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,
|
||||
});
|
||||
console.timeEnd('BlockMesh');
|
||||
|
||||
//console.log(mesh.getTriangleCount().toLocaleString(), 'triangles');
|
||||
//console.log(mesh.getMaterials());
|
||||
//console.log(voxelMesh.getVoxelCount().toLocaleString(), 'voxels');
|
||||
})();
|
||||
@ -35,10 +35,10 @@ export type OtS_FallableBehaviour = 'replace-falling' | 'replace-fallable' | 'pl
|
||||
|
||||
export type OtS_BlockMesh_ConverterConfig = {
|
||||
mode: OtS_BlockMesh_DataMode<RGBA>,
|
||||
dithering?: { mode: 'random' | 'ordered', magnitude: number },
|
||||
fallable?: OtS_FallableBehaviour,
|
||||
smoothness?: OtS_BlockMesh_DataMode<number> & { weight: number },
|
||||
resolution?: number, // [1, 255]
|
||||
dithering: { mode: 'random' | 'ordered', magnitude: number } | null,
|
||||
fallable: OtS_FallableBehaviour | null,
|
||||
smoothness: (OtS_BlockMesh_DataMode<number> & { weight: number }) | null,
|
||||
resolution: number, // [1, 255]
|
||||
}
|
||||
|
||||
export class OtS_BlockMesh_Converter {
|
||||
@ -47,6 +47,10 @@ export class OtS_BlockMesh_Converter {
|
||||
public constructor() {
|
||||
this._config = {
|
||||
mode: { type: 'per-block', data: BLOCK_DATA_DEFAULT.PER_BLOCK },
|
||||
resolution: 255,
|
||||
smoothness: null,
|
||||
dithering: null,
|
||||
fallable: 'replace-falling',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "echo \"No tests\" && exit 0"
|
||||
"test": "echo \"No tests\" && exit 0",
|
||||
"benchmark": "ts-node ./scripts/benchmark.ts"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
||||
57
Sandbox/scripts/benchmark.ts
Normal file
57
Sandbox/scripts/benchmark.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { OtS_Importer_Obj } from 'ots-core/src/importers/obj_importer';
|
||||
import { createOtSTexture, createReadableStream } from '../src/util';
|
||||
import { ASSERT } from 'ots-core/src/util/util';
|
||||
import { OtS_VoxelMesh_Converter } from 'ots-core/src/ots_voxel_mesh_converter';
|
||||
import { OtS_BlockMesh_Converter } from 'ots-core/src/ots_block_mesh_converter';
|
||||
import { BLOCK_DATA_DEFAULT } from 'ots-core/src/ots_block_data_default';
|
||||
|
||||
(async () => {
|
||||
const pathModel = path.join(__dirname, '../../Editor/res/samples/skull.obj');
|
||||
const readableStream = createReadableStream(pathModel);
|
||||
|
||||
console.time('Mesh');
|
||||
const loader = new OtS_Importer_Obj();
|
||||
const mesh = await loader.import(readableStream);
|
||||
console.timeEnd('Mesh');
|
||||
|
||||
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.mo({
|
||||
type: 'textured',
|
||||
name: 'skull',
|
||||
texture: texture,
|
||||
});
|
||||
ASSERT(success, 'Could not update skull material');
|
||||
*/
|
||||
|
||||
console.time('VoxelMesh');
|
||||
const voxelMeshConverter = new OtS_VoxelMesh_Converter();
|
||||
voxelMeshConverter.setConfig({
|
||||
constraintAxis: 'y',
|
||||
size: 380,
|
||||
replaceMode: 'keep',
|
||||
});
|
||||
|
||||
const voxelMesh = voxelMeshConverter.process(mesh);
|
||||
console.timeEnd('VoxelMesh');
|
||||
|
||||
|
||||
console.time('BlockMesh');
|
||||
const blockMeshConverter = new OtS_BlockMesh_Converter();
|
||||
blockMeshConverter.setConfig({
|
||||
mode: { type: 'per-block', data: BLOCK_DATA_DEFAULT.PER_BLOCK },
|
||||
dithering: null,
|
||||
smoothness: null,
|
||||
fallable: 'replace-falling',
|
||||
resolution: 128,
|
||||
});
|
||||
|
||||
const blockMesh = blockMeshConverter.process(voxelMesh);
|
||||
console.timeEnd('BlockMesh');
|
||||
})();
|
||||
@ -12,5 +12,5 @@
|
||||
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": ["src/**/*", "index.ts"]
|
||||
"include": ["src/**/*", "scripts/**/*", "index.ts"]
|
||||
}
|
||||
3
run_benchmark_core.sh
Executable file
3
run_benchmark_core.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
cd Sandbox
|
||||
npm run benchmark
|
||||
Loading…
x
Reference in New Issue
Block a user