Teleporting/Positioning bullet physic objects


I’m using bullet collision shapes for collision detection as it was much faster in my cases than built-in collision detection.

Now I’m trying to implement mouse-picking and want to be able to pick objects which are animated (via bones). For this, I want to attach bullet collision shapes to the bones of the objects (so that they move with the object) and then ray-cast into the scene from the mouse position.

However, when I attach the BulletRigidBodyNode to the bones (via exposeJoint()), it seems to stay in place and not move along with the parent object (nor the bone during animation).

I realize bullet is not really made for this sort of thing, but since I don’t need physics (I never call world.doPhysics()), this should work?

How can I make sure that the Rigid Body Nodes are moved (automatically) to the correct position each frame, depending on the object position and the bone rotation?

I think that you might have to call “setTransformDirty” on your rigid bodies each frame.

In short, I don’t think that Bullet is really designed for such things–it’s main purview is in the simulation of physical responses. As a result, this sort of non-physical work may sometimes call for a few extra hoops.

I think the color indicator from any object written to the buffer will be good alternative for selection.

@Thaumaturge Thanks, setTransformDirty does the trick! Although I also have to call doPhysics every frame now, which I wanted to avoid if possible. It’s currently quite slow and I only really need this for raycasts…

@serega-kkz Thanks, but drwr states in this thread that it would be quite a bit slower, and I don’t think I can afford that at the moment. Also, I’d have to render not only objects individually, but color vertices depending on which bones they belong to (I want to know which part of the leg was clicked, or instance). This sounds like quite a bit of extra programming work that I’d like to avoid.

Update: It does work if I:

  • Use setTransformDirty() every frame
  • call BulletWorld.doPhysics() every frame
  • set all Collision Bodies into a collision group that doesn’t collide with anything.

I call doPhysics with 0 iterations. Any other ideas of how I could speed this up further, or hints what else I could disable?

1 Like

Hmm… Have you set the bodies to be kinematic? After all, they’re not being driven by physics any more.

Another thought: What shapes are you using for your objects? Are you using polygonal shapes or built-in ones (such as capsules)? You might find the latter to be a little faster, perhaps.

A third idea: Have you tried only calling “setTransformDirty” and perhaps “doPhysics” when you actually fire a ray? It may be that you can get away with not having to call them on every frame…

And finally, are you using Bullet for anything other than this detection? If so, and if it’s that other stuff that’s slower with Panda’s built-in system, then you might perhaps experiment with a hybrid approach that uses Panda’s system for this ray-based detection and Bullet for the other elements.

1 Like

You can reduce the size of the buffer that outputs the color. I think this will speed up the process of copying to RAM.

1 Like