CollisionPolygon - How to load them from a model?

How do I load a CollisionPolygon from a model, instead of giving it’s verticies’ position?

I think I didn’t explained my problem correctly:

I need my boat to collide with my course model, instead of passing through it. How can I do that?

PS: Sorry for my bad English.

You have two choices.

The simplest thing is to enable collisions with your course geometry itself. You can do this with something like:

myScene = loader.loadModel('myScene.egg')
courseGeometry = myScene.find('**/courseGeometry')

The above assumes that your course geometry model is a sub-node within your overall scene, named “courseGeometry”. If your course geometry is a model unto itself, you can simply load the model without doing the find operation.

The above is simple to do, and it may be good enough. But when you’re ready to tune for performance, you can consider making special collision polygons for your course geometry instead of colliding directly with the visible geometry.

You would do this in your modeling package. Ideally, you would start with a copy of your course geometry, and simplify the model somewhat by removing any polygons you can get away with (e.g. flatten round corners, etc.) Combine triangles into quads and higher-order convex polygons where possible. You would also make sure that the model is hierarchically subdivided according to each section’s position in space.

If you are using Maya to do your modeling, use the mel script provided with Panda to tag each node of your collision geometry with the “barrier” egg tag. If you are not using Maya, you will have to hand-edit the egg file to add the syntax:

<ObjectType> { barrier }

within the parent group for each node of your collision geometry.

In either case, when you load the model you will have a CollisionNode for each “barrier” tag, instead of visible geometry.


#load a model. reparent it to the camera so we can move it.
s = loader.loadModel('smiley')
s.setPos(0, 25,0)

#create a collision solid for this model
cNode = CollisionNode('s')
sC = s.attachNewNode(cNode)

when i add a solid, is there a way do something like that?


I didn’t understand how do I use the bitmask. How is that, the model is a sub node of render? or it has to be in the render node?

And how do I use another model, not my visible model, but another one to collide?

I’m sorry for my noob questions.

Where do I put the tag:

{ barrier }

in the .egg file?

Do you have any examples that you could show me on how to make a irregular model collide with another model?

Regards in advance,