Cut WIP: Added "Place o cut"
This commit is contained in:
parent
15418bfb76
commit
cd8e0d002b
@ -1494,19 +1494,9 @@ ModelObjectPtrs ModelObject::cut(size_t instance, const Vec3d& cut_center, const
|
||||
instances[instance]->get_mirror()
|
||||
);
|
||||
|
||||
const auto cut_matrix = Geometry::assemble_transform(
|
||||
-cut_center,
|
||||
Vec3d::Zero(),
|
||||
Vec3d::Ones(),
|
||||
Vec3d::Ones()
|
||||
);
|
||||
const auto cut_matrix = Geometry::assemble_transform(-cut_center);
|
||||
|
||||
const auto invert_cut_matrix = Geometry::assemble_transform(
|
||||
cut_center,
|
||||
cut_rotation,
|
||||
Vec3d::Ones(),
|
||||
Vec3d::Ones()
|
||||
);
|
||||
const auto invert_cut_matrix = Geometry::assemble_transform(cut_center, cut_rotation);
|
||||
|
||||
// Displacement (in instance coordinates) to be applied to place the upper parts
|
||||
Vec3d local_displace = Vec3d::Zero();
|
||||
@ -1522,11 +1512,22 @@ ModelObjectPtrs ModelObject::cut(size_t instance, const Vec3d& cut_center, const
|
||||
if (!volume->is_model_part()) {
|
||||
if (volume->source.is_connector) {
|
||||
if (attributes.has(ModelObjectCutAttribute::KeepUpper)) {
|
||||
|
||||
Transform3d m = attributes.has(ModelObjectCutAttribute::PlaceOnCutUpper) ?
|
||||
Geometry::rotation_transform(cut_rotation).inverse() * cut_matrix * instance_matrix * volume_matrix :
|
||||
instance_matrix * volume_matrix;
|
||||
volume->set_transformation(m);
|
||||
|
||||
ModelVolume* vol = upper->add_volume(*volume);
|
||||
// make a "hole" dipper
|
||||
vol->set_scaling_factor(Z, 1.1 * vol->get_scaling_factor(Z));
|
||||
}
|
||||
if (attributes.has(ModelObjectCutAttribute::KeepLower)) {
|
||||
|
||||
Transform3d m = attributes.has(ModelObjectCutAttribute::PlaceOnCutLower) ?
|
||||
Geometry::rotation_transform(Geometry::deg2rad(180.0) * Vec3d::UnitX()) * Geometry::rotation_transform(cut_rotation).inverse() * cut_matrix * instance_matrix * volume_matrix :
|
||||
instance_matrix * volume_matrix;
|
||||
volume->set_transformation(m);
|
||||
ModelVolume* vol = lower->add_volume(*volume);
|
||||
if (attributes.has(ModelObjectCutAttribute::CreateDowels))
|
||||
// make a "hole" dipper
|
||||
@ -1567,10 +1568,7 @@ ModelObjectPtrs ModelObject::cut(size_t instance, const Vec3d& cut_center, const
|
||||
// Transform the mesh by the combined transformation matrix.
|
||||
// Flip the triangles in case the composite transformation is left handed.
|
||||
TriangleMesh mesh(volume->mesh());
|
||||
mesh.transform(cut_matrix * instance_matrix * volume_matrix, true);
|
||||
mesh.rotate(-cut_rotation.z(), Z);
|
||||
mesh.rotate(-cut_rotation.y(), Y);
|
||||
mesh.rotate(-cut_rotation.x(), X);
|
||||
mesh.transform(Geometry::rotation_transform(cut_rotation).inverse() * cut_matrix * instance_matrix * volume_matrix, true);
|
||||
|
||||
volume->reset_mesh();
|
||||
// Reset volume transformation except for offset
|
||||
@ -1590,6 +1588,7 @@ ModelObjectPtrs ModelObject::cut(size_t instance, const Vec3d& cut_center, const
|
||||
}
|
||||
|
||||
if (attributes.has(ModelObjectCutAttribute::KeepUpper) && !upper_mesh.empty()) {
|
||||
if (!attributes.has(ModelObjectCutAttribute::PlaceOnCutUpper))
|
||||
upper_mesh.transform(invert_cut_matrix);
|
||||
|
||||
ModelVolume* vol = upper->add_volume(upper_mesh);
|
||||
@ -1601,6 +1600,9 @@ ModelObjectPtrs ModelObject::cut(size_t instance, const Vec3d& cut_center, const
|
||||
vol->set_material(volume->material_id(), *volume->material());
|
||||
}
|
||||
if (attributes.has(ModelObjectCutAttribute::KeepLower) && !lower_mesh.empty()) {
|
||||
if (attributes.has(ModelObjectCutAttribute::PlaceOnCutLower))
|
||||
lower_mesh.transform(Geometry::assemble_transform(Vec3d::Zero(), Geometry::deg2rad(180.0)*Vec3d::UnitX()));
|
||||
else
|
||||
lower_mesh.transform(invert_cut_matrix);
|
||||
|
||||
ModelVolume* vol = lower->add_volume(lower_mesh);
|
||||
|
@ -304,7 +304,7 @@ enum class ModelVolumeType : int {
|
||||
SUPPORT_ENFORCER,
|
||||
};
|
||||
|
||||
enum class ModelObjectCutAttribute : int { KeepUpper, KeepLower, FlipUpper, FlipLower, CreateDowels };
|
||||
enum class ModelObjectCutAttribute : int { KeepUpper, KeepLower, FlipUpper, FlipLower, PlaceOnCutUpper, PlaceOnCutLower, CreateDowels };
|
||||
using ModelObjectCutAttributes = enum_bitmask<ModelObjectCutAttribute>;
|
||||
ENABLE_ENUM_BITMASK_OPERATORS(ModelObjectCutAttribute);
|
||||
|
||||
|
@ -1121,10 +1121,17 @@ void GLGizmoCut3D::on_render_input_window(float x, float y, float bottom_limit)
|
||||
m_imgui->disabled_begin(!connectors.empty());
|
||||
m_imgui->checkbox(_L("Keep") + "##upper", connectors.empty() ? m_keep_upper : keep);
|
||||
m_imgui->disabled_end();
|
||||
ImGui::SameLine();
|
||||
ImGui::SameLine(3 * m_label_width);
|
||||
|
||||
m_imgui->disabled_begin(!m_keep_upper);
|
||||
m_imgui->disabled_begin(is_approx(Geometry::Transformation(m_rotation_m).get_rotation().x(), 0.) && is_approx(Geometry::Transformation(m_rotation_m).get_rotation().y(), 0.));
|
||||
m_imgui->checkbox(_L("Place on cut") + "##upper", m_rotate_upper); // #ysTODO implement place on cut instead of Flip?
|
||||
|
||||
if (m_imgui->checkbox(_L("Place on cut") + "##upper", m_place_on_cut_upper))
|
||||
m_rotate_upper = false;
|
||||
ImGui::SameLine();
|
||||
if (m_imgui->checkbox(_L("Flip") + "##upper", m_rotate_upper))
|
||||
m_place_on_cut_upper = false;
|
||||
|
||||
m_imgui->disabled_end();
|
||||
m_imgui->disabled_end();
|
||||
|
||||
@ -1134,11 +1141,18 @@ void GLGizmoCut3D::on_render_input_window(float x, float y, float bottom_limit)
|
||||
ImGui::SameLine(2 * m_label_width);
|
||||
|
||||
m_imgui->disabled_begin(!connectors.empty());
|
||||
|
||||
m_imgui->checkbox(_L("Keep") + "##lower", connectors.empty() ? m_keep_lower : keep);
|
||||
m_imgui->disabled_end();
|
||||
ImGui::SameLine();
|
||||
ImGui::SameLine(3 * m_label_width);
|
||||
m_imgui->disabled_begin(!m_keep_lower);
|
||||
m_imgui->checkbox(_L("Place on cut") + "##lower", m_rotate_lower); // #ysTODO implement place on cut instead of Flip?
|
||||
|
||||
if (m_imgui->checkbox(_L("Place on cut") + "##lower", m_place_on_cut_lower))
|
||||
m_rotate_lower = false;
|
||||
ImGui::SameLine();
|
||||
if (m_imgui->checkbox(_L("Flip") + "##lower", m_rotate_lower))
|
||||
m_place_on_cut_lower = false;
|
||||
|
||||
m_imgui->disabled_end();
|
||||
}
|
||||
|
||||
@ -1451,6 +1465,8 @@ void GLGizmoCut3D::perform_cut(const Selection& selection)
|
||||
plater->cut(object_idx, instance_idx, cut_center_offset, rotation,
|
||||
only_if(has_connectors ? true : m_keep_upper, ModelObjectCutAttribute::KeepUpper) |
|
||||
only_if(has_connectors ? true : m_keep_lower, ModelObjectCutAttribute::KeepLower) |
|
||||
only_if(m_place_on_cut_upper, ModelObjectCutAttribute::PlaceOnCutUpper) |
|
||||
only_if(m_place_on_cut_lower, ModelObjectCutAttribute::PlaceOnCutLower) |
|
||||
only_if(m_rotate_upper, ModelObjectCutAttribute::FlipUpper) |
|
||||
only_if(m_rotate_lower, ModelObjectCutAttribute::FlipLower) |
|
||||
only_if(create_dowels_as_separate_object, ModelObjectCutAttribute::CreateDowels));
|
||||
|
@ -61,6 +61,8 @@ class GLGizmoCut3D : public GLGizmoBase
|
||||
|
||||
bool m_keep_upper{ true };
|
||||
bool m_keep_lower{ true };
|
||||
bool m_place_on_cut_upper{ true };
|
||||
bool m_place_on_cut_lower{ true };
|
||||
bool m_rotate_upper{ false };
|
||||
bool m_rotate_lower{ false };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user