Updating btBvhTriangleMeshShape during animation of mesh

Rvo
Posts: 21
Joined: Fri Nov 01, 2013 1:44 pm

Updating btBvhTriangleMeshShape during animation of mesh

Post by Rvo »

Hi guys!

I'm using Ogre and btOgre to generate a btBvhTriangleMeshShape for my animated mesh at initialization. Now, during the animation of the mesh, I'd like to update the collision shape but not totally rebuild it. This takes forever doing it every frame for a medium to highly detailed mesh of > 1000 vertices. I think I read somewhere you can just supply the btBvhTriangleMeshShape with the deformed/moved vertices if nothing was added or removed. But I can't figure out how.

I have all the vertex info and index info. I tried doing a partialRefit / refit but as I expected nothing happened.. I assume I need to supply the btBvhTriangleMeshShape with some form of new information. I figured this maybe has something to do with the StridingMeshInterface but yeah, I'm stuck.

Is it possible what I want? I really need the btBvhTriangleMeshShape because I need a ~100% representation of my mesh in form of the collision shape.
Creating the trimesh every frame is just too slow and I can't imgine there isn't more efficient way. Yet I cannot find it!

I would greatly appreciate a solution, and if possible also working directly with BtOgre... but I would survive if it's just Bullet-oriented :)

Regards,
Reinier.
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Updating btBvhTriangleMeshShape during animation of mesh

Post by c6burns »

Rvo wrote:I think I read somewhere you can just supply the btBvhTriangleMeshShape with the deformed/moved vertices if nothing was added or removed. But I can't figure out how.
I've seen many people think this, but none who ended up with a solution. My understanding is BtOgre borrowed a class from OgreBullet which by its header/name implies it is some kind of animated shape (AnimatedMeshToShapeConverter). If you actually trace it back to the implementation of it in OgreBullet, it's ifdef'd out and looks as if it was not meant to be used. You are free to check it out and correct me if I'm wrong.

A striding mesh interface is just a way to sync render meshes with bullet meshes. BtOgre uses its own method to do this, but the results are the same. There's a mesh strider in the Ogre wiki that works just fine if you wish to compare against BtOgre.

I will assume you are doing skeletal animation. In order to get what you want, you will have to transform every vertex every frame using your bone transforms and blend weights. Perhaps you can make some clever optimizations, but in the end you are rewriting Ogre's software skeletal animation. If you already use software animation, you could likely apply the results of the transforms to the vertices in bullet ... so you wouldn't have to do double the transforms, but you still have to do all the transforms. I do not use software animation so this is not an option I ever explored. I use primitives aligned with bones and I feel this is an excellent solution. This is also what I was used to coming from CryEngine, where they use the actual geometry of the bone objects from 3DS Max (very close to primitives).
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Updating btBvhTriangleMeshShape during animation of mesh

Post by Basroil »

I would suggest you take a look at the newest Blender code that allows animated deformations in some cases. It's certainly not the best example, but it might be a good start.
Rvo
Posts: 21
Joined: Fri Nov 01, 2013 1:44 pm

Re: Updating btBvhTriangleMeshShape during animation of mesh

Post by Rvo »

My problem here is that I really need the exact collision shape. Primitives are waaaay better, I agree, but sadly I cannot go that route for my experiment at uni.

Anyway, the skeletal based animation is already in place and I can grab the vertices an indices just like the original Trimesh is constructed in btOgre.
Just wish I could update the shape easily, which I thought the refit function was its purpose. Somehow it feels like it should be possible...

I guess I'll end up grabbing a really lowpoly mesh and updating that every update. Yikes!