去掉console

This commit is contained in:
2026-06-05 20:59:35 +08:00
parent a0d79cbfe3
commit b1f619083b
3 changed files with 38 additions and 76 deletions

View File

@ -35,6 +35,11 @@ export class AppDropZone {
// 存储原始墙面配置(用于 updateDivisions 时恢复完整墙面列表) // 存储原始墙面配置(用于 updateDivisions 时恢复完整墙面列表)
private originalWalls: WallConfig[] = []; private originalWalls: WallConfig[] = [];
// 存储所有墙面的区域数据(持久化,不会被覆盖)
private allWallZonesData: Map<string, PlacementZoneInfo[]> = new Map();
// 当前激活显示的墙面名称集合(用于控制显示)
private activeWallNames: Set<string> = new Set();
constructor(scene: Scene) { constructor(scene: Scene) {
this.scene = scene; this.scene = scene;
this.placementWall = new AppPlacementWall(scene); this.placementWall = new AppPlacementWall(scene);
@ -93,24 +98,7 @@ export class AppDropZone {
return this.placementWall.generatePlacementAreas(configWithDivisions); 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[] { updateDivisions(divisions: Array<{ name: string; divisions: number }>): PlacementZoneInfo[] {
if (!this.dropZoneConfig) { if (!this.dropZoneConfig) {
console.error('未设置放置区域配置数据,请先调用 setData'); console.error('未设置放置区域配置数据,请先调用 setData');
@ -201,10 +189,6 @@ export class AppDropZone {
} }
}); });
keysToDelete.forEach(key => this.zoneModelMap.delete(key)); 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) { if (modelDivisions !== undefined && currentDivisions !== undefined && modelDivisions !== currentDivisions) {
// 分割数改变了,清空该墙面的所有旧模型 // 分割数改变了,清空该墙面的所有旧模型
console.log(`墙面 ${wallName} 分割数从 ${modelDivisions} 改为 ${currentDivisions},清空旧模型`);
this.unloadWallModels(wallName); this.unloadWallModels(wallName);
// 更新该墙面模型对应的分割数 // 更新该墙面模型对应的分割数
this.wallModelDivisionsMap.set(wallName, currentDivisions); this.wallModelDivisionsMap.set(wallName, currentDivisions);
@ -226,7 +209,6 @@ export class AppDropZone {
// 分割数没变,检查该区域是否已有模型(替换逻辑) // 分割数没变,检查该区域是否已有模型(替换逻辑)
const existingModelId = this.zoneModelMap.get(zoneKey); const existingModelId = this.zoneModelMap.get(zoneKey);
if (existingModelId && this.appModel) { if (existingModelId && this.appModel) {
console.log(`区域 ${zoneKey} 已有模型 ${existingModelId},将替换为 ${modelId}`);
this.appModel.removeByName(existingModelId); this.appModel.removeByName(existingModelId);
} }
} }
@ -238,7 +220,7 @@ export class AppDropZone {
// 记录新模型 // 记录新模型
this.zoneModelMap.set(zoneKey, modelId); this.zoneModelMap.set(zoneKey, modelId);
console.log(`已记录模型 ${modelId} 到区域 ${zoneKey}`);
// 检查该墙面是否已满,如果满了则自动排列 // 检查该墙面是否已满,如果满了则自动排列
this.checkAndAutoArrange(wallName); this.checkAndAutoArrange(wallName);
@ -249,7 +231,7 @@ export class AppDropZone {
* @param modelId 被删除的模型ID * @param modelId 被删除的模型ID
*/ */
notifyModelRemoved(modelId: string): void { notifyModelRemoved(modelId: string): void {
console.log(`[模型删除通知] 模型 ${modelId} 被删除`);
// 找到该模型所在的墙面和索引 // 找到该模型所在的墙面和索引
let removedWallName: string | null = null; let removedWallName: string | null = null;
@ -298,11 +280,12 @@ export class AppDropZone {
// 如果墙面不满,重新启用所有模型的拖拽 // 如果墙面不满,重新启用所有模型的拖拽
if (placedCount < currentDivisions) { if (placedCount < currentDivisions) {
console.log(`[拖拽检查] 墙面 ${wallName} 未满,重新启用拖拽`);
placedModelIds.forEach(modelId => { placedModelIds.forEach(modelId => {
if (this.mainApp && this.mainApp.appModelDrag && typeof this.mainApp.appModelDrag.setDragEnabled === 'function') { if (this.mainApp && this.mainApp.appModelDrag && typeof this.mainApp.appModelDrag.setDragEnabled === 'function') {
this.mainApp.appModelDrag.setDragEnabled(modelId, true); this.mainApp.appModelDrag.setDragEnabled(modelId, true);
console.log(`[拖拽检查] ✓ 已启用模型 ${modelId} 的拖拽功能`);
} }
}); });
} }
@ -354,8 +337,6 @@ export class AppDropZone {
// 如果该墙面已满(放置数量等于分割数),执行自动排列 // 如果该墙面已满(放置数量等于分割数),执行自动排列
if (placedCount === currentDivisions) { if (placedCount === currentDivisions) {
this.autoArrangeWall(wallName); this.autoArrangeWall(wallName);
} else {
console.log(`[自动排列检查] 墙面 ${wallName} 未满,不执行自动排列`);
} }
} }
@ -369,7 +350,7 @@ export class AppDropZone {
const wallZones = this.getZonesByWall(wallName); const wallZones = this.getZonesByWall(wallName);
if (!wallZones.length) { if (!wallZones.length) {
console.log(`[自动排列] 墙面 ${wallName} 没有放置区域,退出`);
return; return;
} }
@ -383,7 +364,7 @@ export class AppDropZone {
modelId: modelId, modelId: modelId,
currentIndex: currentIndex currentIndex: currentIndex
}); });
console.log(`[自动排列] 找到模型: ${modelId}, 当前索引: ${currentIndex}`);
} }
}); });
@ -480,9 +461,9 @@ export class AppDropZone {
* 显示所有放置区域 * 显示所有放置区域
*/ */
show(): void { show(): void {
this.placementWall.show(); // this.placementWall.show();
// 禁用所有已放置模型的拾取 // // 禁用所有已放置模型的拾取
this.setModelsPickable(false); // this.setModelsPickable(false);
} }
/** /**

View File

@ -329,7 +329,7 @@ export class AppModelDrag extends Monobehiver {
const appDropZone = this.mainApp.appDropZone; const appDropZone = this.mainApp.appDropZone;
if (!appDropZone) return; if (!appDropZone) return;
console.log(`[拖拽吸附] 隐藏分割区域`);
appDropZone.hide(); appDropZone.hide();
} }
@ -424,11 +424,10 @@ export class AppModelDrag extends Monobehiver {
// 处理超出边界的情况开关2returnWhenOutOfBounds // 处理超出边界的情况开关2returnWhenOutOfBounds
if (isOutOfBounds) { if (isOutOfBounds) {
console.log(`[拖拽吸附] 模型 ${modelId} 超出边界`);
if (returnWhenOutOfBounds) { if (returnWhenOutOfBounds) {
// 启用了边界返回,回到原来的区域 // 启用了边界返回,回到原来的区域
console.log(`[拖拽吸附] 启用边界返回,回到原区域 ${originalZoneIndex}`);
if (originalZoneIndex !== -1) { if (originalZoneIndex !== -1) {
const originalZone = wallZones[originalZoneIndex]; const originalZone = wallZones[originalZoneIndex];
if (originalZone) { if (originalZone) {
@ -440,13 +439,12 @@ export class AppModelDrag extends Monobehiver {
const angle = Math.atan2(targetDirection.x, targetDirection.z); const angle = Math.atan2(targetDirection.x, targetDirection.z);
rootMesh.rotation.y = angle; rootMesh.rotation.y = angle;
console.log(`[拖拽吸附] 模型 ${modelId} 已返回原区域 ${originalZoneIndex}`);
return; // 不更新映射,保持原映射 return; // 不更新映射,保持原映射
} }
} }
} else { } else {
// 未启用边界返回,保持当前位置,不做吸附 // 未启用边界返回,保持当前位置,不做吸附
console.log(`[拖拽吸附] 未启用边界返回,保持当前位置,不做吸附`);
// 更新映射关系(可能移出了原区域) // 更新映射关系(可能移出了原区域)
this.updateModelZoneMapping(modelId); this.updateModelZoneMapping(modelId);
return; return;
@ -461,13 +459,13 @@ export class AppModelDrag extends Monobehiver {
if (occupyingModelId && occupyingModelId !== modelId) { if (occupyingModelId && occupyingModelId !== modelId) {
// 目标区域已被其他模型占用 // 目标区域已被其他模型占用
console.log(`[拖拽吸附] 目标区域 ${closestZoneIndex} 已被模型 ${occupyingModelId} 占用`);
if (handleOccupiedZone) { if (handleOccupiedZone) {
// 启用了占用区域处理 // 启用了占用区域处理
if (occupiedZoneAction === 'return') { if (occupiedZoneAction === 'return') {
// 返回原位置 // 返回原位置
console.log(`[拖拽吸附] 配置为返回原位置,回到区域 ${originalZoneIndex}`);
if (originalZoneIndex !== -1) { if (originalZoneIndex !== -1) {
const originalZone = wallZones[originalZoneIndex]; const originalZone = wallZones[originalZoneIndex];
if (originalZone) { if (originalZone) {
@ -479,7 +477,6 @@ export class AppModelDrag extends Monobehiver {
const angle = Math.atan2(targetDirection.x, targetDirection.z); const angle = Math.atan2(targetDirection.x, targetDirection.z);
rootMesh.rotation.y = angle; rootMesh.rotation.y = angle;
console.log(`[拖拽吸附] 模型 ${modelId} 返回原区域 ${originalZoneIndex}`);
return; // 不更新映射,保持原映射 return; // 不更新映射,保持原映射
} }
} }
@ -505,7 +502,6 @@ export class AppModelDrag extends Monobehiver {
const angle = Math.atan2(targetDirection.x, targetDirection.z); const angle = Math.atan2(targetDirection.x, targetDirection.z);
rootMesh.rotation.y = angle; rootMesh.rotation.y = angle;
console.log(`[拖拽吸附] 模型 ${modelId} 吸附到区域 ${closestZoneIndex}`);
// 更新映射关系 // 更新映射关系
this.updateModelZoneMapping(modelId); this.updateModelZoneMapping(modelId);
@ -522,7 +518,6 @@ export class AppModelDrag extends Monobehiver {
const rootMesh = meshes[0]; const rootMesh = meshes[0];
const modelPosition = rootMesh.position; const modelPosition = rootMesh.position;
console.log(`[边界检测] 模型 ${modelId} 拖拽结束,当前位置:`, modelPosition);
// 获取 AppDropZone // 获取 AppDropZone
const appDropZone = this.mainApp.appDropZone; const appDropZone = this.mainApp.appDropZone;
@ -540,17 +535,14 @@ export class AppModelDrag extends Monobehiver {
}); });
if (!originalWallName) { if (!originalWallName) {
console.log(`[边界检测] 模型 ${modelId} 未找到原始墙面,跳过检测`);
return; return;
} }
console.log(`[边界检测] 模型 ${modelId} 原始墙面: ${originalWallName}`);
// 获取该墙面的所有分割区域 // 获取该墙面的所有分割区域
const wallZones = appDropZone.getZonesByWall(originalWallName); const wallZones = appDropZone.getZonesByWall(originalWallName);
if (!wallZones.length) return; if (!wallZones.length) return;
console.log(`[边界检测] 墙面 ${originalWallName}${wallZones.length} 个分割区域`);
// 计算模型与每个分割区域的距离,找到最近的区域 // 计算模型与每个分割区域的距离,找到最近的区域
let closestZoneIndex = -1; let closestZoneIndex = -1;
@ -559,7 +551,6 @@ export class AppModelDrag extends Monobehiver {
wallZones.forEach((zone, index) => { wallZones.forEach((zone, index) => {
// 计算模型位置到区域中心的距离 // 计算模型位置到区域中心的距离
const distance = modelPosition.subtract(zone.center).length(); const distance = modelPosition.subtract(zone.center).length();
console.log(`[边界检测] 区域 ${index} 中心:`, zone.center, `距离: ${distance.toFixed(3)}`);
if (distance < minDistance) { if (distance < minDistance) {
minDistance = distance; minDistance = distance;
@ -568,11 +559,9 @@ export class AppModelDrag extends Monobehiver {
}); });
if (closestZoneIndex === -1) { if (closestZoneIndex === -1) {
console.log(`[边界检测] 未找到最近的区域`);
return; return;
} }
console.log(`[边界检测] 模型 ${modelId} 最接近区域 ${closestZoneIndex},距离: ${minDistance.toFixed(3)}`);
// 查找模型当前所在的区域索引 // 查找模型当前所在的区域索引
let currentZoneIndex = -1; let currentZoneIndex = -1;
@ -587,13 +576,11 @@ export class AppModelDrag extends Monobehiver {
// 如果模型移动到了新的区域,更新映射 // 如果模型移动到了新的区域,更新映射
if (currentZoneIndex !== closestZoneIndex) { if (currentZoneIndex !== closestZoneIndex) {
console.log(`[边界检测] 模型 ${modelId} 从区域 ${currentZoneIndex} 移动到区域 ${closestZoneIndex}`);
// 删除旧映射 // 删除旧映射
if (currentZoneIndex !== -1) { if (currentZoneIndex !== -1) {
const oldKey = `${originalWallName}[${currentZoneIndex}]`; const oldKey = `${originalWallName}[${currentZoneIndex}]`;
appDropZone['zoneModelMap']?.delete(oldKey); appDropZone['zoneModelMap']?.delete(oldKey);
console.log(`[边界检测] 删除旧映射: ${oldKey}`);
} }
// 检查目标区域是否已有模型 // 检查目标区域是否已有模型
@ -606,17 +593,14 @@ export class AppModelDrag extends Monobehiver {
const occupiedZoneAction = dragInfo?.config.occupiedZoneAction ?? 'return'; const occupiedZoneAction = dragInfo?.config.occupiedZoneAction ?? 'return';
if (existingModelId && existingModelId !== modelId) { if (existingModelId && existingModelId !== modelId) {
console.log(`[边界检测] 目标区域 ${closestZoneIndex} 已有模型 ${existingModelId}`);
// 只有在启用占用区域处理且为 'replace' 模式下才交换位置 // 只有在启用占用区域处理且为 'replace' 模式下才交换位置
if (handleOccupiedZone && occupiedZoneAction === 'replace') { if (handleOccupiedZone && occupiedZoneAction === 'replace') {
console.log(`[边界检测] 配置为替换模式,交换位置`);
// 将原有模型移动到旧位置 // 将原有模型移动到旧位置
if (currentZoneIndex !== -1) { if (currentZoneIndex !== -1) {
const swapKey = `${originalWallName}[${currentZoneIndex}]`; const swapKey = `${originalWallName}[${currentZoneIndex}]`;
appDropZone['zoneModelMap']?.set(swapKey, existingModelId); appDropZone['zoneModelMap']?.set(swapKey, existingModelId);
console.log(`[边界检测] 模型 ${existingModelId} 移动到区域 ${currentZoneIndex}`);
// 实际移动被替换模型的物理位置 // 实际移动被替换模型的物理位置
const existingMeshes = this.mainApp.appModel?.modelDic?.Get(existingModelId); 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); const angle = Math.atan2(targetDirection.x, targetDirection.z);
existingRootMesh.rotation.y = angle; existingRootMesh.rotation.y = angle;
console.log(`[边界检测] 已将模型 ${existingModelId} 物理移动到区域 ${currentZoneIndex}`);
} }
} }
} }
} else {
console.log(`[边界检测] 未启用替换模式或未启用占用区域处理,允许重叠`);
} }
} }
// 添加新映射 // 添加新映射
appDropZone['zoneModelMap']?.set(newKey, modelId); appDropZone['zoneModelMap']?.set(newKey, modelId);
console.log(`[边界检测] 添加新映射: ${newKey} -> ${modelId}`);
} else {
console.log(`[边界检测] 模型 ${modelId} 仍在区域 ${currentZoneIndex},无需更新映射`);
} }
} }

View File

@ -291,10 +291,10 @@ export class AppPlacementWall {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result return result
? { ? {
r: parseInt(result[1], 16) / 255, r: parseInt(result[1], 16) / 255,
g: parseInt(result[2], 16) / 255, g: parseInt(result[2], 16) / 255,
b: parseInt(result[3], 16) / 255 b: parseInt(result[3], 16) / 255
} }
: { r: 0, g: 0, b: 0 }; : { r: 0, g: 0, b: 0 };
} }
@ -331,23 +331,26 @@ export class AppPlacementWall {
/** /**
* 显示所有放置区域 * 显示所有放置区域
*/ */
show(): void { // show(): void {
this.placementZones.forEach(zone => { // this.placementZones.forEach(zone => {
zone.mesh.isVisible = true; // zone.mesh.isVisible = true;
}); // });
this.borderLines.forEach(line => { // this.borderLines.forEach(line => {
line.isVisible = true; // line.isVisible = true;
}); // });
} // }
/** /**
* 只显示指定墙面的放置区域 * 只显示指定墙面的放置区域
* @param wallName 墙面名称 * @param wallName 墙面名称
*/ */
showWall(wallName: string): void { showWall(wallName: string): void {
// 先隐藏所有 // 先隐藏所有
this.hide(); this.hide();
console.log(this.placementZones, wallName);
// 只显示指定墙面的区域 // 只显示指定墙面的区域
this.placementZones.forEach(zone => { this.placementZones.forEach(zone => {
if (zone.wallName === wallName) { if (zone.wallName === wallName) {