mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-06-22 12:44:51 +08:00
Merge branch 'opengl'
This commit is contained in:
commit
8e2063397a
2
MANIFEST
2
MANIFEST
@ -37,6 +37,7 @@ lib/Slic3r/GUI/OptionsGroup.pm
|
|||||||
lib/Slic3r/GUI/Plater.pm
|
lib/Slic3r/GUI/Plater.pm
|
||||||
lib/Slic3r/GUI/Plater/ObjectDialog.pm
|
lib/Slic3r/GUI/Plater/ObjectDialog.pm
|
||||||
lib/Slic3r/GUI/Preferences.pm
|
lib/Slic3r/GUI/Preferences.pm
|
||||||
|
lib/Slic3r/GUI/PreviewCanvas.pm
|
||||||
lib/Slic3r/GUI/SkeinPanel.pm
|
lib/Slic3r/GUI/SkeinPanel.pm
|
||||||
lib/Slic3r/GUI/SimpleTab.pm
|
lib/Slic3r/GUI/SimpleTab.pm
|
||||||
lib/Slic3r/GUI/Tab.pm
|
lib/Slic3r/GUI/Tab.pm
|
||||||
@ -88,6 +89,7 @@ utils/post-processing/decimate.pl
|
|||||||
utils/post-processing/flowrate.pl
|
utils/post-processing/flowrate.pl
|
||||||
utils/split_stl.pl
|
utils/split_stl.pl
|
||||||
utils/stl-to-amf.pl
|
utils/stl-to-amf.pl
|
||||||
|
utils/view-mesh.pl
|
||||||
utils/zsh/functions/_slic3r
|
utils/zsh/functions/_slic3r
|
||||||
utils/zsh/README.markdown
|
utils/zsh/README.markdown
|
||||||
var/add.png
|
var/add.png
|
||||||
|
@ -14,6 +14,8 @@ use Slic3r::GUI::SkeinPanel;
|
|||||||
use Slic3r::GUI::SimpleTab;
|
use Slic3r::GUI::SimpleTab;
|
||||||
use Slic3r::GUI::Tab;
|
use Slic3r::GUI::Tab;
|
||||||
|
|
||||||
|
our $have_OpenGL = eval "use Slic3r::GUI::PreviewCanvas; 1";
|
||||||
|
|
||||||
use Wx 0.9901 qw(:bitmap :dialog :frame :icon :id :misc :systemsettings :toplevelwindow);
|
use Wx 0.9901 qw(:bitmap :dialog :frame :icon :id :misc :systemsettings :toplevelwindow);
|
||||||
use Wx::Event qw(EVT_CLOSE EVT_MENU);
|
use Wx::Event qw(EVT_CLOSE EVT_MENU);
|
||||||
use base 'Wx::App';
|
use base 'Wx::App';
|
||||||
|
@ -10,10 +10,12 @@ use base 'Wx::Dialog';
|
|||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my ($parent, %params) = @_;
|
my ($parent, %params) = @_;
|
||||||
my $self = $class->SUPER::new($parent, -1, "Object", wxDefaultPosition, [500,350]);
|
my $self = $class->SUPER::new($parent, -1, "Object", wxDefaultPosition, [500,350], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
|
||||||
$self->{object} = $params{object};
|
$self->{object} = $params{object};
|
||||||
|
|
||||||
$self->{tabpanel} = Wx::Notebook->new($self, -1, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL);
|
$self->{tabpanel} = Wx::Notebook->new($self, -1, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL);
|
||||||
|
$self->{tabpanel}->AddPage($self->{preview} = Slic3r::GUI::Plater::ObjectDialog::PreviewTab->new($self->{tabpanel}, object => $self->{object}), "Preview")
|
||||||
|
if $Slic3r::GUI::have_OpenGL;
|
||||||
$self->{tabpanel}->AddPage($self->{info} = Slic3r::GUI::Plater::ObjectDialog::InfoTab->new($self->{tabpanel}, object => $self->{object}), "Info");
|
$self->{tabpanel}->AddPage($self->{info} = Slic3r::GUI::Plater::ObjectDialog::InfoTab->new($self->{tabpanel}, object => $self->{object}), "Info");
|
||||||
$self->{tabpanel}->AddPage($self->{layers} = Slic3r::GUI::Plater::ObjectDialog::LayersTab->new($self->{tabpanel}, object => $self->{object}), "Layers");
|
$self->{tabpanel}->AddPage($self->{layers} = Slic3r::GUI::Plater::ObjectDialog::LayersTab->new($self->{tabpanel}, object => $self->{object}), "Layers");
|
||||||
|
|
||||||
@ -33,6 +35,7 @@ sub new {
|
|||||||
$sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
|
$sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
|
||||||
|
|
||||||
$self->SetSizer($sizer);
|
$self->SetSizer($sizer);
|
||||||
|
$self->SetMinSize($self->GetSize);
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
@ -83,6 +86,24 @@ sub get_properties {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
package Slic3r::GUI::Plater::ObjectDialog::PreviewTab;
|
||||||
|
use Wx qw(:dialog :id :misc :sizer :systemsettings);
|
||||||
|
use base 'Wx::Panel';
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my $class = shift;
|
||||||
|
my ($parent, %params) = @_;
|
||||||
|
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize);
|
||||||
|
$self->{object} = $params{object};
|
||||||
|
|
||||||
|
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
|
||||||
|
$sizer->Add(Slic3r::GUI::PreviewCanvas->new($self, $self->{object}->get_model_object->mesh), 1, wxEXPAND, 0);
|
||||||
|
$self->SetSizer($sizer);
|
||||||
|
$sizer->SetSizeHints($self);
|
||||||
|
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
package Slic3r::GUI::Plater::ObjectDialog::LayersTab;
|
package Slic3r::GUI::Plater::ObjectDialog::LayersTab;
|
||||||
use Wx qw(:dialog :id :misc :sizer :systemsettings);
|
use Wx qw(:dialog :id :misc :sizer :systemsettings);
|
||||||
use Wx::Grid;
|
use Wx::Grid;
|
||||||
|
200
lib/Slic3r/GUI/PreviewCanvas.pm
Normal file
200
lib/Slic3r/GUI/PreviewCanvas.pm
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
package Slic3r::GUI::PreviewCanvas;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use Wx::Event qw(EVT_PAINT EVT_SIZE EVT_ERASE_BACKGROUND EVT_IDLE EVT_TIMER EVT_MOUSEWHEEL);
|
||||||
|
# must load OpenGL *before* Wx::GLCanvas
|
||||||
|
use OpenGL qw(:glconstants :glfunctions);
|
||||||
|
use base qw(Wx::GLCanvas Class::Accessor);
|
||||||
|
use Slic3r::Geometry qw(X Y Z MIN MAX triangle_normal normalize deg2rad tan);
|
||||||
|
use Wx::GLCanvas qw(:all);
|
||||||
|
|
||||||
|
__PACKAGE__->mk_accessors( qw(timer x_rot y_rot dirty init mesh_center zoom
|
||||||
|
verts norms) );
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ($class, $parent, $mesh) = @_;
|
||||||
|
my $self = $class->SUPER::new($parent);
|
||||||
|
|
||||||
|
# prepare mesh
|
||||||
|
{
|
||||||
|
$self->mesh_center($mesh->center);
|
||||||
|
$self->zoom(0.1);
|
||||||
|
|
||||||
|
my @verts = map $self->zoom * $_, map @{ $mesh->vertices->[$_] }, map @$_, @{$mesh->facets};
|
||||||
|
$self->verts(OpenGL::Array->new_list(GL_FLOAT, @verts));
|
||||||
|
|
||||||
|
my @norms = map { @$_, @$_, @$_ } map normalize(triangle_normal(map $mesh->vertices->[$_], @$_)), @{$mesh->facets};
|
||||||
|
$self->norms(OpenGL::Array->new_list(GL_FLOAT, @norms));
|
||||||
|
}
|
||||||
|
|
||||||
|
my $timer = $self->timer( Wx::Timer->new($self) );
|
||||||
|
$timer->Start(50);
|
||||||
|
|
||||||
|
$self->x_rot(0);
|
||||||
|
$self->y_rot(0);
|
||||||
|
|
||||||
|
EVT_PAINT($self, sub {
|
||||||
|
my $dc = Wx::PaintDC->new($self);
|
||||||
|
$self->Render($dc);
|
||||||
|
});
|
||||||
|
EVT_SIZE($self, sub { $self->dirty(1) });
|
||||||
|
EVT_IDLE($self, sub {
|
||||||
|
return unless $self->dirty;
|
||||||
|
return if !$self->IsShownOnScreen;
|
||||||
|
$self->Resize( $self->GetSizeWH );
|
||||||
|
$self->Refresh;
|
||||||
|
});
|
||||||
|
EVT_TIMER($self, -1, sub {
|
||||||
|
my ($self, $e) = @_;
|
||||||
|
|
||||||
|
$self->x_rot( $self->x_rot - 1 );
|
||||||
|
$self->y_rot( $self->y_rot + 2 );
|
||||||
|
|
||||||
|
$self->dirty(1);
|
||||||
|
Wx::WakeUpIdle;
|
||||||
|
});
|
||||||
|
EVT_MOUSEWHEEL($self, sub {
|
||||||
|
my ($self, $e) = @_;
|
||||||
|
|
||||||
|
my $zoom = $self->zoom * (1.0 - $e->GetWheelRotation() / $e->GetWheelDelta() / 10);
|
||||||
|
$zoom = 0.001 if $zoom < 0.001;
|
||||||
|
$zoom = 0.1 if $zoom > 0.1;
|
||||||
|
$self->zoom($zoom);
|
||||||
|
|
||||||
|
$self->Refresh;
|
||||||
|
});
|
||||||
|
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub GetContext {
|
||||||
|
my ($self) = @_;
|
||||||
|
|
||||||
|
if (Wx::wxVERSION >= 2.009) {
|
||||||
|
return $self->{context} ||= Wx::GLContext->new($self);
|
||||||
|
} else {
|
||||||
|
return $self->SUPER::GetContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub SetCurrent {
|
||||||
|
my ($self, $context) = @_;
|
||||||
|
|
||||||
|
if (Wx::wxVERSION >= 2.009) {
|
||||||
|
return $self->SUPER::SetCurrent($context);
|
||||||
|
} else {
|
||||||
|
return $self->SUPER::SetCurrent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub Resize {
|
||||||
|
my ($self, $x, $y) = @_;
|
||||||
|
|
||||||
|
return unless $self->GetContext;
|
||||||
|
$self->dirty(0);
|
||||||
|
|
||||||
|
$self->SetCurrent($self->GetContext);
|
||||||
|
glViewport(0, 0, $x, $y);
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
my_gluPerspective(45, $x/$y, .5, 100);
|
||||||
|
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub my_gluPerspective {
|
||||||
|
my ($fov, $ratio, $near, $far) = @_;
|
||||||
|
|
||||||
|
my $top = tan(deg2rad($fov)*0.5) * $near;
|
||||||
|
my $bottom = -$top;
|
||||||
|
my $left = $ratio * $bottom;
|
||||||
|
my $right = $ratio * $top;
|
||||||
|
|
||||||
|
glFrustum( $left, $right, $bottom, $top, $near, $far );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub DESTROY {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
$self->timer->Stop;
|
||||||
|
$self->timer(undef);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub InitGL {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return if $self->init;
|
||||||
|
return unless $self->GetContext;
|
||||||
|
$self->init(1);
|
||||||
|
|
||||||
|
glEnable(GL_NORMALIZE);
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
glDepthFunc(GL_LESS);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
# Settings for our light.
|
||||||
|
my @LightPos = (0, 0, 2, 1.0);
|
||||||
|
my @LightAmbient = (0.1, 0.1, 0.1, 1.0);
|
||||||
|
my @LightDiffuse = (0.7, 0.5, 0.5, 1.0);
|
||||||
|
my @LightSpecular = (0.1, 0.1, 0.1, 0.1);
|
||||||
|
|
||||||
|
# Enables Smooth Color Shading; try GL_FLAT for (lack of) fun.
|
||||||
|
glShadeModel(GL_SMOOTH);
|
||||||
|
|
||||||
|
# Set up a light, turn it on.
|
||||||
|
glLightfv_p(GL_LIGHT1, GL_POSITION, @LightPos);
|
||||||
|
glLightfv_p(GL_LIGHT1, GL_AMBIENT, @LightAmbient);
|
||||||
|
glLightfv_p(GL_LIGHT1, GL_DIFFUSE, @LightDiffuse);
|
||||||
|
glLightfv_p(GL_LIGHT1, GL_SPECULAR, @LightSpecular);
|
||||||
|
glEnable(GL_LIGHT1);
|
||||||
|
|
||||||
|
# A handy trick -- have surface material mirror the color.
|
||||||
|
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||||
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub Render {
|
||||||
|
my ($self, $dc) = @_;
|
||||||
|
|
||||||
|
return unless $self->GetContext;
|
||||||
|
$self->SetCurrent($self->GetContext);
|
||||||
|
$self->InitGL;
|
||||||
|
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef( 0, 0, -5 );
|
||||||
|
|
||||||
|
# this needs to get a lot better...
|
||||||
|
glRotatef( $self->x_rot, 1, 0, 0 );
|
||||||
|
glRotatef( $self->y_rot, 0, 0, 1 );
|
||||||
|
glTranslatef(map -$_ * $self->zoom, @{ $self->mesh_center });
|
||||||
|
|
||||||
|
$self->draw_mesh;
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
glFlush();
|
||||||
|
|
||||||
|
$self->SwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
sub draw_mesh {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glEnableClientState(GL_NORMAL_ARRAY);
|
||||||
|
|
||||||
|
glVertexPointer_p(3, $self->verts);
|
||||||
|
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
glNormalPointer_p($self->norms);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, $self->verts->elements / 3);
|
||||||
|
|
||||||
|
glDisableClientState(GL_NORMAL_ARRAY);
|
||||||
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
@ -7,7 +7,7 @@ our @ISA = qw(Exporter);
|
|||||||
our @EXPORT_OK = qw(
|
our @EXPORT_OK = qw(
|
||||||
PI X Y Z A B X1 Y1 X2 Y2 MIN MAX epsilon slope line_atan lines_parallel
|
PI X Y Z A B X1 Y1 X2 Y2 MIN MAX epsilon slope line_atan lines_parallel
|
||||||
line_point_belongs_to_segment points_coincide distance_between_points
|
line_point_belongs_to_segment points_coincide distance_between_points
|
||||||
chained_path_items chained_path_points
|
chained_path_items chained_path_points normalize tan
|
||||||
line_length midpoint point_in_polygon point_in_segment segment_in_segment
|
line_length midpoint point_in_polygon point_in_segment segment_in_segment
|
||||||
point_is_on_left_of_segment polyline_lines polygon_lines nearest_point
|
point_is_on_left_of_segment polyline_lines polygon_lines nearest_point
|
||||||
point_along_segment polygon_segment_having_point polygon_has_subsegment
|
point_along_segment polygon_segment_having_point polygon_has_subsegment
|
||||||
@ -45,6 +45,11 @@ sub scaled_epsilon () { epsilon / &Slic3r::SCALING_FACTOR }
|
|||||||
sub scale ($) { $_[0] / &Slic3r::SCALING_FACTOR }
|
sub scale ($) { $_[0] / &Slic3r::SCALING_FACTOR }
|
||||||
sub unscale ($) { $_[0] * &Slic3r::SCALING_FACTOR }
|
sub unscale ($) { $_[0] * &Slic3r::SCALING_FACTOR }
|
||||||
|
|
||||||
|
sub tan {
|
||||||
|
my ($angle) = @_;
|
||||||
|
return (sin $angle) / (cos $angle);
|
||||||
|
}
|
||||||
|
|
||||||
sub slope {
|
sub slope {
|
||||||
my ($line) = @_;
|
my ($line) = @_;
|
||||||
return undef if abs($line->[B][X] - $line->[A][X]) < epsilon; # line is vertical
|
return undef if abs($line->[B][X] - $line->[A][X]) < epsilon; # line is vertical
|
||||||
@ -461,6 +466,14 @@ sub triangle_normal {
|
|||||||
return normal($u, $v);
|
return normal($u, $v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub normalize {
|
||||||
|
my ($line) = @_;
|
||||||
|
|
||||||
|
my $len = sqrt( ($line->[X]**2) + ($line->[Y]**2) + ($line->[Z]**2) )
|
||||||
|
or return [0, 0, 0]; # to avoid illegal division by zero
|
||||||
|
return [ map $_ / $len, @$line ];
|
||||||
|
}
|
||||||
|
|
||||||
# 2D dot product
|
# 2D dot product
|
||||||
sub dot {
|
sub dot {
|
||||||
my ($u, $v) = @_;
|
my ($u, $v) = @_;
|
||||||
|
@ -365,6 +365,19 @@ sub align_to_origin {
|
|||||||
$self->move(map -$extents[$_][MIN], X,Y,Z);
|
$self->move(map -$extents[$_][MIN], X,Y,Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub center_around_origin {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
$self->move(map -$_, @{ $self->center });
|
||||||
|
}
|
||||||
|
|
||||||
|
sub center {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
my @extents = $self->extents;
|
||||||
|
return [ map +($extents[$_][MAX] + $extents[$_][MIN])/2, X,Y,Z ];
|
||||||
|
}
|
||||||
|
|
||||||
sub duplicate {
|
sub duplicate {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my (@shifts) = @_;
|
my (@shifts) = @_;
|
||||||
|
67
utils/view-mesh.pl
Normal file
67
utils/view-mesh.pl
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
|
# This script displays 3D preview of a mesh
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
use FindBin;
|
||||||
|
use lib "$FindBin::Bin/../lib";
|
||||||
|
}
|
||||||
|
|
||||||
|
use Getopt::Long qw(:config no_auto_abbrev);
|
||||||
|
use Slic3r;
|
||||||
|
use Slic3r::GUI;
|
||||||
|
$|++;
|
||||||
|
|
||||||
|
my %opt = ();
|
||||||
|
{
|
||||||
|
my %options = (
|
||||||
|
'help' => sub { usage() },
|
||||||
|
);
|
||||||
|
GetOptions(%options) or usage(1);
|
||||||
|
$ARGV[0] or usage(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $model = Slic3r::Model->read_from_file($ARGV[0]);
|
||||||
|
|
||||||
|
$Slic3r::ViewMesh::mesh = $model->mesh;
|
||||||
|
my $app = Slic3r::ViewMesh->new;
|
||||||
|
$app->MainLoop;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub usage {
|
||||||
|
my ($exit_code) = @_;
|
||||||
|
|
||||||
|
print <<"EOF";
|
||||||
|
Usage: view-mesh.pl [ OPTIONS ] file.stl
|
||||||
|
|
||||||
|
--help Output this usage screen and exit
|
||||||
|
|
||||||
|
EOF
|
||||||
|
exit ($exit_code || 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
package Slic3r::ViewMesh;
|
||||||
|
use Wx qw(:sizer);
|
||||||
|
use base qw(Wx::App);
|
||||||
|
|
||||||
|
our $mesh;
|
||||||
|
|
||||||
|
sub OnInit {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
my $frame = Wx::Frame->new(undef, -1, 'Mesh Viewer', [-1, -1], [500, 400]);
|
||||||
|
my $panel = Wx::Panel->new($frame, -1);
|
||||||
|
|
||||||
|
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
|
||||||
|
$sizer->Add(Slic3r::GUI::PreviewCanvas->new($panel, $mesh), 1, wxEXPAND, 0);
|
||||||
|
$panel->SetSizer($sizer);
|
||||||
|
$sizer->SetSizeHints($panel);
|
||||||
|
|
||||||
|
$frame->Show(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__END__
|
Loading…
x
Reference in New Issue
Block a user