新问题:切换尺寸,在放置配件会重叠
This commit is contained in:
10
index.js
10
index.js
@ -156,8 +156,8 @@ export const executeEvent = async (dropzone_data, result) => {
|
|||||||
const modelId = Date.now();
|
const modelId = Date.now();
|
||||||
|
|
||||||
// 先记录模型放置(会自动处理替换逻辑)
|
// 先记录模型放置(会自动处理替换逻辑)
|
||||||
kernel.dropZone.recordModelPlacement(wallName, index, modelId);
|
kernel.dropZone.recordModelPlacement(wallName, index, name + '_' + modelId);
|
||||||
console.log(Math.abs(rotation.y - 90), Math.abs(rotation.y - 90) > 5 ? 'x' : 'z');
|
console.log(name + '_' + modelId);
|
||||||
// 加载并放置模型
|
// 加载并放置模型
|
||||||
await kernel.model.add({
|
await kernel.model.add({
|
||||||
modelName: name,
|
modelName: name,
|
||||||
@ -210,15 +210,15 @@ export const executeEvent2 = async (result) => {
|
|||||||
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(category);
|
modelAlreadyExists = kernel.model.exists(name + '_' + category);
|
||||||
console.log(`检查模型 ${name + '_' + category} 是否存在:`, modelAlreadyExists);
|
console.log(`检查模型 ${name + '_' + category} 是否存在:`, modelAlreadyExists);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
kernel.dropZone.clearZones();
|
||||||
// 只有在需要更换模型且模型不存在时才清除
|
// 只有在需要更换模型且模型不存在时才清除
|
||||||
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) {
|
||||||
console.log('模型已存在,跳过清除操作,仅更新材质');
|
console.log('模型已存在,跳过清除操作,仅更新材质');
|
||||||
|
|||||||
@ -270,7 +270,7 @@ export class AppModel extends Monobehiver {
|
|||||||
// 检查是否已存在
|
// 检查是否已存在
|
||||||
const existingMeshes = this.modelDic.Get(modelName+'_'+modelId);
|
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 };
|
||||||
}
|
}
|
||||||
@ -284,6 +284,7 @@ export class AppModel extends Monobehiver {
|
|||||||
// 克隆材质,确保每个模型有独立的材质
|
// 克隆材质,确保每个模型有独立的材质
|
||||||
this.cloneMaterials(result.meshes, modelId);
|
this.cloneMaterials(result.meshes, modelId);
|
||||||
|
|
||||||
|
// 存储模型
|
||||||
result.meshes = this.createModelRoot(modelName+'_'+modelId, result.meshes);
|
result.meshes = this.createModelRoot(modelName+'_'+modelId, result.meshes);
|
||||||
this.modelDic.Set(modelName+'_'+modelId, result.meshes);
|
this.modelDic.Set(modelName+'_'+modelId, result.meshes);
|
||||||
|
|
||||||
@ -299,12 +300,12 @@ export class AppModel extends Monobehiver {
|
|||||||
|
|
||||||
// 应用 transform
|
// 应用 transform
|
||||||
if (transform) {
|
if (transform) {
|
||||||
this.applyTransform(modelName+'_'+modelId, transform);
|
this.applyTransform(modelId, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 配置拖拽功能
|
// 配置拖拽功能
|
||||||
if (drag) {
|
if (drag) {
|
||||||
this.mainApp.appModelDrag?.configureDrag(modelName+'_'+modelId, drag);
|
this.mainApp.appModelDrag?.configureDrag(modelId, drag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新 GameManager 的字典
|
// 更新 GameManager 的字典
|
||||||
@ -338,11 +339,11 @@ export class AppModel extends Monobehiver {
|
|||||||
// 克隆材质,确保每个模型有独立的材质
|
// 克隆材质,确保每个模型有独立的材质
|
||||||
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: modelName,
|
modelName: modelName,
|
||||||
modelId: modelId,
|
modelId: modelId,
|
||||||
modelUrl: modelUrl,
|
modelUrl: modelUrl,
|
||||||
@ -353,12 +354,12 @@ export class AppModel extends Monobehiver {
|
|||||||
|
|
||||||
// 应用 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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> {
|
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()) {
|
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 };
|
||||||
}
|
}
|
||||||
@ -284,11 +284,12 @@ export class AppModel extends Monobehiver {
|
|||||||
// 克隆材质,确保每个模型有独立的材质
|
// 克隆材质,确保每个模型有独立的材质
|
||||||
this.cloneMaterials(result.meshes, modelId);
|
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,
|
modelName: modelName,
|
||||||
modelId: modelId,
|
modelId: modelId,
|
||||||
modelUrl: modelUrl,
|
modelUrl: modelUrl,
|
||||||
@ -299,12 +300,12 @@ export class AppModel extends Monobehiver {
|
|||||||
|
|
||||||
// 应用 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新 GameManager 的字典
|
// 更新 GameManager 的字典
|
||||||
@ -338,11 +339,11 @@ export class AppModel extends Monobehiver {
|
|||||||
// 克隆材质,确保每个模型有独立的材质
|
// 克隆材质,确保每个模型有独立的材质
|
||||||
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: modelName,
|
modelName: modelName,
|
||||||
modelId: modelId,
|
modelId: modelId,
|
||||||
modelUrl: modelUrl,
|
modelUrl: modelUrl,
|
||||||
@ -353,12 +354,12 @@ export class AppModel extends Monobehiver {
|
|||||||
|
|
||||||
// 应用 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user