Enhanced volumes manipulation - wip

This commit is contained in:
Enrico Turri 2018-11-12 08:54:22 +01:00
parent a72470079d
commit 22dbcbcd9c
5 changed files with 35 additions and 8 deletions

View File

@ -1177,10 +1177,12 @@ void ModelVolume::set_material(t_model_material_id material_id, const ModelMater
}
#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));
m_convex_hull.translate((float)displacement(0), (float)displacement(1), (float)displacement(2));
Vec3d shift = -mesh.bounding_box().center();
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

View File

@ -324,7 +324,8 @@ public:
void mirror(Axis axis);
#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
void calculate_convex_hull();

View File

@ -1480,6 +1480,10 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation)
(*m_volumes)[i]->set_instance_rotation(rotation);
#else
(*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
else
{
@ -1496,6 +1500,7 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation)
{
// extracts rotations from the composed transformation
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);
}
#else
@ -1584,6 +1589,10 @@ void GLCanvas3D::Selection::scale(const Vec3d& scale)
(*m_volumes)[i]->set_instance_scaling_factor(scale);
#else
(*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
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);
// 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());
(*m_volumes)[i]->set_volume_offset(m * m_cache.volumes_data[i].get_volume_position());
(*m_volumes)[i]->set_volume_scaling_factor(new_scale);
}
#else
@ -5180,6 +5190,16 @@ void GLCanvas3D::_update_gizmos_data()
m_gizmos.set_model_object_ptr(model_object);
#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
{
m_gizmos.set_scale(Vec3d::Ones());

View File

@ -489,6 +489,7 @@ public:
bool is_empty() const { return m_type == Empty; }
bool is_wipe_tower() const { return m_type == WipeTower; }
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_multiple_full_instance() const { return m_type == MultipleFullInstance; }
bool is_single_full_object() const { return m_type == SingleFullObject; }

View File

@ -747,9 +747,8 @@ void ObjectList::load_part( ModelObject* model_object,
}
for (auto volume : object->volumes) {
#if ENABLE_MODELVOLUME_TRANSFORM
Vec3d shift = volume->mesh.bounding_box().center();
volume->translate_geometry(-shift);
volume->translate(delta + shift);
volume->center_geometry();
volume->translate(delta);
#endif // ENABLE_MODELVOLUME_TRANSFORM
auto new_volume = model_object->add_volume(*volume);
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.repair();
auto new_volume = (*m_objects)[obj_idx]->add_volume(mesh);
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;
// set a default extruder value, since user can't add it manually
new_volume->config.set_key_value("extruder", new ConfigOptionInt(0));