1
This commit is contained in:
116
index.js
116
index.js
@ -15,45 +15,58 @@ const config = {
|
||||
gizmo: {
|
||||
position: true,
|
||||
rotation: true,
|
||||
scale: false
|
||||
scale: true
|
||||
},
|
||||
outline: {
|
||||
enable: true,
|
||||
color: "#2196F3",
|
||||
thickness:1,
|
||||
occlusionStrength:0.1,
|
||||
occlusionThreshold:0.0002
|
||||
thickness: 1,
|
||||
occlusionStrength: 0.1,
|
||||
occlusionThreshold: 0.0002
|
||||
}
|
||||
};
|
||||
|
||||
kernel.init(config);
|
||||
kernel.model.add({
|
||||
modelId: "框架",
|
||||
modelUrl: "https://sdk.zguiy.com/resurces/model/框架.glb",
|
||||
modelControlType: "color"
|
||||
});
|
||||
kernel.model.add({
|
||||
modelId: "卷帘大",
|
||||
modelUrl: "https://sdk.zguiy.com/resurces/model/卷帘大.glb",
|
||||
modelControlType: "color"
|
||||
});
|
||||
kernel.model.add({
|
||||
modelId: "卷帘小",
|
||||
modelUrl: "https://sdk.zguiy.com/resurces/model/卷帘小.glb",
|
||||
modelControlType: "color"
|
||||
});
|
||||
kernel.model.add({
|
||||
modelId: "小桌",
|
||||
modelUrl: "https://sdk.zguiy.com/resurces/model/小桌.glb",
|
||||
modelControlType: "rotation"
|
||||
});
|
||||
|
||||
const response = await fetch('http://localhost:3001/api/models/auto-load/list')
|
||||
const data = await response.json()
|
||||
const models = data.data // 这就是模型列表
|
||||
console.log(models);
|
||||
|
||||
models.forEach(model => {
|
||||
kernel.model.add({
|
||||
modelId: model.id,
|
||||
modelUrl: model.file_url || `http://localhost:3001${model.file_path}`,
|
||||
modelControlType: model.model_control_type,
|
||||
});
|
||||
})
|
||||
|
||||
// kernel.model.add({
|
||||
// modelId: "框架",
|
||||
// modelUrl: "https://sdk.zguiy.com/resurces/model/框架.glb",
|
||||
// modelControlType: "color"
|
||||
// });
|
||||
// kernel.model.add({
|
||||
// modelId: "卷帘大",
|
||||
// modelUrl: "https://sdk.zguiy.com/resurces/model/卷帘大.glb",
|
||||
// modelControlType: "color"
|
||||
// });
|
||||
// kernel.model.add({
|
||||
// modelId: "配件中",
|
||||
// modelUrl: "https://sdk.zguiy.com/resurces/model/卷帘小.glb",
|
||||
// modelControlType: "color"
|
||||
// });
|
||||
// kernel.model.add({
|
||||
// modelId: "小桌",
|
||||
// modelUrl: "https://sdk.zguiy.com/resurces/model/小桌.glb",
|
||||
// modelControlType: "rotation"
|
||||
// });
|
||||
|
||||
kernel.on('model:load:progress', (data) => {
|
||||
console.log('模型加载事件', data);
|
||||
});
|
||||
|
||||
|
||||
|
||||
kernel.on('model:loaded', (data) => {
|
||||
console.log('模型加载完成', data);
|
||||
// 隐藏进度条
|
||||
@ -70,19 +83,19 @@ kernel.on('all:ready', (data) => {
|
||||
attribute: 'alpha',
|
||||
value: 0.5,
|
||||
});
|
||||
kernel.hotspot.render([
|
||||
{
|
||||
id: "h1",
|
||||
type: 'hotspot',
|
||||
name: "卷帘门",
|
||||
meshName: "Valve_01",
|
||||
icon: "https://bpic.588ku.com/element_pic/20/06/30/d1046b01afc0b9586844350d131f4daf.jpg!/fw/253/quality/90/unsharp/true/compress/true",
|
||||
offset: [25, 25, 0],
|
||||
radius: 20,
|
||||
color: "#21c7ff",
|
||||
payload: { type: "valve", code: "A" },
|
||||
},
|
||||
]);
|
||||
// kernel.hotspot.render([
|
||||
// {
|
||||
// id: "h1",
|
||||
// type: 'hotspot',
|
||||
// name: "卷帘门",
|
||||
// meshName: "Valve_01",
|
||||
// icon: "https://bpic.588ku.com/element_pic/20/06/30/d1046b01afc0b9586844350d131f4daf.jpg!/fw/253/quality/90/unsharp/true/compress/true",
|
||||
// position: [25, 25, 0],
|
||||
// radius: 20,
|
||||
// color: "#21c7ff",
|
||||
// payload: { type: "valve", code: "A" },
|
||||
// },
|
||||
// ]);
|
||||
});
|
||||
|
||||
|
||||
@ -150,17 +163,26 @@ window.getCurrentPickedMesh = () => currentPickedMesh;
|
||||
// 暴露 kernel 到全局,方便调试
|
||||
|
||||
|
||||
kernel.on('hotspot:click', (data) => {
|
||||
console.log('热点被点击:', data);
|
||||
const { id, name } = data
|
||||
if (name === "卷帘门") {
|
||||
kernel.door.toggle({ upY: 28, downY: 0, speed: 12 });
|
||||
kernel.on('hotspot:click', (event) => {
|
||||
console.log('热点被点击:', event);
|
||||
|
||||
// Y轴剖切,只作用于卷帘门网格,保留下方,剖掉上方
|
||||
const clipHeight = 28; // 调整这个值找到合适的剖切高度
|
||||
console.log('设置剖切:', clipHeight);
|
||||
kernel.clipping.setY(clipHeight, true, ['Box005.001', 'Box006.001']);
|
||||
const { id, name, payload } = event;
|
||||
|
||||
if (payload && payload.skus && payload.skus.length > 0) {
|
||||
console.log('热点关联的SKU列表:', payload.skus);
|
||||
// 这里可以根据 SKU 列表做进一步处理,比如显示产品信息
|
||||
} else {
|
||||
console.log('该热点没有关联SKU');
|
||||
}
|
||||
|
||||
// if (name === "卷帘门") {
|
||||
// kernel.door.toggle({ upY: 28, downY: 0, speed: 12 });
|
||||
|
||||
// // Y轴剖切,只作用于卷帘门网格,保留下方,剖掉上方
|
||||
// const clipHeight = 28; // 调整这个值找到合适的剖切高度
|
||||
// console.log('设置剖切:', clipHeight);
|
||||
// kernel.clipping.setY(clipHeight, true, ['Box005.001', 'Box006.001']);
|
||||
// }
|
||||
});
|
||||
|
||||
window.kernel = kernel;
|
||||
|
||||
Reference in New Issue
Block a user