I do a ray_cast
from the camera along its direction to get the hit face:
def find_hit_face(camera, direction):
_, _, _, hit_face_index, hit_object, _ = (
scene.ray_cast(
depsgraph=context.view_layer.depsgraph,
origin=camera.location,
direction=direction,
distance=camera.data.clip_end,
)
)
polygons = hit_object.data.polygons()
return polygons[hit_face_index]
But I got the error IndexError: bpy_prop_collection[index]: index 5544 out of range, size 2224
.
How can I get the hit face from the hit face index?
updated_object = hit_object.evaluated_get(context.view_layer.depsgraph)
instead ofhit_object
and it works. $\endgroup$