Update material names and add tests for box face UVs and scene document migration

This commit is contained in:
2026-04-15 04:11:48 +02:00
parent 166c5e7dfa
commit 5a443e9da3
4 changed files with 80 additions and 4 deletions

View File

@@ -27,14 +27,14 @@ test("user can assign a face material through the UI and keep it through an auto
await page.getByTestId("face-button-posZ").click();
await page.getByTestId("material-button-starter-amber-grid").click();
await expect(page.getByTestId("selected-face-material-name")).toContainText("Amber Grid");
await expect(page.getByTestId("selected-face-material-name")).toContainText("Stacked Beige Terracotta Tile");
await page.waitForTimeout(400);
await page.reload();
await page.getByRole("button", { name: /Whitebox Box 1/ }).click();
await page.getByTestId("face-button-posZ").click();
await expect(page.getByTestId("selected-face-material-name")).toContainText("Amber Grid");
await expect(page.getByTestId("selected-face-material-name")).toContainText("Stacked Beige Terracotta Tile");
expect(pageErrors).toEqual([]);
expect(consoleErrors).toEqual([]);

View File

@@ -50,7 +50,7 @@ test("first-room workflow covers create, texture, autosave recovery, and run", a
await page.getByRole("button", { name: /Whitebox Box 1/ }).click();
await page.getByTestId("face-button-posZ").click();
await expect(page.getByTestId("selected-face-material-name")).toContainText("Amber Grid");
await expect(page.getByTestId("selected-face-material-name")).toContainText("Stacked Beige Terracotta Tile");
await page.getByTestId("enter-run-mode").click();

View File

@@ -2,7 +2,12 @@ import { BoxGeometry } from "three";
import { describe, expect, it } from "vitest";
import { createBoxBrush } from "../../src/document/brushes";
import { applyBoxBrushFaceUvsToGeometry, createFitToFaceBoxBrushFaceUvState, transformProjectedFaceUv } from "../../src/geometry/box-face-uvs";
import {
applyBoxBrushFaceUvsToGeometry,
createFitToFaceBoxBrushFaceUvState,
createFitToMaterialTileBoxBrushFaceUvState,
transformProjectedFaceUv
} from "../../src/geometry/box-face-uvs";
describe("box face UV projection", () => {
it("fit-to-face produces finite UVs normalized across the target face", () => {
@@ -73,4 +78,24 @@ describe("box face UV projection", () => {
expect(transformedUv.x).toBeCloseTo(2.5);
expect(transformedUv.y).toBeCloseTo(-0.25);
});
it("fits one authored material tile across the face bounds", () => {
const brush = createBoxBrush({
size: {
x: 5,
y: 2,
z: 4
}
});
const uvState = createFitToMaterialTileBoxBrushFaceUvState(brush, "posZ", {
x: 2.5,
y: 2.5
});
expect(uvState.scale).toEqual({
x: 0.5,
y: 1.25
});
});
});

View File

@@ -28,6 +28,7 @@ import {
PLAYER_START_NAVIGATION_MODE_SCENE_DOCUMENT_VERSION,
SCENE_EDITOR_PREFERENCES_SCENE_DOCUMENT_VERSION,
SCENE_TRANSITION_ENTITIES_SCENE_DOCUMENT_VERSION,
SCENE_TRANSITION_SEQUENCE_EFFECTS_SCENE_DOCUMENT_VERSION,
SCENE_DOCUMENT_VERSION,
SPATIAL_AUDIO_SCENE_DOCUMENT_VERSION,
STATIC_SIMPLE_MODEL_COLLIDERS_SCENE_DOCUMENT_VERSION,
@@ -1991,6 +1992,56 @@ describe("scene document JSON", () => {
});
});
it("migrates legacy starter material entries to the asset-backed PBR registry", () => {
const legacyDocument = createEmptySceneDocument({
name: "Legacy Material Registry Scene"
});
const legacyBrush = createBoxBrush({
id: "brush-legacy-materials",
size: {
x: 4,
y: 2,
z: 4
}
});
legacyBrush.faces.posZ.materialId = "starter-amber-grid";
legacyDocument.brushes[legacyBrush.id] = legacyBrush;
const migratedDocument = migrateSceneDocument({
...legacyDocument,
version: SCENE_TRANSITION_SEQUENCE_EFFECTS_SCENE_DOCUMENT_VERSION,
materials: {
...legacyDocument.materials,
"starter-amber-grid": {
id: "starter-amber-grid",
name: "Amber Grid",
pattern: "grid",
baseColorHex: "#d97706",
accentColorHex: "#fbbf24",
tags: ["warm", "grid"]
}
}
});
expect(migratedDocument.version).toBe(SCENE_DOCUMENT_VERSION);
expect(
migratedDocument.brushes["brush-legacy-materials"].faces.posZ.materialId
).toBe("starter-amber-grid");
expect(migratedDocument.materials["starter-amber-grid"]).toEqual(
expect.objectContaining({
id: "starter-amber-grid",
name: "Stacked Beige Terracotta Tile",
assetFolder: "stacked_beige_terracotta_tile_250x250",
previewImageName: "preview.webp",
sizeCm: {
width: 250,
height: 250
}
})
);
});
it("migrates slice 1.2 face materials to the PlayerStart-capable schema", () => {
const migratedDocument = migrateSceneDocument({
version: 3,