This commit is contained in:
2026-05-13 10:43:06 +08:00
parent 6cefd063f2
commit 223fa5dd4e
19 changed files with 2282 additions and 104 deletions

View File

@ -746,42 +746,70 @@ export class GameManager extends Monobehiver {
}
/**
* 应用材质
* @param target 目标对象
* @param material 材质路径
* 应用材质属性
* @param options 材质配置选项
*/
applyMaterial(target: string, attribute: string, value:string): void {
if (attribute !== 'baseColor' || typeof value !== 'string') return;
applyMaterial(options: {
target: string;
albedoColor?: string;
albedoTexture?: string;
normalMap?: string;
metallicTexture?: string;
roughness?: number;
metallic?: number;
}): void {
this.updateDictionaries();
// 示例实现:根据目标和材质路径应用材质
// 1. 查找目标网格
// 1. 查找目标材质
const targetMaterials: PBRMaterial[] = [];
this.materialDic.Values().forEach(material => {
if (material.name === target) {
if (material.name === options.target) {
targetMaterials.push(material);
}
});
if (targetMaterials.length === 0) {
console.warn(`Target not found: ${target}`);
console.warn(`Material not found: ${options.target}`);
return;
}
// 2. 处理材质路径
// 这里可以根据材质路径加载对应的材质配置
// 例如paint/blue 可以映射到特定的材质配置
// 3. 应用材质到目标网格
const color = Color3.FromHexString(value);
// 2. 应用材质属性到目标材质
targetMaterials.forEach(material => {
// 如果是 baseColor 且值是字符串16进制颜色转换为 Color3
// 应用颜色
if (options.albedoColor) {
const color = Color3.FromHexString(options.albedoColor);
material.albedoColor.copyFrom(color);
}
// 如果有纹理颜色会作为纹理的乘法因子
// 强制刷新材质
material.markDirty();
// 应用反照率纹理颜色贴图)
if (options.albedoTexture) {
material.albedoTexture = new Texture(options.albedoTexture);
}
// 应用法线贴图
if (options.normalMap) {
material.bumpTexture = new Texture(options.normalMap);
}
// 应用金属度贴图
if (options.metallicTexture) {
material.metallicTexture = new Texture(options.metallicTexture);
}
// 应用粗糙度值
if (options.roughness !== undefined) {
material.roughness = options.roughness;
}
// 应用金属度值
if (options.metallic !== undefined) {
material.metallic = options.metallic;
}
// 强制刷新材质
material.markDirty();
});
console.log(`Material applied to: ${options.target}`, options);
}
}