Remap paint after split to objects

This commit is contained in:
Noisyfox
2026-05-09 16:18:49 +08:00
parent ff973dc937
commit 7bc8074e69
4 changed files with 12 additions and 4 deletions

View File

@@ -4450,7 +4450,7 @@ int CLI::run(int argc, char **argv)
size_t num_objects = model.objects.size();
for (size_t i = 0; i < num_objects; ++ i) {
ModelObjectPtrs new_objects;
model.objects.front()->split(&new_objects);
model.objects.front()->split(&new_objects, false); // TODO: add cli option to enable this?
model.delete_object(size_t(0));
}
}

View File

@@ -2028,13 +2028,14 @@ static void invalidate_translations(ModelObject* object, const ModelInstance* sr
}
}
void ModelObject::split(ModelObjectPtrs* new_objects)
void ModelObject::split(ModelObjectPtrs* new_objects, const bool remap_paint)
{
std::vector<TriangleMesh> all_meshes;
std::vector<Transform3d> all_transfos;
std::vector<std::pair<int, int>> volume_mesh_counts;
all_meshes.reserve(this->volumes.size() * 5);
bool is_multi_volume_object = (this->volumes.size() > 1);
std::optional<TriangleSelector::SavedPainting> saved_painting;
for (int volume_idx = 0; volume_idx < this->volumes.size(); volume_idx++) {
ModelVolume* volume = this->volumes[volume_idx];
@@ -2046,6 +2047,10 @@ void ModelObject::split(ModelObjectPtrs* new_objects)
volume->text_configuration.reset();
if (!is_multi_volume_object) {
if (remap_paint) {
// Save painting so we could restore them after the mesh split
saved_painting = volume->save_painting();
}
//BBS: not multi volume object, then split mesh.
std::vector<TriangleMesh> volume_meshes = volume->mesh().split();
int mesh_count = 0;
@@ -2123,6 +2128,9 @@ void ModelObject::split(ModelObjectPtrs* new_objects)
COPY_FACETS(seam_facets);
COPY_FACETS(mmu_segmentation_facets);
COPY_FACETS(fuzzy_skin_facets);
} else if (saved_painting) {
// Geometry changed, attempt to remap them to the new mesh
new_vol->restore_painting(saved_painting);
}
// BBS: clear volume's config, as we already set them into object

View File

@@ -516,7 +516,7 @@ public:
void delete_connectors();
void clone_for_cut(ModelObject **obj);
void split(ModelObjectPtrs*new_objects);
void split(ModelObjectPtrs*new_objects, bool remap_paint);
void merge();
// BBS: Boolean opts - Musang King

View File

@@ -7603,7 +7603,7 @@ void Plater::priv::split_object(int obj_idx, bool auto_drop /* = true */)
wxBusyCursor wait;
ModelObjectPtrs new_objects;
current_model_object->split(&new_objects);
current_model_object->split(&new_objects, wxGetApp().app_config->get_bool("keep_painting"));
if (new_objects.size() == 1)
// #ysFIXME use notification
Slic3r::GUI::warning_catcher(q, _L("The selected object couldn't be split."));