Skip to content

Commit

Permalink
Load old RH heightmaps as RF to match the new format
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Feb 27, 2024
1 parent 5838226 commit f59fea6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion addons/zylann.hterrain/hterrain_data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ func _load_map(dir: String, map_type: int, index: int, resource_loader_cache_mod

var must_load_image_in_editor := true

# Short-term compatibility with RGB8 encoding from the godot4 branch
# Forward-compatibility with old heightmap encodings
if Engine.is_editor_hint() and tex == null and map_type == CHANNEL_HEIGHT:
var legacy_fpath := fpath.get_basename() + ".png"
var temp = ResourceLoader.load(legacy_fpath, "", resource_loader_cache_mode)
Expand All @@ -1344,8 +1344,17 @@ func _load_map(dir: String, map_type: int, index: int, resource_loader_cache_mod
"Found a heightmap using legacy RGB8 format. It will be converted to RF. ",
"You may want to remove the old file: {0}").format([fpath]))
tex = convert_heightmap_to_float(temp, _logger)
# This is a different file so we can save without overwriting the old path
_save_map_image(fpath.get_basename(), map_type, tex)

elif temp.get_format() == Image.FORMAT_RH:
_logger.warn(str(
"Found a heightmap using legacy RH format. It will be converted to RF. ",
"You may edit and re-save to make the upgrade persist."))
tex = convert_heightmap_to_float(temp, _logger)
# Not saving yet to prevent unintentional data loss if anything goes wrong?
#_save_map_image(fpath.get_basename(), map_type, tex)

if tex != null and tex is Image:
# The texture is imported as Image,
# perhaps the user wants it to be accessible from RAM in game.
Expand Down

0 comments on commit f59fea6

Please sign in to comment.