This commit is contained in:
2026-05-17 13:59:16 +08:00
parent f76b19697c
commit 870477f864
7 changed files with 176 additions and 93 deletions

View File

@ -498,6 +498,28 @@ export class AppModel extends Monobehiver {
console.log(`Model removed: ${modelName}`);
}
/**
* 清除所有已添加的模型并释放内存
* 主要用于切换尺寸后清除不适用的配件
*/
removeAll(): void {
const modelNames = this.modelDic.Keys();
console.log(`开始清除所有模型,共 ${modelNames.length} 个模型`);
modelNames.forEach(modelName => {
const meshes = this.modelDic.Get(modelName);
if (meshes?.length) {
this.getModelTransformTargets(meshes).forEach(mesh => mesh.dispose(false, true));
}
});
this.modelDic.Clear();
this.modelMetadataDic.Clear();
this.mainApp.gameManager?.updateDictionaries();
console.log('所有模型已清除,内存已释放');
}
/**
* 获取模型元数据
* @param modelName 模型名称

View File

@ -223,6 +223,7 @@ export class AppPlacementWall {
this.scene
);
line.color = new Color3(1, 1, 1); // 白色
line.isPickable = false; // 禁用边框的点击
this.borderLines.push(line);
});
}
@ -265,6 +266,7 @@ export class AppPlacementWall {
this.scene
);
line.color = lineColor;
line.isPickable = false; // 禁用边框的点击
this.borderLines.push(line);
});
}

View File

@ -751,7 +751,6 @@ export class GameManager extends Monobehiver {
*/
applyMaterial(options: {
target: string;
modelId?: string; // 新增指定模型ID只修改该模型的材质
albedoColor?: string;
albedoTexture?: string;
normalMap?: string;
@ -761,37 +760,20 @@ export class GameManager extends Monobehiver {
}): void {
this.updateDictionaries();
// 1. 查找目标材质
// 查找目标材质(支持精确匹配和前缀匹配)
const targetMaterials: PBRMaterial[] = [];
if (options.modelId) {
// 如果指定了模型ID只查找该模型的材质
const materialName = `${options.target}_${options.modelId}`;
this.materialDic.Values().forEach(material => {
if (material.name === materialName) {
targetMaterials.push(material);
}
});
if (targetMaterials.length === 0) {
console.warn(`Material not found for model ${options.modelId}: ${materialName}`);
return;
this.materialDic.Values().forEach(material => {
if (material.name === options.target || material.name.startsWith(`${options.target}_`)) {
targetMaterials.push(material);
}
} else {
// 没有指定模型ID查找所有匹配的材质旧逻辑
this.materialDic.Values().forEach(material => {
if (material.name === options.target || material.name.startsWith(`${options.target}_`)) {
targetMaterials.push(material);
}
});
});
if (targetMaterials.length === 0) {
console.warn(`Material not found: ${options.target}`);
return;
}
if (targetMaterials.length === 0) {
console.warn(`Material not found: ${options.target}`);
return;
}
// 2. 应用材质属性到目标材质
// 应用材质属性到目标材质
targetMaterials.forEach(material => {
// 应用颜色
if (options.albedoColor) {
@ -828,6 +810,6 @@ export class GameManager extends Monobehiver {
material.markDirty();
});
console.log(`Material applied to: ${options.target}${options.modelId ? ` (model: ${options.modelId})` : ''}`, options);
console.log(`Material applied to ${targetMaterials.length} material(s): ${options.target}`, options);
}
}