mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-03 05:40:36 +08:00
Ported couple Model methods to C++
This commit is contained in:
parent
bd2117d346
commit
3ee628c29f
@ -52,33 +52,6 @@ sub set_material {
|
||||
return $material;
|
||||
}
|
||||
|
||||
sub looks_like_multipart_object {
|
||||
my ($self) = @_;
|
||||
|
||||
return 0 if $self->objects_count == 1;
|
||||
return 0 if any { $_->volumes_count > 1 } @{$self->objects};
|
||||
return 0 if any { @{$_->config->get_keys} > 1 } @{$self->objects};
|
||||
|
||||
my %heights = map { $_ => 1 } map $_->mesh->bounding_box->z_min, map @{$_->volumes}, @{$self->objects};
|
||||
return scalar(keys %heights) > 1;
|
||||
}
|
||||
|
||||
sub convert_multipart_object {
|
||||
my ($self) = @_;
|
||||
|
||||
my @objects = @{$self->objects};
|
||||
my $object = $self->add_object(
|
||||
input_file => $objects[0]->input_file,
|
||||
);
|
||||
foreach my $v (map @{$_->volumes}, @objects) {
|
||||
my $volume = $object->add_volume($v);
|
||||
$volume->set_name($v->object->name);
|
||||
}
|
||||
$object->add_instance($_) for @{$objects[0]->instances};
|
||||
|
||||
$self->delete_object($_) for reverse 0..($self->objects_count-2);
|
||||
}
|
||||
|
||||
# Extends C++ class Slic3r::ModelMaterial
|
||||
package Slic3r::Model::Material;
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "Geometry.hpp"
|
||||
#include "IO.hpp"
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
@ -372,6 +373,43 @@ Model::print_info() const
|
||||
(*o)->print_info();
|
||||
}
|
||||
|
||||
bool
|
||||
Model::looks_like_multipart_object() const
|
||||
{
|
||||
if (this->objects.size() == 1) return false;
|
||||
for (const ModelObject* o : this->objects) {
|
||||
if (o->volumes.size() > 1) return false;
|
||||
if (o->config.keys().size() > 1) return false;
|
||||
}
|
||||
|
||||
std::set<coordf_t> heights;
|
||||
for (const ModelObject* o : this->objects)
|
||||
for (const ModelVolume* v : o->volumes)
|
||||
heights.insert(v->mesh.bounding_box().min.z);
|
||||
return heights.size() > 1;
|
||||
}
|
||||
|
||||
void
|
||||
Model::convert_multipart_object()
|
||||
{
|
||||
if (this->objects.empty()) return;
|
||||
|
||||
ModelObject* object = this->add_object();
|
||||
object->input_file = this->objects.front()->input_file;
|
||||
|
||||
for (const ModelObject* o : this->objects) {
|
||||
for (const ModelVolume* v : o->volumes) {
|
||||
ModelVolume* v2 = object->add_volume(*v);
|
||||
v2->name = o->name;
|
||||
}
|
||||
}
|
||||
for (const ModelInstance* i : this->objects.front()->instances)
|
||||
object->add_instance(*i);
|
||||
|
||||
while (this->objects.size() > 1)
|
||||
this->delete_object(0);
|
||||
}
|
||||
|
||||
ModelMaterial::ModelMaterial(Model *model) : model(model) {}
|
||||
ModelMaterial::ModelMaterial(Model *model, const ModelMaterial &other)
|
||||
: attributes(other.attributes), config(other.config), model(model)
|
||||
|
@ -74,6 +74,8 @@ class Model
|
||||
void duplicate_objects(size_t copies_num, coordf_t dist, const BoundingBoxf* bb = NULL);
|
||||
void duplicate_objects_grid(size_t x, size_t y, coordf_t dist);
|
||||
void print_info() const;
|
||||
bool looks_like_multipart_object() const;
|
||||
void convert_multipart_object();
|
||||
};
|
||||
|
||||
// Material, which may be shared across multiple ModelObjects of a single Model.
|
||||
|
@ -95,6 +95,8 @@
|
||||
void duplicate_objects(unsigned int copies_num, double dist, BoundingBoxf* bb = NULL);
|
||||
void duplicate_objects_grid(unsigned int x, unsigned int y, double dist);
|
||||
void print_info();
|
||||
bool looks_like_multipart_object();
|
||||
void convert_multipart_object();
|
||||
void repair();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user