Files
ttstd-3d-director/src/editor/canvas/sceneTransform.test.ts
tongtongstudio 0794486857 feat: 旋转单位改为度并支持轨迹点拖拽
统一数据模型中的旋转为度数并在渲染时转弧度,新增 InspectorAngleField 角度控件,为场景与轨迹点提供滑块和重置按钮;选中轨迹点时角色预览到该点并支持拖拽 gizmo 调整位置;机位点击统一走 selectObject 以正确切换右侧属性卡片。
2026-09-17 11:18:58 +08:00

52 lines
1.9 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 { expect, it } from "vitest";
import type { SceneSettings } from "../schema/directorProject";
import { getSceneGroupTransform } from "./sceneTransform";
function createScene(patch: Partial<SceneSettings> = {}): SceneSettings {
return {
scale: 1,
position: [0, 0, 0],
rotation: [0, 0, 0],
backgroundColor: "#000000",
panoramaYaw: 0,
panoramaRadius: 60,
showLabels: true,
snapToGrid: false,
showGround: true,
groundOpacity: 0.4,
groundHeight: 0,
...patch,
};
}
it("maps the scene scale onto all three axes", () => {
expect(getSceneGroupTransform(createScene({ scale: 2.5 }))).toEqual({
position: [0, 0, 0],
rotation: [0, 0, 0],
scale: [2.5, 2.5, 2.5],
});
});
it("converts the scene rotation from degrees to radians for the Three.js group", () => {
const transform = getSceneGroupTransform(createScene({ position: [1, 3, -2], rotation: [0, 90, 180] }));
expect(transform.position).toEqual([1, 3, -2]);
expect(transform.rotation[0]).toBeCloseTo(0);
expect(transform.rotation[1]).toBeCloseTo(Math.PI / 2);
expect(transform.rotation[2]).toBeCloseTo(Math.PI);
expect(transform.scale).toEqual([1, 1, 1]);
});
it("keeps the ground plane and the viewport grid on the same world height", () => {
const scene = createScene({ scale: 1.5, position: [0, 2, 0], groundHeight: 1.2 });
const transform = getSceneGroupTransform(scene);
const gridElevation = 0.002;
// 地面:局部 y = groundHeight;网格:局部 y = groundHeight + 抬升
// 两者共用同一个场景组 → 世界高度只差 抬升 × 场景缩放,永远不会分叉成两层地面
const groundWorldY = transform.position[1] + scene.groundHeight * transform.scale[1];
const gridWorldY = transform.position[1] + (scene.groundHeight + gridElevation) * transform.scale[1];
expect(gridWorldY - groundWorldY).toBeCloseTo(gridElevation * scene.scale, 6);
});