From fbe124c43b6a4deb00de6da886ec7ad14294083b 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:44:52 +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=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=A2=AB=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=89=E4=B8=94=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8=E9=9C=80=E8=A6=81=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=EF=BC=8C=E6=89=8D=E4=BC=9A=E6=9B=B4=E6=96=B0?= =?UTF-8?q?fbx=E4=B8=AD=E5=BC=95=E7=94=A8=E7=9A=84=E7=BA=B9=E7=90=86uuid?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= 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..5b1213c 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", { encoding: "utf-8" }); + /** + * 用以查找 .mtl => dataAsSubAsset 是否包含uuid + * dataAsSubAsset 本身是字符串,就不再另做解析了,uuid 匹配可以的 + */ + if (fbxMeta.indexOf(uuid) === -1) { + if (fbxMeta.indexOf(`"dataAsSubAsset": null,`) === -1) { + //没有引用默认资源了,不继续查找 + return + } + //材质引用了默认纹理,读取fbx,匹配纹理资源名 + const data = await FileUtil.readFile(path, { encoding: "utf-8" }); + if (data.indexOf(basename(assetInfo.path)) === -1) { + //模型中雀食未引用这个纹理 + return; + } + } + result.push({ + type: ext, + url: EditorAPI.fspathToUrl(path) + }); + } catch (error) { + // 编辑器很坑,如果报错,不会打印。try 保证我们的提交不影响插件原来逻辑,并且有报错使用者也能反馈 + Editor.error(error) + } } }; // 遍历资源目录下的文件 -- Gitee