This commit is contained in:
2026-05-17 15:21:27 +08:00
parent 870477f864
commit 6a5d729568
4 changed files with 40 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

View File

@ -140,7 +140,7 @@ export const executeEvent = async (dropzone_data, result) => {
if (event.event_type === 'change_color') {
const materialName = event.material_name;
const { color, color_map_url, normal_map_url } = event.target_data;
const { color, color_map_url, normal_map_url, metallic, roughness } = event.target_data;
console.log('替换百叶模型颜色:', event.target_data);
kernel.material.apply({
@ -148,6 +148,8 @@ export const executeEvent = async (dropzone_data, result) => {
albedoColor: color,
albedoTexture: color_map_url,
normalMap: normal_map_url,
metallic: metallic,
roughness: roughness
});
console.log(`百叶模型颜色已替换为 ${color}`);
@ -155,22 +157,30 @@ export const executeEvent = async (dropzone_data, result) => {
}
}
//换棚子
export const executeEvent2 = async (result) => {
kernel.dropZone.clearZones();
kernel.model.removeAll();
// 检查是否有模型更换事件
const hasModelChange = result.data.events.some(e => e.event_type === 'change_model');
// 只有在需要更换模型时才清除
if (hasModelChange) {
kernel.dropZone.clearZones();
kernel.model.removeAll();
}
// 先处理所有 change_model 事件
for (const event of result.data.events) {
const { target_data } = event;
if (event.event_type === 'change_model') {
const { target_data } = event;
console.log(event.target_data);
const { id, name, file_url, model_control_type, category, placement_zone } = event.target_data;
const { id, name, file_url, model_control_type, category, placement_zone } = target_data;
console.log('替换百叶模型:', event);
console.log('替换百叶模型类型:', category);
if (placement_zone) {
const { alpha, border_color, color, show_border, thickness, walls } = placement_zone
kernel.dropZone.setData({
color: color,
alpha: +alpha,
thickness: thickness,
@ -179,19 +189,23 @@ export const executeEvent2 = async (result) => {
walls: walls
});
}
// 加载并放置模型
await kernel.model.replace({
modelId: target_data.category,
modelUrl: target_data.file_url,
modelControlType: target_data.model_control_type,
// 加载并放置模型(使用 category 作为 modelId
await kernel.model.add({
modelId: category,
modelUrl: file_url,
modelControlType: model_control_type,
})
console.log(`百叶模型已放置为 ${name}`);
}
}
// 等待模型加载完成后,再处理 change_color 事件
for (const event of result.data.events) {
if (event.event_type === 'change_color') {
const materialName = event.material_name;
const { color, color_map_url, normal_map_url } = event.target_data;
const { color, color_map_url, normal_map_url, metallic, roughness } = event.target_data;
console.log('替换百叶模型颜色:', event.target_data);
kernel.material.apply({
@ -199,6 +213,8 @@ export const executeEvent2 = async (result) => {
albedoColor: color,
albedoTexture: color_map_url,
normalMap: normal_map_url,
metallic: metallic,
roughness: roughness
});
console.log(`百叶模型颜色已替换为 ${color}`);

View File

@ -165,8 +165,12 @@ export class AppModel extends Monobehiver {
// 如果该材质还没有被克隆过,则克隆它
if (!clonedMaterials.has(originalName)) {
const clonedMaterial = originalMaterial.clone(`${originalName}_${modelId}`);
const newName = `${originalName}_${modelId}`;
const clonedMaterial = originalMaterial.clone(newName);
clonedMaterials.set(originalName, clonedMaterial);
console.log(`[cloneMaterials] 克隆材质: ${originalName} -> ${newName}`);
console.log(`[cloneMaterials] 克隆后的材质名称: ${clonedMaterial.name}`);
console.log(`[cloneMaterials] 材质是否在场景中:`, scene.materials.includes(clonedMaterial));
}
// 应用克隆的材质
@ -175,6 +179,7 @@ export class AppModel extends Monobehiver {
});
console.log(`已为模型 ${modelId} 克隆 ${clonedMaterials.size} 个材质`);
console.log(`[cloneMaterials] 场景中的所有材质:`, scene.materials.map(m => m.name));
}
/** 为网格设置阴影(投射和接收) */

View File

@ -760,6 +760,10 @@ export class GameManager extends Monobehiver {
}): void {
this.updateDictionaries();
// 调试:打印所有材质名称
console.log('[applyMaterial] 查找材质:', options.target);
console.log('[applyMaterial] 当前所有材质:', this.materialDic.Values().map(m => m.name));
// 查找目标材质(支持精确匹配和前缀匹配)
const targetMaterials: PBRMaterial[] = [];
this.materialDic.Values().forEach(material => {
@ -773,6 +777,8 @@ export class GameManager extends Monobehiver {
return;
}
console.log('[applyMaterial] 找到材质:', targetMaterials.map(m => m.name));
// 应用材质属性到目标材质
targetMaterials.forEach(material => {
// 应用颜色