点击空白隐藏放置区域

This commit is contained in:
2026-05-14 12:09:10 +08:00
parent 8674efefc7
commit ce73c35b8a
6 changed files with 63 additions and 32 deletions

View File

@ -751,6 +751,7 @@ export class GameManager extends Monobehiver {
*/
applyMaterial(options: {
target: string;
modelId?: string; // 新增指定模型ID只修改该模型的材质
albedoColor?: string;
albedoTexture?: string;
normalMap?: string;
@ -762,15 +763,32 @@ export class GameManager extends Monobehiver {
// 1. 查找目标材质
const targetMaterials: PBRMaterial[] = [];
this.materialDic.Values().forEach(material => {
if (material.name === options.target) {
targetMaterials.push(material);
}
});
if (targetMaterials.length === 0) {
console.warn(`Material not found: ${options.target}`);
return;
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;
}
} 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;
}
}
// 2. 应用材质属性到目标材质
@ -810,6 +828,6 @@ export class GameManager extends Monobehiver {
material.markDirty();
});
console.log(`Material applied to: ${options.target}`, options);
console.log(`Material applied to: ${options.target}${options.modelId ? ` (model: ${options.modelId})` : ''}`, options);
}
}