feat(scene-editor): 增加逐楼层反向坐标转换标记,优化楼层导入与加载逻辑
This commit is contained in:
parent
e69b0419de
commit
d2eb594099
@ -70,29 +70,43 @@ const readScene = async () => {
|
||||
if (sceneJson.length > 0) {
|
||||
// 多楼层
|
||||
floorScenes.value = sceneJson;
|
||||
floorImportFlags.value = new Array(sceneJson.length).fill(false);
|
||||
currentFloorIndex.value = 0;
|
||||
previousFloorIndex.value = 0;
|
||||
editor.value?.load(floorScenes.value[0], editable.value, undefined, requireImportTransform.value);
|
||||
editor.value?.load(
|
||||
floorScenes.value[0],
|
||||
editable.value,
|
||||
undefined,
|
||||
floorImportFlags.value[0] ?? false,
|
||||
);
|
||||
} else {
|
||||
// 空数组
|
||||
message.warn('场景文件为空数组');
|
||||
floorScenes.value = [{}]; // 创建一个默认的空楼层
|
||||
floorImportFlags.value = [false];
|
||||
currentFloorIndex.value = 0;
|
||||
previousFloorIndex.value = 0;
|
||||
editor.value?.load('{}', editable.value, undefined, requireImportTransform.value);
|
||||
editor.value?.load('{}', editable.value, undefined, false);
|
||||
}
|
||||
} else if (sceneJson && typeof sceneJson === 'object' && Object.keys(sceneJson).length > 0) {
|
||||
// 单楼层,统一为多楼层数组格式
|
||||
floorScenes.value = [sceneJson];
|
||||
floorImportFlags.value = [false];
|
||||
currentFloorIndex.value = 0;
|
||||
previousFloorIndex.value = 0;
|
||||
editor.value?.load(floorScenes.value[0], editable.value, undefined, requireImportTransform.value);
|
||||
editor.value?.load(
|
||||
floorScenes.value[0],
|
||||
editable.value,
|
||||
undefined,
|
||||
floorImportFlags.value[0] ?? false,
|
||||
);
|
||||
} else {
|
||||
message.warn('场景文件为空或格式不正确');
|
||||
floorScenes.value = [{}]; // 创建一个默认的空楼层
|
||||
floorImportFlags.value = [false];
|
||||
currentFloorIndex.value = 0;
|
||||
previousFloorIndex.value = 0;
|
||||
editor.value?.load('{}', editable.value, undefined, requireImportTransform.value);
|
||||
editor.value?.load('{}', editable.value, undefined, false);
|
||||
}
|
||||
};
|
||||
|
||||
@ -131,9 +145,11 @@ const saveScene = async (payload?: SaveScenePayload) => {
|
||||
try {
|
||||
const parsed = typeof currentJson === 'string' ? JSON.parse(currentJson) : currentJson;
|
||||
floorScenes.value[currentFloorIndex.value] = parsed;
|
||||
floorImportFlags.value[currentFloorIndex.value] = true;
|
||||
} catch (error) {
|
||||
console.error('解析楼层数据失败:', error);
|
||||
floorScenes.value[currentFloorIndex.value] = currentJson as any;
|
||||
floorImportFlags.value[currentFloorIndex.value] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,6 +216,8 @@ const previousFloorIndex = ref(0);
|
||||
// 新增:判断是否为多楼层模式
|
||||
const isMultiFloor = computed(() => floorScenes.value.length > 1);
|
||||
const requireImportTransform = ref(false);
|
||||
// 新增:逐楼层是否需要反向坐标转换的标记(与 floorScenes 对齐)
|
||||
const floorImportFlags = ref<boolean[]>([]);
|
||||
|
||||
onMounted(() => {
|
||||
document.title = '场景编辑器';
|
||||
@ -495,34 +513,43 @@ const processAndLoadSceneData = async (sceneData: any) => {
|
||||
// 多楼层逻辑
|
||||
if (sceneData.length > 0) {
|
||||
floorScenes.value = sceneData;
|
||||
floorImportFlags.value = new Array(sceneData.length).fill(true);
|
||||
currentFloorIndex.value = 0;
|
||||
previousFloorIndex.value = 0;
|
||||
// 加载第一个楼层到编辑器
|
||||
await editor.value?.load(floorScenes.value[0], editable.value, undefined, requireImportTransform.value);
|
||||
await editor.value?.load(
|
||||
floorScenes.value[0],
|
||||
editable.value,
|
||||
undefined,
|
||||
floorImportFlags.value[0] ?? true,
|
||||
);
|
||||
message.success(`成功导入 ${sceneData.length} 个楼层,当前显示第一层。`);
|
||||
} else {
|
||||
message.warn('导入的场景文件是一个空数组,已加载空场景。');
|
||||
floorScenes.value = [{}];
|
||||
floorImportFlags.value = [false];
|
||||
currentFloorIndex.value = 0;
|
||||
previousFloorIndex.value = 0;
|
||||
await editor.value?.load('{}', editable.value, undefined, requireImportTransform.value);
|
||||
await editor.value?.load('{}', editable.value, undefined, false);
|
||||
}
|
||||
} else if (sceneData && typeof sceneData === 'object' && Object.keys(sceneData).length > 0) {
|
||||
// 单楼层逻辑,统一为多楼层数组格式
|
||||
requireImportTransform.value = true;
|
||||
floorScenes.value = [sceneData];
|
||||
floorImportFlags.value = [true];
|
||||
currentFloorIndex.value = 0;
|
||||
previousFloorIndex.value = 0;
|
||||
// 直接加载(editor.load可以接受对象或字符串)
|
||||
await editor.value?.load(sceneData, editable.value, undefined, requireImportTransform.value);
|
||||
await editor.value?.load(sceneData, editable.value, undefined, floorImportFlags.value[0] ?? true);
|
||||
message.success('成功导入单楼层场景。');
|
||||
} else {
|
||||
message.error('导入失败,场景文件为空或格式不正确。');
|
||||
// 可选:加载一个空场景作为回退
|
||||
floorScenes.value = [{}];
|
||||
floorImportFlags.value = [false];
|
||||
currentFloorIndex.value = 0;
|
||||
previousFloorIndex.value = 0;
|
||||
await editor.value?.load('{}', editable.value, undefined, requireImportTransform.value);
|
||||
await editor.value?.load('{}', editable.value, undefined, false);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('场景文件解析或加载失败:', error);
|
||||
@ -668,12 +695,18 @@ const handleFloorChange = async (value: any) => {
|
||||
const currentJson = editor.value.save();
|
||||
if (currentJson) {
|
||||
floorScenes.value[prevFloorIndex] = JSON.parse(currentJson);
|
||||
floorImportFlags.value[prevFloorIndex] = true;
|
||||
}
|
||||
|
||||
// 加载新楼层
|
||||
currentFloorIndex.value = newFloorIndex;
|
||||
previousFloorIndex.value = newFloorIndex;
|
||||
await editor.value.load(floorScenes.value[newFloorIndex], editable.value, undefined, requireImportTransform.value);
|
||||
await editor.value.load(
|
||||
floorScenes.value[newFloorIndex],
|
||||
editable.value,
|
||||
undefined,
|
||||
floorImportFlags.value[newFloorIndex] ?? false,
|
||||
);
|
||||
} else {
|
||||
currentFloorIndex.value = newFloorIndex;
|
||||
previousFloorIndex.value = newFloorIndex;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user