mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-18 19:12:17 +00:00
Rearrange code a little bit to make it more reusable
This commit is contained in:
@@ -14,27 +14,6 @@ namespace Slic3r {
|
|||||||
|
|
||||||
using namespace Geometry;
|
using namespace Geometry;
|
||||||
|
|
||||||
// Remap painting data from saved source to a cut result mesh, and set on a volume.
|
|
||||||
static void remap_and_set_painting(ModelVolume* vol, const std::optional<TriangleSelector::SavedPainting>& saved)
|
|
||||||
{
|
|
||||||
if (!saved) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto remap_one = [&](const TriangleSelector::TriangleSplittingData& src_data,
|
|
||||||
FacetsAnnotation& target_facets) {
|
|
||||||
if (src_data.bitstream.empty())
|
|
||||||
return;
|
|
||||||
auto result = TriangleSelector::remap_painting(saved->mesh.its, src_data, vol->mesh().its, translation_transform(vol->mesh().get_init_shift()));
|
|
||||||
if (!result.bitstream.empty())
|
|
||||||
target_facets.set_data(result);
|
|
||||||
};
|
|
||||||
remap_one(saved->supported, vol->supported_facets);
|
|
||||||
remap_one(saved->seam, vol->seam_facets);
|
|
||||||
remap_one(saved->mmu, vol->mmu_segmentation_facets);
|
|
||||||
remap_one(saved->fuzzy, vol->fuzzy_skin_facets);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void apply_tolerance(ModelVolume* vol)
|
static void apply_tolerance(ModelVolume* vol)
|
||||||
{
|
{
|
||||||
ModelVolume::CutInfo& cut_info = vol->cut_info;
|
ModelVolume::CutInfo& cut_info = vol->cut_info;
|
||||||
@@ -213,24 +192,24 @@ static void process_solid_part_cut(ModelVolume* volume, const Transform3d& insta
|
|||||||
if (attributes.has(ModelObjectCutAttribute::KeepAsParts)) {
|
if (attributes.has(ModelObjectCutAttribute::KeepAsParts)) {
|
||||||
if (!upper_mesh.empty()) {
|
if (!upper_mesh.empty()) {
|
||||||
add_cut_volume(upper_mesh, upper, volume, cut_matrix, "_A");
|
add_cut_volume(upper_mesh, upper, volume, cut_matrix, "_A");
|
||||||
remap_and_set_painting(upper->volumes.back(), saved_painting);
|
upper->volumes.back()->restore_painting(saved_painting);
|
||||||
}
|
}
|
||||||
if (!lower_mesh.empty()) {
|
if (!lower_mesh.empty()) {
|
||||||
add_cut_volume(lower_mesh, upper, volume, cut_matrix, "_B");
|
add_cut_volume(lower_mesh, upper, volume, cut_matrix, "_B");
|
||||||
upper->volumes.back()->cut_info.is_from_upper = false;
|
upper->volumes.back()->cut_info.is_from_upper = false;
|
||||||
remap_and_set_painting(upper->volumes.back(), saved_painting);
|
upper->volumes.back()->restore_painting(saved_painting);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attributes.has(ModelObjectCutAttribute::KeepUpper) && !upper_mesh.empty()) {
|
if (attributes.has(ModelObjectCutAttribute::KeepUpper) && !upper_mesh.empty()) {
|
||||||
add_cut_volume(upper_mesh, upper, volume, cut_matrix);
|
add_cut_volume(upper_mesh, upper, volume, cut_matrix);
|
||||||
remap_and_set_painting(upper->volumes.back(), saved_painting);
|
upper->volumes.back()->restore_painting(saved_painting);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attributes.has(ModelObjectCutAttribute::KeepLower) && !lower_mesh.empty()) {
|
if (attributes.has(ModelObjectCutAttribute::KeepLower) && !lower_mesh.empty()) {
|
||||||
add_cut_volume(lower_mesh, lower, volume, cut_matrix);
|
add_cut_volume(lower_mesh, lower, volume, cut_matrix);
|
||||||
remap_and_set_painting(lower->volumes.back(), saved_painting);
|
lower->volumes.back()->restore_painting(saved_painting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1980,6 +1980,41 @@ void ModelVolume::reset_extra_facets()
|
|||||||
this->fuzzy_skin_facets.reset();
|
this->fuzzy_skin_facets.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<TriangleSelector::SavedPainting> ModelVolume::save_painting() const
|
||||||
|
{
|
||||||
|
if (is_any_painted() && is_model_part() && !mesh().empty()) {
|
||||||
|
TriangleSelector::SavedPainting sp;
|
||||||
|
sp.mesh = mesh();
|
||||||
|
sp.supported = supported_facets.get_data();
|
||||||
|
sp.seam = seam_facets.get_data();
|
||||||
|
sp.mmu = mmu_segmentation_facets.get_data();
|
||||||
|
sp.fuzzy = fuzzy_skin_facets.get_data();
|
||||||
|
return sp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelVolume::restore_painting(const std::optional<TriangleSelector::SavedPainting>& saved)
|
||||||
|
{
|
||||||
|
if (!saved) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto remap_one = [&](const TriangleSelector::TriangleSplittingData& src_data,
|
||||||
|
FacetsAnnotation& target_facets) {
|
||||||
|
if (src_data.bitstream.empty())
|
||||||
|
return;
|
||||||
|
auto result = TriangleSelector::remap_painting(saved->mesh.its, src_data, mesh().its, Geometry::translation_transform(mesh().get_init_shift()));
|
||||||
|
if (!result.bitstream.empty())
|
||||||
|
target_facets.set_data(result);
|
||||||
|
};
|
||||||
|
remap_one(saved->supported, supported_facets);
|
||||||
|
remap_one(saved->seam, seam_facets);
|
||||||
|
remap_one(saved->mmu, mmu_segmentation_facets);
|
||||||
|
remap_one(saved->fuzzy, fuzzy_skin_facets);
|
||||||
|
}
|
||||||
|
|
||||||
static void invalidate_translations(ModelObject* object, const ModelInstance* src_instance)
|
static void invalidate_translations(ModelObject* object, const ModelInstance* src_instance)
|
||||||
{
|
{
|
||||||
if (!object->origin_translation.isApprox(Vec3d::Zero()) && src_instance->get_offset().isApprox(Vec3d::Zero())) {
|
if (!object->origin_translation.isApprox(Vec3d::Zero()) && src_instance->get_offset().isApprox(Vec3d::Zero())) {
|
||||||
|
|||||||
@@ -881,20 +881,10 @@ public:
|
|||||||
// Save painting data before reset_extra_facets() discards it.
|
// Save painting data before reset_extra_facets() discards it.
|
||||||
// Used for replacing mesh without losing painting data.
|
// Used for replacing mesh without losing painting data.
|
||||||
// Only for model parts (not modifiers/connectors).
|
// Only for model parts (not modifiers/connectors).
|
||||||
std::optional<TriangleSelector::SavedPainting> save_painting() const
|
std::optional<TriangleSelector::SavedPainting> save_painting() const;
|
||||||
{
|
|
||||||
if (is_any_painted() && is_model_part() && !mesh().empty()) {
|
|
||||||
TriangleSelector::SavedPainting sp;
|
|
||||||
sp.mesh = mesh();
|
|
||||||
sp.supported = supported_facets.get_data();
|
|
||||||
sp.seam = seam_facets.get_data();
|
|
||||||
sp.mmu = mmu_segmentation_facets.get_data();
|
|
||||||
sp.fuzzy = fuzzy_skin_facets.get_data();
|
|
||||||
return sp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
// Remap painting data from previous saved source to this mesh
|
||||||
}
|
void restore_painting(const std::optional<TriangleSelector::SavedPainting>& saved);
|
||||||
|
|
||||||
// BBS: quick access for volume extruders, 1 based
|
// BBS: quick access for volume extruders, 1 based
|
||||||
mutable std::vector<int> mmuseg_extruders;
|
mutable std::vector<int> mmuseg_extruders;
|
||||||
|
|||||||
Reference in New Issue
Block a user