Object merge: fixed merge of the objects with changed rotation, scale and mirror
+ Fixed get_object_stl_stats()
This commit is contained in:
parent
4f63095d9a
commit
530786fca4
2 changed files with 32 additions and 20 deletions
|
@ -1480,9 +1480,6 @@ stl_stats ModelObject::get_object_stl_stats() const
|
||||||
// fill full_stats from all objet's meshes
|
// fill full_stats from all objet's meshes
|
||||||
for (ModelVolume* volume : this->volumes)
|
for (ModelVolume* volume : this->volumes)
|
||||||
{
|
{
|
||||||
if (volume->id() == this->volumes[0]->id())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const stl_stats& stats = volume->mesh().stl.stats;
|
const stl_stats& stats = volume->mesh().stl.stats;
|
||||||
|
|
||||||
// initialize full_stats (for repaired errors)
|
// initialize full_stats (for repaired errors)
|
||||||
|
|
|
@ -2506,7 +2506,6 @@ void ObjectList::merge(bool to_multipart_object)
|
||||||
|
|
||||||
// all objects, created from the instances will be added to the end of list
|
// all objects, created from the instances will be added to the end of list
|
||||||
int new_objects_cnt = 0; // count of this new objects
|
int new_objects_cnt = 0; // count of this new objects
|
||||||
// std::vector<int> obj_idxs;
|
|
||||||
|
|
||||||
for (auto map_item : sel_map)
|
for (auto map_item : sel_map)
|
||||||
{
|
{
|
||||||
|
@ -2569,22 +2568,45 @@ void ObjectList::merge(bool to_multipart_object)
|
||||||
new_object->name = _u8L("Merged");
|
new_object->name = _u8L("Merged");
|
||||||
DynamicPrintConfig* config = &new_object->config;
|
DynamicPrintConfig* config = &new_object->config;
|
||||||
|
|
||||||
int frst_obj_idx = obj_idxs.front();
|
|
||||||
const Vec3d& main_offset = (*m_objects)[frst_obj_idx]->instances[0]->get_offset();
|
|
||||||
|
|
||||||
for (int obj_idx : obj_idxs)
|
for (int obj_idx : obj_idxs)
|
||||||
{
|
{
|
||||||
ModelObject* object = (*m_objects)[obj_idx];
|
ModelObject* object = (*m_objects)[obj_idx];
|
||||||
Vec3d offset = object->instances[0]->get_offset();
|
|
||||||
|
|
||||||
if (object->id() == (*m_objects)[frst_obj_idx]->id())
|
const Geometry::Transformation& transformation = object->instances[0]->get_transformation();
|
||||||
new_object->add_instance(*object->instances[0]);
|
Vec3d scale = transformation.get_scaling_factor();
|
||||||
|
Vec3d mirror = transformation.get_mirror();
|
||||||
|
Vec3d rotation = transformation.get_rotation();
|
||||||
|
|
||||||
|
if (object->id() == (*m_objects)[obj_idxs.front()]->id())
|
||||||
|
new_object->add_instance();
|
||||||
|
Transform3d volume_offset_correction = new_object->instances[0]->get_transformation().get_matrix().inverse() * transformation.get_matrix();
|
||||||
|
|
||||||
|
// merge volumes
|
||||||
|
for (const ModelVolume* volume : object->volumes) {
|
||||||
|
ModelVolume* new_volume = new_object->add_volume(*volume);
|
||||||
|
|
||||||
|
//set rotation
|
||||||
|
Vec3d vol_rot = new_volume->get_rotation() + rotation;
|
||||||
|
new_volume->set_rotation(vol_rot);
|
||||||
|
|
||||||
|
// set scale
|
||||||
|
Vec3d vol_sc_fact = new_volume->get_scaling_factor().cwiseProduct(scale);
|
||||||
|
new_volume->set_scaling_factor(vol_sc_fact);
|
||||||
|
|
||||||
|
// set mirror
|
||||||
|
Vec3d vol_mirror = new_volume->get_mirror().cwiseProduct(mirror);
|
||||||
|
new_volume->set_mirror(vol_mirror);
|
||||||
|
|
||||||
|
// set offset
|
||||||
|
Vec3d vol_offset = volume_offset_correction* new_volume->get_offset();
|
||||||
|
new_volume->set_offset(vol_offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
// merge settings
|
||||||
auto new_opt_keys = config->keys();
|
auto new_opt_keys = config->keys();
|
||||||
|
|
||||||
const DynamicPrintConfig& from_config = object->config;
|
const DynamicPrintConfig& from_config = object->config;
|
||||||
auto opt_keys = from_config.keys();
|
auto opt_keys = from_config.keys();
|
||||||
|
|
||||||
// merge settings
|
|
||||||
for (auto& opt_key : opt_keys) {
|
for (auto& opt_key : opt_keys) {
|
||||||
if (find(new_opt_keys.begin(), new_opt_keys.end(), opt_key) == new_opt_keys.end()) {
|
if (find(new_opt_keys.begin(), new_opt_keys.end(), opt_key) == new_opt_keys.end()) {
|
||||||
const ConfigOption* option = from_config.option(opt_key);
|
const ConfigOption* option = from_config.option(opt_key);
|
||||||
|
@ -2596,13 +2618,6 @@ void ObjectList::merge(bool to_multipart_object)
|
||||||
config->set_key_value(opt_key, option->clone());
|
config->set_key_value(opt_key, option->clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge volumes
|
|
||||||
for (const ModelVolume* volume : object->volumes) {
|
|
||||||
ModelVolume* new_volume = new_object->add_volume(*volume);
|
|
||||||
Vec3d vol_offset = offset - main_offset + new_volume->get_offset();
|
|
||||||
new_volume->set_offset(vol_offset);
|
|
||||||
}
|
|
||||||
// save extruder value if it was set
|
// save extruder value if it was set
|
||||||
if (object->volumes.size() == 1 && find(opt_keys.begin(), opt_keys.end(), "extruder") != opt_keys.end()) {
|
if (object->volumes.size() == 1 && find(opt_keys.begin(), opt_keys.end(), "extruder") != opt_keys.end()) {
|
||||||
ModelVolume* volume = new_object->volumes.back();
|
ModelVolume* volume = new_object->volumes.back();
|
||||||
|
|
Loading…
Reference in a new issue