I'am trying to develop a plugin that raycasts an animated mesh to produce pointcloud streams, which then are used as computer vision related training data with known ground truth poses. Everything works fine except of the raycasting when using the ray_cast function on the mesh to be sampled. Below I posted a picture depicting the problem.
On the left, the mesh is undeformed, the ray used is drawn in white and a sphere is created at the hit point result from ray_cast, everything as expected. Middle and right meshs are deformed and the hit points are obviously off the surface.
The code used for raytracing:
def raytrace(obj, ray): drawRay([ray, ray]) valid, pos, _, _ = obj.ray_cast(ray, ray) if valid: bpy.ops.mesh.primitive_uv_sphere_add(segments=15, ring_count=7, radius=0.01, location=pos)
Any help is appreciated, I'am really struggling with this problem and couldn't find any workaround so far. Many thanks in advance.