I'm trying to model ultrasound rays going through human organs. I figured I could use Bullet since it provides an easy to use raycast API and softbody physics, although I have almost no previous experience using it (or any other physics engine for that matter). I picked a kidney from this dataset, and shot a ray through it, recalculating its refraction direction using Snell's Law.
I followed this SoftBody from OBJ example and this Raytest example and created a new entry in the Examples Browser. Ended up with something like this:

Pretty good!

Blue spheres indicate when the ray gets into the kidney, red ones when it goes out. I aimed the ray at a spot where the mesh has a "valley", where the kidney gets concave.
You can see it in a more detailed fashion in this picture, using a much more detailed mesh:

I tried going up with the number of rays, no problem:

I was able to shoot 500 rays at 15fps, using an i7-4510U. Removing rays' rendering led to a little bit more than 30fps.
I figured having a rigidbody would improve performance, so I went ahead using the RigidBody from OBJ example. However, performance dropped to 2fps! Completely removing raycasting leads to 45fps, so raycasting + rigidbody is clearly the problem here.
So, to sum up:
- 1 Softbody + 500 rays = 15 fps
- 1 Softbody + 500 rays (but no ray rendering) = 30fps
- 1 Rigidbody + 500 rays = 2 fps
- 1 Rigidbody = 45 fps
Question 1: I was wondering if anyone could point me in the right direction as to why this is happening. My guess is that the raycasting algorithm checks for the rigidbody's bounding box, and tests against every triangle inside of it, so it ends up doing 500*number_of_triangles tests. I don't know why the softbody doesn't exhibit this behavior. From what I understand, this should be done in Broadphase, right? What can I try to fix this?
Question 2: Which is the right way of adding rigid and soft bodies in the same world? I'm thinking about adding ribs to my model (which are also in that dataset), but I'd rather make them completely rigid.
Question 3: I found the function call generateBendingConstraints (called here) takes a very long time with more complex meshes. Looking through Bullet's code I found a comment saying it's doing a Floyd's algorithm, which is O(v^3). Is there any way to have that precalculated? This is one of the main reasons pushing me to use only rigid bodies, although I can't until I figure out how to do raycasting properly.
My code is at https://github.com/Blito/bullet3/tree/softbody-raycast. It's added as an example in the Examples Browser. I'm using MinGW + C++11, but it should work on any C++11-enabled compiler. I didn't push the meshes I'm using, but you can probably make it work using one of the meshes provided in the other examples.
Thank you for your time!