Support tiling AtlasTexture in TextureRect#113808
Conversation
|
In basic situation (without margins and atlas nesting) works great. I don't understand how atlas margins supposed to work in this situation, so I just recorded a video. Godot_v4.6-dev6_win64_kX5jEjY60q.mp4 |
a7b651f to
f859c08
Compare
If properly supported, the whole atlas texture should be tiled treated as a single "unit", including the margins. Like this: Godot_v4.5.1-stable_win64_UYYpo76D5F.mp4Here's script drawing the above (each "tile" is a separate quad): @tool
extends Control
@export var texture: AtlasTexture
func _process(delta: float) -> void:
queue_redraw()
func _draw() -> void:
var texture_size := texture.get_size()
var drawable_area := Rect2(Vector2.ZERO, size)
var repeat_count: Vector2i = (size / texture_size).ceil()
for y in repeat_count.y:
for x in repeat_count.x:
var cell_coords := Vector2(x, y)
var cell_rect_unclamped := Rect2(cell_coords * texture_size, texture_size)
var cell_rect_clamped := cell_rect_unclamped.intersection(drawable_area)
var src_rect := Rect2(Vector2.ZERO, cell_rect_clamped.size)
draw_texture_rect_region(texture, cell_rect_clamped, src_rect)
Which clearly shows that margins are nor handled "as expected". To handle the margins properly the tiling would need to be drawn either:
So for now I'll only add a note that tiling an AtlasTextures with margins is not supported.
Regarding atlas nesting, note that any number of nested atlas textures (assuming no cyclic dependency, which would likely lead to crashing as it's not being prevented / checked against) can be simplified to a single combined region+margin (nesting can't result in holes etc.), aka it's equivalent to considering a single AtlasTexture. For supporting nesting only such cumulated final region needs to be calculated. Updated the PR accordingly (so nesting with no margins should work just fine). |
f859c08 to
8f77f5a
Compare
8f77f5a to
a289ee7
Compare
|
Thanks! |
… thorvg etc) and backport of several Godot4 enhancements PR godotengine#90431 — --import CLI flag (editor/editor_file_system.h, main/main.cpp) PR godotengine#113808 — AtlasTexture tiling in TextureRect (scene/gui/texture_rect.cpp, scene/gui/texture_rect.h) PR godotengine#110925 — OBJ bump multiplier (editor/import/resource_importer_obj.cpp)
Fixes #113691.
Adds support for tiling an AtlasTexture assigned to a TextureRect by drawing it as a nine patch, which already supports tiling a texture region.
v4.6.dev6.official [dec5a37]
this PR