mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Cut: Use world coordinates
This commit is contained in:
parent
c29493a41b
commit
25f4f1fe55
3 changed files with 13 additions and 14 deletions
|
@ -1005,15 +1005,10 @@ ModelObjectPtrs ModelObject::cut(size_t instance, coordf_t z, bool keep_upper, b
|
||||||
|
|
||||||
// Because transformations are going to be applied to meshes directly,
|
// Because transformations are going to be applied to meshes directly,
|
||||||
// we reset transformation of all instances and volumes,
|
// we reset transformation of all instances and volumes,
|
||||||
// _except_ for translation, which is preserved in the transformation matrix
|
// except for translation, which is preserved in the transformation matrix
|
||||||
// and not applied to the mesh transform.
|
// and not applied to the mesh transform.
|
||||||
// TODO: Do the same for Z-rotation as well?
|
// TODO: Do the same for Z-rotation as well?
|
||||||
|
|
||||||
// Convert z from relative to bb's base to object coordinates
|
|
||||||
// FIXME: doesn't work well for rotated objects
|
|
||||||
const auto bb = instance_bounding_box(instance, true);
|
|
||||||
z -= bb.min(2);
|
|
||||||
|
|
||||||
if (keep_upper) {
|
if (keep_upper) {
|
||||||
for (auto *instance : upper->instances) { cut_reset_transform(instance); }
|
for (auto *instance : upper->instances) { cut_reset_transform(instance); }
|
||||||
}
|
}
|
||||||
|
@ -1030,11 +1025,15 @@ ModelObjectPtrs ModelObject::cut(size_t instance, coordf_t z, bool keep_upper, b
|
||||||
TriangleMesh upper_mesh, lower_mesh;
|
TriangleMesh upper_mesh, lower_mesh;
|
||||||
|
|
||||||
// Transform the mesh by the object transformation matrix
|
// Transform the mesh by the object transformation matrix
|
||||||
volume->mesh.transform(instance_matrix * volume->get_matrix(true));
|
const auto volume_tr = instance_matrix * volume->get_matrix(true);
|
||||||
|
volume->mesh.transform(volume_tr);
|
||||||
cut_reset_transform(volume);
|
cut_reset_transform(volume);
|
||||||
|
|
||||||
|
// Transform z from world to object
|
||||||
|
const auto local_z = volume_tr * Vec3d(0.0, 0.0, z);
|
||||||
|
|
||||||
TriangleMeshSlicer tms(&volume->mesh);
|
TriangleMeshSlicer tms(&volume->mesh);
|
||||||
tms.cut(z, &upper_mesh, &lower_mesh);
|
tms.cut(local_z(2), &upper_mesh, &lower_mesh);
|
||||||
|
|
||||||
if (keep_upper) {
|
if (keep_upper) {
|
||||||
upper_mesh.repair();
|
upper_mesh.repair();
|
||||||
|
|
|
@ -238,7 +238,7 @@ public:
|
||||||
size_t materials_count() const;
|
size_t materials_count() const;
|
||||||
size_t facets_count() const;
|
size_t facets_count() const;
|
||||||
bool needed_repair() const;
|
bool needed_repair() const;
|
||||||
ModelObjectPtrs cut(size_t instance, coordf_t z, bool keep_upper = true, bool keep_lower = true, bool rotate_lower = false);
|
ModelObjectPtrs cut(size_t instance, coordf_t z, bool keep_upper = true, bool keep_lower = true, bool rotate_lower = false); // Note: z is in world coordinates
|
||||||
void split(ModelObjectPtrs* new_objects);
|
void split(ModelObjectPtrs* new_objects);
|
||||||
void repair();
|
void repair();
|
||||||
|
|
||||||
|
|
|
@ -1992,7 +1992,7 @@ void GLGizmoCut::on_set_state()
|
||||||
{
|
{
|
||||||
// Reset m_cut_z on gizmo activation
|
// Reset m_cut_z on gizmo activation
|
||||||
if (get_state() == On) {
|
if (get_state() == On) {
|
||||||
m_cut_z = 0.0;
|
m_cut_z = m_parent.get_selection().get_bounding_box().size()(2) / 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef ENABLE_IMGUI
|
#ifndef ENABLE_IMGUI
|
||||||
|
@ -2014,10 +2014,10 @@ void GLGizmoCut::on_start_dragging(const GLCanvas3D::Selection& selection)
|
||||||
|
|
||||||
const BoundingBoxf3& box = selection.get_bounding_box();
|
const BoundingBoxf3& box = selection.get_bounding_box();
|
||||||
m_start_z = m_cut_z;
|
m_start_z = m_cut_z;
|
||||||
m_max_z = box.size()(2) / 2.0;
|
m_max_z = box.size()(2);
|
||||||
m_drag_pos = m_grabbers[m_hover_id].center;
|
m_drag_pos = m_grabbers[m_hover_id].center;
|
||||||
m_drag_center = box.center();
|
m_drag_center = box.center();
|
||||||
m_drag_center(2) += m_cut_z;
|
m_drag_center(2) = m_cut_z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoCut::on_update(const UpdateData& data)
|
void GLGizmoCut::on_update(const UpdateData& data)
|
||||||
|
@ -2025,7 +2025,7 @@ void GLGizmoCut::on_update(const UpdateData& data)
|
||||||
if (m_hover_id != -1) {
|
if (m_hover_id != -1) {
|
||||||
// Clamp the plane to the object's bounding box
|
// Clamp the plane to the object's bounding box
|
||||||
const double new_z = m_start_z + calc_projection(data.mouse_ray);
|
const double new_z = m_start_z + calc_projection(data.mouse_ray);
|
||||||
m_cut_z = std::max(-m_max_z, std::min(m_max_z, new_z));
|
m_cut_z = std::max(0.0, std::min(m_max_z, new_z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2037,7 +2037,7 @@ void GLGizmoCut::on_render(const GLCanvas3D::Selection& selection) const
|
||||||
|
|
||||||
const BoundingBoxf3& box = selection.get_bounding_box();
|
const BoundingBoxf3& box = selection.get_bounding_box();
|
||||||
Vec3d plane_center = box.center();
|
Vec3d plane_center = box.center();
|
||||||
plane_center(2) += m_cut_z;
|
plane_center(2) = m_cut_z;
|
||||||
|
|
||||||
const float min_x = box.min(0) - Margin;
|
const float min_x = box.min(0) - Margin;
|
||||||
const float max_x = box.max(0) + Margin;
|
const float max_x = box.max(0) + Margin;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue