Collision data with code-generated EggData

I’m trying to use a less complex collision geometry with my code-generated EggData grid. If I use the commented out code (CSTPolyset type with “keep + descend” flags), it works but it is really slow with a large grid. No collisions seem to be detected when I use the CSTPlane type. What is the proper way to use a CSTPlane type in this case?

   def generate(self):
      gridData = self.gridData
      self.data = EggData()
      group = EggGroup()
      self.data.addChild(group)
      #cFlags = EggGroup.CFKeep+EggGroup.CFDescend 
      #group.setCsType(EggGroup.CSTPolyset) 
      cFlags = EggGroup.CFKeep 
      group.setCsType(EggGroup.CSTPlane) 
      group.setCollideFlags(cFlags)       
      vp = EggVertexPool("grid")
      group.addChild(vp)
      for z in range(gridData.height):
         for x in range(gridData.width):
            poly = EggPolygon("%d_%d" % (x,z))
            group.addChild(poly)
            v = EggVertex()
            v.setPos(Point3D(x, 0, z))
            v.setUv(Point2D(0,0))
            poly.addVertex(vp.addVertex(v))
            v = EggVertex()
            v.setPos(Point3D(x+1, 0, z))
            v.setUv(Point2D(1,0))
            poly.addVertex(vp.addVertex(v))
            v = EggVertex()
            v.setPos(Point3D(x+1, 0, z+1))
            v.setUv(Point2D(1,1))
            poly.addVertex(vp.addVertex(v))
            v = EggVertex()
            v.setPos(Point3D(x, 0, z+1))
            v.setUv(Point2D(0,1))
            poly.addVertex(vp.addVertex(v))
            indx = z*gridData.width+x
            if gridData.state[indx] == False:
               poly.setTexture(self.eggTex)
               
            else:
               poly.setTexture(self.eggTex2)
                        
      self.data.recomputePolygonNormals()      
      node = loadEggData(self.data)
      node.setIntoCollideMask(BitMask32.bit(0))
      self.gridNode = NodePath(node)
      self.gridNode.setName("grid_node")

CSTPlane is for CollisionPlane, it means a featureless infinite plane. It will take the first polygon it finds and use that to define the position and orientation of the plane, ignoring the rest of the polygons. I doubt this is what you had in mind.

David

I thought since all of my polys (squares, in a grid) lie in the same plane (y=0) that a plane would be perfect for a collision geometry. I would take the x and z coordinates of the collision and determine which square the cursor was actually pointing to.

What would be a better way to do it?

It sounds to me like using a collision plane and converting the coords into a given square would be a good idea. I’d recommend creating the collision plane with a call like the following:

plane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))

You could always adjust the orientation and location based on the eggdata. Then you just need to add the plane to a collision node, set any masking, add it to the scene graph and you’ll be good to go.

If they’re all in the plane y=0, then it ought to have worked as you say–it’s not obvious what went wrong. The result of loading the egg data should have been a single CollisionPlane at y=0. You could examine the results and see if that’s in fact what you got; if not, it might at least give some insight to the problem.

But why not just create a single CollisionPlane at y=0 directly, instead of messing around with this complex grid creation?

David

I need the poly grid because I want to change the square’s texture when the user clicks there.

Eventually I’d like to turn this exercise into some kind of minesweep game. I know the last thing the world needs is another minesweep game, but it’s easier to learn this stuff when you have a real project to work on.

You could still have a grid of polys, and just check collisions with an invisible plane, though. The things you change the textures on don’t have to be the same thing you do collision checking with.