mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-23 00:31:11 -06:00
Keep model objects aligned to Z = 0 in plater
This commit is contained in:
parent
050f9ff61a
commit
360dee862b
10 changed files with 43 additions and 32 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -99,7 +99,7 @@ class ModelObject
|
|||
center_around_origin() method. Callers might want to apply the same translation
|
||||
to new volumes before adding them to this object in order to preset alignment
|
||||
when user expects that. */
|
||||
Pointf origin_translation;
|
||||
Pointf3 origin_translation;
|
||||
|
||||
// these should be private but we need to expose them via XS until all methods are ported
|
||||
BoundingBoxf3 _bounding_box;
|
||||
|
@ -126,6 +126,7 @@ class ModelObject
|
|||
void raw_bounding_box(BoundingBoxf3* bb) const;
|
||||
void instance_bounding_box(size_t instance_idx, BoundingBoxf3* bb) const;
|
||||
void center_around_origin();
|
||||
void translate(const Vectorf3 &vector);
|
||||
void translate(coordf_t x, coordf_t y, coordf_t z);
|
||||
void scale(const Pointf3 &versor);
|
||||
size_t materials_count() const;
|
||||
|
|
|
@ -41,7 +41,7 @@ Point::translate(double x, double y)
|
|||
}
|
||||
|
||||
void
|
||||
Point::translate(const Point &vector)
|
||||
Point::translate(const Vector &vector)
|
||||
{
|
||||
this->translate(vector.x, vector.y);
|
||||
}
|
||||
|
@ -340,6 +340,12 @@ Pointf3::scale(double factor)
|
|||
this->z *= factor;
|
||||
}
|
||||
|
||||
void
|
||||
Pointf3::translate(const Vectorf3 &vector)
|
||||
{
|
||||
this->translate(vector.x, vector.y, vector.z);
|
||||
}
|
||||
|
||||
void
|
||||
Pointf3::translate(double x, double y, double z)
|
||||
{
|
||||
|
|
|
@ -14,6 +14,7 @@ class Point;
|
|||
class Pointf;
|
||||
class Pointf3;
|
||||
typedef Point Vector;
|
||||
typedef Pointf3 Vectorf3;
|
||||
typedef std::vector<Point> Points;
|
||||
typedef std::vector<Point*> PointPtrs;
|
||||
typedef std::vector<const Point*> PointConstPtrs;
|
||||
|
@ -36,7 +37,7 @@ class Point
|
|||
std::string wkt() const;
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
void translate(const Point &vector);
|
||||
void translate(const Vector &vector);
|
||||
void rotate(double angle, const Point ¢er);
|
||||
bool coincides_with(const Point &point) const;
|
||||
bool coincides_with_epsilon(const Point &point) const;
|
||||
|
@ -93,6 +94,7 @@ class Pointf3 : public Pointf
|
|||
coordf_t z;
|
||||
explicit Pointf3(coordf_t _x = 0, coordf_t _y = 0, coordf_t _z = 0): Pointf(_x, _y), z(_z) {};
|
||||
void scale(double factor);
|
||||
void translate(const Vectorf3 &vector);
|
||||
void translate(double x, double y, double z);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue