mirror of
https://github.com/LucasDower/ObjToSchematic.git
synced 2024-12-21 03:09:14 +08:00
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import { NormalCorrectedRayVoxeliser } from '../src/voxelisers/normal-corrected-ray-voxeliser';
|
|
import { ObjImporter } from '../src/importers/obj_importer';
|
|
import { TextureFiltering } from '../src/texture';
|
|
import { ASSERT, RGB } from '../src/util';
|
|
import { Vector3 } from '../src/vector';
|
|
|
|
import path from 'path';
|
|
|
|
test('Voxelise solid 2x2 cube', () => {
|
|
const importer = new ObjImporter();
|
|
importer.parseFile(path.join(__dirname, './data/cube.obj'));
|
|
const mesh = importer.toMesh();
|
|
mesh.processMesh();
|
|
|
|
const voxeliser = new NormalCorrectedRayVoxeliser();
|
|
const voxelMesh = voxeliser.voxelise(mesh, {
|
|
desiredHeight: 2,
|
|
useMultisampleColouring: false,
|
|
textureFiltering: TextureFiltering.Nearest,
|
|
});
|
|
|
|
const expectedVoxels = [
|
|
{
|
|
position: new Vector3(0, 1, 0),
|
|
colour: new RGB(0, 0, 1),
|
|
},
|
|
{
|
|
position: new Vector3(1, 1, 0),
|
|
colour: new RGB(0, 1, 0),
|
|
},
|
|
{
|
|
position: new Vector3(1, 1, 1),
|
|
colour: new RGB(1, 0, 0),
|
|
},
|
|
{
|
|
position: new Vector3(0, 1, 1),
|
|
colour: new RGB(1, 1, 1),
|
|
},
|
|
{
|
|
position: new Vector3(1, 0, 1),
|
|
colour: new RGB(1, 1, 0),
|
|
},
|
|
{
|
|
position: new Vector3(1, 0, 0),
|
|
colour: new RGB(0, 1, 1),
|
|
},
|
|
{
|
|
position: new Vector3(0, 0, 1),
|
|
colour: new RGB(0, 0, 0),
|
|
},
|
|
{
|
|
position: new Vector3(0, 0, 0),
|
|
colour: new RGB(1, 0, 1),
|
|
},
|
|
];
|
|
|
|
for (const expected of expectedVoxels) {
|
|
expect(voxelMesh.isVoxelAt(expected.position)).toBe(true);
|
|
const voxel = voxelMesh.getVoxelAt(expected.position);
|
|
expect(voxel).toBeDefined(); ASSERT(voxel);
|
|
expect(voxel.colour.toVector3().equals(expected.colour.toVector3()));
|
|
}
|
|
});
|