1

I have a .fbx file consisting of a skeleton and a rig, which I animate in blender. I want to now cast a ray with ray_cast from the current position of a joint to the camera position and test for intersections on the mesh that wraps the skeleton, to get the face of the mesh it intersects with.

I believe you have to transform the start (joint location) and end (camera position) location into the local space of the mesh being tested of the intersection. The intersections are either totally off or not intersecting at all, which is not plausible, since the joints are all located inside of the mesh. When rendering, the mesh seems to be at the correct spot, corresponding to the joint locations.

Do I need to update or transform the mesh in some kind of way before hand? I would be happy for any kind of idea.

mesh = bpy.data.objects['Armatures Mesh']

bpy.context.scene.objects.active = mesh

mat = c.matrix_world.inverted()
start = mat * bpy.data.objects['Armature'].pose.bones[bone].head
end = mat * bpy.data.objects['Camera'].location

direction = end - start
direction.normalize()

x = mesh.ray_cast(start, direction)
ritocesura
  • 11
  • 3

0 Answers0