修复完bug

This commit is contained in:
2026-06-06 02:37:31 +08:00
parent 66d705aa3e
commit d179e456fc
2 changed files with 48 additions and 5 deletions

View File

@ -35,6 +35,9 @@ export class AppDropZone {
// 存储原始墙面配置(用于 updateDivisions 时恢复完整墙面列表)
private originalWalls: WallConfig[] = [];
// 备份数据,用于点击空白处时回退
private backupConfig: DropZoneConfig | null = null;
constructor(scene: Scene) {
this.scene = scene;
this.placementWall = new AppPlacementWall(scene);
@ -100,6 +103,16 @@ export class AppDropZone {
return [];
}
// 每次 updateDivisions 都备份当前配置(深拷贝,保留 Vector3 对象)
this.backupConfig = {
...this.dropZoneConfig,
walls: this.dropZoneConfig.walls.map(wall => ({
...wall,
startPoint: wall.startPoint.clone(),
endPoint: wall.endPoint.clone()
}))
};
// 将数组转换为对象映射
const divisionsMap: Record<string, number> = {};
divisions.forEach(item => {
@ -227,6 +240,8 @@ export class AppDropZone {
// 记录新模型
this.zoneModelMap.set(zoneKey, modelId);
// 成功放置模型,确认当前配置(清除备份)
this.confirmConfig();
// 检查该墙面是否已满,如果满了则自动排列
this.checkAndAutoArrange(wallName);
@ -484,13 +499,41 @@ export class AppDropZone {
/**
* 隐藏所有放置区域
* @param shouldRollback 是否回退到备份配置点击空白处时为true
*/
hide(): void {
hide(shouldRollback: boolean = false): void {
// 如果需要回退且有备份数据,则恢复配置
if (shouldRollback && this.backupConfig) {
this.dropZoneConfig = this.backupConfig;
this.backupConfig = null;
// 同步 wallDivisionsMap
if (this.dropZoneConfig) {
this.dropZoneConfig.walls.forEach(wall => {
this.wallDivisionsMap.set(wall.name, wall.divisions);
});
}
// 重新生成放置区域,使 placementZones 与回退后的配置一致
this.placementWall.generatePlacementAreas({
...this.dropZoneConfig,
walls: this.dropZoneConfig.walls
});
}
this.placementWall.hide();
// 恢复所有已放置模型的拾取
this.setModelsPickable(true);
}
/**
* 确认当前配置(清除备份)
* 当成功放置配件后调用,表示接受当前的配置修改
*/
confirmConfig(): void {
this.backupConfig = null;
}
/**
* 设置所有已放置模型的可拾取状态
* @param pickable 是否可拾取