mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 02:15:55 +08:00
Fix sizes of SVG output
This commit is contained in:
parent
76f8e35502
commit
437e9be329
@ -81,11 +81,7 @@ main(const int argc, const char **argv)
|
|||||||
std::string outfile = cli_config.output.value;
|
std::string outfile = cli_config.output.value;
|
||||||
if (outfile.empty()) outfile = model->objects.front()->input_file + ".svg";
|
if (outfile.empty()) outfile = model->objects.front()->input_file + ".svg";
|
||||||
|
|
||||||
TriangleMesh mesh = model->mesh();
|
SVGExport svg_export(model->mesh());
|
||||||
mesh.mirror_x();
|
|
||||||
mesh.align_to_origin();
|
|
||||||
|
|
||||||
SVGExport svg_export(mesh);
|
|
||||||
svg_export.config.apply(print_config, true);
|
svg_export.config.apply(print_config, true);
|
||||||
svg_export.writeSVG(outfile);
|
svg_export.writeSVG(outfile);
|
||||||
printf("SVG file exported to %s\n", outfile.c_str());
|
printf("SVG file exported to %s\n", outfile.c_str());
|
||||||
|
@ -2,13 +2,23 @@
|
|||||||
#include "ClipperUtils.hpp"
|
#include "ClipperUtils.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#define COORD(x) ((float)unscale(x)*10)
|
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
void
|
void
|
||||||
SVGExport::writeSVG(const std::string &outputfile)
|
SVGExport::writeSVG(const std::string &outputfile)
|
||||||
{
|
{
|
||||||
|
// align to origin taking raft into account
|
||||||
|
BoundingBoxf3 bb = this->mesh.bounding_box();
|
||||||
|
if (this->config.raft_layers > 0) {
|
||||||
|
bb.min.x -= this->config.raft_offset.value;
|
||||||
|
bb.min.y -= this->config.raft_offset.value;
|
||||||
|
bb.max.x += this->config.raft_offset.value;
|
||||||
|
bb.max.y += this->config.raft_offset.value;
|
||||||
|
}
|
||||||
|
this->mesh.translate(-bb.min.x, -bb.min.y, -bb.min.z); // align to origin
|
||||||
|
const Sizef3 size = bb.size();
|
||||||
|
|
||||||
// if we are generating a raft, first_layer_height will not affect mesh slicing
|
// if we are generating a raft, first_layer_height will not affect mesh slicing
|
||||||
const float lh = this->config.layer_height.value;
|
const float lh = this->config.layer_height.value;
|
||||||
const float first_lh = this->config.first_layer_height.value;
|
const float first_lh = this->config.first_layer_height.value;
|
||||||
@ -21,14 +31,14 @@ SVGExport::writeSVG(const std::string &outputfile)
|
|||||||
slice_z.push_back(first_slice_lh/2);
|
slice_z.push_back(first_slice_lh/2);
|
||||||
layer_z.push_back(first_slice_lh);
|
layer_z.push_back(first_slice_lh);
|
||||||
}
|
}
|
||||||
while (layer_z.back() + lh/2 <= this->mesh->stl.stats.max.z) {
|
while (layer_z.back() + lh/2 <= this->mesh.stl.stats.max.z) {
|
||||||
slice_z.push_back(layer_z.back() + lh/2);
|
slice_z.push_back(layer_z.back() + lh/2);
|
||||||
layer_z.push_back(layer_z.back() + lh);
|
layer_z.push_back(layer_z.back() + lh);
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform the slicing
|
// perform the slicing
|
||||||
std::vector<ExPolygons> layers;
|
std::vector<ExPolygons> layers;
|
||||||
TriangleMeshSlicer(this->mesh).slice(slice_z, &layers);
|
TriangleMeshSlicer(&this->mesh).slice(slice_z, &layers);
|
||||||
|
|
||||||
// generate a solid raft if requested
|
// generate a solid raft if requested
|
||||||
if (this->config.raft_layers > 0) {
|
if (this->config.raft_layers > 0) {
|
||||||
@ -49,9 +59,7 @@ SVGExport::writeSVG(const std::string &outputfile)
|
|||||||
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
|
||||||
"<svg width=\"%f\" height=\"%f\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:slic3r=\"http://slic3r.org/namespaces/slic3r\">\n"
|
"<svg width=\"%f\" height=\"%f\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:slic3r=\"http://slic3r.org/namespaces/slic3r\">\n"
|
||||||
"<!-- Generated using Slic3r %s http://slic3r.org/ -->\n"
|
"<!-- Generated using Slic3r %s http://slic3r.org/ -->\n"
|
||||||
, this->mesh->stl.stats.max.x*10, this->mesh->stl.stats.max.y*10, SLIC3R_VERSION);
|
, size.x, size.y, SLIC3R_VERSION);
|
||||||
|
|
||||||
//<g id="layer0" slic3r:z="0.1"> <path...> <path...> </g>
|
|
||||||
|
|
||||||
for (size_t i = 0; i < layer_z.size(); ++i) {
|
for (size_t i = 0; i < layer_z.size(); ++i) {
|
||||||
fprintf(f, "\t<g id=\"layer%zu\" slic3r:z=\"%0.4f\">\n", i, layer_z[i]);
|
fprintf(f, "\t<g id=\"layer%zu\" slic3r:z=\"%0.4f\">\n", i, layer_z[i]);
|
||||||
@ -62,8 +70,8 @@ SVGExport::writeSVG(const std::string &outputfile)
|
|||||||
std::ostringstream d;
|
std::ostringstream d;
|
||||||
d << "M ";
|
d << "M ";
|
||||||
for (Points::const_iterator p = mp->points.begin(); p != mp->points.end(); ++p) {
|
for (Points::const_iterator p = mp->points.begin(); p != mp->points.end(); ++p) {
|
||||||
d << COORD(p->x) << " ";
|
d << unscale(p->x) << " ";
|
||||||
d << COORD(p->y) << " ";
|
d << unscale(p->y) << " ";
|
||||||
}
|
}
|
||||||
d << "z";
|
d << "z";
|
||||||
pd += d.str() + " ";
|
pd += d.str() + " ";
|
||||||
|
@ -14,11 +14,13 @@ class SVGExport
|
|||||||
public:
|
public:
|
||||||
SVGExportConfig config;
|
SVGExportConfig config;
|
||||||
|
|
||||||
SVGExport(TriangleMesh &mesh) : mesh(&mesh) {};
|
SVGExport(const TriangleMesh &mesh) : mesh(mesh) {
|
||||||
|
this->mesh.mirror_x();
|
||||||
|
};
|
||||||
void writeSVG(const std::string &outputfile);
|
void writeSVG(const std::string &outputfile);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TriangleMesh* mesh;
|
TriangleMesh mesh;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user