Object.pm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package Slic3r::Print::Object;
  2. # extends c++ class Slic3r::PrintObject (Print.xsp)
  3. use strict;
  4. use warnings;
  5. use List::Util qw(min max sum first);
  6. use Slic3r::Flow ':roles';
  7. use Slic3r::Geometry qw(scale epsilon);
  8. use Slic3r::Geometry::Clipper qw(diff diff_ex intersection intersection_ex union union_ex
  9. offset offset2 offset_ex offset2_ex JT_MITER);
  10. use Slic3r::Print::State ':steps';
  11. use Slic3r::Surface ':types';
  12. sub layers {
  13. my $self = shift;
  14. return [ map $self->get_layer($_), 0..($self->layer_count - 1) ];
  15. }
  16. sub support_layers {
  17. my $self = shift;
  18. return [ map $self->get_support_layer($_), 0..($self->support_layer_count - 1) ];
  19. }
  20. # 1) Decides Z positions of the layers,
  21. # 2) Initializes layers and their regions
  22. # 3) Slices the object meshes
  23. # 4) Slices the modifier meshes and reclassifies the slices of the object meshes by the slices of the modifier meshes
  24. # 5) Applies size compensation (offsets the slices in XY plane)
  25. # 6) Replaces bad slices by the slices reconstructed from the upper/lower layer
  26. # Resulting expolygons of layer regions are marked as Internal.
  27. #
  28. # this should be idempotent
  29. sub slice {
  30. my $self = shift;
  31. return if $self->step_done(STEP_SLICE);
  32. $self->set_step_started(STEP_SLICE);
  33. $self->print->status_cb->(10, "Processing triangulated mesh");
  34. $self->_slice;
  35. my $warning = $self->_fix_slicing_errors;
  36. warn $warning if (defined($warning) && $warning ne '');
  37. # simplify slices if required
  38. $self->_simplify_slices(scale($self->print->config->resolution))
  39. if ($self->print->config->resolution);
  40. die "No layers were detected. You might want to repair your STL file(s) or check their size or thickness and retry.\n"
  41. if !@{$self->layers};
  42. $self->set_step_done(STEP_SLICE);
  43. }
  44. # 1) Merges typed region slices into stInternal type.
  45. # 2) Increases an "extra perimeters" counter at region slices where needed.
  46. # 3) Generates perimeters, gap fills and fill regions (fill regions of type stInternal).
  47. sub make_perimeters {
  48. my ($self) = @_;
  49. # prerequisites
  50. $self->slice;
  51. if (! $self->step_done(STEP_PERIMETERS)) {
  52. $self->print->status_cb->(20, "Generating perimeters");
  53. $self->_make_perimeters;
  54. }
  55. }
  56. sub prepare_infill {
  57. my ($self) = @_;
  58. # prerequisites
  59. $self->make_perimeters;
  60. return if $self->step_done(STEP_PREPARE_INFILL);
  61. $self->set_step_started(STEP_PREPARE_INFILL);
  62. $self->print->status_cb->(30, "Preparing infill");
  63. $self->_prepare_infill;
  64. $self->set_step_done(STEP_PREPARE_INFILL);
  65. }
  66. sub infill {
  67. my ($self) = @_;
  68. # prerequisites
  69. $self->prepare_infill;
  70. $self->_infill;
  71. }
  72. sub generate_support_material {
  73. my $self = shift;
  74. # prerequisites
  75. $self->slice;
  76. return if $self->step_done(STEP_SUPPORTMATERIAL);
  77. $self->set_step_started(STEP_SUPPORTMATERIAL);
  78. $self->clear_support_layers;
  79. if (($self->config->support_material || $self->config->raft_layers > 0) && scalar(@{$self->layers}) > 1) {
  80. $self->print->status_cb->(85, "Generating support material");
  81. # New supports, C++ implementation.
  82. $self->_generate_support_material;
  83. }
  84. $self->set_step_done(STEP_SUPPORTMATERIAL);
  85. my $stats = sprintf "Weight: %.1fg, Cost: %.1f" , $self->print->total_weight, $self->print->total_cost;
  86. $self->print->status_cb->(85, $stats);
  87. }
  88. 1;