1
This commit is contained in:
@ -192,6 +192,17 @@ const executeEvent = async (dropzone_data, result) => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查模型是否已存在
|
||||
* @param {string} modelId - 模型ID
|
||||
* @returns {boolean} 模型是否存在
|
||||
*/
|
||||
const isModelExists = (modelId) => {
|
||||
const kernel = getKernel();
|
||||
// 调用 SDK 的 API 检查模型是否存在
|
||||
return kernel.model.exists(modelId);
|
||||
}
|
||||
|
||||
//换棚子
|
||||
const executeEvent2 = async (result) => {
|
||||
const kernel = getKernel();
|
||||
@ -199,10 +210,24 @@ const executeEvent2 = async (result) => {
|
||||
// 检查是否有模型更换事件
|
||||
const hasModelChange = result.data.events.some(e => e.event_type === 'change_model');
|
||||
|
||||
// 只有在需要更换模型时才清除
|
||||
// 检查新模型是否已经存在
|
||||
let modelAlreadyExists = false;
|
||||
if (hasModelChange) {
|
||||
const firstModelEvent = result.data.events.find(e => e.event_type === 'change_model');
|
||||
if (firstModelEvent) {
|
||||
const { category } = firstModelEvent.target_data;
|
||||
modelAlreadyExists = isModelExists(category);
|
||||
console.log(`检查模型 ${category} 是否存在:`, modelAlreadyExists);
|
||||
}
|
||||
}
|
||||
|
||||
// 只有在需要更换模型且模型不存在时才清除
|
||||
if (hasModelChange && !modelAlreadyExists) {
|
||||
console.log('模型不存在,执行清除操作');
|
||||
kernel.dropZone.clearZones();
|
||||
kernel.model.removeAll();
|
||||
} else if (modelAlreadyExists) {
|
||||
console.log('模型已存在,跳过清除操作,仅更新材质');
|
||||
}
|
||||
|
||||
// 先处理所有 change_model 事件
|
||||
@ -219,6 +244,12 @@ const executeEvent2 = async (result) => {
|
||||
console.log('替换百叶模型:', event);
|
||||
console.log('替换百叶模型类型:', category);
|
||||
|
||||
// 如果模型已存在,跳过加载
|
||||
if (modelAlreadyExists) {
|
||||
console.log(`模型 ${category} 已存在,跳过加载`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (placement_zone) {
|
||||
const { alpha, border_color, color, show_border, thickness, walls } = placement_zone
|
||||
kernel.dropZone.setData({
|
||||
@ -338,5 +369,6 @@ window.AppLogic = {
|
||||
executeEvent,
|
||||
executeEvent2,
|
||||
getHotspot,
|
||||
getProductConfig
|
||||
getProductConfig,
|
||||
isModelExists // 暴露检查模型是否存在的API
|
||||
};
|
||||
Reference in New Issue
Block a user