ObjToSchematic/tests/normal-corrected-ray-voxeliser.test.ts

65 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-03-24 06:43:36 +08:00
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';
2022-03-26 02:26:09 +08:00
test('Voxelise solid 2x2 cube', () => {
2022-03-24 06:43:36 +08:00
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,
enableAmbientOcclusion: false,
2022-03-24 06:43:36 +08:00
});
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()));
}
});