2022-06-12 09:45:23 +08:00
|
|
|
import { RGBAColours } from '../src/colour';
|
2022-09-11 02:11:13 +08:00
|
|
|
import { ASSERT } from '../src/util/error_util';
|
2022-09-17 19:00:30 +08:00
|
|
|
import { Vector3 } from '../src/vector';
|
|
|
|
import { VoxelMesh } from '../src/voxel_mesh';
|
|
|
|
import { TEST_PREAMBLE } from './preamble';
|
2022-04-17 07:32:13 +08:00
|
|
|
|
|
|
|
test('Voxel neighbours', () => {
|
2022-09-17 19:00:30 +08:00
|
|
|
TEST_PREAMBLE();
|
|
|
|
|
2022-06-19 10:28:06 +08:00
|
|
|
const voxelMesh = new VoxelMesh({
|
|
|
|
voxelOverlapRule: 'first',
|
2022-09-12 00:57:21 +08:00
|
|
|
enableAmbientOcclusion: true,
|
2022-09-11 02:11:13 +08:00
|
|
|
|
2022-06-19 10:28:06 +08:00
|
|
|
});
|
2023-04-16 08:12:31 +08:00
|
|
|
voxelMesh.addVoxel(new Vector3(0, 0, 0), RGBAColours.WHITE);
|
|
|
|
voxelMesh.addVoxel(new Vector3(1, 1, 0), RGBAColours.WHITE);
|
|
|
|
voxelMesh.calculateNeighbours();
|
|
|
|
|
|
|
|
expect(voxelMesh.hasNeighbour(new Vector3(0, 0, 0), new Vector3(1, 1, 0))).toBe(true);
|
|
|
|
expect(voxelMesh.hasNeighbour(new Vector3(0, 0, 0), new Vector3(-1, -1, 0))).toBe(false);
|
|
|
|
expect(voxelMesh.hasNeighbour(new Vector3(1, 1, 0), new Vector3(-1, -1, 0))).toBe(true);
|
|
|
|
expect(voxelMesh.hasNeighbour(new Vector3(1, 1, 0), new Vector3(1, 1, 0))).toBe(false);
|
2022-04-17 07:32:13 +08:00
|
|
|
});
|
2022-06-19 10:28:06 +08:00
|
|
|
|
|
|
|
test('Add voxel', () => {
|
|
|
|
const voxelMesh = new VoxelMesh({
|
|
|
|
voxelOverlapRule: 'first',
|
2022-09-12 00:57:21 +08:00
|
|
|
enableAmbientOcclusion: true,
|
2022-06-19 10:28:06 +08:00
|
|
|
});
|
|
|
|
|
2022-07-15 00:59:35 +08:00
|
|
|
voxelMesh.addVoxel(new Vector3(1, 2, 3), RGBAColours.RED);
|
2022-06-19 10:28:06 +08:00
|
|
|
|
|
|
|
expect(voxelMesh.isVoxelAt(new Vector3(1, 2, 3))).toBe(true);
|
|
|
|
expect(voxelMesh.getVoxelCount()).toBe(1);
|
|
|
|
const voxel = voxelMesh.getVoxelAt(new Vector3(1, 2, 3));
|
|
|
|
expect(voxel).toBeDefined(); ASSERT(voxel);
|
|
|
|
expect(voxel.position.equals(new Vector3(1, 2, 3))).toBe(true);
|
2022-07-15 00:59:35 +08:00
|
|
|
expect(voxel.colour).toEqual(RGBAColours.RED);
|
2022-06-19 10:28:06 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Voxel overlap first', () => {
|
|
|
|
const voxelMesh = new VoxelMesh({
|
|
|
|
voxelOverlapRule: 'first',
|
2022-09-12 00:57:21 +08:00
|
|
|
enableAmbientOcclusion: false,
|
2022-06-19 10:28:06 +08:00
|
|
|
});
|
|
|
|
|
2022-07-15 00:59:35 +08:00
|
|
|
voxelMesh.addVoxel(new Vector3(1, 2, 3), RGBAColours.RED);
|
|
|
|
voxelMesh.addVoxel(new Vector3(1, 2, 3), RGBAColours.BLUE);
|
2022-06-19 10:28:06 +08:00
|
|
|
|
2022-07-15 00:59:35 +08:00
|
|
|
expect(voxelMesh.getVoxelAt(new Vector3(1, 2, 3))?.colour).toEqual(RGBAColours.RED);
|
2022-06-19 10:28:06 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Voxel overlap average', () => {
|
|
|
|
const voxelMesh = new VoxelMesh({
|
|
|
|
voxelOverlapRule: 'average',
|
2022-09-12 00:57:21 +08:00
|
|
|
enableAmbientOcclusion: false,
|
2022-06-19 10:28:06 +08:00
|
|
|
});
|
|
|
|
|
2022-07-15 00:59:35 +08:00
|
|
|
voxelMesh.addVoxel(new Vector3(1, 2, 3), { r: 1.0, g: 0.5, b: 0.25, a: 1.0 });
|
|
|
|
voxelMesh.addVoxel(new Vector3(1, 2, 3), { r: 0.0, g: 0.5, b: 0.75, a: 1.0 });
|
2022-06-19 10:28:06 +08:00
|
|
|
|
2022-09-12 00:57:21 +08:00
|
|
|
expect(voxelMesh.getVoxelAt(new Vector3(1, 2, 3))?.colour).toEqual({ r: 0.5, g: 0.5, b: 0.5, a: 1.0 });
|
2022-06-19 10:28:06 +08:00
|
|
|
});
|