mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-20 20:03:47 +00:00
Remap paint after mesh boolean (from context menu)
This commit is contained in:
@@ -3225,6 +3225,22 @@ void ObjectList::boolean()
|
|||||||
Plater::TakeSnapshot snapshot(wxGetApp().plater(), "boolean");
|
Plater::TakeSnapshot snapshot(wxGetApp().plater(), "boolean");
|
||||||
|
|
||||||
ModelObject* object = (*m_objects)[obj_idxs.front()];
|
ModelObject* object = (*m_objects)[obj_idxs.front()];
|
||||||
|
|
||||||
|
const bool keep_painting = wxGetApp().app_config->get_bool("keep_painting");
|
||||||
|
std::vector<std::optional<TriangleSelector::SavedPainting>> saved_paintings;
|
||||||
|
if (keep_painting) {
|
||||||
|
// Save painting of all the positive parts
|
||||||
|
saved_paintings.reserve(object->volumes.size());
|
||||||
|
for (const ModelVolume* vol : object->volumes) {
|
||||||
|
if (vol && vol->mesh_ptr() && vol->is_model_part() && vol->is_any_painted()) {
|
||||||
|
saved_paintings.emplace_back(vol->save_painting());
|
||||||
|
if (saved_paintings.back()) {
|
||||||
|
saved_paintings.back()->mesh.transform(vol->get_matrix(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TriangleMesh mesh = Plater::combine_mesh_fff(*object, -1, [this](const std::string& msg) {return wxGetApp().notification_manager()->push_plater_error_notification(msg); });
|
TriangleMesh mesh = Plater::combine_mesh_fff(*object, -1, [this](const std::string& msg) {return wxGetApp().notification_manager()->push_plater_error_notification(msg); });
|
||||||
|
|
||||||
// add mesh to model as a new object, keep the original object's name and config
|
// add mesh to model as a new object, keep the original object's name and config
|
||||||
@@ -3236,6 +3252,29 @@ void ObjectList::boolean()
|
|||||||
new_object->add_instance();
|
new_object->add_instance();
|
||||||
ModelVolume* new_volume = new_object->add_volume(mesh);
|
ModelVolume* new_volume = new_object->add_volume(mesh);
|
||||||
|
|
||||||
|
// Remap paint
|
||||||
|
if (keep_painting) {
|
||||||
|
for (auto& saved_painting : saved_paintings) {
|
||||||
|
if (saved_painting) {
|
||||||
|
// For each original painted volume, we need to apply to each instance
|
||||||
|
// because we merged all instances into one in `combine_mesh_fff`
|
||||||
|
|
||||||
|
// First we save the non-instance-translated mesh
|
||||||
|
TriangleMesh vols_mesh(std::move(saved_painting->mesh));
|
||||||
|
|
||||||
|
for (const ModelInstance* i : object->instances) {
|
||||||
|
// Then for each instance, we apply the paint at the given instance place
|
||||||
|
saved_painting->mesh = vols_mesh;
|
||||||
|
saved_painting->mesh.transform(i->get_matrix());
|
||||||
|
|
||||||
|
// Then paint it
|
||||||
|
new_volume->restore_painting(saved_painting, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// BBS: ensure on bed but no need to ensure locate in the center around origin
|
// BBS: ensure on bed but no need to ensure locate in the center around origin
|
||||||
new_object->ensure_on_bed();
|
new_object->ensure_on_bed();
|
||||||
new_object->center_around_origin();
|
new_object->center_around_origin();
|
||||||
|
|||||||
@@ -15108,7 +15108,7 @@ TriangleMesh Plater::combine_mesh_fff(const ModelObject& mo, int instance_id, st
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (instance_id == -1) {
|
if (instance_id == -1) {
|
||||||
TriangleMesh vols_mesh(mesh);
|
TriangleMesh vols_mesh(std::move(mesh));
|
||||||
mesh = TriangleMesh();
|
mesh = TriangleMesh();
|
||||||
for (const ModelInstance* i : mo.instances) {
|
for (const ModelInstance* i : mo.instances) {
|
||||||
TriangleMesh m = vols_mesh;
|
TriangleMesh m = vols_mesh;
|
||||||
|
|||||||
Reference in New Issue
Block a user