1
This commit is contained in:
118
index.html
118
index.html
@ -516,58 +516,10 @@
|
||||
|
||||
await hotspotRequest();
|
||||
})
|
||||
let sku = ""
|
||||
const skuToFunc = async (currentText) => {
|
||||
// 根据 SKU 查询配置和事件
|
||||
try {
|
||||
const response = await fetch(`http://localhost:3000/api/product-configs/by-sku/${currentText}`);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.code === 200 && result.data) {
|
||||
console.log('SKU配置数据:', result.data);
|
||||
console.log('关联事件:', result.data.events);
|
||||
placementWall(1);
|
||||
// 使用 for...of 循环以支持 await
|
||||
for (const event of result.data.events) {
|
||||
if (event.event_type === 'change_model') {
|
||||
const { file_url, model_control_type, category } = event.target_data;
|
||||
console.log('替换百叶模型:', event);
|
||||
|
||||
await kernel.model.replace({
|
||||
modelId: category,
|
||||
modelUrl: file_url,
|
||||
modelControlType: model_control_type,
|
||||
drag: {
|
||||
enable: true,
|
||||
axis: 'x',
|
||||
step: 0.1,
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`百叶模型已替换为 ${currentText}`);
|
||||
}
|
||||
|
||||
if (event.event_type === 'change_color') {
|
||||
const materialName = event.material_name;
|
||||
const { color, color_map_url, normal_map_url } = event.target_data;
|
||||
console.log('替换百叶模型颜色:', event.target_data);
|
||||
|
||||
kernel.material.apply({
|
||||
target: materialName,
|
||||
albedoColor: color,
|
||||
albedoTexture: color_map_url,
|
||||
normalMap: normal_map_url,
|
||||
});
|
||||
|
||||
console.log(`百叶模型颜色已替换为 ${color}`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log(`未查询到数据`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`查询SKU配置或替换模型失败:`, error);
|
||||
}
|
||||
|
||||
sku = currentText;
|
||||
placementWall(1);
|
||||
|
||||
}
|
||||
|
||||
@ -899,12 +851,64 @@
|
||||
|
||||
|
||||
// 监听放置区域点击事件
|
||||
kernel.on('dropzone:click', (data) => {
|
||||
console.log('点击了放置区域:', data);
|
||||
console.log('中心点:', data.center);
|
||||
console.log('宽度:', data.width);
|
||||
console.log('高度:', data.height);
|
||||
console.log('法线:', data.normal);
|
||||
kernel.on('dropzone:click', async (dropzone_data) => {
|
||||
const { position,rotation } = dropzone_data.transform;
|
||||
|
||||
// 将模型放置到该区域
|
||||
try {
|
||||
const response = await fetch(`http://localhost:3000/api/product-configs/by-sku/${sku}`);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.code === 200 && result.data) {
|
||||
console.log('SKU配置数据:', result.data);
|
||||
console.log('关联事件:', result.data.events);
|
||||
|
||||
// 使用 for...of 循环以支持 await
|
||||
for (const event of result.data.events) {
|
||||
if (event.event_type === 'change_model') {
|
||||
const { file_url, model_control_type, category } = event.target_data;
|
||||
console.log('替换百叶模型:', event);
|
||||
|
||||
await kernel.model.replace({
|
||||
modelId: category,
|
||||
modelUrl: file_url,
|
||||
modelControlType: model_control_type,
|
||||
drag: {
|
||||
enable: true,
|
||||
axis: 'x',
|
||||
step: 0.1,
|
||||
}
|
||||
,
|
||||
transform: {
|
||||
position: position,
|
||||
rotation: rotation,
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`百叶模型已替换为 ${currentText}`);
|
||||
}
|
||||
|
||||
if (event.event_type === 'change_color') {
|
||||
const materialName = event.material_name;
|
||||
const { color, color_map_url, normal_map_url } = event.target_data;
|
||||
console.log('替换百叶模型颜色:', event.target_data);
|
||||
|
||||
kernel.material.apply({
|
||||
target: materialName,
|
||||
albedoColor: color,
|
||||
albedoTexture: color_map_url,
|
||||
normalMap: normal_map_url,
|
||||
});
|
||||
|
||||
console.log(`百叶模型颜色已替换为 ${color}`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log(`未查询到数据`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`查询SKU配置或替换模型失败:`, error);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user