I have a mesh with modifiers (subdivision, bevel) and need to raycast in edit mode to the unevaluated mesh below. I can’t create a BVH tree because it’s just too slow… I’m doing about 10 raycasts per second and creating a BVH tree takes about 40ms which adds up to a LOT of hitching.
On the other hand, scene.ray_cast takes only 1-2ms, but returns the evaluated mesh, so you end up getting face indices that don’t exist in edit mode (and subsequently won’t work with bmesh for obvious reasons).
My current solution is to loop through all of the modifiers on the object during invoke() and disable show_in_editmode, then turn them back on when the operator is finished.
This solution is working great with two minor caveats: 1) for some reason, scene.ray_cast will still return the evaluated mesh after turning off show_in_edit mode (likely a deferred update happening) so you have to wait for the frame after disabling modifiers to raycast. 2) it is a bit visually jarring for the user to have the mesh ‘pop’ to its unmodified state and then ‘pop’ back.
TLDR: I have a workable solution, but it’s not perfect. I’m curious if any of you clever chaps have some other ideas for me. Ideally scene.ray_cast() would just have a flag to return unevaluated geometry but in my search I have found no such option.