In a Blender script I'm trying to cast a ray against my object and see what face it hits. However, ray_cast
doesn't work in any way.
You can see in my example I try casting a ray from every angle to the center of the scene. I'm using the default cube that comes with Blender's startup scene. You can easily test this script by opening Blender and deleting everything except the startup cube.
ops = bpy.ops
scene = bpy.context.scene
current_mesh = scene.objects[ 0 ]
scene.objects.active = current_mesh
ops.object.mode_set( mode = 'OBJECT' )
print( current_mesh.ray_cast( ( 0, 0, 10 ), ( 0, 0, 0 ) )[ 0 ] )
print( current_mesh.ray_cast( ( 0, 0, -10 ), ( 0, 0, 0 ) )[ 0 ] )
print( current_mesh.ray_cast( ( 0, 10, 0 ), ( 0, 0, 0 ) )[ 0 ] )
print( current_mesh.ray_cast( ( 0, -10, 0 ), ( 0, 0, 0 ) )[ 0 ] )
print( current_mesh.ray_cast( ( 10, 0, 0 ), ( 0, 0, 0 ) )[ 0 ] )
print( current_mesh.ray_cast( ( -10, 0, 0 ), ( 0, 0, 0 ) )[ 0 ] )
You can see the result of the above script in the screenshot. Every ray cast comes up False
:
I also get the same empty, incorrect results if I replace current_mesh.ray_cast
with scene.ray_cast
.
Why is ray casting completely broken? Since my object is at (0, 0, 0)
I don't think I need to translate any of my ray origins, but either way I'm casting from every cardinal direction and nothing comes back.
I'm using Blender 2.77.