1
This commit is contained in:
40
index.js
40
index.js
@ -140,7 +140,7 @@ export const executeEvent = async (dropzone_data, result) => {
|
||||
|
||||
if (event.event_type === 'change_color') {
|
||||
const materialName = event.material_name;
|
||||
const { color, color_map_url, normal_map_url } = event.target_data;
|
||||
const { color, color_map_url, normal_map_url, metallic, roughness } = event.target_data;
|
||||
console.log('替换百叶模型颜色:', event.target_data);
|
||||
|
||||
kernel.material.apply({
|
||||
@ -148,6 +148,8 @@ export const executeEvent = async (dropzone_data, result) => {
|
||||
albedoColor: color,
|
||||
albedoTexture: color_map_url,
|
||||
normalMap: normal_map_url,
|
||||
metallic: metallic,
|
||||
roughness: roughness
|
||||
});
|
||||
|
||||
console.log(`百叶模型颜色已替换为 ${color}`);
|
||||
@ -155,22 +157,30 @@ export const executeEvent = async (dropzone_data, result) => {
|
||||
}
|
||||
}
|
||||
|
||||
//换棚子
|
||||
export const executeEvent2 = async (result) => {
|
||||
kernel.dropZone.clearZones();
|
||||
kernel.model.removeAll();
|
||||
// 检查是否有模型更换事件
|
||||
const hasModelChange = result.data.events.some(e => e.event_type === 'change_model');
|
||||
|
||||
// 只有在需要更换模型时才清除
|
||||
if (hasModelChange) {
|
||||
kernel.dropZone.clearZones();
|
||||
kernel.model.removeAll();
|
||||
}
|
||||
|
||||
// 先处理所有 change_model 事件
|
||||
for (const event of result.data.events) {
|
||||
const { target_data } = event;
|
||||
if (event.event_type === 'change_model') {
|
||||
const { target_data } = event;
|
||||
console.log(event.target_data);
|
||||
|
||||
const { id, name, file_url, model_control_type, category, placement_zone } = event.target_data;
|
||||
const { id, name, file_url, model_control_type, category, placement_zone } = target_data;
|
||||
console.log('替换百叶模型:', event);
|
||||
console.log('替换百叶模型类型:', category);
|
||||
|
||||
if (placement_zone) {
|
||||
const { alpha, border_color, color, show_border, thickness, walls } = placement_zone
|
||||
kernel.dropZone.setData({
|
||||
|
||||
color: color,
|
||||
alpha: +alpha,
|
||||
thickness: thickness,
|
||||
@ -179,19 +189,23 @@ export const executeEvent2 = async (result) => {
|
||||
walls: walls
|
||||
});
|
||||
}
|
||||
// 加载并放置模型
|
||||
await kernel.model.replace({
|
||||
modelId: target_data.category,
|
||||
modelUrl: target_data.file_url,
|
||||
modelControlType: target_data.model_control_type,
|
||||
|
||||
// 加载并放置模型(使用 category 作为 modelId)
|
||||
await kernel.model.add({
|
||||
modelId: category,
|
||||
modelUrl: file_url,
|
||||
modelControlType: model_control_type,
|
||||
})
|
||||
|
||||
console.log(`百叶模型已放置为 ${name}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 等待模型加载完成后,再处理 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 } = event.target_data;
|
||||
const { color, color_map_url, normal_map_url, metallic, roughness } = event.target_data;
|
||||
console.log('替换百叶模型颜色:', event.target_data);
|
||||
|
||||
kernel.material.apply({
|
||||
@ -199,6 +213,8 @@ export const executeEvent2 = async (result) => {
|
||||
albedoColor: color,
|
||||
albedoTexture: color_map_url,
|
||||
normalMap: normal_map_url,
|
||||
metallic: metallic,
|
||||
roughness: roughness
|
||||
});
|
||||
|
||||
console.log(`百叶模型颜色已替换为 ${color}`);
|
||||
|
||||
Reference in New Issue
Block a user