Merge remote-tracking branch 'origin/dev_native' into tm_sla_supports_backend

This commit is contained in:
tamasmeszaros 2018-11-19 12:56:32 +01:00
commit 0fcdc70327
22 changed files with 523 additions and 189 deletions

View file

@ -951,25 +951,54 @@ bool ModelObject::needed_repair() const
return false;
}
void ModelObject::cut(coordf_t z, Model* model) const
template<class T> static void cut_reset_transform(T *thing) {
const Vec3d offset = thing->get_offset();
thing->set_transformation(Geometry::Transformation());
thing->set_offset(offset);
}
ModelObjectPtrs ModelObject::cut(size_t instance, coordf_t z)
{
// clone this one to duplicate instances, materials etc.
ModelObject* upper = model->add_object(*this);
ModelObject* lower = model->add_object(*this);
// Clone the object to duplicate instances, materials etc.
ModelObject* upper = ModelObject::new_clone(*this);
ModelObject* lower = ModelObject::new_clone(*this);
upper->set_model(nullptr);
lower->set_model(nullptr);
upper->sla_support_points.clear();
lower->sla_support_points.clear();
upper->clear_volumes();
lower->clear_volumes();
upper->input_file = "";
lower->input_file = "";
for (ModelVolume *volume : this->volumes) {
const auto instance_matrix = instances[instance]->get_matrix(true);
// Because transformations are going to be applied to meshes directly,
// we reset transformation of all instances and volumes,
// _except_ for translation, which is preserved in the transformation matrix
// and not applied to the mesh transform.
// TODO: Do the same for Z-rotation as well?
// Convert z from relative to bb's base to object coordinates
// FIXME: doesn't work well for rotated objects
const auto bb = instance_bounding_box(instance, true);
z -= bb.min(2);
for (auto *instance : upper->instances) { cut_reset_transform(instance); }
for (auto *instance : lower->instances) { cut_reset_transform(instance); }
for (ModelVolume *volume : volumes) {
if (! volume->is_model_part()) {
// don't cut modifiers
upper->add_volume(*volume);
lower->add_volume(*volume);
} else {
TriangleMesh upper_mesh, lower_mesh;
// Transform the mesh by the object transformation matrix
volume->mesh.transform(instance_matrix * volume->get_matrix(true));
cut_reset_transform(volume);
TriangleMeshSlicer tms(&volume->mesh);
tms.cut(z, &upper_mesh, &lower_mesh);
@ -977,7 +1006,7 @@ void ModelObject::cut(coordf_t z, Model* model) const
lower_mesh.repair();
upper_mesh.reset_repair_stats();
lower_mesh.reset_repair_stats();
if (upper_mesh.facets_count() > 0) {
ModelVolume* vol = upper->add_volume(upper_mesh);
vol->name = volume->name;
@ -992,6 +1021,15 @@ void ModelObject::cut(coordf_t z, Model* model) const
}
}
}
upper->invalidate_bounding_box();
lower->invalidate_bounding_box();
ModelObjectPtrs res;
if (upper->volumes.size() > 0) { res.push_back(upper); }
if (lower->volumes.size() > 0) { res.push_back(lower); }
return res;
}
void ModelObject::split(ModelObjectPtrs* new_objects)
@ -1011,7 +1049,8 @@ void ModelObject::split(ModelObjectPtrs* new_objects)
mesh->repair();
ModelObject* new_object = m_model->add_object();
// XXX: this seems to be the only real usage of m_model, maybe refactor this so that it's not needed?
ModelObject* new_object = m_model->add_object();
new_object->name = this->name;
new_object->config = this->config;
new_object->instances.reserve(this->instances.size());

View file

@ -237,7 +237,7 @@ public:
size_t materials_count() const;
size_t facets_count() const;
bool needed_repair() const;
void cut(coordf_t z, Model* model) const;
ModelObjectPtrs cut(size_t instance, coordf_t z);
void split(ModelObjectPtrs* new_objects);
void repair();
@ -607,7 +607,7 @@ public:
bool delete_object(ModelID id);
bool delete_object(ModelObject* object);
void clear_objects();
ModelMaterial* add_material(t_model_material_id material_id);
ModelMaterial* add_material(t_model_material_id material_id, const ModelMaterial &other);
ModelMaterial* get_material(t_model_material_id material_id) {

View file

@ -68,6 +68,8 @@ namespace PerlUtils {
extern std::string path_to_parent_path(const char *src);
};
std::string string_printf(const char *format, ...);
// Timestamp formatted for header_slic3r_generated().
extern std::string timestamp_str();
// Standard "generated by Slic3r version xxx timestamp xxx" header string,

View file

@ -3,6 +3,8 @@
#include <locale>
#include <ctime>
#include <cstdarg>
#include <stdio.h>
#ifdef WIN32
#include <windows.h>
@ -297,6 +299,25 @@ namespace PerlUtils {
std::string path_to_parent_path(const char *src) { return boost::filesystem::path(src).parent_path().string(); }
};
std::string string_printf(const char *format, ...)
{
va_list args1;
va_start(args1, format);
va_list args2;
va_copy(args2, args1);
size_t needed_size = ::vsnprintf(nullptr, 0, format, args1) + 1;
va_end(args1);
std::string res(needed_size, '\0');
::vsnprintf(&res.front(), res.size(), format, args2);
va_end(args2);
return res;
}
std::string timestamp_str()
{
const auto now = boost::posix_time::second_clock::local_time();