Godot Version
v4.5.1.stable.arch_linux
Question
Hi community, I am trying to make a custom image importer, that remaps one image’s colours to the positions of where said colour is on another image. So far, I (think I) managed to make the biggest part of logic, but I fail in saving the resource.
# ...
func _get_save_extension() -> String:
return "..." # What do I need to put here?
func _get_resource_type() -> String:
return "..." # What do I need to put here?
# ...
func _import(source_file: String, save_path: String, options: Dictionary, platform_variants: Array[String], gen_files: Array[String]) -> Error:
#region Prepare UV-Map
var uv_map := Image.load_from_file(options.uv_map)
if uv_map == null:
return ERR_CANT_ACQUIRE_RESOURCE
var uv_size := uv_map.get_size()
var color_positions: Dictionary[Color, Color]
for y in uv_size.y:
for x in uv_size.x:
color_positions[uv_map.get_pixel(x, y)] = Color(x, y, 0, 1)
#endregion
#region Generate new Image
var image := Image.load_from_file(source_file)
var size: Vector2i = image.get_size()
var new_image := Image.create(image.get_width(), image.get_height(), image.has_mipmaps(), image.get_format())
new_image.copy_from(image)
for y in size.y:
for x in size.x:
var color := image.get_pixel(x, y)
new_image.set_pixel(x, y, color_positions[color])
#endregion
# How do I save the image?
return ResourceSaver.save(new_image, "%s.%s" % [save_path, _get_save_extension()])
My main questions are:
- What format does it need?
- I see that other imported PNGs get saved as
ctexin.godot/imported/ - They seem to be
CompressedTexture2Ds - So the question is, what do I need to return in the methods
_get_save_extension()and_get_resource_type()?
- I see that other imported PNGs get saved as
- How do I save my custom Image with the
ResourceSaver?