Skip to content

Commit

Permalink
Added an endianess option for raw heightmap import
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Apr 30, 2020
1 parent a2a3da6 commit beb4502
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 283 deletions.
12 changes: 10 additions & 2 deletions addons/zylann.hterrain/hterrain_data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ func _edit_import_maps(input: Dictionary) -> bool:

if input.has(CHANNEL_HEIGHT):
var params = input[CHANNEL_HEIGHT]
if not _import_heightmap(params.path, params.min_height, params.max_height):
if not _import_heightmap(params.path, params.min_height, params.max_height, params.big_endian):
return false

var maptypes = [CHANNEL_COLOR, CHANNEL_SPLAT]
Expand All @@ -1170,7 +1170,7 @@ static func get_adjusted_map_size(width: int, height: int) -> int:
return size_po2


func _import_heightmap(fpath: String, min_y: int, max_y: int) -> bool:
func _import_heightmap(fpath: String, min_y: int, max_y: int, big_endian: bool) -> bool:
var ext = fpath.get_extension().to_lower()

if ext == "png":
Expand Down Expand Up @@ -1229,6 +1229,14 @@ func _import_heightmap(fpath: String, min_y: int, max_y: int) -> bool:
# Can't deduce size
return false

# TODO Need a way to know which endianess our system has!
# For now we have to make an assumption...
# This function is most supposed to execute in the editor.
# The editor officially runs on desktop architectures, which are
# generally little-endian.
if big_endian:
f.endian_swap = true

var res = get_adjusted_map_size(file_res, file_res)

var width = res
Expand Down
48 changes: 40 additions & 8 deletions addons/zylann.hterrain/tools/importer/importer_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,46 @@ onready var _inspector = $VBoxContainer/Inspector
onready var _errors_label = $VBoxContainer/ColorRect/ScrollContainer/VBoxContainer/Errors
onready var _warnings_label = $VBoxContainer/ColorRect/ScrollContainer/VBoxContainer/Warnings

const RAW_LITTLE_ENDIAN = 0
const RAW_BIG_ENDIAN = 1

var _terrain = null
var _logger = Logger.get_for(self)


func _ready():
_inspector.set_prototype({
"heightmap": { "type": TYPE_STRING, "usage": "file", "exts": ["raw", "png"] },
"min_height": { "type": TYPE_REAL, "range": {"min": -2000.0, "max": 2000.0, "step": 1.0}, "default_value": 0.0 },
"max_height": { "type": TYPE_REAL, "range": {"min": -2000.0, "max": 2000.0, "step": 1.0}, "default_value": 400.0 },
"splatmap": { "type": TYPE_STRING, "usage": "file", "exts": ["png"] },
"colormap": { "type": TYPE_STRING, "usage": "file", "exts": ["png"] }
"heightmap": {
"type": TYPE_STRING,
"usage": "file",
"exts": ["raw", "png"]
},
"raw_endianess": {
"type": TYPE_INT,
"usage": "enum",
"enum_items": ["Little Endian", "Big Endian"],
"enabled": false
},
"min_height": {
"type": TYPE_REAL,
"range": {"min": -2000.0, "max": 2000.0, "step": 1.0},
"default_value": 0.0
},
"max_height": {
"type": TYPE_REAL,
"range": {"min": -2000.0, "max": 2000.0, "step": 1.0},
"default_value": 400.0
},
"splatmap": {
"type": TYPE_STRING,
"usage": "file",
"exts": ["png"]
},
"colormap": {
"type": TYPE_STRING,
"usage": "file",
"exts": ["png"]
}
})

# Testing
Expand Down Expand Up @@ -88,10 +117,12 @@ func _on_ImportButton_pressed():

var heightmap_path = _inspector.get_value("heightmap")
if heightmap_path != "":
var endianess = _inspector.get_value("raw_endianess")
params[HTerrainData.CHANNEL_HEIGHT] = {
"path": heightmap_path,
"min_height": _inspector.get_value("min_height"),
"max_height": _inspector.get_value("max_height"),
"big_endian": endianess == RAW_BIG_ENDIAN
}

var colormap_path = _inspector.get_value("colormap")
Expand All @@ -118,12 +149,13 @@ func _on_CancelButton_pressed():
hide()


func _on_Inspector_property_changed(key, value):
pass # replace with function body
func _on_Inspector_property_changed(key: String, value):
if key == "heightmap":
var is_raw = value.get_extension().to_lower() == "raw"
_inspector.set_property_enabled("raw_endianess", is_raw)


func _validate_form():

var res = {
"errors": [],
"warnings": []
Expand Down
Loading

0 comments on commit beb4502

Please sign in to comment.