Use precomputed normals in 3D preview
This commit is contained in:
parent
d4512a12df
commit
bc48e17dff
@ -49,14 +49,14 @@ sub new {
|
||||
color => COLORS->[ $color_idx % scalar(@{&COLORS}) ],
|
||||
};
|
||||
|
||||
my ($vertices, $facets) = ($mesh->vertices, $mesh->facets);
|
||||
{
|
||||
my @verts = map @{ $vertices->[$_] }, map @$_, @$facets;
|
||||
my $vertices = $mesh->vertices;
|
||||
my @verts = map @{ $vertices->[$_] }, map @$_, @{$mesh->facets};
|
||||
$v->{verts} = OpenGL::Array->new_list(GL_FLOAT, @verts);
|
||||
}
|
||||
|
||||
{
|
||||
my @norms = map { @$_, @$_, @$_ } map normalize(triangle_normal(map $vertices->[$_], @$_)), @$facets;
|
||||
my @norms = map @$_, @{$mesh->normals};
|
||||
$v->{norms} = OpenGL::Array->new_list(GL_FLOAT, @norms);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use strict;
|
||||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 50;
|
||||
use Test::More tests => 51;
|
||||
|
||||
is Slic3r::TriangleMesh::hello_world(), 'Hello world!',
|
||||
'hello world';
|
||||
@ -22,6 +22,7 @@ my $cube = {
|
||||
|
||||
is_deeply $vertices, $cube->{vertices}, 'vertices arrayref roundtrip';
|
||||
is_deeply $facets, $cube->{facets}, 'facets arrayref roundtrip';
|
||||
is scalar(@{$m->normals}), scalar(@$facets), 'normals returns the right number of items';
|
||||
|
||||
{
|
||||
my $m2 = $m->clone;
|
||||
|
@ -92,6 +92,27 @@ TriangleMesh::facets()
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV*
|
||||
TriangleMesh::normals()
|
||||
CODE:
|
||||
if (!THIS->repaired) CONFESS("normals() requires repair()");
|
||||
|
||||
// normals
|
||||
AV* normals = newAV();
|
||||
av_extend(normals, THIS->stl.stats.number_of_facets);
|
||||
for (int i = 0; i < THIS->stl.stats.number_of_facets; i++) {
|
||||
AV* facet = newAV();
|
||||
av_store(normals, i, newRV_noinc((SV*)facet));
|
||||
av_extend(facet, 2);
|
||||
av_store(facet, 0, newSVnv(THIS->stl.facet_start[i].normal.x));
|
||||
av_store(facet, 1, newSVnv(THIS->stl.facet_start[i].normal.y));
|
||||
av_store(facet, 2, newSVnv(THIS->stl.facet_start[i].normal.z));
|
||||
}
|
||||
|
||||
RETVAL = newRV_noinc((SV*)normals);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV*
|
||||
TriangleMesh::size()
|
||||
CODE:
|
||||
|
Loading…
Reference in New Issue
Block a user