1
This commit is contained in:
@ -135,27 +135,25 @@ const getEvent = async (dropzone_data, sku) => {
|
||||
|
||||
//点击放置区域执行事件
|
||||
const executeEvent = async (dropzone_data, result) => {
|
||||
const kernel = getKernel();
|
||||
const kernel = getKernel();
|
||||
|
||||
const { wallName, index, transform } = dropzone_data;
|
||||
const { position, rotation } = transform;
|
||||
|
||||
let modelId = null; // 在外部声明,用于在两个循环之间传递
|
||||
let modelName = null;
|
||||
// 第一次循环:处理 change_model
|
||||
for (const event of result.data.events) {
|
||||
if (event.event_type === 'change_model') {
|
||||
console.log(event.target_data);
|
||||
|
||||
const { id, name, file_url, model_control_type, category } = event.target_data;
|
||||
console.log('替换百叶模型:', event);
|
||||
console.log('替换百叶模型类型:', category);
|
||||
const { name, file_url, model_control_type, category } = event.target_data;
|
||||
|
||||
// 生成唯一的模型ID
|
||||
const modelId = id + '_' + Date.now();
|
||||
modelId = Date.now();
|
||||
modelName = name;
|
||||
kernel.dropZone.recordModelPlacement(wallName, index, name + '_' + modelId);
|
||||
|
||||
// 先记录模型放置(会自动处理替换逻辑)
|
||||
kernel.dropZone.recordModelPlacement(wallName, index, modelId);
|
||||
console.log(Math.abs(rotation.y - 90), Math.abs(rotation.y - 90) > 5 ? 'x' : 'z');
|
||||
// 加载并放置模型
|
||||
await kernel.model.add({
|
||||
modelName: name,
|
||||
modelId: modelId,
|
||||
modelUrl: file_url,
|
||||
modelControlType: model_control_type,
|
||||
@ -170,21 +168,24 @@ const executeEvent = async (dropzone_data, result) => {
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`百叶模型已放置为 ${name}`);
|
||||
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,
|
||||
modelId: modelName + '_' + modelId, // 传入 modelId,只替换该模型的材质
|
||||
albedoColor: color,
|
||||
albedoTexture: color_map_url,
|
||||
normalMap: normal_map_url,
|
||||
metallic: metallic,
|
||||
roughness: roughness
|
||||
metallic: +metallic,
|
||||
roughness: +roughness
|
||||
});
|
||||
|
||||
console.log(`百叶模型颜色已替换为 ${color}`);
|
||||
@ -277,15 +278,13 @@ const isModelExists = (modelId) => {
|
||||
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);
|
||||
console.log('替换模型颜色:', event.target_data);
|
||||
|
||||
kernel.material.apply({
|
||||
target: materialName,
|
||||
albedoColor: color,
|
||||
albedoTexture: color_map_url,
|
||||
normalMap: normal_map_url,
|
||||
metallic: metallic,
|
||||
roughness: roughness
|
||||
});
|
||||
|
||||
console.log(`百叶模型颜色已替换为 ${color}`);
|
||||
|
||||
@ -333,11 +333,14 @@
|
||||
</div>
|
||||
<div class="category-content">
|
||||
<div class="option-group">
|
||||
<button class="option-btn" data-option="louver-1">整体</button>
|
||||
<button class="option-btn" data-option="louver-2">3m百叶</button>
|
||||
<button class="option-btn" data-option="louver-1">SPFPDS13FTW</button>
|
||||
<button class="option-btn" data-option="louver-2">SPFPDS13FTC</button>
|
||||
<button class="option-btn" data-option="louver-3">3m下拉帘</button>
|
||||
<button class="option-btn" data-option="louver-4">百叶4</button>
|
||||
<button class="option-btn" data-option="louver-4">卷帘小</button>
|
||||
<button class="option-btn" data-option="louver-4">SPFSW13FTW</button>
|
||||
<button class="option-btn" data-option="louver-4">SPFSW10FTW</button>
|
||||
<button class="option-btn" data-option="louver-4">SPFPDS10FTC</button>
|
||||
<button class="option-btn" data-option="louver-4">SPFPDS10FTW</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -350,10 +353,14 @@
|
||||
</div>
|
||||
<div class="category-content">
|
||||
<div class="option-group">
|
||||
<button class="option-btn" data-option="color-1">SPF111S1010C</button>
|
||||
<button class="option-btn" data-option="color-2">SPF111S1010W</button>
|
||||
13
|
||||
<button class="option-btn" data-option="color-1">SPF111S1013W</button>
|
||||
<button class="option-btn" data-option="color-2">SPF111S1013C</button>
|
||||
<button class="option-btn" data-option="color-3">SPF111S1013TA</button>
|
||||
10
|
||||
<button class="option-btn" data-option="color-1">SPF111S1010W</button>
|
||||
<button class="option-btn" data-option="color-2">SPF111S1010C</button>
|
||||
<button class="option-btn" data-option="color-3">SPF111S1010TA</button>
|
||||
<button class="option-btn" data-option="color-4">木色</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -761,23 +768,24 @@
|
||||
}
|
||||
});
|
||||
|
||||
// 移除按钮事件
|
||||
document.getElementById('remove-model-btn').addEventListener('click', function () {
|
||||
var pickedMesh = window.getCurrentPickedMesh();
|
||||
if (pickedMesh) {
|
||||
var meshName = pickedMesh.name;
|
||||
var success = kernel.model.remove(meshName);
|
||||
if (success) {
|
||||
console.log('模型已移除');
|
||||
// 关闭信息框
|
||||
kernel.domTo3D.detach('model-info');
|
||||
} else {
|
||||
console.log('移除失败:未找到该网格所属的模型');
|
||||
}
|
||||
} else {
|
||||
console.log('没有选中的网格');
|
||||
}
|
||||
});
|
||||
// 移除按钮事件
|
||||
document.getElementById('remove-model-btn').addEventListener('click', () => {
|
||||
const pickedMesh = window.getCurrentPickedMesh();
|
||||
if (pickedMesh) {
|
||||
const meshName = pickedMesh.name;
|
||||
const modelName = kernel.model.findModelNameByMesh(pickedMesh);
|
||||
const success = kernel.model.removeByName(modelName);
|
||||
if (success) {
|
||||
console.log('模型已移除');
|
||||
// 关闭信息框
|
||||
kernel.domTo3D.detach('model-info');
|
||||
} else {
|
||||
console.log('移除失败:未找到该网格所属的模型');
|
||||
}
|
||||
} else {
|
||||
console.log('没有选中的网格');
|
||||
}
|
||||
});
|
||||
|
||||
// 生成放置区域按钮事件
|
||||
var dropZoneVisible = false;
|
||||
|
||||
358552
examples/index.global.js
358552
examples/index.global.js
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user