Files
ttstd-3d-director/src/editor/canvas/DirectorCanvas.grid.test.ts
tongtongstudio b9fd289caf chore: 迁移到 pnpm 并更新打包与测试文档
- 用 pnpm 替换 npm,锁定 pnpm@10.33.0,删除 package-lock.json 相关说明
- package.json 将渲染层依赖移入 devDependencies,减小 app.asar 体积
- 新增 electron:smoke 冒烟脚本与 icon 生成脚本
- win 平台设置 AppUserModelID,修复任务栏图标归组
- 清理 tsBuildInfoFile 输出路径至 node_modules/.tmp
- 更新测试断言以匹配画幅遮罩、取景器缩放与模型库外部资产行为
- README 与打包指南补充 pnpm、镜像与常见问题说明
2026-09-16 20:03:57 +08:00

69 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
DEFAULT_DIRECTOR_VIEW_SNAPSHOT,
getViewportGizmoHitButtonStyle,
getViewportSnapshotFromGizmoDirection,
shouldRenderViewportGrid,
} from "./DirectorCanvas";
import { createDefaultDirectorProject } from "../store/directorStore";
import { getCameraViewSnapshotFromShot } from "../schema/cameraGeometry";
import { Vector3 } from "three";
function expectTupleToBeCloseTo(
received: [number, number, number],
expected: [number, number, number]
) {
received.forEach((value, index) => {
expect(value).toBeCloseTo(expected[index], 5);
});
}
it("keeps the viewport grid visible when there is no panorama background", () => {
expect(shouldRenderViewportGrid(false, false)).toBe(true);
});
it("keeps the viewport grid visible when a panorama background is active", () => {
expect(shouldRenderViewportGrid(true, false)).toBe(true);
});
it("keeps the viewport grid visible when snap to grid is enabled during a panorama background", () => {
expect(shouldRenderViewportGrid(true, true)).toBe(true);
});
it("starts the director and default camera view from a centered front composition", () => {
const defaultCamera = createDefaultDirectorProject().cameras[0];
expect(DEFAULT_DIRECTOR_VIEW_SNAPSHOT).toEqual({
fov: 50,
position: [0, 1.55, 5.4],
target: [0, 1.05, 0],
});
const defaultCameraView = getCameraViewSnapshotFromShot(defaultCamera);
expect(defaultCameraView.fov).toBe(DEFAULT_DIRECTOR_VIEW_SNAPSHOT.fov);
expectTupleToBeCloseTo(defaultCameraView.position, defaultCamera.transform.position);
expect(defaultCameraView.target).toEqual(DEFAULT_DIRECTOR_VIEW_SNAPSHOT.target);
expect(defaultCamera.transform.position[0]).toBe(0);
expect(defaultCamera.transform.position[1]).toBeGreaterThan(DEFAULT_DIRECTOR_VIEW_SNAPSHOT.target[1]);
});
it("keeps the current orbit distance when native gizmo axis clicks switch viewport direction", () => {
const snapshot = getViewportSnapshotFromGizmoDirection(
DEFAULT_DIRECTOR_VIEW_SNAPSHOT,
new Vector3(1, 0, 0)
);
expect(snapshot.fov).toBe(DEFAULT_DIRECTOR_VIEW_SNAPSHOT.fov);
expect(snapshot.target).toEqual(DEFAULT_DIRECTOR_VIEW_SNAPSHOT.target);
expectTupleToBeCloseTo(snapshot.position, [5.423099, 1.05, 0]);
});
it("positions the transparent native gizmo hit target over the visible X axis head", () => {
const style = getViewportGizmoHitButtonStyle(DEFAULT_DIRECTOR_VIEW_SNAPSHOT, [1, 0, 0]);
// 命中框以 .viewport-gizmo-overlay 的 80px 图层为基准(见 index.css 契约测试):
// 中心 40px,X 轴正向落在屏幕半径 25px 处,15px 命中框需回退半个身位。
expect(style.left).toBe("57.5px");
expect(style.top).toBe("32.5px");
expect(style.zIndex).toBe(100);
});