FIX: when filling bed, some objects would be placed out of bed bound

Jira: STUDIO-11996

Change-Id: I149be826821c6ae9a1b33304086337fb7775dc68
This commit is contained in:
shan.chang 2025-05-09 14:46:52 +08:00 committed by lane.wei
parent ac805e7d91
commit 58387fd0d5

View File

@ -230,11 +230,16 @@ void FillBedJob::process()
if (m_selected.size() > 100){
// too many items, just find grid empty cells to put them
Vec2f step = unscaled<float>(get_extents(m_selected.front().poly).size()) + Vec2f(m_selected.front().brim_width, m_selected.front().brim_width);
Vec2f step = unscaled<float>(get_extents(m_selected.front().poly).size()) + 2 * Vec2f(m_selected.front().brim_width, m_selected.front().brim_width);
// calc the polygon position offset based on origin, in order to normalize the initial position of the arrange polygon
auto offset_on_origin = m_selected.front().poly.contour.bounding_box().center();
std::vector<Vec2f> empty_cells = Plater::get_empty_cells(step);
size_t n=std::min(m_selected.size(), empty_cells.size());
for (size_t i = 0; i < n; i++) {
m_selected[i].translation = scaled<coord_t>(empty_cells[i]);
m_selected[i].translation -= offset_on_origin;
m_selected[i].bed_idx= 0;
}
for (size_t i = n; i < m_selected.size(); i++) {