Skip to content

Commit

Permalink
Fix of Repair with Netfabb does not work on builds after 2.3.0 releas…
Browse files Browse the repository at this point in the history
…e (Windows 10) #6193

This is more a workaround than a fix: Windows 10 3D model fixing API refuses
to load a zip64 encoded 3MF. We need to get in touch with Microsoft on that
issue, for now the 3MFs generated for the Windows 10 3D model fixing API
will be limited to 4GB. Saving a bigger 3MF will fail.
  • Loading branch information
bubnikv committed Mar 8, 2021
1 parent 1efa9a0 commit 589d2be
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/libslic3r/Format/3mf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2014,9 +2014,10 @@ namespace Slic3r {
typedef std::map<int, ObjectData> IdToObjectDataMap;

bool m_fullpath_sources{ true };
bool m_zip64 { true };

public:
bool save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data = nullptr);
bool save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data, bool zip64);

private:
bool _save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, const ThumbnailData* thumbnail_data);
Expand All @@ -2036,10 +2037,11 @@ namespace Slic3r {
bool _add_custom_gcode_per_print_z_file_to_archive(mz_zip_archive& archive, Model& model, const DynamicPrintConfig* config);
};

bool _3MF_Exporter::save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data)
bool _3MF_Exporter::save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data, bool zip64)
{
clear_errors();
m_fullpath_sources = fullpath_sources;
m_zip64 = zip64;
return _save_model_to_file(filename, model, config, thumbnail_data);
}

Expand Down Expand Up @@ -2233,9 +2235,13 @@ namespace Slic3r {
{
mz_zip_writer_staged_context context;
if (!mz_zip_writer_add_staged_open(&archive, &context, MODEL_FILE.c_str(),
// Maximum expected and allowed 3MF file size is 16GiB.
// This switches the ZIP file to a 64bit mode, which adds a tiny bit of overhead to file records.
(uint64_t(1) << 30) * 16,
m_zip64 ?
// Maximum expected and allowed 3MF file size is 16GiB.
// This switches the ZIP file to a 64bit mode, which adds a tiny bit of overhead to file records.
(uint64_t(1) << 30) * 16 :
// Maximum expected 3MF file size is 4GB-1. This is a workaround for interoperability with Windows 10 3D model fixing API, see
// GH issue #6193.
(uint64_t(1) << 32) - 1,
nullptr, nullptr, 0, MZ_DEFAULT_COMPRESSION, nullptr, 0, nullptr, 0)) {
add_error("Unable to add model file to archive");
return false;
Expand Down Expand Up @@ -2926,12 +2932,13 @@ bool load_3mf(const char* path, DynamicPrintConfig* config, Model* model, bool c
return res;
}

bool store_3mf(const char* path, Model* model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data)
bool store_3mf(const char* path, Model* model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data, bool zip64)
{
if (path == nullptr || model == nullptr)
return false;

_3MF_Exporter exporter;
exporter.zip64 = zip64;
bool res = exporter.save_model_to_file(path, *model, config, fullpath_sources, thumbnail_data);
if (!res)
exporter.log_errors();
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Format/3mf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Slic3r {

// Save the given model and the config data contained in the given Print into a 3mf file.
// The model could be modified during the export process if meshes are not repaired or have no shared vertices
extern bool store_3mf(const char* path, Model* model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data = nullptr);
extern bool store_3mf(const char* path, Model* model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data = nullptr, bool zip64 = true);

} // namespace Slic3r

Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/Utils/FixModelByWin10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void fix_model_by_win10_sdk_gui(ModelObject &model_object, int volume_idx)
ModelObject *model_object = model.add_object();
model_object->add_volume(*volumes[ivolume]);
model_object->add_instance();
if (!Slic3r::store_3mf(path_src.string().c_str(), &model, nullptr, false)) {
if (!Slic3r::store_3mf(path_src.string().c_str(), &model, nullptr, false, nullptr, false)) {
boost::filesystem::remove(path_src);
throw Slic3r::RuntimeError(L("Export of a temporary 3mf file failed"));
}
Expand Down

0 comments on commit 589d2be

Please sign in to comment.