auto-git:
[unlink] tests/domain/box-brush-face-editing.command.test.js [unlink] tests/domain/build-runtime-scene.test.js [unlink] tests/domain/create-box-brush.command.test.js [unlink] tests/domain/create-empty-scene-document.test.js [unlink] tests/domain/duplicate-selection.command.test.js [unlink] tests/domain/editor-store.test.js [unlink] tests/domain/entity.command.test.js [unlink] tests/domain/interaction-links.validation.test.js [unlink] tests/domain/model-import.test.js [unlink] tests/domain/model-instance.command.test.js [unlink] tests/domain/player-start.command.test.js [unlink] tests/domain/rapier-collision-world.test.js [unlink] tests/domain/runtime-audio-system.test.js [unlink] tests/domain/runtime-interaction-system.test.js [unlink] tests/domain/runtime-scene-validation.test.js [unlink] tests/domain/scene-document-validation.test.js [unlink] tests/domain/transform-session.command.test.js [unlink] tests/domain/world-settings.command.test.js [unlink] tests/domain/world-settings.test.js [unlink] tests/e2e/app-smoke.e2e.js [unlink] tests/e2e/box-brush-authoring.e2e.js [unlink] tests/e2e/entities-foundation.e2e.js [unlink] tests/e2e/face-material-authoring.e2e.js [unlink] tests/e2e/first-room-workflow.e2e.js [unlink] tests/e2e/import-draco-model-asset.e2e.js [unlink] tests/e2e/import-external-model-asset.e2e.js [unlink] tests/e2e/import-model-asset.e2e.js [unlink] tests/e2e/local-lights-and-background.e2e.js [unlink] tests/e2e/orthographic-views.e2e.js [unlink] tests/e2e/runner-v1.e2e.js [unlink] tests/e2e/runtime-click-interaction.e2e.js [unlink] tests/e2e/runtime-trigger-teleport.e2e.js [unlink] tests/e2e/viewport-quad-layout.e2e.js [unlink] tests/e2e/viewport-test-helpers.js [unlink] tests/e2e/whitebox-component-selection.e2e.js [unlink] tests/e2e/world-environment.e2e.js [unlink] tests/geometry/box-brush-geometry.test.js [unlink] tests/geometry/box-face-uvs.test.js [unlink] tests/geometry/model-instance-collider-generation.test.js [unlink] tests/helpers/model-collider-fixtures.js [unlink] tests/serialization/local-draft-storage.test.js [unlink] tests/serialization/project-asset-storage.test.js [unlink] tests/serialization/scene-document-json.test.js [unlink] tests/setup/vitest.setup.js [unlink] tests/unit/audio-assets.test.js [unlink] tests/unit/entity-instances.test.js [unlink] tests/unit/package-scripts.test.js [unlink] tests/unit/transform-foundation.integration.test.js [unlink] tests/unit/viewport-canvas.test.js [unlink] tests/unit/viewport-entity-markers.test.js [unlink] tests/unit/viewport-focus.test.js [unlink] tests/unit/viewport-layout.test.js [unlink] tests/unit/viewport-view-modes.test.js
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createEditorStore } from "../../src/app/editor-store";
|
||||
import { createCreateBoxBrushCommand } from "../../src/commands/create-box-brush-command";
|
||||
import { createSetBoxBrushFaceMaterialCommand } from "../../src/commands/set-box-brush-face-material-command";
|
||||
import { createSetBoxBrushFaceUvStateCommand } from "../../src/commands/set-box-brush-face-uv-state-command";
|
||||
describe("box brush face editing commands", () => {
|
||||
it("applies a material to one box face and supports undo/redo", () => {
|
||||
const store = createEditorStore();
|
||||
store.executeCommand(createCreateBoxBrushCommand());
|
||||
const createdBrush = Object.values(store.getState().document.brushes)[0];
|
||||
store.executeCommand(createSetBoxBrushFaceMaterialCommand({
|
||||
brushId: createdBrush.id,
|
||||
faceId: "posZ",
|
||||
materialId: "starter-amber-grid"
|
||||
}));
|
||||
expect(store.getState().document.brushes[createdBrush.id].faces.posZ.materialId).toBe("starter-amber-grid");
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "brushFace",
|
||||
brushId: createdBrush.id,
|
||||
faceId: "posZ"
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.brushes[createdBrush.id].faces.posZ.materialId).toBeNull();
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.brushes[createdBrush.id].faces.posZ.materialId).toBe("starter-amber-grid");
|
||||
});
|
||||
it("updates face UV state through an undoable command", () => {
|
||||
const store = createEditorStore();
|
||||
store.executeCommand(createCreateBoxBrushCommand());
|
||||
const createdBrush = Object.values(store.getState().document.brushes)[0];
|
||||
store.executeCommand(createSetBoxBrushFaceUvStateCommand({
|
||||
brushId: createdBrush.id,
|
||||
faceId: "posY",
|
||||
uvState: {
|
||||
offset: {
|
||||
x: 0.5,
|
||||
y: -0.25
|
||||
},
|
||||
scale: {
|
||||
x: 0.25,
|
||||
y: 0.5
|
||||
},
|
||||
rotationQuarterTurns: 1,
|
||||
flipU: true,
|
||||
flipV: false
|
||||
},
|
||||
label: "Adjust top face UVs"
|
||||
}));
|
||||
expect(store.getState().document.brushes[createdBrush.id].faces.posY.uv).toEqual({
|
||||
offset: {
|
||||
x: 0.5,
|
||||
y: -0.25
|
||||
},
|
||||
scale: {
|
||||
x: 0.25,
|
||||
y: 0.5
|
||||
},
|
||||
rotationQuarterTurns: 1,
|
||||
flipU: true,
|
||||
flipV: false
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.brushes[createdBrush.id].faces.posY.uv).toEqual({
|
||||
offset: {
|
||||
x: 0,
|
||||
y: 0
|
||||
},
|
||||
scale: {
|
||||
x: 1,
|
||||
y: 1
|
||||
},
|
||||
rotationQuarterTurns: 0,
|
||||
flipU: false,
|
||||
flipV: false
|
||||
});
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.brushes[createdBrush.id].faces.posY.uv.rotationQuarterTurns).toBe(1);
|
||||
expect(store.getState().document.brushes[createdBrush.id].faces.posY.uv.flipU).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,675 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { BoxGeometry } from "three";
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { createPointLightEntity, createInteractableEntity, createPlayerStartEntity, createSoundEmitterEntity, createSpotLightEntity, createTeleportTargetEntity, createTriggerVolumeEntity } from "../../src/entities/entity-instances";
|
||||
import { createTeleportPlayerInteractionLink, createToggleVisibilityInteractionLink } from "../../src/interactions/interaction-links";
|
||||
import { createModelInstance } from "../../src/assets/model-instances";
|
||||
import { createProjectAssetStorageKey } from "../../src/assets/project-assets";
|
||||
import { buildRuntimeSceneFromDocument } from "../../src/runtime-three/runtime-scene-build";
|
||||
import { createFixtureLoadedModelAssetFromGeometry } from "../helpers/model-collider-fixtures";
|
||||
describe("buildRuntimeSceneFromDocument", () => {
|
||||
it("builds runtime brush data, colliders, and an authored player spawn from the document", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-room-floor",
|
||||
center: {
|
||||
x: 0,
|
||||
y: -0.5,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 8,
|
||||
y: 1,
|
||||
z: 8
|
||||
}
|
||||
});
|
||||
brush.faces.posY.materialId = "starter-concrete-checker";
|
||||
const playerStart = createPlayerStartEntity({
|
||||
id: "entity-player-start-main",
|
||||
position: {
|
||||
x: 2,
|
||||
y: 0,
|
||||
z: -1
|
||||
},
|
||||
yawDegrees: 90,
|
||||
collider: {
|
||||
mode: "box",
|
||||
eyeHeight: 1.4,
|
||||
capsuleRadius: 0.3,
|
||||
capsuleHeight: 1.8,
|
||||
boxSize: {
|
||||
x: 0.8,
|
||||
y: 1.6,
|
||||
z: 0.7
|
||||
}
|
||||
}
|
||||
});
|
||||
const soundEmitter = createSoundEmitterEntity({
|
||||
id: "entity-sound-lobby",
|
||||
position: {
|
||||
x: -1,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
audioAssetId: "asset-audio-lobby",
|
||||
volume: 0.75,
|
||||
refDistance: 8,
|
||||
maxDistance: 24,
|
||||
autoplay: true,
|
||||
loop: false
|
||||
});
|
||||
const triggerVolume = createTriggerVolumeEntity({
|
||||
id: "entity-trigger-door",
|
||||
position: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 2
|
||||
},
|
||||
size: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 1
|
||||
},
|
||||
triggerOnEnter: true,
|
||||
triggerOnExit: false
|
||||
});
|
||||
const teleportTarget = createTeleportTargetEntity({
|
||||
id: "entity-teleport-target-main",
|
||||
position: {
|
||||
x: 6,
|
||||
y: 0,
|
||||
z: -3
|
||||
},
|
||||
yawDegrees: 270
|
||||
});
|
||||
const interactable = createInteractableEntity({
|
||||
id: "entity-interactable-console",
|
||||
position: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 1
|
||||
},
|
||||
radius: 1.5,
|
||||
prompt: "Use Console",
|
||||
enabled: true
|
||||
});
|
||||
const pointLight = createPointLightEntity({
|
||||
id: "entity-point-light-main",
|
||||
position: {
|
||||
x: 2,
|
||||
y: 3,
|
||||
z: 1
|
||||
}
|
||||
});
|
||||
const spotLight = createSpotLightEntity({
|
||||
id: "entity-spot-light-main",
|
||||
position: {
|
||||
x: -2,
|
||||
y: 4,
|
||||
z: 0
|
||||
},
|
||||
direction: {
|
||||
x: 0.2,
|
||||
y: -1,
|
||||
z: 0.1
|
||||
}
|
||||
});
|
||||
const imageAsset = {
|
||||
id: "asset-background-panorama",
|
||||
kind: "image",
|
||||
sourceName: "skybox-panorama.svg",
|
||||
mimeType: "image/svg+xml",
|
||||
storageKey: createProjectAssetStorageKey("asset-background-panorama"),
|
||||
byteLength: 2048,
|
||||
metadata: {
|
||||
kind: "image",
|
||||
width: 512,
|
||||
height: 256,
|
||||
hasAlpha: false,
|
||||
warnings: []
|
||||
}
|
||||
};
|
||||
const audioAsset = {
|
||||
id: "asset-audio-lobby",
|
||||
kind: "audio",
|
||||
sourceName: "lobby-loop.ogg",
|
||||
mimeType: "audio/ogg",
|
||||
storageKey: createProjectAssetStorageKey("asset-audio-lobby"),
|
||||
byteLength: 4096,
|
||||
metadata: {
|
||||
kind: "audio",
|
||||
durationSeconds: 3.25,
|
||||
channelCount: 2,
|
||||
sampleRateHz: 48000,
|
||||
warnings: []
|
||||
}
|
||||
};
|
||||
const modelAsset = {
|
||||
id: "asset-model-triangle",
|
||||
kind: "model",
|
||||
sourceName: "tiny-triangle.gltf",
|
||||
mimeType: "model/gltf+json",
|
||||
storageKey: createProjectAssetStorageKey("asset-model-triangle"),
|
||||
byteLength: 36,
|
||||
metadata: {
|
||||
kind: "model",
|
||||
format: "gltf",
|
||||
sceneName: "Fixture Triangle Scene",
|
||||
nodeCount: 2,
|
||||
meshCount: 1,
|
||||
materialNames: ["Fixture Material"],
|
||||
textureNames: [],
|
||||
animationNames: [],
|
||||
boundingBox: {
|
||||
min: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
max: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 0
|
||||
}
|
||||
},
|
||||
warnings: []
|
||||
}
|
||||
};
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-triangle",
|
||||
assetId: modelAsset.id,
|
||||
position: {
|
||||
x: -2,
|
||||
y: 0,
|
||||
z: 4
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 90,
|
||||
z: 0
|
||||
},
|
||||
scale: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 2
|
||||
}
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument({ name: "Runtime Slice" }),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
},
|
||||
assets: {
|
||||
[audioAsset.id]: audioAsset,
|
||||
[modelAsset.id]: modelAsset,
|
||||
[imageAsset.id]: imageAsset
|
||||
},
|
||||
modelInstances: {
|
||||
[modelInstance.id]: modelInstance
|
||||
},
|
||||
entities: {
|
||||
[playerStart.id]: playerStart,
|
||||
[soundEmitter.id]: soundEmitter,
|
||||
[triggerVolume.id]: triggerVolume,
|
||||
[teleportTarget.id]: teleportTarget,
|
||||
[interactable.id]: interactable,
|
||||
[pointLight.id]: pointLight,
|
||||
[spotLight.id]: spotLight
|
||||
},
|
||||
interactionLinks: {
|
||||
"link-teleport": createTeleportPlayerInteractionLink({
|
||||
id: "link-teleport",
|
||||
sourceEntityId: triggerVolume.id,
|
||||
trigger: "enter",
|
||||
targetEntityId: teleportTarget.id
|
||||
}),
|
||||
"link-hide-brush": createToggleVisibilityInteractionLink({
|
||||
id: "link-hide-brush",
|
||||
sourceEntityId: triggerVolume.id,
|
||||
trigger: "exit",
|
||||
targetBrushId: brush.id,
|
||||
visible: false
|
||||
}),
|
||||
"link-click-teleport": createTeleportPlayerInteractionLink({
|
||||
id: "link-click-teleport",
|
||||
sourceEntityId: interactable.id,
|
||||
trigger: "click",
|
||||
targetEntityId: teleportTarget.id
|
||||
})
|
||||
}
|
||||
};
|
||||
document.world.background = {
|
||||
mode: "image",
|
||||
assetId: imageAsset.id,
|
||||
environmentIntensity: 0.75
|
||||
};
|
||||
document.world.ambientLight.intensity = 0.55;
|
||||
document.world.sunLight.direction = {
|
||||
x: -0.8,
|
||||
y: 1.2,
|
||||
z: 0.1
|
||||
};
|
||||
const runtimeScene = buildRuntimeSceneFromDocument(document);
|
||||
expect(runtimeScene.world).toEqual(document.world);
|
||||
expect(runtimeScene.world).not.toBe(document.world);
|
||||
expect(runtimeScene.world.sunLight.direction).not.toBe(document.world.sunLight.direction);
|
||||
expect(runtimeScene.brushes).toHaveLength(1);
|
||||
expect(runtimeScene.modelInstances).toEqual([
|
||||
{
|
||||
instanceId: "model-instance-triangle",
|
||||
assetId: "asset-model-triangle",
|
||||
name: undefined,
|
||||
position: {
|
||||
x: -2,
|
||||
y: 0,
|
||||
z: 4
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 90,
|
||||
z: 0
|
||||
},
|
||||
scale: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 2
|
||||
}
|
||||
}
|
||||
]);
|
||||
expect(runtimeScene.brushes[0].rotationDegrees).toEqual({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
});
|
||||
expect(runtimeScene.brushes[0].faces.posY.material?.id).toBe("starter-concrete-checker");
|
||||
expect(runtimeScene.colliders).toEqual([
|
||||
{
|
||||
kind: "box",
|
||||
source: "brush",
|
||||
brushId: "brush-room-floor",
|
||||
center: {
|
||||
x: 0,
|
||||
y: -0.5,
|
||||
z: 0
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 8,
|
||||
y: 1,
|
||||
z: 8
|
||||
},
|
||||
worldBounds: {
|
||||
min: {
|
||||
x: -4,
|
||||
y: -1,
|
||||
z: -4
|
||||
},
|
||||
max: {
|
||||
x: 4,
|
||||
y: 0,
|
||||
z: 4
|
||||
}
|
||||
}
|
||||
}
|
||||
]);
|
||||
expect(runtimeScene.sceneBounds).toEqual({
|
||||
min: {
|
||||
x: -4,
|
||||
y: -1,
|
||||
z: -4
|
||||
},
|
||||
max: {
|
||||
x: 4,
|
||||
y: 0,
|
||||
z: 4
|
||||
},
|
||||
center: {
|
||||
x: 0,
|
||||
y: -0.5,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 8,
|
||||
y: 1,
|
||||
z: 8
|
||||
}
|
||||
});
|
||||
expect(runtimeScene.entities).toEqual({
|
||||
playerStarts: [
|
||||
{
|
||||
entityId: "entity-player-start-main",
|
||||
position: {
|
||||
x: 2,
|
||||
y: 0,
|
||||
z: -1
|
||||
},
|
||||
yawDegrees: 90,
|
||||
collider: {
|
||||
mode: "box",
|
||||
eyeHeight: 1.4,
|
||||
size: {
|
||||
x: 0.8,
|
||||
y: 1.6,
|
||||
z: 0.7
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
soundEmitters: [
|
||||
{
|
||||
entityId: "entity-sound-lobby",
|
||||
position: {
|
||||
x: -1,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
audioAssetId: audioAsset.id,
|
||||
volume: 0.75,
|
||||
refDistance: 8,
|
||||
maxDistance: 24,
|
||||
autoplay: true,
|
||||
loop: false
|
||||
}
|
||||
],
|
||||
triggerVolumes: [
|
||||
{
|
||||
entityId: "entity-trigger-door",
|
||||
position: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 2
|
||||
},
|
||||
size: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 1
|
||||
},
|
||||
triggerOnEnter: true,
|
||||
triggerOnExit: true
|
||||
}
|
||||
],
|
||||
teleportTargets: [
|
||||
{
|
||||
entityId: "entity-teleport-target-main",
|
||||
position: {
|
||||
x: 6,
|
||||
y: 0,
|
||||
z: -3
|
||||
},
|
||||
yawDegrees: 270
|
||||
}
|
||||
],
|
||||
interactables: [
|
||||
{
|
||||
entityId: "entity-interactable-console",
|
||||
position: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 1
|
||||
},
|
||||
radius: 1.5,
|
||||
prompt: "Use Console",
|
||||
enabled: true
|
||||
}
|
||||
]
|
||||
});
|
||||
expect(runtimeScene.localLights).toEqual({
|
||||
pointLights: [
|
||||
{
|
||||
entityId: "entity-point-light-main",
|
||||
position: {
|
||||
x: 2,
|
||||
y: 3,
|
||||
z: 1
|
||||
},
|
||||
colorHex: "#ffffff",
|
||||
intensity: 1.25,
|
||||
distance: 8
|
||||
}
|
||||
],
|
||||
spotLights: [
|
||||
{
|
||||
entityId: "entity-spot-light-main",
|
||||
position: {
|
||||
x: -2,
|
||||
y: 4,
|
||||
z: 0
|
||||
},
|
||||
direction: {
|
||||
x: 0.2,
|
||||
y: -1,
|
||||
z: 0.1
|
||||
},
|
||||
colorHex: "#ffffff",
|
||||
intensity: 1.5,
|
||||
distance: 12,
|
||||
angleDegrees: 35
|
||||
}
|
||||
]
|
||||
});
|
||||
expect(runtimeScene.interactionLinks).toEqual([
|
||||
{
|
||||
id: "link-click-teleport",
|
||||
sourceEntityId: "entity-interactable-console",
|
||||
trigger: "click",
|
||||
action: {
|
||||
type: "teleportPlayer",
|
||||
targetEntityId: "entity-teleport-target-main"
|
||||
}
|
||||
},
|
||||
{
|
||||
id: "link-teleport",
|
||||
sourceEntityId: "entity-trigger-door",
|
||||
trigger: "enter",
|
||||
action: {
|
||||
type: "teleportPlayer",
|
||||
targetEntityId: "entity-teleport-target-main"
|
||||
}
|
||||
},
|
||||
{
|
||||
id: "link-hide-brush",
|
||||
sourceEntityId: "entity-trigger-door",
|
||||
trigger: "exit",
|
||||
action: {
|
||||
type: "toggleVisibility",
|
||||
targetBrushId: "brush-room-floor",
|
||||
visible: false
|
||||
}
|
||||
}
|
||||
]);
|
||||
expect(runtimeScene.playerStart).toEqual({
|
||||
entityId: "entity-player-start-main",
|
||||
position: {
|
||||
x: 2,
|
||||
y: 0,
|
||||
z: -1
|
||||
},
|
||||
yawDegrees: 90,
|
||||
collider: {
|
||||
mode: "box",
|
||||
eyeHeight: 1.4,
|
||||
size: {
|
||||
x: 0.8,
|
||||
y: 1.6,
|
||||
z: 0.7
|
||||
}
|
||||
}
|
||||
});
|
||||
expect(runtimeScene.playerCollider).toEqual({
|
||||
mode: "box",
|
||||
eyeHeight: 1.4,
|
||||
size: {
|
||||
x: 0.8,
|
||||
y: 1.6,
|
||||
z: 0.7
|
||||
}
|
||||
});
|
||||
expect(runtimeScene.spawn).toEqual({
|
||||
source: "playerStart",
|
||||
entityId: "entity-player-start-main",
|
||||
position: {
|
||||
x: 2,
|
||||
y: 0,
|
||||
z: -1
|
||||
},
|
||||
yawDegrees: 90
|
||||
});
|
||||
});
|
||||
it("builds a deterministic fallback spawn when no PlayerStart is authored", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-room-wall",
|
||||
center: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 6,
|
||||
y: 2,
|
||||
z: 6
|
||||
}
|
||||
});
|
||||
const runtimeScene = buildRuntimeSceneFromDocument({
|
||||
...createEmptySceneDocument({ name: "Fallback Runtime Scene" }),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
});
|
||||
expect(runtimeScene.playerStart).toBeNull();
|
||||
expect(runtimeScene.playerCollider).toEqual({
|
||||
mode: "capsule",
|
||||
radius: 0.3,
|
||||
height: 1.8,
|
||||
eyeHeight: 1.6
|
||||
});
|
||||
expect(runtimeScene.entities).toEqual({
|
||||
playerStarts: [],
|
||||
soundEmitters: [],
|
||||
triggerVolumes: [],
|
||||
teleportTargets: [],
|
||||
interactables: []
|
||||
});
|
||||
expect(runtimeScene.interactionLinks).toEqual([]);
|
||||
expect(runtimeScene.spawn).toEqual({
|
||||
source: "fallback",
|
||||
entityId: null,
|
||||
position: {
|
||||
x: 0,
|
||||
y: 2.1,
|
||||
z: 6
|
||||
},
|
||||
yawDegrees: 180
|
||||
});
|
||||
});
|
||||
it("blocks first-person runtime builds when PlayerStart is missing", () => {
|
||||
expect(() => buildRuntimeSceneFromDocument(createEmptySceneDocument({ name: "Missing Player Start" }), {
|
||||
navigationMode: "firstPerson"
|
||||
})).toThrow("First-person run requires an authored Player Start");
|
||||
});
|
||||
it("adds generated imported-model colliders to the runtime scene build", () => {
|
||||
const floorBrush = createBoxBrush({
|
||||
id: "brush-runtime-floor",
|
||||
center: {
|
||||
x: 0,
|
||||
y: -0.5,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 8,
|
||||
y: 1,
|
||||
z: 8
|
||||
}
|
||||
});
|
||||
const { asset, loadedAsset } = createFixtureLoadedModelAssetFromGeometry("asset-runtime-collider", new BoxGeometry(1, 2, 1));
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-runtime-collider",
|
||||
assetId: asset.id,
|
||||
position: {
|
||||
x: 2,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
collision: {
|
||||
mode: "static",
|
||||
visible: true
|
||||
}
|
||||
});
|
||||
const runtimeScene = buildRuntimeSceneFromDocument({
|
||||
...createEmptySceneDocument({ name: "Imported Collider Scene" }),
|
||||
assets: {
|
||||
[asset.id]: asset
|
||||
},
|
||||
brushes: {
|
||||
[floorBrush.id]: floorBrush
|
||||
},
|
||||
modelInstances: {
|
||||
[modelInstance.id]: modelInstance
|
||||
}
|
||||
}, {
|
||||
loadedModelAssets: {
|
||||
[asset.id]: loadedAsset
|
||||
}
|
||||
});
|
||||
expect(runtimeScene.colliders).toHaveLength(2);
|
||||
expect(runtimeScene.colliders[1]).toMatchObject({
|
||||
source: "modelInstance",
|
||||
instanceId: modelInstance.id,
|
||||
assetId: asset.id,
|
||||
kind: "trimesh",
|
||||
mode: "static",
|
||||
visible: true
|
||||
});
|
||||
expect(runtimeScene.sceneBounds?.max.y).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
it("preserves rotated whitebox box transforms for runner rendering and collision bounds", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-rotated-room",
|
||||
center: {
|
||||
x: 1.25,
|
||||
y: 1.5,
|
||||
z: -0.75
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 45,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 4
|
||||
}
|
||||
});
|
||||
const runtimeScene = buildRuntimeSceneFromDocument({
|
||||
...createEmptySceneDocument({ name: "Rotated Whitebox Scene" }),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
});
|
||||
expect(runtimeScene.brushes[0]).toMatchObject({
|
||||
center: brush.center,
|
||||
rotationDegrees: brush.rotationDegrees,
|
||||
size: brush.size
|
||||
});
|
||||
expect(runtimeScene.colliders[0]).toMatchObject({
|
||||
source: "brush",
|
||||
brushId: brush.id,
|
||||
center: brush.center,
|
||||
rotationDegrees: brush.rotationDegrees,
|
||||
size: brush.size
|
||||
});
|
||||
expect(runtimeScene.sceneBounds?.min.x).toBeCloseTo(-0.8713203436);
|
||||
expect(runtimeScene.sceneBounds?.max.x).toBeCloseTo(3.3713203436);
|
||||
expect(runtimeScene.sceneBounds?.min.z).toBeCloseTo(-2.8713203436);
|
||||
expect(runtimeScene.sceneBounds?.max.z).toBeCloseTo(1.3713203436);
|
||||
});
|
||||
});
|
||||
@@ -1,234 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createEditorStore } from "../../src/app/editor-store";
|
||||
import { createCreateBoxBrushCommand } from "../../src/commands/create-box-brush-command";
|
||||
import { createMoveBoxBrushCommand } from "../../src/commands/move-box-brush-command";
|
||||
import { createRotateBoxBrushCommand } from "../../src/commands/rotate-box-brush-command";
|
||||
import { createResizeBoxBrushCommand } from "../../src/commands/resize-box-brush-command";
|
||||
import { createSetBoxBrushNameCommand } from "../../src/commands/set-box-brush-name-command";
|
||||
describe("box brush commands", () => {
|
||||
it("creates a canonical box brush and supports undo/redo", () => {
|
||||
const store = createEditorStore();
|
||||
store.executeCommand(createCreateBoxBrushCommand({
|
||||
center: {
|
||||
x: 1.2,
|
||||
y: 1.1,
|
||||
z: -0.6
|
||||
},
|
||||
size: {
|
||||
x: 2.2,
|
||||
y: 2.7,
|
||||
z: 3.6
|
||||
}
|
||||
}));
|
||||
const brush = Object.values(store.getState().document.brushes)[0];
|
||||
expect(brush).toBeDefined();
|
||||
expect(brush.kind).toBe("box");
|
||||
expect(brush.center).toEqual({
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: -1
|
||||
});
|
||||
expect(brush.rotationDegrees).toEqual({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
});
|
||||
expect(brush.size).toEqual({
|
||||
x: 2,
|
||||
y: 3,
|
||||
z: 4
|
||||
});
|
||||
expect(Object.keys(brush.faces)).toEqual(["posX", "negX", "posY", "negY", "posZ", "negZ"]);
|
||||
expect(brush.faces.posX).toEqual({
|
||||
materialId: null,
|
||||
uv: {
|
||||
offset: {
|
||||
x: 0,
|
||||
y: 0
|
||||
},
|
||||
scale: {
|
||||
x: 1,
|
||||
y: 1
|
||||
},
|
||||
rotationQuarterTurns: 0,
|
||||
flipU: false,
|
||||
flipV: false
|
||||
}
|
||||
});
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "brushes",
|
||||
ids: [brush.id]
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.brushes).toEqual({});
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.brushes[brush.id]).toEqual(brush);
|
||||
});
|
||||
it("moves and resizes a box brush through undoable commands", () => {
|
||||
const store = createEditorStore();
|
||||
store.executeCommand(createCreateBoxBrushCommand());
|
||||
const createdBrush = Object.values(store.getState().document.brushes)[0];
|
||||
store.executeCommand(createMoveBoxBrushCommand({
|
||||
brushId: createdBrush.id,
|
||||
center: {
|
||||
x: 2.4,
|
||||
y: 3.2,
|
||||
z: -1.7
|
||||
}
|
||||
}));
|
||||
store.executeCommand(createResizeBoxBrushCommand({
|
||||
brushId: createdBrush.id,
|
||||
size: {
|
||||
x: 4.2,
|
||||
y: 1.2,
|
||||
z: 0.2
|
||||
}
|
||||
}));
|
||||
expect(store.getState().document.brushes[createdBrush.id].center).toEqual({
|
||||
x: 2,
|
||||
y: 3,
|
||||
z: -2
|
||||
});
|
||||
expect(store.getState().document.brushes[createdBrush.id].size).toEqual({
|
||||
x: 4,
|
||||
y: 1,
|
||||
z: 1
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.brushes[createdBrush.id].size).toEqual({
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 2
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.brushes[createdBrush.id].center).toEqual({
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
});
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.brushes[createdBrush.id].center).toEqual({
|
||||
x: 2,
|
||||
y: 3,
|
||||
z: -2
|
||||
});
|
||||
expect(store.getState().document.brushes[createdBrush.id].size).toEqual({
|
||||
x: 4,
|
||||
y: 1,
|
||||
z: 1
|
||||
});
|
||||
});
|
||||
it("preserves floating-point move, rotate, and scale authoring when snapping is disabled", () => {
|
||||
const store = createEditorStore();
|
||||
store.executeCommand(createCreateBoxBrushCommand({
|
||||
center: {
|
||||
x: 1.25,
|
||||
y: 1.5,
|
||||
z: -0.75
|
||||
},
|
||||
size: {
|
||||
x: 2.5,
|
||||
y: 3.25,
|
||||
z: 4.75
|
||||
},
|
||||
snapToGrid: false
|
||||
}));
|
||||
const createdBrush = Object.values(store.getState().document.brushes)[0];
|
||||
store.executeCommand(createMoveBoxBrushCommand({
|
||||
brushId: createdBrush.id,
|
||||
center: {
|
||||
x: 2.125,
|
||||
y: 3.375,
|
||||
z: -1.625
|
||||
},
|
||||
snapToGrid: false
|
||||
}));
|
||||
store.executeCommand(createRotateBoxBrushCommand({
|
||||
brushId: createdBrush.id,
|
||||
rotationDegrees: {
|
||||
x: 12.5,
|
||||
y: 37.5,
|
||||
z: -8.25
|
||||
}
|
||||
}));
|
||||
store.executeCommand(createResizeBoxBrushCommand({
|
||||
brushId: createdBrush.id,
|
||||
size: {
|
||||
x: 3.5,
|
||||
y: 1.75,
|
||||
z: 5.125
|
||||
},
|
||||
snapToGrid: false
|
||||
}));
|
||||
expect(store.getState().document.brushes[createdBrush.id]).toMatchObject({
|
||||
center: {
|
||||
x: 2.125,
|
||||
y: 3.375,
|
||||
z: -1.625
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 12.5,
|
||||
y: 37.5,
|
||||
z: -8.25
|
||||
},
|
||||
size: {
|
||||
x: 3.5,
|
||||
y: 1.75,
|
||||
z: 5.125
|
||||
}
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.brushes[createdBrush.id].size).toEqual({
|
||||
x: 2.5,
|
||||
y: 3.25,
|
||||
z: 4.75
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.brushes[createdBrush.id].rotationDegrees).toEqual({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.brushes[createdBrush.id].center).toEqual({
|
||||
x: 1.25,
|
||||
y: 1.5,
|
||||
z: -0.75
|
||||
});
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.brushes[createdBrush.id]).toMatchObject({
|
||||
center: {
|
||||
x: 2.125,
|
||||
y: 3.375,
|
||||
z: -1.625
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 12.5,
|
||||
y: 37.5,
|
||||
z: -8.25
|
||||
},
|
||||
size: {
|
||||
x: 3.5,
|
||||
y: 1.75,
|
||||
z: 5.125
|
||||
}
|
||||
});
|
||||
});
|
||||
it("renames a box brush through an undoable command", () => {
|
||||
const store = createEditorStore();
|
||||
store.executeCommand(createCreateBoxBrushCommand());
|
||||
const createdBrush = Object.values(store.getState().document.brushes)[0];
|
||||
store.executeCommand(createSetBoxBrushNameCommand({
|
||||
brushId: createdBrush.id,
|
||||
name: "Entry Room"
|
||||
}));
|
||||
expect(store.getState().document.brushes[createdBrush.id].name).toBe("Entry Room");
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.brushes[createdBrush.id].name).toBeUndefined();
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.brushes[createdBrush.id].name).toBe("Entry Room");
|
||||
});
|
||||
});
|
||||
@@ -1,68 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { SCENE_DOCUMENT_VERSION, createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { STARTER_MATERIAL_LIBRARY } from "../../src/materials/starter-material-library";
|
||||
describe("createEmptySceneDocument", () => {
|
||||
it("creates a versioned empty scene document", () => {
|
||||
const document = createEmptySceneDocument();
|
||||
expect(document.version).toBe(SCENE_DOCUMENT_VERSION);
|
||||
expect(document.name).toBe("Untitled Scene");
|
||||
expect(document.world).toEqual({
|
||||
background: {
|
||||
mode: "solid",
|
||||
colorHex: "#2f3947"
|
||||
},
|
||||
ambientLight: {
|
||||
colorHex: "#f7f1e8",
|
||||
intensity: 1
|
||||
},
|
||||
sunLight: {
|
||||
colorHex: "#fff1d5",
|
||||
intensity: 1.75,
|
||||
direction: {
|
||||
x: -0.6,
|
||||
y: 1,
|
||||
z: 0.35
|
||||
}
|
||||
},
|
||||
advancedRendering: {
|
||||
enabled: false,
|
||||
shadows: {
|
||||
enabled: false,
|
||||
mapSize: 2048,
|
||||
type: "pcfSoft",
|
||||
bias: -0.0005
|
||||
},
|
||||
ambientOcclusion: {
|
||||
enabled: false,
|
||||
intensity: 1,
|
||||
radius: 0.5,
|
||||
samples: 8
|
||||
},
|
||||
bloom: {
|
||||
enabled: false,
|
||||
intensity: 0.75,
|
||||
threshold: 0.85,
|
||||
radius: 0.35
|
||||
},
|
||||
toneMapping: {
|
||||
mode: "acesFilmic",
|
||||
exposure: 1
|
||||
},
|
||||
depthOfField: {
|
||||
enabled: false,
|
||||
focusDistance: 10,
|
||||
focalLength: 0.03,
|
||||
bokehScale: 1.5
|
||||
},
|
||||
fogPath: "performance",
|
||||
waterPath: "performance",
|
||||
waterReflectionMode: "none"
|
||||
}
|
||||
});
|
||||
expect(document.brushes).toEqual({});
|
||||
expect(document.entities).toEqual({});
|
||||
expect(document.modelInstances).toEqual({});
|
||||
expect(document.interactionLinks).toEqual({});
|
||||
expect(Object.keys(document.materials)).toEqual(STARTER_MATERIAL_LIBRARY.map((material) => material.id));
|
||||
});
|
||||
});
|
||||
@@ -1,244 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createModelInstance } from "../../src/assets/model-instances";
|
||||
import { createProjectAssetStorageKey } from "../../src/assets/project-assets";
|
||||
import { createEditorStore } from "../../src/app/editor-store";
|
||||
import { createDuplicateSelectionCommand } from "../../src/commands/duplicate-selection-command";
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { createTriggerVolumeEntity } from "../../src/entities/entity-instances";
|
||||
const modelAsset = {
|
||||
id: "asset-model-duplicate",
|
||||
kind: "model",
|
||||
sourceName: "duplicate-fixture.gltf",
|
||||
mimeType: "model/gltf+json",
|
||||
storageKey: createProjectAssetStorageKey("asset-model-duplicate"),
|
||||
byteLength: 64,
|
||||
metadata: {
|
||||
kind: "model",
|
||||
format: "gltf",
|
||||
sceneName: "Duplicate Fixture",
|
||||
nodeCount: 1,
|
||||
meshCount: 1,
|
||||
materialNames: [],
|
||||
textureNames: [],
|
||||
animationNames: [],
|
||||
boundingBox: {
|
||||
min: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
max: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 1
|
||||
},
|
||||
size: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 1
|
||||
}
|
||||
},
|
||||
warnings: []
|
||||
}
|
||||
};
|
||||
describe("duplicate selection command", () => {
|
||||
it("duplicates one selected whitebox solid with a fresh id and supports undo/redo", () => {
|
||||
const sourceBrush = createBoxBrush({
|
||||
id: "brush-source",
|
||||
center: {
|
||||
x: 2,
|
||||
y: 1,
|
||||
z: -3
|
||||
}
|
||||
});
|
||||
const store = createEditorStore({
|
||||
initialDocument: {
|
||||
...createEmptySceneDocument({ name: "Duplicate Brush" }),
|
||||
brushes: {
|
||||
[sourceBrush.id]: sourceBrush
|
||||
}
|
||||
}
|
||||
});
|
||||
store.setSelection({
|
||||
kind: "brushes",
|
||||
ids: [sourceBrush.id]
|
||||
});
|
||||
store.executeCommand(createDuplicateSelectionCommand());
|
||||
const selection = store.getState().selection;
|
||||
expect(selection.kind).toBe("brushes");
|
||||
if (selection.kind !== "brushes") {
|
||||
throw new Error("Expected duplicated brush selection.");
|
||||
}
|
||||
expect(selection.ids).toHaveLength(1);
|
||||
expect(selection.ids[0]).not.toBe(sourceBrush.id);
|
||||
const duplicatedBrush = store.getState().document.brushes[selection.ids[0]];
|
||||
expect(duplicatedBrush).toBeDefined();
|
||||
expect(duplicatedBrush.center).toEqual(sourceBrush.center);
|
||||
expect(duplicatedBrush.faces).toEqual(sourceBrush.faces);
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(Object.keys(store.getState().document.brushes)).toEqual([sourceBrush.id]);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "brushes",
|
||||
ids: [duplicatedBrush.id]
|
||||
});
|
||||
expect(store.getState().document.brushes[duplicatedBrush.id]).toEqual(duplicatedBrush);
|
||||
});
|
||||
it("duplicates one selected model instance without duplicating its asset", () => {
|
||||
const sourceModelInstance = createModelInstance({
|
||||
id: "model-instance-source",
|
||||
assetId: modelAsset.id,
|
||||
position: {
|
||||
x: -4,
|
||||
y: 2,
|
||||
z: 5
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 25,
|
||||
z: 0
|
||||
},
|
||||
scale: {
|
||||
x: 1.5,
|
||||
y: 1.5,
|
||||
z: 1.5
|
||||
}
|
||||
});
|
||||
const store = createEditorStore({
|
||||
initialDocument: {
|
||||
...createEmptySceneDocument({ name: "Duplicate Model Instance" }),
|
||||
assets: {
|
||||
[modelAsset.id]: modelAsset
|
||||
},
|
||||
modelInstances: {
|
||||
[sourceModelInstance.id]: sourceModelInstance
|
||||
}
|
||||
}
|
||||
});
|
||||
store.setSelection({
|
||||
kind: "modelInstances",
|
||||
ids: [sourceModelInstance.id]
|
||||
});
|
||||
store.executeCommand(createDuplicateSelectionCommand());
|
||||
const selection = store.getState().selection;
|
||||
expect(selection.kind).toBe("modelInstances");
|
||||
if (selection.kind !== "modelInstances") {
|
||||
throw new Error("Expected duplicated model instance selection.");
|
||||
}
|
||||
const duplicatedModelInstanceId = selection.ids[0];
|
||||
expect(duplicatedModelInstanceId).not.toBe(sourceModelInstance.id);
|
||||
const duplicatedModelInstance = store.getState().document.modelInstances[duplicatedModelInstanceId];
|
||||
expect(duplicatedModelInstance.assetId).toBe(sourceModelInstance.assetId);
|
||||
expect(duplicatedModelInstance.position).toEqual(sourceModelInstance.position);
|
||||
expect(store.getState().document.assets[modelAsset.id]).toEqual(modelAsset);
|
||||
expect(Object.keys(store.getState().document.assets)).toHaveLength(1);
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.modelInstances[sourceModelInstance.id]).toEqual(sourceModelInstance);
|
||||
expect(store.getState().document.modelInstances[duplicatedModelInstanceId]).toBeUndefined();
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "modelInstances",
|
||||
ids: [duplicatedModelInstanceId]
|
||||
});
|
||||
});
|
||||
it("duplicates one selected entity with a fresh id and selects the duplicate", () => {
|
||||
const sourceEntity = createTriggerVolumeEntity({
|
||||
id: "entity-source-trigger",
|
||||
position: {
|
||||
x: 8,
|
||||
y: 1,
|
||||
z: -2
|
||||
},
|
||||
size: {
|
||||
x: 4,
|
||||
y: 3,
|
||||
z: 2
|
||||
},
|
||||
triggerOnEnter: false,
|
||||
triggerOnExit: true
|
||||
});
|
||||
const store = createEditorStore({
|
||||
initialDocument: {
|
||||
...createEmptySceneDocument({ name: "Duplicate Entity" }),
|
||||
entities: {
|
||||
[sourceEntity.id]: sourceEntity
|
||||
}
|
||||
}
|
||||
});
|
||||
store.setSelection({
|
||||
kind: "entities",
|
||||
ids: [sourceEntity.id]
|
||||
});
|
||||
store.executeCommand(createDuplicateSelectionCommand());
|
||||
const selection = store.getState().selection;
|
||||
expect(selection.kind).toBe("entities");
|
||||
if (selection.kind !== "entities") {
|
||||
throw new Error("Expected duplicated entity selection.");
|
||||
}
|
||||
expect(selection.ids).toHaveLength(1);
|
||||
expect(selection.ids[0]).not.toBe(sourceEntity.id);
|
||||
const duplicatedEntity = store.getState().document.entities[selection.ids[0]];
|
||||
expect(duplicatedEntity).toBeDefined();
|
||||
expect(duplicatedEntity.kind).toBe(sourceEntity.kind);
|
||||
expect(duplicatedEntity.position).toEqual(sourceEntity.position);
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.entities[sourceEntity.id]).toEqual(sourceEntity);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "entities",
|
||||
ids: [duplicatedEntity.id]
|
||||
});
|
||||
});
|
||||
it("duplicates multiple selected whitebox solids in one operation", () => {
|
||||
const sourceBrushA = createBoxBrush({
|
||||
id: "brush-source-a",
|
||||
center: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
}
|
||||
});
|
||||
const sourceBrushB = createBoxBrush({
|
||||
id: "brush-source-b",
|
||||
center: {
|
||||
x: 6,
|
||||
y: 2,
|
||||
z: -4
|
||||
}
|
||||
});
|
||||
const store = createEditorStore({
|
||||
initialDocument: {
|
||||
...createEmptySceneDocument({ name: "Duplicate Multi" }),
|
||||
brushes: {
|
||||
[sourceBrushA.id]: sourceBrushA,
|
||||
[sourceBrushB.id]: sourceBrushB
|
||||
}
|
||||
}
|
||||
});
|
||||
store.setSelection({
|
||||
kind: "brushes",
|
||||
ids: [sourceBrushA.id, sourceBrushB.id]
|
||||
});
|
||||
store.executeCommand(createDuplicateSelectionCommand());
|
||||
const selection = store.getState().selection;
|
||||
expect(selection.kind).toBe("brushes");
|
||||
if (selection.kind !== "brushes") {
|
||||
throw new Error("Expected duplicated multi-brush selection.");
|
||||
}
|
||||
expect(selection.ids).toHaveLength(2);
|
||||
expect(new Set(selection.ids).size).toBe(2);
|
||||
expect(selection.ids).not.toEqual([sourceBrushA.id, sourceBrushB.id]);
|
||||
const duplicatedBrushA = store.getState().document.brushes[selection.ids[0]];
|
||||
const duplicatedBrushB = store.getState().document.brushes[selection.ids[1]];
|
||||
expect(duplicatedBrushA.center).toEqual(sourceBrushA.center);
|
||||
expect(duplicatedBrushB.center).toEqual(sourceBrushB.center);
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(Object.keys(store.getState().document.brushes).sort()).toEqual([sourceBrushA.id, sourceBrushB.id]);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "brushes",
|
||||
ids: [duplicatedBrushA.id, duplicatedBrushB.id]
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,360 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createEditorStore } from "../../src/app/editor-store";
|
||||
import { createCreateBoxBrushCommand } from "../../src/commands/create-box-brush-command";
|
||||
import { createSetSceneNameCommand } from "../../src/commands/set-scene-name-command";
|
||||
import { createTransformSession } from "../../src/core/transform-session";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
class MemoryStorage {
|
||||
values = new Map();
|
||||
getItem(key) {
|
||||
return this.values.get(key) ?? null;
|
||||
}
|
||||
setItem(key, value) {
|
||||
this.values.set(key, value);
|
||||
}
|
||||
removeItem(key) {
|
||||
this.values.delete(key);
|
||||
}
|
||||
}
|
||||
class ThrowingStorage {
|
||||
getItem() {
|
||||
throw new Error("blocked read");
|
||||
}
|
||||
setItem() {
|
||||
throw new Error("blocked write");
|
||||
}
|
||||
removeItem() { }
|
||||
}
|
||||
describe("EditorStore", () => {
|
||||
it("returns a stable snapshot between store updates", () => {
|
||||
const store = createEditorStore();
|
||||
const initialSnapshot = store.getState();
|
||||
const repeatedSnapshot = store.getState();
|
||||
expect(repeatedSnapshot).toBe(initialSnapshot);
|
||||
store.executeCommand(createSetSceneNameCommand("Snapshot Scene"));
|
||||
const updatedSnapshot = store.getState();
|
||||
expect(updatedSnapshot).not.toBe(initialSnapshot);
|
||||
expect(updatedSnapshot.document.name).toBe("Snapshot Scene");
|
||||
});
|
||||
it("applies command history with undo and redo", () => {
|
||||
const store = createEditorStore();
|
||||
store.executeCommand(createSetSceneNameCommand("Foundation Room"));
|
||||
expect(store.getState().document.name).toBe("Foundation Room");
|
||||
expect(store.getState().canUndo).toBe(true);
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.name).toBe("Untitled Scene");
|
||||
expect(store.getState().canRedo).toBe(true);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.name).toBe("Foundation Room");
|
||||
});
|
||||
it("saves and loads a local draft document", () => {
|
||||
const storage = new MemoryStorage();
|
||||
const writerStore = createEditorStore({ storage });
|
||||
writerStore.executeCommand(createSetSceneNameCommand("Draft Scene"));
|
||||
writerStore.setViewportLayoutMode("quad");
|
||||
writerStore.setActiveViewportPanel("bottomRight");
|
||||
writerStore.setViewportPanelViewMode("topLeft", "top");
|
||||
writerStore.setViewportPanelDisplayMode("topLeft", "wireframe");
|
||||
writerStore.setViewportPanelCameraState("topLeft", {
|
||||
target: {
|
||||
x: 6,
|
||||
y: 2,
|
||||
z: -4
|
||||
},
|
||||
perspectiveOrbit: {
|
||||
radius: 18,
|
||||
theta: 0.9,
|
||||
phi: 1.1
|
||||
},
|
||||
orthographicZoom: 2.25
|
||||
});
|
||||
expect(writerStore.saveDraft()).toEqual({
|
||||
status: "saved",
|
||||
message: "Local draft saved."
|
||||
});
|
||||
const readerStore = createEditorStore({
|
||||
initialDocument: createEmptySceneDocument({ name: "Fresh Scene" }),
|
||||
storage
|
||||
});
|
||||
expect(readerStore.loadDraft()).toMatchObject({
|
||||
status: "loaded",
|
||||
message: "Local draft loaded."
|
||||
});
|
||||
expect(readerStore.getState().document.name).toBe("Draft Scene");
|
||||
expect(readerStore.getState().viewportLayoutMode).toBe("quad");
|
||||
expect(readerStore.getState().activeViewportPanelId).toBe("bottomRight");
|
||||
expect(readerStore.getState().viewportPanels.topLeft).toMatchObject({
|
||||
viewMode: "top",
|
||||
displayMode: "wireframe",
|
||||
cameraState: {
|
||||
target: {
|
||||
x: 6,
|
||||
y: 2,
|
||||
z: -4
|
||||
},
|
||||
perspectiveOrbit: {
|
||||
radius: 18,
|
||||
theta: 0.9,
|
||||
phi: 1.1
|
||||
},
|
||||
orthographicZoom: 2.25
|
||||
}
|
||||
});
|
||||
});
|
||||
it("fails gracefully when storage access throws", () => {
|
||||
const store = createEditorStore({ storage: new ThrowingStorage() });
|
||||
expect(store.saveDraft()).toMatchObject({
|
||||
status: "error",
|
||||
message: expect.stringContaining("blocked write")
|
||||
});
|
||||
expect(store.loadDraft()).toMatchObject({
|
||||
status: "error",
|
||||
message: expect.stringContaining("blocked read")
|
||||
});
|
||||
});
|
||||
it("restores the previous editor tool when leaving play mode", () => {
|
||||
const store = createEditorStore();
|
||||
store.setToolMode("create");
|
||||
store.enterPlayMode();
|
||||
expect(store.getState().toolMode).toBe("play");
|
||||
store.exitPlayMode();
|
||||
expect(store.getState().toolMode).toBe("create");
|
||||
});
|
||||
it("tracks viewport layout and per-panel state independently from the document", () => {
|
||||
const store = createEditorStore();
|
||||
expect(store.getState().whiteboxSelectionMode).toBe("object");
|
||||
expect(store.getState().viewportLayoutMode).toBe("single");
|
||||
expect(store.getState().activeViewportPanelId).toBe("topLeft");
|
||||
expect(store.getState().viewportPanels.topLeft.viewMode).toBe("perspective");
|
||||
expect(store.getState().viewportPanels.topRight.viewMode).toBe("top");
|
||||
expect(store.getState().viewportPanels.topRight.displayMode).toBe("authoring");
|
||||
expect(store.getState().viewportQuadSplit).toEqual({
|
||||
x: 0.5,
|
||||
y: 0.5
|
||||
});
|
||||
store.setViewportLayoutMode("quad");
|
||||
store.setActiveViewportPanel("bottomRight");
|
||||
store.setViewportPanelViewMode("bottomRight", "front");
|
||||
store.setViewportPanelDisplayMode("bottomRight", "normal");
|
||||
store.setViewportQuadSplit({
|
||||
x: 0.38,
|
||||
y: 0.62
|
||||
});
|
||||
expect(store.getState().viewportLayoutMode).toBe("quad");
|
||||
expect(store.getState().activeViewportPanelId).toBe("bottomRight");
|
||||
expect(store.getState().viewportPanels.bottomRight.viewMode).toBe("front");
|
||||
expect(store.getState().viewportPanels.bottomRight.displayMode).toBe("normal");
|
||||
expect(store.getState().viewportQuadSplit).toEqual({
|
||||
x: 0.38,
|
||||
y: 0.62
|
||||
});
|
||||
});
|
||||
it("tracks whitebox component selection mode independently from document state", () => {
|
||||
const store = createEditorStore();
|
||||
store.setWhiteboxSelectionMode("face");
|
||||
expect(store.getState().whiteboxSelectionMode).toBe("face");
|
||||
store.setWhiteboxSelectionMode("edge");
|
||||
expect(store.getState().whiteboxSelectionMode).toBe("edge");
|
||||
store.setWhiteboxSelectionMode("vertex");
|
||||
expect(store.getState().whiteboxSelectionMode).toBe("vertex");
|
||||
store.setWhiteboxSelectionMode("object");
|
||||
expect(store.getState().whiteboxSelectionMode).toBe("object");
|
||||
});
|
||||
it("normalizes selected whitebox components back to the owning solid when switching to a different component mode", () => {
|
||||
const store = createEditorStore();
|
||||
store.executeCommand(createCreateBoxBrushCommand());
|
||||
const createdBrush = Object.values(store.getState().document.brushes)[0];
|
||||
store.setWhiteboxSelectionMode("face");
|
||||
store.setSelection({
|
||||
kind: "brushFace",
|
||||
brushId: createdBrush.id,
|
||||
faceId: "posY"
|
||||
});
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "brushFace",
|
||||
brushId: createdBrush.id,
|
||||
faceId: "posY"
|
||||
});
|
||||
store.setWhiteboxSelectionMode("edge");
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "brushes",
|
||||
ids: [createdBrush.id]
|
||||
});
|
||||
store.setSelection({
|
||||
kind: "brushEdge",
|
||||
brushId: createdBrush.id,
|
||||
edgeId: "edgeX_posY_negZ"
|
||||
});
|
||||
store.setWhiteboxSelectionMode("vertex");
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "brushes",
|
||||
ids: [createdBrush.id]
|
||||
});
|
||||
store.setSelection({
|
||||
kind: "brushVertex",
|
||||
brushId: createdBrush.id,
|
||||
vertexId: "posX_posY_negZ"
|
||||
});
|
||||
store.setWhiteboxSelectionMode("object");
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "brushes",
|
||||
ids: [createdBrush.id]
|
||||
});
|
||||
});
|
||||
it("shares transient creation preview state across viewport panels", () => {
|
||||
const store = createEditorStore();
|
||||
expect(store.getState().viewportTransientState.toolPreview).toEqual({
|
||||
kind: "none"
|
||||
});
|
||||
store.setViewportToolPreview({
|
||||
kind: "create",
|
||||
sourcePanelId: "topLeft",
|
||||
target: {
|
||||
kind: "box-brush"
|
||||
},
|
||||
center: {
|
||||
x: 4,
|
||||
y: 0,
|
||||
z: 8
|
||||
}
|
||||
});
|
||||
expect(store.getState().viewportTransientState.toolPreview).toEqual({
|
||||
kind: "create",
|
||||
sourcePanelId: "topLeft",
|
||||
target: {
|
||||
kind: "box-brush"
|
||||
},
|
||||
center: {
|
||||
x: 4,
|
||||
y: 0,
|
||||
z: 8
|
||||
}
|
||||
});
|
||||
store.setViewportToolPreview({
|
||||
kind: "create",
|
||||
sourcePanelId: "bottomRight",
|
||||
target: {
|
||||
kind: "entity",
|
||||
entityKind: "pointLight",
|
||||
audioAssetId: null
|
||||
},
|
||||
center: {
|
||||
x: 2,
|
||||
y: 1,
|
||||
z: -3
|
||||
}
|
||||
});
|
||||
expect(store.getState().viewportTransientState.toolPreview).toEqual({
|
||||
kind: "create",
|
||||
sourcePanelId: "bottomRight",
|
||||
target: {
|
||||
kind: "entity",
|
||||
entityKind: "pointLight",
|
||||
audioAssetId: null
|
||||
},
|
||||
center: {
|
||||
x: 2,
|
||||
y: 1,
|
||||
z: -3
|
||||
}
|
||||
});
|
||||
store.clearViewportToolPreview("topRight");
|
||||
expect(store.getState().viewportTransientState.toolPreview).toEqual({
|
||||
kind: "create",
|
||||
sourcePanelId: "bottomRight",
|
||||
target: {
|
||||
kind: "entity",
|
||||
entityKind: "pointLight",
|
||||
audioAssetId: null
|
||||
},
|
||||
center: {
|
||||
x: 2,
|
||||
y: 1,
|
||||
z: -3
|
||||
}
|
||||
});
|
||||
store.clearViewportToolPreview("bottomRight");
|
||||
expect(store.getState().viewportTransientState.toolPreview).toEqual({
|
||||
kind: "none"
|
||||
});
|
||||
});
|
||||
it("tracks a shared transient transform session and clears it when selection changes", () => {
|
||||
const store = createEditorStore();
|
||||
store.setTransformSession(createTransformSession({
|
||||
source: "keyboard",
|
||||
sourcePanelId: "bottomRight",
|
||||
operation: "translate",
|
||||
target: {
|
||||
kind: "brush",
|
||||
brushId: "brush-main",
|
||||
initialCenter: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
initialRotationDegrees: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
initialSize: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 2
|
||||
}
|
||||
}
|
||||
}));
|
||||
expect(store.getState().viewportTransientState.transformSession).toMatchObject({
|
||||
kind: "active",
|
||||
source: "keyboard",
|
||||
sourcePanelId: "bottomRight",
|
||||
operation: "translate",
|
||||
target: {
|
||||
kind: "brush",
|
||||
brushId: "brush-main"
|
||||
},
|
||||
preview: {
|
||||
kind: "brush",
|
||||
center: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 2
|
||||
}
|
||||
}
|
||||
});
|
||||
store.setSelection({
|
||||
kind: "brushes",
|
||||
ids: ["brush-main"]
|
||||
});
|
||||
expect(store.getState().viewportTransientState.transformSession).toEqual({
|
||||
kind: "none"
|
||||
});
|
||||
});
|
||||
it("clears transient viewport preview when leaving create mode", () => {
|
||||
const store = createEditorStore();
|
||||
store.setToolMode("create");
|
||||
store.setViewportToolPreview({
|
||||
kind: "create",
|
||||
sourcePanelId: "bottomRight",
|
||||
target: {
|
||||
kind: "model-instance",
|
||||
assetId: "asset-1"
|
||||
},
|
||||
center: null
|
||||
});
|
||||
store.setToolMode("select");
|
||||
expect(store.getState().viewportTransientState.toolPreview).toEqual({
|
||||
kind: "none"
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,153 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createEditorStore } from "../../src/app/editor-store";
|
||||
import { createUpsertEntityCommand } from "../../src/commands/upsert-entity-command";
|
||||
import { createPointLightEntity, createSoundEmitterEntity, createSpotLightEntity, createTriggerVolumeEntity } from "../../src/entities/entity-instances";
|
||||
describe("typed entity upsert command", () => {
|
||||
it("places a Sound Emitter and restores the previous tool mode across undo and redo", () => {
|
||||
const store = createEditorStore();
|
||||
const soundEmitter = createSoundEmitterEntity({
|
||||
position: {
|
||||
x: 1,
|
||||
y: 2,
|
||||
z: 3
|
||||
},
|
||||
audioAssetId: null,
|
||||
volume: 0.5,
|
||||
refDistance: 5,
|
||||
maxDistance: 12
|
||||
});
|
||||
store.setToolMode("create");
|
||||
store.executeCommand(createUpsertEntityCommand({
|
||||
entity: soundEmitter,
|
||||
label: "Place sound emitter"
|
||||
}));
|
||||
expect(store.getState().toolMode).toBe("select");
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "entities",
|
||||
ids: [soundEmitter.id]
|
||||
});
|
||||
expect(store.getState().document.entities[soundEmitter.id]).toEqual(soundEmitter);
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().toolMode).toBe("create");
|
||||
expect(store.getState().document.entities).toEqual({});
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().toolMode).toBe("select");
|
||||
expect(store.getState().document.entities[soundEmitter.id]).toEqual(soundEmitter);
|
||||
});
|
||||
it("places a Point Light and restores the previous tool mode across undo and redo", () => {
|
||||
const store = createEditorStore();
|
||||
const pointLight = createPointLightEntity({
|
||||
position: {
|
||||
x: 2,
|
||||
y: 3,
|
||||
z: 4
|
||||
},
|
||||
colorHex: "#ccddee",
|
||||
intensity: 1.5,
|
||||
distance: 9
|
||||
});
|
||||
store.setToolMode("create");
|
||||
store.executeCommand(createUpsertEntityCommand({
|
||||
entity: pointLight,
|
||||
label: "Place point light"
|
||||
}));
|
||||
expect(store.getState().toolMode).toBe("select");
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "entities",
|
||||
ids: [pointLight.id]
|
||||
});
|
||||
expect(store.getState().document.entities[pointLight.id]).toEqual(pointLight);
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().toolMode).toBe("create");
|
||||
expect(store.getState().document.entities).toEqual({});
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().toolMode).toBe("select");
|
||||
expect(store.getState().document.entities[pointLight.id]).toEqual(pointLight);
|
||||
});
|
||||
it("updates an existing Trigger Volume without changing its entity id", () => {
|
||||
const store = createEditorStore();
|
||||
const triggerVolume = createTriggerVolumeEntity({
|
||||
id: "entity-trigger-main",
|
||||
size: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 2
|
||||
}
|
||||
});
|
||||
const movedTriggerVolume = createTriggerVolumeEntity({
|
||||
...triggerVolume,
|
||||
position: {
|
||||
x: 4,
|
||||
y: 1,
|
||||
z: -2
|
||||
},
|
||||
size: {
|
||||
x: 3,
|
||||
y: 4,
|
||||
z: 5
|
||||
},
|
||||
triggerOnEnter: false,
|
||||
triggerOnExit: true
|
||||
});
|
||||
store.executeCommand(createUpsertEntityCommand({
|
||||
entity: triggerVolume,
|
||||
label: "Place trigger volume"
|
||||
}));
|
||||
store.setToolMode("create");
|
||||
store.executeCommand(createUpsertEntityCommand({
|
||||
entity: movedTriggerVolume,
|
||||
label: "Update trigger volume"
|
||||
}));
|
||||
expect(store.getState().toolMode).toBe("select");
|
||||
expect(store.getState().document.entities[triggerVolume.id]).toEqual(movedTriggerVolume);
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().toolMode).toBe("create");
|
||||
expect(store.getState().document.entities[triggerVolume.id]).toEqual(triggerVolume);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.entities[triggerVolume.id]).toEqual(movedTriggerVolume);
|
||||
});
|
||||
it("updates an existing Spot Light without changing its entity id", () => {
|
||||
const store = createEditorStore();
|
||||
const spotLight = createSpotLightEntity({
|
||||
id: "entity-spot-main",
|
||||
position: {
|
||||
x: -3,
|
||||
y: 4,
|
||||
z: 2
|
||||
}
|
||||
});
|
||||
const movedSpotLight = createSpotLightEntity({
|
||||
...spotLight,
|
||||
position: {
|
||||
x: 5,
|
||||
y: 6,
|
||||
z: -4
|
||||
},
|
||||
direction: {
|
||||
x: 0.5,
|
||||
y: -1,
|
||||
z: 0.25
|
||||
},
|
||||
colorHex: "#aaccee",
|
||||
intensity: 2.25,
|
||||
distance: 14,
|
||||
angleDegrees: 50
|
||||
});
|
||||
store.executeCommand(createUpsertEntityCommand({
|
||||
entity: spotLight,
|
||||
label: "Place spot light"
|
||||
}));
|
||||
store.setToolMode("create");
|
||||
store.executeCommand(createUpsertEntityCommand({
|
||||
entity: movedSpotLight,
|
||||
label: "Update spot light"
|
||||
}));
|
||||
expect(store.getState().toolMode).toBe("select");
|
||||
expect(store.getState().document.entities[spotLight.id]).toEqual(movedSpotLight);
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().toolMode).toBe("create");
|
||||
expect(store.getState().document.entities[spotLight.id]).toEqual(spotLight);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.entities[spotLight.id]).toEqual(movedSpotLight);
|
||||
});
|
||||
});
|
||||
@@ -1,242 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { validateSceneDocument } from "../../src/document/scene-document-validation";
|
||||
import { createModelInstance } from "../../src/assets/model-instances";
|
||||
import { createProjectAssetStorageKey } from "../../src/assets/project-assets";
|
||||
import { createInteractableEntity, createPlayerStartEntity, createSoundEmitterEntity, createTeleportTargetEntity, createTriggerVolumeEntity } from "../../src/entities/entity-instances";
|
||||
import { createPlayAnimationInteractionLink, createPlaySoundInteractionLink, createTeleportPlayerInteractionLink, createToggleVisibilityInteractionLink, createStopSoundInteractionLink } from "../../src/interactions/interaction-links";
|
||||
describe("interaction link validation", () => {
|
||||
it("accepts valid Trigger Volume and Interactable links", () => {
|
||||
const triggerVolume = createTriggerVolumeEntity({
|
||||
id: "entity-trigger-main"
|
||||
});
|
||||
const interactable = createInteractableEntity({
|
||||
id: "entity-interactable-main",
|
||||
prompt: "Use Console"
|
||||
});
|
||||
const teleportTarget = createTeleportTargetEntity({
|
||||
id: "entity-teleport-main"
|
||||
});
|
||||
const audioAsset = {
|
||||
id: "asset-audio-main",
|
||||
kind: "audio",
|
||||
sourceName: "lobby-loop.ogg",
|
||||
mimeType: "audio/ogg",
|
||||
storageKey: createProjectAssetStorageKey("asset-audio-main"),
|
||||
byteLength: 4096,
|
||||
metadata: {
|
||||
kind: "audio",
|
||||
durationSeconds: 4,
|
||||
channelCount: 2,
|
||||
sampleRateHz: 48000,
|
||||
warnings: []
|
||||
}
|
||||
};
|
||||
const soundEmitter = createSoundEmitterEntity({
|
||||
id: "entity-sound-main",
|
||||
audioAssetId: audioAsset.id
|
||||
});
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-door"
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
},
|
||||
entities: {
|
||||
[triggerVolume.id]: triggerVolume,
|
||||
[interactable.id]: interactable,
|
||||
[teleportTarget.id]: teleportTarget,
|
||||
[soundEmitter.id]: soundEmitter
|
||||
},
|
||||
assets: {
|
||||
[audioAsset.id]: audioAsset
|
||||
},
|
||||
interactionLinks: {
|
||||
"link-teleport": createTeleportPlayerInteractionLink({
|
||||
id: "link-teleport",
|
||||
sourceEntityId: triggerVolume.id,
|
||||
trigger: "enter",
|
||||
targetEntityId: teleportTarget.id
|
||||
}),
|
||||
"link-visibility": createToggleVisibilityInteractionLink({
|
||||
id: "link-visibility",
|
||||
sourceEntityId: triggerVolume.id,
|
||||
trigger: "exit",
|
||||
targetBrushId: brush.id,
|
||||
visible: false
|
||||
}),
|
||||
"link-click-teleport": createTeleportPlayerInteractionLink({
|
||||
id: "link-click-teleport",
|
||||
sourceEntityId: interactable.id,
|
||||
trigger: "click",
|
||||
targetEntityId: teleportTarget.id
|
||||
}),
|
||||
"link-play-sound": createPlaySoundInteractionLink({
|
||||
id: "link-play-sound",
|
||||
sourceEntityId: interactable.id,
|
||||
trigger: "click",
|
||||
targetSoundEmitterId: soundEmitter.id
|
||||
}),
|
||||
"link-stop-sound": createStopSoundInteractionLink({
|
||||
id: "link-stop-sound",
|
||||
sourceEntityId: triggerVolume.id,
|
||||
trigger: "exit",
|
||||
targetSoundEmitterId: soundEmitter.id
|
||||
})
|
||||
}
|
||||
};
|
||||
const validation = validateSceneDocument(document);
|
||||
expect(validation.errors).toEqual([]);
|
||||
});
|
||||
it("detects sound playback links that target a sound emitter without an audio asset", () => {
|
||||
const triggerVolume = createTriggerVolumeEntity({
|
||||
id: "entity-trigger-main"
|
||||
});
|
||||
const soundEmitter = createSoundEmitterEntity({
|
||||
id: "entity-sound-main"
|
||||
});
|
||||
const validation = validateSceneDocument({
|
||||
...createEmptySceneDocument(),
|
||||
entities: {
|
||||
[triggerVolume.id]: triggerVolume,
|
||||
[soundEmitter.id]: soundEmitter
|
||||
},
|
||||
interactionLinks: {
|
||||
"link-play-sound": createPlaySoundInteractionLink({
|
||||
id: "link-play-sound",
|
||||
sourceEntityId: triggerVolume.id,
|
||||
trigger: "enter",
|
||||
targetSoundEmitterId: soundEmitter.id
|
||||
})
|
||||
}
|
||||
});
|
||||
expect(validation.errors).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "missing-sound-emitter-audio-asset",
|
||||
path: "interactionLinks.link-play-sound.action.targetSoundEmitterId"
|
||||
})
|
||||
]));
|
||||
});
|
||||
it("detects invalid interaction link source and target references", () => {
|
||||
const playerStart = createPlayerStartEntity({
|
||||
id: "entity-player-start-main"
|
||||
});
|
||||
const triggerVolume = createTriggerVolumeEntity({
|
||||
id: "entity-trigger-main"
|
||||
});
|
||||
const interactable = createInteractableEntity({
|
||||
id: "entity-interactable-main"
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
entities: {
|
||||
[playerStart.id]: playerStart,
|
||||
[triggerVolume.id]: triggerVolume,
|
||||
[interactable.id]: interactable
|
||||
},
|
||||
interactionLinks: {
|
||||
"link-invalid-source": createTeleportPlayerInteractionLink({
|
||||
id: "link-invalid-source",
|
||||
sourceEntityId: playerStart.id,
|
||||
trigger: "enter",
|
||||
targetEntityId: "entity-missing-teleport-target"
|
||||
}),
|
||||
"link-invalid-visibility": createToggleVisibilityInteractionLink({
|
||||
id: "link-invalid-visibility",
|
||||
sourceEntityId: triggerVolume.id,
|
||||
trigger: "exit",
|
||||
targetBrushId: "brush-missing"
|
||||
}),
|
||||
"link-invalid-click-trigger": createTeleportPlayerInteractionLink({
|
||||
id: "link-invalid-click-trigger",
|
||||
sourceEntityId: interactable.id,
|
||||
trigger: "enter",
|
||||
targetEntityId: "entity-missing-teleport-target"
|
||||
})
|
||||
}
|
||||
};
|
||||
const validation = validateSceneDocument(document);
|
||||
expect(validation.errors).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "invalid-interaction-source-kind",
|
||||
path: "interactionLinks.link-invalid-source.sourceEntityId"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "missing-teleport-target-entity",
|
||||
path: "interactionLinks.link-invalid-source.action.targetEntityId"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "missing-visibility-target-brush",
|
||||
path: "interactionLinks.link-invalid-visibility.action.targetBrushId"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "unsupported-interaction-trigger",
|
||||
path: "interactionLinks.link-invalid-click-trigger.trigger"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "missing-teleport-target-entity",
|
||||
path: "interactionLinks.link-invalid-click-trigger.action.targetEntityId"
|
||||
})
|
||||
]));
|
||||
});
|
||||
it("detects playAnimation links that reference a missing clip on the target model asset", () => {
|
||||
const modelAsset = {
|
||||
id: "asset-model-animated",
|
||||
kind: "model",
|
||||
sourceName: "animated.glb",
|
||||
mimeType: "model/gltf-binary",
|
||||
storageKey: createProjectAssetStorageKey("asset-model-animated"),
|
||||
byteLength: 1024,
|
||||
metadata: {
|
||||
kind: "model",
|
||||
format: "glb",
|
||||
sceneName: null,
|
||||
nodeCount: 1,
|
||||
meshCount: 1,
|
||||
materialNames: [],
|
||||
textureNames: [],
|
||||
animationNames: ["Idle", "Run"],
|
||||
boundingBox: null,
|
||||
warnings: []
|
||||
}
|
||||
};
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-animated",
|
||||
assetId: modelAsset.id
|
||||
});
|
||||
const triggerVolume = createTriggerVolumeEntity({
|
||||
id: "entity-trigger-main"
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
assets: {
|
||||
[modelAsset.id]: modelAsset
|
||||
},
|
||||
modelInstances: {
|
||||
[modelInstance.id]: modelInstance
|
||||
},
|
||||
entities: {
|
||||
[triggerVolume.id]: triggerVolume
|
||||
},
|
||||
interactionLinks: {
|
||||
"link-play-missing-clip": createPlayAnimationInteractionLink({
|
||||
id: "link-play-missing-clip",
|
||||
sourceEntityId: triggerVolume.id,
|
||||
trigger: "enter",
|
||||
targetModelInstanceId: modelInstance.id,
|
||||
clipName: "Walk"
|
||||
})
|
||||
}
|
||||
};
|
||||
const validation = validateSceneDocument(document);
|
||||
expect(validation.errors).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "missing-play-animation-clip",
|
||||
path: "interactionLinks.link-play-missing-clip.action.clipName"
|
||||
})
|
||||
]));
|
||||
});
|
||||
});
|
||||
@@ -1,54 +0,0 @@
|
||||
import path from "node:path";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { importModelAssetFromFile, importModelAssetFromFiles, loadModelAssetFromStorage } from "../../src/assets/gltf-model-import";
|
||||
import { createInMemoryProjectAssetStorage } from "../../src/assets/project-asset-storage";
|
||||
const tinyGlbFixturePath = path.resolve(process.cwd(), "fixtures/assets/tiny-triangle.glb");
|
||||
const externalTriangleGltfPath = path.resolve(process.cwd(), "fixtures/assets/external-triangle/scene.gltf");
|
||||
const externalTriangleBinPath = path.resolve(process.cwd(), "fixtures/assets/external-triangle/triangle.bin");
|
||||
function createTestFile(bytes, name, type) {
|
||||
const arrayBuffer = new ArrayBuffer(bytes.byteLength);
|
||||
new Uint8Array(arrayBuffer).set(bytes);
|
||||
return {
|
||||
name,
|
||||
type,
|
||||
lastModified: Date.now(),
|
||||
size: arrayBuffer.byteLength,
|
||||
webkitRelativePath: "",
|
||||
arrayBuffer: async () => arrayBuffer.slice(0)
|
||||
};
|
||||
}
|
||||
describe("model import", () => {
|
||||
it("imports and reloads a tiny GLB fixture", async () => {
|
||||
const storage = createInMemoryProjectAssetStorage();
|
||||
const fileBytes = await readFile(tinyGlbFixturePath);
|
||||
const file = createTestFile(fileBytes, "tiny-triangle.glb", "model/gltf-binary");
|
||||
const importedModel = await importModelAssetFromFile(file, storage);
|
||||
expect(importedModel.asset.mimeType).toBe("model/gltf-binary");
|
||||
expect(importedModel.asset.metadata.format).toBe("glb");
|
||||
expect(importedModel.asset.byteLength).toBe(fileBytes.byteLength);
|
||||
expect(importedModel.modelInstance.assetId).toBe(importedModel.asset.id);
|
||||
const storedAsset = await storage.getAsset(importedModel.asset.storageKey);
|
||||
expect(Object.keys(storedAsset?.files ?? {})).toEqual(["tiny-triangle.glb"]);
|
||||
const reloadedAsset = await loadModelAssetFromStorage(storage, importedModel.asset);
|
||||
expect(reloadedAsset.metadata.format).toBe("glb");
|
||||
expect(reloadedAsset.template.children.length).toBeGreaterThan(0);
|
||||
});
|
||||
it("imports and reloads a gltf fixture with external resources", async () => {
|
||||
const storage = createInMemoryProjectAssetStorage();
|
||||
const gltfBytes = await readFile(externalTriangleGltfPath);
|
||||
const binBytes = await readFile(externalTriangleBinPath);
|
||||
const importedModel = await importModelAssetFromFiles([
|
||||
createTestFile(binBytes, "triangle.bin", "application/octet-stream"),
|
||||
createTestFile(gltfBytes, "scene.gltf", "model/gltf+json")
|
||||
], storage);
|
||||
expect(importedModel.asset.mimeType).toBe("model/gltf+json");
|
||||
expect(importedModel.asset.metadata.format).toBe("gltf");
|
||||
expect(importedModel.asset.byteLength).toBe(gltfBytes.byteLength + binBytes.byteLength);
|
||||
const storedAsset = await storage.getAsset(importedModel.asset.storageKey);
|
||||
expect(Object.keys(storedAsset?.files ?? {}).sort()).toEqual(["scene.gltf", "triangle.bin"]);
|
||||
const reloadedAsset = await loadModelAssetFromStorage(storage, importedModel.asset);
|
||||
expect(reloadedAsset.metadata.meshCount).toBe(1);
|
||||
expect(reloadedAsset.template.children.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
@@ -1,147 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createEditorStore } from "../../src/app/editor-store";
|
||||
import { createImportModelAssetCommand } from "../../src/commands/import-model-asset-command";
|
||||
import { createUpsertModelInstanceCommand } from "../../src/commands/upsert-model-instance-command";
|
||||
import { createModelInstance } from "../../src/assets/model-instances";
|
||||
import { createProjectAssetStorageKey } from "../../src/assets/project-assets";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
describe("model instance commands", () => {
|
||||
const modelAsset = {
|
||||
id: "asset-model-triangle",
|
||||
kind: "model",
|
||||
sourceName: "tiny-triangle.gltf",
|
||||
mimeType: "model/gltf+json",
|
||||
storageKey: createProjectAssetStorageKey("asset-model-triangle"),
|
||||
byteLength: 36,
|
||||
metadata: {
|
||||
kind: "model",
|
||||
format: "gltf",
|
||||
sceneName: "Fixture Triangle Scene",
|
||||
nodeCount: 2,
|
||||
meshCount: 1,
|
||||
materialNames: ["Fixture Material"],
|
||||
textureNames: [],
|
||||
animationNames: [],
|
||||
boundingBox: {
|
||||
min: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
max: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 0
|
||||
}
|
||||
},
|
||||
warnings: []
|
||||
}
|
||||
};
|
||||
it("imports a model asset and placed model instance through undo and redo", () => {
|
||||
const store = createEditorStore();
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-triangle",
|
||||
assetId: modelAsset.id,
|
||||
name: "Fixture Triangle",
|
||||
position: {
|
||||
x: 4,
|
||||
y: 2,
|
||||
z: -3
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 45,
|
||||
z: 0
|
||||
},
|
||||
scale: {
|
||||
x: 1.5,
|
||||
y: 2,
|
||||
z: 1.5
|
||||
}
|
||||
});
|
||||
store.executeCommand(createImportModelAssetCommand({
|
||||
asset: modelAsset,
|
||||
modelInstance,
|
||||
label: "Import fixture triangle"
|
||||
}));
|
||||
expect(store.getState().document.assets[modelAsset.id]).toEqual(modelAsset);
|
||||
expect(store.getState().document.modelInstances[modelInstance.id]).toEqual(modelInstance);
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "modelInstances",
|
||||
ids: [modelInstance.id]
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.assets).toEqual({});
|
||||
expect(store.getState().document.modelInstances).toEqual({});
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.assets[modelAsset.id]).toEqual(modelAsset);
|
||||
expect(store.getState().document.modelInstances[modelInstance.id]).toEqual(modelInstance);
|
||||
});
|
||||
it("updates an existing model instance transform without changing the asset reference", () => {
|
||||
const existingModelInstance = createModelInstance({
|
||||
id: "model-instance-triangle",
|
||||
assetId: modelAsset.id,
|
||||
position: {
|
||||
x: 1,
|
||||
y: 0,
|
||||
z: 1
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
scale: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 1
|
||||
}
|
||||
});
|
||||
const store = createEditorStore({
|
||||
initialDocument: {
|
||||
...createEmptySceneDocument({ name: "Model Instance Scene" }),
|
||||
assets: {
|
||||
[modelAsset.id]: modelAsset
|
||||
},
|
||||
modelInstances: {
|
||||
[existingModelInstance.id]: existingModelInstance
|
||||
}
|
||||
}
|
||||
});
|
||||
const updatedModelInstance = createModelInstance({
|
||||
id: existingModelInstance.id,
|
||||
assetId: modelAsset.id,
|
||||
name: existingModelInstance.name,
|
||||
position: {
|
||||
x: 5,
|
||||
y: 1,
|
||||
z: -2
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 15,
|
||||
y: 90,
|
||||
z: 0
|
||||
},
|
||||
scale: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 2
|
||||
}
|
||||
});
|
||||
store.executeCommand(createUpsertModelInstanceCommand({
|
||||
modelInstance: updatedModelInstance,
|
||||
label: "Update fixture triangle"
|
||||
}));
|
||||
expect(store.getState().document.modelInstances[existingModelInstance.id]).toEqual(updatedModelInstance);
|
||||
expect(store.getState().document.assets[modelAsset.id]).toEqual(modelAsset);
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.modelInstances[existingModelInstance.id]).toEqual(existingModelInstance);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.modelInstances[existingModelInstance.id]).toEqual(updatedModelInstance);
|
||||
});
|
||||
});
|
||||
@@ -1,70 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createEditorStore } from "../../src/app/editor-store";
|
||||
import { createSetPlayerStartCommand } from "../../src/commands/set-player-start-command";
|
||||
describe("player start command", () => {
|
||||
it("restores the previous tool mode across undo and redo when placing PlayerStart", () => {
|
||||
const store = createEditorStore();
|
||||
store.setToolMode("create");
|
||||
store.executeCommand(createSetPlayerStartCommand({
|
||||
position: {
|
||||
x: 2,
|
||||
y: 0,
|
||||
z: -2
|
||||
},
|
||||
yawDegrees: 90
|
||||
}));
|
||||
const placedPlayerStart = Object.values(store.getState().document.entities)[0];
|
||||
expect(placedPlayerStart).toBeDefined();
|
||||
expect(store.getState().toolMode).toBe("select");
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().toolMode).toBe("create");
|
||||
expect(store.getState().document.entities).toEqual({});
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().toolMode).toBe("select");
|
||||
expect(store.getState().document.entities[placedPlayerStart.id]).toEqual(placedPlayerStart);
|
||||
});
|
||||
it("restores the previous tool mode across undo and redo when moving PlayerStart", () => {
|
||||
const store = createEditorStore();
|
||||
store.executeCommand(createSetPlayerStartCommand({
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
yawDegrees: 0
|
||||
}));
|
||||
const existingPlayerStart = Object.values(store.getState().document.entities)[0];
|
||||
store.setToolMode("create");
|
||||
store.executeCommand(createSetPlayerStartCommand({
|
||||
entityId: existingPlayerStart.id,
|
||||
position: {
|
||||
x: 4,
|
||||
y: 0,
|
||||
z: 1
|
||||
},
|
||||
yawDegrees: 180
|
||||
}));
|
||||
expect(store.getState().toolMode).toBe("select");
|
||||
expect(store.getState().document.entities[existingPlayerStart.id]).toMatchObject({
|
||||
position: {
|
||||
x: 4,
|
||||
y: 0,
|
||||
z: 1
|
||||
},
|
||||
yawDegrees: 180
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().toolMode).toBe("create");
|
||||
expect(store.getState().document.entities[existingPlayerStart.id]).toEqual(existingPlayerStart);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().toolMode).toBe("select");
|
||||
expect(store.getState().document.entities[existingPlayerStart.id]).toMatchObject({
|
||||
position: {
|
||||
x: 4,
|
||||
y: 0,
|
||||
z: 1
|
||||
},
|
||||
yawDegrees: 180
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,352 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { BoxGeometry, PlaneGeometry } from "three";
|
||||
import { createModelInstance } from "../../src/assets/model-instances";
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { createPlayerStartEntity } from "../../src/entities/entity-instances";
|
||||
import { RapierCollisionWorld } from "../../src/runtime-three/rapier-collision-world";
|
||||
import { buildRuntimeSceneFromDocument } from "../../src/runtime-three/runtime-scene-build";
|
||||
import { createFixtureLoadedModelAssetFromGeometry } from "../helpers/model-collider-fixtures";
|
||||
describe("RapierCollisionWorld", () => {
|
||||
it("resolves first-person motion against brush and imported model colliders in one query path", async () => {
|
||||
const floorBrush = createBoxBrush({
|
||||
id: "brush-floor",
|
||||
center: {
|
||||
x: 0,
|
||||
y: -0.5,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 10,
|
||||
y: 1,
|
||||
z: 10
|
||||
}
|
||||
});
|
||||
const { asset, loadedAsset } = createFixtureLoadedModelAssetFromGeometry("asset-model-crate", new BoxGeometry(1, 1, 1));
|
||||
const crateInstance = createModelInstance({
|
||||
id: "model-instance-crate",
|
||||
assetId: asset.id,
|
||||
position: {
|
||||
x: 2,
|
||||
y: 0.5,
|
||||
z: 0
|
||||
},
|
||||
collision: {
|
||||
mode: "static",
|
||||
visible: true
|
||||
}
|
||||
});
|
||||
const runtimeScene = buildRuntimeSceneFromDocument({
|
||||
...createEmptySceneDocument({ name: "Brush And Model Collision Scene" }),
|
||||
assets: {
|
||||
[asset.id]: asset
|
||||
},
|
||||
brushes: {
|
||||
[floorBrush.id]: floorBrush
|
||||
},
|
||||
modelInstances: {
|
||||
[crateInstance.id]: crateInstance
|
||||
}
|
||||
}, {
|
||||
loadedModelAssets: {
|
||||
[asset.id]: loadedAsset
|
||||
}
|
||||
});
|
||||
const collisionWorld = await RapierCollisionWorld.create(runtimeScene.colliders, runtimeScene.playerCollider);
|
||||
try {
|
||||
const landing = collisionWorld.resolveFirstPersonMotion({
|
||||
x: 0,
|
||||
y: 2,
|
||||
z: 0
|
||||
}, {
|
||||
x: 0,
|
||||
y: -3,
|
||||
z: 0
|
||||
}, runtimeScene.playerCollider);
|
||||
expect(landing.grounded).toBe(true);
|
||||
expect(landing.feetPosition.y).toBeLessThan(0.02);
|
||||
const blocked = collisionWorld.resolveFirstPersonMotion({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}, {
|
||||
x: 3,
|
||||
y: 0,
|
||||
z: 0
|
||||
}, runtimeScene.playerCollider);
|
||||
expect(blocked.feetPosition.x).toBeLessThan(1.21);
|
||||
expect(blocked.feetPosition.y).toBeLessThan(0.02);
|
||||
expect(blocked.collidedAxes.x).toBe(true);
|
||||
}
|
||||
finally {
|
||||
collisionWorld.dispose();
|
||||
}
|
||||
});
|
||||
it("initializes and resolves first-person motion against terrain heightfield colliders", async () => {
|
||||
const terrainGeometry = new PlaneGeometry(8, 8, 4, 4);
|
||||
terrainGeometry.rotateX(-Math.PI / 2);
|
||||
const positionAttribute = terrainGeometry.getAttribute("position");
|
||||
for (let index = 0; index < positionAttribute.count; index += 1) {
|
||||
const x = positionAttribute.getX(index);
|
||||
const z = positionAttribute.getZ(index);
|
||||
positionAttribute.setY(index, 2 + x * 0.25 + z * 0.75);
|
||||
}
|
||||
positionAttribute.needsUpdate = true;
|
||||
terrainGeometry.computeVertexNormals();
|
||||
const { asset, loadedAsset } = createFixtureLoadedModelAssetFromGeometry("asset-model-terrain", terrainGeometry);
|
||||
const terrainInstance = createModelInstance({
|
||||
id: "model-instance-terrain",
|
||||
assetId: asset.id,
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
collision: {
|
||||
mode: "terrain",
|
||||
visible: true
|
||||
}
|
||||
});
|
||||
const runtimeScene = buildRuntimeSceneFromDocument({
|
||||
...createEmptySceneDocument({ name: "Terrain Collision Scene" }),
|
||||
assets: {
|
||||
[asset.id]: asset
|
||||
},
|
||||
modelInstances: {
|
||||
[terrainInstance.id]: terrainInstance
|
||||
}
|
||||
}, {
|
||||
loadedModelAssets: {
|
||||
[asset.id]: loadedAsset
|
||||
}
|
||||
});
|
||||
const collisionWorld = await RapierCollisionWorld.create(runtimeScene.colliders, runtimeScene.playerCollider);
|
||||
try {
|
||||
const highLanding = collisionWorld.resolveFirstPersonMotion({
|
||||
x: -2,
|
||||
y: 6,
|
||||
z: 2
|
||||
}, {
|
||||
x: 0,
|
||||
y: -8,
|
||||
z: 0
|
||||
}, runtimeScene.playerCollider);
|
||||
const lowLanding = collisionWorld.resolveFirstPersonMotion({
|
||||
x: 2,
|
||||
y: 6,
|
||||
z: -2
|
||||
}, {
|
||||
x: 0,
|
||||
y: -8,
|
||||
z: 0
|
||||
}, runtimeScene.playerCollider);
|
||||
expect(highLanding.grounded).toBe(true);
|
||||
expect(highLanding.feetPosition.y).toBeGreaterThan(2.9);
|
||||
expect(highLanding.feetPosition.y).toBeLessThan(3.1);
|
||||
expect(lowLanding.grounded).toBe(true);
|
||||
expect(lowLanding.feetPosition.y).toBeGreaterThan(0.9);
|
||||
expect(lowLanding.feetPosition.y).toBeLessThan(1.1);
|
||||
const traversed = collisionWorld.resolveFirstPersonMotion(highLanding.feetPosition, {
|
||||
x: -1,
|
||||
y: 0,
|
||||
z: 0
|
||||
}, runtimeScene.playerCollider);
|
||||
expect(traversed.feetPosition.x).toBeLessThan(-2.5);
|
||||
expect(traversed.collidedAxes.x).toBe(false);
|
||||
}
|
||||
finally {
|
||||
collisionWorld.dispose();
|
||||
}
|
||||
});
|
||||
it("resolves motion against freely rotated whitebox box colliders", async () => {
|
||||
const floorBrush = createBoxBrush({
|
||||
id: "brush-floor-rotated-wall",
|
||||
center: {
|
||||
x: 0,
|
||||
y: -0.5,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 10,
|
||||
y: 1,
|
||||
z: 10
|
||||
}
|
||||
});
|
||||
const wallBrush = createBoxBrush({
|
||||
id: "brush-wall-rotated",
|
||||
center: {
|
||||
x: 1.2,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 45,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 0.4,
|
||||
y: 2,
|
||||
z: 4
|
||||
}
|
||||
});
|
||||
const runtimeScene = buildRuntimeSceneFromDocument({
|
||||
...createEmptySceneDocument({ name: "Rotated Brush Collision Scene" }),
|
||||
brushes: {
|
||||
[floorBrush.id]: floorBrush,
|
||||
[wallBrush.id]: wallBrush
|
||||
}
|
||||
});
|
||||
const collisionWorld = await RapierCollisionWorld.create(runtimeScene.colliders, runtimeScene.playerCollider);
|
||||
try {
|
||||
const blocked = collisionWorld.resolveFirstPersonMotion({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}, {
|
||||
x: 2,
|
||||
y: 0,
|
||||
z: 0
|
||||
}, runtimeScene.playerCollider);
|
||||
expect(blocked.collidedAxes.x).toBe(true);
|
||||
expect(blocked.feetPosition.x).toBeLessThan(1.3);
|
||||
expect(blocked.feetPosition.z).toBeGreaterThan(0.25);
|
||||
expect(blocked.feetPosition.z).toBeLessThan(1.25);
|
||||
}
|
||||
finally {
|
||||
collisionWorld.dispose();
|
||||
}
|
||||
});
|
||||
it("uses the authored Player Start box collider in the Rapier motion path", async () => {
|
||||
const floorBrush = createBoxBrush({
|
||||
id: "brush-floor-box-player",
|
||||
center: {
|
||||
x: 0,
|
||||
y: -0.5,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 10,
|
||||
y: 1,
|
||||
z: 10
|
||||
}
|
||||
});
|
||||
const wallBrush = createBoxBrush({
|
||||
id: "brush-wall-box-player",
|
||||
center: {
|
||||
x: 1.2,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 0.4,
|
||||
y: 2,
|
||||
z: 4
|
||||
}
|
||||
});
|
||||
const playerStart = createPlayerStartEntity({
|
||||
id: "entity-player-start-box",
|
||||
collider: {
|
||||
mode: "box",
|
||||
eyeHeight: 1.4,
|
||||
capsuleRadius: 0.3,
|
||||
capsuleHeight: 1.8,
|
||||
boxSize: {
|
||||
x: 0.8,
|
||||
y: 1.6,
|
||||
z: 0.8
|
||||
}
|
||||
}
|
||||
});
|
||||
const runtimeScene = buildRuntimeSceneFromDocument({
|
||||
...createEmptySceneDocument({ name: "Box Player Collider Scene" }),
|
||||
brushes: {
|
||||
[floorBrush.id]: floorBrush,
|
||||
[wallBrush.id]: wallBrush
|
||||
},
|
||||
entities: {
|
||||
[playerStart.id]: playerStart
|
||||
}
|
||||
});
|
||||
const collisionWorld = await RapierCollisionWorld.create(runtimeScene.colliders, runtimeScene.playerCollider);
|
||||
try {
|
||||
const landing = collisionWorld.resolveFirstPersonMotion({
|
||||
x: 0,
|
||||
y: 2,
|
||||
z: 0
|
||||
}, {
|
||||
x: 0,
|
||||
y: -3,
|
||||
z: 0
|
||||
}, runtimeScene.playerCollider);
|
||||
expect(landing.grounded).toBe(true);
|
||||
expect(landing.feetPosition.y).toBeLessThan(0.02);
|
||||
const blocked = collisionWorld.resolveFirstPersonMotion(landing.feetPosition, {
|
||||
x: 2,
|
||||
y: 0,
|
||||
z: 0
|
||||
}, runtimeScene.playerCollider);
|
||||
expect(blocked.collidedAxes.x).toBe(true);
|
||||
expect(blocked.feetPosition.x).toBeLessThan(0.61);
|
||||
}
|
||||
finally {
|
||||
collisionWorld.dispose();
|
||||
}
|
||||
});
|
||||
it("supports authored Player Start collision mode none without world clipping", async () => {
|
||||
const wallBrush = createBoxBrush({
|
||||
id: "brush-wall-no-collision",
|
||||
center: {
|
||||
x: 0.5,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 0.4,
|
||||
y: 2,
|
||||
z: 4
|
||||
}
|
||||
});
|
||||
const playerStart = createPlayerStartEntity({
|
||||
id: "entity-player-start-none",
|
||||
collider: {
|
||||
mode: "none",
|
||||
eyeHeight: 1.6,
|
||||
capsuleRadius: 0.3,
|
||||
capsuleHeight: 1.8,
|
||||
boxSize: {
|
||||
x: 0.6,
|
||||
y: 1.8,
|
||||
z: 0.6
|
||||
}
|
||||
}
|
||||
});
|
||||
const runtimeScene = buildRuntimeSceneFromDocument({
|
||||
...createEmptySceneDocument({ name: "No Collision Player Scene" }),
|
||||
brushes: {
|
||||
[wallBrush.id]: wallBrush
|
||||
},
|
||||
entities: {
|
||||
[playerStart.id]: playerStart
|
||||
}
|
||||
});
|
||||
const collisionWorld = await RapierCollisionWorld.create(runtimeScene.colliders, runtimeScene.playerCollider);
|
||||
try {
|
||||
const moved = collisionWorld.resolveFirstPersonMotion({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}, {
|
||||
x: 2,
|
||||
y: 0,
|
||||
z: 0
|
||||
}, runtimeScene.playerCollider);
|
||||
expect(moved.collidedAxes.x).toBe(false);
|
||||
expect(moved.feetPosition.x).toBe(2);
|
||||
expect(moved.feetPosition.y).toBe(0);
|
||||
}
|
||||
finally {
|
||||
collisionWorld.dispose();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { computeSoundEmitterDistanceGain } from "../../src/runtime-three/runtime-audio-system";
|
||||
describe("computeSoundEmitterDistanceGain", () => {
|
||||
it("keeps full volume near the emitter and eases smoothly to silence at max distance", () => {
|
||||
expect(computeSoundEmitterDistanceGain(4, 6, 24)).toBe(1);
|
||||
expect(computeSoundEmitterDistanceGain(6, 6, 24)).toBe(1);
|
||||
expect(computeSoundEmitterDistanceGain(12, 6, 24)).toBeCloseTo(0.198, 3);
|
||||
expect(computeSoundEmitterDistanceGain(18, 6, 24)).toBeCloseTo(0.012, 3);
|
||||
expect(computeSoundEmitterDistanceGain(24, 6, 24)).toBe(0);
|
||||
expect(computeSoundEmitterDistanceGain(30, 6, 24)).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -1,377 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createPlayAnimationInteractionLink, createPlaySoundInteractionLink, createTeleportPlayerInteractionLink, createToggleVisibilityInteractionLink, createStopAnimationInteractionLink, createStopSoundInteractionLink } from "../../src/interactions/interaction-links";
|
||||
import { createDefaultWorldSettings } from "../../src/document/world-settings";
|
||||
import { RuntimeInteractionSystem } from "../../src/runtime-three/runtime-interaction-system";
|
||||
function createRuntimeSceneFixture() {
|
||||
return {
|
||||
world: {
|
||||
...createDefaultWorldSettings(),
|
||||
background: {
|
||||
mode: "solid",
|
||||
colorHex: "#000000"
|
||||
},
|
||||
ambientLight: {
|
||||
colorHex: "#ffffff",
|
||||
intensity: 1
|
||||
},
|
||||
sunLight: {
|
||||
colorHex: "#ffffff",
|
||||
intensity: 1,
|
||||
direction: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
brushes: [],
|
||||
volumes: {
|
||||
fog: [],
|
||||
water: []
|
||||
},
|
||||
colliders: [],
|
||||
sceneBounds: null,
|
||||
localLights: {
|
||||
pointLights: [],
|
||||
spotLights: []
|
||||
},
|
||||
modelInstances: [],
|
||||
entities: {
|
||||
playerStarts: [],
|
||||
soundEmitters: [
|
||||
{
|
||||
entityId: "entity-sound-lobby",
|
||||
position: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
audioAssetId: "asset-audio-lobby",
|
||||
volume: 0.75,
|
||||
refDistance: 6,
|
||||
maxDistance: 24,
|
||||
autoplay: false,
|
||||
loop: true
|
||||
}
|
||||
],
|
||||
triggerVolumes: [
|
||||
{
|
||||
entityId: "entity-trigger-main",
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 2
|
||||
},
|
||||
triggerOnEnter: true,
|
||||
triggerOnExit: true
|
||||
}
|
||||
],
|
||||
teleportTargets: [
|
||||
{
|
||||
entityId: "entity-teleport-main",
|
||||
position: {
|
||||
x: 8,
|
||||
y: 0,
|
||||
z: -4
|
||||
},
|
||||
yawDegrees: 180
|
||||
}
|
||||
],
|
||||
interactables: [
|
||||
{
|
||||
entityId: "entity-interactable-console",
|
||||
position: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 1
|
||||
},
|
||||
radius: 2,
|
||||
prompt: "Use Console",
|
||||
enabled: true
|
||||
},
|
||||
{
|
||||
entityId: "entity-interactable-disabled",
|
||||
position: {
|
||||
x: 0.25,
|
||||
y: 1,
|
||||
z: 1
|
||||
},
|
||||
radius: 2,
|
||||
prompt: "Disabled Prompt",
|
||||
enabled: false
|
||||
}
|
||||
]
|
||||
},
|
||||
interactionLinks: [],
|
||||
playerStart: null,
|
||||
playerCollider: {
|
||||
mode: "capsule",
|
||||
radius: 0.3,
|
||||
height: 1.8,
|
||||
eyeHeight: 1.6
|
||||
},
|
||||
spawn: {
|
||||
source: "fallback",
|
||||
entityId: null,
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
yawDegrees: 0
|
||||
}
|
||||
};
|
||||
}
|
||||
describe("RuntimeInteractionSystem", () => {
|
||||
it("dispatches teleport player on Trigger Volume enter", () => {
|
||||
const runtimeScene = createRuntimeSceneFixture();
|
||||
runtimeScene.interactionLinks = [
|
||||
createTeleportPlayerInteractionLink({
|
||||
id: "link-teleport",
|
||||
sourceEntityId: "entity-trigger-main",
|
||||
trigger: "enter",
|
||||
targetEntityId: "entity-teleport-main"
|
||||
})
|
||||
];
|
||||
const interactionSystem = new RuntimeInteractionSystem();
|
||||
const dispatches = [];
|
||||
interactionSystem.updatePlayerPosition({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}, runtimeScene, {
|
||||
teleportPlayer: (target, link) => {
|
||||
dispatches.push(`${link.id}:${target.entityId}:${target.position.x}`);
|
||||
},
|
||||
toggleBrushVisibility: () => {
|
||||
dispatches.push("toggle");
|
||||
},
|
||||
playAnimation: () => { },
|
||||
stopAnimation: () => { },
|
||||
playSound: () => { },
|
||||
stopSound: () => { }
|
||||
});
|
||||
interactionSystem.updatePlayerPosition({
|
||||
x: 0.25,
|
||||
y: 0,
|
||||
z: 0.25
|
||||
}, runtimeScene, {
|
||||
teleportPlayer: (target, link) => {
|
||||
dispatches.push(`${link.id}:${target.entityId}:${target.position.x}`);
|
||||
},
|
||||
toggleBrushVisibility: () => {
|
||||
dispatches.push("toggle");
|
||||
},
|
||||
playAnimation: () => { },
|
||||
stopAnimation: () => { },
|
||||
playSound: () => { },
|
||||
stopSound: () => { }
|
||||
});
|
||||
expect(dispatches).toEqual(["link-teleport:entity-teleport-main:8"]);
|
||||
});
|
||||
it("dispatches animation actions with the authored target model instance and clip", () => {
|
||||
const runtimeScene = createRuntimeSceneFixture();
|
||||
runtimeScene.interactionLinks = [
|
||||
createPlayAnimationInteractionLink({
|
||||
id: "link-play-animation",
|
||||
sourceEntityId: "entity-interactable-console",
|
||||
trigger: "click",
|
||||
targetModelInstanceId: "model-instance-animated",
|
||||
clipName: "Walk",
|
||||
loop: false
|
||||
}),
|
||||
createStopAnimationInteractionLink({
|
||||
id: "link-stop-animation",
|
||||
sourceEntityId: "entity-interactable-console",
|
||||
trigger: "click",
|
||||
targetModelInstanceId: "model-instance-animated"
|
||||
})
|
||||
];
|
||||
const interactionSystem = new RuntimeInteractionSystem();
|
||||
const dispatches = [];
|
||||
interactionSystem.dispatchClickInteraction("entity-interactable-console", runtimeScene, {
|
||||
teleportPlayer: () => {
|
||||
throw new Error("Teleport should not dispatch in this fixture.");
|
||||
},
|
||||
toggleBrushVisibility: () => {
|
||||
throw new Error("Visibility should not dispatch in this fixture.");
|
||||
},
|
||||
playAnimation: (instanceId, clipName, loop, link) => {
|
||||
dispatches.push(`${link.id}:${instanceId}:${clipName}:${loop === false ? "once" : "loop"}`);
|
||||
},
|
||||
stopAnimation: (instanceId, link) => {
|
||||
dispatches.push(`${link.id}:${instanceId}`);
|
||||
},
|
||||
playSound: () => { },
|
||||
stopSound: () => { }
|
||||
});
|
||||
expect(dispatches).toEqual([
|
||||
"link-play-animation:model-instance-animated:Walk:once",
|
||||
"link-stop-animation:model-instance-animated"
|
||||
]);
|
||||
});
|
||||
it("dispatches visibility actions only when exiting an occupied Trigger Volume", () => {
|
||||
const runtimeScene = createRuntimeSceneFixture();
|
||||
runtimeScene.interactionLinks = [
|
||||
createToggleVisibilityInteractionLink({
|
||||
id: "link-hide-door",
|
||||
sourceEntityId: "entity-trigger-main",
|
||||
trigger: "exit",
|
||||
targetBrushId: "brush-door",
|
||||
visible: false
|
||||
})
|
||||
];
|
||||
const interactionSystem = new RuntimeInteractionSystem();
|
||||
const dispatches = [];
|
||||
interactionSystem.updatePlayerPosition({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}, runtimeScene, {
|
||||
teleportPlayer: () => {
|
||||
throw new Error("Teleport should not dispatch in this fixture.");
|
||||
},
|
||||
toggleBrushVisibility: (brushId, visible) => {
|
||||
dispatches.push({
|
||||
brushId,
|
||||
visible
|
||||
});
|
||||
},
|
||||
playAnimation: () => { },
|
||||
stopAnimation: () => { },
|
||||
playSound: () => { },
|
||||
stopSound: () => { }
|
||||
});
|
||||
interactionSystem.updatePlayerPosition({
|
||||
x: 3,
|
||||
y: 0,
|
||||
z: 0
|
||||
}, runtimeScene, {
|
||||
teleportPlayer: () => {
|
||||
throw new Error("Teleport should not dispatch in this fixture.");
|
||||
},
|
||||
toggleBrushVisibility: (brushId, visible) => {
|
||||
dispatches.push({
|
||||
brushId,
|
||||
visible
|
||||
});
|
||||
},
|
||||
playAnimation: () => { },
|
||||
stopAnimation: () => { },
|
||||
playSound: () => { },
|
||||
stopSound: () => { }
|
||||
});
|
||||
expect(dispatches).toEqual([
|
||||
{
|
||||
brushId: "brush-door",
|
||||
visible: false
|
||||
}
|
||||
]);
|
||||
});
|
||||
it("shows a click prompt only for enabled interactables with authored click links inside range", () => {
|
||||
const runtimeScene = createRuntimeSceneFixture();
|
||||
runtimeScene.interactionLinks = [
|
||||
createTeleportPlayerInteractionLink({
|
||||
id: "link-click-teleport",
|
||||
sourceEntityId: "entity-interactable-console",
|
||||
trigger: "click",
|
||||
targetEntityId: "entity-teleport-main"
|
||||
})
|
||||
];
|
||||
const interactionSystem = new RuntimeInteractionSystem();
|
||||
expect(interactionSystem.resolveClickInteractionPrompt({
|
||||
x: 0,
|
||||
y: 1.6,
|
||||
z: 0
|
||||
}, {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 1
|
||||
}, runtimeScene)).toEqual({
|
||||
sourceEntityId: "entity-interactable-console",
|
||||
prompt: "Use Console",
|
||||
distance: expect.any(Number),
|
||||
range: 2
|
||||
});
|
||||
expect(interactionSystem.resolveClickInteractionPrompt({
|
||||
x: 0,
|
||||
y: 1.6,
|
||||
z: 0
|
||||
}, {
|
||||
x: 1,
|
||||
y: 0,
|
||||
z: 0
|
||||
}, runtimeScene)).toBeNull();
|
||||
});
|
||||
it("dispatches click actions for the targeted Interactable", () => {
|
||||
const runtimeScene = createRuntimeSceneFixture();
|
||||
runtimeScene.interactionLinks = [
|
||||
createTeleportPlayerInteractionLink({
|
||||
id: "link-click-teleport",
|
||||
sourceEntityId: "entity-interactable-console",
|
||||
trigger: "click",
|
||||
targetEntityId: "entity-teleport-main"
|
||||
})
|
||||
];
|
||||
const interactionSystem = new RuntimeInteractionSystem();
|
||||
const dispatches = [];
|
||||
interactionSystem.dispatchClickInteraction("entity-interactable-console", runtimeScene, {
|
||||
teleportPlayer: (target, link) => {
|
||||
dispatches.push(`${link.id}:${target.entityId}:${target.position.x}`);
|
||||
},
|
||||
toggleBrushVisibility: () => {
|
||||
throw new Error("Visibility should not dispatch for this click fixture.");
|
||||
},
|
||||
playAnimation: () => { },
|
||||
stopAnimation: () => { },
|
||||
playSound: () => { },
|
||||
stopSound: () => { }
|
||||
});
|
||||
expect(dispatches).toEqual(["link-click-teleport:entity-teleport-main:8"]);
|
||||
});
|
||||
it("dispatches play and stop sound actions for the targeted Sound Emitter", () => {
|
||||
const runtimeScene = createRuntimeSceneFixture();
|
||||
runtimeScene.interactionLinks = [
|
||||
createPlaySoundInteractionLink({
|
||||
id: "link-play-sound",
|
||||
sourceEntityId: "entity-interactable-console",
|
||||
trigger: "click",
|
||||
targetSoundEmitterId: "entity-sound-lobby"
|
||||
}),
|
||||
createStopSoundInteractionLink({
|
||||
id: "link-stop-sound",
|
||||
sourceEntityId: "entity-interactable-console",
|
||||
trigger: "click",
|
||||
targetSoundEmitterId: "entity-sound-lobby"
|
||||
})
|
||||
];
|
||||
const interactionSystem = new RuntimeInteractionSystem();
|
||||
const dispatches = [];
|
||||
interactionSystem.dispatchClickInteraction("entity-interactable-console", runtimeScene, {
|
||||
teleportPlayer: () => {
|
||||
throw new Error("Teleport should not dispatch in this fixture.");
|
||||
},
|
||||
toggleBrushVisibility: () => {
|
||||
throw new Error("Visibility should not dispatch in this fixture.");
|
||||
},
|
||||
playAnimation: () => {
|
||||
throw new Error("Animation should not dispatch in this fixture.");
|
||||
},
|
||||
stopAnimation: () => {
|
||||
throw new Error("Animation should not dispatch in this fixture.");
|
||||
},
|
||||
playSound: (soundEmitterId, link) => {
|
||||
dispatches.push(`${link.id}:${soundEmitterId}`);
|
||||
},
|
||||
stopSound: (soundEmitterId, link) => {
|
||||
dispatches.push(`${link.id}:${soundEmitterId}`);
|
||||
}
|
||||
});
|
||||
expect(dispatches).toEqual(["link-play-sound:entity-sound-lobby", "link-stop-sound:entity-sound-lobby"]);
|
||||
});
|
||||
});
|
||||
@@ -1,85 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { BoxGeometry } from "three";
|
||||
import { createModelInstance } from "../../src/assets/model-instances";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { validateRuntimeSceneBuild } from "../../src/runtime-three/runtime-scene-validation";
|
||||
import { createFixtureLoadedModelAssetFromGeometry } from "../helpers/model-collider-fixtures";
|
||||
describe("validateRuntimeSceneBuild", () => {
|
||||
it("reports missing loaded geometry for collider modes that depend on imported mesh data", () => {
|
||||
const { asset } = createFixtureLoadedModelAssetFromGeometry("asset-model-static-validation", new BoxGeometry(1, 1, 1));
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-static-validation",
|
||||
assetId: asset.id,
|
||||
collision: {
|
||||
mode: "static",
|
||||
visible: false
|
||||
}
|
||||
});
|
||||
const validation = validateRuntimeSceneBuild({
|
||||
...createEmptySceneDocument({ name: "Missing Model Geometry Scene" }),
|
||||
assets: {
|
||||
[asset.id]: asset
|
||||
},
|
||||
modelInstances: {
|
||||
[modelInstance.id]: modelInstance
|
||||
}
|
||||
}, {
|
||||
navigationMode: "orbitVisitor",
|
||||
loadedModelAssets: {}
|
||||
});
|
||||
expect(validation.errors.map((diagnostic) => diagnostic.code)).toContain("missing-model-collider-geometry");
|
||||
});
|
||||
it("fails terrain mode clearly when the source mesh is incompatible with the heightfield path", () => {
|
||||
const { asset, loadedAsset } = createFixtureLoadedModelAssetFromGeometry("asset-model-terrain-validation", new BoxGeometry(1, 1, 1));
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-terrain-validation",
|
||||
assetId: asset.id,
|
||||
collision: {
|
||||
mode: "terrain",
|
||||
visible: true
|
||||
}
|
||||
});
|
||||
const validation = validateRuntimeSceneBuild({
|
||||
...createEmptySceneDocument({ name: "Invalid Terrain Scene" }),
|
||||
assets: {
|
||||
[asset.id]: asset
|
||||
},
|
||||
modelInstances: {
|
||||
[modelInstance.id]: modelInstance
|
||||
}
|
||||
}, {
|
||||
navigationMode: "orbitVisitor",
|
||||
loadedModelAssets: {
|
||||
[asset.id]: loadedAsset
|
||||
}
|
||||
});
|
||||
expect(validation.errors.map((diagnostic) => diagnostic.code)).toContain("unsupported-terrain-model-collider");
|
||||
});
|
||||
it("warns that dynamic collision currently participates as fixed queryable world geometry", () => {
|
||||
const { asset, loadedAsset } = createFixtureLoadedModelAssetFromGeometry("asset-model-dynamic-validation", new BoxGeometry(1, 1, 1));
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-dynamic-validation",
|
||||
assetId: asset.id,
|
||||
collision: {
|
||||
mode: "dynamic",
|
||||
visible: false
|
||||
}
|
||||
});
|
||||
const validation = validateRuntimeSceneBuild({
|
||||
...createEmptySceneDocument({ name: "Dynamic Collider Scene" }),
|
||||
assets: {
|
||||
[asset.id]: asset
|
||||
},
|
||||
modelInstances: {
|
||||
[modelInstance.id]: modelInstance
|
||||
}
|
||||
}, {
|
||||
navigationMode: "orbitVisitor",
|
||||
loadedModelAssets: {
|
||||
[asset.id]: loadedAsset
|
||||
}
|
||||
});
|
||||
expect(validation.errors).toEqual([]);
|
||||
expect(validation.warnings.map((diagnostic) => diagnostic.code)).toContain("dynamic-model-collider-fixed-query-only");
|
||||
});
|
||||
});
|
||||
@@ -1,472 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { validateSceneDocument } from "../../src/document/scene-document-validation";
|
||||
import { createPointLightEntity, createInteractableEntity, createPlayerStartEntity, createSoundEmitterEntity, createSpotLightEntity, createTeleportTargetEntity, createTriggerVolumeEntity } from "../../src/entities/entity-instances";
|
||||
import { createProjectAssetStorageKey } from "../../src/assets/project-assets";
|
||||
describe("validateSceneDocument", () => {
|
||||
it("accepts a valid first-room document", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-room-shell"
|
||||
});
|
||||
const playerStart = createPlayerStartEntity({
|
||||
id: "entity-player-start-main"
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument({ name: "First Room" }),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
},
|
||||
entities: {
|
||||
[playerStart.id]: playerStart
|
||||
}
|
||||
};
|
||||
const validation = validateSceneDocument(document);
|
||||
expect(validation.errors).toEqual([]);
|
||||
expect(validation.warnings).toEqual([]);
|
||||
});
|
||||
it("detects duplicate authored ids across collections", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "shared-room-id"
|
||||
});
|
||||
const playerStart = createPlayerStartEntity({
|
||||
id: "shared-room-id"
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
},
|
||||
entities: {
|
||||
"entity-player-start-main": playerStart
|
||||
}
|
||||
};
|
||||
const validation = validateSceneDocument(document);
|
||||
expect(validation.errors).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "entity-id-mismatch"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "duplicate-authored-id"
|
||||
})
|
||||
]));
|
||||
});
|
||||
it("detects invalid box sizes and missing material references", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-invalid"
|
||||
});
|
||||
brush.rotationDegrees.y = Number.NaN;
|
||||
brush.size.x = 0;
|
||||
brush.faces.posZ.materialId = "material-that-does-not-exist";
|
||||
const validation = validateSceneDocument({
|
||||
...createEmptySceneDocument(),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
});
|
||||
expect(validation.errors).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "invalid-box-rotation",
|
||||
path: "brushes.brush-invalid.rotationDegrees"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-box-size",
|
||||
path: "brushes.brush-invalid.size"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "missing-material-ref",
|
||||
path: "brushes.brush-invalid.faces.posZ.materialId"
|
||||
})
|
||||
]));
|
||||
});
|
||||
it("detects invalid Player Start values", () => {
|
||||
const validation = validateSceneDocument({
|
||||
...createEmptySceneDocument(),
|
||||
entities: {
|
||||
"entity-player-start-main": {
|
||||
id: "entity-player-start-main",
|
||||
kind: "playerStart",
|
||||
position: {
|
||||
x: 0,
|
||||
y: Number.NaN,
|
||||
z: 0
|
||||
},
|
||||
yawDegrees: Number.NaN,
|
||||
collider: {
|
||||
mode: "capsule",
|
||||
eyeHeight: 3,
|
||||
capsuleRadius: 0.4,
|
||||
capsuleHeight: 0.5,
|
||||
boxSize: {
|
||||
x: 0.6,
|
||||
y: -1,
|
||||
z: 0.6
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
expect(validation.errors).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "invalid-player-start-position"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-player-start-yaw"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-player-start-capsule-proportions"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-player-start-box-size"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-player-start-eye-height"
|
||||
})
|
||||
]));
|
||||
});
|
||||
it("detects invalid typed entity values across the entity registry", () => {
|
||||
const soundEmitter = createSoundEmitterEntity({
|
||||
id: "entity-sound-main"
|
||||
});
|
||||
const triggerVolume = createTriggerVolumeEntity({
|
||||
id: "entity-trigger-main"
|
||||
});
|
||||
const teleportTarget = createTeleportTargetEntity({
|
||||
id: "entity-teleport-main"
|
||||
});
|
||||
const interactable = createInteractableEntity({
|
||||
id: "entity-interactable-main"
|
||||
});
|
||||
const validation = validateSceneDocument({
|
||||
...createEmptySceneDocument(),
|
||||
entities: {
|
||||
[soundEmitter.id]: {
|
||||
...soundEmitter,
|
||||
refDistance: Number.NaN
|
||||
},
|
||||
[triggerVolume.id]: {
|
||||
...triggerVolume,
|
||||
size: {
|
||||
x: 0,
|
||||
y: 2,
|
||||
z: 2
|
||||
}
|
||||
},
|
||||
[teleportTarget.id]: {
|
||||
...teleportTarget,
|
||||
yawDegrees: Number.POSITIVE_INFINITY
|
||||
},
|
||||
[interactable.id]: {
|
||||
...interactable,
|
||||
prompt: " ",
|
||||
enabled: "yes"
|
||||
}
|
||||
}
|
||||
});
|
||||
expect(validation.errors).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "invalid-sound-emitter-ref-distance"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-trigger-volume-size"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-teleport-target-yaw"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-interactable-prompt"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-interactable-enabled"
|
||||
})
|
||||
]));
|
||||
});
|
||||
it("detects missing and invalid audio asset references on Sound Emitters", () => {
|
||||
const audioAsset = {
|
||||
id: "asset-audio-main",
|
||||
kind: "audio",
|
||||
sourceName: "lobby-loop.ogg",
|
||||
mimeType: "audio/ogg",
|
||||
storageKey: createProjectAssetStorageKey("asset-audio-main"),
|
||||
byteLength: 4096,
|
||||
metadata: {
|
||||
kind: "audio",
|
||||
durationSeconds: 4.25,
|
||||
channelCount: 2,
|
||||
sampleRateHz: 48000,
|
||||
warnings: []
|
||||
}
|
||||
};
|
||||
const modelAsset = {
|
||||
id: "asset-model-main",
|
||||
kind: "model",
|
||||
sourceName: "fixture.glb",
|
||||
mimeType: "model/gltf-binary",
|
||||
storageKey: createProjectAssetStorageKey("asset-model-main"),
|
||||
byteLength: 128,
|
||||
metadata: {
|
||||
kind: "model",
|
||||
format: "glb",
|
||||
sceneName: null,
|
||||
nodeCount: 1,
|
||||
meshCount: 1,
|
||||
materialNames: [],
|
||||
textureNames: [],
|
||||
animationNames: [],
|
||||
boundingBox: null,
|
||||
warnings: []
|
||||
}
|
||||
};
|
||||
const missingAudioEmitter = createSoundEmitterEntity({
|
||||
id: "entity-sound-missing",
|
||||
audioAssetId: "asset-missing-audio"
|
||||
});
|
||||
const wrongKindAudioEmitter = createSoundEmitterEntity({
|
||||
id: "entity-sound-wrong-kind",
|
||||
audioAssetId: modelAsset.id
|
||||
});
|
||||
const validAudioEmitter = createSoundEmitterEntity({
|
||||
id: "entity-sound-valid",
|
||||
audioAssetId: audioAsset.id
|
||||
});
|
||||
const validation = validateSceneDocument({
|
||||
...createEmptySceneDocument(),
|
||||
assets: {
|
||||
[audioAsset.id]: audioAsset,
|
||||
[modelAsset.id]: modelAsset
|
||||
},
|
||||
entities: {
|
||||
[missingAudioEmitter.id]: missingAudioEmitter,
|
||||
[wrongKindAudioEmitter.id]: wrongKindAudioEmitter,
|
||||
[validAudioEmitter.id]: validAudioEmitter
|
||||
}
|
||||
});
|
||||
expect(validation.errors).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "missing-sound-emitter-audio-asset",
|
||||
path: "entities.entity-sound-missing.audioAssetId"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-sound-emitter-audio-asset-kind",
|
||||
path: "entities.entity-sound-wrong-kind.audioAssetId"
|
||||
})
|
||||
]));
|
||||
});
|
||||
it("accepts authored point and spot lights with an active image background asset", () => {
|
||||
const imageAsset = {
|
||||
id: "asset-background-panorama",
|
||||
kind: "image",
|
||||
sourceName: "skybox-panorama.svg",
|
||||
mimeType: "image/svg+xml",
|
||||
storageKey: createProjectAssetStorageKey("asset-background-panorama"),
|
||||
byteLength: 2048,
|
||||
metadata: {
|
||||
kind: "image",
|
||||
width: 512,
|
||||
height: 256,
|
||||
hasAlpha: false,
|
||||
warnings: ["Background images work best as a 2:1 equirectangular panorama."]
|
||||
}
|
||||
};
|
||||
const pointLight = createPointLightEntity({
|
||||
id: "entity-point-light-main",
|
||||
position: {
|
||||
x: 1,
|
||||
y: 3,
|
||||
z: -2
|
||||
}
|
||||
});
|
||||
const spotLight = createSpotLightEntity({
|
||||
id: "entity-spot-light-main",
|
||||
position: {
|
||||
x: -1,
|
||||
y: 4,
|
||||
z: 2
|
||||
},
|
||||
direction: {
|
||||
x: 0.25,
|
||||
y: -1,
|
||||
z: 0.15
|
||||
}
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
assets: {
|
||||
[imageAsset.id]: imageAsset
|
||||
},
|
||||
entities: {
|
||||
[pointLight.id]: pointLight,
|
||||
[spotLight.id]: spotLight
|
||||
}
|
||||
};
|
||||
document.world.background = {
|
||||
mode: "image",
|
||||
assetId: imageAsset.id,
|
||||
environmentIntensity: 0.5
|
||||
};
|
||||
const validation = validateSceneDocument(document);
|
||||
expect(validation.errors).toEqual([]);
|
||||
});
|
||||
it("detects invalid local light values and missing image background assets", () => {
|
||||
const pointLight = createPointLightEntity({
|
||||
id: "entity-point-light-invalid"
|
||||
});
|
||||
pointLight.colorHex = "not-a-color";
|
||||
pointLight.intensity = -1;
|
||||
pointLight.distance = 0;
|
||||
const spotLight = createSpotLightEntity({
|
||||
id: "entity-spot-light-invalid"
|
||||
});
|
||||
spotLight.direction = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
};
|
||||
spotLight.distance = -2;
|
||||
spotLight.angleDegrees = 180;
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
entities: {
|
||||
[pointLight.id]: pointLight,
|
||||
[spotLight.id]: spotLight
|
||||
}
|
||||
};
|
||||
document.world.background = {
|
||||
mode: "image",
|
||||
assetId: "asset-missing-background",
|
||||
environmentIntensity: 0.5
|
||||
};
|
||||
const validation = validateSceneDocument(document);
|
||||
expect(validation.errors).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "invalid-point-light-color"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-point-light-intensity"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-point-light-distance"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-spot-light-direction"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-spot-light-distance"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-spot-light-angle"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "missing-world-background-asset"
|
||||
})
|
||||
]));
|
||||
});
|
||||
it("detects invalid world lighting and background settings", () => {
|
||||
const document = createEmptySceneDocument();
|
||||
document.world.background = {
|
||||
mode: "verticalGradient",
|
||||
topColorHex: "sky-blue",
|
||||
bottomColorHex: "#18212b"
|
||||
};
|
||||
document.world.ambientLight.intensity = -0.25;
|
||||
document.world.sunLight.direction = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
};
|
||||
const validation = validateSceneDocument(document);
|
||||
expect(validation.errors).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "invalid-world-background-top-color",
|
||||
path: "world.background.topColorHex"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-world-ambient-intensity",
|
||||
path: "world.ambientLight.intensity"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-world-sun-direction",
|
||||
path: "world.sunLight.direction"
|
||||
})
|
||||
]));
|
||||
});
|
||||
it("detects invalid advanced rendering settings", () => {
|
||||
const document = createEmptySceneDocument();
|
||||
document.world.advancedRendering = {
|
||||
...document.world.advancedRendering,
|
||||
enabled: true,
|
||||
shadows: {
|
||||
...document.world.advancedRendering.shadows,
|
||||
mapSize: 3000,
|
||||
type: "ultra",
|
||||
bias: Number.NaN
|
||||
},
|
||||
ambientOcclusion: {
|
||||
...document.world.advancedRendering.ambientOcclusion,
|
||||
samples: 0
|
||||
},
|
||||
bloom: {
|
||||
...document.world.advancedRendering.bloom,
|
||||
intensity: -0.25,
|
||||
threshold: -1,
|
||||
radius: -0.5
|
||||
},
|
||||
toneMapping: {
|
||||
mode: "filmic",
|
||||
exposure: 0
|
||||
},
|
||||
depthOfField: {
|
||||
...document.world.advancedRendering.depthOfField,
|
||||
focalLength: 0,
|
||||
bokehScale: -2
|
||||
}
|
||||
};
|
||||
const validation = validateSceneDocument(document);
|
||||
expect(validation.errors).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "invalid-advanced-rendering-shadow-map-size",
|
||||
path: "world.advancedRendering.shadows.mapSize"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-advanced-rendering-shadow-type",
|
||||
path: "world.advancedRendering.shadows.type"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-advanced-rendering-shadow-bias",
|
||||
path: "world.advancedRendering.shadows.bias"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-advanced-rendering-ao-samples",
|
||||
path: "world.advancedRendering.ambientOcclusion.samples"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-advanced-rendering-bloom-intensity",
|
||||
path: "world.advancedRendering.bloom.intensity"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-advanced-rendering-bloom-threshold",
|
||||
path: "world.advancedRendering.bloom.threshold"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-advanced-rendering-bloom-radius",
|
||||
path: "world.advancedRendering.bloom.radius"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-advanced-rendering-tone-mapping-mode",
|
||||
path: "world.advancedRendering.toneMapping.mode"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-advanced-rendering-tone-mapping-exposure",
|
||||
path: "world.advancedRendering.toneMapping.exposure"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-advanced-rendering-dof-focal-length",
|
||||
path: "world.advancedRendering.depthOfField.focalLength"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "invalid-advanced-rendering-dof-bokeh-scale",
|
||||
path: "world.advancedRendering.depthOfField.bokehScale"
|
||||
})
|
||||
]));
|
||||
});
|
||||
});
|
||||
@@ -1,581 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createEditorStore } from "../../src/app/editor-store";
|
||||
import { createModelInstance } from "../../src/assets/model-instances";
|
||||
import { createProjectAssetStorageKey } from "../../src/assets/project-assets";
|
||||
import { createCommitTransformSessionCommand } from "../../src/commands/commit-transform-session-command";
|
||||
import { createTransformSession, resolveTransformTarget, supportsTransformAxisConstraint, supportsTransformOperation } from "../../src/core/transform-session";
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { createPlayerStartEntity } from "../../src/entities/entity-instances";
|
||||
const modelAsset = {
|
||||
id: "asset-model-transform-fixture",
|
||||
kind: "model",
|
||||
sourceName: "transform-fixture.glb",
|
||||
mimeType: "model/gltf-binary",
|
||||
storageKey: createProjectAssetStorageKey("asset-model-transform-fixture"),
|
||||
byteLength: 64,
|
||||
metadata: {
|
||||
kind: "model",
|
||||
format: "glb",
|
||||
sceneName: "Transform Fixture",
|
||||
nodeCount: 1,
|
||||
meshCount: 1,
|
||||
materialNames: [],
|
||||
textureNames: [],
|
||||
animationNames: [],
|
||||
boundingBox: {
|
||||
min: {
|
||||
x: -0.5,
|
||||
y: 0,
|
||||
z: -0.5
|
||||
},
|
||||
max: {
|
||||
x: 0.5,
|
||||
y: 1,
|
||||
z: 0.5
|
||||
},
|
||||
size: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 1
|
||||
}
|
||||
},
|
||||
warnings: []
|
||||
}
|
||||
};
|
||||
describe("transform session commit commands", () => {
|
||||
it("resolves component transform targets in matching mode and enforces operation support", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-main"
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
};
|
||||
const faceWrongModeResolved = resolveTransformTarget(document, {
|
||||
kind: "brushFace",
|
||||
brushId: brush.id,
|
||||
faceId: "posZ"
|
||||
});
|
||||
const faceResolved = resolveTransformTarget(document, {
|
||||
kind: "brushFace",
|
||||
brushId: brush.id,
|
||||
faceId: "posZ"
|
||||
}, "face");
|
||||
const edgeResolved = resolveTransformTarget(document, {
|
||||
kind: "brushEdge",
|
||||
brushId: brush.id,
|
||||
edgeId: "edgeX_posY_negZ"
|
||||
}, "edge");
|
||||
const vertexResolved = resolveTransformTarget(document, {
|
||||
kind: "brushVertex",
|
||||
brushId: brush.id,
|
||||
vertexId: "posX_posY_negZ"
|
||||
}, "vertex");
|
||||
const faceModeBrushResolved = resolveTransformTarget(document, {
|
||||
kind: "brushes",
|
||||
ids: [brush.id]
|
||||
}, "face");
|
||||
const objectResolved = resolveTransformTarget(document, {
|
||||
kind: "brushes",
|
||||
ids: [brush.id]
|
||||
});
|
||||
expect(faceWrongModeResolved.target).toBeNull();
|
||||
expect(faceWrongModeResolved.message).toContain("Face mode");
|
||||
expect(faceResolved.target).toMatchObject({
|
||||
kind: "brushFace",
|
||||
brushId: brush.id,
|
||||
faceId: "posZ"
|
||||
});
|
||||
expect(edgeResolved.target).toMatchObject({
|
||||
kind: "brushEdge",
|
||||
brushId: brush.id,
|
||||
edgeId: "edgeX_posY_negZ"
|
||||
});
|
||||
expect(vertexResolved.target).toMatchObject({
|
||||
kind: "brushVertex",
|
||||
brushId: brush.id,
|
||||
vertexId: "posX_posY_negZ"
|
||||
});
|
||||
expect(faceModeBrushResolved.target).toBeNull();
|
||||
expect(faceModeBrushResolved.message).toContain("Object mode");
|
||||
expect(objectResolved.target).toMatchObject({
|
||||
kind: "brush",
|
||||
brushId: brush.id,
|
||||
initialCenter: brush.center,
|
||||
initialRotationDegrees: brush.rotationDegrees,
|
||||
initialSize: brush.size
|
||||
});
|
||||
expect(objectResolved.target).not.toBeNull();
|
||||
expect(supportsTransformOperation(objectResolved.target, "translate")).toBe(true);
|
||||
expect(supportsTransformOperation(objectResolved.target, "rotate")).toBe(true);
|
||||
expect(supportsTransformOperation(objectResolved.target, "scale")).toBe(true);
|
||||
expect(supportsTransformOperation(faceResolved.target, "translate")).toBe(true);
|
||||
expect(supportsTransformOperation(faceResolved.target, "rotate")).toBe(true);
|
||||
expect(supportsTransformOperation(faceResolved.target, "scale")).toBe(true);
|
||||
expect(supportsTransformOperation(vertexResolved.target, "translate")).toBe(true);
|
||||
expect(supportsTransformOperation(vertexResolved.target, "rotate")).toBe(false);
|
||||
expect(supportsTransformOperation(vertexResolved.target, "scale")).toBe(false);
|
||||
});
|
||||
it("applies axis-constraint rules across object and component transform sessions", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-axis-rules"
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
};
|
||||
const faceTarget = resolveTransformTarget(document, {
|
||||
kind: "brushFace",
|
||||
brushId: brush.id,
|
||||
faceId: "posX"
|
||||
}, "face").target;
|
||||
const edgeTarget = resolveTransformTarget(document, {
|
||||
kind: "brushEdge",
|
||||
brushId: brush.id,
|
||||
edgeId: "edgeY_posX_posZ"
|
||||
}, "edge").target;
|
||||
const vertexTarget = resolveTransformTarget(document, {
|
||||
kind: "brushVertex",
|
||||
brushId: brush.id,
|
||||
vertexId: "posX_posY_posZ"
|
||||
}, "vertex").target;
|
||||
if (faceTarget === null || faceTarget.kind !== "brushFace") {
|
||||
throw new Error("Expected a face transform target.");
|
||||
}
|
||||
if (edgeTarget === null || edgeTarget.kind !== "brushEdge") {
|
||||
throw new Error("Expected an edge transform target.");
|
||||
}
|
||||
if (vertexTarget === null || vertexTarget.kind !== "brushVertex") {
|
||||
throw new Error("Expected a vertex transform target.");
|
||||
}
|
||||
const faceRotateSession = createTransformSession({
|
||||
source: "keyboard",
|
||||
sourcePanelId: "topLeft",
|
||||
operation: "rotate",
|
||||
target: faceTarget
|
||||
});
|
||||
const edgeScaleSession = createTransformSession({
|
||||
source: "keyboard",
|
||||
sourcePanelId: "topLeft",
|
||||
operation: "scale",
|
||||
target: edgeTarget
|
||||
});
|
||||
const vertexTranslateSession = createTransformSession({
|
||||
source: "keyboard",
|
||||
sourcePanelId: "topLeft",
|
||||
operation: "translate",
|
||||
target: vertexTarget
|
||||
});
|
||||
expect(supportsTransformAxisConstraint(faceRotateSession, "x")).toBe(true);
|
||||
expect(supportsTransformAxisConstraint(faceRotateSession, "y")).toBe(false);
|
||||
expect(supportsTransformAxisConstraint(faceRotateSession, "z")).toBe(false);
|
||||
expect(supportsTransformAxisConstraint(edgeScaleSession, "x")).toBe(true);
|
||||
expect(supportsTransformAxisConstraint(edgeScaleSession, "y")).toBe(false);
|
||||
expect(supportsTransformAxisConstraint(edgeScaleSession, "z")).toBe(true);
|
||||
expect(supportsTransformAxisConstraint(vertexTranslateSession, "x")).toBe(true);
|
||||
expect(supportsTransformAxisConstraint(vertexTranslateSession, "y")).toBe(true);
|
||||
expect(supportsTransformAxisConstraint(vertexTranslateSession, "z")).toBe(true);
|
||||
});
|
||||
it("commits whitebox box rotate and scale transforms with undo and redo", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-transform-main",
|
||||
center: {
|
||||
x: 1.25,
|
||||
y: 1.5,
|
||||
z: -0.75
|
||||
},
|
||||
size: {
|
||||
x: 2.5,
|
||||
y: 2,
|
||||
z: 4
|
||||
}
|
||||
});
|
||||
const store = createEditorStore({
|
||||
initialDocument: {
|
||||
...createEmptySceneDocument({ name: "Brush Transform Fixture" }),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
}
|
||||
});
|
||||
const target = resolveTransformTarget(store.getState().document, {
|
||||
kind: "brushes",
|
||||
ids: [brush.id]
|
||||
}).target;
|
||||
if (target === null || target.kind !== "brush") {
|
||||
throw new Error("Expected a whitebox box transform target.");
|
||||
}
|
||||
const rotateSession = createTransformSession({
|
||||
source: "keyboard",
|
||||
sourcePanelId: "topLeft",
|
||||
operation: "rotate",
|
||||
target
|
||||
});
|
||||
rotateSession.preview = {
|
||||
kind: "brush",
|
||||
center: {
|
||||
...brush.center
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 37.5,
|
||||
z: 12.5
|
||||
},
|
||||
size: {
|
||||
...brush.size
|
||||
}
|
||||
};
|
||||
store.executeCommand(createCommitTransformSessionCommand(store.getState().document, rotateSession));
|
||||
expect(store.getState().document.brushes[brush.id].rotationDegrees).toEqual({
|
||||
x: 0,
|
||||
y: 37.5,
|
||||
z: 12.5
|
||||
});
|
||||
const scaleTarget = resolveTransformTarget(store.getState().document, {
|
||||
kind: "brushes",
|
||||
ids: [brush.id]
|
||||
}).target;
|
||||
if (scaleTarget === null || scaleTarget.kind !== "brush") {
|
||||
throw new Error("Expected a whitebox box transform target after rotation.");
|
||||
}
|
||||
const scaleSession = createTransformSession({
|
||||
source: "keyboard",
|
||||
sourcePanelId: "topLeft",
|
||||
operation: "scale",
|
||||
target: scaleTarget
|
||||
});
|
||||
scaleSession.preview = {
|
||||
kind: "brush",
|
||||
center: {
|
||||
...brush.center
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 37.5,
|
||||
z: 12.5
|
||||
},
|
||||
size: {
|
||||
x: 3.25,
|
||||
y: 1.75,
|
||||
z: 5.5
|
||||
}
|
||||
};
|
||||
store.executeCommand(createCommitTransformSessionCommand(store.getState().document, scaleSession));
|
||||
expect(store.getState().document.brushes[brush.id]).toMatchObject({
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 37.5,
|
||||
z: 12.5
|
||||
},
|
||||
size: {
|
||||
x: 3.25,
|
||||
y: 1.75,
|
||||
z: 5.5
|
||||
}
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.brushes[brush.id]).toMatchObject({
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 37.5,
|
||||
z: 12.5
|
||||
},
|
||||
size: {
|
||||
x: 2.5,
|
||||
y: 2,
|
||||
z: 4
|
||||
}
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.brushes[brush.id]).toEqual(brush);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.brushes[brush.id]).toMatchObject({
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 37.5,
|
||||
z: 12.5
|
||||
},
|
||||
size: {
|
||||
x: 3.25,
|
||||
y: 1.75,
|
||||
z: 5.5
|
||||
}
|
||||
});
|
||||
});
|
||||
it("commits a face transform preview and restores it through undo/redo", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-face-transform",
|
||||
center: { x: 0, y: 1, z: 0 },
|
||||
size: { x: 2, y: 2, z: 2 }
|
||||
});
|
||||
const store = createEditorStore({
|
||||
initialDocument: {
|
||||
...createEmptySceneDocument({ name: "Face Transform Fixture" }),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
}
|
||||
});
|
||||
const target = resolveTransformTarget(store.getState().document, {
|
||||
kind: "brushFace",
|
||||
brushId: brush.id,
|
||||
faceId: "posX"
|
||||
}, "face").target;
|
||||
if (target === null || target.kind !== "brushFace") {
|
||||
throw new Error("Expected a whitebox face transform target.");
|
||||
}
|
||||
const session = createTransformSession({
|
||||
source: "keyboard",
|
||||
sourcePanelId: "topLeft",
|
||||
operation: "translate",
|
||||
target
|
||||
});
|
||||
session.preview = {
|
||||
kind: "brush",
|
||||
center: { x: 0.5, y: 1, z: 0 },
|
||||
rotationDegrees: { x: 0, y: 0, z: 0 },
|
||||
size: { x: 3, y: 2, z: 2 }
|
||||
};
|
||||
store.executeCommand(createCommitTransformSessionCommand(store.getState().document, session));
|
||||
expect(store.getState().document.brushes[brush.id]).toMatchObject({
|
||||
center: { x: 0.5, y: 1, z: 0 },
|
||||
size: { x: 3, y: 2, z: 2 }
|
||||
});
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "brushFace",
|
||||
brushId: brush.id,
|
||||
faceId: "posX"
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.brushes[brush.id]).toEqual(brush);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.brushes[brush.id]).toMatchObject({
|
||||
center: { x: 0.5, y: 1, z: 0 },
|
||||
size: { x: 3, y: 2, z: 2 }
|
||||
});
|
||||
});
|
||||
it("commits a vertex transform preview and preserves vertex selection through undo/redo", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-vertex-transform",
|
||||
center: { x: 0, y: 1, z: 0 },
|
||||
size: { x: 2, y: 2, z: 2 }
|
||||
});
|
||||
const store = createEditorStore({
|
||||
initialDocument: {
|
||||
...createEmptySceneDocument({ name: "Vertex Transform Fixture" }),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
}
|
||||
});
|
||||
const target = resolveTransformTarget(store.getState().document, {
|
||||
kind: "brushVertex",
|
||||
brushId: brush.id,
|
||||
vertexId: "posX_posY_posZ"
|
||||
}, "vertex").target;
|
||||
if (target === null || target.kind !== "brushVertex") {
|
||||
throw new Error("Expected a whitebox vertex transform target.");
|
||||
}
|
||||
const session = createTransformSession({
|
||||
source: "keyboard",
|
||||
sourcePanelId: "topLeft",
|
||||
operation: "translate",
|
||||
target
|
||||
});
|
||||
session.preview = {
|
||||
kind: "brush",
|
||||
center: { x: 0.5, y: 1.5, z: 0.5 },
|
||||
rotationDegrees: { x: 0, y: 0, z: 0 },
|
||||
size: { x: 3, y: 3, z: 3 }
|
||||
};
|
||||
store.executeCommand(createCommitTransformSessionCommand(store.getState().document, session));
|
||||
expect(store.getState().document.brushes[brush.id]).toMatchObject({
|
||||
center: { x: 0.5, y: 1.5, z: 0.5 },
|
||||
size: { x: 3, y: 3, z: 3 }
|
||||
});
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "brushVertex",
|
||||
brushId: brush.id,
|
||||
vertexId: "posX_posY_posZ"
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.brushes[brush.id]).toEqual(brush);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "brushVertex",
|
||||
brushId: brush.id,
|
||||
vertexId: "posX_posY_posZ"
|
||||
});
|
||||
});
|
||||
it("commits a model instance translate/rotate/scale transform with undo and redo", () => {
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-main",
|
||||
assetId: modelAsset.id,
|
||||
position: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
scale: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 1
|
||||
}
|
||||
});
|
||||
const store = createEditorStore({
|
||||
initialDocument: {
|
||||
...createEmptySceneDocument({ name: "Transform Fixture" }),
|
||||
assets: {
|
||||
[modelAsset.id]: modelAsset
|
||||
},
|
||||
modelInstances: {
|
||||
[modelInstance.id]: modelInstance
|
||||
}
|
||||
}
|
||||
});
|
||||
const target = resolveTransformTarget(store.getState().document, {
|
||||
kind: "modelInstances",
|
||||
ids: [modelInstance.id]
|
||||
}).target;
|
||||
if (target === null || target.kind !== "modelInstance") {
|
||||
throw new Error("Expected a model instance transform target.");
|
||||
}
|
||||
const session = createTransformSession({
|
||||
source: "keyboard",
|
||||
sourcePanelId: "topLeft",
|
||||
operation: "scale",
|
||||
target
|
||||
});
|
||||
session.preview = {
|
||||
kind: "modelInstance",
|
||||
position: {
|
||||
x: 4,
|
||||
y: 1,
|
||||
z: -2
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 90,
|
||||
z: 0
|
||||
},
|
||||
scale: {
|
||||
x: 1.5,
|
||||
y: 2,
|
||||
z: 1.5
|
||||
}
|
||||
};
|
||||
store.executeCommand(createCommitTransformSessionCommand(store.getState().document, session));
|
||||
expect(store.getState().document.modelInstances[modelInstance.id]).toMatchObject({
|
||||
position: {
|
||||
x: 4,
|
||||
y: 1,
|
||||
z: -2
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 90,
|
||||
z: 0
|
||||
},
|
||||
scale: {
|
||||
x: 1.5,
|
||||
y: 2,
|
||||
z: 1.5
|
||||
}
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.modelInstances[modelInstance.id]).toEqual(modelInstance);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.modelInstances[modelInstance.id]).toMatchObject({
|
||||
position: {
|
||||
x: 4,
|
||||
y: 1,
|
||||
z: -2
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 90,
|
||||
z: 0
|
||||
},
|
||||
scale: {
|
||||
x: 1.5,
|
||||
y: 2,
|
||||
z: 1.5
|
||||
}
|
||||
});
|
||||
});
|
||||
it("commits a rotatable entity transform with undo and redo", () => {
|
||||
const playerStart = createPlayerStartEntity({
|
||||
id: "entity-player-start-main",
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
yawDegrees: 0
|
||||
});
|
||||
const store = createEditorStore({
|
||||
initialDocument: {
|
||||
...createEmptySceneDocument({ name: "Entity Transform Fixture" }),
|
||||
entities: {
|
||||
[playerStart.id]: playerStart
|
||||
}
|
||||
}
|
||||
});
|
||||
const target = resolveTransformTarget(store.getState().document, {
|
||||
kind: "entities",
|
||||
ids: [playerStart.id]
|
||||
}).target;
|
||||
if (target === null || target.kind !== "entity") {
|
||||
throw new Error("Expected an entity transform target.");
|
||||
}
|
||||
const session = createTransformSession({
|
||||
source: "keyboard",
|
||||
sourcePanelId: "topLeft",
|
||||
operation: "rotate",
|
||||
target
|
||||
});
|
||||
session.preview = {
|
||||
kind: "entity",
|
||||
position: {
|
||||
x: 6,
|
||||
y: 0,
|
||||
z: -4
|
||||
},
|
||||
rotation: {
|
||||
kind: "yaw",
|
||||
yawDegrees: 90
|
||||
}
|
||||
};
|
||||
store.executeCommand(createCommitTransformSessionCommand(store.getState().document, session));
|
||||
expect(store.getState().document.entities[playerStart.id]).toMatchObject({
|
||||
position: {
|
||||
x: 6,
|
||||
y: 0,
|
||||
z: -4
|
||||
},
|
||||
yawDegrees: 90
|
||||
});
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.entities[playerStart.id]).toEqual(playerStart);
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.entities[playerStart.id]).toMatchObject({
|
||||
position: {
|
||||
x: 6,
|
||||
y: 0,
|
||||
z: -4
|
||||
},
|
||||
yawDegrees: 90
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,30 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createEditorStore } from "../../src/app/editor-store";
|
||||
import { createSetWorldSettingsCommand } from "../../src/commands/set-world-settings-command";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { cloneWorldSettings } from "../../src/document/world-settings";
|
||||
describe("createSetWorldSettingsCommand", () => {
|
||||
it("updates authored world settings and restores them through undo", () => {
|
||||
const store = createEditorStore();
|
||||
const originalWorld = cloneWorldSettings(store.getState().document.world);
|
||||
const nextWorld = cloneWorldSettings(originalWorld);
|
||||
nextWorld.background = {
|
||||
mode: "verticalGradient",
|
||||
topColorHex: "#6e8db4",
|
||||
bottomColorHex: "#18212b"
|
||||
};
|
||||
nextWorld.ambientLight.intensity = 0.45;
|
||||
nextWorld.advancedRendering.enabled = true;
|
||||
nextWorld.advancedRendering.shadows.enabled = true;
|
||||
nextWorld.advancedRendering.shadows.mapSize = 4096;
|
||||
nextWorld.advancedRendering.toneMapping.mode = "reinhard";
|
||||
nextWorld.advancedRendering.toneMapping.exposure = 1.35;
|
||||
store.executeCommand(createSetWorldSettingsCommand({
|
||||
label: "Set world lighting",
|
||||
world: nextWorld
|
||||
}));
|
||||
expect(store.getState().document.world).toEqual(nextWorld);
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.world).toEqual(createEmptySceneDocument().world);
|
||||
});
|
||||
});
|
||||
@@ -1,58 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { areWorldSettingsEqual, changeWorldBackgroundMode, cloneWorldSettings, createDefaultWorldSettings } from "../../src/document/world-settings";
|
||||
describe("world settings helpers", () => {
|
||||
it("clones world settings without retaining nested references", () => {
|
||||
const source = createDefaultWorldSettings();
|
||||
const clone = cloneWorldSettings(source);
|
||||
expect(clone).toEqual(source);
|
||||
expect(clone).not.toBe(source);
|
||||
expect(clone.background).not.toBe(source.background);
|
||||
expect(clone.sunLight.direction).not.toBe(source.sunLight.direction);
|
||||
expect(clone.advancedRendering).not.toBe(source.advancedRendering);
|
||||
expect(clone.advancedRendering.shadows).not.toBe(source.advancedRendering.shadows);
|
||||
});
|
||||
it("switches a solid background into a gradient while preserving the authored color as the top edge", () => {
|
||||
const gradient = changeWorldBackgroundMode({
|
||||
mode: "solid",
|
||||
colorHex: "#334455"
|
||||
}, "verticalGradient");
|
||||
expect(gradient).toEqual({
|
||||
mode: "verticalGradient",
|
||||
topColorHex: "#334455",
|
||||
bottomColorHex: "#141a22"
|
||||
});
|
||||
});
|
||||
it("switches and clones image backgrounds by asset id", () => {
|
||||
const imageBackground = changeWorldBackgroundMode({
|
||||
mode: "solid",
|
||||
colorHex: "#334455"
|
||||
}, "image", "asset-background-panorama");
|
||||
expect(imageBackground).toEqual({
|
||||
mode: "image",
|
||||
assetId: "asset-background-panorama",
|
||||
environmentIntensity: 0.5
|
||||
});
|
||||
const nextImageBackground = changeWorldBackgroundMode(imageBackground, "image", "asset-background-panorama-2");
|
||||
expect(nextImageBackground).toEqual({
|
||||
mode: "image",
|
||||
assetId: "asset-background-panorama-2",
|
||||
environmentIntensity: 0.5
|
||||
});
|
||||
const world = createDefaultWorldSettings();
|
||||
world.background = nextImageBackground;
|
||||
const clonedWorld = cloneWorldSettings(world);
|
||||
expect(clonedWorld.background).toEqual(nextImageBackground);
|
||||
expect(clonedWorld.background).not.toBe(world.background);
|
||||
expect(areWorldSettingsEqual(world, clonedWorld)).toBe(true);
|
||||
});
|
||||
it("compares authored world settings by value", () => {
|
||||
const left = createDefaultWorldSettings();
|
||||
const right = cloneWorldSettings(left);
|
||||
expect(areWorldSettingsEqual(left, right)).toBe(true);
|
||||
right.sunLight.direction.x = right.sunLight.direction.x + 0.25;
|
||||
expect(areWorldSettingsEqual(left, right)).toBe(false);
|
||||
right.sunLight.direction.x = left.sunLight.direction.x;
|
||||
right.advancedRendering.bloom.intensity = right.advancedRendering.bloom.intensity + 0.1;
|
||||
expect(areWorldSettingsEqual(left, right)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,24 +0,0 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
test("app boots and shows the viewport shell", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await expect(page.getByTestId("toolbar-scene-name")).toHaveValue("Untitled Scene");
|
||||
await expect(page.getByTestId("viewport-shell")).toBeVisible();
|
||||
await expect(page.getByTestId("viewport-panel-topLeft")).toBeVisible();
|
||||
await expect(page.getByTestId("viewport-layout-single")).toBeVisible();
|
||||
await expect(page.getByTestId("viewport-layout-quad")).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: "World" })).toBeVisible();
|
||||
await expect(page.getByTestId("world-background-mode-value")).toBeVisible();
|
||||
await expect(page.getByTestId("enter-run-mode")).toBeVisible();
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,138 +0,0 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { beginBoxCreation, clickViewport, getEditorStoreSnapshot } from "./viewport-test-helpers";
|
||||
test("user can create a whitebox box with float transforms and keep it through reload and run mode", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await beginBoxCreation(page);
|
||||
const creationSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(creationSnapshot).toMatchObject({
|
||||
toolMode: "create",
|
||||
viewportTransientState: {
|
||||
toolPreview: {
|
||||
kind: "create",
|
||||
sourcePanelId: "topLeft",
|
||||
target: {
|
||||
kind: "box-brush"
|
||||
},
|
||||
center: null
|
||||
}
|
||||
}
|
||||
});
|
||||
await page.keyboard.press("Escape");
|
||||
const cancelledSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(cancelledSnapshot).toMatchObject({
|
||||
toolMode: "select",
|
||||
viewportTransientState: {
|
||||
toolPreview: {
|
||||
kind: "none"
|
||||
}
|
||||
}
|
||||
});
|
||||
await beginBoxCreation(page);
|
||||
await clickViewport(page);
|
||||
await page.getByTestId("whitebox-snap-toggle").click();
|
||||
const committedSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(committedSnapshot).toMatchObject({
|
||||
toolMode: "select",
|
||||
viewportTransientState: {
|
||||
toolPreview: {
|
||||
kind: "none"
|
||||
}
|
||||
}
|
||||
});
|
||||
await expect(page.getByRole("button", { name: /Whitebox Box 1/ })).toBeVisible();
|
||||
await expect(page.getByText("1 solid selected (Whitebox Box 1)")).toBeVisible();
|
||||
await expect(page.getByTestId("apply-brush-position")).toHaveCount(0);
|
||||
await expect(page.getByTestId("apply-brush-size")).toHaveCount(0);
|
||||
await page.getByTestId("brush-center-x").fill("1.25");
|
||||
await page.getByTestId("brush-center-x").press("Tab");
|
||||
await page.getByTestId("brush-center-y").fill("2.125");
|
||||
await page.getByTestId("brush-center-y").press("Tab");
|
||||
await page.getByTestId("brush-rotation-y").fill("37.5");
|
||||
await page.getByTestId("brush-rotation-y").press("Tab");
|
||||
await page.getByTestId("brush-size-z").fill("4.5");
|
||||
await page.getByTestId("brush-size-z").press("Tab");
|
||||
await page.getByTestId("selected-brush-name").fill("Entry Room");
|
||||
await page.getByTestId("selected-brush-name").press("Tab");
|
||||
await expect(page.getByTestId("selected-brush-name")).toHaveValue("Entry Room");
|
||||
await page.getByRole("button", { name: "Save Draft" }).click();
|
||||
await page.reload();
|
||||
await expect(page.getByRole("button", { name: /^Entry Room$/ })).toBeVisible();
|
||||
await page.getByRole("button", { name: /^Entry Room$/ }).click();
|
||||
await expect(page.getByTestId("brush-center-x")).toHaveValue("1.25");
|
||||
await expect(page.getByTestId("brush-center-y")).toHaveValue("2.125");
|
||||
await expect(page.getByTestId("brush-rotation-y")).toHaveValue("37.5");
|
||||
await expect(page.getByTestId("brush-size-z")).toHaveValue("4.5");
|
||||
await expect(page.getByTestId("viewport-overlay-topLeft")).toHaveCount(0);
|
||||
await page.getByTestId("enter-run-mode").click();
|
||||
await expect(page.getByTestId("runner-shell")).toBeVisible();
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
test("switching selection while a transform input is active does not overwrite the newly selected brush", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await beginBoxCreation(page);
|
||||
await clickViewport(page);
|
||||
await beginBoxCreation(page);
|
||||
await clickViewport(page);
|
||||
const outlinerButtons = page.getByTestId("outliner-brush-list").getByRole("button");
|
||||
await outlinerButtons.nth(0).click();
|
||||
await page.getByTestId("brush-size-z").fill("4");
|
||||
await outlinerButtons.nth(1).click();
|
||||
await expect(page.getByText("1 solid selected (Whitebox Box 2)")).toBeVisible();
|
||||
await expect(page.getByTestId("brush-size-z")).toHaveValue("2");
|
||||
await outlinerButtons.nth(0).click();
|
||||
await expect(page.getByTestId("brush-size-z")).toHaveValue("4");
|
||||
});
|
||||
test("shift+d duplicates the current selection and does not trigger while typing", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await beginBoxCreation(page);
|
||||
await clickViewport(page);
|
||||
const beforeDuplicateSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(beforeDuplicateSnapshot.selection).toMatchObject({
|
||||
kind: "brushes"
|
||||
});
|
||||
const sourceBrushId = beforeDuplicateSnapshot.selection.ids?.[0];
|
||||
expect(sourceBrushId).toBeDefined();
|
||||
await page.keyboard.press("Shift+D");
|
||||
const afterDuplicateSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(afterDuplicateSnapshot.selection).toMatchObject({
|
||||
kind: "brushes"
|
||||
});
|
||||
expect(Object.keys(afterDuplicateSnapshot.document.brushes)).toHaveLength(2);
|
||||
expect(afterDuplicateSnapshot.viewportTransientState.transformSession).toMatchObject({
|
||||
kind: "active",
|
||||
operation: "translate"
|
||||
});
|
||||
const duplicatedBrushId = afterDuplicateSnapshot.selection.ids?.[0];
|
||||
expect(duplicatedBrushId).toBeDefined();
|
||||
expect(duplicatedBrushId).not.toBe(sourceBrushId);
|
||||
const sourceCenter = beforeDuplicateSnapshot.document.brushes[sourceBrushId].center;
|
||||
const duplicatedCenter = afterDuplicateSnapshot.document.brushes[duplicatedBrushId].center;
|
||||
expect(duplicatedCenter).toEqual(sourceCenter);
|
||||
await page.getByTestId("selected-brush-name").click();
|
||||
await page.keyboard.press("Shift+D");
|
||||
const afterTypingShortcutSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(Object.keys(afterTypingShortcutSnapshot.document.brushes)).toHaveLength(2);
|
||||
});
|
||||
@@ -1,155 +0,0 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { clickViewport, getEditorStoreSnapshot, setViewportCreationPreview } from "./viewport-test-helpers";
|
||||
test("user can place and select typed entities from the entity foundation workflow", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-sound-emitter").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "soundEmitter", audioAssetId: null }, { x: 4, y: 1, z: -6 });
|
||||
await expect(page.getByTestId("viewport-snap-preview-topLeft")).toBeVisible();
|
||||
await clickViewport(page, "topLeft");
|
||||
const soundEmitterSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(soundEmitterSnapshot).toMatchObject({
|
||||
toolMode: "select",
|
||||
viewportTransientState: {
|
||||
toolPreview: {
|
||||
kind: "none"
|
||||
}
|
||||
}
|
||||
});
|
||||
const selectedSoundEmitterId = soundEmitterSnapshot.selection.kind === "entities" ? soundEmitterSnapshot.selection.ids?.[0] ?? null : null;
|
||||
expect(selectedSoundEmitterId).not.toBeNull();
|
||||
const selectedSoundEmitter = soundEmitterSnapshot.document.entities[selectedSoundEmitterId];
|
||||
if (selectedSoundEmitter === undefined) {
|
||||
throw new Error("Placed sound emitter is missing from the document snapshot.");
|
||||
}
|
||||
expect(selectedSoundEmitter.position).toMatchObject({
|
||||
x: 4,
|
||||
y: 1,
|
||||
z: -6
|
||||
});
|
||||
await expect(page.getByTestId("sound-emitter-ref-distance")).toHaveValue("6");
|
||||
await expect(page.getByTestId("sound-emitter-max-distance")).toHaveValue("24");
|
||||
await page.getByTestId("sound-emitter-ref-distance").fill("9");
|
||||
await page.getByTestId("sound-emitter-ref-distance").press("Tab");
|
||||
await page.getByTestId("sound-emitter-autoplay").click();
|
||||
await page.getByTestId("sound-emitter-loop").click();
|
||||
await expect(page.getByTestId("sound-emitter-autoplay")).toBeChecked();
|
||||
await expect(page.getByTestId("sound-emitter-loop")).toBeChecked();
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-interactable").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "interactable", audioAssetId: null }, { x: -8, y: 1, z: 12 });
|
||||
await expect(page.getByTestId("viewport-snap-preview-topLeft")).toBeVisible();
|
||||
await clickViewport(page, "topLeft");
|
||||
const interactableSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(interactableSnapshot).toMatchObject({
|
||||
toolMode: "select",
|
||||
viewportTransientState: {
|
||||
toolPreview: {
|
||||
kind: "none"
|
||||
}
|
||||
}
|
||||
});
|
||||
await expect(page.getByTestId("interactable-prompt")).toHaveValue("Use");
|
||||
await page
|
||||
.locator('[data-testid^="outliner-entity-"]')
|
||||
.filter({ hasText: "Sound Emitter" })
|
||||
.first()
|
||||
.click();
|
||||
await expect(page.getByTestId("sound-emitter-ref-distance")).toHaveValue("9");
|
||||
await expect(page.getByTestId("sound-emitter-autoplay")).toBeChecked();
|
||||
await expect(page.getByTestId("sound-emitter-loop")).toBeChecked();
|
||||
await expect(page.getByTestId("interactable-prompt")).toHaveCount(0);
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
test("shift+a opens the add menu at the cursor", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await page.mouse.move(420, 260);
|
||||
await page.keyboard.press("Shift+A");
|
||||
await expect(page.getByRole("menu", { name: "Add" })).toBeVisible();
|
||||
await page.getByTestId("add-menu-lights").click();
|
||||
await page.getByTestId("add-menu-point-light").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "pointLight", audioAssetId: null }, { x: 12, y: 3, z: -4 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await expect(page.getByTestId("point-light-intensity")).toHaveValue("1.25");
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
test("escape cancels a typed entity creation preview", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-player-start").click();
|
||||
const creationSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(creationSnapshot).toMatchObject({
|
||||
toolMode: "create",
|
||||
viewportTransientState: {
|
||||
toolPreview: {
|
||||
kind: "create",
|
||||
sourcePanelId: "topLeft",
|
||||
target: {
|
||||
kind: "entity",
|
||||
entityKind: "playerStart",
|
||||
audioAssetId: null
|
||||
},
|
||||
center: null
|
||||
}
|
||||
}
|
||||
});
|
||||
await page.keyboard.press("Escape");
|
||||
const cancelledSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(cancelledSnapshot).toMatchObject({
|
||||
toolMode: "select",
|
||||
viewportTransientState: {
|
||||
toolPreview: {
|
||||
kind: "none"
|
||||
}
|
||||
}
|
||||
});
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { beginBoxCreation, clickViewport } from "./viewport-test-helpers";
|
||||
test("user can assign a face material through the UI and keep it through a draft reload", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await beginBoxCreation(page);
|
||||
await clickViewport(page);
|
||||
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 page.getByRole("button", { name: "Save Draft" }).click();
|
||||
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");
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,54 +0,0 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { beginBoxCreation, clickViewport, setViewportCreationPreview } from "./viewport-test-helpers";
|
||||
test("first-room workflow covers create, texture, save/load, and run", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await beginBoxCreation(page);
|
||||
await clickViewport(page);
|
||||
await page.getByTestId("face-button-posZ").click();
|
||||
await page.getByTestId("material-button-starter-amber-grid").click();
|
||||
await page.getByRole("button", { name: "First Person" }).click();
|
||||
await expect(page.getByTestId("status-message")).toContainText("Author a Player Start before running");
|
||||
await expect(page.getByTestId("status-run-preflight")).toContainText("Blocked");
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-player-start").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "playerStart", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page.getByTestId("player-start-position-x").fill("2");
|
||||
await page.getByTestId("player-start-position-x").press("Tab");
|
||||
await page.getByTestId("player-start-position-z").fill("-2");
|
||||
await page.getByTestId("player-start-position-z").press("Tab");
|
||||
await page.getByTestId("player-start-yaw").fill("90");
|
||||
await page.getByTestId("player-start-yaw").press("Tab");
|
||||
await expect(page.getByTestId("status-run-preflight")).toContainText("Ready for First Person");
|
||||
await page.getByRole("button", { name: "Save Draft" }).click();
|
||||
await beginBoxCreation(page);
|
||||
await clickViewport(page);
|
||||
await expect(page.getByRole("button", { name: /Whitebox Box 2/ })).toBeVisible();
|
||||
await page.getByRole("button", { name: "Load Draft" }).click();
|
||||
await expect(page.getByRole("button", { name: /Whitebox Box 2/ })).toHaveCount(0);
|
||||
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 page.getByTestId("enter-run-mode").click();
|
||||
await expect(page.getByTestId("runner-shell")).toBeVisible();
|
||||
await expect(page.getByTestId("runner-spawn-state")).toContainText("Player Start");
|
||||
await expect(page.getByTestId("runner-player-position")).toContainText("2.00,");
|
||||
await expect(page.getByTestId("runner-player-position")).toContainText(", -2.00");
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,59 +0,0 @@
|
||||
import path from "node:path";
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { clickViewport, getEditorStoreSnapshot, setViewportCreationPreview } from "./viewport-test-helpers";
|
||||
const fixturePath = path.resolve(process.cwd(), "fixtures/assets/tiny-triangle-draco.glb");
|
||||
test("imports a draco-compressed glb asset, places an instance, and survives reload", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-import").click();
|
||||
await page.getByTestId("import-menu-model").click();
|
||||
await page.locator('input[type="file"][accept*="gltf"]').setInputFiles(fixturePath);
|
||||
await expect(page.getByTestId("outliner-model-instance-list").getByRole("button")).toHaveCount(1);
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-assets").click();
|
||||
await page.getByTestId("add-menu-assets-models").click();
|
||||
const addMenu = page.getByRole("menu", { name: "Add" });
|
||||
await expect(addMenu.getByRole("menuitem", { name: "tiny-triangle-draco.glb" })).toBeVisible();
|
||||
await addMenu.getByRole("menuitem", { name: "tiny-triangle-draco.glb" }).click();
|
||||
const importedSnapshot = await getEditorStoreSnapshot(page);
|
||||
const importedModelAsset = Object.values(importedSnapshot.document.assets).find((asset) => asset.kind === "model" && asset.sourceName === "tiny-triangle-draco.glb");
|
||||
if (importedModelAsset === undefined) {
|
||||
throw new Error("Imported model asset was not found in the document snapshot.");
|
||||
}
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "model-instance", assetId: importedModelAsset.id }, { x: 84, y: 0, z: -88 });
|
||||
await expect(page.getByTestId("viewport-snap-preview-topLeft")).toBeVisible();
|
||||
await clickViewport(page, "topLeft");
|
||||
await expect(page.getByTestId("outliner-model-instance-list").getByRole("button")).toHaveCount(2);
|
||||
const snapshot = await getEditorStoreSnapshot(page);
|
||||
const selectedModelInstanceId = snapshot.selection.kind === "modelInstances" ? snapshot.selection.ids?.[0] ?? null : null;
|
||||
expect(selectedModelInstanceId).not.toBeNull();
|
||||
const selectedModelInstance = snapshot.document.modelInstances[selectedModelInstanceId];
|
||||
if (selectedModelInstance === undefined) {
|
||||
throw new Error("Placed model instance is missing from the document snapshot.");
|
||||
}
|
||||
expect(selectedModelInstance.position).toMatchObject({
|
||||
x: 84,
|
||||
z: -88
|
||||
});
|
||||
await page.getByRole("button", { name: "Save Draft" }).dispatchEvent("click");
|
||||
await expect(page.getByTestId("status-message")).toContainText("Local draft saved.");
|
||||
await page.reload();
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-assets").click();
|
||||
await page.getByTestId("add-menu-assets-models").click();
|
||||
await expect(page.getByRole("menu", { name: "Add" }).getByRole("menuitem", { name: "tiny-triangle-draco.glb" })).toBeVisible();
|
||||
await expect(page.getByTestId("outliner-model-instance-list").getByRole("button")).toHaveCount(2);
|
||||
await expect(page.getByTestId("asset-status-message")).toHaveCount(0);
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,53 +0,0 @@
|
||||
import path from "node:path";
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { clickViewport, getEditorStoreSnapshot, setViewportCreationPreview } from "./viewport-test-helpers";
|
||||
const gltfFixturePath = path.resolve(process.cwd(), "fixtures/assets/external-triangle/scene.gltf");
|
||||
const binFixturePath = path.resolve(process.cwd(), "fixtures/assets/external-triangle/triangle.bin");
|
||||
test("imports a gltf asset with external resources and places an instance", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-import").click();
|
||||
await page.getByTestId("import-menu-model").click();
|
||||
await page.locator('input[type="file"][accept*="gltf"]').setInputFiles([gltfFixturePath, binFixturePath]);
|
||||
await expect(page.getByTestId("outliner-model-instance-list").getByRole("button")).toHaveCount(1);
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-assets").click();
|
||||
await page.getByTestId("add-menu-assets-models").click();
|
||||
const addMenu = page.getByRole("menu", { name: "Add" });
|
||||
await expect(addMenu.getByRole("menuitem", { name: "scene.gltf" })).toBeVisible();
|
||||
await addMenu.getByRole("menuitem", { name: "scene.gltf" }).hover();
|
||||
await expect(page.getByTestId("status-asset-hover")).toContainText("Storage key:");
|
||||
await addMenu.getByRole("menuitem", { name: "scene.gltf" }).click();
|
||||
const importedSnapshot = await getEditorStoreSnapshot(page);
|
||||
const importedModelAsset = Object.values(importedSnapshot.document.assets).find((asset) => asset.kind === "model" && asset.sourceName === "scene.gltf");
|
||||
if (importedModelAsset === undefined) {
|
||||
throw new Error("Imported model asset was not found in the document snapshot.");
|
||||
}
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "model-instance", assetId: importedModelAsset.id }, { x: 88, y: 0, z: -84 });
|
||||
await expect(page.getByTestId("viewport-snap-preview-topLeft")).toBeVisible();
|
||||
await clickViewport(page, "topLeft");
|
||||
await expect(page.getByTestId("outliner-model-instance-list").getByRole("button")).toHaveCount(2);
|
||||
const snapshot = await getEditorStoreSnapshot(page);
|
||||
const selectedModelInstanceId = snapshot.selection.kind === "modelInstances" ? snapshot.selection.ids?.[0] ?? null : null;
|
||||
expect(selectedModelInstanceId).not.toBeNull();
|
||||
const selectedModelInstance = snapshot.document.modelInstances[selectedModelInstanceId];
|
||||
if (selectedModelInstance === undefined) {
|
||||
throw new Error("Placed model instance is missing from the document snapshot.");
|
||||
}
|
||||
expect(selectedModelInstance.position).toMatchObject({
|
||||
x: 88,
|
||||
z: -84
|
||||
});
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,101 +0,0 @@
|
||||
import path from "node:path";
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { clickViewport, getEditorStoreSnapshot, setViewportCreationPreview } from "./viewport-test-helpers";
|
||||
const fixturePath = path.resolve(process.cwd(), "fixtures/assets/tiny-triangle.gltf");
|
||||
test("imports a model asset, places an instance, and survives reload", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-import").click();
|
||||
await expect(page.getByTestId("import-menu-model")).toBeVisible();
|
||||
await expect(page.getByTestId("import-menu-environment")).toBeVisible();
|
||||
await expect(page.getByTestId("import-menu-audio")).toBeVisible();
|
||||
await page.getByTestId("import-menu-model").click();
|
||||
await page.locator('input[type="file"][accept*="gltf"]').setInputFiles(fixturePath);
|
||||
await expect(page.getByTestId("outliner-model-instance-list").getByRole("button")).toHaveCount(1);
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-assets").click();
|
||||
await page.getByTestId("add-menu-assets-models").click();
|
||||
const addMenu = page.getByRole("menu", { name: "Add" });
|
||||
await expect(addMenu.getByRole("menuitem", { name: "tiny-triangle.gltf" })).toBeVisible();
|
||||
await addMenu.getByRole("menuitem", { name: "tiny-triangle.gltf" }).hover();
|
||||
await expect(page.getByTestId("status-asset-hover")).toContainText("Storage key:");
|
||||
await addMenu.getByRole("menuitem", { name: "tiny-triangle.gltf" }).click();
|
||||
const importedSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(importedSnapshot).toMatchObject({
|
||||
toolMode: "create",
|
||||
viewportTransientState: {
|
||||
toolPreview: {
|
||||
kind: "create",
|
||||
sourcePanelId: "topLeft",
|
||||
target: {
|
||||
kind: "model-instance",
|
||||
assetId: expect.any(String)
|
||||
},
|
||||
center: null
|
||||
}
|
||||
}
|
||||
});
|
||||
const importedModelAsset = Object.values(importedSnapshot.document.assets).find((asset) => asset.kind === "model" && asset.sourceName === "tiny-triangle.gltf");
|
||||
if (importedModelAsset === undefined) {
|
||||
throw new Error("Imported model asset was not found in the document snapshot.");
|
||||
}
|
||||
await page.keyboard.press("Escape");
|
||||
const cancelledSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(cancelledSnapshot).toMatchObject({
|
||||
toolMode: "select",
|
||||
viewportTransientState: {
|
||||
toolPreview: {
|
||||
kind: "none"
|
||||
}
|
||||
}
|
||||
});
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-assets").click();
|
||||
await page.getByTestId("add-menu-assets-models").click();
|
||||
await page.getByRole("menu", { name: "Add" }).getByRole("menuitem", { name: "tiny-triangle.gltf" }).click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "model-instance", assetId: importedModelAsset.id }, { x: 92, y: 0, z: -76 });
|
||||
await expect(page.getByTestId("viewport-snap-preview-topLeft")).toBeVisible();
|
||||
await clickViewport(page, "topLeft");
|
||||
const committedSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(committedSnapshot).toMatchObject({
|
||||
toolMode: "select",
|
||||
viewportTransientState: {
|
||||
toolPreview: {
|
||||
kind: "none"
|
||||
}
|
||||
}
|
||||
});
|
||||
await expect(page.getByTestId("outliner-model-instance-list").getByRole("button")).toHaveCount(2);
|
||||
const snapshot = committedSnapshot;
|
||||
const selectedModelInstanceId = snapshot.selection.kind === "modelInstances" ? snapshot.selection.ids?.[0] ?? null : null;
|
||||
expect(selectedModelInstanceId).not.toBeNull();
|
||||
const selectedModelInstance = snapshot.document.modelInstances[selectedModelInstanceId];
|
||||
if (selectedModelInstance === undefined) {
|
||||
throw new Error("Placed model instance is missing from the document snapshot.");
|
||||
}
|
||||
expect(selectedModelInstance.position).toMatchObject({
|
||||
x: 92,
|
||||
z: -76
|
||||
});
|
||||
await page.getByRole("button", { name: "Save Draft" }).dispatchEvent("click");
|
||||
await expect(page.getByTestId("status-message")).toContainText("Local draft saved.");
|
||||
await page.reload();
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-assets").click();
|
||||
await page.getByTestId("add-menu-assets-models").click();
|
||||
await expect(page.getByRole("menu", { name: "Add" }).getByRole("menuitem", { name: "tiny-triangle.gltf" })).toBeVisible();
|
||||
await expect(page.getByTestId("outliner-model-instance-list").getByRole("button")).toHaveCount(2);
|
||||
await expect(page.getByTestId("asset-status-message")).toHaveCount(0);
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,71 +0,0 @@
|
||||
import path from "node:path";
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { clickViewport, setViewportCreationPreview } from "./viewport-test-helpers";
|
||||
const panoramaFixturePath = path.resolve(process.cwd(), "fixtures/assets/skybox-panorama.svg");
|
||||
test("local lights and background images persist through editor and runner flows", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-import").click();
|
||||
await page.getByTestId("import-menu-environment").click();
|
||||
await page.locator('input[type="file"][accept*="image"]').setInputFiles(panoramaFixturePath);
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-assets").click();
|
||||
await page.getByTestId("add-menu-assets-environments").click();
|
||||
const addMenu = page.getByRole("menu", { name: "Add" });
|
||||
await expect(addMenu.getByRole("menuitem", { name: "skybox-panorama.svg" })).toBeVisible();
|
||||
await addMenu.getByRole("menuitem", { name: "skybox-panorama.svg" }).click();
|
||||
await expect(page.getByTestId("world-background-mode-value")).toContainText("Image");
|
||||
await expect(page.getByTestId("world-background-asset-value")).toContainText("skybox-panorama.svg");
|
||||
await expect(page.getByTestId("viewport-canvas-topLeft")).toHaveCSS("background-image", /url/);
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-lights").click();
|
||||
await page.getByTestId("add-menu-point-light").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "pointLight", audioAssetId: null }, { x: 12, y: 3, z: -4 });
|
||||
await expect(page.getByTestId("viewport-snap-preview-topLeft")).toBeVisible();
|
||||
await clickViewport(page, "topLeft");
|
||||
await expect(page.getByTestId("point-light-distance")).toHaveValue("8");
|
||||
await page.getByTestId("point-light-distance").fill("12");
|
||||
await page.getByTestId("point-light-distance").press("Tab");
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-lights").click();
|
||||
await page.getByTestId("add-menu-spot-light").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "spotLight", audioAssetId: null }, { x: -10, y: 4, z: 6 });
|
||||
await expect(page.getByTestId("viewport-snap-preview-topLeft")).toBeVisible();
|
||||
await clickViewport(page, "topLeft");
|
||||
await expect(page.getByTestId("spot-light-angle")).toHaveValue("35");
|
||||
await page.getByTestId("spot-light-angle").fill("48");
|
||||
await page.getByTestId("spot-light-angle").press("Tab");
|
||||
await page.getByTestId("spot-light-direction-y").fill("-0.9");
|
||||
await page.getByTestId("spot-light-direction-y").press("Tab");
|
||||
await expect(page.locator('[data-testid^="outliner-entity-"]')).toHaveCount(2);
|
||||
await page.getByRole("button", { name: "Save Draft" }).click();
|
||||
await expect(page.getByTestId("status-message")).toContainText("Local draft saved.");
|
||||
await page.reload();
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-assets").click();
|
||||
await page.getByTestId("add-menu-assets-environments").click();
|
||||
const reloadedAddMenu = page.getByRole("menu", { name: "Add" });
|
||||
await expect(reloadedAddMenu.getByRole("menuitem", { name: "skybox-panorama.svg" })).toBeVisible();
|
||||
await reloadedAddMenu.getByRole("menuitem", { name: "skybox-panorama.svg" }).click();
|
||||
await expect(page.locator('[data-testid^="outliner-entity-"]')).toHaveCount(2);
|
||||
await expect(page.getByTestId("viewport-canvas-topLeft")).toHaveCSS("background-image", /url/);
|
||||
await page.getByTestId("enter-run-mode").click();
|
||||
await expect(page.getByTestId("runner-shell")).toBeVisible();
|
||||
await expect(page.getByTestId("runner-shell")).toHaveCSS("background-image", /url/);
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,47 +0,0 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { beginBoxCreation, clickViewport, getViewportOverlay, getViewportPanel } from "./viewport-test-helpers";
|
||||
test("orthographic panel controls keep brush authoring and selection behavior intact", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await beginBoxCreation(page);
|
||||
await clickViewport(page, "topLeft");
|
||||
await expect(page.getByRole("button", { name: /Whitebox Box 1/ })).toBeVisible();
|
||||
await expect(page.getByText("1 solid selected (Whitebox Box 1)")).toBeVisible();
|
||||
await expect(page.getByTestId("viewport-active-panel")).toHaveCount(0);
|
||||
await expect(page.getByTestId("viewport-panel-topLeft-view-perspective")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(getViewportOverlay(page, "topLeft")).toBeVisible();
|
||||
await expect(page.getByTestId("viewport-selection-mode-topLeft")).toHaveText("Object");
|
||||
await page.getByTestId("viewport-panel-topLeft-view-top").dispatchEvent("click");
|
||||
await expect(page.getByTestId("viewport-panel-topLeft-view-top")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByTestId("viewport-selection-mode-topLeft")).toHaveText("Object");
|
||||
await page.getByTestId("viewport-panel-topLeft-view-front").dispatchEvent("click");
|
||||
await expect(page.getByTestId("viewport-panel-topLeft-view-front")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByTestId("viewport-selection-mode-topLeft")).toHaveText("Object");
|
||||
await page.getByTestId("viewport-panel-topLeft-view-side").dispatchEvent("click");
|
||||
await expect(page.getByTestId("viewport-panel-topLeft-view-side")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByTestId("viewport-selection-mode-topLeft")).toHaveText("Object");
|
||||
await page.getByTestId("viewport-panel-topLeft-display-authoring").dispatchEvent("click");
|
||||
await expect(page.getByTestId("viewport-panel-topLeft-display-authoring")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByTestId("viewport-canvas-topLeft")).toHaveCSS("background-color", "rgb(0, 0, 0)");
|
||||
await expect(getViewportPanel(page, "topLeft")).toHaveAttribute("data-active", "true");
|
||||
await expect(page.getByText("1 solid selected (Whitebox Box 1)")).toBeVisible();
|
||||
await page.getByTestId("viewport-panel-topLeft-display-wireframe").dispatchEvent("click");
|
||||
await expect(page.getByTestId("viewport-panel-topLeft-display-wireframe")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByTestId("viewport-canvas-topLeft")).toHaveCSS("background-color", "rgb(0, 0, 0)");
|
||||
await expect(page.getByText("1 solid selected (Whitebox Box 1)")).toBeVisible();
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,40 +0,0 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { clickViewport, setViewportCreationPreview } from "./viewport-test-helpers";
|
||||
test("user can place PlayerStart, enter run mode, and spawn from it", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-player-start").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "playerStart", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page.getByTestId("player-start-position-x").fill("4");
|
||||
await page.getByTestId("player-start-position-x").press("Tab");
|
||||
await page.getByTestId("player-start-position-z").fill("-2");
|
||||
await page.getByTestId("player-start-position-z").press("Tab");
|
||||
await page.getByTestId("player-start-yaw").fill("90");
|
||||
await page.getByTestId("player-start-yaw").press("Tab");
|
||||
await page.getByTestId("enter-run-mode").click();
|
||||
await expect(page.getByTestId("runner-shell")).toBeVisible();
|
||||
await expect(page.getByTestId("runner-spawn-state")).toContainText("Player Start");
|
||||
await expect(page.getByTestId("runner-player-position")).toContainText("4.00, 0.00, -2.00");
|
||||
await page.getByTestId("runner-mode-orbit-visitor").click();
|
||||
await expect(page.getByTestId("runner-mode-orbit-visitor")).toHaveClass(/toolbar__button--active/);
|
||||
await page.getByTestId("exit-run-mode").click();
|
||||
await expect(page.getByTestId("viewport-shell")).toBeVisible();
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,75 +0,0 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { clickViewport, setViewportCreationPreview } from "./viewport-test-helpers";
|
||||
for (const navigationMode of [
|
||||
{
|
||||
buttonLabel: "First Person",
|
||||
name: "first-person"
|
||||
},
|
||||
{
|
||||
buttonLabel: "Third Person",
|
||||
name: "third-person"
|
||||
}
|
||||
]) {
|
||||
test(`Interactable click prompt can teleport the player in ${navigationMode.name} run mode`, async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-player-start").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "playerStart", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page
|
||||
.getByTestId("player-start-navigation-mode")
|
||||
.selectOption(navigationMode.buttonLabel === "First Person"
|
||||
? "firstPerson"
|
||||
: "thirdPerson");
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-interactable").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "interactable", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page.getByTestId("interactable-position-y").fill("1");
|
||||
await page.getByTestId("interactable-position-y").press("Tab");
|
||||
await page.getByTestId("interactable-position-z").fill("1");
|
||||
await page.getByTestId("interactable-position-z").press("Tab");
|
||||
await page.getByTestId("interactable-radius").fill("4");
|
||||
await page.getByTestId("interactable-radius").press("Tab");
|
||||
await page.getByTestId("interactable-prompt").fill("Use Console");
|
||||
await page.getByTestId("interactable-prompt").press("Tab");
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-teleport-target").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "teleportTarget", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page.getByTestId("teleportTarget-position-x").fill("6");
|
||||
await page.getByTestId("teleportTarget-position-x").press("Tab");
|
||||
await page
|
||||
.locator('[data-testid^="outliner-entity-"]')
|
||||
.filter({ hasText: "Interactable" })
|
||||
.first()
|
||||
.click();
|
||||
await page.getByTestId("add-interactable-teleport-link").click();
|
||||
await page.getByTestId("enter-run-mode").click();
|
||||
await expect(page.getByTestId("runner-shell")).toBeVisible();
|
||||
await expect(page.getByTestId("runner-interaction-state")).toContainText("Ready");
|
||||
await expect(page.getByTestId("runner-interaction-prompt")).toBeVisible();
|
||||
await expect(page.getByTestId("runner-interaction-prompt-text")).toContainText("Use Console");
|
||||
await page.locator('[data-testid="runner-shell"] canvas').click();
|
||||
await expect(page.getByTestId("runner-player-position")).toContainText("6.00,");
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { clickViewport, setViewportCreationPreview } from "./viewport-test-helpers";
|
||||
test("Trigger Volume enter can teleport the player to a Teleport Target", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-player-start").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "playerStart", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-trigger-volume").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "triggerVolume", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-entities").click();
|
||||
await page.getByTestId("add-menu-teleport-target").click();
|
||||
await setViewportCreationPreview(page, "topLeft", { kind: "entity", entityKind: "teleportTarget", audioAssetId: null }, { x: 0, y: 0, z: 0 });
|
||||
await clickViewport(page, "topLeft");
|
||||
await page.getByTestId("teleportTarget-position-x").fill("6");
|
||||
await page.getByTestId("teleportTarget-position-x").press("Tab");
|
||||
await page
|
||||
.locator('[data-testid^="outliner-entity-"]')
|
||||
.filter({ hasText: "Trigger Volume" })
|
||||
.first()
|
||||
.click();
|
||||
await page.getByTestId("add-trigger-teleport-link").click();
|
||||
await page.getByRole("button", { name: "First Person" }).first().click();
|
||||
await page.getByTestId("enter-run-mode").click();
|
||||
await expect(page.getByTestId("runner-shell")).toBeVisible();
|
||||
await expect(page.getByTestId("runner-player-position")).toContainText("6.00,");
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,134 +0,0 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { beginBoxCreation, clickViewport, getEditorStoreSnapshot, getViewportPanel, setSharedBoxCreationPreview } from "./viewport-test-helpers";
|
||||
test("quad viewport layout shows four linked panels with shared selection and active panel state", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await beginBoxCreation(page);
|
||||
await clickViewport(page, "topLeft");
|
||||
await expect(page.getByRole("button", { name: /Whitebox Box 1/ })).toBeVisible();
|
||||
await expect(page.getByText("1 solid selected (Whitebox Box 1)")).toBeVisible();
|
||||
await page.getByTestId("viewport-layout-quad").click();
|
||||
await expect(page.getByTestId("viewport-panel-topLeft")).toBeVisible();
|
||||
await expect(page.getByTestId("viewport-panel-topRight")).toBeVisible();
|
||||
await expect(page.getByTestId("viewport-panel-bottomLeft")).toBeVisible();
|
||||
await expect(page.getByTestId("viewport-panel-bottomRight")).toBeVisible();
|
||||
const initialLayoutSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(initialLayoutSnapshot.viewportQuadSplit).toEqual({
|
||||
x: 0.5,
|
||||
y: 0.5
|
||||
});
|
||||
const dragSplitter = async (testId, deltaX, deltaY) => {
|
||||
const splitter = page.getByTestId(testId);
|
||||
const box = await splitter.boundingBox();
|
||||
if (box === null) {
|
||||
throw new Error(`Missing splitter handle: ${testId}`);
|
||||
}
|
||||
await page.mouse.move(box.x + box.width * 0.5, box.y + box.height * 0.5);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(box.x + box.width * 0.5 + deltaX, box.y + box.height * 0.5 + deltaY);
|
||||
await page.mouse.up();
|
||||
};
|
||||
await dragSplitter("viewport-quad-splitter-center", 80, 48);
|
||||
const afterCenterResizeSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(afterCenterResizeSnapshot.viewportQuadSplit.x).toBeGreaterThan(0.5);
|
||||
expect(afterCenterResizeSnapshot.viewportQuadSplit.y).toBeGreaterThan(0.5);
|
||||
await dragSplitter("viewport-quad-splitter-vertical", -60, 0);
|
||||
const afterVerticalResizeSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(afterVerticalResizeSnapshot.viewportQuadSplit.x).toBeLessThan(afterCenterResizeSnapshot.viewportQuadSplit.x);
|
||||
expect(Math.abs(afterVerticalResizeSnapshot.viewportQuadSplit.y - afterCenterResizeSnapshot.viewportQuadSplit.y)).toBeLessThan(0.02);
|
||||
await dragSplitter("viewport-quad-splitter-horizontal", 0, -40);
|
||||
const afterHorizontalResizeSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(Math.abs(afterHorizontalResizeSnapshot.viewportQuadSplit.x - afterVerticalResizeSnapshot.viewportQuadSplit.x)).toBeLessThan(0.02);
|
||||
expect(afterHorizontalResizeSnapshot.viewportQuadSplit.y).toBeLessThan(afterVerticalResizeSnapshot.viewportQuadSplit.y);
|
||||
await expect(page.getByTestId("viewport-panel-topLeft-view-perspective")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByTestId("viewport-panel-topLeft-display-normal")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByTestId("viewport-panel-topRight-view-top")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByTestId("viewport-panel-topRight-display-authoring")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByTestId("viewport-canvas-topRight")).toHaveCSS("background-color", "rgb(0, 0, 0)");
|
||||
await expect(page.getByTestId("viewport-panel-bottomLeft-view-front")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByTestId("viewport-panel-bottomLeft-display-authoring")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByTestId("viewport-panel-bottomRight-view-side")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByTestId("viewport-panel-bottomRight-display-authoring")).toHaveAttribute("aria-pressed", "true");
|
||||
for (const panelId of ["topLeft", "topRight", "bottomLeft", "bottomRight"]) {
|
||||
await expect(getViewportPanel(page, panelId).locator(".viewport-panel__subtitle")).toHaveCount(0);
|
||||
await expect(getViewportPanel(page, panelId).locator(".viewport-canvas__overlay-text")).toHaveCount(0);
|
||||
}
|
||||
await setSharedBoxCreationPreview(page, "topLeft", { x: 4, y: 0, z: 8 });
|
||||
const initialSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(initialSnapshot).toMatchObject({
|
||||
viewportTransientState: {
|
||||
toolPreview: {
|
||||
kind: "create",
|
||||
sourcePanelId: "topLeft",
|
||||
target: {
|
||||
kind: "box-brush"
|
||||
},
|
||||
center: {
|
||||
x: 4,
|
||||
y: 0,
|
||||
z: 8
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
await getViewportPanel(page, "topRight").click({ position: { x: 16, y: 16 }, force: true });
|
||||
await page.getByTestId("viewport-panel-topRight-view-side").dispatchEvent("click");
|
||||
await expect(getViewportPanel(page, "topRight")).toHaveAttribute("data-active", "true");
|
||||
await expect(page.getByTestId("viewport-panel-topRight-view-side")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByRole("button", { name: /Whitebox Box 1/ })).toBeVisible();
|
||||
const transferredSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(transferredSnapshot).toMatchObject({
|
||||
viewportTransientState: {
|
||||
toolPreview: {
|
||||
kind: "create",
|
||||
sourcePanelId: "topLeft",
|
||||
target: {
|
||||
kind: "box-brush"
|
||||
},
|
||||
center: {
|
||||
x: 4,
|
||||
y: 0,
|
||||
z: 8
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
await getViewportPanel(page, "topLeft").click({ position: { x: 16, y: 16 }, force: true });
|
||||
await page.getByTestId("viewport-panel-topLeft-display-authoring").dispatchEvent("click");
|
||||
await expect(getViewportPanel(page, "topLeft")).toHaveAttribute("data-active", "true");
|
||||
await expect(page.getByTestId("viewport-panel-topLeft-display-authoring")).toHaveAttribute("aria-pressed", "true");
|
||||
await expect(page.getByTestId("viewport-canvas-topLeft")).toHaveCSS("background-color", "rgb(0, 0, 0)");
|
||||
await expect(page.getByText("1 solid selected (Whitebox Box 1)")).toBeVisible();
|
||||
const finalSnapshot = await getEditorStoreSnapshot(page);
|
||||
expect(finalSnapshot).toMatchObject({
|
||||
viewportTransientState: {
|
||||
toolPreview: {
|
||||
kind: "create",
|
||||
sourcePanelId: "topLeft",
|
||||
target: {
|
||||
kind: "box-brush"
|
||||
},
|
||||
center: {
|
||||
x: 4,
|
||||
y: 0,
|
||||
z: 8
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,105 +0,0 @@
|
||||
export const DEFAULT_VIEWPORT_PANEL_ID = "topLeft";
|
||||
export function getViewportPanel(page, panelId = DEFAULT_VIEWPORT_PANEL_ID) {
|
||||
return page.getByTestId(`viewport-panel-${panelId}`);
|
||||
}
|
||||
export function getViewportCanvas(page, panelId = DEFAULT_VIEWPORT_PANEL_ID) {
|
||||
return getViewportPanel(page, panelId).locator("canvas");
|
||||
}
|
||||
export function getViewportOverlay(page, panelId = DEFAULT_VIEWPORT_PANEL_ID) {
|
||||
return page.getByTestId(`viewport-overlay-${panelId}`);
|
||||
}
|
||||
export async function getEditorStoreSnapshot(page) {
|
||||
return page.evaluate(() => {
|
||||
const store = window.__webeditor3dEditorStore;
|
||||
if (store === undefined) {
|
||||
throw new Error("Editor store debug hook is unavailable.");
|
||||
}
|
||||
return store.getState();
|
||||
});
|
||||
}
|
||||
export async function getViewportToolPreview(page) {
|
||||
const snapshot = await getEditorStoreSnapshot(page);
|
||||
return snapshot.viewportTransientState.toolPreview;
|
||||
}
|
||||
export async function replaceSceneDocument(page, document) {
|
||||
await page.evaluate((nextDocument) => {
|
||||
const store = window.__webeditor3dEditorStore;
|
||||
if (store === undefined) {
|
||||
throw new Error("Editor store debug hook is unavailable.");
|
||||
}
|
||||
store.replaceDocument(nextDocument);
|
||||
}, document);
|
||||
}
|
||||
export async function setViewportCreationPreview(page, panelId, target, center) {
|
||||
await page.evaluate(({ sourcePanelId, nextTarget, nextCenter }) => {
|
||||
const store = window.__webeditor3dEditorStore;
|
||||
if (store === undefined) {
|
||||
throw new Error("Editor store debug hook is unavailable.");
|
||||
}
|
||||
store.setViewportToolPreview({
|
||||
kind: "create",
|
||||
sourcePanelId,
|
||||
target: nextTarget,
|
||||
center: nextCenter
|
||||
});
|
||||
}, {
|
||||
sourcePanelId: panelId,
|
||||
nextTarget: target,
|
||||
nextCenter: center
|
||||
});
|
||||
}
|
||||
export async function clearViewportCreationPreview(page) {
|
||||
await page.evaluate(() => {
|
||||
const store = window.__webeditor3dEditorStore;
|
||||
if (store === undefined) {
|
||||
throw new Error("Editor store debug hook is unavailable.");
|
||||
}
|
||||
store.setViewportToolPreview({
|
||||
kind: "none"
|
||||
});
|
||||
});
|
||||
}
|
||||
export async function beginBoxCreation(page) {
|
||||
await page.getByTestId("outliner-add-button").click();
|
||||
await page.getByTestId("add-menu-box").click();
|
||||
}
|
||||
export async function clickViewport(page, panelId = DEFAULT_VIEWPORT_PANEL_ID) {
|
||||
const viewportPanel = getViewportPanel(page, panelId);
|
||||
await viewportPanel.click({ position: { x: 16, y: 16 }, force: true });
|
||||
const fallbackButton = viewportPanel.getByTestId(`viewport-fallback-create-${panelId}`);
|
||||
if ((await fallbackButton.count()) > 0) {
|
||||
await fallbackButton.click();
|
||||
return;
|
||||
}
|
||||
const viewportCanvas = getViewportCanvas(page, panelId);
|
||||
if ((await viewportCanvas.count()) > 0) {
|
||||
await viewportCanvas.click();
|
||||
return;
|
||||
}
|
||||
}
|
||||
export async function clickViewportAtRatio(page, panelId, xRatio, yRatio) {
|
||||
const viewportCanvas = getViewportCanvas(page, panelId);
|
||||
if ((await viewportCanvas.count()) > 0) {
|
||||
const canvasBox = await viewportCanvas.boundingBox();
|
||||
if (canvasBox !== null) {
|
||||
await viewportCanvas.click({
|
||||
position: {
|
||||
x: canvasBox.width * xRatio,
|
||||
y: canvasBox.height * yRatio
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
const viewportPanel = getViewportPanel(page, panelId);
|
||||
const box = await viewportPanel.boundingBox();
|
||||
if (box === null) {
|
||||
throw new Error(`Missing viewport panel for ${panelId}.`);
|
||||
}
|
||||
await page.mouse.click(box.x + box.width * xRatio, box.y + box.height * yRatio);
|
||||
}
|
||||
export async function setSharedBoxCreationPreview(page, panelId, center) {
|
||||
return setViewportCreationPreview(page, panelId, {
|
||||
kind: "box-brush"
|
||||
}, center);
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { clickViewportAtRatio, getEditorStoreSnapshot, replaceSceneDocument } from "./viewport-test-helpers";
|
||||
test("whitebox component selection modes keep object picking intentional across perspective and orthographic panes", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
test.skip((await page.getByText("Viewport Unavailable").count()) > 0, "WebGL is unavailable in this Playwright environment.");
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-selection-modes-main",
|
||||
name: "Selection Fixture",
|
||||
center: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 2
|
||||
}
|
||||
});
|
||||
await replaceSceneDocument(page, {
|
||||
...createEmptySceneDocument({ name: "Selection Modes Scene" }),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
});
|
||||
await page.evaluate(({ target }) => {
|
||||
const store = window.__webeditor3dEditorStore;
|
||||
if (store === undefined) {
|
||||
throw new Error("Editor store debug hook is unavailable.");
|
||||
}
|
||||
const topLeftCameraState = store.getState().viewportPanels.topLeft.cameraState;
|
||||
store.setViewportPanelCameraState("topLeft", {
|
||||
...topLeftCameraState,
|
||||
target,
|
||||
perspectiveOrbit: {
|
||||
radius: 4.5,
|
||||
theta: 0.72,
|
||||
phi: 1.08
|
||||
}
|
||||
});
|
||||
}, { target: brush.center });
|
||||
await expect(page.getByTestId("viewport-selection-mode-topLeft")).toHaveText("Object");
|
||||
await clickViewportAtRatio(page, "topLeft", 0.5, 0.52);
|
||||
let snapshot = await getEditorStoreSnapshot(page);
|
||||
expect(snapshot.whiteboxSelectionMode).toBe("object");
|
||||
expect(snapshot.selection).toMatchObject({
|
||||
kind: "brushes",
|
||||
ids: [brush.id]
|
||||
});
|
||||
await page.getByTestId("viewport-layout-quad").click();
|
||||
await page.evaluate(({ target }) => {
|
||||
const store = window.__webeditor3dEditorStore;
|
||||
if (store === undefined) {
|
||||
throw new Error("Editor store debug hook is unavailable.");
|
||||
}
|
||||
const topRightCameraState = store.getState().viewportPanels.topRight.cameraState;
|
||||
store.setViewportPanelViewMode("topRight", "top");
|
||||
store.setViewportPanelCameraState("topRight", {
|
||||
...topRightCameraState,
|
||||
target,
|
||||
orthographicZoom: 8
|
||||
});
|
||||
}, { target: brush.center });
|
||||
await page.getByTestId("whitebox-selection-mode-face").click();
|
||||
await expect(page.getByTestId("viewport-selection-mode-topRight")).toHaveText("Face");
|
||||
await clickViewportAtRatio(page, "topRight", 0.5, 0.5);
|
||||
snapshot = await getEditorStoreSnapshot(page);
|
||||
expect(snapshot.whiteboxSelectionMode).toBe("face");
|
||||
expect(snapshot.selection).toMatchObject({
|
||||
kind: "brushFace",
|
||||
brushId: brush.id,
|
||||
faceId: "posY"
|
||||
});
|
||||
await expect(page.getByTestId("viewport-panel-active-badge-topRight")).toBeVisible();
|
||||
await page.getByTestId("whitebox-selection-mode-edge").click();
|
||||
await expect(page.getByTestId("viewport-selection-mode-topRight")).toHaveText("Edge");
|
||||
await clickViewportAtRatio(page, "topRight", 0.5, 0.12);
|
||||
snapshot = await getEditorStoreSnapshot(page);
|
||||
expect(snapshot.whiteboxSelectionMode).toBe("edge");
|
||||
expect(snapshot.selection).toMatchObject({
|
||||
kind: "brushEdge",
|
||||
brushId: brush.id,
|
||||
edgeId: "edgeX_posY_negZ"
|
||||
});
|
||||
await page.getByTestId("whitebox-selection-mode-vertex").click();
|
||||
await expect(page.getByTestId("viewport-selection-mode-topRight")).toHaveText("Vertex");
|
||||
await clickViewportAtRatio(page, "topRight", 0.88, 0.12);
|
||||
snapshot = await getEditorStoreSnapshot(page);
|
||||
expect(snapshot.whiteboxSelectionMode).toBe("vertex");
|
||||
expect(snapshot.selection).toMatchObject({
|
||||
kind: "brushVertex",
|
||||
brushId: brush.id,
|
||||
vertexId: "posX_posY_negZ"
|
||||
});
|
||||
await page.getByTestId("whitebox-selection-mode-object").click();
|
||||
await clickViewportAtRatio(page, "topRight", 0.5, 0.5);
|
||||
snapshot = await getEditorStoreSnapshot(page);
|
||||
expect(snapshot.whiteboxSelectionMode).toBe("object");
|
||||
expect(snapshot.selection).toMatchObject({
|
||||
kind: "brushes",
|
||||
ids: [brush.id]
|
||||
});
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,52 +0,0 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
async function setColorInput(locator, value) {
|
||||
await locator.evaluate((element, nextValue) => {
|
||||
const input = element;
|
||||
input.value = nextValue;
|
||||
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
input.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
}, value);
|
||||
}
|
||||
test("world environment settings persist and carry into the runner", async ({ page }) => {
|
||||
const pageErrors = [];
|
||||
const consoleErrors = [];
|
||||
page.on("pageerror", (error) => {
|
||||
pageErrors.push(error.message);
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") {
|
||||
consoleErrors.push(message.text());
|
||||
}
|
||||
});
|
||||
await page.goto("/");
|
||||
await page.evaluate((storageKey) => {
|
||||
window.localStorage.removeItem(storageKey);
|
||||
}, "webeditor3d.scene-document-draft");
|
||||
await page.reload();
|
||||
await page.getByTestId("world-background-mode-gradient").click();
|
||||
await setColorInput(page.getByTestId("world-background-top-color"), "#6a87ab");
|
||||
await setColorInput(page.getByTestId("world-background-bottom-color"), "#151b23");
|
||||
await setColorInput(page.getByTestId("world-ambient-color"), "#d4e2ff");
|
||||
await page.getByTestId("world-ambient-intensity").fill("0.45");
|
||||
await page.getByTestId("world-ambient-intensity").press("Tab");
|
||||
await page.getByTestId("world-sun-intensity").fill("2.25");
|
||||
await page.getByTestId("world-sun-intensity").press("Tab");
|
||||
await page.getByTestId("world-sun-direction-x").fill("-1");
|
||||
await page.getByTestId("world-sun-direction-x").press("Tab");
|
||||
await expect(page.getByTestId("world-background-mode-value")).toContainText("Vertical Gradient");
|
||||
await expect(page.getByTestId("viewport-canvas-topLeft")).toHaveCSS("background-image", /linear-gradient/);
|
||||
await page.getByRole("button", { name: "Save Draft" }).click();
|
||||
await page.getByTestId("world-background-mode-solid").click();
|
||||
await setColorInput(page.getByTestId("world-background-solid-color"), "#223344");
|
||||
await page.getByTestId("world-ambient-intensity").fill("0.9");
|
||||
await page.getByTestId("world-ambient-intensity").press("Tab");
|
||||
await page.getByRole("button", { name: "Load Draft" }).click();
|
||||
await expect(page.getByTestId("world-background-mode-value")).toContainText("Vertical Gradient");
|
||||
await expect(page.getByTestId("world-ambient-intensity")).toHaveValue("0.45");
|
||||
await expect(page.getByTestId("viewport-canvas-topLeft")).toHaveCSS("background-image", /linear-gradient/);
|
||||
await page.getByTestId("enter-run-mode").click();
|
||||
await expect(page.getByTestId("runner-shell")).toBeVisible();
|
||||
await expect(page.getByTestId("runner-shell")).toHaveCSS("background-image", /linear-gradient/);
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
@@ -1,62 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { getBoxBrushBounds, getBoxBrushCornerPositions } from "../../src/geometry/box-brush";
|
||||
describe("box brush geometry", () => {
|
||||
it("builds finite bounds and eight corner positions from canonical box data", () => {
|
||||
const brush = createBoxBrush({
|
||||
center: {
|
||||
x: 2,
|
||||
y: 4,
|
||||
z: -3
|
||||
},
|
||||
size: {
|
||||
x: 6,
|
||||
y: 2,
|
||||
z: 4
|
||||
}
|
||||
});
|
||||
expect(getBoxBrushBounds(brush)).toEqual({
|
||||
min: {
|
||||
x: -1,
|
||||
y: 3,
|
||||
z: -5
|
||||
},
|
||||
max: {
|
||||
x: 5,
|
||||
y: 5,
|
||||
z: -1
|
||||
}
|
||||
});
|
||||
const corners = getBoxBrushCornerPositions(brush);
|
||||
expect(corners).toHaveLength(8);
|
||||
expect(new Set(corners.map((corner) => `${corner.x}:${corner.y}:${corner.z}`)).size).toBe(8);
|
||||
expect(corners.every((corner) => Number.isFinite(corner.x) && Number.isFinite(corner.y) && Number.isFinite(corner.z))).toBe(true);
|
||||
});
|
||||
it("derives rotated world bounds from authored box rotation without changing stable corner count", () => {
|
||||
const brush = createBoxBrush({
|
||||
center: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 45,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 4
|
||||
}
|
||||
});
|
||||
const bounds = getBoxBrushBounds(brush);
|
||||
const corners = getBoxBrushCornerPositions(brush);
|
||||
expect(bounds.min.x).toBeCloseTo(-2.1213203436);
|
||||
expect(bounds.max.x).toBeCloseTo(2.1213203436);
|
||||
expect(bounds.min.z).toBeCloseTo(-2.1213203436);
|
||||
expect(bounds.max.z).toBeCloseTo(2.1213203436);
|
||||
expect(corners).toHaveLength(8);
|
||||
expect(new Set(corners.map((corner) => `${corner.x}:${corner.y}:${corner.z}`)).size).toBe(8);
|
||||
});
|
||||
});
|
||||
@@ -1,60 +0,0 @@
|
||||
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";
|
||||
describe("box face UV projection", () => {
|
||||
it("fit-to-face produces finite UVs normalized across the target face", () => {
|
||||
const brush = createBoxBrush({
|
||||
size: {
|
||||
x: 4,
|
||||
y: 2,
|
||||
z: 6
|
||||
}
|
||||
});
|
||||
brush.faces.posZ.uv = createFitToFaceBoxBrushFaceUvState(brush, "posZ");
|
||||
const geometry = new BoxGeometry(brush.size.x, brush.size.y, brush.size.z);
|
||||
applyBoxBrushFaceUvsToGeometry(geometry, brush);
|
||||
const uvAttribute = geometry.getAttribute("uv");
|
||||
const indexAttribute = geometry.getIndex();
|
||||
const posZGroup = geometry.groups.find((group) => group.materialIndex === 4);
|
||||
expect(indexAttribute).not.toBeNull();
|
||||
expect(posZGroup).toBeDefined();
|
||||
const uniqueVertexIndices = new Set();
|
||||
for (let indexOffset = posZGroup.start; indexOffset < posZGroup.start + posZGroup.count; indexOffset += 1) {
|
||||
uniqueVertexIndices.add(indexAttribute.getX(indexOffset));
|
||||
}
|
||||
const uvValues = Array.from(uniqueVertexIndices, (vertexIndex) => ({
|
||||
u: uvAttribute.getX(vertexIndex),
|
||||
v: uvAttribute.getY(vertexIndex)
|
||||
}));
|
||||
expect(uvValues).toHaveLength(4);
|
||||
expect(uvValues.every((uv) => Number.isFinite(uv.u) && Number.isFinite(uv.v))).toBe(true);
|
||||
expect(Math.min(...uvValues.map((uv) => uv.u))).toBeCloseTo(0);
|
||||
expect(Math.max(...uvValues.map((uv) => uv.u))).toBeCloseTo(1);
|
||||
expect(Math.min(...uvValues.map((uv) => uv.v))).toBeCloseTo(0);
|
||||
expect(Math.max(...uvValues.map((uv) => uv.v))).toBeCloseTo(1);
|
||||
});
|
||||
it("applies rotation, scale, and offset deterministically to projected UVs", () => {
|
||||
const transformedUv = transformProjectedFaceUv({
|
||||
x: 4,
|
||||
y: 0
|
||||
}, {
|
||||
x: 4,
|
||||
y: 2
|
||||
}, {
|
||||
offset: {
|
||||
x: 0.5,
|
||||
y: -0.25
|
||||
},
|
||||
scale: {
|
||||
x: 0.5,
|
||||
y: 1
|
||||
},
|
||||
rotationQuarterTurns: 1,
|
||||
flipU: true,
|
||||
flipV: false
|
||||
});
|
||||
expect(transformedUv.x).toBeCloseTo(2.5);
|
||||
expect(transformedUv.y).toBeCloseTo(-0.25);
|
||||
});
|
||||
});
|
||||
@@ -1,122 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { BoxGeometry, Group, Mesh, MeshBasicMaterial, PlaneGeometry } from "three";
|
||||
import { createModelInstance } from "../../src/assets/model-instances";
|
||||
import { buildGeneratedModelCollider } from "../../src/geometry/model-instance-collider-generation";
|
||||
import { createFixtureLoadedModelAsset, createFixtureLoadedModelAssetFromGeometry, createFixtureModelAssetRecord } from "../helpers/model-collider-fixtures";
|
||||
describe("buildGeneratedModelCollider", () => {
|
||||
it("builds a simple oriented box collider from asset bounds", () => {
|
||||
const { asset } = createFixtureLoadedModelAssetFromGeometry("asset-model-simple", new BoxGeometry(2, 4, 6));
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-simple",
|
||||
assetId: asset.id,
|
||||
collision: {
|
||||
mode: "simple",
|
||||
visible: true
|
||||
}
|
||||
});
|
||||
const collider = buildGeneratedModelCollider(modelInstance, asset);
|
||||
expect(collider).not.toBeNull();
|
||||
expect(collider).toMatchObject({
|
||||
kind: "box",
|
||||
mode: "simple",
|
||||
visible: true,
|
||||
center: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 2,
|
||||
y: 4,
|
||||
z: 6
|
||||
}
|
||||
});
|
||||
});
|
||||
it("builds a static triangle-mesh collider from loaded model geometry", () => {
|
||||
const { asset, loadedAsset } = createFixtureLoadedModelAssetFromGeometry("asset-model-static", new BoxGeometry(2, 1, 3));
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-static",
|
||||
assetId: asset.id,
|
||||
collision: {
|
||||
mode: "static",
|
||||
visible: false
|
||||
}
|
||||
});
|
||||
const collider = buildGeneratedModelCollider(modelInstance, asset, loadedAsset);
|
||||
expect(collider).not.toBeNull();
|
||||
expect(collider?.kind).toBe("trimesh");
|
||||
if (collider === null || collider.kind !== "trimesh") {
|
||||
throw new Error("Expected a trimesh collider.");
|
||||
}
|
||||
expect(collider.mode).toBe("static");
|
||||
expect(Array.from(collider.vertices)).toSatisfy((values) => values.every(Number.isFinite));
|
||||
expect(Array.from(collider.indices)).toSatisfy((values) => values.every(Number.isInteger));
|
||||
});
|
||||
it("builds a terrain heightfield from a regular-grid mesh", () => {
|
||||
const geometry = new PlaneGeometry(4, 4, 2, 2);
|
||||
geometry.rotateX(-Math.PI * 0.5);
|
||||
const { asset, loadedAsset } = createFixtureLoadedModelAssetFromGeometry("asset-model-terrain", geometry);
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-terrain",
|
||||
assetId: asset.id,
|
||||
collision: {
|
||||
mode: "terrain",
|
||||
visible: true
|
||||
}
|
||||
});
|
||||
const collider = buildGeneratedModelCollider(modelInstance, asset, loadedAsset);
|
||||
expect(collider).not.toBeNull();
|
||||
expect(collider?.kind).toBe("heightfield");
|
||||
if (collider === null || collider.kind !== "heightfield") {
|
||||
throw new Error("Expected a heightfield collider.");
|
||||
}
|
||||
expect(collider).toMatchObject({
|
||||
mode: "terrain",
|
||||
rows: 3,
|
||||
cols: 3
|
||||
});
|
||||
expect(Array.from(collider.heights)).toSatisfy((values) => values.every(Number.isFinite));
|
||||
});
|
||||
it("fails terrain mode for meshes that are not a clean regular-grid terrain surface", () => {
|
||||
const { asset, loadedAsset } = createFixtureLoadedModelAssetFromGeometry("asset-model-invalid-terrain", new BoxGeometry(2, 2, 2));
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-invalid-terrain",
|
||||
assetId: asset.id,
|
||||
collision: {
|
||||
mode: "terrain",
|
||||
visible: false
|
||||
}
|
||||
});
|
||||
expect(() => buildGeneratedModelCollider(modelInstance, asset, loadedAsset)).toThrow("cannot use terrain collision");
|
||||
});
|
||||
it("builds explicit convex compound pieces for dynamic mode", () => {
|
||||
const template = new Group();
|
||||
const material = new MeshBasicMaterial();
|
||||
const leftBox = new Mesh(new BoxGeometry(1, 1, 1), material);
|
||||
const rightBox = new Mesh(new BoxGeometry(1, 2, 1), material);
|
||||
leftBox.position.set(-1.25, 0.5, 0);
|
||||
rightBox.position.set(1.25, 1, 0);
|
||||
template.add(leftBox);
|
||||
template.add(rightBox);
|
||||
template.updateMatrixWorld(true);
|
||||
const asset = createFixtureModelAssetRecord("asset-model-dynamic", template);
|
||||
const loadedAsset = createFixtureLoadedModelAsset(asset, template);
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-dynamic",
|
||||
assetId: asset.id,
|
||||
collision: {
|
||||
mode: "dynamic",
|
||||
visible: true
|
||||
}
|
||||
});
|
||||
const collider = buildGeneratedModelCollider(modelInstance, asset, loadedAsset);
|
||||
expect(collider).not.toBeNull();
|
||||
expect(collider).toMatchObject({
|
||||
kind: "compound",
|
||||
mode: "dynamic",
|
||||
decomposition: "spatial-bisect",
|
||||
runtimeBehavior: "fixedQueryOnly"
|
||||
});
|
||||
expect(collider?.kind === "compound" ? collider.pieces.length : 0).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
});
|
||||
@@ -1,84 +0,0 @@
|
||||
import { Box3, Group, Mesh, MeshBasicMaterial } from "three";
|
||||
import { createProjectAssetStorageKey } from "../../src/assets/project-assets";
|
||||
function countMeshes(group) {
|
||||
let count = 0;
|
||||
group.traverse((object) => {
|
||||
if (object.isMesh === true) {
|
||||
count += 1;
|
||||
}
|
||||
});
|
||||
return count;
|
||||
}
|
||||
function countNodes(group) {
|
||||
let count = 0;
|
||||
group.traverse(() => {
|
||||
count += 1;
|
||||
});
|
||||
return count;
|
||||
}
|
||||
function createBoundingBox(group) {
|
||||
const bounds = new Box3().setFromObject(group);
|
||||
if (bounds.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
min: {
|
||||
x: bounds.min.x,
|
||||
y: bounds.min.y,
|
||||
z: bounds.min.z
|
||||
},
|
||||
max: {
|
||||
x: bounds.max.x,
|
||||
y: bounds.max.y,
|
||||
z: bounds.max.z
|
||||
},
|
||||
size: {
|
||||
x: bounds.max.x - bounds.min.x,
|
||||
y: bounds.max.y - bounds.min.y,
|
||||
z: bounds.max.z - bounds.min.z
|
||||
}
|
||||
};
|
||||
}
|
||||
export function createFixtureModelAssetRecord(id, template, sourceName = `${id}.glb`) {
|
||||
template.updateMatrixWorld(true);
|
||||
return {
|
||||
id,
|
||||
kind: "model",
|
||||
sourceName,
|
||||
mimeType: "model/gltf-binary",
|
||||
storageKey: createProjectAssetStorageKey(id),
|
||||
byteLength: 128,
|
||||
metadata: {
|
||||
kind: "model",
|
||||
format: "glb",
|
||||
sceneName: sourceName,
|
||||
nodeCount: countNodes(template),
|
||||
meshCount: countMeshes(template),
|
||||
materialNames: [],
|
||||
textureNames: [],
|
||||
animationNames: [],
|
||||
boundingBox: createBoundingBox(template),
|
||||
warnings: []
|
||||
}
|
||||
};
|
||||
}
|
||||
export function createFixtureLoadedModelAsset(asset, template) {
|
||||
template.updateMatrixWorld(true);
|
||||
return {
|
||||
assetId: asset.id,
|
||||
storageKey: asset.storageKey,
|
||||
metadata: asset.metadata,
|
||||
template,
|
||||
animations: []
|
||||
};
|
||||
}
|
||||
export function createFixtureLoadedModelAssetFromGeometry(assetId, geometry) {
|
||||
const template = new Group();
|
||||
template.add(new Mesh(geometry, new MeshBasicMaterial()));
|
||||
template.updateMatrixWorld(true);
|
||||
const asset = createFixtureModelAssetRecord(assetId, template);
|
||||
return {
|
||||
asset,
|
||||
loadedAsset: createFixtureLoadedModelAsset(asset, template)
|
||||
};
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { SCENE_DOCUMENT_VERSION, createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { serializeSceneDocument } from "../../src/serialization/scene-document-json";
|
||||
import { DEFAULT_SCENE_DRAFT_STORAGE_KEY, getBrowserStorageAccess, loadOrCreateSceneDocument, loadSceneDocumentDraft, saveSceneDocumentDraft } from "../../src/serialization/local-draft-storage";
|
||||
import { createDefaultViewportLayoutState } from "../../src/viewport-three/viewport-layout";
|
||||
class MemoryStorage {
|
||||
values = new Map();
|
||||
getItem(key) {
|
||||
return this.values.get(key) ?? null;
|
||||
}
|
||||
setItem(key, value) {
|
||||
this.values.set(key, value);
|
||||
}
|
||||
removeItem(key) {
|
||||
this.values.delete(key);
|
||||
}
|
||||
}
|
||||
class ThrowingStorage {
|
||||
options;
|
||||
constructor(options = {}) {
|
||||
this.options = options;
|
||||
}
|
||||
getItem() {
|
||||
if (this.options.onGetItem !== undefined) {
|
||||
throw this.options.onGetItem;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
setItem() {
|
||||
if (this.options.onSetItem !== undefined) {
|
||||
throw this.options.onSetItem;
|
||||
}
|
||||
}
|
||||
removeItem() {
|
||||
if (this.options.onRemoveItem !== undefined) {
|
||||
throw this.options.onRemoveItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
describe("local draft storage", () => {
|
||||
it("falls back to a fresh document when stored draft JSON is invalid", () => {
|
||||
const storage = new MemoryStorage();
|
||||
storage.setItem(DEFAULT_SCENE_DRAFT_STORAGE_KEY, "{invalid-json");
|
||||
const result = loadOrCreateSceneDocument(storage);
|
||||
expect(result.document.version).toBe(SCENE_DOCUMENT_VERSION);
|
||||
expect(result.document).toEqual(createEmptySceneDocument());
|
||||
expect(result.diagnostic).toContain("Stored local draft could not be loaded.");
|
||||
expect(result.diagnostic).toContain("Starting with a fresh empty document.");
|
||||
});
|
||||
it("reports browser storage access failures without throwing", () => {
|
||||
const originalDescriptor = Object.getOwnPropertyDescriptor(window, "localStorage");
|
||||
Object.defineProperty(window, "localStorage", {
|
||||
configurable: true,
|
||||
get() {
|
||||
throw new Error("access denied");
|
||||
}
|
||||
});
|
||||
try {
|
||||
const result = getBrowserStorageAccess();
|
||||
expect(result.storage).toBeNull();
|
||||
expect(result.diagnostic).toContain("Browser local storage is unavailable.");
|
||||
expect(result.diagnostic).toContain("access denied");
|
||||
}
|
||||
finally {
|
||||
if (originalDescriptor !== undefined) {
|
||||
Object.defineProperty(window, "localStorage", originalDescriptor);
|
||||
}
|
||||
else {
|
||||
Reflect.deleteProperty(window, "localStorage");
|
||||
}
|
||||
}
|
||||
});
|
||||
it("returns an error result when reading from storage throws", () => {
|
||||
const result = loadSceneDocumentDraft(new ThrowingStorage({
|
||||
onGetItem: new Error("blocked read")
|
||||
}));
|
||||
expect(result.status).toBe("error");
|
||||
expect(result.message).toContain("blocked read");
|
||||
});
|
||||
it("returns an error result when saving to storage throws", () => {
|
||||
const result = saveSceneDocumentDraft(new ThrowingStorage({
|
||||
onSetItem: new Error("quota exceeded")
|
||||
}), createEmptySceneDocument());
|
||||
expect(result.status).toBe("error");
|
||||
expect(result.message).toContain("quota exceeded");
|
||||
});
|
||||
it("stores and restores editor viewport layout state alongside the document draft", () => {
|
||||
const storage = new MemoryStorage();
|
||||
const viewportLayoutState = createDefaultViewportLayoutState();
|
||||
viewportLayoutState.layoutMode = "quad";
|
||||
viewportLayoutState.activePanelId = "bottomRight";
|
||||
viewportLayoutState.panels.topLeft.displayMode = "wireframe";
|
||||
viewportLayoutState.panels.topLeft.cameraState.target = {
|
||||
x: 8,
|
||||
y: 3,
|
||||
z: -5
|
||||
};
|
||||
viewportLayoutState.panels.topLeft.cameraState.perspectiveOrbit.theta = 1.25;
|
||||
viewportLayoutState.panels.topLeft.cameraState.orthographicZoom = 2.5;
|
||||
expect(saveSceneDocumentDraft(storage, createEmptySceneDocument({ name: "Viewport Draft" }), viewportLayoutState)).toEqual({
|
||||
status: "saved",
|
||||
message: "Local draft saved."
|
||||
});
|
||||
const result = loadSceneDocumentDraft(storage);
|
||||
expect(result).toMatchObject({
|
||||
status: "loaded",
|
||||
document: {
|
||||
name: "Viewport Draft"
|
||||
},
|
||||
viewportLayoutState: {
|
||||
layoutMode: "quad",
|
||||
activePanelId: "bottomRight",
|
||||
panels: {
|
||||
topLeft: {
|
||||
displayMode: "wireframe",
|
||||
cameraState: {
|
||||
target: {
|
||||
x: 8,
|
||||
y: 3,
|
||||
z: -5
|
||||
},
|
||||
perspectiveOrbit: {
|
||||
theta: 1.25
|
||||
},
|
||||
orthographicZoom: 2.5
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
it("loads older raw scene-document drafts without requiring viewport layout state", () => {
|
||||
const storage = new MemoryStorage();
|
||||
storage.setItem(DEFAULT_SCENE_DRAFT_STORAGE_KEY, serializeSceneDocument(createEmptySceneDocument({ name: "Legacy Draft" })));
|
||||
const result = loadSceneDocumentDraft(storage);
|
||||
expect(result).toMatchObject({
|
||||
status: "loaded",
|
||||
document: {
|
||||
name: "Legacy Draft"
|
||||
},
|
||||
viewportLayoutState: null
|
||||
});
|
||||
});
|
||||
it("refuses to save an invalid scene document draft", () => {
|
||||
const invalidBrush = createBoxBrush({
|
||||
id: "brush-invalid"
|
||||
});
|
||||
invalidBrush.faces.posX.materialId = "missing-material";
|
||||
const result = saveSceneDocumentDraft(new MemoryStorage(), {
|
||||
...createEmptySceneDocument(),
|
||||
brushes: {
|
||||
[invalidBrush.id]: invalidBrush
|
||||
}
|
||||
});
|
||||
expect(result.status).toBe("error");
|
||||
expect(result.message).toContain("validation error");
|
||||
});
|
||||
});
|
||||
@@ -1,30 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createProjectAssetStorageKey } from "../../src/assets/project-assets";
|
||||
import { createInMemoryProjectAssetStorage } from "../../src/assets/project-asset-storage";
|
||||
describe("project asset storage", () => {
|
||||
it("stores, clones, and deletes binary asset file packages", async () => {
|
||||
const storage = createInMemoryProjectAssetStorage();
|
||||
const storageKey = createProjectAssetStorageKey("asset-model-triangle");
|
||||
const bytes = new Uint8Array([0, 1, 2, 3, 4]).buffer;
|
||||
const sidecarBytes = new Uint8Array([9, 8, 7]).buffer;
|
||||
await storage.putAsset(storageKey, {
|
||||
files: {
|
||||
"tiny-triangle.gltf": {
|
||||
bytes,
|
||||
mimeType: "model/gltf+json"
|
||||
},
|
||||
"triangle.bin": {
|
||||
bytes: sidecarBytes,
|
||||
mimeType: "application/octet-stream"
|
||||
}
|
||||
}
|
||||
});
|
||||
const loadedAsset = await storage.getAsset(storageKey);
|
||||
expect(loadedAsset).not.toBeNull();
|
||||
expect(Object.keys(loadedAsset?.files ?? {})).toEqual(["tiny-triangle.gltf", "triangle.bin"]);
|
||||
expect(Array.from(new Uint8Array(loadedAsset?.files["tiny-triangle.gltf"]?.bytes ?? new ArrayBuffer(0)))).toEqual([0, 1, 2, 3, 4]);
|
||||
expect(Array.from(new Uint8Array(loadedAsset?.files["triangle.bin"]?.bytes ?? new ArrayBuffer(0)))).toEqual([9, 8, 7]);
|
||||
await storage.deleteAsset(storageKey);
|
||||
await expect(storage.getAsset(storageKey)).resolves.toBeNull();
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1 +0,0 @@
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
@@ -1,66 +0,0 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { createInMemoryProjectAssetStorage } from "../../src/assets/project-asset-storage";
|
||||
import { importAudioAssetFromFile, loadAudioAssetFromStorage } from "../../src/assets/audio-assets";
|
||||
describe("audio asset import and storage", () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
it("persists audio through the generic project asset storage and reloads decoded buffers", async () => {
|
||||
const decodedBuffer = {
|
||||
duration: 2.5,
|
||||
numberOfChannels: 2,
|
||||
sampleRate: 44100
|
||||
};
|
||||
const decodeCalls = [];
|
||||
const closeCalls = [];
|
||||
class MockAudioContext {
|
||||
state = "running";
|
||||
async decodeAudioData(bytes) {
|
||||
decodeCalls.push(bytes);
|
||||
return decodedBuffer;
|
||||
}
|
||||
async close() {
|
||||
closeCalls.push(1);
|
||||
}
|
||||
}
|
||||
vi.stubGlobal("AudioContext", MockAudioContext);
|
||||
vi.stubGlobal("webkitAudioContext", MockAudioContext);
|
||||
const storage = createInMemoryProjectAssetStorage();
|
||||
const fileBytes = new Uint8Array([1, 2, 3, 4]).buffer;
|
||||
const file = {
|
||||
name: "lobby-loop.ogg",
|
||||
type: "audio/ogg",
|
||||
webkitRelativePath: "",
|
||||
arrayBuffer: async () => fileBytes
|
||||
};
|
||||
const importedAudio = await importAudioAssetFromFile(file, storage);
|
||||
const storedAsset = await storage.getAsset(importedAudio.asset.storageKey);
|
||||
const reloadedAudio = await loadAudioAssetFromStorage(storage, importedAudio.asset);
|
||||
expect(importedAudio.asset).toMatchObject({
|
||||
kind: "audio",
|
||||
sourceName: "lobby-loop.ogg",
|
||||
mimeType: "audio/ogg",
|
||||
byteLength: fileBytes.byteLength
|
||||
});
|
||||
expect(importedAudio.asset.metadata).toMatchObject({
|
||||
kind: "audio",
|
||||
durationSeconds: 2.5,
|
||||
channelCount: 2,
|
||||
sampleRateHz: 44100
|
||||
});
|
||||
expect(storedAsset).toEqual({
|
||||
files: {
|
||||
"lobby-loop.ogg": {
|
||||
bytes: fileBytes,
|
||||
mimeType: "audio/ogg"
|
||||
}
|
||||
}
|
||||
});
|
||||
expect(reloadedAudio.assetId).toBe(importedAudio.asset.id);
|
||||
expect(reloadedAudio.storageKey).toBe(importedAudio.asset.storageKey);
|
||||
expect(reloadedAudio.metadata).toEqual(importedAudio.asset.metadata);
|
||||
expect(reloadedAudio.buffer).toBe(decodedBuffer);
|
||||
expect(decodeCalls).toHaveLength(2);
|
||||
expect(closeCalls).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
@@ -1,85 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DEFAULT_POINT_LIGHT_COLOR_HEX, DEFAULT_POINT_LIGHT_DISTANCE, DEFAULT_POINT_LIGHT_INTENSITY, DEFAULT_PLAYER_START_BOX_SIZE, DEFAULT_PLAYER_START_CAPSULE_HEIGHT, DEFAULT_PLAYER_START_CAPSULE_RADIUS, DEFAULT_PLAYER_START_EYE_HEIGHT, DEFAULT_SPOT_LIGHT_ANGLE_DEGREES, DEFAULT_SPOT_LIGHT_COLOR_HEX, DEFAULT_SPOT_LIGHT_DISTANCE, DEFAULT_SPOT_LIGHT_DIRECTION, DEFAULT_SPOT_LIGHT_INTENSITY, DEFAULT_INTERACTABLE_PROMPT, DEFAULT_SOUND_EMITTER_AUDIO_ASSET_ID, DEFAULT_SOUND_EMITTER_MAX_DISTANCE, DEFAULT_SOUND_EMITTER_REF_DISTANCE, DEFAULT_SOUND_EMITTER_VOLUME, DEFAULT_TRIGGER_VOLUME_SIZE, createPointLightEntity, createDefaultEntityInstance, createInteractableEntity, createSpotLightEntity, getEntityRegistryEntry } from "../../src/entities/entity-instances";
|
||||
describe("entity registry defaults", () => {
|
||||
it("creates explicit typed defaults for each supported entity kind", () => {
|
||||
expect(createDefaultEntityInstance("playerStart")).toMatchObject({
|
||||
kind: "playerStart",
|
||||
position: { x: 0, y: 0, z: 0 },
|
||||
yawDegrees: 0,
|
||||
collider: {
|
||||
mode: "capsule",
|
||||
eyeHeight: DEFAULT_PLAYER_START_EYE_HEIGHT,
|
||||
capsuleRadius: DEFAULT_PLAYER_START_CAPSULE_RADIUS,
|
||||
capsuleHeight: DEFAULT_PLAYER_START_CAPSULE_HEIGHT,
|
||||
boxSize: DEFAULT_PLAYER_START_BOX_SIZE
|
||||
}
|
||||
});
|
||||
expect(createDefaultEntityInstance("pointLight")).toMatchObject({
|
||||
kind: "pointLight",
|
||||
position: { x: 0, y: 0, z: 0 },
|
||||
colorHex: DEFAULT_POINT_LIGHT_COLOR_HEX,
|
||||
intensity: DEFAULT_POINT_LIGHT_INTENSITY,
|
||||
distance: DEFAULT_POINT_LIGHT_DISTANCE
|
||||
});
|
||||
expect(createDefaultEntityInstance("spotLight")).toMatchObject({
|
||||
kind: "spotLight",
|
||||
position: { x: 0, y: 0, z: 0 },
|
||||
direction: DEFAULT_SPOT_LIGHT_DIRECTION,
|
||||
colorHex: DEFAULT_SPOT_LIGHT_COLOR_HEX,
|
||||
intensity: DEFAULT_SPOT_LIGHT_INTENSITY,
|
||||
distance: DEFAULT_SPOT_LIGHT_DISTANCE,
|
||||
angleDegrees: DEFAULT_SPOT_LIGHT_ANGLE_DEGREES
|
||||
});
|
||||
expect(createDefaultEntityInstance("soundEmitter")).toMatchObject({
|
||||
kind: "soundEmitter",
|
||||
position: { x: 0, y: 0, z: 0 },
|
||||
audioAssetId: DEFAULT_SOUND_EMITTER_AUDIO_ASSET_ID,
|
||||
volume: DEFAULT_SOUND_EMITTER_VOLUME,
|
||||
refDistance: DEFAULT_SOUND_EMITTER_REF_DISTANCE,
|
||||
maxDistance: DEFAULT_SOUND_EMITTER_MAX_DISTANCE,
|
||||
autoplay: false,
|
||||
loop: false
|
||||
});
|
||||
expect(createDefaultEntityInstance("triggerVolume")).toMatchObject({
|
||||
kind: "triggerVolume",
|
||||
position: { x: 0, y: 0, z: 0 },
|
||||
size: DEFAULT_TRIGGER_VOLUME_SIZE,
|
||||
triggerOnEnter: true,
|
||||
triggerOnExit: false
|
||||
});
|
||||
expect(createDefaultEntityInstance("teleportTarget")).toMatchObject({
|
||||
kind: "teleportTarget",
|
||||
position: { x: 0, y: 0, z: 0 },
|
||||
yawDegrees: 0
|
||||
});
|
||||
expect(createDefaultEntityInstance("interactable")).toMatchObject({
|
||||
kind: "interactable",
|
||||
position: { x: 0, y: 0, z: 0 },
|
||||
radius: 1.5,
|
||||
prompt: DEFAULT_INTERACTABLE_PROMPT,
|
||||
enabled: true
|
||||
});
|
||||
});
|
||||
it("keeps entity metadata and prompt validation explicit", () => {
|
||||
expect(getEntityRegistryEntry("triggerVolume")).toMatchObject({
|
||||
kind: "triggerVolume",
|
||||
label: "Trigger Volume"
|
||||
});
|
||||
expect(createInteractableEntity({
|
||||
prompt: " Open "
|
||||
}).prompt).toBe("Open");
|
||||
expect(() => createInteractableEntity({
|
||||
prompt: " "
|
||||
})).toThrow("Interactable prompt must be non-empty.");
|
||||
expect(() => createPointLightEntity({
|
||||
distance: 0
|
||||
})).toThrow("Point Light distance must be a finite number greater than zero.");
|
||||
expect(() => createSpotLightEntity({
|
||||
direction: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}
|
||||
})).toThrow("Spot Light direction must not be the zero vector.");
|
||||
});
|
||||
});
|
||||
@@ -1,17 +0,0 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
function readPackageManifest() {
|
||||
return JSON.parse(readFileSync(resolve(process.cwd(), "package.json"), "utf8"));
|
||||
}
|
||||
describe("package scripts", () => {
|
||||
it("exposes the expected verification script contract", () => {
|
||||
const packageManifest = readPackageManifest();
|
||||
expect(packageManifest.scripts).toBeDefined();
|
||||
expect(packageManifest.scripts?.["test"]).toBeDefined();
|
||||
expect(packageManifest.scripts?.["test:browser"]).toBeDefined();
|
||||
expect(packageManifest.scripts?.["test:e2e"]).toBeDefined();
|
||||
expect(packageManifest.scripts?.["typecheck"]).toBeDefined();
|
||||
expect(packageManifest.scripts?.["test:typecheck"]).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,494 +0,0 @@
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { act } from "react";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { App } from "../../src/app/App";
|
||||
import { createEditorStore } from "../../src/app/editor-store";
|
||||
import { createModelInstance } from "../../src/assets/model-instances";
|
||||
import { createProjectAssetStorageKey } from "../../src/assets/project-assets";
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { createPlayerStartEntity } from "../../src/entities/entity-instances";
|
||||
const { MockViewportHost, viewportHostInstances } = vi.hoisted(() => {
|
||||
const viewportHostInstances = [];
|
||||
class MockViewportHost {
|
||||
panelId = null;
|
||||
setPanelId = vi.fn((panelId) => {
|
||||
this.panelId = panelId;
|
||||
});
|
||||
mount = vi.fn();
|
||||
dispose = vi.fn();
|
||||
updateWorld = vi.fn();
|
||||
updateAssets = vi.fn();
|
||||
updateDocument = vi.fn();
|
||||
setViewMode = vi.fn();
|
||||
setDisplayMode = vi.fn();
|
||||
setCameraState = vi.fn();
|
||||
setBrushSelectionChangeHandler = vi.fn();
|
||||
setCameraStateChangeHandler = vi.fn();
|
||||
setCreationPreviewChangeHandler = vi.fn();
|
||||
setCreationCommitHandler = vi.fn();
|
||||
setTransformSessionChangeHandler = vi.fn();
|
||||
setTransformCommitHandler = vi.fn();
|
||||
setTransformCancelHandler = vi.fn();
|
||||
setWhiteboxHoverLabelChangeHandler = vi.fn();
|
||||
setWhiteboxSelectionMode = vi.fn();
|
||||
setWhiteboxSnapSettings = vi.fn();
|
||||
setToolMode = vi.fn();
|
||||
setCreationPreview = vi.fn();
|
||||
setTransformSession = vi.fn();
|
||||
focusSelection = vi.fn();
|
||||
constructor() {
|
||||
viewportHostInstances.push(this);
|
||||
}
|
||||
}
|
||||
return {
|
||||
MockViewportHost,
|
||||
viewportHostInstances
|
||||
};
|
||||
});
|
||||
vi.mock("../../src/viewport-three/viewport-host", () => ({
|
||||
ViewportHost: MockViewportHost
|
||||
}));
|
||||
vi.mock("../../src/assets/project-asset-storage", () => ({
|
||||
getBrowserProjectAssetStorageAccess: vi.fn(async () => ({
|
||||
storage: null,
|
||||
diagnostic: null
|
||||
}))
|
||||
}));
|
||||
const modelAsset = {
|
||||
id: "asset-model-transform-integration",
|
||||
kind: "model",
|
||||
sourceName: "transform-fixture.glb",
|
||||
mimeType: "model/gltf-binary",
|
||||
storageKey: createProjectAssetStorageKey("asset-model-transform-integration"),
|
||||
byteLength: 64,
|
||||
metadata: {
|
||||
kind: "model",
|
||||
format: "glb",
|
||||
sceneName: "Transform Fixture",
|
||||
nodeCount: 1,
|
||||
meshCount: 1,
|
||||
materialNames: [],
|
||||
textureNames: [],
|
||||
animationNames: [],
|
||||
boundingBox: {
|
||||
min: {
|
||||
x: -0.5,
|
||||
y: 0,
|
||||
z: -0.5
|
||||
},
|
||||
max: {
|
||||
x: 0.5,
|
||||
y: 1,
|
||||
z: 0.5
|
||||
},
|
||||
size: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 1
|
||||
}
|
||||
},
|
||||
warnings: []
|
||||
}
|
||||
};
|
||||
function getTopLeftViewportHost() {
|
||||
const viewportHost = viewportHostInstances.find((instance) => instance.panelId === "topLeft");
|
||||
if (viewportHost === undefined) {
|
||||
throw new Error("Top-left viewport host was not mounted.");
|
||||
}
|
||||
return viewportHost;
|
||||
}
|
||||
async function renderTransformFixtureApp() {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-transform-main",
|
||||
name: "Brush Transform Fixture",
|
||||
center: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
}
|
||||
});
|
||||
const playerStart = createPlayerStartEntity({
|
||||
id: "entity-player-start-transform",
|
||||
name: "Player Start Fixture",
|
||||
position: {
|
||||
x: 2,
|
||||
y: 0,
|
||||
z: -2
|
||||
},
|
||||
yawDegrees: 0
|
||||
});
|
||||
const modelInstance = createModelInstance({
|
||||
id: "model-instance-transform-main",
|
||||
assetId: modelAsset.id,
|
||||
name: "Model Transform Fixture",
|
||||
position: {
|
||||
x: -3,
|
||||
y: 0,
|
||||
z: 3
|
||||
}
|
||||
});
|
||||
const store = createEditorStore({
|
||||
initialDocument: {
|
||||
...createEmptySceneDocument({ name: "Transform Fixture" }),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
},
|
||||
assets: {
|
||||
[modelAsset.id]: modelAsset
|
||||
},
|
||||
entities: {
|
||||
[playerStart.id]: playerStart
|
||||
},
|
||||
modelInstances: {
|
||||
[modelInstance.id]: modelInstance
|
||||
}
|
||||
}
|
||||
});
|
||||
render(_jsx(App, { store: store }));
|
||||
await waitFor(() => {
|
||||
expect(viewportHostInstances.length).toBeGreaterThan(0);
|
||||
expect(getTopLeftViewportHost().setTransformCommitHandler).toHaveBeenCalled();
|
||||
});
|
||||
return {
|
||||
store,
|
||||
brush,
|
||||
playerStart,
|
||||
modelInstance,
|
||||
viewportHost: getTopLeftViewportHost()
|
||||
};
|
||||
}
|
||||
async function renderQuadTransformFixtureApp() {
|
||||
const fixture = await renderTransformFixtureApp();
|
||||
act(() => {
|
||||
fixture.store.setViewportLayoutMode("quad");
|
||||
});
|
||||
return fixture;
|
||||
}
|
||||
function getLatestTransformSession(store) {
|
||||
const transformSession = store.getState().viewportTransientState.transformSession;
|
||||
if (transformSession.kind !== "active") {
|
||||
throw new Error("Expected an active transform session.");
|
||||
}
|
||||
return transformSession;
|
||||
}
|
||||
function emitTransformPreview(viewportHost, transformSession) {
|
||||
const handler = viewportHost.setTransformSessionChangeHandler.mock.calls.at(-1)?.[0];
|
||||
if (handler === undefined) {
|
||||
throw new Error("Transform session change handler was not registered.");
|
||||
}
|
||||
act(() => {
|
||||
handler(transformSession);
|
||||
});
|
||||
}
|
||||
function commitTransform(viewportHost, transformSession) {
|
||||
const handler = viewportHost.setTransformCommitHandler.mock.calls.at(-1)?.[0];
|
||||
if (handler === undefined) {
|
||||
throw new Error("Transform commit handler was not registered.");
|
||||
}
|
||||
act(() => {
|
||||
handler(transformSession);
|
||||
});
|
||||
}
|
||||
describe("transform foundation integration", () => {
|
||||
beforeEach(() => {
|
||||
viewportHostInstances.length = 0;
|
||||
vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockImplementation(() => ({}));
|
||||
});
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
it("moves a whole brush through keyboard entry, axis constraint, and viewport commit", async () => {
|
||||
const { store, brush, viewportHost } = await renderTransformFixtureApp();
|
||||
await act(async () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Brush Transform Fixture$/ }));
|
||||
});
|
||||
fireEvent.keyDown(window, {
|
||||
key: "g",
|
||||
code: "KeyG"
|
||||
});
|
||||
expect(store.getState().viewportTransientState.transformSession).toMatchObject({
|
||||
kind: "active",
|
||||
operation: "translate",
|
||||
axisConstraint: null,
|
||||
target: {
|
||||
kind: "brush",
|
||||
brushId: brush.id
|
||||
}
|
||||
});
|
||||
fireEvent.keyDown(window, {
|
||||
key: "x",
|
||||
code: "KeyX"
|
||||
});
|
||||
expect(store.getState().viewportTransientState.transformSession).toMatchObject({
|
||||
kind: "active",
|
||||
axisConstraint: "x"
|
||||
});
|
||||
const previewSession = {
|
||||
...getLatestTransformSession(store),
|
||||
preview: {
|
||||
kind: "brush",
|
||||
center: {
|
||||
x: 6,
|
||||
y: brush.center.y,
|
||||
z: brush.center.z
|
||||
},
|
||||
rotationDegrees: {
|
||||
...brush.rotationDegrees
|
||||
},
|
||||
size: {
|
||||
...brush.size
|
||||
}
|
||||
}
|
||||
};
|
||||
emitTransformPreview(viewportHost, previewSession);
|
||||
commitTransform(viewportHost, previewSession);
|
||||
expect(store.getState().viewportTransientState.transformSession).toEqual({
|
||||
kind: "none"
|
||||
});
|
||||
expect(store.getState().document.brushes[brush.id].center).toEqual({
|
||||
x: 6,
|
||||
y: brush.center.y,
|
||||
z: brush.center.z
|
||||
});
|
||||
});
|
||||
it("rotates and scales a whole whitebox box through the shared transform controller", async () => {
|
||||
const { store, brush, viewportHost } = await renderTransformFixtureApp();
|
||||
await act(async () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Brush Transform Fixture$/ }));
|
||||
});
|
||||
fireEvent.click(screen.getByTestId("transform-rotate-button"));
|
||||
const rotatePreviewSession = {
|
||||
...getLatestTransformSession(store),
|
||||
preview: {
|
||||
kind: "brush",
|
||||
center: {
|
||||
...brush.center
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 37.5,
|
||||
z: 12.5
|
||||
},
|
||||
size: {
|
||||
...brush.size
|
||||
}
|
||||
}
|
||||
};
|
||||
emitTransformPreview(viewportHost, rotatePreviewSession);
|
||||
commitTransform(viewportHost, rotatePreviewSession);
|
||||
expect(store.getState().document.brushes[brush.id].rotationDegrees).toEqual({
|
||||
x: 0,
|
||||
y: 37.5,
|
||||
z: 12.5
|
||||
});
|
||||
fireEvent.click(screen.getByTestId("transform-scale-button"));
|
||||
const scalePreviewSession = {
|
||||
...getLatestTransformSession(store),
|
||||
preview: {
|
||||
kind: "brush",
|
||||
center: {
|
||||
...brush.center
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 37.5,
|
||||
z: 12.5
|
||||
},
|
||||
size: {
|
||||
x: 3.5,
|
||||
y: 2.5,
|
||||
z: 4.5
|
||||
}
|
||||
}
|
||||
};
|
||||
emitTransformPreview(viewportHost, scalePreviewSession);
|
||||
commitTransform(viewportHost, scalePreviewSession);
|
||||
expect(store.getState().document.brushes[brush.id]).toMatchObject({
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 37.5,
|
||||
z: 12.5
|
||||
},
|
||||
size: {
|
||||
x: 3.5,
|
||||
y: 2.5,
|
||||
z: 4.5
|
||||
}
|
||||
});
|
||||
});
|
||||
it("keeps transform controls coherent across object and component modes", async () => {
|
||||
const { store, brush } = await renderTransformFixtureApp();
|
||||
await act(async () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Brush Transform Fixture$/ }));
|
||||
});
|
||||
expect(screen.getByTestId("transform-translate-button")).not.toBeDisabled();
|
||||
await act(async () => {
|
||||
fireEvent.click(screen.getByTestId("whitebox-selection-mode-face"));
|
||||
});
|
||||
expect(store.getState().whiteboxSelectionMode).toBe("face");
|
||||
expect(screen.getByTestId("transform-translate-button")).toBeDisabled();
|
||||
expect(screen.getByTestId("transform-rotate-button")).toBeDisabled();
|
||||
expect(screen.getByTestId("transform-scale-button")).toBeDisabled();
|
||||
act(() => {
|
||||
store.setSelection({
|
||||
kind: "brushFace",
|
||||
brushId: brush.id,
|
||||
faceId: "posY"
|
||||
});
|
||||
});
|
||||
expect(screen.getByTestId("transform-translate-button")).not.toBeDisabled();
|
||||
expect(screen.getByTestId("transform-rotate-button")).not.toBeDisabled();
|
||||
expect(screen.getByTestId("transform-scale-button")).not.toBeDisabled();
|
||||
await act(async () => {
|
||||
fireEvent.click(screen.getByTestId("whitebox-selection-mode-vertex"));
|
||||
});
|
||||
act(() => {
|
||||
store.setSelection({
|
||||
kind: "brushVertex",
|
||||
brushId: brush.id,
|
||||
vertexId: "posX_posY_posZ"
|
||||
});
|
||||
});
|
||||
expect(screen.getByTestId("transform-translate-button")).not.toBeDisabled();
|
||||
expect(screen.getByTestId("transform-rotate-button")).toBeDisabled();
|
||||
expect(screen.getByTestId("transform-scale-button")).toBeDisabled();
|
||||
await act(async () => {
|
||||
fireEvent.click(screen.getByTestId("whitebox-selection-mode-object"));
|
||||
});
|
||||
expect(store.getState().whiteboxSelectionMode).toBe("object");
|
||||
expect(store.getState().selection).toEqual({
|
||||
kind: "brushes",
|
||||
ids: [brush.id]
|
||||
});
|
||||
expect(screen.getByTestId("transform-translate-button")).not.toBeDisabled();
|
||||
});
|
||||
it("moves an entity through the shared transform controller", async () => {
|
||||
const { store, playerStart, viewportHost } = await renderTransformFixtureApp();
|
||||
await act(async () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Player Start Fixture$/ }));
|
||||
});
|
||||
fireEvent.keyDown(window, {
|
||||
key: "g",
|
||||
code: "KeyG"
|
||||
});
|
||||
const previewSession = {
|
||||
...getLatestTransformSession(store),
|
||||
preview: {
|
||||
kind: "entity",
|
||||
position: {
|
||||
x: 8,
|
||||
y: 0,
|
||||
z: -4
|
||||
},
|
||||
rotation: {
|
||||
kind: "yaw",
|
||||
yawDegrees: playerStart.yawDegrees
|
||||
}
|
||||
}
|
||||
};
|
||||
emitTransformPreview(viewportHost, previewSession);
|
||||
commitTransform(viewportHost, previewSession);
|
||||
expect(store.getState().document.entities[playerStart.id]).toMatchObject({
|
||||
position: {
|
||||
x: 8,
|
||||
y: 0,
|
||||
z: -4
|
||||
}
|
||||
});
|
||||
});
|
||||
it("cancels an active transform with Escape without committing preview changes", async () => {
|
||||
const { store, playerStart, viewportHost } = await renderTransformFixtureApp();
|
||||
await act(async () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Player Start Fixture$/ }));
|
||||
});
|
||||
fireEvent.keyDown(window, {
|
||||
key: "g",
|
||||
code: "KeyG"
|
||||
});
|
||||
emitTransformPreview(viewportHost, {
|
||||
...getLatestTransformSession(store),
|
||||
preview: {
|
||||
kind: "entity",
|
||||
position: {
|
||||
x: 12,
|
||||
y: 0,
|
||||
z: -6
|
||||
},
|
||||
rotation: {
|
||||
kind: "yaw",
|
||||
yawDegrees: playerStart.yawDegrees
|
||||
}
|
||||
}
|
||||
});
|
||||
fireEvent.keyDown(window, {
|
||||
key: "Escape",
|
||||
code: "Escape"
|
||||
});
|
||||
expect(store.getState().viewportTransientState.transformSession).toEqual({
|
||||
kind: "none"
|
||||
});
|
||||
expect(store.getState().document.entities[playerStart.id]).toEqual(playerStart);
|
||||
});
|
||||
it("moves a model instance through the shared transform controller", async () => {
|
||||
const { store, modelInstance, viewportHost } = await renderTransformFixtureApp();
|
||||
await act(async () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Model Transform Fixture$/ }));
|
||||
});
|
||||
fireEvent.keyDown(window, {
|
||||
key: "g",
|
||||
code: "KeyG"
|
||||
});
|
||||
const previewSession = {
|
||||
...getLatestTransformSession(store),
|
||||
preview: {
|
||||
kind: "modelInstance",
|
||||
position: {
|
||||
x: -1,
|
||||
y: 0,
|
||||
z: 7
|
||||
},
|
||||
rotationDegrees: {
|
||||
...modelInstance.rotationDegrees
|
||||
},
|
||||
scale: {
|
||||
...modelInstance.scale
|
||||
}
|
||||
}
|
||||
};
|
||||
emitTransformPreview(viewportHost, previewSession);
|
||||
commitTransform(viewportHost, previewSession);
|
||||
expect(store.getState().document.modelInstances[modelInstance.id]).toMatchObject({
|
||||
position: {
|
||||
x: -1,
|
||||
y: 0,
|
||||
z: 7
|
||||
}
|
||||
});
|
||||
});
|
||||
it("uses the hovered quad viewport as the active transform panel for keyboard entry", async () => {
|
||||
const { store, brush } = await renderQuadTransformFixtureApp();
|
||||
await act(async () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: /^Brush Transform Fixture$/ }));
|
||||
});
|
||||
fireEvent.pointerMove(screen.getByTestId("viewport-panel-bottomRight"), {
|
||||
clientX: 24,
|
||||
clientY: 24
|
||||
});
|
||||
fireEvent.keyDown(window, {
|
||||
key: "g",
|
||||
code: "KeyG"
|
||||
});
|
||||
expect(store.getState().activeViewportPanelId).toBe("bottomRight");
|
||||
expect(store.getState().viewportTransientState.transformSession).toMatchObject({
|
||||
kind: "active",
|
||||
operation: "translate",
|
||||
sourcePanelId: "bottomRight",
|
||||
target: {
|
||||
kind: "brush",
|
||||
brushId: brush.id
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,92 +0,0 @@
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { render, waitFor } from "@testing-library/react";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createInactiveTransformSession } from "../../src/core/transform-session";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { ViewportCanvas } from "../../src/viewport-three/ViewportCanvas";
|
||||
import { createDefaultViewportPanelCameraState } from "../../src/viewport-three/viewport-layout";
|
||||
const { MockViewportHost, viewportHostInstances } = vi.hoisted(() => {
|
||||
const viewportHostInstances = [];
|
||||
class MockViewportHost {
|
||||
mount = vi.fn();
|
||||
dispose = vi.fn();
|
||||
updateWorld = vi.fn();
|
||||
updateAssets = vi.fn();
|
||||
updateDocument = vi.fn();
|
||||
setViewMode = vi.fn();
|
||||
setDisplayMode = vi.fn();
|
||||
setCameraState = vi.fn();
|
||||
setBrushSelectionChangeHandler = vi.fn();
|
||||
setCameraStateChangeHandler = vi.fn();
|
||||
setCreationPreviewChangeHandler = vi.fn();
|
||||
setCreationCommitHandler = vi.fn();
|
||||
setTransformSessionChangeHandler = vi.fn();
|
||||
setTransformCommitHandler = vi.fn();
|
||||
setTransformCancelHandler = vi.fn();
|
||||
setWhiteboxHoverLabelChangeHandler = vi.fn();
|
||||
setWhiteboxSelectionMode = vi.fn();
|
||||
setWhiteboxSnapSettings = vi.fn();
|
||||
setToolMode = vi.fn();
|
||||
setCreationPreview = vi.fn();
|
||||
setTransformSession = vi.fn();
|
||||
setPanelId = vi.fn();
|
||||
focusSelection = vi.fn();
|
||||
constructor() {
|
||||
viewportHostInstances.push(this);
|
||||
}
|
||||
}
|
||||
return {
|
||||
MockViewportHost,
|
||||
viewportHostInstances
|
||||
};
|
||||
});
|
||||
vi.mock("../../src/viewport-three/viewport-host", () => ({
|
||||
ViewportHost: MockViewportHost
|
||||
}));
|
||||
describe("ViewportCanvas", () => {
|
||||
beforeEach(() => {
|
||||
viewportHostInstances.length = 0;
|
||||
vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockImplementation(() => ({}));
|
||||
});
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
it("wires the creation commit handler into the viewport host", async () => {
|
||||
const sceneDocument = createEmptySceneDocument();
|
||||
const cameraState = createDefaultViewportPanelCameraState();
|
||||
const toolPreview = {
|
||||
kind: "create",
|
||||
sourcePanelId: "topLeft",
|
||||
target: {
|
||||
kind: "box-brush"
|
||||
},
|
||||
center: null
|
||||
};
|
||||
const onCommitCreation = vi.fn(() => true);
|
||||
const onCameraStateChange = vi.fn((_cameraState) => undefined);
|
||||
const onToolPreviewChange = vi.fn((_toolPreview) => undefined);
|
||||
const onTransformSessionChange = vi.fn((_transformSession) => undefined);
|
||||
const onTransformCommit = vi.fn((_transformSession) => undefined);
|
||||
const onTransformCancel = vi.fn(() => undefined);
|
||||
const onSelectionChange = vi.fn();
|
||||
render(_jsx(ViewportCanvas, { panelId: "topLeft", world: sceneDocument.world, sceneDocument: sceneDocument, projectAssets: sceneDocument.assets, loadedModelAssets: {}, loadedImageAssets: {}, whiteboxSelectionMode: "object", whiteboxSnapEnabled: true, whiteboxSnapStep: 1, selection: { kind: "none" }, toolMode: "create", toolPreview: toolPreview, transformSession: createInactiveTransformSession(), cameraState: cameraState, viewMode: "perspective", displayMode: "authoring", layoutMode: "single", isActivePanel: true, focusRequestId: 0, focusSelection: { kind: "none" }, onSelectionChange: onSelectionChange, onCommitCreation: onCommitCreation, onCameraStateChange: onCameraStateChange, onToolPreviewChange: onToolPreviewChange, onTransformSessionChange: onTransformSessionChange, onTransformCommit: onTransformCommit, onTransformCancel: onTransformCancel }));
|
||||
await waitFor(() => {
|
||||
expect(viewportHostInstances).toHaveLength(1);
|
||||
expect(viewportHostInstances[0].setCreationCommitHandler).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
const registeredHandler = viewportHostInstances[0].setCreationCommitHandler.mock.calls[0][0];
|
||||
expect(registeredHandler(toolPreview)).toBe(true);
|
||||
expect(onCommitCreation).toHaveBeenCalledWith(toolPreview);
|
||||
});
|
||||
it("applies and subscribes to persisted camera state through the viewport host", async () => {
|
||||
const sceneDocument = createEmptySceneDocument();
|
||||
const cameraState = createDefaultViewportPanelCameraState();
|
||||
const onCameraStateChange = vi.fn((_cameraState) => undefined);
|
||||
render(_jsx(ViewportCanvas, { panelId: "topLeft", world: sceneDocument.world, sceneDocument: sceneDocument, projectAssets: sceneDocument.assets, loadedModelAssets: {}, loadedImageAssets: {}, whiteboxSelectionMode: "object", whiteboxSnapEnabled: true, whiteboxSnapStep: 1, selection: { kind: "none" }, toolMode: "select", toolPreview: { kind: "none" }, transformSession: createInactiveTransformSession(), cameraState: cameraState, viewMode: "perspective", displayMode: "normal", layoutMode: "single", isActivePanel: true, focusRequestId: 0, focusSelection: { kind: "none" }, onSelectionChange: vi.fn(), onCommitCreation: vi.fn(() => true), onCameraStateChange: onCameraStateChange, onToolPreviewChange: vi.fn(), onTransformSessionChange: vi.fn(), onTransformCommit: vi.fn(), onTransformCancel: vi.fn() }));
|
||||
await waitFor(() => {
|
||||
expect(viewportHostInstances).toHaveLength(1);
|
||||
expect(viewportHostInstances[0].setCameraState).toHaveBeenCalledWith(cameraState);
|
||||
expect(viewportHostInstances[0].setCameraStateChangeHandler).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,23 +0,0 @@
|
||||
import { BoxGeometry, CylinderGeometry, SphereGeometry, TorusGeometry } from "three";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createSoundEmitterMarkerMeshes } from "../../src/viewport-three/viewport-entity-markers";
|
||||
describe("createSoundEmitterMarkerMeshes", () => {
|
||||
it("builds a speaker-like marker instead of a sphere", () => {
|
||||
const meshes = createSoundEmitterMarkerMeshes(0x72d7c9, false);
|
||||
expect(meshes).toHaveLength(5);
|
||||
expect(meshes[0].geometry).toBeInstanceOf(BoxGeometry);
|
||||
expect(meshes[1].geometry).toBeInstanceOf(TorusGeometry);
|
||||
expect(meshes[2].geometry).toBeInstanceOf(CylinderGeometry);
|
||||
expect(meshes[3].geometry).toBeInstanceOf(TorusGeometry);
|
||||
expect(meshes[4].geometry).toBeInstanceOf(CylinderGeometry);
|
||||
expect(meshes.some((mesh) => mesh.geometry instanceof SphereGeometry)).toBe(false);
|
||||
expect(meshes[0].position).toMatchObject({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
});
|
||||
expect(meshes[1].position.y).toBeGreaterThan(meshes[3].position.y);
|
||||
expect(meshes[1].position.z).toBeGreaterThan(0);
|
||||
expect(meshes[3].position.z).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
@@ -1,232 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { createPointLightEntity, createPlayerStartEntity, createSpotLightEntity, createTriggerVolumeEntity } from "../../src/entities/entity-instances";
|
||||
import { resolveViewportFocusTarget } from "../../src/viewport-three/viewport-focus";
|
||||
describe("resolveViewportFocusTarget", () => {
|
||||
it("frames the selected brush", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-room",
|
||||
center: {
|
||||
x: 3,
|
||||
y: 2,
|
||||
z: -1
|
||||
},
|
||||
size: {
|
||||
x: 6,
|
||||
y: 4,
|
||||
z: 2
|
||||
}
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
};
|
||||
expect(resolveViewportFocusTarget(document, {
|
||||
kind: "brushes",
|
||||
ids: [brush.id]
|
||||
})).toEqual({
|
||||
center: {
|
||||
x: 3,
|
||||
y: 2,
|
||||
z: -1
|
||||
},
|
||||
radius: Math.hypot(6, 4, 2) * 0.5
|
||||
});
|
||||
});
|
||||
it("frames rotated whitebox boxes around their authored center with a stable object radius", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-rotated-room",
|
||||
center: {
|
||||
x: 1.25,
|
||||
y: 1.5,
|
||||
z: -0.75
|
||||
},
|
||||
rotationDegrees: {
|
||||
x: 0,
|
||||
y: 45,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: 4
|
||||
}
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
};
|
||||
expect(resolveViewportFocusTarget(document, {
|
||||
kind: "brushes",
|
||||
ids: [brush.id]
|
||||
})).toEqual({
|
||||
center: {
|
||||
x: 1.25,
|
||||
y: 1.5,
|
||||
z: -0.75
|
||||
},
|
||||
radius: Math.hypot(2, 2, 4) * 0.5
|
||||
});
|
||||
});
|
||||
it("frames the owning brush when a face is selected", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-face-room"
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
};
|
||||
const focusTarget = resolveViewportFocusTarget(document, {
|
||||
kind: "brushFace",
|
||||
brushId: brush.id,
|
||||
faceId: "posZ"
|
||||
});
|
||||
expect(focusTarget?.center).toEqual(brush.center);
|
||||
expect(focusTarget?.radius).toBe(Math.hypot(2, 2, 2) * 0.5);
|
||||
});
|
||||
it("frames the selected Player Start helper", () => {
|
||||
const playerStart = createPlayerStartEntity({
|
||||
id: "entity-player-start-main",
|
||||
position: {
|
||||
x: 4,
|
||||
y: 0,
|
||||
z: -2
|
||||
},
|
||||
yawDegrees: 90
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
entities: {
|
||||
[playerStart.id]: playerStart
|
||||
}
|
||||
};
|
||||
const focusTarget = resolveViewportFocusTarget(document, {
|
||||
kind: "entities",
|
||||
ids: [playerStart.id]
|
||||
});
|
||||
expect(focusTarget?.center).toEqual({
|
||||
x: 4,
|
||||
y: 0.3,
|
||||
z: -2
|
||||
});
|
||||
expect(focusTarget?.radius).toBeGreaterThan(0.6);
|
||||
});
|
||||
it("frames the selected Point Light helper", () => {
|
||||
const pointLight = createPointLightEntity({
|
||||
id: "entity-point-light-main",
|
||||
position: {
|
||||
x: 2,
|
||||
y: 3,
|
||||
z: -1
|
||||
},
|
||||
distance: 8
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
entities: {
|
||||
[pointLight.id]: pointLight
|
||||
}
|
||||
};
|
||||
const focusTarget = resolveViewportFocusTarget(document, {
|
||||
kind: "entities",
|
||||
ids: [pointLight.id]
|
||||
});
|
||||
expect(focusTarget).toEqual({
|
||||
center: {
|
||||
x: 2,
|
||||
y: 3,
|
||||
z: -1
|
||||
},
|
||||
radius: 8
|
||||
});
|
||||
});
|
||||
it("frames the selected Spot Light helper", () => {
|
||||
const spotLight = createSpotLightEntity({
|
||||
id: "entity-spot-light-main",
|
||||
position: {
|
||||
x: -2,
|
||||
y: 4,
|
||||
z: 1
|
||||
},
|
||||
distance: 12
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
entities: {
|
||||
[spotLight.id]: spotLight
|
||||
}
|
||||
};
|
||||
const focusTarget = resolveViewportFocusTarget(document, {
|
||||
kind: "entities",
|
||||
ids: [spotLight.id]
|
||||
});
|
||||
expect(focusTarget).toEqual({
|
||||
center: {
|
||||
x: -2,
|
||||
y: 4,
|
||||
z: 1
|
||||
},
|
||||
radius: 12
|
||||
});
|
||||
});
|
||||
it("frames a selected Trigger Volume around its authored bounds", () => {
|
||||
const triggerVolume = createTriggerVolumeEntity({
|
||||
id: "entity-trigger-main",
|
||||
position: {
|
||||
x: 3,
|
||||
y: 2,
|
||||
z: -1
|
||||
},
|
||||
size: {
|
||||
x: 4,
|
||||
y: 6,
|
||||
z: 2
|
||||
}
|
||||
});
|
||||
const document = {
|
||||
...createEmptySceneDocument(),
|
||||
entities: {
|
||||
[triggerVolume.id]: triggerVolume
|
||||
}
|
||||
};
|
||||
const focusTarget = resolveViewportFocusTarget(document, {
|
||||
kind: "entities",
|
||||
ids: [triggerVolume.id]
|
||||
});
|
||||
expect(focusTarget).toEqual({
|
||||
center: {
|
||||
x: 3,
|
||||
y: 2,
|
||||
z: -1
|
||||
},
|
||||
radius: Math.hypot(2, 3, 1)
|
||||
});
|
||||
});
|
||||
it("frames the authored scene when nothing is selected and returns null when the scene is empty", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-room"
|
||||
});
|
||||
const populatedDocument = {
|
||||
...createEmptySceneDocument(),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
};
|
||||
expect(resolveViewportFocusTarget(populatedDocument, { kind: "none" })).toEqual({
|
||||
center: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
radius: Math.hypot(2, 2, 2) * 0.5
|
||||
});
|
||||
expect(resolveViewportFocusTarget(createEmptySceneDocument(), { kind: "none" })).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,36 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createDefaultViewportLayoutState, getViewportDisplayModeLabel, getViewportLayoutModeLabel, getViewportPanelLabel } from "../../src/viewport-three/viewport-layout";
|
||||
describe("viewport layout", () => {
|
||||
it("defaults to a quad-ready panel arrangement with orthographic authoring panes", () => {
|
||||
const layout = createDefaultViewportLayoutState();
|
||||
expect(layout.layoutMode).toBe("single");
|
||||
expect(layout.activePanelId).toBe("topLeft");
|
||||
expect(layout.panels.topLeft).toMatchObject({
|
||||
viewMode: "perspective",
|
||||
displayMode: "normal"
|
||||
});
|
||||
expect(layout.panels.topRight).toMatchObject({
|
||||
viewMode: "top",
|
||||
displayMode: "authoring"
|
||||
});
|
||||
expect(layout.panels.bottomLeft).toMatchObject({
|
||||
viewMode: "front",
|
||||
displayMode: "authoring"
|
||||
});
|
||||
expect(layout.panels.bottomRight).toMatchObject({
|
||||
viewMode: "side",
|
||||
displayMode: "authoring"
|
||||
});
|
||||
expect(layout.viewportQuadSplit).toEqual({
|
||||
x: 0.5,
|
||||
y: 0.5
|
||||
});
|
||||
});
|
||||
it("exposes readable labels for the layout and panel chrome", () => {
|
||||
expect(getViewportLayoutModeLabel("single")).toBe("Single View");
|
||||
expect(getViewportLayoutModeLabel("quad")).toBe("4-Panel");
|
||||
expect(getViewportDisplayModeLabel("authoring")).toBe("Authoring");
|
||||
expect(getViewportDisplayModeLabel("wireframe")).toBe("Wireframe");
|
||||
expect(getViewportPanelLabel("topRight")).toBe("Top Right");
|
||||
});
|
||||
});
|
||||
@@ -1,61 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getViewportViewModeControlHint, getViewportViewModeDefinition, getViewportViewModeGridPlaneLabel, getViewportViewModeLabel } from "../../src/viewport-three/viewport-view-modes";
|
||||
describe("viewport view modes", () => {
|
||||
it("defines the orthographic axes and grid planes explicitly", () => {
|
||||
expect(getViewportViewModeDefinition("top")).toMatchObject({
|
||||
label: "Top",
|
||||
cameraType: "orthographic",
|
||||
cameraDirection: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
cameraUp: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: -1
|
||||
},
|
||||
gridPlane: "xz",
|
||||
snapAxis: "y"
|
||||
});
|
||||
expect(getViewportViewModeDefinition("front")).toMatchObject({
|
||||
label: "Front",
|
||||
cameraType: "orthographic",
|
||||
cameraDirection: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 1
|
||||
},
|
||||
cameraUp: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
gridPlane: "xy",
|
||||
snapAxis: "z"
|
||||
});
|
||||
expect(getViewportViewModeDefinition("side")).toMatchObject({
|
||||
label: "Side",
|
||||
cameraType: "orthographic",
|
||||
cameraDirection: {
|
||||
x: -1,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
cameraUp: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
gridPlane: "yz",
|
||||
snapAxis: "x"
|
||||
});
|
||||
});
|
||||
it("exposes readable labels and grid hints for the UI", () => {
|
||||
expect(getViewportViewModeLabel("perspective")).toBe("Perspective");
|
||||
expect(getViewportViewModeLabel("top")).toBe("Top");
|
||||
expect(getViewportViewModeGridPlaneLabel("front")).toBe("XY");
|
||||
expect(getViewportViewModeControlHint("perspective")).toContain("orbits");
|
||||
expect(getViewportViewModeControlHint("side")).toContain("pans");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user