diff options
Diffstat (limited to 'editor/plugins/editor_preview_plugins.cpp')
-rw-r--r-- | editor/plugins/editor_preview_plugins.cpp | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index 7ac924571d..a2c36b1f3c 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -76,7 +76,7 @@ void post_process_preview(Ref<Image> p_image) { } bool EditorTexturePreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "Texture2D"); + return ClassDB::is_parent_class(p_type, "Texture2D") || ClassDB::is_parent_class(p_type, "Texture3D") || ClassDB::is_parent_class(p_type, "TextureLayered"); } bool EditorTexturePreviewPlugin::generate_small_preview_automatically() const { @@ -85,9 +85,13 @@ bool EditorTexturePreviewPlugin::generate_small_preview_automatically() const { Ref<Texture2D> EditorTexturePreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const { Ref<Image> img; - Ref<AtlasTexture> atex = p_from; - if (atex.is_valid()) { - Ref<Texture2D> tex = atex->get_atlas(); + + Ref<AtlasTexture> tex_atlas = p_from; + Ref<Texture3D> tex_3d = p_from; + Ref<TextureLayered> tex_lyr = p_from; + + if (tex_atlas.is_valid()) { + Ref<Texture2D> tex = tex_atlas->get_atlas(); if (!tex.is_valid()) { return Ref<Texture2D>(); } @@ -97,11 +101,36 @@ Ref<Texture2D> EditorTexturePreviewPlugin::generate(const Ref<Resource> &p_from, return Ref<Texture2D>(); } - if (!atex->get_region().has_area()) { + if (!tex_atlas->get_region().has_area()) { + return Ref<Texture2D>(); + } + + img = atlas->get_region(tex_atlas->get_region()); + + } else if (tex_3d.is_valid()) { + if (tex_3d->get_depth() == 0) { + return Ref<Texture2D>(); + } + + const int mid_depth = (tex_3d->get_depth() - 1) / 2; + + Vector<Ref<Image>> data = tex_3d->get_data(); + if (!data.is_empty() && data[mid_depth].is_valid()) { + img = data[mid_depth]->duplicate(); + } + + } else if (tex_lyr.is_valid()) { + if (tex_lyr->get_layers() == 0) { return Ref<Texture2D>(); } - img = atlas->get_region(atex->get_region()); + const int mid_layer = (tex_lyr->get_layers() - 1) / 2; + + Ref<Image> data = tex_lyr->get_layer_data(mid_layer); + if (data.is_valid()) { + img = data->duplicate(); + } + } else { Ref<Texture2D> tex = p_from; if (tex.is_valid()) { @@ -115,6 +144,7 @@ Ref<Texture2D> EditorTexturePreviewPlugin::generate(const Ref<Resource> &p_from, if (img.is_null() || img->is_empty()) { return Ref<Texture2D>(); } + p_metadata["dimensions"] = img->get_size(); img->clear_mipmaps(); |