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

@ -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();