mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-25 15:47:25 +08:00
Implemented TriangleMesh->merge
This commit is contained in:
parent
27e7c6b9f7
commit
3919ba83d8
@ -525,4 +525,23 @@ TriangleMesh::split() const
|
|||||||
return meshes;
|
return meshes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TriangleMesh::merge(const TriangleMesh* mesh)
|
||||||
|
{
|
||||||
|
// reset stats and metadata
|
||||||
|
int number_of_facets = this->stl.stats.number_of_facets;
|
||||||
|
stl_initialize(&this->stl);
|
||||||
|
stl_invalidate_shared_vertices(&this->stl);
|
||||||
|
|
||||||
|
// update facet count and allocate more memory
|
||||||
|
this->stl.stats.number_of_facets = number_of_facets + mesh->stl.stats.number_of_facets;
|
||||||
|
this->stl.stats.original_num_facets = this->stl.stats.number_of_facets;
|
||||||
|
stl_reallocate(&this->stl);
|
||||||
|
|
||||||
|
// copy facets
|
||||||
|
for (int i = 0; i < mesh->stl.stats.number_of_facets; i++) {
|
||||||
|
this->stl.facet_start[number_of_facets + i] = mesh->stl.facet_start[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ class TriangleMesh
|
|||||||
void rotate(double angle, Point* center);
|
void rotate(double angle, Point* center);
|
||||||
std::vector<Polygons>* slice(const std::vector<double> &z);
|
std::vector<Polygons>* slice(const std::vector<double> &z);
|
||||||
TriangleMeshPtrs split() const;
|
TriangleMeshPtrs split() const;
|
||||||
|
void merge(const TriangleMesh* mesh);
|
||||||
stl_file stl;
|
stl_file stl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ static void stl_count_facets(stl_file *stl, char *file);
|
|||||||
extern void stl_allocate(stl_file *stl);
|
extern void stl_allocate(stl_file *stl);
|
||||||
static void stl_read(stl_file *stl, int first_facet, int first);
|
static void stl_read(stl_file *stl, int first_facet, int first);
|
||||||
static void stl_facet_stats(stl_file *stl, stl_facet facet, int first);
|
static void stl_facet_stats(stl_file *stl, stl_facet facet, int first);
|
||||||
static void stl_reallocate(stl_file *stl);
|
extern void stl_reallocate(stl_file *stl);
|
||||||
static int stl_get_little_int(FILE *fp);
|
static int stl_get_little_int(FILE *fp);
|
||||||
static float stl_get_little_float(FILE *fp);
|
static float stl_get_little_float(FILE *fp);
|
||||||
extern void stl_get_size(stl_file *stl);
|
extern void stl_get_size(stl_file *stl);
|
||||||
|
@ -213,7 +213,7 @@ stl_open_merge(stl_file *stl, char *file)
|
|||||||
stl_read(stl, first_facet, 0);
|
stl_read(stl, first_facet, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
extern void
|
||||||
stl_reallocate(stl_file *stl)
|
stl_reallocate(stl_file *stl)
|
||||||
{
|
{
|
||||||
/* Reallocate more memory for the .STL file(s) */
|
/* Reallocate more memory for the .STL file(s) */
|
||||||
|
@ -4,7 +4,7 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Slic3r::XS;
|
use Slic3r::XS;
|
||||||
use Test::More tests => 45;
|
use Test::More tests => 46;
|
||||||
|
|
||||||
is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
|
is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
|
||||||
'hello world';
|
'hello world';
|
||||||
@ -46,6 +46,11 @@ my $cube = {
|
|||||||
my $result = $m->split;
|
my $result = $m->split;
|
||||||
is scalar(@$result), 1, 'split';
|
is scalar(@$result), 1, 'split';
|
||||||
isa_ok $result->[0], 'Slic3r::TriangleMesh::XS', 'split';
|
isa_ok $result->[0], 'Slic3r::TriangleMesh::XS', 'split';
|
||||||
|
|
||||||
|
my $m2 = Slic3r::TriangleMesh::XS->new;
|
||||||
|
$m2->ReadFromPerl($cube->{vertices}, $cube->{facets});
|
||||||
|
$m->merge($m2);
|
||||||
|
is $m->stats->{number_of_facets}, 2 * $m2->stats->{number_of_facets}, 'merge';
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
void align_to_origin();
|
void align_to_origin();
|
||||||
void rotate(double angle, Point* center);
|
void rotate(double angle, Point* center);
|
||||||
TriangleMeshPtrs split();
|
TriangleMeshPtrs split();
|
||||||
|
void merge(TriangleMesh* mesh);
|
||||||
%{
|
%{
|
||||||
|
|
||||||
SV*
|
SV*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user