mirror of
https://github.com/godotengine/godot
synced 2024-11-02 14:43:31 +00:00
Add frame support for Sprite3D with region enabled
This commit is contained in:
parent
16d402147b
commit
1e3e770073
1 changed files with 14 additions and 20 deletions
|
@ -382,36 +382,30 @@ void Sprite3D::_draw() {
|
||||||
|
|
||||||
VS::get_singleton()->immediate_clear(immediate);
|
VS::get_singleton()->immediate_clear(immediate);
|
||||||
if (!texture.is_valid())
|
if (!texture.is_valid())
|
||||||
return; //no texuture no life
|
return;
|
||||||
Vector2 tsize = texture->get_size();
|
Vector2 tsize = texture->get_size();
|
||||||
if (tsize.x == 0 || tsize.y == 0)
|
if (tsize.x == 0 || tsize.y == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Size2i s;
|
Rect2 base_rect;
|
||||||
Rect2 src_rect;
|
if (region)
|
||||||
|
base_rect = region_rect;
|
||||||
|
else
|
||||||
|
base_rect = Rect2(0, 0, texture->get_width(), texture->get_height());
|
||||||
|
|
||||||
if (region) {
|
Size2 frame_size = base_rect.size / Size2(hframes, vframes);
|
||||||
|
Point2 frame_offset = Point2(frame % hframes, frame / hframes);
|
||||||
|
frame_offset *= frame_size;
|
||||||
|
|
||||||
s = region_rect.size;
|
Point2 dest_offset = get_offset();
|
||||||
src_rect = region_rect;
|
|
||||||
} else {
|
|
||||||
s = texture->get_size();
|
|
||||||
s = s / Size2(hframes, vframes);
|
|
||||||
|
|
||||||
src_rect.size = s;
|
|
||||||
src_rect.position.x += (frame % hframes) * s.x;
|
|
||||||
src_rect.position.y += (frame / hframes) * s.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point2 ofs = get_offset();
|
|
||||||
if (is_centered())
|
if (is_centered())
|
||||||
ofs -= s / 2;
|
dest_offset -= frame_size / 2;
|
||||||
|
|
||||||
Rect2 dst_rect(ofs, s);
|
|
||||||
|
|
||||||
|
Rect2 src_rect(base_rect.position + frame_offset, frame_size);
|
||||||
|
Rect2 final_dst_rect(dest_offset, frame_size);
|
||||||
Rect2 final_rect;
|
Rect2 final_rect;
|
||||||
Rect2 final_src_rect;
|
Rect2 final_src_rect;
|
||||||
if (!texture->get_rect_region(dst_rect, src_rect, final_rect, final_src_rect))
|
if (!texture->get_rect_region(final_dst_rect, src_rect, final_rect, final_src_rect))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (final_rect.size.x == 0 || final_rect.size.y == 0)
|
if (final_rect.size.x == 0 || final_rect.size.y == 0)
|
||||||
|
|
Loading…
Reference in a new issue