Align objects imported from AMF to ground. #3785

This commit is contained in:
Alessandro Ranellucci 2017-03-23 14:10:41 +01:00
parent 84a5075fce
commit bd2117d346
4 changed files with 19 additions and 0 deletions

View File

@ -671,6 +671,9 @@ sub load_model_objects {
# add a default instance and center object around origin
$o->center_around_origin; # also aligns object to Z = 0
$o->add_instance(offset => $bed_centerf);
} else {
# if object has defined positions we still need to ensure it's aligned to Z = 0
$o->align_to_ground;
}
{

View File

@ -597,6 +597,20 @@ ModelObject::instance_bounding_box(size_t instance_idx) const
return bb;
}
void
ModelObject::align_to_ground()
{
// calculate the displacements needed to
// center this object around the origin
BoundingBoxf3 bb;
for (const ModelVolume* v : this->volumes)
if (!v->modifier)
bb.merge(v->mesh.bounding_box());
this->translate(0, 0, -bb.min.z);
this->origin_translation.translate(0, 0, -bb.min.z);
}
void
ModelObject::center_around_origin()
{

View File

@ -149,6 +149,7 @@ class ModelObject
TriangleMesh raw_mesh() const;
BoundingBoxf3 raw_bounding_box() const;
BoundingBoxf3 instance_bounding_box(size_t instance_idx) const;
void align_to_ground();
void center_around_origin();
void translate(const Vectorf3 &vector);
void translate(coordf_t x, coordf_t y, coordf_t z);

View File

@ -207,6 +207,7 @@ ModelMaterial::attributes()
bool needed_repair() const;
int materials_count() const;
int facets_count();
void align_to_ground();
void center_around_origin();
void translate(double x, double y, double z);
void scale_xyz(Pointf3* versor)