Advertisement

hack a bounding box into nehe milkshape loader

Started by November 01, 2009 02:25 AM
2 comments, last by bzroom 15 years ago
hai.. im trying to create collision detection in nehe's milkshape model loading tutorial but im not sure how to do it.im very new to this field.can anyone plz guide me or atleast show me the right path to get this right?
I would make it so that any mesh element with a "_bb" appended to the name is loaded as a collision primitive, and not drawn.

So your model would have two meshes, character and character_bb. It might be kind of tricky to deduce the box's center, size, and orientation from the 8 randomly ordered vertices but i'm sure it's possible.

Alternatively, and for things like frustum culling, if no bounding box is found you can simply create an AABB around the entire model by iterating the vertices and keeping track of the min and max in all axes.
Advertisement
ya i roughly understand what u mean but im not sure how to put it in the source code.can u please explain me further in detail??or can u atleast show me a website for me to refer??thanks in advance
I'm assuming that all of the meshes are stored with their name in the .ms3d file. In your model loader it will be iterating over the list of meshes and copying them into some data structure. At that point it should look and see if there is a "_bb" appended to the mesh name. If so, it should not add the mesh to the renderable portion of the model structure, but rather it should add a collision primitive to the "additional data" portion of the model structure.

This is going to require heavy modification of the loader and resultant model structure. If you've just copied the code from a tutorial it's probably next to impossible until you understand exactly what is going on and could redesign the system to match your needs.

I don't really have the energy to describe in complete detail the ideal model structure but i can at least show you this.
struct Model{ vector<Mesh> Meshes; vector<Bone> Bones; vector<BoundingBox> BoundingBoxes;};//fills output with the data read from file: "path"bool LoadMilkshapeModel(const string &path, Model &output);


It is in this function that you'd read parse and decide what to do with the geometry. It is either meant for rendering, or meant for collision detection or other spatial queries.

I know of no published resource which would describe this method. It's just an easy way to attribute your meshes with addition data, by appending little string tokens to the name. You could name them anything it could be that a plus sign after the name means a collision object. You could even encode the mass of the object: trashcan_render and trascan_collision_10kg

If you haven't picked up on it yet. Most game models also include additional artist placed geometry. The artist models the object, but then he also models the collision primitives as additional meshes and then tags them as "i'm a collision mesh" so that they dont get rendered and get used by the physics system.

As a fallback, one can be automatically generated as a simple AABB.

This topic is closed to new replies.

Advertisement