Fix AtlasTexture nesting
This commit is contained in:
parent
6fac314b5d
commit
63fd172fce
2 changed files with 4 additions and 21 deletions
|
@ -222,28 +222,14 @@ void SpriteFramesEditor::_sheet_add_frames() {
|
|||
|
||||
int fc = frames->get_frame_count(edited_anim);
|
||||
|
||||
Point2 src_origin;
|
||||
Rect2 src_region(Point2(), texture_size);
|
||||
|
||||
AtlasTexture *src_atlas = Object::cast_to<AtlasTexture>(*split_sheet_preview->get_texture());
|
||||
if (src_atlas && src_atlas->get_atlas().is_valid()) {
|
||||
src_origin = src_atlas->get_region().position - src_atlas->get_margin().position;
|
||||
src_region = src_atlas->get_region();
|
||||
}
|
||||
|
||||
for (Set<int>::Element *E = frames_selected.front(); E; E = E->next()) {
|
||||
int idx = E->get();
|
||||
Point2 frame_coords(idx % frame_count_x, idx / frame_count_x);
|
||||
|
||||
Rect2 frame(frame_coords * frame_size + src_origin, frame_size);
|
||||
Rect2 region = frame.clip(src_region);
|
||||
Rect2 margin(region == Rect2() ? Point2() : region.position - frame.position, frame.size - region.size);
|
||||
|
||||
Ref<AtlasTexture> at;
|
||||
at.instance();
|
||||
at->set_atlas(split_sheet_preview->get_texture());
|
||||
at->set_region(region);
|
||||
at->set_margin(margin);
|
||||
at->set_region(Rect2(frame_coords * frame_size, frame_size));
|
||||
|
||||
undo_redo->add_do_method(frames, "add_frame", edited_anim, at, -1);
|
||||
undo_redo->add_undo_method(frames, "remove_frame", edited_anim, fc);
|
||||
|
|
|
@ -1005,8 +1005,7 @@ void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m
|
|||
rc.size.height = atlas->get_height();
|
||||
}
|
||||
|
||||
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
|
||||
VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(p_pos + margin.position, rc.size), atlas->get_rid(), rc, p_modulate, p_transpose, normal_rid, filter_clip);
|
||||
atlas->draw_rect_region(p_canvas_item, Rect2(p_pos + margin.position, rc.size), rc, p_modulate, p_transpose, p_normal_map);
|
||||
}
|
||||
|
||||
void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map) const {
|
||||
|
@ -1027,8 +1026,7 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile
|
|||
Vector2 scale = p_rect.size / (region.size + margin.size);
|
||||
Rect2 dr(p_rect.position + margin.position * scale, rc.size * scale);
|
||||
|
||||
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
|
||||
VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, dr, atlas->get_rid(), rc, p_modulate, p_transpose, normal_rid, filter_clip);
|
||||
atlas->draw_rect_region(p_canvas_item, dr, rc, p_modulate, p_transpose, p_normal_map);
|
||||
}
|
||||
void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map, bool p_clip_uv) const {
|
||||
//this might not necessarily work well if using a rect, needs to be fixed properly
|
||||
|
@ -1040,8 +1038,7 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons
|
|||
Rect2 src_c;
|
||||
get_rect_region(p_rect, p_src_rect, dr, src_c);
|
||||
|
||||
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
|
||||
VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, dr, atlas->get_rid(), src_c, p_modulate, p_transpose, normal_rid, filter_clip);
|
||||
atlas->draw_rect_region(p_canvas_item, dr, src_c, p_modulate, p_transpose, p_normal_map);
|
||||
}
|
||||
|
||||
bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const {
|
||||
|
|
Loading…
Reference in a new issue