feat: replace Terre drag transform workarounds with preview queries#624
feat: replace Terre drag transform workarounds with preview queries#624A-kirami wants to merge 11 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a protocol-based editor preview sync mechanism, updating the preview protocol with new queries and commands, and refactoring the EffectEditor and TransformableBox to resolve and apply drag transforms using reference boxes and baselines. The feedback highlights critical issues, including a missing dependency array in a useEffect hook in TransformableBox that prevents updates when switching sentences, direct state mutation in EffectEditor instead of using .set(), and potential runtime crashes in getValueByPath and pickDragTransformFields due to a lack of defensive checks against null values.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
背景
当前 Terre 的拖拽变换链路主要依赖编辑器侧本地推断 reference geometry、base transform 和 target baseline。
这套实现虽然可用,但本质上是在前端复刻 runtime 布局与继承规则,容易在引擎布局、素材尺寸、Live2D、默认 transform 或 target 状态变化后产生漂移。
本次改动的目标是让 Terre 优先消费 runtime 已定义的 preview query 契约:
preview.query.reference-boxpreview.query.base-transformpreview.query.transform-baseline在支持 query 的 V1 runtime 上,拖拽框初始化、baseline 解析和写回语义都基于 query 结果;在旧 runtime 或 query 不可用时,继续保持当前 legacy 行为,不破坏现有效果编辑体验。
另外,这个 PR 也顺带补齐了一处与新 preview runtime 语义对齐的编辑器侧小改动:
Terre 的实时
setEffect预览会显式标记phase: 'preview',避免新 runtime 将高频预览交互误当成 durable commit 处理。主要改动
在
EditorPreviewHost补齐 query 路由能力:requestId -> editor socket的 pending 映射response/error按 requestId 回传给原 editor在
EditorPreviewClient补齐 request owner 生命周期:base-transform查询结果,并在 runtime 重连后失效为拖拽链路抽出最小 transform resolver:
position / scale / rotation让
TransformableBox在 query 路径下改用reference-box初始化几何:2560x1440referenceBox.stageWidth / stageHeight收紧拖拽写回语义:
顺带补齐效果编辑器实时预览的 phase 标记:
editor-preview-protocol中为SetEffectPayload增加可选phasesetEffect预览调用点统一发送phase: 'preview'submitScene() -> sync-scene收敛 runtime兼容与降级
unsupported时,继续走当前 legacy 拖拽与效果编辑路径reference-box不可用、超时或返回非 ready 状态时,回退到当前旧行为base-transform或transform-baseline失败不会阻断拖拽,但未触达字段不会被补写setEffect.phase时,效果编辑器功能仍保持兼容,只是没有对应的预览性能收益验证重点
reference-box.ready时,拖拽框与 runtime reference geometry 对齐setTransform -target=...能显示 target 当前 inherited transform,而不是固定0 / 1 / 0position,只缩放时只写scale,只旋转时只写rotationsetEffectpayload 会带phase: 'preview'submitScene() -> sync-scene路径收敛,不额外引入新的 commit path非目标
EffectEditor整体表单模型react-moveable相关
需要先合并 OpenWebGAL/WebGAL#991
解决了 #612 以及一些拖拽变换的已知问题和潜在问题