Collision objects using blender

I am working on getting collision detection to work and I have a fairly large object that would be much too expensive to calculate collision using visible geometry. I think my best option would just to create a large rectangle to encompass the entire object. I use blender for my modeling, Is there anyway I can include the collision mesh within the .egg file using blender? If not, how would I create a collision node out of a separate mesh?

There’s probably people who could answer this better (or more accurately as I don’t have a running copy of Blender with me at the moment), but I’ve played with this before using Blender and Chicken exporter.

Firstly, you should be able to export multiple meshes using Chicken. Just have them all selected when you export (or select them all after the script view is up and then click update selection).

It’s important to note that creating a collision object in a modeler isn’t all that different than using visible geometry. It’s just that you don’t want you collision geometry to be visible, and you want it to have fewer polygons so collision calculations are faster. So, for example, if you were to create a big box to hold your object, you could export it as it’s own .egg file. Load your visible object. Load your collision object. Hide the collision object (NodePath::hide) and reparent it to your visible node path. Now you can set the collide masks on the invisible node path exactly like you would as if it were a visible geometry you were using for collision detection.

You don’t have to create two eggs files though. As far as I know Chicken doesn’t have the ability to specify groups as collision solids, so name your meshes intelligently, you will have to edit the .egg file by hand. Export all your meshes into one egg file. The Blender “objects” will be separated out as groups in the egg file. Find your collision object’s group and add the tag. This specifies that group as invisible geometry. You should also be able to set the collide masks here as well, but I haven’t played around with that. Refer to the egg specification for more info. When you load up your object, if you didn’t set the collide masks in the egg file, you’ll have to find your collision geometry and set its masks. Use NodePath::find . The Labyrinth tutorial is good example of how to use find for this purpose.

Also, be aware that any collision geometry created with way is like, if not actually, a CollisionPolygon. It will only be useful as an “into” object. This might be a problem if your large object is moving through the world, but maybe not. I’ve also found it useful, if your object can only bump it things in certain ways, to use CollisionSegments, created programaticlly, as “bumpers”, rather than having a fully encompassing collision geometry. Also, keep in mind that it your object is in anyway close to spherical, creating a CollisionSphere is the fastest route to go.

Actually Chicken does have the ability to tag objects as collision solids through Object Types.
Object Types are shortcuts for arbitrary bits of egg file syntax that are defined in your panda 3d .conf files. There’s a few of those that deal with defining collision solids so you can use those in Chicken for that purpose.

How to do that is explained in the manual, but for convenience I’ll explain here. You select your object, go to the logic panel (F4), and add a property named ObjectType, set its type to String, and give it a value corresponding to the object type you want (“sphere” for instance is one of the default types in Confauto.prc that defines a collision sphere). You can define additional object types in your Config.prc to do anything you want.
Also I should mention that any other property defined in this panel is exported as a Tag; that way you can export additional information with your models that you can use in your game logic.