1
This commit is contained in:
16
index.js
16
index.js
@ -119,6 +119,8 @@ export const getPlacementZone = async (sku) => {
|
||||
|
||||
//执行事件
|
||||
export const getEvent = async (dropzone_data, sku) => {
|
||||
console.log(sku);
|
||||
|
||||
// 将模型放置到该区域
|
||||
try {
|
||||
const response = await fetch(apiConfig.getApiUrl(`/api/product-configs/by-sku/${sku}`));
|
||||
@ -145,20 +147,16 @@ export const executeEvent = async (dropzone_data, result) => {
|
||||
const { wallName, index, transform } = dropzone_data;
|
||||
const { position, rotation } = transform;
|
||||
|
||||
// 第一次循环:处理 change_model
|
||||
for (const event of result.data.events) {
|
||||
if (event.event_type === 'change_model') {
|
||||
console.log(event.target_data);
|
||||
|
||||
const { name, file_url, model_control_type, category } = event.target_data;
|
||||
|
||||
|
||||
// 生成唯一的模型ID
|
||||
const modelId = Date.now();
|
||||
|
||||
// 先记录模型放置(会自动处理替换逻辑)
|
||||
kernel.dropZone.recordModelPlacement(wallName, index, name + '_' + modelId);
|
||||
console.log(name + '_' + modelId);
|
||||
// 加载并放置模型
|
||||
|
||||
await kernel.model.add({
|
||||
modelName: name,
|
||||
modelId: modelId,
|
||||
@ -175,13 +173,15 @@ export const executeEvent = async (dropzone_data, result) => {
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`百叶模型已放置为 ${name + '_' + category}`);
|
||||
console.log(`百叶模型已放置为 ${name + '_' + modelId}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 第二次循环:处理 change_color(此时模型已加载完成)
|
||||
for (const event of result.data.events) {
|
||||
if (event.event_type === 'change_color') {
|
||||
const materialName = event.material_name;
|
||||
const { color, color_map_url, normal_map_url, metallic, roughness } = event.target_data;
|
||||
console.log('替换百叶模型颜色:', event.target_data);
|
||||
|
||||
kernel.material.apply({
|
||||
target: materialName,
|
||||
|
||||
Reference in New Issue
Block a user