This commit is contained in:
2026-06-04 16:15:21 +08:00
parent 7676364229
commit bef0bf527b
34 changed files with 158 additions and 309 deletions

View File

@ -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}`;
};

View File

@ -366,7 +366,7 @@
<div class="option-group">
<button class="option-btn" data-option="size-1">SPF111S1013W</button>
<button class="option-btn" data-option="size-2">SPF111S1013TA</button>
<button class="option-btn" data-option="size-3">SPF111S1013C</button>
<button class="option-btn" data-option="size-3">SPF111SEM13</button>
</div>
</div>
</div>
@ -410,13 +410,20 @@
<!-- 80 系列 -->
<div class="series-divider">----- 80 -----</div>
<div class="option-group">
<button class="option-btn" data-option="size-4">SPF80S1020C</button>
<button class="option-btn" data-option="size-4">SPF80S1020L</button>
</div>
<!-- 111 系列 -->
<div class="series-divider">----- 111 -----</div>
<div class="option-group">
<button class="option-btn" data-option="size-7">SPF111S1020C</button>
</div>
<!-- vs 系列 -->
<div class="series-divider">----- vs -----</div>
<div class="option-group">
<button class="option-btn" data-option="size-7">SPF111S1020PILLAR4PCS</button>
</div>
</div>
</div>
</div>
@ -466,8 +473,8 @@
</div>
<div class="category-content expanded">
<div class="option-group">
<button class="option-btn" data-option="color-3">SPFPDS10FTW</button>
<button class="option-btn" data-option="color-4">SPFPDS10FTC</button>
<button class="option-btn" data-option="color-3">SPFPCD10FTW</button>
<button class="option-btn" data-option="color-4">SPFDPH10FTA</button>
</div>
</div>
</div>
@ -870,7 +877,7 @@
console.log(kernel);
// 存储当前选中的材质名和网格
var currentMaterialName = '';
var currentPickedMesh = null;