fix(asset-center): hide gizmo until node selection

This commit is contained in:
WuYongJie 2026-04-25 18:51:38 +08:00
parent 4d80f3a7d6
commit 093d8a215c
5 changed files with 33 additions and 21 deletions

View File

@ -309,6 +309,29 @@ const seriesTemplates = [
] as SeriesTemplateDTO[]
describe('AssetCenterClient 预览操作区', () => {
it('加载模型节点后不会默认选中第一个节点', async () => {
const actor = userEvent.setup()
render(
<AssetCenterClient
initialFamilies={[createFamily()]}
initialVariants={[createVariant()]}
initialSubstrates={[] as SubstrateDTO[]}
initialSeriesTemplates={seriesTemplates}
finishes={[] as MaterialDTO[]}
materialCategories={[]}
metrics={[]}
user={user}
/>,
)
await actor.click(screen.getByText('桌面板族'))
await actor.click(screen.getByText('桌面板A'))
expect(screen.getByText('selected:none')).toBeInTheDocument()
expect(screen.queryByText('selected:panel-a')).not.toBeInTheDocument()
})
it('会把一次 gizmo 拖拽封成一条撤销记录,Ctrl+Z 后直接回到拖拽前', async () => {
const actor = userEvent.setup()

View File

@ -2350,7 +2350,7 @@ export default function AssetCenterClient({
return Object.fromEntries(nextEntries)
})
setSelectedPreviewNodeName((current) =>
current && nodeNames.includes(current) ? current : nodeNames[0] ?? null,
current && nodeNames.includes(current) ? current : null,
)
}}
onNodeSelect={(payload) => {

View File

@ -469,7 +469,6 @@ function ModelViewerComponent({
const engineRef = useRef<ThreeDEngine | null>(null);
const transformControlsRef = useRef<TransformControls | null>(null);
const transformHelperRef = useRef<THREE.Object3D | null>(null);
const fallbackTransformNodeNameRef = useRef<string | null>(null);
const pointerStartRef = useRef<
{ x: number; y: number; button: number } | null
>(null);
@ -1272,8 +1271,7 @@ function ModelViewerComponent({
applyRotationSnap();
// hover 时重绘样式(Three.js 会覆盖 material color)
const resolveActiveNodeName = () =>
selectedNodeNameRef.current ?? fallbackTransformNodeNameRef.current;
const resolveActiveNodeName = () => selectedNodeNameRef.current;
const beginInteraction = () => {
const activeNodeName = resolveActiveNodeName();
const engine = engineRef.current;
@ -1413,32 +1411,23 @@ function ModelViewerComponent({
syncRotationSnapRef.current?.();
applyGizmoStyleRef.current?.();
if (!enableTranslateGizmoRef.current) {
fallbackTransformNodeNameRef.current = null;
if (!enableTranslateGizmoRef.current || !selectedNodeNameRef.current) {
currentTransformControls.detach();
currentHelper.visible = false;
transformInteractionActiveRef.current = false;
return;
}
let activeNodeName = selectedNodeNameRef.current;
let targetObject = currentEngine.resolveObjectByNodeName(activeNodeName);
if (!targetObject) {
const fallbackTarget = currentEngine.resolveDefaultTransformTarget?.();
activeNodeName = fallbackTarget?.nodeName ?? null;
targetObject = fallbackTarget?.object ?? null;
}
const activeNodeName = selectedNodeNameRef.current;
const targetObject = currentEngine.resolveObjectByNodeName(activeNodeName);
if (!targetObject) {
fallbackTransformNodeNameRef.current = null;
currentTransformControls.detach();
currentHelper.visible = false;
transformInteractionActiveRef.current = false;
return;
}
fallbackTransformNodeNameRef.current =
activeNodeName === selectedNodeNameRef.current ? null : activeNodeName;
currentTransformControls.enabled = true;
currentTransformControls.showX = true;
currentTransformControls.showY = true;

View File

@ -285,7 +285,7 @@ describe("ModelViewer gizmo mode switching", () => {
);
});
it("没有显式节点名时,会回退到模型默认对象显示 gizmo", async () => {
it("没有显式节点名时,不显示 gizmo", async () => {
render(
<ModelViewer
modelUrl="/demo.glb"
@ -297,10 +297,10 @@ describe("ModelViewer gizmo mode switching", () => {
await flushViewer();
expect(resolveDefaultTransformTargetMock).toHaveBeenCalled();
expect(resolveDefaultTransformTargetMock).not.toHaveBeenCalled();
expect(transformControlsInstances).toHaveLength(1);
expect(transformControlsInstances[0]?.attach).toHaveBeenCalledWith(targetObject);
expect(transformControlsInstances[0]?.helper.visible).toBe(true);
expect(transformControlsInstances[0]?.attach).not.toHaveBeenCalled();
expect(transformControlsInstances[0]?.helper.visible).toBe(false);
});
it("移动时只显示有变化的轴,并显示 mm 数值", async () => {

View File

@ -69,7 +69,7 @@ export function ViewportStageShell({
<div className="absolute inset-0 z-0">{children}</div>
{/* Obsidian Atelier vertical viewport tools */}
<div className="absolute left-8 top-1/2 z-30 flex -translate-y-1/2 flex-col items-center gap-1 rounded-[8px] bg-white/92 p-1.5 shadow-[0_18px_48px_rgba(45,51,53,0.14)] ring-1 ring-black/[0.08] backdrop-blur-xl transition-all duration-300">
<div className="absolute left-8 top-1/2 z-30 flex -translate-y-1/2 flex-col items-center gap-1 rounded-[8px] bg-white/72 p-1.5 shadow-[0_18px_48px_rgba(45,51,53,0.14)] ring-1 ring-white/70 backdrop-blur-2xl transition-all duration-300 supports-[backdrop-filter]:bg-white/62">
{/* 交互模式 */}
{enableTranslateGizmo && (
<div className="flex flex-col items-center gap-1.5">