Enhanced volumes manipulation - wip
This commit is contained in:
parent
a72470079d
commit
22dbcbcd9c
@ -1177,10 +1177,12 @@ void ModelVolume::set_material(t_model_material_id material_id, const ModelMater
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||||
void ModelVolume::translate_geometry(const Vec3d& displacement)
|
void ModelVolume::center_geometry()
|
||||||
{
|
{
|
||||||
mesh.translate((float)displacement(0), (float)displacement(1), (float)displacement(2));
|
Vec3d shift = -mesh.bounding_box().center();
|
||||||
m_convex_hull.translate((float)displacement(0), (float)displacement(1), (float)displacement(2));
|
mesh.translate((float)shift(0), (float)shift(1), (float)shift(2));
|
||||||
|
m_convex_hull.translate((float)shift(0), (float)shift(1), (float)shift(2));
|
||||||
|
translate(-shift);
|
||||||
}
|
}
|
||||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
|
||||||
|
@ -324,7 +324,8 @@ public:
|
|||||||
void mirror(Axis axis);
|
void mirror(Axis axis);
|
||||||
|
|
||||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||||
void translate_geometry(const Vec3d& displacement);
|
// translates the mesh and the convex hull so that the origin of their vertices is in the center of this volume's bounding box
|
||||||
|
void center_geometry();
|
||||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
|
||||||
void calculate_convex_hull();
|
void calculate_convex_hull();
|
||||||
|
@ -1480,6 +1480,10 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation)
|
|||||||
(*m_volumes)[i]->set_instance_rotation(rotation);
|
(*m_volumes)[i]->set_instance_rotation(rotation);
|
||||||
#else
|
#else
|
||||||
(*m_volumes)[i]->set_rotation(rotation);
|
(*m_volumes)[i]->set_rotation(rotation);
|
||||||
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
else if (is_single_volume() || is_single_modifier())
|
||||||
|
(*m_volumes)[i]->set_volume_rotation(rotation);
|
||||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1496,6 +1500,7 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation)
|
|||||||
{
|
{
|
||||||
// extracts rotations from the composed transformation
|
// extracts rotations from the composed transformation
|
||||||
Vec3d new_rotation = Geometry::extract_euler_angles(m * m_cache.volumes_data[i].get_volume_rotation_matrix());
|
Vec3d new_rotation = Geometry::extract_euler_angles(m * m_cache.volumes_data[i].get_volume_rotation_matrix());
|
||||||
|
(*m_volumes)[i]->set_volume_offset(m * m_cache.volumes_data[i].get_volume_position());
|
||||||
(*m_volumes)[i]->set_volume_rotation(new_rotation);
|
(*m_volumes)[i]->set_volume_rotation(new_rotation);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -1584,6 +1589,10 @@ void GLCanvas3D::Selection::scale(const Vec3d& scale)
|
|||||||
(*m_volumes)[i]->set_instance_scaling_factor(scale);
|
(*m_volumes)[i]->set_instance_scaling_factor(scale);
|
||||||
#else
|
#else
|
||||||
(*m_volumes)[i]->set_scaling_factor(scale);
|
(*m_volumes)[i]->set_scaling_factor(scale);
|
||||||
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
else if (is_single_volume() || is_single_modifier())
|
||||||
|
(*m_volumes)[i]->set_volume_scaling_factor(scale);
|
||||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1602,6 +1611,7 @@ void GLCanvas3D::Selection::scale(const Vec3d& scale)
|
|||||||
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> new_matrix = (m * m_cache.volumes_data[i].get_volume_scale_matrix()).matrix().block(0, 0, 3, 3);
|
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> new_matrix = (m * m_cache.volumes_data[i].get_volume_scale_matrix()).matrix().block(0, 0, 3, 3);
|
||||||
// extracts scaling factors from the composed transformation
|
// extracts scaling factors from the composed transformation
|
||||||
Vec3d new_scale(new_matrix.col(0).norm(), new_matrix.col(1).norm(), new_matrix.col(2).norm());
|
Vec3d new_scale(new_matrix.col(0).norm(), new_matrix.col(1).norm(), new_matrix.col(2).norm());
|
||||||
|
(*m_volumes)[i]->set_volume_offset(m * m_cache.volumes_data[i].get_volume_position());
|
||||||
(*m_volumes)[i]->set_volume_scaling_factor(new_scale);
|
(*m_volumes)[i]->set_volume_scaling_factor(new_scale);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -5180,6 +5190,16 @@ void GLCanvas3D::_update_gizmos_data()
|
|||||||
m_gizmos.set_model_object_ptr(model_object);
|
m_gizmos.set_model_object_ptr(model_object);
|
||||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
}
|
}
|
||||||
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
else if (m_selection.is_single_volume() || m_selection.is_single_modifier())
|
||||||
|
{
|
||||||
|
const GLVolume* volume = m_volumes.volumes[*m_selection.get_volume_idxs().begin()];
|
||||||
|
m_gizmos.set_scale(volume->get_volume_scaling_factor());
|
||||||
|
m_gizmos.set_rotation(volume->get_volume_rotation());
|
||||||
|
m_gizmos.set_flattening_data(nullptr);
|
||||||
|
m_gizmos.set_model_object_ptr(nullptr);
|
||||||
|
}
|
||||||
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_gizmos.set_scale(Vec3d::Ones());
|
m_gizmos.set_scale(Vec3d::Ones());
|
||||||
|
@ -489,6 +489,7 @@ public:
|
|||||||
bool is_empty() const { return m_type == Empty; }
|
bool is_empty() const { return m_type == Empty; }
|
||||||
bool is_wipe_tower() const { return m_type == WipeTower; }
|
bool is_wipe_tower() const { return m_type == WipeTower; }
|
||||||
bool is_modifier() const { return (m_type == SingleModifier) || (m_type == MultipleModifier); }
|
bool is_modifier() const { return (m_type == SingleModifier) || (m_type == MultipleModifier); }
|
||||||
|
bool is_single_modifier() const { return m_type == SingleModifier; }
|
||||||
bool is_single_full_instance() const;
|
bool is_single_full_instance() const;
|
||||||
bool is_multiple_full_instance() const { return m_type == MultipleFullInstance; }
|
bool is_multiple_full_instance() const { return m_type == MultipleFullInstance; }
|
||||||
bool is_single_full_object() const { return m_type == SingleFullObject; }
|
bool is_single_full_object() const { return m_type == SingleFullObject; }
|
||||||
|
@ -747,9 +747,8 @@ void ObjectList::load_part( ModelObject* model_object,
|
|||||||
}
|
}
|
||||||
for (auto volume : object->volumes) {
|
for (auto volume : object->volumes) {
|
||||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||||
Vec3d shift = volume->mesh.bounding_box().center();
|
volume->center_geometry();
|
||||||
volume->translate_geometry(-shift);
|
volume->translate(delta);
|
||||||
volume->translate(delta + shift);
|
|
||||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
auto new_volume = model_object->add_volume(*volume);
|
auto new_volume = model_object->add_volume(*volume);
|
||||||
new_volume->set_type(static_cast<ModelVolume::Type>(type));
|
new_volume->set_type(static_cast<ModelVolume::Type>(type));
|
||||||
@ -797,10 +796,14 @@ void ObjectList::load_generic_subobject(const std::string& type_name, const int
|
|||||||
mesh.translate(-size(0)*1.5 / 2.0, -size(1)*1.5 / 2.0, 0);
|
mesh.translate(-size(0)*1.5 / 2.0, -size(1)*1.5 / 2.0, 0);
|
||||||
}
|
}
|
||||||
mesh.repair();
|
mesh.repair();
|
||||||
|
|
||||||
auto new_volume = (*m_objects)[obj_idx]->add_volume(mesh);
|
auto new_volume = (*m_objects)[obj_idx]->add_volume(mesh);
|
||||||
new_volume->set_type(static_cast<ModelVolume::Type>(type));
|
new_volume->set_type(static_cast<ModelVolume::Type>(type));
|
||||||
|
|
||||||
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
new_volume->center_geometry();
|
||||||
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
|
||||||
new_volume->name = name;
|
new_volume->name = name;
|
||||||
// set a default extruder value, since user can't add it manually
|
// set a default extruder value, since user can't add it manually
|
||||||
new_volume->config.set_key_value("extruder", new ConfigOptionInt(0));
|
new_volume->config.set_key_value("extruder", new ConfigOptionInt(0));
|
||||||
|
Loading…
Reference in New Issue
Block a user