feat: 在播放控制器中添加视图中心定位逻辑,优化场景切换后的视图体验
This commit is contained in:
parent
4ce5921d5c
commit
b2fc2d8d73
@ -4,6 +4,7 @@ import { type Ref, ref, type ShallowRef, shallowRef } from 'vue';
|
||||
|
||||
import type { RobotRealtimeInfo } from '../apis/robot';
|
||||
import type { EditorService } from '../services/editor.service';
|
||||
import { useViewState } from '../services/useViewState';
|
||||
import ws from '../services/ws';
|
||||
|
||||
// Define the structure of WebSocket messages for playback
|
||||
@ -51,6 +52,15 @@ export function usePlaybackWebSocket(editorService: ShallowRef<EditorService | u
|
||||
const currentSceneId = ref<string | null>(null);
|
||||
const sceneJson = ref<string | null>(null);
|
||||
|
||||
const { calculateCenterPoint, jumpToPosition } = useViewState();
|
||||
|
||||
const locateCenter = () => {
|
||||
if (editorService.value) {
|
||||
const { centerX, centerY } = calculateCenterPoint(editorService.value);
|
||||
jumpToPosition(editorService.value, centerX, centerY, false, 0.05);
|
||||
}
|
||||
};
|
||||
|
||||
const latestRobotData = new Map<string, RobotRealtimeInfo>();
|
||||
let animationFrameId: number;
|
||||
|
||||
@ -82,6 +92,11 @@ export function usePlaybackWebSocket(editorService: ShallowRef<EditorService | u
|
||||
// For seamless scene switching, we only update the scene JSON.
|
||||
// Time and playback state should continue uninterrupted.
|
||||
sceneJson.value = msg.data;
|
||||
// After receiving a new scene, automatically center the view.
|
||||
// Use a timeout to allow the new scene to be rendered first.
|
||||
setTimeout(() => {
|
||||
locateCenter();
|
||||
}, 100);
|
||||
} else if (msg.type === 'AMR') {
|
||||
(msg.data as RobotRealtimeInfo[]).forEach(robot => {
|
||||
latestRobotData.set(robot.id, robot);
|
||||
|
Loading…
x
Reference in New Issue
Block a user