Skip to content

Commit

Permalink
implemented the --export-stl-with-support cli option to export meshes…
Browse files Browse the repository at this point in the history
… with SLA support.
  • Loading branch information
rhradec committed Mar 21, 2024
1 parent c8c9096 commit 180df64
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
75 changes: 42 additions & 33 deletions src/PrusaSlicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,19 @@ int CLI::run(int argc, char **argv)
} else if (opt_key == "export_3mf") {
if (! this->export_models(IO::TMF))
return 1;
} else if (opt_key == "export_gcode" || opt_key == "export_sla" || opt_key == "slice") {
} else if (opt_key == "export_gcode" || opt_key == "export_sla" || opt_key == "slice" || opt_key == "export_stl_with_support" ) {
if (opt_key == "export_gcode" && printer_technology == ptSLA) {
boost::nowide::cerr << "error: cannot export G-code for an FFF configuration" << std::endl;
return 1;
} else if (opt_key == "export_sla" && printer_technology == ptFFF) {
boost::nowide::cerr << "error: cannot export SLA slices for a SLA configuration" << std::endl;
return 1;
}
// if we are exporting stl with support, force the printer technology to SLA
if ( opt_key == "export_stl_with_support" ) {
printer_technology = ptSLA;
}

// Make a copy of the model if the current action is not the last action, as the model may be
// modified by the centering and such.
Model model_copy;
Expand Down Expand Up @@ -632,45 +637,49 @@ int CLI::run(int argc, char **argv)
try {
std::string outfile_final;
print->process();
if (printer_technology == ptFFF) {
// The outfile is processed by a PlaceholderParser.
outfile = fff_print.export_gcode(outfile, nullptr, nullptr);
outfile_final = fff_print.print_statistics().finalize_output_path(outfile);
if ( opt_key == "export_stl_with_support" ) {
// generate the support mesh
SLAPrint *slaprint = static_cast<SLAPrint*>(print);
TriangleMesh *mesh = ( TriangleMesh * )&(slaprint->objects()[0]->support_mesh());
// generate the pad mesh and merge with the support
mesh->merge(slaprint->objects()[0]->pad_mesh());

// grab the object modified mesh and merge with the support+pad
std::shared_ptr<const indexed_triangle_set> m = slaprint->objects()[0]->get_mesh_to_print();
TriangleMesh inst_object_mesh;
if (m)
inst_object_mesh = TriangleMesh{*m};
mesh->merge(inst_object_mesh);

// now export with support
Slic3r::store_stl(outfile.c_str(), mesh, true);
std::cout << "File exported to " << outfile << " with supports" << std::endl;
} else {
outfile = sla_print.output_filepath(outfile);
// We need to finalize the filename beforehand because the export function sets the filename inside the zip metadata
outfile_final = sla_print.print_statistics().finalize_output_path(outfile);
sla_print.export_print(outfile_final);
}
if (outfile != outfile_final) {
if (Slic3r::rename_file(outfile, outfile_final)) {
boost::nowide::cerr << "Renaming file " << outfile << " to " << outfile_final << " failed" << std::endl;
return 1;
if (printer_technology == ptFFF) {
// The outfile is processed by a PlaceholderParser.
outfile = fff_print.export_gcode(outfile, nullptr, nullptr);
outfile_final = fff_print.print_statistics().finalize_output_path(outfile);
} else {
outfile = sla_print.output_filepath(outfile);
// We need to finalize the filename beforehand because the export function sets the filename inside the zip metadata
outfile_final = sla_print.print_statistics().finalize_output_path(outfile);
sla_print.export_print(outfile_final);
}
outfile = outfile_final;
if (outfile != outfile_final) {
if (Slic3r::rename_file(outfile, outfile_final)) {
boost::nowide::cerr << "Renaming file " << outfile << " to " << outfile_final << " failed" << std::endl;
return 1;
}
outfile = outfile_final;
}
// Run the post-processing scripts if defined.
run_post_process_scripts(outfile, fff_print.full_print_config());
boost::nowide::cout << "Slicing result exported to " << outfile << std::endl;
}
// Run the post-processing scripts if defined.
run_post_process_scripts(outfile, fff_print.full_print_config());
boost::nowide::cout << "Slicing result exported to " << outfile << std::endl;
} catch (const std::exception &ex) {
boost::nowide::cerr << ex.what() << std::endl;
return 1;
}

// =======================================================================================================================================
// export the mesh + support to a file
// =======================================================================================================================================
SLAPrint *slaprint = static_cast<SLAPrint*>(print);
TriangleMesh *mesh = ( TriangleMesh * )&(slaprint->objects()[0]->support_mesh());
mesh->merge(slaprint->objects()[0]->pad_mesh());

std::shared_ptr<const indexed_triangle_set> m = slaprint->objects()[0]->get_mesh_to_print();
TriangleMesh inst_object_mesh;
if (m)
inst_object_mesh = TriangleMesh{*m};
mesh->merge(inst_object_mesh);
Slic3r::store_obj("/tmp/xxx.obj", mesh);
// =======================================================================================================================================
}

/*
Expand Down
5 changes: 5 additions & 0 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4900,6 +4900,11 @@ CLIActionsConfigDef::CLIActionsConfigDef()
def->tooltip = L("Export the model(s) as STL.");
def->set_default_value(new ConfigOptionBool(false));

def = this->add("export_stl_with_support", coBool);
def->label = L("Export STL with supports");
def->tooltip = L("Export the model(s) as STL, including print supports.");
def->set_default_value(new ConfigOptionBool(false));

def = this->add("export_gcode", coBool);
def->label = L("Export G-code");
def->tooltip = L("Slice the model and export toolpaths as G-code.");
Expand Down

0 comments on commit 180df64

Please sign in to comment.