diff --git a/src/libslic3r/ModelArrange.cpp b/src/libslic3r/ModelArrange.cpp index 2a6677a6d..f88b131de 100644 --- a/src/libslic3r/ModelArrange.cpp +++ b/src/libslic3r/ModelArrange.cpp @@ -861,8 +861,37 @@ void find_new_position(const Model &model, // Create the arranger for the box shaped bed AutoArranger arrange(binbb, min_obj_distance); std::cout << "preload size: " << preshapes.front().size() << std::endl; + if(!preshapes.front().empty()) arrange.preload(preshapes); + auto shptrit = shapes_ptr.begin(); + for(auto shit = shapes.begin(); shit != shapes.end(); ++shit, ++shptrit) + { + // Try to place items to the center + Item& itm = *shit; + auto ibb = itm.boundingBox(); + auto d = ibb.center() - binbb.center(); + itm.translate(d); + if(!arrange.is_colliding(itm)) { + arrange.preload({{itm}}); + + auto offset = itm.translation(); + Radians rot = itm.rotation(); + ModelInstance *minst = *shptrit; + Vec3d foffset(offset.X*SCALING_FACTOR, + offset.Y*SCALING_FACTOR, + minst->get_offset()(Z)); + + // write the transformation data into the model instance + minst->set_rotation(Z, rot); + minst->set_offset(foffset); + + shit = shapes.erase(shit); + shptrit = shapes_ptr.erase(shptrit); + break; + } + } + // Arrange and return the items with their respective indices within the // input sequence. result = arrange(shapes.begin(), shapes.end());