Fixed update of ModelVolume offset after GLVolume manipulation

This commit is contained in:
Enrico Turri 2018-11-07 14:01:03 +01:00
parent 102bc99958
commit b05aa00089
2 changed files with 31 additions and 20 deletions

View File

@ -1246,7 +1246,7 @@ size_t ModelVolume::split(unsigned int max_extruders)
void ModelVolume::translate(const Vec3d& displacement) void ModelVolume::translate(const Vec3d& displacement)
{ {
#if ENABLE_MODELVOLUME_TRANSFORM #if ENABLE_MODELVOLUME_TRANSFORM
m_transformation.set_offset(m_transformation.get_offset() + displacement); set_offset(get_offset() + displacement);
#else #else
mesh.translate((float)displacement(0), (float)displacement(1), (float)displacement(2)); mesh.translate((float)displacement(0), (float)displacement(1), (float)displacement(2));
m_convex_hull.translate((float)displacement(0), (float)displacement(1), (float)displacement(2)); m_convex_hull.translate((float)displacement(0), (float)displacement(1), (float)displacement(2));
@ -1256,7 +1256,7 @@ void ModelVolume::translate(const Vec3d& displacement)
void ModelVolume::scale(const Vec3d& scaling_factors) void ModelVolume::scale(const Vec3d& scaling_factors)
{ {
#if ENABLE_MODELVOLUME_TRANSFORM #if ENABLE_MODELVOLUME_TRANSFORM
m_transformation.set_scaling_factor(m_transformation.get_scaling_factor().cwiseProduct(scaling_factors)); set_scaling_factor(get_scaling_factor().cwiseProduct(scaling_factors));
#else #else
mesh.scale(scaling_factors); mesh.scale(scaling_factors);
m_convex_hull.scale(scaling_factors); m_convex_hull.scale(scaling_factors);
@ -1281,7 +1281,7 @@ void ModelVolume::rotate(double angle, Axis axis)
void ModelVolume::rotate(double angle, const Vec3d& axis) void ModelVolume::rotate(double angle, const Vec3d& axis)
{ {
#if ENABLE_MODELVOLUME_TRANSFORM #if ENABLE_MODELVOLUME_TRANSFORM
m_transformation.set_rotation(m_transformation.get_rotation() + Geometry::extract_euler_angles(Eigen::Quaterniond(Eigen::AngleAxisd(angle, axis)).toRotationMatrix())); set_rotation(get_rotation() + Geometry::extract_euler_angles(Eigen::Quaterniond(Eigen::AngleAxisd(angle, axis)).toRotationMatrix()));
#else #else
mesh.rotate(angle, axis); mesh.rotate(angle, axis);
m_convex_hull.rotate(angle, axis); m_convex_hull.rotate(angle, axis);
@ -1291,14 +1291,14 @@ void ModelVolume::rotate(double angle, const Vec3d& axis)
void ModelVolume::mirror(Axis axis) void ModelVolume::mirror(Axis axis)
{ {
#if ENABLE_MODELVOLUME_TRANSFORM #if ENABLE_MODELVOLUME_TRANSFORM
Vec3d mirror = m_transformation.get_mirror(); Vec3d mirror = get_mirror();
switch (axis) switch (axis)
{ {
case X: { mirror(0) *= -1.0; break; } case X: { mirror(0) *= -1.0; break; }
case Y: { mirror(1) *= -1.0; break; } case Y: { mirror(1) *= -1.0; break; }
case Z: { mirror(2) *= -1.0; break; } case Z: { mirror(2) *= -1.0; break; }
} }
m_transformation.set_mirror(mirror); set_mirror(mirror);
#else #else
mesh.mirror(axis); mesh.mirror(axis);
m_convex_hull.mirror(axis); m_convex_hull.mirror(axis);
@ -1375,10 +1375,10 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes
for (unsigned int i = 0; i < 3; ++i) for (unsigned int i = 0; i < 3; ++i)
{ {
#if ENABLE_MODELVOLUME_TRANSFORM #if ENABLE_MODELVOLUME_TRANSFORM
if (std::abs(m_transformation.get_scaling_factor((Axis)i)-1.0) > EPSILON) if (std::abs(get_scaling_factor((Axis)i)-1.0) > EPSILON)
{ {
bbox.min(i) *= m_transformation.get_scaling_factor((Axis)i); bbox.min(i) *= get_scaling_factor((Axis)i);
bbox.max(i) *= m_transformation.get_scaling_factor((Axis)i); bbox.max(i) *= get_scaling_factor((Axis)i);
#else #else
if (std::abs(this->m_scaling_factor(i) - 1.0) > EPSILON) if (std::abs(this->m_scaling_factor(i) - 1.0) > EPSILON)
{ {
@ -1391,8 +1391,8 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes
// Translate the bounding box. // Translate the bounding box.
if (! dont_translate) { if (! dont_translate) {
#if ENABLE_MODELVOLUME_TRANSFORM #if ENABLE_MODELVOLUME_TRANSFORM
bbox.min += m_transformation.get_offset(); bbox.min += get_offset();
bbox.max += m_transformation.get_offset(); bbox.max += get_offset();
#else #else
bbox.min += this->m_offset; bbox.min += this->m_offset;
bbox.max += this->m_offset; bbox.max += this->m_offset;
@ -1416,9 +1416,9 @@ void ModelInstance::transform_polygon(Polygon* polygon) const
{ {
#if ENABLE_MODELVOLUME_TRANSFORM #if ENABLE_MODELVOLUME_TRANSFORM
// CHECK_ME -> Is the following correct or it should take in account all three rotations ? // CHECK_ME -> Is the following correct or it should take in account all three rotations ?
polygon->rotate(m_transformation.get_rotation(Z)); // rotate around polygon origin polygon->rotate(get_rotation(Z)); // rotate around polygon origin
// CHECK_ME -> Is the following correct ? // CHECK_ME -> Is the following correct ?
polygon->scale(m_transformation.get_scaling_factor(X), m_transformation.get_scaling_factor(Y)); // scale around polygon origin polygon->scale(get_scaling_factor(X), get_scaling_factor(Y)); // scale around polygon origin
#else #else
// CHECK_ME -> Is the following correct or it should take in account all three rotations ? // CHECK_ME -> Is the following correct or it should take in account all three rotations ?
polygon->rotate(this->m_rotation(2)); // rotate around polygon origin polygon->rotate(this->m_rotation(2)); // rotate around polygon origin

View File

@ -6274,35 +6274,45 @@ void GLCanvas3D::_on_move()
if (m_model == nullptr) if (m_model == nullptr)
return; return;
std::set<std::pair<int, int>> done; // prevent moving instances twice std::set<std::pair<int, int>> done; // keeps track of moved instances
bool object_moved = false; bool object_moved = false;
Vec3d wipe_tower_origin = Vec3d::Zero(); Vec3d wipe_tower_origin = Vec3d::Zero();
Selection::EMode selection_mode = m_selection.get_mode();
for (const GLVolume* v : m_volumes.volumes) for (const GLVolume* v : m_volumes.volumes)
{ {
int object_idx = v->object_idx(); int object_idx = v->object_idx();
int instance_idx = v->instance_idx(); int instance_idx = v->instance_idx();
int volume_idx = v->volume_idx();
// prevent moving instances twice
std::pair<int, int> done_id(object_idx, instance_idx); std::pair<int, int> done_id(object_idx, instance_idx);
if (done.find(done_id) != done.end())
continue;
if (object_idx < 1000) if ((0 <= object_idx) && (object_idx < (int)m_model->objects.size()))
{ {
done.insert(done_id); done.insert(done_id);
// Move instances. // Move instances/volumes
ModelObject* model_object = m_model->objects[object_idx]; ModelObject* model_object = m_model->objects[object_idx];
if (model_object != nullptr) if (model_object != nullptr)
{ {
#if ENABLE_MODELVOLUME_TRANSFORM #if ENABLE_MODELVOLUME_TRANSFORM
if (selection_mode == Selection::Instance)
{
model_object->instances[instance_idx]->set_offset(v->get_instance_offset()); model_object->instances[instance_idx]->set_offset(v->get_instance_offset());
object_moved = true;
}
else if (selection_mode == Selection::Volume)
{
model_object->volumes[volume_idx]->set_offset(v->get_volume_offset());
object_moved = true;
}
if (object_moved)
#else #else
model_object->instances[instance_idx]->set_offset(v->get_offset()); model_object->instances[instance_idx]->set_offset(v->get_offset());
object_moved = true;
#endif // ENABLE_MODELVOLUME_TRANSFORM #endif // ENABLE_MODELVOLUME_TRANSFORM
model_object->invalidate_bounding_box(); model_object->invalidate_bounding_box();
object_moved = true;
} }
} }
else if (object_idx == 1000) else if (object_idx == 1000)
@ -6314,6 +6324,7 @@ void GLCanvas3D::_on_move()
#endif // ENABLE_MODELVOLUME_TRANSFORM #endif // ENABLE_MODELVOLUME_TRANSFORM
} }
// Fixes sinking/flying instances
for (const std::pair<int, int>& i : done) for (const std::pair<int, int>& i : done)
{ {
ModelObject* m = m_model->objects[i.first]; ModelObject* m = m_model->objects[i.first];