Refactor, fix wall normals and gap detection.

This commit is contained in:
tamasmeszaros 2019-06-11 15:35:09 +02:00
parent ddd0a9abb6
commit b7e3ee0709
2 changed files with 43 additions and 35 deletions

View file

@ -857,6 +857,7 @@ Contour3D create_base_pool(const Polygons &ground_layer,
if(wingheight > 0) { if(wingheight > 0) {
// Generate the smoothed edge geometry // Generate the smoothed edge geometry
wh = 0; wh = 0;
ob = middle_base;
if(s_eradius) pool.merge(round_edges(middle_base, if(s_eradius) pool.merge(round_edges(middle_base,
r, r,
phi - 90, // from tangent lines phi - 90, // from tangent lines
@ -872,55 +873,58 @@ Contour3D create_base_pool(const Polygons &ground_layer,
} }
if (cfg.embed_object) { if (cfg.embed_object) {
ExPolygons pp = diff_ex(to_polygons(bottom_poly), ExPolygons bttms = diff_ex(to_polygons(bottom_poly),
to_polygons(obj_self_pad)); to_polygons(obj_self_pad));
assert(!bttms.empty());
std::sort(bttms.begin(), bttms.end(),
[](const ExPolygon& e1, const ExPolygon& e2) {
return e1.contour.area() > e2.contour.area();
});
if(wingheight > 0) inner_base.holes = bttms.front().holes;
else top_poly.holes = bttms.front().holes;
// Generate outer walls auto straight_walls =
auto fp = [](const Point &p, Point::coord_type z) { [&pool](const Polygon &cntr, coord_t z_low, coord_t z_high) {
return unscale(x(p), y(p), z);
};
auto straight_walls = [&pool, s_thickness, fp](const Polygon &cntr)
{
auto lines = cntr.lines(); auto lines = cntr.lines();
bool cclk = cntr.is_counter_clockwise();
for (auto &l : lines) { for (auto &l : lines) {
auto s = coord_t(pool.points.size()); auto s = coord_t(pool.points.size());
pool.points.emplace_back(fp(l.a, -s_thickness)); auto& pts = pool.points;
pool.points.emplace_back(fp(l.b, -s_thickness)); pts.emplace_back(unscale(l.a.x(), l.a.y(), z_low));
pool.points.emplace_back(fp(l.a, 0)); pts.emplace_back(unscale(l.b.x(), l.b.y(), z_low));
pool.points.emplace_back(fp(l.b, 0)); pts.emplace_back(unscale(l.a.x(), l.a.y(), z_high));
pts.emplace_back(unscale(l.b.x(), l.b.y(), z_high));
if(cclk) { pool.indices.emplace_back(s, s + 1, s + 3);
pool.indices.emplace_back(s + 3, s + 1, s); pool.indices.emplace_back(s, s + 3, s + 2);
pool.indices.emplace_back(s + 2, s + 3, s);
} else {
pool.indices.emplace_back(s, s + 1, s + 3);
pool.indices.emplace_back(s, s + 3, s + 2);
}
} }
}; };
for (ExPolygon &ep : pp) { coord_t z_lo = -mm(fullheight), z_hi = -mm(wingheight);
pool.merge(triangulate_expolygon_3d(ep)); for (ExPolygon &ep : bttms) {
pool.merge(triangulate_expolygon_3d(ep, -fullheight, true)); pool.merge(triangulate_expolygon_3d(ep, -fullheight, true));
for (auto &h : ep.holes) straight_walls(h, z_lo, z_hi);
for (auto &h : ep.holes) straight_walls(h);
} }
// Skip the outer contour. TODO: make sure the first in the list // Skip the outer contour, triangulate the holes
// IS the outer contour. for (auto it = std::next(bttms.begin()); it != bttms.end(); ++it) {
for (auto it = std::next(pp.begin()); it != pp.end(); ++it) pool.merge(triangulate_expolygon_3d(*it, -wingheight));
straight_walls(it->contour); straight_walls(it->contour, z_lo, z_hi);
}
} else { } else {
// Now we need to triangulate the top and bottom plates as well as // Now we need to triangulate the top and bottom plates as well as
// the cavity bottom plate which is the same as the bottom plate // the cavity bottom plate which is the same as the bottom plate
// but it is elevated by the thickness. // but it is elevated by the thickness.
pool.merge(triangulate_expolygon_3d(top_poly));
pool.merge(triangulate_expolygon_3d(bottom_poly, -fullheight, true)); pool.merge(triangulate_expolygon_3d(bottom_poly, -fullheight, true));
} }
pool.merge(triangulate_expolygon_3d(top_poly));
if(wingheight > 0) if(wingheight > 0)
pool.merge(triangulate_expolygon_3d(inner_base, -wingheight)); pool.merge(triangulate_expolygon_3d(inner_base, -wingheight));

View file

@ -2164,7 +2164,10 @@ public:
m_cfg.base_radius_mm + EPSILON; m_cfg.base_radius_mm + EPSILON;
while(!found && alpha < 2*PI) { while(!found && alpha < 2*PI) {
for (unsigned n = 0; n < needpillars; n++) { for (unsigned n = 0;
n < needpillars && (!n || canplace[n - 1]);
n++)
{
double a = alpha + n * PI / 3; double a = alpha + n * PI / 3;
Vec3d s = sp; Vec3d s = sp;
s(X) += std::cos(a) * r; s(X) += std::cos(a) * r;
@ -2173,11 +2176,12 @@ public:
// Check the path vertically down // Check the path vertically down
auto hr = bridge_mesh_intersect(s, {0, 0, -1}, pillar().r); auto hr = bridge_mesh_intersect(s, {0, 0, -1}, pillar().r);
Vec3d gndsp{s(X), s(Y), gnd};
// If the path is clear, check for pillar base collisions // If the path is clear, check for pillar base collisions
canplace[n] = std::isinf(hr.distance()) canplace[n] = std::isinf(hr.distance()) &&
&& m_mesh.squared_distance({s(X), s(Y), gnd}) std::sqrt(m_mesh.squared_distance(gndsp)) >
> min_dist; min_dist;
} }
found = std::all_of(canplace.begin(), canplace.end(), found = std::all_of(canplace.begin(), canplace.end(),