1
This commit is contained in:
122
index.html
122
index.html
@ -911,126 +911,8 @@
|
||||
|
||||
// 生成放置区域按钮事件
|
||||
let dropZoneVisible = false;
|
||||
document.getElementById('dropzone-btn').addEventListener('click', async () => {
|
||||
|
||||
const { wallName, index } = dropzone_data;
|
||||
|
||||
// 先正常放置模型
|
||||
await window.AppLogic.getEvent(dropzone_data, sku);
|
||||
|
||||
// 检查该墙面是否已满
|
||||
const zones = kernel.dropZone.getPlacementZones();
|
||||
const wallZones = zones.filter(z => z.wallName === wallName);
|
||||
|
||||
// 获取该墙面已放置的模型
|
||||
const placedModels = kernel.dropZone.getPlacedModels(wallName);
|
||||
|
||||
// 如果该墙面所有区域都已占用
|
||||
if (placedModels.length === wallZones.length) {
|
||||
console.log(`${wallName} 墙面已满,自动排列模型`);
|
||||
|
||||
// 按区域索引排序
|
||||
const sortedZones = wallZones.sort((a, b) => a.index - b.index);
|
||||
|
||||
// 重新排列模型到对应区域
|
||||
placedModels.forEach((model, idx) => {
|
||||
const targetZone = sortedZones[idx];
|
||||
const { position, rotation } = targetZone.transform;
|
||||
|
||||
// 移动模型到目标位置
|
||||
kernel.transform.position({
|
||||
modelId: model.modelId,
|
||||
vector3: position
|
||||
});
|
||||
|
||||
kernel.transform.rotation({
|
||||
modelId: model.modelId,
|
||||
vector3: rotation
|
||||
});
|
||||
|
||||
// 禁用该模型的拖拽
|
||||
kernel.model.setDragEnabled(model.modelId, false);
|
||||
});
|
||||
|
||||
console.log('模型已自动排列并禁用拖拽');
|
||||
}
|
||||
// if (!dropZoneVisible) {
|
||||
// // 更新按钮文字
|
||||
// document.getElementById('dropzone-btn').textContent = '隐藏放置区域';
|
||||
// console.log('已生成并显示放置区域');
|
||||
// } else {
|
||||
// // 隐藏放置区域
|
||||
// kernel.dropZone.hideAll();
|
||||
// dropZoneVisible = false;
|
||||
|
||||
// // 更新按钮文字
|
||||
// document.getElementById('dropzone-btn').textContent = '生成放置区域';
|
||||
// console.log('已隐藏放置区域');
|
||||
// }
|
||||
});
|
||||
|
||||
// 初始化放置区域配置数据(只需设置一次)
|
||||
const initPlacementZoneConfig = (divisions = 3) => {
|
||||
|
||||
// 只清除旧的放置区域网格,不清除模型
|
||||
kernel.dropZone.clearZones();
|
||||
// 调整 baseY 来控制整体高度(正数向上,负数向下)
|
||||
const baseY = 0.09; // 修改这个值来调整整体高度
|
||||
const height = 2.27;
|
||||
// 调整 offset 来控制每个面向外或向内的偏移
|
||||
// 正数 = 向外移动,负数 = 向内移动
|
||||
const wallOffset = 0; // 修改这个值来调整墙面偏移
|
||||
|
||||
kernel.dropZone.setData({
|
||||
|
||||
color: "#21c7ff",
|
||||
alpha: 0.3,
|
||||
thickness: 2,
|
||||
showBorder: true,
|
||||
borderColor: "#ffffff",
|
||||
walls: [
|
||||
{
|
||||
name: 'front',
|
||||
startPoint: [-1.45, baseY, -1.45],
|
||||
endPoint: [1.45, baseY, -1.45],
|
||||
height: height,
|
||||
divisions: divisions,
|
||||
offset: wallOffset // 向外或向内偏移
|
||||
},
|
||||
|
||||
{
|
||||
name: 'back',
|
||||
startPoint: [1.45, baseY, 1.45],
|
||||
endPoint: [-1.45, baseY, 1.45],
|
||||
height: height,
|
||||
divisions: divisions,
|
||||
offset: wallOffset
|
||||
},
|
||||
{
|
||||
name: 'left',
|
||||
startPoint: [-1.45, baseY, 1.45],
|
||||
endPoint: [-1.45, baseY, -1.45],
|
||||
height: height,
|
||||
divisions: divisions,
|
||||
offset: wallOffset
|
||||
},
|
||||
{
|
||||
name: 'right',
|
||||
startPoint: [1.45, baseY, -1.45],
|
||||
endPoint: [1.45, baseY, 1.45],
|
||||
height: height,
|
||||
divisions: divisions,
|
||||
offset: wallOffset
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
kernel.dropZone.generateDropZones(divisions);
|
||||
// 显示放置区域
|
||||
kernel.dropZone.show();
|
||||
dropZoneVisible = true;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 监听放置区域点击事件
|
||||
kernel.on('dropzone:click', async (dropzone_data) => {
|
||||
@ -1038,8 +920,6 @@
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// 存储当前选中的材质名和网格
|
||||
let currentMaterialName = '';
|
||||
let currentPickedMesh = null;
|
||||
|
||||
Reference in New Issue
Block a user