mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-22 04:28:05 +08:00
Incomplete work for porting translate()
This commit is contained in:
parent
515d5707c9
commit
04d5d1bb9b
@ -107,4 +107,9 @@ void TriangleMesh::scale(float factor)
|
|||||||
stl_scale(&(this->stl), factor);
|
stl_scale(&(this->stl), factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TriangleMesh::translate(float x, float y, float z)
|
||||||
|
{
|
||||||
|
stl_translate(&(this->stl), x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ class TriangleMesh
|
|||||||
void Repair();
|
void Repair();
|
||||||
void WriteOBJFile(char* output_file);
|
void WriteOBJFile(char* output_file);
|
||||||
void scale(float factor);
|
void scale(float factor);
|
||||||
|
void translate(float x, float y, float z);
|
||||||
stl_file stl;
|
stl_file stl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,6 +23,14 @@
|
|||||||
|
|
||||||
#include "stl.h"
|
#include "stl.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
stl_invalidate_shared_vertices(stl_file *stl)
|
||||||
|
{
|
||||||
|
if (stl->v_indices != NULL)
|
||||||
|
free(stl->v_indices);
|
||||||
|
if (stl->v_shared != NULL)
|
||||||
|
free(stl->v_shared);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stl_generate_shared_vertices(stl_file *stl)
|
stl_generate_shared_vertices(stl_file *stl)
|
||||||
@ -38,6 +46,9 @@ stl_generate_shared_vertices(stl_file *stl)
|
|||||||
int next_facet;
|
int next_facet;
|
||||||
int reversed;
|
int reversed;
|
||||||
|
|
||||||
|
// make sure this function is idempotent and does not leak memory
|
||||||
|
stl_invalidate_shared_vertices(stl);
|
||||||
|
|
||||||
stl->v_indices = (v_indices_struct*)
|
stl->v_indices = (v_indices_struct*)
|
||||||
calloc(stl->stats.number_of_facets, sizeof(v_indices_struct));
|
calloc(stl->stats.number_of_facets, sizeof(v_indices_struct));
|
||||||
if(stl->v_indices == NULL) perror("stl_generate_shared_vertices");
|
if(stl->v_indices == NULL) perror("stl_generate_shared_vertices");
|
||||||
|
@ -163,6 +163,7 @@ extern void stl_mirror_xy(stl_file *stl);
|
|||||||
extern void stl_mirror_yz(stl_file *stl);
|
extern void stl_mirror_yz(stl_file *stl);
|
||||||
extern void stl_mirror_xz(stl_file *stl);
|
extern void stl_mirror_xz(stl_file *stl);
|
||||||
extern void stl_open_merge(stl_file *stl, char *file);
|
extern void stl_open_merge(stl_file *stl, char *file);
|
||||||
|
extern void stl_invalidate_shared_vertices(stl_file *stl);
|
||||||
extern void stl_generate_shared_vertices(stl_file *stl);
|
extern void stl_generate_shared_vertices(stl_file *stl);
|
||||||
extern void stl_write_obj(stl_file *stl, char *file);
|
extern void stl_write_obj(stl_file *stl, char *file);
|
||||||
extern void stl_write_off(stl_file *stl, char *file);
|
extern void stl_write_off(stl_file *stl, char *file);
|
||||||
|
@ -87,17 +87,19 @@ stl_translate(stl_file *stl, float x, float y, float z)
|
|||||||
{
|
{
|
||||||
for(j = 0; j < 3; j++)
|
for(j = 0; j < 3; j++)
|
||||||
{
|
{
|
||||||
stl->facet_start[i].vertex[j].x -= (stl->stats.min.x - x);
|
stl->facet_start[i].vertex[j].x += x;
|
||||||
stl->facet_start[i].vertex[j].y -= (stl->stats.min.y - y);
|
stl->facet_start[i].vertex[j].y += y;
|
||||||
stl->facet_start[i].vertex[j].z -= (stl->stats.min.z - z);
|
stl->facet_start[i].vertex[j].z += z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stl->stats.max.x -= (stl->stats.min.x - x);
|
stl->stats.min.x += x;
|
||||||
stl->stats.max.y -= (stl->stats.min.y - y);
|
stl->stats.min.y += y;
|
||||||
stl->stats.max.z -= (stl->stats.min.z - z);
|
stl->stats.min.z += z;
|
||||||
stl->stats.min.x = x;
|
stl->stats.max.x += x;
|
||||||
stl->stats.min.y = y;
|
stl->stats.max.y += y;
|
||||||
stl->stats.min.z = z;
|
stl->stats.max.z += z;
|
||||||
|
|
||||||
|
stl_invalidate_shared_vertices(stl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -128,6 +130,8 @@ stl_scale(stl_file *stl, float factor)
|
|||||||
stl->facet_start[i].vertex[j].z *= factor;
|
stl->facet_start[i].vertex[j].z *= factor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stl_invalidate_shared_vertices(stl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void calculate_normals(stl_file *stl)
|
static void calculate_normals(stl_file *stl)
|
||||||
|
@ -4,7 +4,7 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Slic3r::XS;
|
use Slic3r::XS;
|
||||||
use Test::More tests => 6;
|
use Test::More tests => 7;
|
||||||
|
|
||||||
is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
|
is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
|
||||||
'hello world';
|
'hello world';
|
||||||
@ -31,6 +31,9 @@ my $cube = {
|
|||||||
|
|
||||||
$m->scale(2);
|
$m->scale(2);
|
||||||
ok abs($m->stats->{volume} - 40*40*40) < 1E-2, 'scale';
|
ok abs($m->stats->{volume} - 40*40*40) < 1E-2, 'scale';
|
||||||
|
|
||||||
|
$m->translate(5,10,0);
|
||||||
|
is_deeply $m->vertices->[0], [45,50,0], 'translate';
|
||||||
}
|
}
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
void Repair();
|
void Repair();
|
||||||
void WriteOBJFile(char* output_file);
|
void WriteOBJFile(char* output_file);
|
||||||
void scale(float factor);
|
void scale(float factor);
|
||||||
|
void translate(float x, float y, float z);
|
||||||
%{
|
%{
|
||||||
|
|
||||||
SV*
|
SV*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user