Skip to content

Commit

Permalink
Removed references to packed_texarr and packed_tex formats.
Browse files Browse the repository at this point in the history
They were used made-up file formats used in the Godot 3 version of the
plugin and are no longer used, due to the removal of custom importers,
which were hard to maintain and not possible to port to Godot 4.
  • Loading branch information
Zylann committed Oct 5, 2023
1 parent ab72c6f commit 11e0db9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 111 deletions.
73 changes: 0 additions & 73 deletions addons/zylann.hterrain/doc/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

var import_data := _parse_json_file(texture.resource_path)
if import_data.is_empty() or not import_data.has("src"):
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 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)

Expand All @@ -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

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"]
# 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.

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 != "":
Expand Down
4 changes: 2 additions & 2 deletions addons/zylann.hterrain/tools/util/editor_util.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ 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):
_add_image_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
Expand Down

0 comments on commit 11e0db9

Please sign in to comment.