新问题:切换尺寸,在放置配件会重叠
This commit is contained in:
28
index.js
28
index.js
@ -82,7 +82,7 @@ export const getAutoLoadModelList = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kernel.model.add({
|
kernel.model.add({
|
||||||
modelName: model.name+'_'+model.category,
|
modelName: model.name + '_' + model.category,
|
||||||
modelId: model.category,
|
modelId: model.category,
|
||||||
modelUrl: model.file_url,
|
modelUrl: model.file_url,
|
||||||
modelControlType: model.model_control_type,
|
modelControlType: model.model_control_type,
|
||||||
@ -156,11 +156,11 @@ 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,
|
||||||
modelId: modelId,
|
modelId: modelId,
|
||||||
modelUrl: file_url,
|
modelUrl: file_url,
|
||||||
modelControlType: model_control_type,
|
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') {
|
if (event.event_type === 'change_color') {
|
||||||
@ -209,17 +209,17 @@ export const executeEvent2 = async (result) => {
|
|||||||
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(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('模型已存在,跳过清除操作,仅更新材质');
|
||||||
}
|
}
|
||||||
@ -237,7 +237,7 @@ export const executeEvent2 = async (result) => {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,12 +256,12 @@ export const executeEvent2 = async (result) => {
|
|||||||
// 加载并放置模型(使用 category 作为 modelId)
|
// 加载并放置模型(使用 category 作为 modelId)
|
||||||
await kernel.model.add({
|
await kernel.model.add({
|
||||||
modelName: name,
|
modelName: name,
|
||||||
modelId: category,
|
modelId: category,
|
||||||
modelUrl: file_url,
|
modelUrl: file_url,
|
||||||
modelControlType: model_control_type,
|
modelControlType: model_control_type,
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(`模型已放置为 ${name+'_'+category}`);
|
console.log(`模型已放置为 ${name + '_' + category}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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