fix triangle selector painting on models with transformation

This commit is contained in:
PavelMikus 2022-08-15 13:03:37 +02:00
parent 4eaa863ba4
commit 970c9e033d
4 changed files with 12 additions and 13 deletions

View File

@ -428,14 +428,14 @@ void PrintObject::generate_support_spots()
auto obj_transform = this->trafo_centered(); auto obj_transform = this->trafo_centered();
for (ModelVolume *model_volume : this->model_object()->volumes) { for (ModelVolume *model_volume : this->model_object()->volumes) {
if (model_volume->is_model_part()) { if (model_volume->is_model_part()) {
Transform3d model_transformation = model_volume->get_matrix(); Transform3d mesh_transformation = obj_transform * model_volume->get_matrix();
Transform3f inv_transform = (obj_transform * model_transformation).inverse().cast<float>(); Transform3d inv_transform = mesh_transformation.inverse();
TriangleSelectorWrapper selector { model_volume->mesh() }; TriangleSelectorWrapper selector { model_volume->mesh(), mesh_transformation};
for (const SupportSpotsGenerator::SupportPoint &support_point : issues.support_points) { for (const SupportSpotsGenerator::SupportPoint &support_point : issues.support_points) {
Vec3f point = Vec3f(inv_transform * support_point.position); Vec3f point = Vec3f(inv_transform.cast<float>() * support_point.position);
Vec3f origin = Vec3f( Vec3f origin = Vec3f(
inv_transform * Vec3f(support_point.position.x(), support_point.position.y(), 0.0f)); inv_transform.cast<float>() * Vec3f(support_point.position.x(), support_point.position.y(), 0.0f));
selector.enforce_spot(point, origin, 1.5f); selector.enforce_spot(point, origin, 1.5f);
} }

View File

@ -984,8 +984,6 @@ Issues check_global_stability(SupportGridFilter supports_presence_grid,
for (size_t island_idx = 0; island_idx < islands_graph[layer_idx].islands.size(); ++island_idx) { for (size_t island_idx = 0; island_idx < islands_graph[layer_idx].islands.size(); ++island_idx) {
const Island &island = islands_graph[layer_idx].islands[island_idx]; const Island &island = islands_graph[layer_idx].islands[island_idx];
ObjectPart &part = active_object_parts.access(prev_island_to_object_part_mapping[island_idx]); ObjectPart &part = active_object_parts.access(prev_island_to_object_part_mapping[island_idx]);
IslandConnection &weakest_conn = prev_island_weakest_connection[island_idx]; IslandConnection &weakest_conn = prev_island_weakest_connection[island_idx];
#ifdef DETAILED_DEBUG_LOGS #ifdef DETAILED_DEBUG_LOGS
weakest_conn.print_info("weakest connection info: "); weakest_conn.print_info("weakest connection info: ");

View File

@ -1,11 +1,10 @@
#include "Model.hpp"
#include "TriangleSelectorWrapper.hpp" #include "TriangleSelectorWrapper.hpp"
#include <memory> #include <memory>
namespace Slic3r { namespace Slic3r {
TriangleSelectorWrapper::TriangleSelectorWrapper(const TriangleMesh &mesh) : TriangleSelectorWrapper::TriangleSelectorWrapper(const TriangleMesh &mesh, const Transform3d& mesh_transform) :
mesh(mesh), selector(mesh), triangles_tree( mesh(mesh), mesh_transform(mesh_transform), selector(mesh), triangles_tree(
AABBTreeIndirect::build_aabb_tree_over_indexed_triangle_set(mesh.its.vertices, mesh.its.indices)) { AABBTreeIndirect::build_aabb_tree_over_indexed_triangle_set(mesh.its.vertices, mesh.its.indices)) {
} }
@ -23,7 +22,7 @@ void TriangleSelectorWrapper::enforce_spot(const Vec3f &point, const Vec3f &orig
Vec3f face_normal = its_face_normal(mesh.its, hit.id); Vec3f face_normal = its_face_normal(mesh.its, hit.id);
if ((point - pos).norm() < radius && face_normal.dot(dir) < 0) { if ((point - pos).norm() < radius && face_normal.dot(dir) < 0) {
std::unique_ptr<TriangleSelector::Cursor> cursor = std::make_unique<TriangleSelector::Sphere>( std::unique_ptr<TriangleSelector::Cursor> cursor = std::make_unique<TriangleSelector::Sphere>(
pos, origin, radius, Transform3d::Identity(), TriangleSelector::ClippingPlane { }); pos, origin, radius, this->mesh_transform, TriangleSelector::ClippingPlane { });
selector.select_patch(hit.id, std::move(cursor), EnforcerBlockerType::ENFORCER, Transform3d::Identity(), selector.select_patch(hit.id, std::move(cursor), EnforcerBlockerType::ENFORCER, Transform3d::Identity(),
true, 0.0f); true, 0.0f);
break; break;
@ -36,7 +35,7 @@ void TriangleSelectorWrapper::enforce_spot(const Vec3f &point, const Vec3f &orig
triangles_tree, point, hit_idx_out, hit_point_out); triangles_tree, point, hit_idx_out, hit_point_out);
if (dist < radius) { if (dist < radius) {
std::unique_ptr<TriangleSelector::Cursor> cursor = std::make_unique<TriangleSelector::Sphere>( std::unique_ptr<TriangleSelector::Cursor> cursor = std::make_unique<TriangleSelector::Sphere>(
point, origin, radius, Transform3d::Identity(), TriangleSelector::ClippingPlane { }); point, origin, radius, this->mesh_transform, TriangleSelector::ClippingPlane { });
selector.select_patch(hit_idx_out, std::move(cursor), EnforcerBlockerType::ENFORCER, selector.select_patch(hit_idx_out, std::move(cursor), EnforcerBlockerType::ENFORCER,
Transform3d::Identity(), Transform3d::Identity(),
true, 0.0f); true, 0.0f);

View File

@ -2,6 +2,7 @@
#define SRC_LIBSLIC3R_TRIANGLESELECTORWRAPPER_HPP_ #define SRC_LIBSLIC3R_TRIANGLESELECTORWRAPPER_HPP_
#include "TriangleSelector.hpp" #include "TriangleSelector.hpp"
#include "Model.hpp"
#include "AABBTreeIndirect.hpp" #include "AABBTreeIndirect.hpp"
namespace Slic3r { namespace Slic3r {
@ -15,10 +16,11 @@ namespace Slic3r {
class TriangleSelectorWrapper { class TriangleSelectorWrapper {
public: public:
const TriangleMesh &mesh; const TriangleMesh &mesh;
const Transform3d& mesh_transform;
TriangleSelector selector; TriangleSelector selector;
AABBTreeIndirect::Tree<3, float> triangles_tree; AABBTreeIndirect::Tree<3, float> triangles_tree;
TriangleSelectorWrapper(const TriangleMesh &mesh); TriangleSelectorWrapper(const TriangleMesh &mesh, const Transform3d& mesh_transform);
void enforce_spot(const Vec3f &point, const Vec3f& origin, float radius); void enforce_spot(const Vec3f &point, const Vec3f& origin, float radius);