I have a problem. I use the intersect_ray_tri() function to find the intersection between a ray and a mesh. Somethimes it works perfectly fine and somethimes it only finds one of the two intersecton or none of the intersections. It seems like the problem has something do do with the angle it hits the mesh. I'm not sure if it is a bug or not. I really appreciate all your help.

http://pasteall.org/blend/index.php?id=44571 Open the .blend. You see a sphere emtpy. This defines the direction whichin the ray goes with the camera origin as a base point. When jumping one frame forwards/backward the script gets executed. If it finds an intersection it will add an empty to the location of the intersection(this is just for debugging now). Try do move the empty(make sure it stays behind on of the two meshes, as othervise it's clear it will not find an intersection) and you will see somethimes it finds both, somethimes just one one somethimes none of the intersections.


1 Answer 1


I'd say it's this bit

    dir = camera.location - pointer.location
    intersections = []

    for face in bm.faces:
        verts = []
        for vert in face.verts:

            loc = obj.matrix_world * vert.co

        found = geometry.intersect_ray_tri(verts[0], verts[1], verts[2], dir, camera.location, True)

dir.negate() is being called for each face, effectively flipping the the ray on each iteration, giving a 50% chance of hitting the tri when it is in camera to pointer ray path.

Suggest setting

dir = (pointer.location - camera.location).normalized()

in the first place, and removing dir.negate().

  • 1
    $\begingroup$ Oh man! You saved my life! That's why it worked at the beginning. I must have somehow moved it into the loop! Man I appreciate your help so much! Thanks $\endgroup$
    – 3Descape
    Commented Dec 6, 2016 at 12:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .