This commit is contained in:
2026-05-16 14:18:06 +08:00
parent b41c3e80bf
commit 25c193b35a
4 changed files with 75 additions and 66 deletions

View File

@ -54,10 +54,9 @@ export class AppDropZone {
/**
* 生成放置区域
* @param divisions 可选的统一分割数量,如果不传则使用每个墙面自己的 divisions
* @param config 配置参数(可选,如果不传则使用 setData 设置的数据)
*/
generateDropZones(divisions?: number, config?: DropZoneConfig): PlacementZoneInfo[] {
generateDropZones(config?: DropZoneConfig): PlacementZoneInfo[] {
const finalConfig = config || this.dropZoneConfig;
if (!finalConfig) {
@ -65,13 +64,12 @@ export class AppDropZone {
return [];
}
// 为墙面设置分割数
// 为墙面设置分割数(使用每个墙面自己的 divisions默认为 1
const configWithDivisions: DropZoneConfig = {
...finalConfig, // 保留所有配置属性color, alpha, thickness, showBorder, borderColor
walls: finalConfig.walls.map(wall => ({
...wall,
// 如果传入了统一的 divisions使用它否则使用墙面自己的 divisions都没有则默认为 1
divisions: divisions !== undefined ? divisions : (wall.divisions || 1)
divisions: wall.divisions || 1
}))
};
@ -83,6 +81,34 @@ export class AppDropZone {
return this.placementWall.generatePlacementAreas(configWithDivisions);
}
/**
* 更新墙面分割数并重新生成放置区域
* @param divisions 分割数对象key 为墙面名称value 为分割数,例如 { "前": 4, "后": 1, "左": 1, "右": 1 }
*/
updateDivisions(divisions: Record<string, number>): PlacementZoneInfo[] {
if (!this.dropZoneConfig) {
console.error('未设置放置区域配置数据,请先调用 setData');
return [];
}
// 更新配置中的墙面分割数
this.dropZoneConfig.walls = this.dropZoneConfig.walls.map(wall => ({
...wall,
divisions: divisions[wall.name] !== undefined ? divisions[wall.name] : wall.divisions || 1
}));
// 清除旧的放置区域网格(不清除模型)
this.clearZones();
// 重新生成放置区域
const zones = this.generateDropZones();
// 显示放置区域
this.show();
return zones;
}
/**
* 卸载指定墙面的所有模型(内部方法)
*/

View File

@ -316,15 +316,21 @@ export class KernelAdapter {
},
/**
* 生成放置区域(使用已存储的配置数据)
* @param divisions 可选的统一分割数量,如果不传则使用每个墙面自己的 divisions
* @example
* // 使用每个墙面自己的分割数
* kernel.dropZone.generateDropZones();
* // 或者统一设置所有墙面的分割数
* kernel.dropZone.generateDropZones(5);
*/
generateDropZones: (divisions?: number): any[] => {
return this.mainApp.appDropZone.generateDropZones(divisions);
generateDropZones: (): any[] => {
return this.mainApp.appDropZone.generateDropZones();
},
/**
* 更新墙面分割数并重新生成放置区域
* @param divisions 分割数对象key 为墙面名称value 为分割数
* @example
* kernel.dropZone.updateDivisions({ "前": 4, "后": 1, "左": 1, "右": 1 });
*/
updateDivisions: (divisions: Record<string, number>): any[] => {
return this.mainApp.appDropZone.updateDivisions(divisions);
},
/**
* 显示所有放置区域