Skip to content

Commit

Permalink
model importer - api for other formats than fbx
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Dec 18, 2024
1 parent 2702509 commit d0083b5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/editor/asset_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPlugin*> getPlugins() override {
return m_plugins;
}
Expand Down
1 change: 1 addition & 0 deletions src/editor/asset_browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*> extensions) = 0;
virtual void removePlugin(IPlugin& plugin) = 0;
virtual IPlugin* getPlugin(StringView extension) const = 0;
virtual Span<IPlugin*> getPlugins() = 0;
virtual void openInExternalEditor(struct Resource* resource) const = 0;
virtual void openInExternalEditor(struct StringView path) const = 0;
Expand Down
19 changes: 18 additions & 1 deletion src/renderer/editor/render_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,9 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin {
auto* render_module = static_cast<RenderModule*>(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() {
Expand Down Expand Up @@ -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<ModelPlugin*>(plugin);
UniquePtr<ModelPlugin::EditorWindow> win = UniquePtr<ModelPlugin::EditorWindow>::create(allocator, path, *model_plugin, app, allocator);
app.getAssetBrowser().addWindow(win.move());
}

}

LUMIX_STUDIO_ENTRY(renderer) {
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/editor/render_plugins.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

namespace Lumix {

struct Path;
struct StudioApp;

LUMIX_RENDERER_API void createModelEditor(const Path& path, StudioApp& app);

} // namespace Lumix

0 comments on commit d0083b5

Please sign in to comment.