set egg model to collide by code?

I have an egg which doesn’t have collisions set up on it when exported.
How can I set a collide mask to it?
I can get the geomnode from the modelRoot, but geomnode doesn’t have that method, as well as NodePath. It seems to be a PandaNode method… but I don’t think I can wrap the geomnode inside a PandaNode and NodePath.node() will return a geomnode. What to do?

Set collision bitmask on collision node?
Make collision node first and then set bitmask on it.
You can make it in code too if you want, but i think its more practical to do it in modeling software.

How?
I need the geomNode for collisions. So I need to make a collisionNode from the geomNode, right? How?

Easiest way would be to make it in modeling package, just add tag Collide:Polyset keep descend to geometry.

That is only way i know how to get polyset collision solid, if i wanted to generate it in code, i would ask too.

Sorry that i couldnt help :slight_smile:

Sure.
We can just wait for someone else to answer.

I think you could use NodePath.calcTightBounds() and use the result to construct a CollisionBox out of that:

maxPoint = Point3()
minPoint = Point3()
myModel.calcTightBounds(minPoint, maxPoint)
collBox = CollisionBox(minPoint, maxPoint)
collNode = CollisionNode('name')
collNode.addSolid(collBox)

If a collision box is not a sufficiently good fit for your model, and the model has a number of distinct parts, you can recursively get the bounding volume on each part and create appropriate collision solids. I don’t know how Panda3D comes up with bounding volumes though; it seems likely they would all just be boxes or something.

No an option: terrain mesh.
Im surprised nobody knows this…

you could always just open the egg file and add the tag yourself. if you go into the egg file and add

" { Polyset keep descend }"

it should be added inside the group that you want to add collision to e.g

