Object.pm 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package Slic3r::Print::Object;
  2. # extends c++ class Slic3r::PrintObject (Print.xsp)
  3. use strict;
  4. use warnings;
  5. use POSIX;
  6. use List::Util qw(min max sum first any);
  7. use Slic3r::Flow ':roles';
  8. use Slic3r::Geometry qw(X Y Z PI scale unscale chained_path epsilon);
  9. use Slic3r::Geometry::Clipper qw(diff diff_ex intersection intersection_ex union union_ex
  10. offset offset_ex offset2 offset2_ex intersection_ppl CLIPPER_OFFSET_SCALE JT_MITER);
  11. use Slic3r::Print::State ':steps';
  12. use Slic3r::Surface ':types';
  13. # TODO: lazy
  14. sub fill_maker {
  15. my $self = shift;
  16. return Slic3r::Fill->new(bounding_box => $self->bounding_box);
  17. }
  18. sub region_volumes {
  19. my $self = shift;
  20. return [ map $self->get_region_volumes($_), 0..($self->region_count - 1) ];
  21. }
  22. sub layers {
  23. my $self = shift;
  24. return [ map $self->get_layer($_), 0..($self->layer_count - 1) ];
  25. }
  26. sub support_layers {
  27. my $self = shift;
  28. return [ map $self->get_support_layer($_), 0..($self->support_layer_count - 1) ];
  29. }
  30. sub generate_support_material {
  31. my $self = shift;
  32. # prerequisites
  33. $self->slice;
  34. return if $self->step_done(STEP_SUPPORTMATERIAL);
  35. $self->set_step_started(STEP_SUPPORTMATERIAL);
  36. $self->clear_support_layers;
  37. if ((!$self->config->support_material
  38. && $self->config->raft_layers == 0
  39. && $self->config->support_material_enforce_layers == 0)
  40. || scalar(@{$self->layers}) < 2
  41. ) {
  42. $self->set_step_done(STEP_SUPPORTMATERIAL);
  43. return;
  44. }
  45. $self->print->status_cb->(85, "Generating support material");
  46. $self->_support_material->generate($self);
  47. $self->set_step_done(STEP_SUPPORTMATERIAL);
  48. my $stats = sprintf "Weight: %.1fg, Cost: %.1f" , $self->print->total_weight, $self->print->total_cost;
  49. $self->print->status_cb->(85, $stats);
  50. }
  51. sub _support_material {
  52. my ($self) = @_;
  53. my $first_layer_flow = Slic3r::Flow->new_from_width(
  54. width => ($self->print->config->first_layer_extrusion_width || $self->config->support_material_extrusion_width),
  55. role => FLOW_ROLE_SUPPORT_MATERIAL,
  56. nozzle_diameter => $self->print->config->nozzle_diameter->[ $self->config->support_material_extruder-1 ]
  57. // $self->print->config->nozzle_diameter->[0],
  58. layer_height => $self->config->get_abs_value('first_layer_height'),
  59. bridge_flow_ratio => 0,
  60. );
  61. return Slic3r::Print::SupportMaterial->new(
  62. print_config => $self->print->config,
  63. object_config => $self->config,
  64. first_layer_flow => $first_layer_flow,
  65. flow => $self->support_material_flow(FLOW_ROLE_SUPPORT_MATERIAL),
  66. interface_flow => $self->support_material_flow(FLOW_ROLE_SUPPORT_MATERIAL_INTERFACE),
  67. );
  68. }
  69. 1;