MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / generate

Method generate

editor/inspector/editor_preview_plugins.cpp:93–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91}
92
93Ref<Texture2D> EditorTexturePreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const {
94 Ref<Image> img;
95
96 Ref<AtlasTexture> tex_atlas = p_from;
97 Ref<Texture3D> tex_3d = p_from;
98 Ref<TextureLayered> tex_lyr = p_from;
99
100 if (tex_atlas.is_valid()) {
101 Ref<Texture2D> tex = tex_atlas->get_atlas();
102 if (tex.is_null()) {
103 return Ref<Texture2D>();
104 }
105
106 Ref<Image> atlas = tex->get_image();
107 if (atlas.is_null()) {
108 return Ref<Texture2D>();
109 }
110
111 if (atlas->is_compressed()) {
112 atlas = atlas->duplicate();
113 if (atlas->decompress() != OK) {
114 return Ref<Texture2D>();
115 }
116 }
117
118 if (!tex_atlas->get_region().has_area()) {
119 return Ref<Texture2D>();
120 }
121
122 img = atlas->get_region(tex_atlas->get_region());
123
124 } else if (tex_3d.is_valid()) {
125 if (tex_3d->get_depth() == 0) {
126 return Ref<Texture2D>();
127 }
128
129 Vector<Ref<Image>> data = tex_3d->get_data();
130 if (data.size() != tex_3d->get_depth()) {
131 return Ref<Texture2D>();
132 }
133
134 // Use the middle slice for the thumbnail.
135 const int mid_depth = (tex_3d->get_depth() - 1) / 2;
136 if (!data.is_empty() && data[mid_depth].is_valid()) {
137 img = data[mid_depth]->duplicate();
138 }
139
140 } else if (tex_lyr.is_valid()) {
141 if (tex_lyr->get_layers() == 0) {
142 return Ref<Texture2D>();
143 }
144
145 // Use the middle slice for the thumbnail.
146 const int mid_layer = (tex_lyr->get_layers() - 1) / 2;
147
148 Ref<Image> data = tex_lyr->get_layer_data(mid_layer);
149 if (data.is_valid()) {
150 img = data->duplicate();

Callers 1

importMethod · 0.45

Calls 15

post_process_previewFunction · 0.85
RIDClass · 0.85
MAXFunction · 0.85
MINFunction · 0.85
CLAMPFunction · 0.85
get_atlasMethod · 0.80
is_compressedMethod · 0.80
clear_mipmapsMethod · 0.80
get_bitMethod · 0.80
request_and_waitMethod · 0.80
strip_edgesMethod · 0.80
instance_set_baseMethod · 0.80

Tested by

no test coverage detected