somegroup{
{ Polyset keep descend }
someverts{

thats how my egg files look anyway

What makes you think I could?
If I could do that I’d just set it in Blender myself
Hm, lets say I dont have the egg file anymore.
Or Im generating the geometry procedurally.

Just because I’m curious: What do you mean when you talk about wrapping an object inside another? Are you talking about a delegate pattern?

You are aware that GeomNode is derived from PandaNode, right? If not, reading the API documentation will help. This means that a GeomNode inherites the methods from PandaNode, in particular “setIntoCollideMask”. So what are you talking about?

Oh, I meant wrapping geomnode inside nodepath. It was a mistake as the methods I needed were for pandaNode.So it didnt make any sense.

EDIT: Nevermind…
PS> For everyone else who is curious:

geomnode = mynodepath.find('**/-GeomNode').node()
geomnode.setIntoCollideMask(BitMask32.bit(1))

BTW, .setFromCollideMask() is not available to PandaNode/GeomNode because CollisionPolygon can’t be an from object.
And if your egg has multiple geomnodes, just use findAllMatches()

For the record, the into mask on a GeomNode has nothing to do with CollisionPolygon. If there are any CollisionPolygons on the model, for instance created by the egg loader with a { Polyset } entry, they will be under a CollisionNode, not under GeomNode. The collide mask on GeomNode has to do with collision-against-geometry, which is the slow method (considerably slower than CollisionPolygons).

Do you mean because its usually higher poly,
or because its stored triangulated?
Because I want to simply have my own custom tags and the geomnodes used for collisions arent meant to be rendered.

All of the above, but even without those differences, CollisionPolygons are many times faster than the exactly equivalent Geom, just because the data structure of a Geom is optimized for render data, whereas the data structure of a CollisionPolygon is optimized for collision data.

Basically, collide-with-geometry is only provided as an option to facilitate development, so you can do a quick-and-dirty collision against your visual geometry for cases when you really don’t care about performance. But if performance matters to you, you should always use CollisionPolygons.

Especially if the geometry isn’t even intended to be rendered. In that case, you have no excuse, and you should have created CollisionPolygons in the first place.

David

Okay, I thought about it and I guess I could use the standard collision tags and another tag for custom stuff like collision bit.
There is one problem. Im using tags to set everything up in Blender, but Im not sure whats the best way to tell which visible mesh uses which collision mesh in the egg file. Does the egg file allow “hierarchy” like this- if I parent the collision mesh to the visible mesh, will that data be stored in the .egg?
I know the egg is usually like this:

modelRoot/
    collisionNode
    geomNode
    Actor

Can it be like this?

modelRoot/
    geomNode/
        collisionNode

So i could easily set collision solids when loading the file?
If no, what do you suggest to do?

answer please.

Looks like that would work, at least in the scene graph. Not sure about egg, but have you tried it?

My question’s about getting parenting info from egg to Panda, what do you mean here?

I dont notice any “Parent” or “Child” tag.

<CoordinateSystem> { Z-up }

<Comment> { "Egg laid by Chicken for Blender, version R91" }

<Group> Circle {
}
<Group> Cube.002 {
  <Transform> {
    <Matrix4> {
      1.000000 0.000000 0.000000 0.000000
      0.000000 1.000000 0.000000 0.000000
      0.000000 0.000000 1.000000 0.000000
      6.000000 0.000000 0.000000 1.000000
    }
  }
  <VertexPool> Cube.002 {
    <Vertex> 0 {
      7.0 0.999999940395 -1.0
    }
    <Vertex> 1 {
      7.0 -1.0 -1.0
    }
    <Vertex> 2 {
      5.0 -0.999999821186 -1.0
    }
    <Vertex> 3 {
      5.00000047684 1.00000035763 -1.0
    }
    <Vertex> 4 {
      7.00000047684 0.999999463558 1.0
    }
    <Vertex> 5 {
      5.0 1.0 1.0
    }
    <Vertex> 6 {
      4.99999952316 -0.999999642372 1.0
    }
    <Vertex> 7 {
      6.99999952316 -1.00000059605 1.0
    }
    <Vertex> 8 {
      7.0 0.999999940395 -1.0
    }
    <Vertex> 9 {
      7.00000047684 0.999999463558 1.0
    }
    <Vertex> 10 {
      6.99999952316 -1.00000059605 1.0
    }
    <Vertex> 11 {
      7.0 -1.0 -1.0
    }
    <Vertex> 12 {
      7.0 -1.0 -1.0
    }
    <Vertex> 13 {
      6.99999952316 -1.00000059605 1.0
    }
    <Vertex> 14 {
      4.99999952316 -0.999999642372 1.0
    }
    <Vertex> 15 {
      5.0 -0.999999821186 -1.0
    }
    <Vertex> 16 {
      5.0 -0.999999821186 -1.0
    }
    <Vertex> 17 {
      4.99999952316 -0.999999642372 1.0
    }
    <Vertex> 18 {
      5.0 1.0 1.0
    }
    <Vertex> 19 {
      5.00000047684 1.00000035763 -1.0
    }
    <Vertex> 20 {
      7.00000047684 0.999999463558 1.0
    }
    <Vertex> 21 {
      7.0 0.999999940395 -1.0
    }
    <Vertex> 22 {
      5.00000047684 1.00000035763 -1.0
    }
    <Vertex> 23 {
      5.0 1.0 1.0
    }
  }
  <Polygon> {
    <Normal> { 0.000000 0.000000 -1.000000
    }
    <VertexRef> { 0 1 2 3 <Ref> { Cube.002 } }
  }
  <Polygon> {
    <Normal> { 0.000000 -0.000000 1.000000
    }
    <VertexRef> { 4 5 6 7 <Ref> { Cube.002 } }
  }
  <Polygon> {
    <Normal> { 1.000000 -0.000000 -0.000000
    }
    <VertexRef> { 8 9 10 11 <Ref> { Cube.002 } }
  }
  <Polygon> {
    <Normal> { -0.000000 -1.000000 -0.000000
    }
    <VertexRef> { 12 13 14 15 <Ref> { Cube.002 } }
  }
  <Polygon> {
    <Normal> { -1.000000 0.000000 -0.000000
    }
    <VertexRef> { 16 17 18 19 <Ref> { Cube.002 } }
  }
  <Polygon> {
    <Normal> { 0.000000 1.000000 0.000000
    }
    <VertexRef> { 20 21 22 23 <Ref> { Cube.002 } }
  }
  <Group> Cube.001 {
    <Transform> {
      <Matrix4> {
        1.000000 0.000000 0.000000 0.000000
        0.000000 1.000000 0.000000 0.000000
        0.000000 0.000000 1.000000 0.000000
        -3.000000 0.000000 0.000000 1.000000
      }
    }
    <VertexPool> Cube.001 {
      <Vertex> 0 {
        4.0 0.999999940395 -1.0
      }
      <Vertex> 1 {
        4.0 -1.0 -1.0
      }
      <Vertex> 2 {
        1.99999988079 -0.999999821186 -1.0
      }
      <Vertex> 3 {
        2.00000047684 1.00000035763 -1.0
      }
      <Vertex> 4 {
        4.00000047684 0.999999463558 1.0
      }
      <Vertex> 5 {
        2.0 1.0 1.0
      }
      <Vertex> 6 {
        1.99999964237 -0.999999642372 1.0
      }
      <Vertex> 7 {
        3.99999928474 -1.00000059605 1.0
      }
      <Vertex> 8 {
        4.0 0.999999940395 -1.0
      }
      <Vertex> 9 {
        4.00000047684 0.999999463558 1.0
      }
      <Vertex> 10 {
        3.99999928474 -1.00000059605 1.0
      }
      <Vertex> 11 {
        4.0 -1.0 -1.0
      }
      <Vertex> 12 {
        4.0 -1.0 -1.0
      }
      <Vertex> 13 {
        3.99999928474 -1.00000059605 1.0
      }
      <Vertex> 14 {
        1.99999964237 -0.999999642372 1.0
      }
      <Vertex> 15 {
        1.99999988079 -0.999999821186 -1.0
      }
      <Vertex> 16 {
        1.99999988079 -0.999999821186 -1.0
      }
      <Vertex> 17 {
        1.99999964237 -0.999999642372 1.0
      }
      <Vertex> 18 {
        2.0 1.0 1.0
      }
      <Vertex> 19 {
        2.00000047684 1.00000035763 -1.0
      }
      <Vertex> 20 {
        4.00000047684 0.999999463558 1.0
      }
      <Vertex> 21 {
        4.0 0.999999940395 -1.0
      }
      <Vertex> 22 {
        2.00000047684 1.00000035763 -1.0
      }
      <Vertex> 23 {
        2.0 1.0 1.0
      }
    }
    <Polygon> {
      <Normal> { 0.000000 0.000000 -1.000000
      }
      <VertexRef> { 0 1 2 3 <Ref> { Cube.001 } }
    }
    <Polygon> {
      <Normal> { 0.000000 -0.000000 1.000000
      }
      <VertexRef> { 4 5 6 7 <Ref> { Cube.001 } }
    }
    <Polygon> {
      <Normal> { 1.000000 -0.000000 0.000000
      }
      <VertexRef> { 8 9 10 11 <Ref> { Cube.001 } }
    }
    <Polygon> {
      <Normal> { -0.000000 -1.000000 -0.000000
      }
      <VertexRef> { 12 13 14 15 <Ref> { Cube.001 } }
    }
    <Polygon> {
      <Normal> { -1.000000 0.000000 -0.000000
      }
      <VertexRef> { 16 17 18 19 <Ref> { Cube.001 } }
    }
    <Polygon> {
      <Normal> { 0.000000 1.000000 0.000000
      }
      <VertexRef> { 20 21 22 23 <Ref> { Cube.001 } }
    }
    <Group> Cube {
      <Transform> {
        <Matrix4> {
          1.000000 0.000000 0.000000 0.000000
          0.000000 1.000000 0.000000 0.000000
          0.000000 0.000000 1.000000 0.000000
          -3.000000 0.000000 0.000000 1.000000
        }
      }
      <VertexPool> Cube {
        <Vertex> 0 {
          1.0 0.999999940395 -1.0
        }
        <Vertex> 1 {
          1.0 -1.0 -1.0
        }
        <Vertex> 2 {
          -1.00000011921 -0.999999821186 -1.0
        }
        <Vertex> 3 {
          -0.999999642372 1.00000035763 -1.0
        }
        <Vertex> 4 {
          1.00000047684 0.999999463558 1.0
        }
        <Vertex> 5 {
          -0.999999940395 1.0 1.0
        }
        <Vertex> 6 {
          -1.00000035763 -0.999999642372 1.0
        }
        <Vertex> 7 {
          0.999999344349 -1.00000059605 1.0
        }
        <Vertex> 8 {
          1.0 0.999999940395 -1.0
        }
        <Vertex> 9 {
          1.00000047684 0.999999463558 1.0
        }
        <Vertex> 10 {
          0.999999344349 -1.00000059605 1.0
        }
        <Vertex> 11 {
          1.0 -1.0 -1.0
        }
        <Vertex> 12 {
          1.0 -1.0 -1.0
        }
        <Vertex> 13 {
          0.999999344349 -1.00000059605 1.0
        }
        <Vertex> 14 {
          -1.00000035763 -0.999999642372 1.0
        }
        <Vertex> 15 {
          -1.00000011921 -0.999999821186 -1.0
        }
        <Vertex> 16 {
          -1.00000011921 -0.999999821186 -1.0
        }
        <Vertex> 17 {
          -1.00000035763 -0.999999642372 1.0
        }
        <Vertex> 18 {
          -0.999999940395 1.0 1.0
        }
        <Vertex> 19 {
          -0.999999642372 1.00000035763 -1.0
        }
        <Vertex> 20 {
          1.00000047684 0.999999463558 1.0
        }
        <Vertex> 21 {
          1.0 0.999999940395 -1.0
        }
        <Vertex> 22 {
          -0.999999642372 1.00000035763 -1.0
        }
        <Vertex> 23 {
          -0.999999940395 1.0 1.0
        }
      }
      <Polygon> {
        <Normal> { 0.000000 0.000000 -1.000000
        }
        <VertexRef> { 0 1 2 3 <Ref> { Cube } }
      }
      <Polygon> {
        <Normal> { 0.000000 -0.000000 1.000000
        }
        <VertexRef> { 4 5 6 7 <Ref> { Cube } }
      }
      <Polygon> {
        <Normal> { 1.000000 -0.000000 0.000000
        }
        <VertexRef> { 8 9 10 11 <Ref> { Cube } }
      }
      <Polygon> {
        <Normal> { -0.000000 -1.000000 -0.000000
        }
        <VertexRef> { 12 13 14 15 <Ref> { Cube } }
      }
      <Polygon> {
        <Normal> { -1.000000 0.000000 -0.000000
        }
        <VertexRef> { 16 17 18 19 <Ref> { Cube } }
      }
      <Polygon> {
        <Normal> { 0.000000 1.000000 0.000000
        }
        <VertexRef> { 20 21 22 23 <Ref> { Cube } }
      }
    }
  }
}

Parenting in the EGG file is done by nesting entries. So a parenting structure could look like this:

<Group> tree {
  <Group> branch {
    (vertexpool)
    (polygons)
    <Group> branch_collision {
      <Collide> { Polyset }
      (vertexpool)
      (polygons)
    }
  }
}

I haven’t used Chicken before, but judging from the EGG file you have posted it looks like it does export the hierarchy properly, for example Cube.002 is the parent of Cube.001 which is the parent of Cube.

Oh, awesome!