Last active
December 14, 2024 13:36
-
-
Save nan0m/c280761802c6dfc86533d1de89d27dae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tool | |
extends NoiseTexture2D | |
class_name BakeableNoiseTexture2D | |
#clickable button to execute the bake (can be exchanged with @tool_button when godot 4.4 is out) | |
@export var bake: bool = false: | |
set(value): | |
bake = false | |
bake_execute() | |
## choose bake extension | |
@export_enum("png", "jpg", "webp") var bake_format: String = "png" | |
##the save_png, save_jpg, and save_webp methods, take different arguments, if you need any of them like e.g. compression, feel free to modify this to your liking | |
func bake_execute(): | |
if not Engine.is_editor_hint(): return | |
var path: String = self.resource_path | |
var ext: String = path.get_extension() | |
if not path or not ext: return | |
path = path.rstrip(ext) + bake_format | |
var method: String = "save_" +bake_format | |
self.get_image().call(method,path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment