From d0083b57360b82d3d66a0a5a5aa1bf609c9f9540 Mon Sep 17 00:00:00 2001 From: Mikulas Florek Date: Wed, 18 Dec 2024 17:02:01 +0100 Subject: [PATCH] model importer - api for other formats than fbx --- src/editor/asset_browser.cpp | 10 ++++++++++ src/editor/asset_browser.h | 1 + src/renderer/editor/render_plugins.cpp | 19 ++++++++++++++++++- src/renderer/editor/render_plugins.h | 10 ++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/renderer/editor/render_plugins.h diff --git a/src/editor/asset_browser.cpp b/src/editor/asset_browser.cpp index 89a45205a3..543badba54 100644 --- a/src/editor/asset_browser.cpp +++ b/src/editor/asset_browser.cpp @@ -961,6 +961,16 @@ struct AssetBrowserImpl : AssetBrowser { m_plugin_map.eraseIf([&plugin](IPlugin* p){ return p == &plugin; }); } + IPlugin* getPlugin(StringView extension) const override { + char ext_str[9]; + makeLowercase(ext_str, extension); + u64 key = 0; + ASSERT(extension.size() <= sizeof(key)); + memcpy(&key, ext_str, extension.size()); + auto iter = m_plugin_map.find(key); + return iter.isValid() ? iter.value() : nullptr; + } + Span getPlugins() override { return m_plugins; } diff --git a/src/editor/asset_browser.h b/src/editor/asset_browser.h index 2b8fa12883..005df02edc 100644 --- a/src/editor/asset_browser.h +++ b/src/editor/asset_browser.h @@ -33,6 +33,7 @@ struct LUMIX_EDITOR_API AssetBrowser : StudioApp::GUIPlugin { virtual bool resourceInput(const char* str_id, Path& buf, ResourceType type, float width = -1) = 0; virtual void addPlugin(IPlugin& plugin, Span extensions) = 0; virtual void removePlugin(IPlugin& plugin) = 0; + virtual IPlugin* getPlugin(StringView extension) const = 0; virtual Span getPlugins() = 0; virtual void openInExternalEditor(struct Resource* resource) const = 0; virtual void openInExternalEditor(struct StringView path) const = 0; diff --git a/src/renderer/editor/render_plugins.cpp b/src/renderer/editor/render_plugins.cpp index c10b63d5bf..292c21474b 100644 --- a/src/renderer/editor/render_plugins.cpp +++ b/src/renderer/editor/render_plugins.cpp @@ -2033,7 +2033,9 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin { auto* render_module = static_cast(m_viewer.m_world->getModule(MODEL_INSTANCE_TYPE)); render_module->setModelInstancePath(*m_viewer.m_mesh, m_resource->getPath()); - m_fbx_async_handle = engine.getFileSystem().getContent(path, makeDelegate<&EditorWindow::onFBXLoaded>(this)); + if (Path::hasExtension(path, "fbx")) { + m_fbx_async_handle = engine.getFileSystem().getContent(path, makeDelegate<&EditorWindow::onFBXLoaded>(this)); + } } ~EditorWindow() { @@ -5587,6 +5589,21 @@ struct StudioAppPlugin : StudioApp::IPlugin bool m_vsync = true; }; +} // anonymous namespace + +namespace Lumix { + +// ModelPlugin handles only fbx, but other formats +// can use the same EditorWindow as ModelPlugin +void createModelEditor(const Path& path, StudioApp& app) { + IAllocator& allocator = app.getAllocator(); + AssetBrowser::IPlugin* plugin = app.getAssetBrowser().getPlugin("fbx"); + ASSERT(plugin); + ModelPlugin* model_plugin = static_cast(plugin); + UniquePtr win = UniquePtr::create(allocator, path, *model_plugin, app, allocator); + app.getAssetBrowser().addWindow(win.move()); +} + } LUMIX_STUDIO_ENTRY(renderer) { diff --git a/src/renderer/editor/render_plugins.h b/src/renderer/editor/render_plugins.h new file mode 100644 index 0000000000..9d357096fe --- /dev/null +++ b/src/renderer/editor/render_plugins.h @@ -0,0 +1,10 @@ +#pragma once + +namespace Lumix { + +struct Path; +struct StudioApp; + +LUMIX_RENDERER_API void createModelEditor(const Path& path, StudioApp& app); + +} // namespace Lumix \ No newline at end of file