Keep model objects aligned to Z = 0 in plater

This commit is contained in:
Alessandro Ranellucci 2014-12-12 22:43:04 +01:00
parent 050f9ff61a
commit 360dee862b
10 changed files with 43 additions and 32 deletions

View file

@ -480,26 +480,31 @@ ModelObject::center_around_origin()
mesh.bounding_box(&bb);
}
// first align to origin on XY
double shift_x = -bb.min.x;
double shift_y = -bb.min.y;
// first align to origin on XYZ
Vectorf3 vector(-bb.min.x, -bb.min.y, -bb.min.z);
// then center it on XY
Sizef3 size = bb.size();
shift_x -= size.x/2;
shift_y -= size.y/2;
vector.x -= size.x/2;
vector.y -= size.y/2;
this->translate(shift_x, shift_y, 0);
this->origin_translation.translate(shift_x, shift_y);
this->translate(vector);
this->origin_translation.translate(vector);
if (!this->instances.empty()) {
for (ModelInstancePtrs::const_iterator i = this->instances.begin(); i != this->instances.end(); ++i) {
(*i)->offset.translate(-shift_x, -shift_y);
(*i)->offset.translate(-vector.x, -vector.y);
}
this->update_bounding_box();
}
}
void
ModelObject::translate(const Vectorf3 &vector)
{
this->translate(vector.x, vector.y, vector.z);
}
void
ModelObject::translate(coordf_t x, coordf_t y, coordf_t z)
{