From 2925db734c53563d36d02e2d25406770f8b6568a Mon Sep 17 00:00:00 2001 From: McHorse Date: Sat, 18 Jan 2025 16:15:39 +0000 Subject: [PATCH] BBS exporter: UX update and UV fix --- plugins.json | 4 +- plugins/bbs_exporter/bbs_exporter.js | 57 ++++++++++++++++++++++++++-- plugins/bbs_exporter/changelog.json | 20 ++++++++++ 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/plugins.json b/plugins.json index da9c567a..8b12dbfb 100644 --- a/plugins.json +++ b/plugins.json @@ -813,8 +813,8 @@ "title": "BBS Model Ex/importer", "icon": "icon.png", "author": "McHorse", - "description": "Adds actions to export/import models in BBS format, which is used by BBS machinima studio.", - "version": "1.2.4", + "description": "Adds actions to export/import models in BBS format, which is used by BBS mod.", + "version": "1.3", "variant": "both", "tags": ["Exporter", "Importer"], "min_version": "4.8.0", diff --git a/plugins/bbs_exporter/bbs_exporter.js b/plugins/bbs_exporter/bbs_exporter.js index 024126bf..150ae5d2 100644 --- a/plugins/bbs_exporter/bbs_exporter.js +++ b/plugins/bbs_exporter/bbs_exporter.js @@ -323,7 +323,7 @@ if (texture && texture.uuid == textureUuid) { - return [texture.width, texture.height]; + return [texture.uv_width, texture.uv_height]; } } } @@ -581,6 +581,21 @@ name: "BBS model", extension: "json", remember: false, + load_filter: { + type: "json", + extensions: ["json"], + condition: (file) => { + return file && file.model && file.model.groups && file.model.texture; + } + }, + load(content, file) { + if (!Undo) + { + setupProject(Formats.free); + } + + importBBS(content); + }, compile(options) { return autoStringify(compile()); }, @@ -615,6 +630,12 @@ description: "When enabled, copies to the buffer only cubes from the first found group. This option is ignored when Copy to buffer option is disabled!", type: "checkbox", value: false + }, + exportAsFolder: { + label: "Export to folder", + description: "When enabled, you can pick the folder where .bbs.json and the texture would be exported to.", + type: "checkbox", + value: false } }, onConfirm: function(formData) { @@ -623,7 +644,35 @@ lastOptions.model = formData.exportModel; lastOptions.animations = formData.exportAnimations; - if (formData.copyToBuffer) + if (formData.exportAsFolder) + { + var folder = Blockbench.pickDirectory({ + title: "Export destination..." + }); + + if (folder) + { + Blockbench.writeFile(PathModule.join(folder, "model.bbs.json"), { + content: autoStringify(compile()) + }); + + Texture.all.forEach((t) => + { + if (t.error) + { + return; + } + + var name = t.name.endsWith(".png") ? t.name : t.name + ".png"; + + Blockbench.writeFile(PathModule.join(folder, name), { + content: t.source, + savetype: 'image' + }); + }); + } + } + else if (formData.copyToBuffer) { var data = {}; @@ -648,9 +697,9 @@ Plugin.register("bbs_exporter", { title: "BBS Model Ex/importer", author: "McHorse", - description: "Adds actions to export/import models in BBS format, which is used by BBS machinima studio.", + description: "Adds actions to export/import models in BBS format, which is used by BBS mod.", icon: "icon.png", - version: "1.2.4", + version: "1.3", min_version: "4.8.0", variant: "both", has_changelog: true, diff --git a/plugins/bbs_exporter/changelog.json b/plugins/bbs_exporter/changelog.json index cef10e29..77e54c61 100644 --- a/plugins/bbs_exporter/changelog.json +++ b/plugins/bbs_exporter/changelog.json @@ -37,5 +37,25 @@ ] } ] + }, + "1.3": { + "title": "1.3", + "date": "2025-01-18", + "author": "McHorse", + "categories": [ + { + "title": "Features", + "list": [ + "Added option \"Export to folder\" to exporter to automatically export not only the .bbs.json file, but texture(s) as well!", + "Added load filter to ease importing .bbs.json models via drag-and-dropping or by opening file with Blockbench" + ] + }, + { + "title": "Bug fixes", + "list": [ + "Fixed wrong UV size being used when a texture has different UV size" + ] + } + ] } } \ No newline at end of file