SPE-1841: Use multi-material segmentation for all volumes of the model when at least one volume is painted.

For volumes that are not painted, we assume that they are entirely painted by the assigned extruder to this volume.
This commit is contained in:
Lukáš Hejl 2024-09-11 14:43:21 +02:00 committed by Lukas Matena
parent 8d8ee31283
commit 3edec09a2e
3 changed files with 21 additions and 13 deletions

View File

@ -1602,6 +1602,15 @@ static void update_color_changes_using_color_projection_ranges(std::vector<Color
}
}
static indexed_triangle_set_with_color extract_mesh_with_color(const ModelVolume &volume) {
if (const int volume_extruder_id = volume.extruder_id(); !volume.is_mm_painted() && volume_extruder_id >= 0) {
const TriangleMesh &mesh = volume.mesh();
return {mesh.its.indices, mesh.its.vertices, std::vector<uint8_t>(mesh.its.indices.size(), uint8_t(volume_extruder_id))};
}
return volume.mm_segmentation_facets.get_all_facets_strict_with_colors(volume);
}
std::vector<std::vector<ExPolygons>> multi_material_segmentation_by_painting(const PrintObject &print_object, const std::function<void()> &throw_on_cancel_callback)
{
const size_t num_extruders = print_object.print()->config().nozzle_diameter.size();
@ -1650,7 +1659,7 @@ std::vector<std::vector<ExPolygons>> multi_material_segmentation_by_painting(con
BOOST_LOG_TRIVIAL(debug) << "MM segmentation - Slicing painted triangles - Begin";
const std::vector<float> layer_zs = get_print_object_layers_zs(layers);
for (const ModelVolume *mv : print_object.model_object()->volumes) {
const indexed_triangle_set_with_color mesh_with_color = mv->mm_segmentation_facets.get_all_facets_strict_with_colors(*mv);
const indexed_triangle_set_with_color mesh_with_color = extract_mesh_with_color(*mv);
const Transform3d trafo = print_object.trafo_centered() * mv->get_matrix();
const MeshSlicingParams slicing_params{trafo};

View File

@ -1403,17 +1403,19 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
print_object_regions->ref_cnt_inc();
}
std::vector<unsigned int> painting_extruders;
if (const auto &volumes = print_object.model_object()->volumes;
num_extruders > 1 &&
std::find_if(volumes.begin(), volumes.end(), [](const ModelVolume *v) { return ! v->mm_segmentation_facets.empty(); }) != volumes.end()) {
if (const auto &volumes = print_object.model_object()->volumes; num_extruders > 1 && print_object.model_object()->is_mm_painted()) {
std::array<bool, static_cast<size_t>(TriangleStateType::Count)> used_facet_states{};
for (const ModelVolume *volume : volumes) {
const std::vector<bool> &volume_used_facet_states = volume->mm_segmentation_facets.get_data().used_states;
if (volume->is_mm_painted()) {
const std::vector<bool> &volume_used_facet_states = volume->mm_segmentation_facets.get_data().used_states;
assert(volume_used_facet_states.size() == used_facet_states.size());
for (size_t state_idx = 0; state_idx < std::min(volume_used_facet_states.size(), used_facet_states.size()); ++state_idx)
used_facet_states[state_idx] |= volume_used_facet_states[state_idx];
assert(volume_used_facet_states.size() == used_facet_states.size());
for (size_t state_idx = 0; state_idx < std::min(volume_used_facet_states.size(), used_facet_states.size()); ++state_idx) {
used_facet_states[state_idx] |= volume_used_facet_states[state_idx];
}
} else if (const int volume_extruder_id = volume->extruder_id(); volume_extruder_id >= 0) {
used_facet_states[volume_extruder_id] |= true;
}
}
for (size_t state_idx = static_cast<size_t>(TriangleStateType::Extruder1); state_idx < used_facet_states.size(); ++state_idx) {

View File

@ -753,10 +753,7 @@ void PrintObject::slice_volumes()
m_print->throw_if_canceled();
// Is any ModelVolume MMU painted?
if (const auto& volumes = this->model_object()->volumes;
m_print->config().nozzle_diameter.size() > 1 &&
std::find_if(volumes.begin(), volumes.end(), [](const ModelVolume* v) { return !v->mm_segmentation_facets.empty(); }) != volumes.end()) {
if (m_print->config().nozzle_diameter.size() > 1 && this->model_object()->is_mm_painted()) {
// If XY Size compensation is also enabled, notify the user that XY Size compensation
// would not be used because the object is multi-material painted.
if (m_config.xy_size_compensation.value != 0.f) {