diff --git a/modules/gridmap/editor/grid_map_editor_plugin.cpp b/modules/gridmap/editor/grid_map_editor_plugin.cpp index 8086539052..ea90a03678 100644 --- a/modules/gridmap/editor/grid_map_editor_plugin.cpp +++ b/modules/gridmap/editor/grid_map_editor_plugin.cpp @@ -42,6 +42,7 @@ #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_zoom_widget.h" #include "editor/gui/filter_line_edit.h" +#include "editor/inspector/editor_resource_preview.h" #include "editor/scene/3d/mesh_library_editor_plugin.h" #include "editor/scene/3d/node_3d_editor_plugin.h" #include "editor/settings/editor_command_palette.h" @@ -1138,7 +1139,14 @@ void GridMapEditor::update_palette() { if (preview.is_valid()) { mesh_library_palette->set_item_icon(item, preview); mesh_library_palette->set_item_tooltip(item, name); + } else { + Ref mesh = mesh_library->get_item_mesh(id); + if (mesh.is_valid()) { + // Fallback to the item's mesh preview. + EditorResourcePreview::get_singleton()->queue_edited_resource_preview(mesh, callable_mp(this, &GridMapEditor::_update_resource_preview).bind(item)); + } } + mesh_library_palette->set_item_text(item, name); mesh_library_palette->set_item_metadata(item, id); @@ -1150,6 +1158,12 @@ void GridMapEditor::update_palette() { } } +void GridMapEditor::_update_resource_preview(const String &p_path, const Ref &p_preview, const Ref &p_small_preview, int p_idx) { + if (p_idx < mesh_library_palette->get_item_count()) { + mesh_library_palette->set_item_icon(p_idx, p_preview); + } +} + void GridMapEditor::_update_mesh_library() { ERR_FAIL_NULL(node); diff --git a/modules/gridmap/editor/grid_map_editor_plugin.h b/modules/gridmap/editor/grid_map_editor_plugin.h index de7cbabec5..5e9e87643b 100644 --- a/modules/gridmap/editor/grid_map_editor_plugin.h +++ b/modules/gridmap/editor/grid_map_editor_plugin.h @@ -219,11 +219,12 @@ class GridMapEditor : public EditorDock { ItemList *mesh_library_palette = nullptr; Label *info_message = nullptr; - void update_grid(); // Change which and where the grid is displayed + void update_grid(); // Change which and where the grid is displayed. void _draw_grids(const Vector3 &cell_size); void _configure(); void _menu_option(int); void update_palette(); + void _update_resource_preview(const String &p_path, const Ref &p_preview, const Ref &p_small_preview, int p_idx); void _update_mesh_library(); void _set_display_mode(int p_mode); void _item_selected_cbk(int idx);