3mf I/O - Fixed object sinking into bed after import

This commit is contained in:
Enrico Turri 2018-03-06 10:26:39 +01:00
parent 7320a87183
commit 9f7607c064
3 changed files with 29 additions and 1 deletions

View File

@ -572,6 +572,9 @@ namespace Slic3r {
}
}
// fixes the min z of the model if negative
model.adjust_min_z();
return true;
}

View File

@ -409,6 +409,25 @@ void Model::convert_multipart_object()
this->objects.push_back(object);
}
void Model::adjust_min_z()
{
if (objects.empty())
return;
if (bounding_box().min.z < 0.0)
{
for (ModelObject* obj : objects)
{
if (obj != nullptr)
{
coordf_t obj_min_z = obj->bounding_box().min.z;
if (obj_min_z < 0.0)
obj->translate(0.0, 0.0, -obj_min_z);
}
}
}
}
ModelObject::ModelObject(Model *model, const ModelObject &other, bool copy_volumes) :
name(other.name),
input_file(other.input_file),
@ -671,7 +690,10 @@ void ModelObject::transform(const float* matrix3x4)
v->mesh.transform(matrix3x4);
}
origin_translation = Pointf3(0.0f, 0.0f, 0.0f);
//#####################################################################################################
origin_translation = Pointf3(0.0, 0.0, 0.0);
// origin_translation = Pointf3(0.0f, 0.0f, 0.0f);
//#####################################################################################################
invalidate_bounding_box();
}

View File

@ -273,6 +273,9 @@ public:
bool looks_like_multipart_object() const;
void convert_multipart_object();
// Ensures that the min z of the model is not negative
void adjust_min_z();
void print_info() const { for (const ModelObject *o : this->objects) o->print_info(); }
};