mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 22:45:58 +08:00
Merge branch 'lm_webslicer'
This commit is contained in:
commit
d56760abb5
4
deps/+LibBGCode/LibBGCode.cmake
vendored
4
deps/+LibBGCode/LibBGCode.cmake
vendored
@ -1,8 +1,8 @@
|
|||||||
set(LibBGCode_SOURCE_DIR "" CACHE PATH "Optionally specify local LibBGCode source directory")
|
set(LibBGCode_SOURCE_DIR "" CACHE PATH "Optionally specify local LibBGCode source directory")
|
||||||
|
|
||||||
set(_source_dir_line
|
set(_source_dir_line
|
||||||
URL https://github.com/prusa3d/libbgcode/archive/d33a277a3ce2c0a7f9ba325caac6d730e0f7a412.zip
|
URL https://github.com/prusa3d/libbgcode/archive/5041c093b33e2748e76d6b326f2251310823f3df.zip
|
||||||
URL_HASH SHA256=0db3b0852df8d3ae32a4283884bc4ad6f1dd4d3c748ed679491f70b1e1d1acd5)
|
URL_HASH SHA256=c323aa196a82d75f08a5b114c95f2d1a019e84b555a196e55d8ea52e5787284c)
|
||||||
|
|
||||||
if (LibBGCode_SOURCE_DIR)
|
if (LibBGCode_SOURCE_DIR)
|
||||||
set(_source_dir_line "SOURCE_DIR;${LibBGCode_SOURCE_DIR};BUILD_ALWAYS;ON")
|
set(_source_dir_line "SOURCE_DIR;${LibBGCode_SOURCE_DIR};BUILD_ALWAYS;ON")
|
||||||
|
@ -171,6 +171,34 @@ static bool export_models(std::vector<Model>& models, IO::ExportFormat format, c
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ThumbnailData resize_and_crop(const std::vector<unsigned char>& data, int width, int height, int width_new, int height_new) {
|
||||||
|
ThumbnailData th;
|
||||||
|
|
||||||
|
float scale_x = float(width_new) / width;
|
||||||
|
float scale_y = float(height_new) / height;
|
||||||
|
float scale = std::max(scale_x, scale_y); // Choose the larger scale to fill the box
|
||||||
|
int resized_width = int(width * scale);
|
||||||
|
int resized_height = int(height * scale);
|
||||||
|
|
||||||
|
std::vector<unsigned char> resized_rgba(resized_width * resized_height * 4);
|
||||||
|
stbir_resize_uint8_linear(data.data(), width, height, 4 * width,
|
||||||
|
resized_rgba.data(), resized_width, resized_height, 4 * resized_width,
|
||||||
|
STBIR_RGBA);
|
||||||
|
|
||||||
|
th.set(width_new, height_new);
|
||||||
|
int crop_x = (resized_width - width_new) / 2;
|
||||||
|
int crop_y = (resized_height - height_new) / 2;
|
||||||
|
|
||||||
|
for (int y = 0; y < height_new; ++y) {
|
||||||
|
std::memcpy(th.pixels.data() + y * width_new * 4,
|
||||||
|
resized_rgba.data() + ((y + crop_y) * resized_width + crop_x) * 4,
|
||||||
|
width_new * 4);
|
||||||
|
}
|
||||||
|
return th;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static std::function<ThumbnailsList(const ThumbnailsParams&)> get_thumbnail_generator_cli(const std::string& filename)
|
static std::function<ThumbnailsList(const ThumbnailsParams&)> get_thumbnail_generator_cli(const std::string& filename)
|
||||||
{
|
{
|
||||||
if (boost::iends_with(filename, ".3mf")) {
|
if (boost::iends_with(filename, ".3mf")) {
|
||||||
@ -214,15 +242,8 @@ static std::function<ThumbnailsList(const ThumbnailsParams&)> get_thumbnail_gene
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const Vec2d& size : params.sizes) {
|
for (const Vec2d& size : params.sizes) {
|
||||||
ThumbnailData th;
|
|
||||||
Point isize(size);
|
Point isize(size);
|
||||||
th.set(isize.x(), isize.y());
|
list_out.push_back(resize_and_crop(data, width, height, isize.x(), isize.y()));
|
||||||
std::vector<unsigned char> resized_rgba(th.width * th.height * 4);
|
|
||||||
stbir_resize_uint8_linear(data.data(), width, height, 4 * width,
|
|
||||||
resized_rgba.data(), th.width, th.height, 4 * th.width,
|
|
||||||
STBIR_RGBA);
|
|
||||||
th.pixels = resized_rgba;
|
|
||||||
list_out.push_back(th);
|
|
||||||
}
|
}
|
||||||
return list_out;
|
return list_out;
|
||||||
};
|
};
|
||||||
|
@ -930,6 +930,18 @@ static inline std::optional<std::string> find_M84(const std::string &gcode) {
|
|||||||
void GCodeGenerator::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGeneratorCallback thumbnail_cb)
|
void GCodeGenerator::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGeneratorCallback thumbnail_cb)
|
||||||
{
|
{
|
||||||
const bool export_to_binary_gcode = print.full_print_config().option<ConfigOptionBool>("binary_gcode")->value;
|
const bool export_to_binary_gcode = print.full_print_config().option<ConfigOptionBool>("binary_gcode")->value;
|
||||||
|
|
||||||
|
std::string prepared_by_info;
|
||||||
|
if (const char* extras = boost::nowide::getenv("SLIC3R_PREPARED_BY_INFO"); extras) {
|
||||||
|
std::string str(extras);
|
||||||
|
if (str.size() < 50 && std::all_of(str.begin(), str.end(), [](char c) { return c < 127 && c != '\n' && c != '\r'; }))
|
||||||
|
prepared_by_info = extras;
|
||||||
|
else {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "Value in SLIC3R_PREPARED_BY_INFO env variable is invalid. Closing.";
|
||||||
|
std::terminate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if exporting gcode in binary format:
|
// if exporting gcode in binary format:
|
||||||
// we generate here the data to be passed to the post-processor, who is responsible to export them to file
|
// we generate here the data to be passed to the post-processor, who is responsible to export them to file
|
||||||
// 1) generate the thumbnails
|
// 1) generate the thumbnails
|
||||||
@ -955,6 +967,8 @@ void GCodeGenerator::_do_export(Print& print, GCodeOutputStream &file, Thumbnail
|
|||||||
// file data
|
// file data
|
||||||
binary_data.file_metadata.raw_data.emplace_back("Producer", std::string(SLIC3R_APP_NAME) + " " + std::string(SLIC3R_VERSION));
|
binary_data.file_metadata.raw_data.emplace_back("Producer", std::string(SLIC3R_APP_NAME) + " " + std::string(SLIC3R_VERSION));
|
||||||
binary_data.file_metadata.raw_data.emplace_back("Produced on", Utils::utc_timestamp());
|
binary_data.file_metadata.raw_data.emplace_back("Produced on", Utils::utc_timestamp());
|
||||||
|
if (! prepared_by_info.empty())
|
||||||
|
binary_data.file_metadata.raw_data.emplace_back("Prepared by", prepared_by_info);
|
||||||
|
|
||||||
// config data
|
// config data
|
||||||
encode_full_config(*m_print, binary_data.slicer_metadata.raw_data);
|
encode_full_config(*m_print, binary_data.slicer_metadata.raw_data);
|
||||||
@ -1024,9 +1038,13 @@ void GCodeGenerator::_do_export(Print& print, GCodeOutputStream &file, Thumbnail
|
|||||||
this->m_avoid_crossing_curled_overhangs.init_bed_shape(get_bed_shape(print.config()));
|
this->m_avoid_crossing_curled_overhangs.init_bed_shape(get_bed_shape(print.config()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!export_to_binary_gcode)
|
if (!export_to_binary_gcode) {
|
||||||
// Write information on the generator.
|
// Write information on the generator.
|
||||||
file.write_format("; %s\n\n", Slic3r::header_slic3r_generated().c_str());
|
file.write_format("; %s\n", Slic3r::header_slic3r_generated().c_str());
|
||||||
|
if (! prepared_by_info.empty())
|
||||||
|
file.write_format("; prepared by %s\n", prepared_by_info.c_str());
|
||||||
|
file.write_format("\n");
|
||||||
|
}
|
||||||
|
|
||||||
if (! export_to_binary_gcode) {
|
if (! export_to_binary_gcode) {
|
||||||
// if exporting gcode in ascii format, generate the thumbnails here
|
// if exporting gcode in ascii format, generate the thumbnails here
|
||||||
|
Loading…
x
Reference in New Issue
Block a user