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