点击空白隐藏放置区域
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user