Files
OrcaSlicer-bambulab/src/libslic3r/Fill/FillHoneycomb.cpp
T

84 lines
3.9 KiB
C++
Raw Normal View History

2016-04-11 17:08:30 +02:00
#include "../ClipperUtils.hpp"
#include "../ShortestPath.hpp"
2016-04-11 17:08:30 +02:00
#include "../Surface.hpp"
#include "FillHoneycomb.hpp"
namespace Slic3r {
2016-09-13 11:26:38 +02:00
void FillHoneycomb::_fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Polylines &polylines_out)
2016-04-11 17:08:30 +02:00
{
// cache hexagons math
CacheID cache_id(params.density, this->spacing);
Cache::iterator it_m = this->cache.find(cache_id);
if (it_m == this->cache.end()) {
it_m = this->cache.insert(it_m, std::pair<CacheID, CacheData>(cache_id, CacheData()));
2020-11-16 12:51:51 +01:00
CacheData &m = it_m->second;
coord_t min_spacing = coord_t(scale_(this->spacing));
m.distance = coord_t(min_spacing / params.density);
m.hex_side = coord_t(m.distance / (sqrt(3)/2));
m.hex_width = m.distance * 2; // $m->{hex_width} == $m->{hex_side} * sqrt(3);
coord_t hex_height = m.hex_side * 2;
m.pattern_height = hex_height + m.hex_side;
m.y_short = coord_t(m.distance * sqrt(3)/3);
m.x_offset = min_spacing / 2;
m.y_offset = coord_t(m.x_offset * sqrt(3)/3);
m.hex_center = Point(m.hex_width/2, m.hex_side);
2016-04-11 17:08:30 +02:00
}
CacheData &m = it_m->second;
2020-11-16 12:51:51 +01:00
Polylines all_polylines;
2016-04-11 17:08:30 +02:00
{
// adjust actual bounding box to the nearest multiple of our hex pattern
// and align it so that it matches across layers
2016-09-13 11:26:38 +02:00
BoundingBox bounding_box = expolygon.contour.bounding_box();
2016-04-11 17:08:30 +02:00
{
// rotate bounding box according to infill direction
Polygon bb_polygon = bounding_box.polygon();
2016-09-13 11:26:38 +02:00
bb_polygon.rotate(direction.first, m.hex_center);
2016-04-11 17:08:30 +02:00
bounding_box = bb_polygon.bounding_box();
// extend bounding box so that our pattern will be aligned with other layers
// $bounding_box->[X1] and [Y1] represent the displacement between new bounding box offset and old one
2016-09-13 11:26:38 +02:00
// The infill is not aligned to the object bounding box, but to a world coordinate system. Supposedly good enough.
bounding_box.merge(_align_to_grid(bounding_box.min, Point(m.hex_width, m.pattern_height)));
2016-04-11 17:08:30 +02:00
}
2016-09-13 11:26:38 +02:00
coord_t x = bounding_box.min(0);
while (x <= bounding_box.max(0)) {
2020-11-16 12:51:51 +01:00
Polyline p;
2016-04-11 17:08:30 +02:00
coord_t ax[2] = { x + m.x_offset, x + m.distance - m.x_offset };
for (size_t i = 0; i < 2; ++ i) {
std::reverse(p.points.begin(), p.points.end()); // turn first half upside down
for (coord_t y = bounding_box.min(1); y <= bounding_box.max(1); y += m.y_short + m.hex_side + m.y_short + m.hex_side) {
2016-04-11 17:08:30 +02:00
p.points.push_back(Point(ax[1], y + m.y_offset));
p.points.push_back(Point(ax[0], y + m.y_short - m.y_offset));
p.points.push_back(Point(ax[0], y + m.y_short + m.hex_side + m.y_offset));
p.points.push_back(Point(ax[1], y + m.y_short + m.hex_side + m.y_short - m.y_offset));
p.points.push_back(Point(ax[1], y + m.y_short + m.hex_side + m.y_short + m.hex_side + m.y_offset));
}
ax[0] = ax[0] + m.distance;
ax[1] = ax[1] + m.distance;
std::swap(ax[0], ax[1]); // draw symmetrical pattern
x += m.distance;
}
2016-09-13 11:26:38 +02:00
p.rotate(-direction.first, m.hex_center);
2020-11-16 12:51:51 +01:00
all_polylines.push_back(p);
2016-04-11 17:08:30 +02:00
}
}
2020-11-16 12:51:51 +01:00
all_polylines = intersection_pl(std::move(all_polylines), to_polygons(expolygon));
if (params.dont_connect || all_polylines.size() <= 1)
append(polylines_out, chain_polylines(std::move(all_polylines)));
else
connect_infill(std::move(all_polylines), expolygon, polylines_out, this->spacing, params);
2016-04-11 17:08:30 +02:00
}
} // namespace Slic3r