Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnrico Turri <enricoturri@seznam.cz>2019-08-20 15:35:23 +0300
committerEnrico Turri <enricoturri@seznam.cz>2019-08-20 15:35:23 +0300
commit1b6490af4cded5d0fc4a1f25bac430d5aa4a9416 (patch)
treef1e9ef10b30c7da5d5b85dba92f2f824410f4534 /src/slic3r/GUI/3DScene.cpp
parent2e3c71baaf959d88158afe864f570a5542298ba2 (diff)
Export materials file for gcode toolpaths when exported to obj file
Diffstat (limited to 'src/slic3r/GUI/3DScene.cpp')
-rw-r--r--src/slic3r/GUI/3DScene.cpp47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp
index 88a7edee6..d29e41d35 100644
--- a/src/slic3r/GUI/3DScene.cpp
+++ b/src/slic3r/GUI/3DScene.cpp
@@ -886,14 +886,51 @@ void GLVolumeCollection::export_toolpaths_to_obj(const char* filename) const
if (!has_toolpaths_to_export())
return;
- FILE* fp = boost::nowide::fopen(filename, "w");
+ // collect color information to generate materials
+ std::set<std::array<float, 4>> colors;
+ for (const GLVolume* volume : this->volumes)
+ {
+ if (!can_export_to_obj(*volume))
+ continue;
+
+ std::array<float, 4> color;
+ ::memcpy((void*)color.data(), (const void*)volume->color, 4 * sizeof(float));
+ colors.insert(color);
+ }
+
+ // save materials file
+ boost::filesystem::path mat_filename(filename);
+ mat_filename.replace_extension("mtl");
+ FILE* fp = boost::nowide::fopen(mat_filename.string().c_str(), "w");
+ if (fp == nullptr) {
+ BOOST_LOG_TRIVIAL(error) << "GLVolumeCollection::export_toolpaths_to_obj: Couldn't open " << mat_filename.string().c_str() << " for writing";
+ return;
+ }
+
+ fprintf(fp, "# G-Code Toolpaths Materials\n");
+ fprintf(fp, "# Generated by %s based on Slic3r\n", SLIC3R_BUILD_ID);
+
+ unsigned int colors_count = 1;
+ for (const std::array<float, 4>& color : colors)
+ {
+ fprintf(fp, "\nnewmtl material_%d\n", colors_count++);
+ fprintf(fp, "Ka 1 1 1\n");
+ fprintf(fp, "Kd %f %f %f\n", color[0], color[1], color[2]);
+ fprintf(fp, "Ks 0 0 0\n");
+ }
+
+ fclose(fp);
+
+ // save geometry file
+ fp = boost::nowide::fopen(filename, "w");
if (fp == nullptr) {
BOOST_LOG_TRIVIAL(error) << "GLVolumeCollection::export_toolpaths_to_obj: Couldn't open " << filename << " for writing";
return;
}
fprintf(fp, "# G-Code Toolpaths\n");
- fprintf(fp, "# Generated by %s based on Slic3r\n\n", SLIC3R_BUILD_ID);
+ fprintf(fp, "# Generated by %s based on Slic3r\n", SLIC3R_BUILD_ID);
+ fprintf(fp, "\nmtllib ./%s\n", mat_filename.filename().string().c_str());
unsigned int vertices_count = 0;
unsigned int volumes_count = 0;
@@ -987,6 +1024,12 @@ void GLVolumeCollection::export_toolpaths_to_obj(const char* filename) const
fprintf(fp, "vn %f %f %f\n", vertices_and_normals_interleaved[i + 0], vertices_and_normals_interleaved[i + 1], vertices_and_normals_interleaved[i + 2]);
}
+ std::array<float, 4> color;
+ ::memcpy((void*)color.data(), (const void*)volume->color, 4 * sizeof(float));
+ colors.insert(color);
+ fprintf(fp, "\n# material volume %d\n", volumes_count);
+ fprintf(fp, "usemtl material_%lld\n", 1 + std::distance(colors.begin(), colors.find(color)));
+
fprintf(fp, "\n# triangular facets volume %d\n", volumes_count);
for (unsigned int i = 0; i < triangle_indices.size(); i += 3)
{