去掉console
This commit is contained in:
@ -35,6 +35,11 @@ export class AppDropZone {
|
||||
// 存储原始墙面配置(用于 updateDivisions 时恢复完整墙面列表)
|
||||
private originalWalls: WallConfig[] = [];
|
||||
|
||||
// 存储所有墙面的区域数据(持久化,不会被覆盖)
|
||||
private allWallZonesData: Map<string, PlacementZoneInfo[]> = new Map();
|
||||
// 当前激活显示的墙面名称集合(用于控制显示)
|
||||
private activeWallNames: Set<string> = new Set();
|
||||
|
||||
constructor(scene: Scene) {
|
||||
this.scene = scene;
|
||||
this.placementWall = new AppPlacementWall(scene);
|
||||
@ -93,24 +98,7 @@ export class AppDropZone {
|
||||
return this.placementWall.generatePlacementAreas(configWithDivisions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新墙面分割数并重新生成放置区域
|
||||
* @param divisions 分割数数组,每个元素包含 name(墙面名称或方向标识)和 divisions(分割数)
|
||||
* @example
|
||||
* // 方式1:精确匹配墙面名称(推荐)
|
||||
* updateDivisions([
|
||||
* { name: "前1", divisions: 1 },
|
||||
* { name: "前2", divisions: 2 },
|
||||
* { name: "左", divisions: 3 },
|
||||
* { name: "右", divisions: 4 }
|
||||
* ])
|
||||
*
|
||||
* // 方式2:模糊匹配方向(兼容旧版)
|
||||
* updateDivisions([
|
||||
* { name: "前", divisions: 4 },
|
||||
* { name: "后", divisions: 1 }
|
||||
* ])
|
||||
*/
|
||||
|
||||
updateDivisions(divisions: Array<{ name: string; divisions: number }>): PlacementZoneInfo[] {
|
||||
if (!this.dropZoneConfig) {
|
||||
console.error('未设置放置区域配置数据,请先调用 setData');
|
||||
@ -201,10 +189,6 @@ export class AppDropZone {
|
||||
}
|
||||
});
|
||||
keysToDelete.forEach(key => this.zoneModelMap.delete(key));
|
||||
|
||||
if (modelsToUnload.length > 0) {
|
||||
console.log(`已卸载墙面 ${wallName} 的 ${modelsToUnload.length} 个模型`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -218,7 +202,6 @@ export class AppDropZone {
|
||||
// 检查分割数是否改变
|
||||
if (modelDivisions !== undefined && currentDivisions !== undefined && modelDivisions !== currentDivisions) {
|
||||
// 分割数改变了,清空该墙面的所有旧模型
|
||||
console.log(`墙面 ${wallName} 分割数从 ${modelDivisions} 改为 ${currentDivisions},清空旧模型`);
|
||||
this.unloadWallModels(wallName);
|
||||
// 更新该墙面模型对应的分割数
|
||||
this.wallModelDivisionsMap.set(wallName, currentDivisions);
|
||||
@ -226,7 +209,6 @@ export class AppDropZone {
|
||||
// 分割数没变,检查该区域是否已有模型(替换逻辑)
|
||||
const existingModelId = this.zoneModelMap.get(zoneKey);
|
||||
if (existingModelId && this.appModel) {
|
||||
console.log(`区域 ${zoneKey} 已有模型 ${existingModelId},将替换为 ${modelId}`);
|
||||
this.appModel.removeByName(existingModelId);
|
||||
}
|
||||
}
|
||||
@ -238,7 +220,7 @@ export class AppDropZone {
|
||||
|
||||
// 记录新模型
|
||||
this.zoneModelMap.set(zoneKey, modelId);
|
||||
console.log(`已记录模型 ${modelId} 到区域 ${zoneKey}`);
|
||||
|
||||
|
||||
// 检查该墙面是否已满,如果满了则自动排列
|
||||
this.checkAndAutoArrange(wallName);
|
||||
@ -249,7 +231,7 @@ export class AppDropZone {
|
||||
* @param modelId 被删除的模型ID
|
||||
*/
|
||||
notifyModelRemoved(modelId: string): void {
|
||||
console.log(`[模型删除通知] 模型 ${modelId} 被删除`);
|
||||
|
||||
|
||||
// 找到该模型所在的墙面和索引
|
||||
let removedWallName: string | null = null;
|
||||
@ -298,11 +280,12 @@ export class AppDropZone {
|
||||
|
||||
// 如果墙面不满,重新启用所有模型的拖拽
|
||||
if (placedCount < currentDivisions) {
|
||||
console.log(`[拖拽检查] 墙面 ${wallName} 未满,重新启用拖拽`);
|
||||
|
||||
placedModelIds.forEach(modelId => {
|
||||
if (this.mainApp && this.mainApp.appModelDrag && typeof this.mainApp.appModelDrag.setDragEnabled === 'function') {
|
||||
this.mainApp.appModelDrag.setDragEnabled(modelId, true);
|
||||
console.log(`[拖拽检查] ✓ 已启用模型 ${modelId} 的拖拽功能`);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -354,8 +337,6 @@ export class AppDropZone {
|
||||
// 如果该墙面已满(放置数量等于分割数),执行自动排列
|
||||
if (placedCount === currentDivisions) {
|
||||
this.autoArrangeWall(wallName);
|
||||
} else {
|
||||
console.log(`[自动排列检查] 墙面 ${wallName} 未满,不执行自动排列`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -369,7 +350,7 @@ export class AppDropZone {
|
||||
const wallZones = this.getZonesByWall(wallName);
|
||||
|
||||
if (!wallZones.length) {
|
||||
console.log(`[自动排列] 墙面 ${wallName} 没有放置区域,退出`);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -383,7 +364,7 @@ export class AppDropZone {
|
||||
modelId: modelId,
|
||||
currentIndex: currentIndex
|
||||
});
|
||||
console.log(`[自动排列] 找到模型: ${modelId}, 当前索引: ${currentIndex}`);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@ -480,9 +461,9 @@ export class AppDropZone {
|
||||
* 显示所有放置区域
|
||||
*/
|
||||
show(): void {
|
||||
this.placementWall.show();
|
||||
// 禁用所有已放置模型的拾取
|
||||
this.setModelsPickable(false);
|
||||
// this.placementWall.show();
|
||||
// // 禁用所有已放置模型的拾取
|
||||
// this.setModelsPickable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -329,7 +329,7 @@ export class AppModelDrag extends Monobehiver {
|
||||
const appDropZone = this.mainApp.appDropZone;
|
||||
if (!appDropZone) return;
|
||||
|
||||
console.log(`[拖拽吸附] 隐藏分割区域`);
|
||||
|
||||
appDropZone.hide();
|
||||
}
|
||||
|
||||
@ -424,11 +424,10 @@ export class AppModelDrag extends Monobehiver {
|
||||
|
||||
// 处理超出边界的情况(开关2:returnWhenOutOfBounds)
|
||||
if (isOutOfBounds) {
|
||||
console.log(`[拖拽吸附] 模型 ${modelId} 超出边界`);
|
||||
|
||||
|
||||
if (returnWhenOutOfBounds) {
|
||||
// 启用了边界返回,回到原来的区域
|
||||
console.log(`[拖拽吸附] 启用边界返回,回到原区域 ${originalZoneIndex}`);
|
||||
if (originalZoneIndex !== -1) {
|
||||
const originalZone = wallZones[originalZoneIndex];
|
||||
if (originalZone) {
|
||||
@ -440,13 +439,12 @@ export class AppModelDrag extends Monobehiver {
|
||||
const angle = Math.atan2(targetDirection.x, targetDirection.z);
|
||||
rootMesh.rotation.y = angle;
|
||||
|
||||
console.log(`[拖拽吸附] 模型 ${modelId} 已返回原区域 ${originalZoneIndex}`);
|
||||
return; // 不更新映射,保持原映射
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 未启用边界返回,保持当前位置,不做吸附
|
||||
console.log(`[拖拽吸附] 未启用边界返回,保持当前位置,不做吸附`);
|
||||
|
||||
// 更新映射关系(可能移出了原区域)
|
||||
this.updateModelZoneMapping(modelId);
|
||||
return;
|
||||
@ -461,13 +459,13 @@ export class AppModelDrag extends Monobehiver {
|
||||
|
||||
if (occupyingModelId && occupyingModelId !== modelId) {
|
||||
// 目标区域已被其他模型占用
|
||||
console.log(`[拖拽吸附] 目标区域 ${closestZoneIndex} 已被模型 ${occupyingModelId} 占用`);
|
||||
|
||||
|
||||
if (handleOccupiedZone) {
|
||||
// 启用了占用区域处理
|
||||
if (occupiedZoneAction === 'return') {
|
||||
// 返回原位置
|
||||
console.log(`[拖拽吸附] 配置为返回原位置,回到区域 ${originalZoneIndex}`);
|
||||
|
||||
if (originalZoneIndex !== -1) {
|
||||
const originalZone = wallZones[originalZoneIndex];
|
||||
if (originalZone) {
|
||||
@ -479,7 +477,6 @@ export class AppModelDrag extends Monobehiver {
|
||||
const angle = Math.atan2(targetDirection.x, targetDirection.z);
|
||||
rootMesh.rotation.y = angle;
|
||||
|
||||
console.log(`[拖拽吸附] 模型 ${modelId} 返回原区域 ${originalZoneIndex}`);
|
||||
return; // 不更新映射,保持原映射
|
||||
}
|
||||
}
|
||||
@ -505,7 +502,6 @@ export class AppModelDrag extends Monobehiver {
|
||||
const angle = Math.atan2(targetDirection.x, targetDirection.z);
|
||||
rootMesh.rotation.y = angle;
|
||||
|
||||
console.log(`[拖拽吸附] 模型 ${modelId} 吸附到区域 ${closestZoneIndex}`);
|
||||
|
||||
// 更新映射关系
|
||||
this.updateModelZoneMapping(modelId);
|
||||
@ -522,7 +518,6 @@ export class AppModelDrag extends Monobehiver {
|
||||
const rootMesh = meshes[0];
|
||||
const modelPosition = rootMesh.position;
|
||||
|
||||
console.log(`[边界检测] 模型 ${modelId} 拖拽结束,当前位置:`, modelPosition);
|
||||
|
||||
// 获取 AppDropZone
|
||||
const appDropZone = this.mainApp.appDropZone;
|
||||
@ -540,17 +535,14 @@ export class AppModelDrag extends Monobehiver {
|
||||
});
|
||||
|
||||
if (!originalWallName) {
|
||||
console.log(`[边界检测] 模型 ${modelId} 未找到原始墙面,跳过检测`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`[边界检测] 模型 ${modelId} 原始墙面: ${originalWallName}`);
|
||||
|
||||
// 获取该墙面的所有分割区域
|
||||
const wallZones = appDropZone.getZonesByWall(originalWallName);
|
||||
if (!wallZones.length) return;
|
||||
|
||||
console.log(`[边界检测] 墙面 ${originalWallName} 有 ${wallZones.length} 个分割区域`);
|
||||
|
||||
// 计算模型与每个分割区域的距离,找到最近的区域
|
||||
let closestZoneIndex = -1;
|
||||
@ -559,7 +551,6 @@ export class AppModelDrag extends Monobehiver {
|
||||
wallZones.forEach((zone, index) => {
|
||||
// 计算模型位置到区域中心的距离
|
||||
const distance = modelPosition.subtract(zone.center).length();
|
||||
console.log(`[边界检测] 区域 ${index} 中心:`, zone.center, `距离: ${distance.toFixed(3)}`);
|
||||
|
||||
if (distance < minDistance) {
|
||||
minDistance = distance;
|
||||
@ -568,11 +559,9 @@ export class AppModelDrag extends Monobehiver {
|
||||
});
|
||||
|
||||
if (closestZoneIndex === -1) {
|
||||
console.log(`[边界检测] 未找到最近的区域`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`[边界检测] 模型 ${modelId} 最接近区域 ${closestZoneIndex},距离: ${minDistance.toFixed(3)}`);
|
||||
|
||||
// 查找模型当前所在的区域索引
|
||||
let currentZoneIndex = -1;
|
||||
@ -587,13 +576,11 @@ export class AppModelDrag extends Monobehiver {
|
||||
|
||||
// 如果模型移动到了新的区域,更新映射
|
||||
if (currentZoneIndex !== closestZoneIndex) {
|
||||
console.log(`[边界检测] 模型 ${modelId} 从区域 ${currentZoneIndex} 移动到区域 ${closestZoneIndex}`);
|
||||
|
||||
// 删除旧映射
|
||||
if (currentZoneIndex !== -1) {
|
||||
const oldKey = `${originalWallName}[${currentZoneIndex}]`;
|
||||
appDropZone['zoneModelMap']?.delete(oldKey);
|
||||
console.log(`[边界检测] 删除旧映射: ${oldKey}`);
|
||||
}
|
||||
|
||||
// 检查目标区域是否已有模型
|
||||
@ -606,17 +593,14 @@ export class AppModelDrag extends Monobehiver {
|
||||
const occupiedZoneAction = dragInfo?.config.occupiedZoneAction ?? 'return';
|
||||
|
||||
if (existingModelId && existingModelId !== modelId) {
|
||||
console.log(`[边界检测] 目标区域 ${closestZoneIndex} 已有模型 ${existingModelId}`);
|
||||
|
||||
// 只有在启用占用区域处理且为 'replace' 模式下才交换位置
|
||||
if (handleOccupiedZone && occupiedZoneAction === 'replace') {
|
||||
console.log(`[边界检测] 配置为替换模式,交换位置`);
|
||||
|
||||
// 将原有模型移动到旧位置
|
||||
if (currentZoneIndex !== -1) {
|
||||
const swapKey = `${originalWallName}[${currentZoneIndex}]`;
|
||||
appDropZone['zoneModelMap']?.set(swapKey, existingModelId);
|
||||
console.log(`[边界检测] 模型 ${existingModelId} 移动到区域 ${currentZoneIndex}`);
|
||||
|
||||
// 实际移动被替换模型的物理位置
|
||||
const existingMeshes = this.mainApp.appModel?.modelDic?.Get(existingModelId);
|
||||
@ -633,20 +617,14 @@ export class AppModelDrag extends Monobehiver {
|
||||
const angle = Math.atan2(targetDirection.x, targetDirection.z);
|
||||
existingRootMesh.rotation.y = angle;
|
||||
|
||||
console.log(`[边界检测] 已将模型 ${existingModelId} 物理移动到区域 ${currentZoneIndex}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log(`[边界检测] 未启用替换模式或未启用占用区域处理,允许重叠`);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加新映射
|
||||
appDropZone['zoneModelMap']?.set(newKey, modelId);
|
||||
console.log(`[边界检测] 添加新映射: ${newKey} -> ${modelId}`);
|
||||
} else {
|
||||
console.log(`[边界检测] 模型 ${modelId} 仍在区域 ${currentZoneIndex},无需更新映射`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -331,23 +331,26 @@ export class AppPlacementWall {
|
||||
/**
|
||||
* 显示所有放置区域
|
||||
*/
|
||||
show(): void {
|
||||
this.placementZones.forEach(zone => {
|
||||
zone.mesh.isVisible = true;
|
||||
});
|
||||
this.borderLines.forEach(line => {
|
||||
line.isVisible = true;
|
||||
});
|
||||
}
|
||||
// show(): void {
|
||||
// this.placementZones.forEach(zone => {
|
||||
// zone.mesh.isVisible = true;
|
||||
// });
|
||||
// this.borderLines.forEach(line => {
|
||||
// line.isVisible = true;
|
||||
// });
|
||||
// }
|
||||
|
||||
/**
|
||||
* 只显示指定墙面的放置区域
|
||||
* @param wallName 墙面名称
|
||||
*/
|
||||
showWall(wallName: string): void {
|
||||
|
||||
// 先隐藏所有
|
||||
this.hide();
|
||||
|
||||
|
||||
console.log(this.placementZones, wallName);
|
||||
// 只显示指定墙面的区域
|
||||
this.placementZones.forEach(zone => {
|
||||
if (zone.wallName === wallName) {
|
||||
|
||||
Reference in New Issue
Block a user