mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-21 05:37:52 -06:00
Automatic placement of instance at bed level
This commit is contained in:
parent
66e97aa4eb
commit
503166a6a4
6 changed files with 193 additions and 6 deletions
|
@ -1478,6 +1478,98 @@ void GLCanvas3D::Selection::mirror(Axis axis)
|
|||
}
|
||||
#endif // ENABLE_MIRROR
|
||||
|
||||
void GLCanvas3D::Selection::translate(unsigned int object_idx, const Vec3d& displacement)
|
||||
{
|
||||
if (!m_valid)
|
||||
return;
|
||||
|
||||
for (unsigned int i : m_list)
|
||||
{
|
||||
GLVolume* v = (*m_volumes)[i];
|
||||
if (v->object_idx() == object_idx)
|
||||
v->set_offset(v->get_offset() + displacement);
|
||||
}
|
||||
|
||||
std::set<unsigned int> done; // prevent processing volumes twice
|
||||
done.insert(m_list.begin(), m_list.end());
|
||||
|
||||
for (unsigned int i : m_list)
|
||||
{
|
||||
if (done.size() == m_volumes->size())
|
||||
break;
|
||||
|
||||
const GLVolume* volume = (*m_volumes)[i];
|
||||
int object_idx = volume->object_idx();
|
||||
if (object_idx >= 1000)
|
||||
continue;
|
||||
|
||||
// Process unselected volumes of the object.
|
||||
for (unsigned int j = 0; j < (unsigned int)m_volumes->size(); ++j)
|
||||
{
|
||||
if (done.size() == m_volumes->size())
|
||||
break;
|
||||
|
||||
if (done.find(j) != done.end())
|
||||
continue;
|
||||
|
||||
GLVolume* v = (*m_volumes)[j];
|
||||
if (v->object_idx() != object_idx)
|
||||
continue;
|
||||
|
||||
v->set_offset(v->get_offset() + displacement);
|
||||
done.insert(j);
|
||||
}
|
||||
}
|
||||
|
||||
m_bounding_box_dirty = true;
|
||||
}
|
||||
|
||||
void GLCanvas3D::Selection::translate(unsigned int object_idx, unsigned int instance_idx, const Vec3d& displacement)
|
||||
{
|
||||
if (!m_valid)
|
||||
return;
|
||||
|
||||
for (unsigned int i : m_list)
|
||||
{
|
||||
GLVolume* v = (*m_volumes)[i];
|
||||
if ((v->object_idx() == object_idx) && (v->instance_idx() == instance_idx))
|
||||
v->set_offset(v->get_offset() + displacement);
|
||||
}
|
||||
|
||||
std::set<unsigned int> done; // prevent processing volumes twice
|
||||
done.insert(m_list.begin(), m_list.end());
|
||||
|
||||
for (unsigned int i : m_list)
|
||||
{
|
||||
if (done.size() == m_volumes->size())
|
||||
break;
|
||||
|
||||
const GLVolume* volume = (*m_volumes)[i];
|
||||
int object_idx = volume->object_idx();
|
||||
if (object_idx >= 1000)
|
||||
continue;
|
||||
|
||||
// Process unselected volumes of the object.
|
||||
for (unsigned int j = 0; j < (unsigned int)m_volumes->size(); ++j)
|
||||
{
|
||||
if (done.size() == m_volumes->size())
|
||||
break;
|
||||
|
||||
if (done.find(j) != done.end())
|
||||
continue;
|
||||
|
||||
GLVolume* v = (*m_volumes)[j];
|
||||
if ((v->object_idx() != object_idx) || (v->instance_idx() != instance_idx))
|
||||
continue;
|
||||
|
||||
v->set_offset(v->get_offset() + displacement);
|
||||
done.insert(j);
|
||||
}
|
||||
}
|
||||
|
||||
m_bounding_box_dirty = true;
|
||||
}
|
||||
|
||||
void GLCanvas3D::Selection::render(bool show_indirect_selection) const
|
||||
{
|
||||
if (is_empty())
|
||||
|
@ -6666,6 +6758,14 @@ void GLCanvas3D::_on_move()
|
|||
wipe_tower_origin = v->get_offset();
|
||||
}
|
||||
|
||||
for (const std::pair<int, int>& i : done)
|
||||
{
|
||||
ModelObject* m = m_model->objects[i.first];
|
||||
Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second));
|
||||
m_selection.translate(i.first, i.second, shift);
|
||||
m->translate_instance(i.second, shift);
|
||||
}
|
||||
|
||||
if (object_moved)
|
||||
post_event(SimpleEvent(EVT_GLCANVAS_INSTANCE_MOVED));
|
||||
|
||||
|
@ -6700,10 +6800,19 @@ void GLCanvas3D::_on_rotate()
|
|||
if (model_object != nullptr)
|
||||
{
|
||||
model_object->instances[instance_idx]->set_rotation(v->get_rotation());
|
||||
model_object->instances[instance_idx]->set_offset(v->get_offset());
|
||||
model_object->invalidate_bounding_box();
|
||||
}
|
||||
}
|
||||
|
||||
for (const std::pair<int, int>& i : done)
|
||||
{
|
||||
ModelObject* m = m_model->objects[i.first];
|
||||
Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second));
|
||||
m_selection.translate(i.first, i.second, shift);
|
||||
m->translate_instance(i.second, shift);
|
||||
}
|
||||
|
||||
post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
|
||||
}
|
||||
|
||||
|
@ -6734,10 +6843,19 @@ void GLCanvas3D::_on_scale()
|
|||
if (model_object != nullptr)
|
||||
{
|
||||
model_object->instances[instance_idx]->set_scaling_factor(v->get_scaling_factor());
|
||||
model_object->instances[instance_idx]->set_offset(v->get_offset());
|
||||
model_object->invalidate_bounding_box();
|
||||
}
|
||||
}
|
||||
|
||||
for (const std::pair<int, int>& i : done)
|
||||
{
|
||||
ModelObject* m = m_model->objects[i.first];
|
||||
Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second));
|
||||
m_selection.translate(i.first, i.second, shift);
|
||||
m->translate_instance(i.second, shift);
|
||||
}
|
||||
|
||||
post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
|
||||
}
|
||||
|
||||
|
|
|
@ -508,6 +508,9 @@ public:
|
|||
void mirror(Axis axis);
|
||||
#endif // ENABLE_MIRROR
|
||||
|
||||
void translate(unsigned int object_idx, const Vec3d& displacement);
|
||||
void translate(unsigned int object_idx, unsigned int instance_idx, const Vec3d& displacement);
|
||||
|
||||
void render(bool show_indirect_selection) const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -706,6 +706,7 @@ void ObjectList::load_part( ModelObject* model_object,
|
|||
if (model_object->origin_translation != Vec3d::Zero())
|
||||
{
|
||||
object->center_around_origin();
|
||||
object->ensure_on_bed();
|
||||
delta = model_object->origin_translation - object->origin_translation;
|
||||
}
|
||||
for (auto volume : object->volumes) {
|
||||
|
|
|
@ -1151,6 +1151,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_
|
|||
if (type_3mf) {
|
||||
for (ModelObject* model_object : model.objects) {
|
||||
model_object->center_around_origin();
|
||||
model_object->ensure_on_bed();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1235,6 +1236,8 @@ std::vector<size_t> Plater::priv::load_model_objects(const ModelObjectPtrs &mode
|
|||
}
|
||||
}
|
||||
|
||||
object->ensure_on_bed();
|
||||
|
||||
// print.auto_assign_extruders(object);
|
||||
// print.add_model_object(object);
|
||||
}
|
||||
|
@ -1628,6 +1631,7 @@ void Plater::priv::split_object()
|
|||
{
|
||||
m->name = current_model_object->name + "_" + std::to_string(counter++);
|
||||
m->center_around_origin();
|
||||
m->ensure_on_bed();
|
||||
}
|
||||
|
||||
remove(obj_idx);
|
||||
|
@ -2552,6 +2556,7 @@ void Plater::changed_object_settings(int obj_idx)
|
|||
// recenter and re - align to Z = 0
|
||||
auto model_object = p->model.objects[obj_idx];
|
||||
model_object->center_around_origin();
|
||||
model_object->ensure_on_bed();
|
||||
}
|
||||
|
||||
// update print
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue