Mirror of ModelVolume as transformation component (without modifying the mesh)

This commit is contained in:
Enrico Turri 2018-11-05 08:51:00 +01:00
parent fb6a08cfb0
commit 864bc6ad48
2 changed files with 23 additions and 4 deletions

View file

@ -894,15 +894,16 @@ void ModelObject::rotate(double angle, const Vec3d& axis)
this->invalidate_bounding_box(); this->invalidate_bounding_box();
} }
void ModelObject::mirror(const Axis &axis) void ModelObject::mirror(Axis axis)
{ {
for (ModelVolume *v : this->volumes) for (ModelVolume *v : this->volumes)
{ {
v->mesh.mirror(axis); v->mirror(axis);
v->m_convex_hull.mirror(axis);
} }
#if !ENABLE_MODELVOLUME_TRANSFORM
this->origin_translation = Vec3d::Zero(); this->origin_translation = Vec3d::Zero();
#endif // !ENABLE_MODELVOLUME_TRANSFORM
this->invalidate_bounding_box(); this->invalidate_bounding_box();
} }
@ -1276,6 +1277,23 @@ void ModelVolume::rotate(double angle, const Vec3d& axis)
#endif // ENABLE_MODELVOLUME_TRANSFORM #endif // ENABLE_MODELVOLUME_TRANSFORM
} }
void ModelVolume::mirror(Axis axis)
{
#if ENABLE_MODELVOLUME_TRANSFORM
Vec3d mirror = m_transformation.get_mirror();
switch (axis)
{
case X: { mirror(0) *= -1.0; break; }
case Y: { mirror(1) *= -1.0; break; }
case Z: { mirror(2) *= -1.0; break; }
}
m_transformation.set_mirror(mirror);
#else
mesh.mirror(axis);
m_convex_hull.mirror(axis);
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
#if !ENABLE_MODELVOLUME_TRANSFORM #if !ENABLE_MODELVOLUME_TRANSFORM
void ModelInstance::set_rotation(const Vec3d& rotation) void ModelInstance::set_rotation(const Vec3d& rotation)
{ {

View file

@ -233,7 +233,7 @@ public:
void scale(double x, double y, double z) { this->scale(Vec3d(x, y, z)); } void scale(double x, double y, double z) { this->scale(Vec3d(x, y, z)); }
void rotate(double angle, Axis axis); void rotate(double angle, Axis axis);
void rotate(double angle, const Vec3d& axis); void rotate(double angle, const Vec3d& axis);
void mirror(const Axis &axis); void mirror(Axis axis);
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;
@ -321,6 +321,7 @@ public:
void scale(double s) { scale(Vec3d(s, s, s)); } void scale(double s) { scale(Vec3d(s, s, s)); }
void rotate(double angle, Axis axis); void rotate(double angle, Axis axis);
void rotate(double angle, const Vec3d& axis); void rotate(double angle, const Vec3d& axis);
void mirror(Axis axis);
ModelMaterial* assign_unique_material(); ModelMaterial* assign_unique_material();