1
This commit is contained in:
@ -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 模型名称
|
||||
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,6 +58,16 @@ export class KernelAdapter {
|
||||
*/
|
||||
findModelNameByMesh: (mesh: any): string | undefined => {
|
||||
return this.mainApp.appModel.findModelNameByMesh(mesh);
|
||||
},
|
||||
/**
|
||||
* 清除所有已添加的模型并释放内存
|
||||
* 主要用于切换尺寸后清除不适用的配件
|
||||
* @example
|
||||
* // 切换尺寸时清除所有配件
|
||||
* kernel.model.removeAll();
|
||||
*/
|
||||
removeAll: (): void => {
|
||||
this.mainApp.appModel.removeAll();
|
||||
}
|
||||
};
|
||||
|
||||
@ -69,7 +79,6 @@ export class KernelAdapter {
|
||||
*/
|
||||
apply: (options: {
|
||||
target: string;
|
||||
modelId?: string; // 可选:指定模型ID,只修改该模型的材质
|
||||
albedoColor?: string;
|
||||
albedoTexture?: string;
|
||||
normalMap?: string;
|
||||
|
||||
Reference in New Issue
Block a user