Skip to content

Commit

Permalink
Fix: invalid distance from surface when load from 3mf
Browse files Browse the repository at this point in the history
  • Loading branch information
Jony01 committed Dec 8, 2023
1 parent 834f6ef commit e1d9393
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/libslic3r/EmbossShape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct EmbossShape
// Note: image is only cache it is not neccessary to store

// Store file data as plain string
assert(file_data != nullptr);
// For Embossed text file_data are nullptr
ar(path, path_in_3mf, (file_data != nullptr) ? *file_data : std::string(""));
}
template<class Archive> void load(Archive &ar) {
Expand Down
13 changes: 9 additions & 4 deletions src/slic3r/GUI/SurfaceDrag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,20 @@ std::optional<float> calc_distance(const GLVolume &gl_volume, RaycastManager &ra
if (volume->is_the_only_one_part())
return {};

if (!volume->emboss_shape.has_value())
return {};

RaycastManager::AllowVolumes condition = create_condition(object->volumes, volume->id());
RaycastManager::Meshes meshes = create_meshes(canvas, condition);
raycaster.actualize(*instance, &condition, &meshes);
return calc_distance(gl_volume, raycaster, &condition);
return calc_distance(gl_volume, raycaster, &condition, volume->emboss_shape->fix_3mf_tr);
}

std::optional<float> calc_distance(const GLVolume &gl_volume, const RaycastManager &raycaster, const RaycastManager::ISkip *condition)
{
std::optional<float> calc_distance(const GLVolume &gl_volume, const RaycastManager &raycaster,
const RaycastManager::ISkip *condition, const std::optional<Slic3r::Transform3d>& fix) {
Transform3d w = gl_volume.world_matrix();
if (fix.has_value())
w = w * fix->inverse();
Vec3d p = w.translation();
Vec3d dir = -get_z_base(w);
auto hit_opt = raycaster.closest_hit(p, dir, condition);
Expand Down Expand Up @@ -589,7 +594,7 @@ bool start_dragging(const Vec2d &mouse_pos,

std::optional<float> start_distance;
if (!volume->emboss_shape->projection.use_surface)
start_distance = calc_distance(gl_volume, raycast_manager, &condition);
start_distance = calc_distance(gl_volume, raycast_manager, &condition, volume->emboss_shape->fix_3mf_tr);
surface_drag = SurfaceDrag{mouse_offset, world_tr, instance_tr_inv,
gl_volume_ptr, condition, start_angle,
start_distance, true, mouse_offset_without_sla_shift};
Expand Down
3 changes: 2 additions & 1 deletion src/slic3r/GUI/SurfaceDrag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ std::optional<Vec3d> calc_surface_offset(const Selection &selection, RaycastMana
/// <param name="canvas">Contain model</param>
/// <returns>Calculated distance from surface</returns>
std::optional<float> calc_distance(const GLVolume &gl_volume, RaycastManager &raycaster, GLCanvas3D &canvas);
std::optional<float> calc_distance(const GLVolume &gl_volume, const RaycastManager &raycaster, const RaycastManager::ISkip *condition);
std::optional<float> calc_distance(const GLVolume &gl_volume, const RaycastManager &raycaster,
const RaycastManager::ISkip *condition, const std::optional<Slic3r::Transform3d>& fix);

/// <summary>
/// Calculate up vector angle
Expand Down

0 comments on commit e1d9393

Please sign in to comment.