fix(scene-editor): 简化楼层加载逻辑,提升代码可读性,并增加加载完成后自动定位功能
This commit is contained in:
parent
0e9c0eb037
commit
dbb8ed4172
@ -73,12 +73,7 @@ const readScene = async () => {
|
||||
floorImportFlags.value = new Array(sceneJson.length).fill(false);
|
||||
currentFloorIndex.value = 0;
|
||||
previousFloorIndex.value = 0;
|
||||
editor.value?.load(
|
||||
floorScenes.value[0],
|
||||
editable.value,
|
||||
undefined,
|
||||
floorImportFlags.value[0] ?? false,
|
||||
);
|
||||
editor.value?.load(floorScenes.value[0], editable.value, undefined, floorImportFlags.value[0] ?? false);
|
||||
} else {
|
||||
// 空数组
|
||||
message.warn('场景文件为空数组');
|
||||
@ -94,12 +89,7 @@ const readScene = async () => {
|
||||
floorImportFlags.value = [false];
|
||||
currentFloorIndex.value = 0;
|
||||
previousFloorIndex.value = 0;
|
||||
editor.value?.load(
|
||||
floorScenes.value[0],
|
||||
editable.value,
|
||||
undefined,
|
||||
floorImportFlags.value[0] ?? false,
|
||||
);
|
||||
editor.value?.load(floorScenes.value[0], editable.value, undefined, floorImportFlags.value[0] ?? false);
|
||||
} else {
|
||||
message.warn('场景文件为空或格式不正确');
|
||||
floorScenes.value = [{}]; // 创建一个默认的空楼层
|
||||
@ -517,12 +507,7 @@ const processAndLoadSceneData = async (sceneData: any) => {
|
||||
currentFloorIndex.value = 0;
|
||||
previousFloorIndex.value = 0;
|
||||
// 加载第一个楼层到编辑器
|
||||
await editor.value?.load(
|
||||
floorScenes.value[0],
|
||||
editable.value,
|
||||
undefined,
|
||||
floorImportFlags.value[0] ?? true,
|
||||
);
|
||||
await editor.value?.load(floorScenes.value[0], editable.value, undefined, floorImportFlags.value[0] ?? true);
|
||||
message.success(`成功导入 ${sceneData.length} 个楼层,当前显示第一层。`);
|
||||
} else {
|
||||
message.warn('导入的场景文件是一个空数组,已加载空场景。');
|
||||
@ -551,6 +536,13 @@ const processAndLoadSceneData = async (sceneData: any) => {
|
||||
previousFloorIndex.value = 0;
|
||||
await editor.value?.load('{}', editable.value, undefined, false);
|
||||
}
|
||||
// 导入并加载完成后,立即定位到新楼层内容中心,提升体验
|
||||
try {
|
||||
const { centerX, centerY } = calculateCenterPoint(editor.value);
|
||||
await jumpToPosition(editor.value, centerX, centerY, false, 0.05);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('场景文件解析或加载失败:', error);
|
||||
message.error('导入失败:文件不是有效的JSON格式或数据无法加载。');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user