Calculating collision shape from a .obj model

Post Reply
Posts: 1
Joined: Thu Nov 08, 2012 12:05 pm

Calculating collision shape from a .obj model

Post by Jishaxe » Thu Nov 08, 2012 12:12 pm

Hi, I'm new to Bullet and need to ask about something..
I'm developing a 3D game where you play is a robot on wheels and your character is affected by physics continuously. So, if you are pushed, you fall over. If you roll into a wall, you'll bounce off. I think I have this part done - I'll just have a constant force pushing your character while the wheels are moving and touching the floor.

However, how would I get the collision shape for your character? The model is loaded from an .obj model file. I have access to every triangle. I'm completely new to physics, not sure how this stuff works. Would I just get the bounding box and use a cube collision box? What about other shapes your character might collide with too? How would I match the collision shape to the shape of the model?

Sorry if what I'm saying isn't very clear - I am rushing this post as I have to go in a second and would like an answer for when I get home. Thanks, Jishaxe.

Posts: 19
Joined: Sat Aug 18, 2012 2:20 am
Location: Chennai, India

Re: Calculating collision shape from a .obj model

Post by codetiger » Sun Nov 11, 2012 6:28 am

You can use convexHull shape which can directly take the vertex and index lists of your model and build a hull shape. This should be the easiest was to do it. However, if you are not looking into that much details, you can use compound shape. Compound shape is a bunch of shapes joined together.

Posts: 149
Joined: Fri Jun 24, 2011 8:53 am

Re: Calculating collision shape from a .obj model

Post by MaxDZ8 » Tue Nov 13, 2012 8:27 am

Without seeing the model it's hard to tell whatever a convex hull will be sufficient.
I'm fairly sure there's an obj->bullet serialization example in the 2.78 SDK (and probably in all others). It produces a polysoup so you're strongly encouraged in using a lower-detail LOD for the model.
Of course this takes for granted the model is somewhat monolithic in nature. If this isn't the case you'll have to model the various constraints.
Compound shapes are another possibility but I'm unsure about their use, I think I read somewhere they didn't work as expected on GPU-accelerated broadphase (but I guess that's an outdated statement now).

Post Reply