1
This commit is contained in:
@ -208,7 +208,7 @@ export class AppModel extends Monobehiver {
|
||||
});
|
||||
|
||||
if (result.success && result.meshes) {
|
||||
this.cloneMaterials(result.meshes, modelName);
|
||||
// this.cloneMaterials(result.meshes, modelName);
|
||||
this.modelDic.Set(modelName, result.meshes);
|
||||
|
||||
// 更新 GameManager 的字典
|
||||
|
||||
@ -745,12 +745,13 @@ export class GameManager extends Monobehiver {
|
||||
applyMaterial(target: string, attribute: string, value: number | string): void {
|
||||
// 这里需要根据实际的材质管理逻辑实现
|
||||
console.log(`Applying attribute ${attribute} to ${value}`);
|
||||
console.log(this.materialDic);
|
||||
|
||||
// 示例实现:根据目标和材质路径应用材质
|
||||
// 1. 查找目标网格
|
||||
const targetMaterials: PBRMaterial[] = [];
|
||||
this.materialDic.Values().forEach(material => {
|
||||
if (material.name.includes(target)) {
|
||||
if (material.name === target) {
|
||||
console.log(`${this.materialDic.Get(material.name)}`, material);
|
||||
targetMaterials.push(material);
|
||||
}
|
||||
@ -769,8 +770,23 @@ export class GameManager extends Monobehiver {
|
||||
targetMaterials.forEach(material => {
|
||||
if (attribute === 'baseColor' && typeof value === 'string') {
|
||||
// 如果是 baseColor 且值是字符串(16进制颜色),转换为 Color3
|
||||
material.albedoColor = Color3.FromHexString(value);
|
||||
console.log(`Applying baseColor ${value} to material: ${material.name}`);
|
||||
const color = Color3.FromHexString(value);
|
||||
|
||||
console.log(`Before: albedoColor =`, material.albedoColor);
|
||||
console.log(`Before: albedoTexture =`, material.albedoTexture);
|
||||
|
||||
material.albedoColor = color;
|
||||
|
||||
// 如果有纹理,颜色会作为纹理的乘法因子
|
||||
if (material.albedoTexture) {
|
||||
console.log(`Material ${material.name} has albedoTexture, color will tint the texture`);
|
||||
}
|
||||
|
||||
// 强制刷新材质
|
||||
material.markDirty();
|
||||
|
||||
console.log(`After: albedoColor =`, material.albedoColor);
|
||||
console.log(`Applying baseColor ${value} to material: ${material.name}`, color);
|
||||
} else if (material[attribute]) {
|
||||
material[attribute] = value;
|
||||
console.log(`Applying attribute ${attribute} to ${value} to mesh: ${material.name}`);
|
||||
|
||||
Reference in New Issue
Block a user