@@ -12,6 +12,8 @@ const HT_Logger = preload("./util/logger.gd")
12
12
const HT_ImageFileCache = preload ("./util/image_file_cache.gd" )
13
13
const HT_XYZFormat = preload ("./util/xyz_format.gd" )
14
14
15
+ const ENABLE_LEGACY_HEIGHTMAP_RH_CONVERSION_IN_EDITOR = true
16
+
15
17
enum {
16
18
BIT_DEPTH_UNDEFINED = 0 ,
17
19
BIT_DEPTH_16 = 16 ,
@@ -1331,29 +1333,39 @@ func _load_map(dir: String, map_type: int, index: int, resource_loader_cache_mod
1331
1333
1332
1334
var must_load_image_in_editor := true
1333
1335
1334
- # Forward-compatibility with old heightmap encodings
1335
- if Engine . is_editor_hint () and tex == null and map_type == CHANNEL_HEIGHT :
1336
- var legacy_fpath := fpath . get_basename () + ".png"
1337
- var temp = ResourceLoader . load ( legacy_fpath , "" , resource_loader_cache_mode )
1338
- if temp != null :
1339
- if temp is Texture2D :
1340
- temp = temp . get_image ()
1341
- if temp is Image :
1342
- if temp .get_format () == Image .FORMAT_RGB8 :
1336
+ if Engine . is_editor_hint ():
1337
+ # Short-term compatibility with RGB8 encoding from the godot4 branch
1338
+ if tex == null and map_type == CHANNEL_HEIGHT :
1339
+ var legacy_fpath := fpath . get_basename () + ".png"
1340
+ var temp = ResourceLoader . load ( legacy_fpath , "" , resource_loader_cache_mode )
1341
+ if temp != null :
1342
+ if temp is Texture2D :
1343
+ temp = temp . get_image ()
1344
+ if temp is Image and temp .get_format () == Image .FORMAT_RGB8 :
1343
1345
_logger .warn (str (
1344
1346
"Found a heightmap using legacy RGB8 format. It will be converted to RF. " ,
1345
1347
"You may want to remove the old file: {0} " ).format ([fpath ]))
1346
1348
tex = convert_heightmap_to_float (temp , _logger )
1347
1349
# This is a different file so we can save without overwriting the old path
1348
1350
_save_map_image (fpath .get_basename (), map_type , tex )
1349
1351
1350
- elif temp .get_format () == Image .FORMAT_RH :
1351
- _logger .warn (str (
1352
- "Found a heightmap using legacy RH format. It will be converted to RF. " ,
1353
- "You may edit and re-save to make the upgrade persist." ))
1354
- tex = convert_heightmap_to_float (temp , _logger )
1355
- # Not saving yet to prevent unintentional data loss if anything goes wrong?
1356
- # _save_map_image(fpath.get_basename(), map_type, tex)
1352
+ # Forward-compatibility with legacy format used in godot3
1353
+ if ENABLE_LEGACY_HEIGHTMAP_RH_CONVERSION_IN_EDITOR \
1354
+ and tex != null and map_type == CHANNEL_HEIGHT :
1355
+ var temp := tex as Image
1356
+ if temp == null and tex is Texture2D :
1357
+ var tex_format := RenderingServer .texture_get_format (tex .get_rid ())
1358
+ if tex_format == Image .FORMAT_RH :
1359
+ # Downloads image from RenderingServer, might be expensive
1360
+ temp = tex .get_image ()
1361
+ if temp != null and temp .get_format () == Image .FORMAT_RH :
1362
+ _logger .warn (str (
1363
+ "Found a heightmap using legacy RH format. It will be converted to RF. " ,
1364
+ "You may edit and re-save to make the upgrade persist." ))
1365
+ temp .convert (Image .FORMAT_RF )
1366
+ tex = temp
1367
+ # Not saving yet to prevent unintentional data loss if anything goes wrong?
1368
+ # _save_map_image(fpath.get_basename(), map_type, tex)
1357
1369
1358
1370
if tex != null and tex is Image :
1359
1371
# The texture is imported as Image,
0 commit comments