This commit is contained in:
2026-05-19 12:45:22 +08:00
parent 093a671fd7
commit fef2c4e3bd
4 changed files with 48 additions and 34 deletions

View File

@ -203,7 +203,7 @@ const isModelExists = (modelId) => {
return kernel.model.exists(modelId);
}
//一般是换棚子/换颜色/显示放置区域
//一般是换棚子/换颜色/设置放置区域
const executeEvent2 = async (result) => {
const kernel = getKernel();
@ -215,18 +215,19 @@ const isModelExists = (modelId) => {
if (hasModelChange) {
const firstModelEvent = result.data.events.find(e => e.event_type === 'change_model');
if (firstModelEvent && firstModelEvent.target_data) {
const {name, category } = firstModelEvent.target_data;
modelAlreadyExists = kernel.model.exists(name+'_'+category);
console.log(`检查模型 ${name+'_'+category} 是否存在:`, modelAlreadyExists);
const { name, category } = firstModelEvent.target_data;
modelAlreadyExists = kernel.model.exists(name + '_' + category);
console.log(`检查模型 ${name + '_' + category} 是否存在:`, modelAlreadyExists);
}
}
// 只有在需要更换模型且模型不存在时才清除
if (hasModelChange && !modelAlreadyExists) {
console.log('模型不存在,执行清除操作');
kernel.dropZone.clearZones();
kernel.model.removeAll();
} else if (modelAlreadyExists) {
kernel.dropZone.hide();
console.log('模型已存在,跳过清除操作,仅更新材质');
}
@ -241,10 +242,9 @@ const isModelExists = (modelId) => {
};
const { id, name, file_url, model_control_type, category, placement_zone } = target_data;
// 如果模型已存在,跳过加载
if (modelAlreadyExists) {
console.log(`模型 ${name+'_'+category} 已存在,跳过加载`);
console.log(`模型 ${name + '_' + category} 已存在,跳过加载`);
continue;
}
@ -262,12 +262,13 @@ const isModelExists = (modelId) => {
// 加载并放置模型(使用 category 作为 modelId
await kernel.model.add({
modelName: name,
modelId: category,
modelUrl: file_url,
modelControlType: model_control_type,
})
console.log(`模型已放置为 ${name}`);
console.log(`模型已放置为 ${name + '_' + category}`);
}
}
@ -293,6 +294,7 @@ const isModelExists = (modelId) => {
}
//加载热点
const getHotspot = async () => {
const kernel = getKernel();

View File

@ -129089,6 +129089,7 @@ discard;}}
return await this.addMultiple(modelConfig);
}
return await this.addSingle(
modelConfig.modelName,
modelConfig.modelId,
modelConfig.modelUrl,
modelConfig.modelControlType,
@ -129099,10 +129100,10 @@ discard;}}
/**
* 添加单个模型
*/
async addSingle(modelName, modelUrl, modelControlType, drag, transform) {
const existingMeshes = this.modelDic.Get(modelName);
async addSingle(modelName, modelId, modelUrl, modelControlType, drag, transform) {
const existingMeshes = this.modelDic.Get(modelName + "_" + modelId);
if (existingMeshes?.length && !existingMeshes[0].isDisposed()) {
console.log(`模型 ${modelName} 已存在,直接显示`);
console.log(`模型 ${modelName + modelId} 已存在,直接显示`);
this.showMeshes(existingMeshes);
return { success: true, meshes: existingMeshes };
}
@ -129110,21 +129111,22 @@ discard;}}
this.emitSingleProgress(modelUrl, event);
});
if (result.success && result.meshes) {
this.cloneMaterials(result.meshes, modelName);
result.meshes = this.createModelRoot(modelName, result.meshes);
this.modelDic.Set(modelName, result.meshes);
this.modelMetadataDic.Set(modelName, {
modelId: modelName,
this.cloneMaterials(result.meshes, modelId);
result.meshes = this.createModelRoot(modelName + "_" + modelId, result.meshes);
this.modelDic.Set(modelName + "_" + modelId, result.meshes);
this.modelMetadataDic.Set(modelName + "_" + modelId, {
modelName,
modelId,
modelUrl,
modelControlType,
drag,
transform
});
if (transform) {
this.applyTransform(modelName, transform);
this.applyTransform(modelName + "_" + modelId, transform);
}
if (drag) {
this.mainApp.appModelDrag?.configureDrag(modelName, drag);
this.mainApp.appModelDrag?.configureDrag(modelName + "_" + modelId, drag);
}
this.mainApp.gameManager?.updateDictionaries();
EventBridge.modelLoaded({ urls: [modelUrl] });
@ -129141,15 +129143,16 @@ discard;}}
const results = [];
EventBridge.modelLoadProgress({ loaded: 0, total, progress: 0, percentage: 0 });
for (let i = 0; i < models.length; i++) {
const { modelId, modelUrl, modelControlType, drag, transform } = models[i];
const { modelName, modelId, modelUrl, modelControlType, drag, transform } = models[i];
const result = await this.loadSingleModel(modelUrl, (event) => {
this.emitProgress(i, total, modelUrl, event);
});
if (result.success && result.meshes) {
this.cloneMaterials(result.meshes, modelId);
result.meshes = this.createModelRoot(modelId, result.meshes);
this.modelDic.Set(modelId, result.meshes);
this.modelMetadataDic.Set(modelId, {
result.meshes = this.createModelRoot(modelName, result.meshes);
this.modelDic.Set(modelName + "_" + modelId, result.meshes);
this.modelMetadataDic.Set(modelName + "_" + modelId, {
modelName,
modelId,
modelUrl,
modelControlType,
@ -129157,10 +129160,10 @@ discard;}}
transform
});
if (transform) {
this.applyTransform(modelId, transform);
this.applyTransform(modelName + "_" + modelId, transform);
}
if (drag) {
this.mainApp.appModelDrag?.configureDrag(modelId, drag);
this.mainApp.appModelDrag?.configureDrag(modelName + "_" + modelId, drag);
}
}
results.push(result);
@ -129265,6 +129268,7 @@ discard;}}
async replaceModel(modelConfig) {
this.removeByName(modelConfig.modelId);
return await this.addSingle(
modelConfig.modelName,
modelConfig.modelId,
modelConfig.modelUrl,
modelConfig.modelControlType,
@ -355123,8 +355127,11 @@ clipPos=viewProjection*worldPos;previousClipPos=previousViewProjection*previousW
const transformTarget = this.mainApp.appModel.getModelTransformTargetByMesh(pickInfo.pickedMesh);
this.mainApp.appPositionGizmo.attach(transformTarget ?? pickInfo.pickedMesh);
const modelMetadata = this.mainApp.appModel.getMetadataByMesh(pickInfo.pickedMesh);
const modelName = this.mainApp.appModel.findModelNameByMesh(pickInfo.pickedMesh);
console.log(modelName);
EventBridge.modelClick({
meshName: pickInfo.pickedMesh.name,
modelName,
pickedMesh: pickInfo.pickedMesh,
pickedPoint: pickInfo.pickedPoint,
materialName,
@ -356840,6 +356847,8 @@ clipPos=viewProjection*worldPos;previousClipPos=previousViewProjection*previousW
wallModelDivisionsMap = /* @__PURE__ */ new Map();
// 存储放置区域配置数据
dropZoneConfig = null;
// 存储原始墙面配置(用于 updateDivisions 时恢复完整墙面列表)
originalWalls = [];
constructor(scene) {
this.scene = scene;
this.placementWall = new AppPlacementWall(scene);
@ -356856,6 +356865,7 @@ clipPos=viewProjection*worldPos;previousClipPos=previousViewProjection*previousW
*/
setData(config) {
this.dropZoneConfig = config;
this.originalWalls = config.walls.map((wall) => ({ ...wall }));
}
/**
* 生成放置区域
@ -356931,15 +356941,17 @@ clipPos=viewProjection*worldPos;previousClipPos=previousViewProjection*previousW
}
return null;
};
this.dropZoneConfig.walls = this.dropZoneConfig.walls.map((wall) => {
this.dropZoneConfig.walls = this.originalWalls.map((wall) => {
const newDivisions = matchWallName(wall.name);
const finalDivisions = newDivisions !== null ? newDivisions : wall.divisions || 1;
console.log(`墙面 "${wall.name}" 匹配到分割数: ${finalDivisions}`);
if (newDivisions === null) {
return null;
}
console.log(`墙面 "${wall.name}" 匹配到分割数: ${newDivisions}`);
return {
...wall,
divisions: finalDivisions
divisions: newDivisions
};
});
}).filter((wall) => wall !== null);
this.clearZones();
const zones = this.generateDropZones();
this.show();

View File

@ -339,10 +339,10 @@
<button class="option-btn" data-option="louver-4">SPFSW13FTC</button>
<button class="option-btn" data-option="louver-4">SPFSW10FTW</button>
<button class="option-btn" data-option="louver-4">SPFSW10FTC</button>
<button class="option-btn" data-option="louver-4">SPFPDS10FTW</button>
</div>
</div>
</div>
<!-- 配色 -->
<div class="config-category">
<div class="category-header" data-category="color">

View File

@ -197,7 +197,7 @@ export const executeEvent = async (dropzone_data, result) => {
}
}
//一般是换棚子/换颜色/显示放置区域
//一般是换棚子/换颜色/设置放置区域
export const executeEvent2 = async (result) => {
const kernel = getKernel();
@ -214,14 +214,14 @@ export const executeEvent2 = async (result) => {
console.log(`检查模型 ${name + '_' + category} 是否存在:`, modelAlreadyExists);
}
}
// 只有在需要更换模型且模型不存在时才清除
if (hasModelChange && !modelAlreadyExists) {
console.log('模型不存在,执行清除操作');
kernel.model.removeAll();
kernel.model.removeAll();
} else if (modelAlreadyExists) {
kernel.dropZone.hide();
kernel.dropZone.hide();
console.log('模型已存在,跳过清除操作,仅更新材质');
}