1
This commit is contained in:
51
index.js
51
index.js
@ -37,9 +37,9 @@ export const init = async (customConfig = {}) => {
|
||||
modelUrlList: [],
|
||||
env: { envPath: 'https://sdk.zguiy.com/resurces/hdr/hdr.env', intensity: 1.2, rotationY: 0.3, background: true },
|
||||
gizmo: {
|
||||
position: true,
|
||||
rotation: true,
|
||||
scale: true
|
||||
position: false,
|
||||
rotation: false,
|
||||
scale: false
|
||||
},
|
||||
outline: {
|
||||
enable: true,
|
||||
@ -67,7 +67,7 @@ export const getAutoLoadModelList = async () => {
|
||||
const models = data.data // 这就是模型列表
|
||||
|
||||
models.forEach(model => {
|
||||
console.log(model.placement_zone);
|
||||
|
||||
if (model.placement_zone) {
|
||||
const { alpha, border_color, color, show_border, thickness, walls } = model.placement_zone
|
||||
kernel.dropZone.setData({
|
||||
@ -80,8 +80,9 @@ export const getAutoLoadModelList = async () => {
|
||||
walls: walls
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
kernel.model.add({
|
||||
modelName: model.name+'_'+model.category,
|
||||
modelId: model.category,
|
||||
modelUrl: model.file_url,
|
||||
modelControlType: model.model_control_type,
|
||||
@ -148,18 +149,18 @@ export const executeEvent = async (dropzone_data, result) => {
|
||||
if (event.event_type === 'change_model') {
|
||||
console.log(event.target_data);
|
||||
|
||||
const { id, name, file_url, model_control_type, category } = event.target_data;
|
||||
console.log('替换百叶模型:', event);
|
||||
console.log('替换百叶模型类型:', category);
|
||||
const { name, file_url, model_control_type, category } = event.target_data;
|
||||
|
||||
|
||||
// 生成唯一的模型ID
|
||||
const modelId = id + '_' + Date.now();
|
||||
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');
|
||||
// 加载并放置模型
|
||||
await kernel.model.add({
|
||||
modelName: name ,
|
||||
modelId: modelId,
|
||||
modelUrl: file_url,
|
||||
modelControlType: model_control_type,
|
||||
@ -174,7 +175,7 @@ export const executeEvent = async (dropzone_data, result) => {
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`百叶模型已放置为 ${name}`);
|
||||
console.log(`百叶模型已放置为 ${name+'_'+category}`);
|
||||
}
|
||||
|
||||
if (event.event_type === 'change_color') {
|
||||
@ -202,12 +203,25 @@ export const executeEvent2 = async (result) => {
|
||||
|
||||
// 检查是否有模型更换事件
|
||||
const hasModelChange = result.data.events.some(e => e.event_type === 'change_model');
|
||||
const modelExists = await kernel.model.exists(modelId);
|
||||
console.log(modelExists);
|
||||
// 只有在需要更换模型时才清除
|
||||
|
||||
// 检查新模型是否已经存在
|
||||
let modelAlreadyExists = false;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 只有在需要更换模型且模型不存在时才清除
|
||||
if (hasModelChange && !modelAlreadyExists) {
|
||||
console.log('模型不存在,执行清除操作');
|
||||
kernel.dropZone.clearZones();
|
||||
kernel.model.removeAll();
|
||||
} else if (modelAlreadyExists) {
|
||||
console.log('模型已存在,跳过清除操作,仅更新材质');
|
||||
}
|
||||
|
||||
// 先处理所有 change_model 事件
|
||||
@ -221,7 +235,11 @@ export const executeEvent2 = async (result) => {
|
||||
};
|
||||
|
||||
const { id, name, file_url, model_control_type, category, placement_zone } = target_data;
|
||||
|
||||
// 如果模型已存在,跳过加载
|
||||
if (modelAlreadyExists) {
|
||||
console.log(`模型 ${name+'_'+category} 已存在,跳过加载`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (placement_zone) {
|
||||
const { alpha, border_color, color, show_border, thickness, walls } = placement_zone
|
||||
@ -237,12 +255,13 @@ export const executeEvent2 = async (result) => {
|
||||
|
||||
// 加载并放置模型(使用 category 作为 modelId)
|
||||
await kernel.model.add({
|
||||
modelId: category,
|
||||
modelName: name,
|
||||
modelId: category,
|
||||
modelUrl: file_url,
|
||||
modelControlType: model_control_type,
|
||||
})
|
||||
|
||||
console.log(`模型已放置为 ${name}`);
|
||||
console.log(`模型已放置为 ${name+'_'+category}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user