diff --git a/src/main/finder.js b/src/main/finder.js index 9deda1214bdae2a0a20f179092b1b6cf88910135..413210a9bd447050bc6126155b949a01da907d1c 100644 --- a/src/main/finder.js +++ b/src/main/finder.js @@ -82,6 +82,7 @@ const Finder = { * @returns {Promise<{ type: string, url: string, refs?: object[]}[]>} */ async findRefs(uuid) { + const assetInfo = EditorAPI.assetInfoByUuid(uuid); const result = []; // 文件处理函数 const handler = async (path, stats) => { @@ -132,6 +133,37 @@ const Finder = { url: EditorAPI.fspathToUrl(path), }); } + } else if (ext === ".fbx" || ext === ".FBX") { + try { + if (assetInfo.type !== "texture") { + return; + } + //判断模型中的材质是否引用了 纹理 + const fbxMeta = await FileUtil.readFile(path + ".meta"); + /** + * 用以查找 .mtl => dataAsSubAsset 是否包含uuid + * dataAsSubAsset 本身是字符串,就不再另做解析了,uuid 匹配可以的 + */ + if (fbxMeta.indexOf(uuid) === -1) { + //是否引用了默认的材质(引擎的bug,需要手动切换材质再保存才会有数据) + if (fbxMeta.indexOf(`"dataAsSubAsset": null,`) === -1) { + return + } + //引用了默认材质,读取fbx,匹配纹理资源名 + const data = await FileUtil.readFile(path); + if (data.indexOf(basename(assetInfo.path)) === -1) { + //模型中未引用这个纹理 yyds + return; + } + } + result.push({ + type: ext, + url: EditorAPI.fspathToUrl(path) + }); + } catch (error) { + // 编辑器很坑,如果报错,不会打印。try 保证我们的提交不影响插件原来逻辑,并且有报错使用者也能反馈 + Editor.error(error) + } } }; // 遍历资源目录下的文件