2026-04-15 08:11:43 +02:00
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
|
|
|
|
|
|
import {
|
2026-04-15 09:13:17 +02:00
|
|
|
createConeBrush,
|
2026-04-15 08:11:43 +02:00
|
|
|
createRadialPrismBrush,
|
2026-04-15 09:13:17 +02:00
|
|
|
createTorusBrush,
|
2026-04-15 08:11:43 +02:00
|
|
|
createWedgeBrush
|
|
|
|
|
} from "../../src/document/brushes";
|
|
|
|
|
import { createPlayerStartEntity } from "../../src/entities/entity-instances";
|
|
|
|
|
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
|
|
|
|
import { buildRuntimeSceneFromDocument } from "../../src/runtime-three/runtime-scene-build";
|
|
|
|
|
|
|
|
|
|
describe("whitebox primitives runtime build", () => {
|
2026-04-15 09:13:17 +02:00
|
|
|
it("builds runtime meshes and colliders for wedge, cylinder, cone, and torus solids", () => {
|
2026-04-15 08:11:43 +02:00
|
|
|
const document = createEmptySceneDocument({ name: "Primitive Runtime" });
|
|
|
|
|
const wedge = createWedgeBrush({
|
|
|
|
|
id: "brush-wedge-runtime",
|
|
|
|
|
center: { x: -2, y: 1, z: 0 }
|
|
|
|
|
});
|
|
|
|
|
const cylinder = createRadialPrismBrush({
|
|
|
|
|
id: "brush-cylinder-runtime",
|
|
|
|
|
center: { x: 2, y: 1, z: 0 },
|
|
|
|
|
sideCount: 12
|
|
|
|
|
});
|
2026-04-15 09:13:17 +02:00
|
|
|
const cone = createConeBrush({
|
|
|
|
|
id: "brush-cone-runtime",
|
|
|
|
|
center: { x: 6, y: 1, z: 0 },
|
|
|
|
|
sideCount: 12
|
|
|
|
|
});
|
|
|
|
|
const torus = createTorusBrush({
|
|
|
|
|
id: "brush-torus-runtime",
|
|
|
|
|
center: { x: 10, y: 1, z: 0 },
|
|
|
|
|
majorSegmentCount: 16,
|
|
|
|
|
tubeSegmentCount: 8
|
|
|
|
|
});
|
2026-04-15 08:11:43 +02:00
|
|
|
const playerStart = createPlayerStartEntity({
|
|
|
|
|
id: "entity-player-start-primitives"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
document.brushes[wedge.id] = wedge;
|
|
|
|
|
document.brushes[cylinder.id] = cylinder;
|
2026-04-15 09:13:17 +02:00
|
|
|
document.brushes[cone.id] = cone;
|
|
|
|
|
document.brushes[torus.id] = torus;
|
2026-04-15 08:11:43 +02:00
|
|
|
document.entities[playerStart.id] = playerStart;
|
|
|
|
|
|
|
|
|
|
const runtimeScene = buildRuntimeSceneFromDocument(document);
|
|
|
|
|
|
|
|
|
|
expect(runtimeScene.brushes.map((brush) => brush.kind)).toEqual([
|
|
|
|
|
"wedge",
|
2026-04-15 09:13:17 +02:00
|
|
|
"radialPrism",
|
|
|
|
|
"cone",
|
|
|
|
|
"torus"
|
2026-04-15 08:11:43 +02:00
|
|
|
]);
|
2026-04-15 09:13:17 +02:00
|
|
|
expect(runtimeScene.colliders).toHaveLength(4);
|
2026-04-15 08:11:43 +02:00
|
|
|
expect(
|
|
|
|
|
runtimeScene.colliders.every(
|
|
|
|
|
(collider) =>
|
|
|
|
|
collider.kind === "trimesh" &&
|
|
|
|
|
collider.source === "brush" &&
|
|
|
|
|
collider.vertices.length > 0 &&
|
|
|
|
|
collider.indices.length > 0
|
|
|
|
|
)
|
|
|
|
|
).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
});
|