Skip to content

Instantly share code, notes, and snippets.

@nan0m
Last active December 14, 2024 13:36
Show Gist options
  • Save nan0m/c280761802c6dfc86533d1de89d27dae to your computer and use it in GitHub Desktop.
Save nan0m/c280761802c6dfc86533d1de89d27dae to your computer and use it in GitHub Desktop.
@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