auto-git:
[add] playwright.config.js [add] src/app/App.js [add] src/app/editor-store.js [add] src/app/use-editor-store.js [add] src/assets/audio-assets.js [add] src/assets/gltf-model-import.js [add] src/assets/image-assets.js [add] src/assets/model-instance-labels.js [add] src/assets/model-instance-rendering.js [add] src/assets/model-instances.js [add] src/assets/project-asset-storage.js [add] src/assets/project-assets.js [add] src/commands/brush-command-helpers.js [add] src/commands/command-history.js [add] src/commands/command.js [add] src/commands/commit-transform-session-command.js [add] src/commands/create-box-brush-command.js [add] src/commands/delete-box-brush-command.js [add] src/commands/delete-entity-command.js [add] src/commands/delete-interaction-link-command.js [add] src/commands/delete-model-instance-command.js [add] src/commands/import-audio-asset-command.js [add] src/commands/import-background-image-asset-command.js [add] src/commands/import-model-asset-command.js [add] src/commands/move-box-brush-command.js [add] src/commands/resize-box-brush-command.js [add] src/commands/rotate-box-brush-command.js [add] src/commands/set-box-brush-face-material-command.js [add] src/commands/set-box-brush-face-uv-state-command.js [add] src/commands/set-box-brush-name-command.js [add] src/commands/set-box-brush-transform-command.js [add] src/commands/set-entity-name-command.js [add] src/commands/set-model-instance-name-command.js [add] src/commands/set-player-start-command.js [add] src/commands/set-scene-name-command.js [add] src/commands/set-world-settings-command.js [add] src/commands/upsert-entity-command.js [add] src/commands/upsert-interaction-link-command.js [add] src/commands/upsert-model-instance-command.js [add] src/core/ids.js [add] src/core/selection.js [add] src/core/tool-mode.js [add] src/core/transform-session.js [add] src/core/vector.js [add] src/core/whitebox-selection-feedback.js [add] src/core/whitebox-selection-mode.js [add] src/document/brushes.js [add] src/document/migrate-scene-document.js [add] src/document/scene-document-validation.js [add] src/document/scene-document.js [add] src/document/world-settings.js [add] src/entities/entity-instances.js [add] src/entities/entity-labels.js [add] src/geometry/box-brush-components.js [add] src/geometry/box-brush-mesh.js [add] src/geometry/box-brush.js [add] src/geometry/box-face-uvs.js [add] src/geometry/grid-snapping.js [add] src/geometry/model-instance-collider-debug-mesh.js [add] src/geometry/model-instance-collider-generation.js [add] src/interactions/interaction-links.js [add] src/main.js [add] src/materials/starter-material-library.js [add] src/materials/starter-material-textures.js [add] src/rendering/advanced-rendering.js [add] src/runner-web/RunnerCanvas.js [add] src/runtime-three/first-person-navigation-controller.js [add] src/runtime-three/navigation-controller.js [add] src/runtime-three/orbit-visitor-navigation-controller.js [add] src/runtime-three/player-collision.js [add] src/runtime-three/rapier-collision-world.js [add] src/runtime-three/runtime-audio-system.js [add] src/runtime-three/runtime-host.js [add] src/runtime-three/runtime-interaction-system.js [add] src/runtime-three/runtime-scene-build.js [add] src/runtime-three/runtime-scene-validation.js [add] src/serialization/local-draft-storage.js [add] src/serialization/scene-document-json.js [add] src/shared-ui/HierarchicalMenu.js [add] src/shared-ui/Panel.js [add] src/shared-ui/world-background-style.js [add] src/viewport-three/ViewportCanvas.js [add] src/viewport-three/ViewportPanel.js [add] src/viewport-three/viewport-entity-markers.js [add] src/viewport-three/viewport-focus.js [add] src/viewport-three/viewport-host.js [add] src/viewport-three/viewport-layout.js [add] src/viewport-three/viewport-transient-state.js [add] src/viewport-three/viewport-view-modes.js [add] tests/domain/box-brush-face-editing.command.test.js [add] tests/domain/build-runtime-scene.test.js [add] tests/domain/create-box-brush.command.test.js [add] tests/domain/create-empty-scene-document.test.js [add] tests/domain/editor-store.test.js [add] tests/domain/entity.command.test.js [add] tests/domain/interaction-links.validation.test.js [add] tests/domain/model-import.test.js [add] tests/domain/model-instance.command.test.js [add] tests/domain/player-start.command.test.js [add] tests/domain/rapier-collision-world.test.js [add] tests/domain/runtime-audio-system.test.js [add] tests/domain/runtime-interaction-system.test.js [add] tests/domain/runtime-scene-validation.test.js [add] tests/domain/scene-document-validation.test.js [add] tests/domain/transform-session.command.test.js [add] tests/domain/world-settings.command.test.js [add] tests/domain/world-settings.test.js [add] tests/e2e/app-smoke.e2e.js [add] tests/e2e/box-brush-authoring.e2e.js [add] tests/e2e/entities-foundation.e2e.js [add] tests/e2e/face-material-authoring.e2e.js [add] tests/e2e/first-room-workflow.e2e.js [add] tests/e2e/import-draco-model-asset.e2e.js [add] tests/e2e/import-external-model-asset.e2e.js [add] tests/e2e/import-model-asset.e2e.js [add] tests/e2e/local-lights-and-background.e2e.js [add] tests/e2e/orthographic-views.e2e.js [add] tests/e2e/runner-v1.e2e.js [add] tests/e2e/runtime-click-interaction.e2e.js [add] tests/e2e/runtime-trigger-teleport.e2e.js [add] tests/e2e/viewport-quad-layout.e2e.js [add] tests/e2e/viewport-test-helpers.js [add] tests/e2e/whitebox-component-selection.e2e.js [add] tests/e2e/world-environment.e2e.js [add] tests/geometry/box-brush-geometry.test.js [add] tests/geometry/box-face-uvs.test.js [add] tests/geometry/model-instance-collider-generation.test.js [add] tests/helpers/model-collider-fixtures.js [add] tests/serialization/local-draft-storage.test.js [add] tests/serialization/project-asset-storage.test.js [add] tests/serialization/scene-document-json.test.js [add] tests/setup/vitest.setup.js [add] tests/unit/audio-assets.test.js [add] tests/unit/entity-instances.test.js [add] tests/unit/package-scripts.test.js [add] tests/unit/transform-foundation.integration.test.js [add] tests/unit/viewport-canvas.test.js [add] tests/unit/viewport-entity-markers.test.js [add] tests/unit/viewport-focus.test.js [add] tests/unit/viewport-layout.test.js [add] tests/unit/viewport-view-modes.test.js [add] vite.config.js [add] vitest.config.js
This commit is contained in:
80
tests/domain/box-brush-face-editing.command.test.js
Normal file
80
tests/domain/box-brush-face-editing.command.test.js
Normal file
@@ -0,0 +1,80 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
675
tests/domain/build-runtime-scene.test.js
Normal file
675
tests/domain/build-runtime-scene.test.js
Normal file
@@ -0,0 +1,675 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
234
tests/domain/create-box-brush.command.test.js
Normal file
234
tests/domain/create-box-brush.command.test.js
Normal file
@@ -0,0 +1,234 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
65
tests/domain/create-empty-scene-document.test.js
Normal file
65
tests/domain/create-empty-scene-document.test.js
Normal file
@@ -0,0 +1,65 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
});
|
||||
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));
|
||||
});
|
||||
});
|
||||
360
tests/domain/editor-store.test.js
Normal file
360
tests/domain/editor-store.test.js
Normal file
@@ -0,0 +1,360 @@
|
||||
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"
|
||||
});
|
||||
});
|
||||
});
|
||||
153
tests/domain/entity.command.test.js
Normal file
153
tests/domain/entity.command.test.js
Normal file
@@ -0,0 +1,153 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
242
tests/domain/interaction-links.validation.test.js
Normal file
242
tests/domain/interaction-links.validation.test.js
Normal file
@@ -0,0 +1,242 @@
|
||||
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"
|
||||
})
|
||||
]));
|
||||
});
|
||||
});
|
||||
54
tests/domain/model-import.test.js
Normal file
54
tests/domain/model-import.test.js
Normal file
@@ -0,0 +1,54 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
147
tests/domain/model-instance.command.test.js
Normal file
147
tests/domain/model-instance.command.test.js
Normal file
@@ -0,0 +1,147 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
70
tests/domain/player-start.command.test.js
Normal file
70
tests/domain/player-start.command.test.js
Normal file
@@ -0,0 +1,70 @@
|
||||
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
|
||||
});
|
||||
});
|
||||
});
|
||||
352
tests/domain/rapier-collision-world.test.js
Normal file
352
tests/domain/rapier-collision-world.test.js
Normal file
@@ -0,0 +1,352 @@
|
||||
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();
|
||||
}
|
||||
});
|
||||
});
|
||||
12
tests/domain/runtime-audio-system.test.js
Normal file
12
tests/domain/runtime-audio-system.test.js
Normal file
@@ -0,0 +1,12 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
373
tests/domain/runtime-interaction-system.test.js
Normal file
373
tests/domain/runtime-interaction-system.test.js
Normal file
@@ -0,0 +1,373 @@
|
||||
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: [],
|
||||
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"]);
|
||||
});
|
||||
});
|
||||
85
tests/domain/runtime-scene-validation.test.js
Normal file
85
tests/domain/runtime-scene-validation.test.js
Normal file
@@ -0,0 +1,85 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
472
tests/domain/scene-document-validation.test.js
Normal file
472
tests/domain/scene-document-validation.test.js
Normal file
@@ -0,0 +1,472 @@
|
||||
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"
|
||||
})
|
||||
]));
|
||||
});
|
||||
});
|
||||
581
tests/domain/transform-session.command.test.js
Normal file
581
tests/domain/transform-session.command.test.js
Normal file
@@ -0,0 +1,581 @@
|
||||
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
|
||||
});
|
||||
});
|
||||
});
|
||||
30
tests/domain/world-settings.command.test.js
Normal file
30
tests/domain/world-settings.command.test.js
Normal file
@@ -0,0 +1,30 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
58
tests/domain/world-settings.test.js
Normal file
58
tests/domain/world-settings.test.js
Normal file
@@ -0,0 +1,58 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user