Collision Models

I can’t seem to figure it out, so can someone talk me through the process of creating a collision model, loading the egg/nodes, and creating the collision node?

I can’t find anything in the manual or API for collisions beyond the geometry panda supplies. While I know I should use spheres for From objects, I want to use hitboxes/low poly models for my Into objects.

My modeling software is Maya if that makes any difference.

Im not sure how the conversion works for that format, it might already apply the collision stuff for you but just incase, here is a way of doing it by hand.

When you convert to egg format, you should be able to open that up into a text editor and you should see something like…

<CoordinateSystem> { Z-Up }

<Texture> myTexture {

<VertexPool> myVerts {
  <Vertex> 1 {
    0 1 1
    <UV> { 1 1 }

<Group> myPolys {
  <Polygon> {
    <TRef> { myTexture }
    <Normal> { 0 -1 0 }
    <VertexRef> { 3 7 8 4 <Ref> { myVerts } }

What you need to do is add in…

<Collide> myCollisionName { polyset keep }

after this line,

<Group> myPolys {

Then when you load the model you should be able to search for myCollisionName in the model. Have a look at how the labyrinth example deals with the getting/handling of that bit.

Have fun!

Here is a sample of what I did in my test game, I load the main scene and a separate collision model, which has its wall { Polyset descend } tags to make it a collision geom node.

Hope it helps.

# load the visual model
self.scene = loader.loadModel('models/course1/course1')

#load the collisions model
self.solids = loader.loadModel('models/course1/course1_coll')

#load player model
self.player = loader.loadModel('models/carnsx/carnsx')

#search for group "wall"
# in my model I've set the tag:
#  <Group> wall {
#   <Collide> wall { Polyset descend }
# this tells panda its a geom collision node
walls = self.solids.find("**/wall")
# Set the collision bit in the IntoCollideMask

Edit: Darn, sandman beat me to it. Not nice posting while I’m still writing :stuck_out_tongue:

Excellent. So as long as that myCollisionName { polyset keep } (does the keep/descend matter?) is there, it’s automatically an into object?

I assume the mycollisionName is the name the collision traverser returns.

Thanks for the quick help!

keep descend makes sure any following group inherrits the same collision properties

Have a look here for more details on the tag… … iew=markup

The myCollisionName is whatever you want it to be, give it a meaningful name so you remember what it is when you search for it.

Have fun!

hey, i´m trying to add a collision tag in my model exported from 3d max. but the code doesn´t have a group before the tags, to add the collide tag, like i saw in an earlier post.

this is my code:

<CoordinateSystem> { Z-Up }

<Comment> {
  "MaxEggPlugin nul.max -a model 'C:\Panda3D-1.0.5\models\lego1x1.egg'"
<Group> {
  <Dart> { 1 }
  <Group> "Scene Root" {
    <Group> "Ego 05" {
      <VertexPool> "Ego 05.verts" {
        <Vertex> 1 {
          2.96797 2.96797 0
          <UV> { 1 0 }
          <Normal> { 0 0 -0.296797 }
        <Vertex> 2 {
          2.96797 0 0
          <UV> { 1 1 }
          <Normal> { 0 0 -0.296797 }
        <Vertex> 3 {
        <Vertex> 39 {
          1.71327 0.778307 3.56156
          <UV> { 0.654509 0.0244718 }
          <Normal> { 0 0 0.296797 }
      <Polygon> {
        <RGBA> { 0.952941 0.435294 0.294118 1 }
        <VertexRef> { 1 2 3 <Ref> { "Ego 05.verts" } }
      <Polygon> {
        <RGBA> { 0.952941 0.435294 0.294118 1 }
        <VertexRef> { 3 4 1 <Ref> { "Ego 05.verts" } }

i´ve tried to add the code

<Collide> myCollisionName {Polyset descend }

after all the tags and, when i use the command

NodePath.node().find("**/myCollisionName") #nodepath is the name that i create

the prompt return a error message saying that the node is empty. in what line i need to add the tag? and what is the difference between polyset keep and polyset descend?

I’m not sure what you want to do, but if you just want collisions on pre-existing models, you don’t have to edit the .egg file. You can create a collision sphere/polygon/whatever in panda and parent the sphere to the model.

Read through the collision detection tutorial that comes with panda, and search the forums for collision detection examples, there should be a bunch of them.

I’ve done a few rapid prototypes with panda, and I would never even consider editing the .egg file for collisions…it’s much nicer to do it in panda using code.

I am going though the same considerations.

What are the pros and cons of putting the CollisionSolids in the .egg fil vs. putting is in the .py file?

Imho. if you did not make the model yourself, and like me is new to Panda, it can be a bit confusion to figure out an .egg file.

But perhaps you’d argue it belongs to the .egg file
or perhaps it is faster (esp. if converted to .bam)

Please voice your opinion on this :slight_smile:

  • Its easier to use
  • It supports collision polygrons (for geom collisions)
  • Its faster then loading 50 collision spheres and saves code
  • More efficient

those are my reasons anyway ^^

I also found its usefull to edit some egg files in notepad to make sure all is as it should be. When exporting from 3dsmax, I usually get a tag trown in at the start of the first group, I have to remove that when I use tags.

Thanks for the reply Yellow.
I just have a few considerations - no offence.

Easier to use?

  • Well, I hope I will get there as well some day :slight_smile:
    Supports collision poygons?
  • I do hope I can use them in the .py as well.
    Faster than loading 50 collisionSpheres?
  • Ermm, I thought we were talking about putting the exact same code in the
    .egg-file or the .py file.
  • Please let me know, if you really need other solids to do it in the other
    kind of file (I am not very experienced with this yet)
    Saves code?
  • Well, you have to write the code anyhow, whether you put it in the .egg or
    the .py still makes it code, doesn’t it?
    More efficient?
  • I hope so - especially if converted to .bam (Does anyone know for sure?)

ok, i´m seeing the people don´t understand what i want. maybe because my english is not so good. do you know the collision detection tutorial? the maze model has a tag, not colision spheres or something like this. my model is complex like a maze, and put colision spheres or tubes will be boring a lot. do you understand now?
thanks for the patience

Kutz: Use collision Polygons in the egg file. To understand more about it, look a the link that The_Sandman posted above. It tells you all about Polyset, keep and descend.

Rainbow Brite: Yes you can add collision polygons in code, but it is a whole lot easier if you are able to position them in a modeling program. I still use collision solids in code, but sometimes the egg file is the better way. Especially for a polyset collision solid, which is what Kutz seems to be looking for.

  • well… “I” find it easier to use because I can just place my solids using a modeling program, which is ofcourse more visual so… easier for me to grasp :wink:
  • Collision polygons; I create simplified geometry in a modeling program for the player to collide with, this is usefull for things like walls, terrain or to tell the engine the player is in a certain area (ie water). I supose you could add collision polygons through code, but that would be rather a lot of trouble.
  • Python code is rather slow compared to C++, as far as I understand, loading from egg or bam files is mostly done in C++, while you need more lines for creating your collision models in python.
  • Code in the egg file isnt python, its comparable to .x model format, merely a human readable format, while the bam files are the binary format. So… I dont think you can compare egg/bam code to python code.

I’m not a guru in this field, but this is what I figure…

Sorry for taking this thread astray.
I just figured the generel discussion of .egg vs .py was interesting.
I will make a new thread for this discussion now.
So Kutz can get his answers here.