mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-30 01:54:40 +08:00
Fixed a bug in the hole-aware raycaster
This commit is contained in:
parent
49678fe418
commit
d8f2c8cdab
@ -223,7 +223,10 @@ bool DrainHole::get_intersections(const Vec3f& s, const Vec3f& dir,
|
|||||||
// they are on the cylinder and not past it:
|
// they are on the cylinder and not past it:
|
||||||
for (int i=-1; i<=1 && found !=2; i+=2) {
|
for (int i=-1; i<=1 && found !=2; i+=2) {
|
||||||
Vec3f isect = closest + i*dist * projected_ray.direction();
|
Vec3f isect = closest + i*dist * projected_ray.direction();
|
||||||
float par = (isect-proj_origin).norm() / par_scale;
|
Vec3f to_isect = isect-proj_origin;
|
||||||
|
float par = to_isect.norm() / par_scale;
|
||||||
|
if (to_isect.normalized().dot(proj_dir.normalized()) < 0.f)
|
||||||
|
par *= -1.f;
|
||||||
Vec3d hit_normal = (pos-isect).normalized().cast<double>();
|
Vec3d hit_normal = (pos-isect).normalized().cast<double>();
|
||||||
isect = ray.pointAt(par);
|
isect = ray.pointAt(par);
|
||||||
// check that the intersection is between the base planes:
|
// check that the intersection is between the base planes:
|
||||||
|
@ -8,6 +8,38 @@
|
|||||||
|
|
||||||
using namespace Slic3r;
|
using namespace Slic3r;
|
||||||
|
|
||||||
|
// First do a simple test of the hole raycaster.
|
||||||
|
TEST_CASE("Raycaster - find intersections of a line and cylinder")
|
||||||
|
{
|
||||||
|
sla::DrainHole hole{Vec3f(0,0,0), Vec3f(0,0,1), 5, 10};
|
||||||
|
std::array<std::pair<float, Vec3d>, 2> out;
|
||||||
|
Vec3f s;
|
||||||
|
Vec3f dir;
|
||||||
|
|
||||||
|
// Start inside the hole and cast perpendicular to its axis.
|
||||||
|
s = {-1.f, 0, 5.f};
|
||||||
|
dir = {1.f, 0, 0};
|
||||||
|
hole.get_intersections(s, dir, out);
|
||||||
|
REQUIRE(out[0].first == Approx(-4.f));
|
||||||
|
REQUIRE(out[1].first == Approx(6.f));
|
||||||
|
|
||||||
|
// Start outside and cast parallel to axis.
|
||||||
|
s = {0, 0, -1.f};
|
||||||
|
dir = {0, 0, 1.f};
|
||||||
|
hole.get_intersections(s, dir, out);
|
||||||
|
REQUIRE(std::abs(out[0].first - 1.f) < 0.001f);
|
||||||
|
REQUIRE(std::abs(out[1].first - 11.f) < 0.001f);
|
||||||
|
|
||||||
|
// Start outside and cast so that entry is in base and exit on the cylinder
|
||||||
|
s = {0, -1.f, -1.f};
|
||||||
|
dir = {0, 1.f, 1.f};
|
||||||
|
dir.normalize();
|
||||||
|
hole.get_intersections(s, dir, out);
|
||||||
|
REQUIRE(std::abs(out[0].first - std::sqrt(2.f)) < 0.001f);
|
||||||
|
REQUIRE(std::abs(out[1].first - std::sqrt(72.f)) < 0.001f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create a simple scene with a 20mm cube and a big hole in the front wall
|
// Create a simple scene with a 20mm cube and a big hole in the front wall
|
||||||
// with 5mm radius. Then shoot rays from interesting positions and see where
|
// with 5mm radius. Then shoot rays from interesting positions and see where
|
||||||
// they land.
|
// they land.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user