Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why won't my rays intersect? #110

Open
TirushOne opened this issue Jul 7, 2024 · 1 comment
Open

why won't my rays intersect? #110

TirushOne opened this issue Jul 7, 2024 · 1 comment

Comments

@TirushOne
Copy link

TirushOne commented Jul 7, 2024

So I have a problem, obvious ray intersections just arn't happening, like, at all, I can't get any rays (from the origin, but anywere else as well) to hit my custom mesh. this is part of a small personal project so it's only a couple hundred lines and I have already tested everything else and the problem seems to stem from this code here:

fn closest_hit(&self, ray: &Ray<f32, 3>) -> Option<(f32, usize)> {
       let mut closest_dist = f32::INFINITY;
       let mut closest_idx = 0;

    for tri in self.bvh.traverse_iterator(&ray, &self.tris) {
        let p1 = Point3::from(self.verts[tri.indices[0]]);
        let p2 = Point3::from(self.verts[tri.indices[1]]);
        let p3 = Point3::from(self.verts[tri.indices[2]]);
        
        let res = ray.intersects_triangle(&p1, &p2, &p3);
        
        if res.distance < closest_dist {
            closest_dist = res.distance;
            closest_idx = tri.index;
        }
    }

    if closest_dist == f32::INFINITY {
        None
    } else {
        Some((closest_dist, closest_idx))
    }
}

this code always return None no matter where the ray is, it's durection or the normals of the triangles being tested. The iterator always returns no items. And like I said I already validated everything else and it's driving me insane. Does anyone know what could possibley be causing this issue? Here is some debug info on the bvh:

child_l Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {-2.050189, 2.050189, 2.050189}
child_l Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {-2.050189, -0.990136, 2.050189}
child_l Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {-2.050189, -0.990136, 2.050189}
shape 14
child_r Min bound: {-2.050189, -2.050189, -0.990136}; Max bound: {-2.050189, -0.990136, 2.050189}
shape 5
child_r Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {-2.050189, 2.050189, 2.050189}
child_l Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {-2.050189, 2.050189, -0.990136}
child_l Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {-2.050189, 0.990136, -0.990136}
shape 7
child_r Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {-2.050189, 2.050189, -0.990136}
shape 16
child_r Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {-2.050189, 2.050189, 2.050189}
child_l Min bound: {-2.050189, 0.990136, -2.050189}; Max bound: {-2.050189, 2.050189, 2.050189}
child_l Min bound: {-2.050189, 0.990136, -2.050189}; Max bound: {-2.050189, 2.050189, 0.990136}
shape 8
child_r Min bound: {-2.050189, 0.990136, -2.050189}; Max bound: {-2.050189, 2.050189, 2.050189}
shape 17
child_r Min bound: {-2.050189, -2.050189, 0.990136}; Max bound: {-2.050189, 2.050189, 2.050189}
child_l Min bound: {-2.050189, -2.050189, 0.990136}; Max bound: {-2.050189, 2.050189, 2.050189}
shape 15
child_r Min bound: {-2.050189, -0.990136, 0.990136}; Max bound: {-2.050189, 2.050189, 2.050189}
shape 6
child_r Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {2.050189, 2.050189, 2.050189}
child_l Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {2.050189, -2.050189, 2.050189}
child_l Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {2.050189, -2.050189, 2.050189}
shape 2
child_r Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {2.050189, -2.050189, 2.050189}
shape 11
child_r Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {2.050189, 2.050189, 2.050189}
child_l Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {2.050189, 2.050189, -2.050189}
child_l Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {2.050189, 2.050189, -2.050189}
shape 4
child_r Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {2.050189, 2.050189, -2.050189}
shape 13
child_r Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {2.050189, 2.050189, 2.050189}
child_l Min bound: {-2.050189, -2.050189, -2.050189}; Max bound: {2.050189, 2.050189, 2.050189}
child_l Min bound: {-2.050189, -2.050189, 2.050189}; Max bound: {2.050189, 2.050189, 2.050189}
child_l Min bound: {-2.050189, -2.050189, 2.050189}; Max bound: {2.050189, 2.050189, 2.050189}
shape 1
child_r Min bound: {-2.050189, -2.050189, 2.050189}; Max bound: {2.050189, 2.050189, 2.050189}
shape 10
child_r Min bound: {-2.050189, 2.050189, -2.050189}; Max bound: {2.050189, 2.050189, 2.050189}
child_l Min bound: {-2.050189, 2.050189, -2.050189}; Max bound: {2.050189, 2.050189, 2.050189}
shape 0
child_r Min bound: {-2.050189, 2.050189, -2.050189}; Max bound: {2.050189, 2.050189, 2.050189}
shape 9
child_r Min bound: {2.050189, -2.050189, -2.050189}; Max bound: {2.050189, 2.050189, 2.050189}
child_l Min bound: {2.050189, -2.050189, -2.050189}; Max bound: {2.050189, 2.050189, 2.050189}
shape 3
child_r Min bound: {2.050189, -2.050189, -2.050189}; Max bound: {2.050189, 2.050189, 2.050189}
shape 12

@svenstaro
Copy link
Owner

Can you look at the example and check whether that gives you results? Also, running the tests should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants