PandaSteer 2

I splitted the collision terrain into small pieces, currently 3x3 grid of quads, and it’s adjustable.
screenshot showing the rendered & randomly colored 3x3 quads collision nodes.

    # Now create a terrain model from the heightmap.
    tnp = render.attachNewNode("Terrain")
    data4Rendering = EggData()
    vp = EggVertexPool('Terrain vertex pool')
    # nodepath to hold collision nodes
    tCollNP = tnp.attachNewNode("Terrain4Collision")
    # supply the eggGroup & eggVPool for the first node
    vCollpool = EggVertexPool('TerrainCollision vpool')
    collGroup = EggGroup('collQuads')
    collGroup.addObjectType('barrier')
    # we use (numQuadGrid x numQuadGrid) quads for 1 collision node
    numQuadGrid=3
    # the modulo of (size-2)/numQuadGrid, to mark when the quads must be built into 1 geom
    edgeMod=(size-2)%numQuadGrid
    for i in range(0,len(midpoints)-1, numQuadGrid):
        # limit nextIrange to avoid it from jump over the edge
        nextIrange=min(numQuadGrid,len(midpoints)-1-i)
        for j in range(0,len(midpoints)-1):
            for nextI in range(0,nextIrange):
                bl = Point3D(i+nextI,j,midpoints[i+nextI][j])
                tr = Point3D(i+nextI+1,j+1,midpoints[i+nextI+1][j+1])
                br = Point3D(i+nextI+1,j,midpoints[i+nextI+1][j])
                tl = Point3D(i+nextI,j+1,midpoints[i+nextI][j+1])
                poly, polyColl = makeRectangle(vp,vCollpool,bl,tr,br,tl)
                data4Rendering.addChild(poly)
                # add a quad for collision terrain
                collGroup.addChild(polyColl)
                # build the collision node geom
                if j%numQuadGrid==edgeMod and nextI==nextIrange-1:
                   data4Collision = EggData()
                   data4Collision.addChild(collGroup)
                   rectNode = loadEggData(data4Collision)
                   cNP=tCollNP.attachNewNode(rectNode.getChild(0).getChild(0))
                   # uncomment the next line to see the collision geom
                   #cNP.show()
                   # supply the eggGroup & eggVPool for the next node
                   collGroup = EggGroup('collQuads')
                   collGroup.addObjectType('barrier')
                   vCollpool = EggVertexPool('TerrainCollision vpool')
    pandaNode = loadEggData(data4Rendering)
    tnp.attachNewNode(pandaNode)
    return tnp, tCollNP

Thanks for the pointer, David, now it can hit 39 fps ! :smiley: