1
This commit is contained in:
@ -35,7 +35,7 @@ const init = async (customConfig = {}) => {
|
||||
const defaultConfig = {
|
||||
container: document.querySelector('#renderDom'),
|
||||
modelUrlList: [],
|
||||
env: { envPath: 'https://cdn.files.zguiy.com/zt/environment.env', intensity: 1.2, rotationY: 0.3, background: false },
|
||||
env: { envPath: 'https://cdn.files.zguiy.com/zt/environment.env', intensity: 1.5, rotationY: 0.3, background: false },
|
||||
gizmo: {
|
||||
position: false,
|
||||
rotation: false,
|
||||
@ -53,6 +53,7 @@ const init = async (customConfig = {}) => {
|
||||
// 合并用户自定义配置
|
||||
const config = { ...defaultConfig, ...customConfig };
|
||||
kernel.init(config);
|
||||
await getAutoLoadModelList()
|
||||
}
|
||||
|
||||
//初始化加载模型
|
||||
@ -97,10 +98,12 @@ const getPlacementZone = async (sku) => {
|
||||
let division_include = []
|
||||
// 同时包含10和13
|
||||
const only10_13 = /(?=.*10)(?=.*13)/.test(pergolaSku)
|
||||
// 只包含10 无13 无12
|
||||
const only10 = /(?=.*10)(?!.*13)(?!.*12)/.test(pergolaSku)
|
||||
// 只包含10 无13 无12 无20
|
||||
const only10 = /(?=.*10)(?!.*13)(?!.*12)(?!.*20)/.test(pergolaSku)
|
||||
// 同时包含10和12
|
||||
const only10_12 = /(?=.*10)(?=.*12)/.test(pergolaSku)
|
||||
// 同时包含10和20
|
||||
const only10_20 = /(?=.*10)(?=.*20)/.test(pergolaSku)
|
||||
|
||||
// 1. 只要字符串里包含 10,就返回 true
|
||||
const has10 = /10/.test(sku);
|
||||
@ -131,6 +134,25 @@ const getPlacementZone = async (sku) => {
|
||||
if (only10_12 && has10) {
|
||||
division_include.push('左', '右')
|
||||
}
|
||||
//棚子同时包10和20的并且含配件是10
|
||||
if (only10_20 && has10) {
|
||||
|
||||
if (pergolaSku === "SPF111S1020PILLAR4PCS") {
|
||||
division_include.push('左', '右')
|
||||
}
|
||||
else {
|
||||
division_include.push('前', '后', '左', '右', "前1", "后1", "前2", "后2")
|
||||
}
|
||||
}
|
||||
|
||||
//棚子同时包10和20的并且含配件是13
|
||||
if (only10_20 && has13) {
|
||||
|
||||
if (pergolaSku === "SPF111S1020PILLAR4PCS") {
|
||||
division_include.push('前', '后')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const response = await fetch(getApiUrl(`/api/product-configs/by-sku/${sku}`));
|
||||
const result = await response.json();
|
||||
@ -181,48 +203,48 @@ const getEvent = async (dropzone_data, sku) => {
|
||||
|
||||
//点击放置区域执行事件 一般是换配件
|
||||
const executeEvent = async (dropzone_data, result, sku) => {
|
||||
const kernel = getKernel();
|
||||
|
||||
const { wallName, index, transform } = dropzone_data;
|
||||
const { position, rotation } = transform;
|
||||
|
||||
let modelId = null; // 在外部声明,用于在两个循环之间传递
|
||||
let modelName = null;
|
||||
let pergolaSku = null; // 用于存储棚子的 SKU
|
||||
|
||||
// 第一次循环:处理 change_model
|
||||
for (const event of result.data.events) {
|
||||
if (event.event_type === 'change_model') {
|
||||
const { name, file_url, model_control_type, category } = event.target_data;
|
||||
const kernel = getKernel();
|
||||
|
||||
// 生成唯一的模型ID
|
||||
modelId = Date.now();
|
||||
modelName = name;
|
||||
kernel.dropZone.recordModelPlacement(wallName, index, name + '_' + modelId);
|
||||
|
||||
await kernel.model.add({
|
||||
modelName: name,
|
||||
modelId: modelId,
|
||||
modelUrl: file_url,
|
||||
modelControlType: model_control_type,
|
||||
drag: {
|
||||
enable: true,
|
||||
axis: rotation.y === 0 || rotation.y === 180 ? 'x' : 'z',
|
||||
step: 0.1,
|
||||
snapToZone: true, // 拖拽吸附到最近的分割区域
|
||||
returnWhenOutOfBounds: true, // 拖拽到区域外时返回原位置
|
||||
handleOccupiedZone: true, // 处理已占用区域(false=允许重叠)
|
||||
occupiedZoneAction: 'replace' // 当开关3=true时的行为:'return'=返回原位置,'replace'=替换
|
||||
},
|
||||
transform: {
|
||||
position: position,
|
||||
rotation: rotation,
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`百叶模型已放置为 ${name + '_' + modelId}`);
|
||||
}
|
||||
}
|
||||
const { wallName, index, transform } = dropzone_data;
|
||||
const { position, rotation } = transform;
|
||||
|
||||
let modelId = null; // 在外部声明,用于在两个循环之间传递
|
||||
let modelName = null;
|
||||
let pergolaSku = null; // 用于存储棚子的 SKU
|
||||
|
||||
// 第一次循环:处理 change_model
|
||||
for (const event of result.data.events) {
|
||||
if (event.event_type === 'change_model') {
|
||||
const { name, file_url, model_control_type, category } = event.target_data;
|
||||
|
||||
// 生成唯一的模型ID
|
||||
modelId = Date.now();
|
||||
modelName = name;
|
||||
kernel.dropZone.recordModelPlacement(wallName, index, name + '_' + modelId);
|
||||
|
||||
await kernel.model.add({
|
||||
modelName: name,
|
||||
modelId: modelId,
|
||||
modelUrl: file_url,
|
||||
modelControlType: model_control_type,
|
||||
drag: {
|
||||
enable: true,
|
||||
axis: rotation.y === 0 || rotation.y === 180 ? 'x' : 'z',
|
||||
step: 0.1,
|
||||
snapToZone: true, // 拖拽吸附到最近的分割区域
|
||||
returnWhenOutOfBounds: true, // 拖拽到区域外时返回原位置
|
||||
handleOccupiedZone: true, // 处理已占用区域(false=允许重叠)
|
||||
occupiedZoneAction: 'replace' // 当开关3=true时的行为:'return'=返回原位置,'replace'=替换
|
||||
},
|
||||
transform: {
|
||||
position: position,
|
||||
rotation: rotation,
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`百叶模型已放置为 ${name + '_' + modelId}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 第二次循环:处理 change_color(此时模型已加载完成)
|
||||
for (const event of result.data.events) {
|
||||
@ -422,8 +444,8 @@ const getProductConfig = async (sku) => {
|
||||
}
|
||||
|
||||
// API 配置
|
||||
//const API_BASE_URL = 'https://ztserver.zguiy.com';
|
||||
const API_BASE_URL = 'http://localhost:26517';
|
||||
const API_BASE_URL = 'https://ztserver.zguiy.com';
|
||||
//const API_BASE_URL = 'http://localhost:26517';
|
||||
const getApiUrl = (path) => {
|
||||
return `${API_BASE_URL}${path}`;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user