aether-shards/test/grid/VoxelManager.test.js

65 lines
1.9 KiB
JavaScript
Raw Normal View History

2025-12-16 23:52:58 +00:00
import { expect } from "@esm-bundle/chai";
import { VoxelManager } from "../../src/grid/VoxelManager.js";
import { VoxelGrid } from "../../src/grid/VoxelGrid.js";
2025-12-17 19:26:42 +00:00
import * as THREE from "three";
2025-12-16 23:52:58 +00:00
2025-12-17 19:26:42 +00:00
describe.skip("Phase 1: VoxelManager Rendering (WebGL)", () => {
2025-12-16 23:52:58 +00:00
let grid;
let scene;
let manager;
2025-12-17 19:26:42 +00:00
let renderer;
before(() => {
// 1. Setup a real WebGL Renderer (Headless)
const canvas = document.createElement("canvas");
// Force context creation to check support
const context = canvas.getContext("webgl");
if (!context) {
console.warn(
"WebGL not supported in this test environment. Skipping render checks."
);
this.skip();
}
2025-12-16 23:52:58 +00:00
2025-12-17 19:26:42 +00:00
renderer = new THREE.WebGLRenderer({ canvas, context });
2025-12-16 23:52:58 +00:00
});
2025-12-17 19:26:42 +00:00
beforeEach(() => {
grid = new VoxelGrid(4, 4, 4);
scene = new THREE.Scene();
manager = new VoxelManager(grid, scene, null);
2025-12-16 23:52:58 +00:00
});
2025-12-17 19:26:42 +00:00
it("CoA 1: init() should create a real InstancedMesh in the scene", () => {
grid.fill(1); // Fill with stone
manager.init();
2025-12-16 23:52:58 +00:00
2025-12-17 19:26:42 +00:00
const mesh = scene.children.find((c) => c.isInstancedMesh);
expect(mesh).to.exist;
expect(mesh.count).to.equal(64); // 4*4*4
2025-12-16 23:52:58 +00:00
});
2025-12-17 19:26:42 +00:00
it("CoA 2: update() should correctly position instances", () => {
grid.setCell(0, 0, 0, 1); // Only one block
manager.init();
2025-12-16 23:52:58 +00:00
2025-12-17 19:26:42 +00:00
const mesh = scene.children[0];
const matrix = new THREE.Matrix4();
mesh.getMatrixAt(0, matrix); // Get transform of first block
2025-12-16 23:52:58 +00:00
2025-12-17 19:26:42 +00:00
const position = new THREE.Vector3().setFromMatrixPosition(matrix);
2025-12-16 23:52:58 +00:00
2025-12-17 19:26:42 +00:00
expect(position.x).to.equal(0);
expect(position.y).to.equal(0);
expect(position.z).to.equal(0);
2025-12-16 23:52:58 +00:00
});
2025-12-17 19:26:42 +00:00
it("CoA 3: render loop should not crash", () => {
// Verify we can actually call render() without WebGL errors
const camera = new THREE.PerspectiveCamera();
manager.init();
2025-12-16 23:52:58 +00:00
2025-12-17 19:26:42 +00:00
expect(() => renderer.render(scene, camera)).to.not.throw();
2025-12-16 23:52:58 +00:00
});
});