mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-08 22:35:15 -06:00
New feature: Splitting an object into a multi-part volume.
This commit is contained in:
parent
a1f6403463
commit
b724d789fd
6 changed files with 95 additions and 30 deletions
|
@ -685,6 +685,36 @@ ModelMaterial* ModelVolume::assign_unique_material()
|
|||
return model->add_material(this->_material_id);
|
||||
}
|
||||
|
||||
// Split this volume, append the result to the object owning this volume.
|
||||
// Return the number of volumes created from this one.
|
||||
// This is useful to assign different materials to different volumes of an object.
|
||||
size_t ModelVolume::split()
|
||||
{
|
||||
TriangleMeshPtrs meshptrs = this->mesh.split();
|
||||
if (meshptrs.size() <= 1) {
|
||||
delete meshptrs.front();
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t idx = 0;
|
||||
size_t ivolume = std::find(this->object->volumes.begin(), this->object->volumes.end(), this) - this->object->volumes.begin();
|
||||
std::string name = this->name;
|
||||
for (TriangleMesh *mesh : meshptrs) {
|
||||
mesh->repair();
|
||||
if (idx == 0)
|
||||
this->mesh = std::move(*mesh);
|
||||
else
|
||||
this->object->volumes.insert(this->object->volumes.begin() + (++ ivolume), new ModelVolume(object, *this, std::move(*mesh)));
|
||||
char str_idx[64];
|
||||
sprintf(str_idx, "_%d", idx + 1);
|
||||
this->object->volumes[ivolume]->name = name + str_idx;
|
||||
delete mesh;
|
||||
++ idx;
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const
|
||||
{
|
||||
mesh->rotate_z(this->rotation); // rotate around mesh origin
|
||||
|
|
|
@ -161,6 +161,10 @@ public:
|
|||
void material_id(t_model_material_id material_id);
|
||||
ModelMaterial* material() const;
|
||||
void set_material(t_model_material_id material_id, const ModelMaterial &material);
|
||||
// Split this volume, append the result to the object owning this volume.
|
||||
// Return the number of volumes created from this one.
|
||||
// This is useful to assign different materials to different volumes of an object.
|
||||
size_t split();
|
||||
|
||||
ModelMaterial* assign_unique_material();
|
||||
|
||||
|
@ -174,6 +178,9 @@ private:
|
|||
ModelVolume(ModelObject *object, const ModelVolume &other) :
|
||||
name(other.name), mesh(other.mesh), config(other.config), modifier(other.modifier), object(object)
|
||||
{ this->material_id(other.material_id()); }
|
||||
ModelVolume(ModelObject *object, const ModelVolume &other, const TriangleMesh &&mesh) :
|
||||
name(other.name), mesh(std::move(mesh)), config(other.config), modifier(other.modifier), object(object)
|
||||
{ this->material_id(other.material_id()); }
|
||||
};
|
||||
|
||||
// A single instance of a ModelObject.
|
||||
|
|
|
@ -78,28 +78,11 @@ TriangleMesh::TriangleMesh(const Pointf3s &points, const std::vector<Point3>& fa
|
|||
stl_get_size(&stl);
|
||||
}
|
||||
|
||||
TriangleMesh::TriangleMesh(const TriangleMesh &other)
|
||||
: stl(other.stl), repaired(other.repaired)
|
||||
TriangleMesh::TriangleMesh(const TriangleMesh &other) :
|
||||
repaired(false)
|
||||
{
|
||||
this->stl.heads = NULL;
|
||||
this->stl.tail = NULL;
|
||||
this->stl.error = other.stl.error;
|
||||
if (other.stl.facet_start != NULL) {
|
||||
this->stl.facet_start = (stl_facet*)calloc(other.stl.stats.number_of_facets, sizeof(stl_facet));
|
||||
std::copy(other.stl.facet_start, other.stl.facet_start + other.stl.stats.number_of_facets, this->stl.facet_start);
|
||||
}
|
||||
if (other.stl.neighbors_start != NULL) {
|
||||
this->stl.neighbors_start = (stl_neighbors*)calloc(other.stl.stats.number_of_facets, sizeof(stl_neighbors));
|
||||
std::copy(other.stl.neighbors_start, other.stl.neighbors_start + other.stl.stats.number_of_facets, this->stl.neighbors_start);
|
||||
}
|
||||
if (other.stl.v_indices != NULL) {
|
||||
this->stl.v_indices = (v_indices_struct*)calloc(other.stl.stats.number_of_facets, sizeof(v_indices_struct));
|
||||
std::copy(other.stl.v_indices, other.stl.v_indices + other.stl.stats.number_of_facets, this->stl.v_indices);
|
||||
}
|
||||
if (other.stl.v_shared != NULL) {
|
||||
this->stl.v_shared = (stl_vertex*)calloc(other.stl.stats.shared_vertices, sizeof(stl_vertex));
|
||||
std::copy(other.stl.v_shared, other.stl.v_shared + other.stl.stats.shared_vertices, this->stl.v_shared);
|
||||
}
|
||||
stl_initialize(&this->stl);
|
||||
*this = other;
|
||||
}
|
||||
|
||||
TriangleMesh::TriangleMesh(TriangleMesh &&other) :
|
||||
|
@ -109,9 +92,30 @@ TriangleMesh::TriangleMesh(TriangleMesh &&other) :
|
|||
this->swap(other);
|
||||
}
|
||||
|
||||
TriangleMesh& TriangleMesh::operator= (TriangleMesh other)
|
||||
TriangleMesh& TriangleMesh::operator=(const TriangleMesh &other)
|
||||
{
|
||||
this->swap(other);
|
||||
stl_close(&this->stl);
|
||||
this->stl = other.stl;
|
||||
this->repaired = other.repaired;
|
||||
this->stl.heads = nullptr;
|
||||
this->stl.tail = nullptr;
|
||||
this->stl.error = other.stl.error;
|
||||
if (other.stl.facet_start != nullptr) {
|
||||
this->stl.facet_start = (stl_facet*)calloc(other.stl.stats.number_of_facets, sizeof(stl_facet));
|
||||
std::copy(other.stl.facet_start, other.stl.facet_start + other.stl.stats.number_of_facets, this->stl.facet_start);
|
||||
}
|
||||
if (other.stl.neighbors_start != nullptr) {
|
||||
this->stl.neighbors_start = (stl_neighbors*)calloc(other.stl.stats.number_of_facets, sizeof(stl_neighbors));
|
||||
std::copy(other.stl.neighbors_start, other.stl.neighbors_start + other.stl.stats.number_of_facets, this->stl.neighbors_start);
|
||||
}
|
||||
if (other.stl.v_indices != nullptr) {
|
||||
this->stl.v_indices = (v_indices_struct*)calloc(other.stl.stats.number_of_facets, sizeof(v_indices_struct));
|
||||
std::copy(other.stl.v_indices, other.stl.v_indices + other.stl.stats.number_of_facets, this->stl.v_indices);
|
||||
}
|
||||
if (other.stl.v_shared != nullptr) {
|
||||
this->stl.v_shared = (stl_vertex*)calloc(other.stl.stats.shared_vertices, sizeof(stl_vertex));
|
||||
std::copy(other.stl.v_shared, other.stl.v_shared + other.stl.stats.shared_vertices, this->stl.v_shared);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -427,7 +431,7 @@ TriangleMesh::split() const
|
|||
if (!this->repaired) CONFESS("split() requires repair()");
|
||||
|
||||
// loop while we have remaining facets
|
||||
while (1) {
|
||||
for (;;) {
|
||||
// get the first facet
|
||||
std::queue<int> facet_queue;
|
||||
std::deque<int> facets;
|
||||
|
|
|
@ -24,8 +24,8 @@ public:
|
|||
TriangleMesh(const Pointf3s &points, const std::vector<Point3> &facets);
|
||||
TriangleMesh(const TriangleMesh &other);
|
||||
TriangleMesh(TriangleMesh &&other);
|
||||
TriangleMesh& operator= (TriangleMesh other);
|
||||
TriangleMesh& operator= (TriangleMesh &&other);
|
||||
TriangleMesh& operator=(const TriangleMesh &other);
|
||||
TriangleMesh& operator=(TriangleMesh &&other);
|
||||
void swap(TriangleMesh &other);
|
||||
~TriangleMesh();
|
||||
void ReadSTLFile(const char* input_file);
|
||||
|
|
|
@ -297,6 +297,8 @@ ModelMaterial::attributes()
|
|||
%code%{ RETVAL = THIS->modifier; %};
|
||||
void set_modifier(bool modifier)
|
||||
%code%{ THIS->modifier = modifier; %};
|
||||
|
||||
size_t split();
|
||||
|
||||
ModelMaterial* assign_unique_material();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue