Thursday, April 28, 2011

Soft body manipulation with Phantom arm

From the last demo that I presented, I was working on the integration of the soft bodies in my application. I found it extremely difficult to achieve, due to the fact that there is no documentation on world configuration, bodies configuration and so on.

In the end, I managed to integrate soft bodies, trying this and that, using a so called technique of "try and see".

Here is what I discovered during these days of using Bullet. There is the explanation, and some remarks.

There are two ways to do collision between rigidBody and soft body (that I discovered):
1. register only VF_SS, but in such case no btGImpactCollisionAlgorithm must be registered, otherwise no collision between soft and rigid from mesh will be done. Also no clusters must be used. Better simulation. No collision between concave rigid bodies will be present.
2. register CL_SS + CL_RS, generate clusters, and m_kLST = 1.0f (material) must be used. btGImpact collision algorithm can be used, thus all objects will collide. Worse soft body simulation than in the point1, but maybe this is because I used the same parameter values for the softBody configuration and material (better not from the point of performance, but visual results, because this second method is faster).

Remarks:
1. Every object in the scene must have the mass set depending on the volume of the object, but how to calculate this for the models that are imported from different model files, I don't know. (So it's up to you to decide, at import, the mass, based on the stability of the simulation)
2. The value of the force applied to the soft body must be based on the mass of the whole object. Otherwise the simulation may become unstable, objects blow up and disappear.
3. Bullet mixes up my vertex indexes at the creation of the softBody from a trimesh, so if I want to apply a texture on the softBody, it will not be applied correctly. I didn't figure out for the moment how to correct this. The only thing I can think about is to create a map, and to map every vertex of the softBody to the original index, but this will cost too mush computation performance. (The result of this can be observed in the video below)
4. Collision between softBody and other bodies is dependent of the tessellation, so you must find what's the best value for your case.
5. I must use collision margin for the soft bodies and rigid bodies of 0.5; I would like to know the relationship of the collision margin to the simulation stability, since if I leave collision margin = default, my soft bodies blow up. (No one on the bullet forum replied to this, so it's disappointing, and no solution for my case, of course, if I would spend some weeks trying to figure out what's the relationship, maybe I'll find it).
6. I can't move the soft body as I do in the case of rigid bodies, especially in the case of torque. There is no such functionality to get the current velocity of the entire soft body (we can access the velocity for every single node instead), and we can't apply a torque on the body, as in the case of the rigid bodies. In the case of the movement, Hooke's law and damping effect do they work.

And here is what I achieved (The application performance is very low because the haptic rendering, graphic rendering and simulation is done on the same thread. Using glut, that's the problem. Must change.):

Wednesday, April 6, 2011

Hanoi towers using OpenHaptics, OpenGL, Bullet and Assimp

At the moment I do my professional training, and I'm developing an application with haptics. I created a scene with Hanoi Towers, to demonstrate what I achieved. Currently, it runs OK, but I have problems like:
1. Low performance when objects collide (about 7-9 FPS). I use btGImpactMeshShape for all the objects in my scene, except walls.
2. I can't use Scheduler in OpenHaptics, well in fact I can, but program crashes when I try to shut down it properly. I use HL and HD at the same time. OpenHaptics documentation is very poor (v.3) at this subject and not only , so there are many problems also that cause me a headache.
3. I have also problems with collision detection in Bullet, since there are cases (and often), when I can push the objects in my scene through others. My world is a closed box, so even if theoretically must not allow objects to pass the walls, I can force them (by pushing with the arm, or turning simulation off, applying a force and then turning simulation on again) to pass the walls of the box, so they might fall into abyss :D.

Well, since I'm a beginner in all this, I'm satisfied to know that I managed to do at least this. Future work will be on soft objects. I would like to thank http://somapanam.wordpress.com/ (Since the name of the author is not displayed on the blog, I would not publish it) for the code that it made public, and that I used as a reference to understand how OpenHaptics and Bullet can work together.
And here's my demo video: