From 8bc130c20dc36d086fc29f5b22479d79f2dc590d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E5=BF=97=E9=94=8B?= <378741819@qq.com> Date: Sat, 4 Dec 2021 01:18:47 +0000 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=20fbx=20=E4=B8=AD=E6=9D=90?= =?UTF-8?q?=E8=B4=A8=E5=BC=95=E7=94=A8=E7=9A=84=E7=BA=B9=E7=90=86=EF=BC=8C?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=AF=86=E5=88=AB=E5=88=B0=EF=BC=88=E4=B8=89?= =?UTF-8?q?=E7=BA=A7=E5=B5=8C=E5=A5=97=EF=BC=8C=E4=B8=94=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8=E4=BF=9D=E5=AD=98fbx=E6=9D=90?= =?UTF-8?q?=E8=B4=A8=E7=9A=84=E9=BB=98=E8=AE=A4=E7=BA=B9=E7=90=86uuid?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/finder.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/finder.js b/src/main/finder.js index 9deda12..413210a 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) + } } }; // 遍历资源目录下的文件 -- Gitee