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

View File

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