mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-30 21:21:10 +00:00 
			
		
		
		
	Add metadata to resource previews
This commit is contained in:
		
							parent
							
								
									74c34aed38
								
							
						
					
					
						commit
						04317e9ced
					
				
					 7 changed files with 108 additions and 87 deletions
				
			
		|  | @ -79,7 +79,7 @@ bool EditorTexturePreviewPlugin::generate_small_preview_automatically() const { | |||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| Ref<Texture2D> EditorTexturePreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size) 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()) { | ||||
|  | @ -107,6 +107,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(); | ||||
| 
 | ||||
|  | @ -141,7 +142,7 @@ bool EditorImagePreviewPlugin::handles(const String &p_type) const { | |||
| 	return p_type == "Image"; | ||||
| } | ||||
| 
 | ||||
| Ref<Texture2D> EditorImagePreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { | ||||
| Ref<Texture2D> EditorImagePreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const { | ||||
| 	Ref<Image> img = p_from; | ||||
| 
 | ||||
| 	if (img.is_null() || img->is_empty()) { | ||||
|  | @ -185,7 +186,7 @@ bool EditorBitmapPreviewPlugin::handles(const String &p_type) const { | |||
| 	return ClassDB::is_parent_class(p_type, "BitMap"); | ||||
| } | ||||
| 
 | ||||
| Ref<Texture2D> EditorBitmapPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { | ||||
| Ref<Texture2D> EditorBitmapPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const { | ||||
| 	Ref<BitMap> bm = p_from; | ||||
| 
 | ||||
| 	if (bm->get_size() == Size2()) { | ||||
|  | @ -246,11 +247,11 @@ bool EditorPackedScenePreviewPlugin::handles(const String &p_type) const { | |||
| 	return ClassDB::is_parent_class(p_type, "PackedScene"); | ||||
| } | ||||
| 
 | ||||
| Ref<Texture2D> EditorPackedScenePreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { | ||||
| 	return generate_from_path(p_from->get_path(), p_size); | ||||
| Ref<Texture2D> EditorPackedScenePreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const { | ||||
| 	return generate_from_path(p_from->get_path(), p_size, p_metadata); | ||||
| } | ||||
| 
 | ||||
| Ref<Texture2D> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size) const { | ||||
| Ref<Texture2D> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size, Dictionary &p_metadata) const { | ||||
| 	String temp_path = EditorPaths::get_singleton()->get_cache_dir(); | ||||
| 	String cache_base = ProjectSettings::get_singleton()->globalize_path(p_path).md5_text(); | ||||
| 	cache_base = temp_path.path_join("resthumb-" + cache_base); | ||||
|  | @ -298,7 +299,7 @@ bool EditorMaterialPreviewPlugin::generate_small_preview_automatically() const { | |||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| Ref<Texture2D> EditorMaterialPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { | ||||
| Ref<Texture2D> EditorMaterialPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const { | ||||
| 	Ref<Material> material = p_from; | ||||
| 	ERR_FAIL_COND_V(material.is_null(), Ref<Texture2D>()); | ||||
| 
 | ||||
|  | @ -455,7 +456,7 @@ bool EditorScriptPreviewPlugin::handles(const String &p_type) const { | |||
| 	return ClassDB::is_parent_class(p_type, "Script"); | ||||
| } | ||||
| 
 | ||||
| Ref<Texture2D> EditorScriptPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { | ||||
| Ref<Texture2D> EditorScriptPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const { | ||||
| 	Ref<Script> scr = p_from; | ||||
| 	if (scr.is_null()) { | ||||
| 		return Ref<Texture2D>(); | ||||
|  | @ -590,7 +591,7 @@ bool EditorAudioStreamPreviewPlugin::handles(const String &p_type) const { | |||
| 	return ClassDB::is_parent_class(p_type, "AudioStream"); | ||||
| } | ||||
| 
 | ||||
| Ref<Texture2D> EditorAudioStreamPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { | ||||
| Ref<Texture2D> EditorAudioStreamPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const { | ||||
| 	Ref<AudioStream> stream = p_from; | ||||
| 	ERR_FAIL_COND_V(stream.is_null(), Ref<Texture2D>()); | ||||
| 
 | ||||
|  | @ -680,7 +681,7 @@ bool EditorMeshPreviewPlugin::handles(const String &p_type) const { | |||
| 	return ClassDB::is_parent_class(p_type, "Mesh"); // Any mesh.
 | ||||
| } | ||||
| 
 | ||||
| Ref<Texture2D> EditorMeshPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { | ||||
| Ref<Texture2D> EditorMeshPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const { | ||||
| 	Ref<Mesh> mesh = p_from; | ||||
| 	ERR_FAIL_COND_V(mesh.is_null(), Ref<Texture2D>()); | ||||
| 
 | ||||
|  | @ -797,7 +798,7 @@ bool EditorFontPreviewPlugin::handles(const String &p_type) const { | |||
| 	return ClassDB::is_parent_class(p_type, "Font"); | ||||
| } | ||||
| 
 | ||||
| Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size) const { | ||||
| Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size, Dictionary &p_metadata) const { | ||||
| 	Ref<Font> sampled_font = ResourceLoader::load(p_path); | ||||
| 	ERR_FAIL_COND_V(sampled_font.is_null(), Ref<Texture2D>()); | ||||
| 
 | ||||
|  | @ -846,12 +847,12 @@ Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path, | |||
| 	return ImageTexture::create_from_image(img); | ||||
| } | ||||
| 
 | ||||
| Ref<Texture2D> EditorFontPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { | ||||
| Ref<Texture2D> EditorFontPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const { | ||||
| 	String path = p_from->get_path(); | ||||
| 	if (!FileAccess::exists(path)) { | ||||
| 		return Ref<Texture2D>(); | ||||
| 	} | ||||
| 	return generate_from_path(path, p_size); | ||||
| 	return generate_from_path(path, p_size, p_metadata); | ||||
| } | ||||
| 
 | ||||
| EditorFontPreviewPlugin::EditorFontPreviewPlugin() { | ||||
|  | @ -887,7 +888,7 @@ bool EditorGradientPreviewPlugin::generate_small_preview_automatically() const { | |||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| Ref<Texture2D> EditorGradientPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { | ||||
| Ref<Texture2D> EditorGradientPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const { | ||||
| 	Ref<Gradient> gradient = p_from; | ||||
| 	if (gradient.is_valid()) { | ||||
| 		Ref<GradientTexture1D> ptex; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 kobewi
						kobewi