[solved] Creating Basic(Advanced?) Triggers


I’m new to the Panda3D engine and as far as I see it, it’s really nice.
Which brings me to my following problem (sorry, but the description of the problem is a bit lengthy):

I will have different meshes in my “game” which the player can click on. As I searched through the forums I realized that this is called something like a ‘trigger’ (on a GUI it would be a button…).
And so is how it should work: The player sees a mesh, a very basic example would be a cube or a pyramid, around he/she can move the camera (the mesh is always in the center of the view, so the camera practically moves on a sphere with the mesh as center). As the player moves around he/she can click on different predefined sides, as for the example above it would be the six sides of the cube or the four sides of the pyramid.
After the long prelude, my actual problem: How do I realize the clicking on the mesh’s sides?
This is how I tried it: I found the collision ray and successfully used this thechnque to pick the mesh in the center (cube, pyramid). But defining in code which polygon corresponds to which side / trigger / button is somewhat awkward. It becomes more awkward as the mesh becomes more complex. And working on polygon level in python … that could be a slow way to go at least if you want the game to be able to run on netbooks. (netbooks are a hell way to go since they don’t have any powerful graphicard, so this thought may be a honest wish…)
I tried to (FYI: I model in blender and use the Chicken R44 exporter) model extra objects, a plane in this case, above the corresponding sides but the exporter doesn’t seem to export it in a way that panda can read it, at least it’s not in the scene graph after loading (the cube is).
I searched the egg file (with a little help of the egg manual, thanks there!) and found this:

  <Polygon> {
    <TRef> { Material }
    <MRef> { Material }
    <Normal> { 0.000000 0.000000 -1.000000 }
    <VertexRef> { 0 1 2 3 <Ref> { Obj } }

and a example of the vertex reference (since it’s a cube they all look the ‘same’):

    <Vertex> 0 {
      0.999055027962 0.999056637287 -1.00094175339
      <UV> UVTex { 0.666667 1.000000 }

This es are all in a Obj and the polygons are not, but they are in the same group. (as intended)

To sum it up:
How would you do it? Are there any best practices? And is the ‘i-model-a-polygon-in-my-model-program-and-assign-code-to-it’ a good way?

If you have reached this point I would like to thank you for reading this lengthy post :wink:

Ok, the plane’s don’t get exported, thats my mistake above. The polygons are the polygons of the cube and have nothing to do with the plane.

The ChickenR44 export can’t export scene graphs at it seams (that was the problem) I exported (for testing) each object in a seperate egg and copy and pasted them in one egg file (have I mentioned it that the egg files are nice?) and the picking works now as expected.
But the question remains: Is there any better way to do it?

I think you’ve enumerated your two choices well. To restate, your choices are: (a) create a different object for each different face that you want to detect independently, or (b) create just one object which includes all faces, and determine by examining the particular polygon which face was clicked.

There are pros and cons to both approaches. You have selected (a), which isn’t a bad way to go. I can’t think of a way that is universally better.