新问题:切换尺寸,在放置配件会重叠

This commit is contained in:
2026-05-18 19:27:06 +08:00
parent 840e3d6a55
commit 8478d45046
3 changed files with 39 additions and 37 deletions

View File

@ -67,7 +67,7 @@ export const getAutoLoadModelList = async () => {
const models = data.data // 这就是模型列表
models.forEach(model => {
if (model.placement_zone) {
const { alpha, border_color, color, show_border, thickness, walls } = model.placement_zone
kernel.dropZone.setData({
@ -80,9 +80,9 @@ export const getAutoLoadModelList = async () => {
walls: walls
});
}
kernel.model.add({
modelName: model.name+'_'+model.category,
modelName: model.name + '_' + model.category,
modelId: model.category,
modelUrl: model.file_url,
modelControlType: model.model_control_type,
@ -150,17 +150,17 @@ export const executeEvent = async (dropzone_data, result) => {
console.log(event.target_data);
const { name, file_url, model_control_type, category } = event.target_data;
// 生成唯一的模型ID
const modelId = Date.now();
// 先记录模型放置(会自动处理替换逻辑)
kernel.dropZone.recordModelPlacement(wallName, index, modelId);
console.log(Math.abs(rotation.y - 90), Math.abs(rotation.y - 90) > 5 ? 'x' : 'z');
kernel.dropZone.recordModelPlacement(wallName, index, name + '_' + modelId);
console.log(name + '_' + modelId);
// 加载并放置模型
await kernel.model.add({
modelName: name ,
modelName: name,
modelId: modelId,
modelUrl: file_url,
modelControlType: model_control_type,
@ -175,7 +175,7 @@ export const executeEvent = async (dropzone_data, result) => {
}
});
console.log(`百叶模型已放置为 ${name+'_'+category}`);
console.log(`百叶模型已放置为 ${name + '_' + category}`);
}
if (event.event_type === 'change_color') {
@ -209,17 +209,17 @@ export const executeEvent2 = async (result) => {
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(category);
console.log(`检查模型 ${name+'_'+category} 是否存在:`, modelAlreadyExists);
const { name, category } = firstModelEvent.target_data;
modelAlreadyExists = kernel.model.exists(name + '_' + category);
console.log(`检查模型 ${name + '_' + category} 是否存在:`, modelAlreadyExists);
}
}
kernel.dropZone.clearZones();
// 只有在需要更换模型且模型不存在时才清除
if (hasModelChange && !modelAlreadyExists) {
console.log('模型不存在,执行清除操作');
kernel.dropZone.clearZones();
kernel.model.removeAll();
kernel.model.removeAll();
} else if (modelAlreadyExists) {
console.log('模型已存在,跳过清除操作,仅更新材质');
}
@ -237,7 +237,7 @@ export const executeEvent2 = async (result) => {
const { id, name, file_url, model_control_type, category, placement_zone } = target_data;
// 如果模型已存在,跳过加载
if (modelAlreadyExists) {
console.log(`模型 ${name+'_'+category} 已存在,跳过加载`);
console.log(`模型 ${name + '_' + category} 已存在,跳过加载`);
continue;
}
@ -256,12 +256,12 @@ export const executeEvent2 = async (result) => {
// 加载并放置模型(使用 category 作为 modelId
await kernel.model.add({
modelName: name,
modelId: category,
modelId: category,
modelUrl: file_url,
modelControlType: model_control_type,
})
console.log(`模型已放置为 ${name+'_'+category}`);
console.log(`模型已放置为 ${name + '_' + category}`);
}
}

View File

@ -270,7 +270,7 @@ export class AppModel extends Monobehiver {
// 检查是否已存在
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 };
}
@ -284,6 +284,7 @@ export class AppModel extends Monobehiver {
// 克隆材质,确保每个模型有独立的材质
this.cloneMaterials(result.meshes, modelId);
// 存储模型
result.meshes = this.createModelRoot(modelName+'_'+modelId, result.meshes);
this.modelDic.Set(modelName+'_'+modelId, result.meshes);
@ -299,12 +300,12 @@ export class AppModel extends Monobehiver {
// 应用 transform
if (transform) {
this.applyTransform(modelName+'_'+modelId, transform);
this.applyTransform(modelId, transform);
}
// 配置拖拽功能
if (drag) {
this.mainApp.appModelDrag?.configureDrag(modelName+'_'+modelId, drag);
this.mainApp.appModelDrag?.configureDrag(modelId, drag);
}
// 更新 GameManager 的字典
@ -338,11 +339,11 @@ export class AppModel extends Monobehiver {
// 克隆材质,确保每个模型有独立的材质
this.cloneMaterials(result.meshes, modelId);
result.meshes = this.createModelRoot(modelId, result.meshes);
this.modelDic.Set(modelId, result.meshes);
result.meshes = this.createModelRoot(modelName, result.meshes);
this.modelDic.Set(modelName+'_'+modelId, result.meshes);
// 存储元数据
this.modelMetadataDic.Set(modelId, {
this.modelMetadataDic.Set(modelName+'_'+modelId, {
modelName: modelName,
modelId: modelId,
modelUrl: modelUrl,
@ -353,12 +354,12 @@ export class AppModel extends Monobehiver {
// 应用 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);
}
}

View File

@ -268,9 +268,9 @@ export class AppModel extends Monobehiver {
*/
private async addSingle(modelName: string, modelId: string, modelUrl: string, modelControlType?: ModelControlType, drag?: DragConfig, transform?: ModelTransform): Promise<LoadResult> {
// 检查是否已存在
const existingMeshes = this.modelDic.Get(modelId);
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 };
}
@ -284,11 +284,12 @@ export class AppModel extends Monobehiver {
// 克隆材质,确保每个模型有独立的材质
this.cloneMaterials(result.meshes, modelId);
result.meshes = this.createModelRoot(modelId, result.meshes);
this.modelDic.Set(modelId, result.meshes);
// 存储模型
result.meshes = this.createModelRoot(modelName+'_'+modelId, result.meshes);
this.modelDic.Set(modelName+'_'+modelId, result.meshes);
// 存储元数据
this.modelMetadataDic.Set(modelId, {
this.modelMetadataDic.Set(modelName+'_'+modelId, {
modelName: modelName,
modelId: modelId,
modelUrl: modelUrl,
@ -299,12 +300,12 @@ export class AppModel extends Monobehiver {
// 应用 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);
}
// 更新 GameManager 的字典
@ -338,11 +339,11 @@ export class AppModel extends Monobehiver {
// 克隆材质,确保每个模型有独立的材质
this.cloneMaterials(result.meshes, modelId);
result.meshes = this.createModelRoot(modelId, result.meshes);
this.modelDic.Set(modelId, result.meshes);
result.meshes = this.createModelRoot(modelName, result.meshes);
this.modelDic.Set(modelName+'_'+modelId, result.meshes);
// 存储元数据
this.modelMetadataDic.Set(modelId, {
this.modelMetadataDic.Set(modelName+'_'+modelId, {
modelName: modelName,
modelId: modelId,
modelUrl: modelUrl,
@ -353,12 +354,12 @@ export class AppModel extends Monobehiver {
// 应用 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);
}
}