This commit is contained in:
2026-05-18 18:53:30 +08:00
parent fb193c0528
commit 840e3d6a55
12 changed files with 907 additions and 68 deletions

View File

@ -203,8 +203,8 @@ const isModelExists = (modelId) => {
return kernel.model.exists(modelId);
}
//换棚子
const executeEvent2 = async (result) => {
//一般是换棚子/换颜色/显示放置区域
const executeEvent2 = async (result) => {
const kernel = getKernel();
// 检查是否有模型更换事件
@ -214,10 +214,10 @@ const executeEvent2 = async (result) => {
let modelAlreadyExists = false;
if (hasModelChange) {
const firstModelEvent = result.data.events.find(e => e.event_type === 'change_model');
if (firstModelEvent) {
const { category } = firstModelEvent.target_data;
modelAlreadyExists = isModelExists(category);
console.log(`检查模型 ${category} 是否存在:`, modelAlreadyExists);
if (firstModelEvent && firstModelEvent.target_data) {
const {name, category } = firstModelEvent.target_data;
modelAlreadyExists = kernel.model.exists(name+'_'+category);
console.log(`检查模型 ${name+'_'+category} 是否存在:`, modelAlreadyExists);
}
}
@ -241,12 +241,10 @@ const executeEvent2 = async (result) => {
};
const { id, name, file_url, model_control_type, category, placement_zone } = target_data;
console.log('替换百叶模型:', event);
console.log('替换百叶模型类型:', category);
// 如果模型已存在,跳过加载
if (modelAlreadyExists) {
console.log(`模型 ${category} 已存在,跳过加载`);
console.log(`模型 ${name+'_'+category} 已存在,跳过加载`);
continue;
}
@ -269,7 +267,7 @@ const executeEvent2 = async (result) => {
modelControlType: model_control_type,
})
console.log(`百叶模型已放置为 ${name}`);
console.log(`模型已放置为 ${name}`);
}
}

View File

@ -355762,14 +355762,26 @@ clipPos=viewProjection*worldPos;previousClipPos=previousViewProjection*previousW
const color = Color3.FromHexString(options.albedoColor);
material.albedoColor.copyFrom(color);
}
if (options.albedoTexture) {
material.albedoTexture = new Texture(options.albedoTexture);
if (options.albedoTexture !== void 0) {
if (options.albedoTexture) {
material.albedoTexture = new Texture(options.albedoTexture);
} else {
material.albedoTexture = null;
}
}
if (options.normalMap) {
material.bumpTexture = new Texture(options.normalMap);
if (options.normalMap !== void 0) {
if (options.normalMap) {
material.bumpTexture = new Texture(options.normalMap);
} else {
material.bumpTexture = null;
}
}
if (options.metallicTexture) {
material.metallicTexture = new Texture(options.metallicTexture);
if (options.metallicTexture !== void 0) {
if (options.metallicTexture) {
material.metallicTexture = new Texture(options.metallicTexture);
} else {
material.metallicTexture = null;
}
}
if (options.roughness !== void 0) {
material.roughness = options.roughness;
@ -357185,6 +357197,19 @@ clipPos=viewProjection*worldPos;previousClipPos=previousViewProjection*previousW
*/
removeAll: () => {
this.mainApp.appModel.removeAll();
},
/**
* 检查模型是否已加载
* @param modelId 模型ID
* @returns 模型是否存在
* @example
* // 检查模型是否已加载,避免重复加载
* if (!kernel.model.exists('shed_001')) {
* await kernel.model.add({ modelId: 'shed_001', modelUrl: '...' });
* }
*/
exists: (modelId) => {
return this.mainApp.appModel.exists(modelId);
}
};
/** 材质管理 */