update addons

This commit is contained in:
deed 2023-10-15 11:32:30 +02:00
parent ed3ec686b8
commit 70f00bdee2
4 changed files with 53 additions and 114 deletions

View file

@ -478,79 +478,6 @@ It can also be done using [packed texture importers](packed-texture-importers),
Because Godot would strip out the alpha channel if a packed texture was imported as a normal map, you should not make your texture import as "Normal Map" in the importer dock.
### Packed texture importers
In order to support the [import tool](#using-the-import-tool), this plugin defines two special texture importers, which allow to pack multiple input textures into one. They otherwise behave the same as Godot's default importers.
The type of file they import are JSON files, which refer to the source image files you wish to pack together, along with a few other options.
#### Packed textures
File extension: `.packed_tex`
Example for an albedo+bump texture:
```json
{
"contains_albedo": true,
"src": {
"rgb": "res://textures/src/grass_albedo.png",
"a": "res://textures/src/grass_bump.png",
}
}
```
Example for a normal+roughness texture, with conversion from DirectX to OpenGL (optional):
```json
{
"src": {
"rgb": "res://textures/src/rocks_normal.png",
"a": "res://textures/src/rocks_roughness.png",
"normalmap_flip_y": true
}
}
```
You can also specify a plain color instead of a path, if you don't need a texture. It will act as if the source texture was filled with this color. The expected format is ARGB.
```
"rgb": "#ff888800"
```
#### Packed texture arrays
File extension: `.packed_texarr`
This one requires you to specify a `resolution`, because each layer of the texture array must have the same size and be square. The resolution is a single integer number.
What you can put in each layer is the same as for [packed textures](#packed-textures).
```json
{
"contains_albedo": true,
"resolution": 1024,
"layers": [
{
"rgb": "res://textures/src/grass_albedo.png",
"a": "res://textures/src/grass_bump.png"
},
{
"rgb": "res://textures/src/rocks_albedo.png",
"a": "res://textures/src/rocks_bump.png"
},
{
"rgb": "res://textures/src/sand_albedo.png",
"a": "res://textures/src/sand_bump.png"
}
]
}
```
#### Limitations
Such importers support most of the features needed for terrain textures, however some features found in Godot's importers are not implemented. This is because Godot does not have any API to extend the existing importers, so they had to be re-implemented from scratch in GDScript. For example, lossy compression to save disk space is not supported, because it requires access to WebP compression API which is not exposed.
See [Godot proposal](https://github.com/godotengine/godot-proposals/issues/1943)
### Depth blending
`Bump` textures holds a particular usage in this plugin:

View file

@ -433,7 +433,7 @@ func _on_ClearNormal_pressed():
func _on_ModeSelector_item_selected(index: int):
var id = _mode_selector.get_selected_id()
var id := _mode_selector.get_selected_id()
if id == _texture_set.get_mode():
return
@ -446,13 +446,13 @@ func _on_ModeSelector_item_selected(index: int):
else:
if _texture_set.get_mode() == HTerrainTextureSet.MODE_TEXTURES:
_mode_confirmation_dialog.window_title = "Switch to TextureArrays"
_mode_confirmation_dialog.title = "Switch to TextureArrays"
_mode_confirmation_dialog.dialog_text = \
"This will unload all textures currently setup. Do you want to continue?"
_mode_confirmation_dialog.popup_centered()
else:
_mode_confirmation_dialog.window_title = "Switch to Textures"
_mode_confirmation_dialog.title = "Switch to Textures"
_mode_confirmation_dialog.dialog_text = \
"This will unload all textures currently setup. Do you want to continue?"
_mode_confirmation_dialog.popup_centered()

View file

@ -212,20 +212,26 @@ func set_texture_set(texture_set: HTerrainTextureSet):
if texture == null or texture.resource_path == "":
continue
if not texture.resource_path.ends_with(".packed_tex"):
continue
# In Godot 3 we used a custom format to store and composite source images
# with a custom importer. It was removed during the port to Godot 4 because it
# was too hard to maintain a custom texture importer (too much logic to replicate
# from Godot's builtin importer, which wasn't exposed).
# For now the import tool won't remember source images between editor sessions.
var import_data := _parse_json_file(texture.resource_path)
if import_data.is_empty() or not import_data.has("src"):
continue
var src_types = HTerrainTextureSet.get_src_types_from_type(type)
var src_data = import_data["src"]
if src_data.has("rgb"):
slot.texture_paths[src_types[0]] = src_data["rgb"]
if src_data.has("a"):
slot.texture_paths[src_types[1]] = src_data["a"]
# if not texture.resource_path.ends_with(".packed_tex"):
# continue
#
# var import_data := _parse_json_file(texture.resource_path)
# if import_data.is_empty() or not import_data.has("src"):
# continue
#
# var src_types = HTerrainTextureSet.get_src_types_from_type(type)
#
# var src_data = import_data["src"]
# if src_data.has("rgb"):
# slot.texture_paths[src_types[0]] = src_data["rgb"]
# if src_data.has("a"):
# slot.texture_paths[src_types[1]] = src_data["a"]
_slots_data.append(slot)
@ -238,30 +244,36 @@ func set_texture_set(texture_set: HTerrainTextureSet):
if texture_array == null or texture_array.resource_path == "":
continue
if not texture_array.resource_path.ends_with(".packed_texarr"):
continue
# In Godot 3 we used a custom format to store and composite source images
# with a custom importer. It was removed during the port to Godot 4 because it
# was too hard to maintain a custom texture importer (too much logic to replicate
# from Godot's builtin importer, which wasn't exposed).
# For now the import tool won't remember source images between editor sessions.
var import_data := _parse_json_file(texture_array.resource_path)
if import_data.is_empty() or not import_data.has("layers"):
continue
var layers_data = import_data["layers"]
for slot_index in len(layers_data):
var src_data = layers_data[slot_index]
var src_types = HTerrainTextureSet.get_src_types_from_type(type)
while slot_index >= len(_slots_data):
var slot = HT_TextureSetImportEditorSlot.new()
_slots_data.append(slot)
var slot : HT_TextureSetImportEditorSlot = _slots_data[slot_index]
if src_data.has("rgb"):
slot.texture_paths[src_types[0]] = src_data["rgb"]
if src_data.has("a"):
slot.texture_paths[src_types[1]] = src_data["a"]
# if not texture_array.resource_path.ends_with(".packed_texarr"):
# continue
#
# var import_data := _parse_json_file(texture_array.resource_path)
# if import_data.is_empty() or not import_data.has("layers"):
# continue
#
# var layers_data = import_data["layers"]
#
# for slot_index in len(layers_data):
# var src_data = layers_data[slot_index]
#
# var src_types = HTerrainTextureSet.get_src_types_from_type(type)
#
# while slot_index >= len(_slots_data):
# var slot = HT_TextureSetImportEditorSlot.new()
# _slots_data.append(slot)
#
# var slot : HT_TextureSetImportEditorSlot = _slots_data[slot_index]
#
# if src_data.has("rgb"):
# slot.texture_paths[src_types[0]] = src_data["rgb"]
# if src_data.has("a"):
# slot.texture_paths[src_types[1]] = src_data["a"]
# TODO If the set doesn't have a file, use terrain path by default?
if texture_set.resource_path != "":

View file

@ -74,7 +74,7 @@ static func _add_texture_filters(file_dialog):
# Godot
file_dialog.add_filter("*.ctex ; CompressedTexture files")
# Packed textures
file_dialog.add_filter("*.packed_tex ; HTerrainPackedTexture files")
# file_dialog.add_filter("*.packed_tex ; HTerrainPackedTexture files")
static func _add_texture_array_filters(file_dialog):
@ -82,7 +82,7 @@ static func _add_texture_array_filters(file_dialog):
# Godot
file_dialog.add_filter("*.ctexarray ; TextureArray files")
# Packed textures
file_dialog.add_filter("*.packed_texarr ; HTerrainPackedTextureArray files")
# file_dialog.add_filter("*.packed_texarr ; HTerrainPackedTextureArray files")
# Tries to load a texture with the ResourceLoader, and if it fails, attempts