From 163e0e3ebd4c7b74307fc1ccebbf7e12266f2cf6 Mon Sep 17 00:00:00 2001 From: Timo Schwarzer Date: Thu, 3 Jan 2019 13:08:06 +0100 Subject: [PATCH] Add thumbnails to LargeTexture --- editor/plugins/editor_preview_plugins.cpp | 3 +++ scene/resources/texture.cpp | 11 +++++++++++ scene/resources/texture.h | 1 + 3 files changed, 15 insertions(+) diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index ccaddbc0a85..8464dfd0aaf 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -86,6 +86,7 @@ Ref EditorTexturePreviewPlugin::generate(const RES &p_from, const Size2 Ref img; Ref atex = p_from; + Ref ltex = p_from; if (atex.is_valid()) { Ref tex = atex->get_atlas(); if (!tex.is_valid()) { @@ -93,6 +94,8 @@ Ref EditorTexturePreviewPlugin::generate(const RES &p_from, const Size2 } Ref atlas = tex->get_data(); img = atlas->get_rect(atex->get_region()); + } else if (ltex.is_valid()) { + img = ltex->to_image(); } else { Ref tex = p_from; img = tex->get_data(); diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index ad962a3551b..2e0f04ffcb0 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -1205,6 +1205,17 @@ Ref LargeTexture::get_piece_texture(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, pieces.size(), Ref()); return pieces[p_idx].texture; } +Ref LargeTexture::to_image() const { + + Ref img = memnew(Image(this->get_width(), this->get_height(), false, Image::FORMAT_RGBA8)); + for (int i = 0; i < pieces.size(); i++) { + + Ref src_img = pieces[i].texture->get_data(); + img->blit_rect(src_img, Rect2(0, 0, src_img->get_width(), src_img->get_height()), pieces[i].offset); + } + + return img; +} void LargeTexture::_bind_methods() { diff --git a/scene/resources/texture.h b/scene/resources/texture.h index cf23aad2392..2b67ebec62f 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -330,6 +330,7 @@ public: int get_piece_count() const; Vector2 get_piece_offset(int p_idx) const; Ref get_piece_texture(int p_idx) const; + Ref to_image() const; virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref &p_normal_map = Ref()) const; virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref &p_normal_map = Ref()) const;