Performance help

Hey all,
I am starting to understand this bit by bit. I want to tank everyone on the forums, you guys have been great about helping me out.

The following code displays at 34 fps and it is just the base map without any units or UI. How can I improve performance? None of these objects will ever move (At some point they may have animation).

import direct.directbase.DirectStart
from pandac.PandaModules import *

hextile = loader.loadModel("hextiles/3dHexTile_Grass.egg")
backstop = loader.loadModel("hextiles/BlackPlane.egg")
rbc = RigidBodyCombiner('rbc')
rbcnp = NodePath(rbc)

map = NodePath('map')
backstop = backstop.copyTo(map)
for x in xrange(-39,40):
    for y in xrange(-19,20):
        hextile = hextile.copyTo(map)



BlackPlane.egg is

<CoordinateSystem> { Z-up }

<Comment> { "Egg laid by Chicken for Blender v1.0" }

<Material> Material.001 {
  <Scalar> diffr {0.800000011921}
  <Scalar> diffg {0.800000011921}
  <Scalar> diffb {0.800000011921}
  <Scalar> specr {0.25}
  <Scalar> specg {0.25}
  <Scalar> specb {0.25}
  <Scalar> shininess {12.5}
<Texture> Material.001 {
  "/c/Documents and Settings/Owner.PAPERWEIGHT_III/My Documents/hextiles/Black.jpg"
<Group> Plane {
  <VertexPool> Plane {
    <Vertex> 0 {
      59.999996 59.999989 0.000000
    <Vertex> 1 {
      -59.999981 60.000015 0.000000
    <Vertex> 2 {
      -60.000015 -59.999996 0.000000
    <Vertex> 3 {
      59.999996 -60.000008 0.000000
  <Polygon> {
    <TRef> { Material.001 }
    <MRef> { Material.001 }
    <Normal> { 0.000000 0.000000 1.000000 }
    <VertexRef> { 0 1 2 3 <Ref> { Plane } }

3dHexTile_Grass.egg is a 48 vertex 3d Hexagon shape terrain tile (I am NOT a 3d modeler so I would love to have a more simple one).


1.dont call flattenStrong on the entire level!
2nd. dont use RBC for static geometry. in general dont use RBC at all unless you know you need to use it.
3rd, use dummy nodes to group .hmm maybe 10x10 hextiles and flatten the single dummynodes maybe you can group more into one node. but not all of them.

dont exactly know how to place hextiles exactly but with square tiles it would look like this:

for x1 in range(-4,4):
    for y1 in range(-4,4):
        dummyNode =  NodePath('dummy') 
        dummyNode.setPos(x1*10 , y1*10 ,0)
        for x2 in range(0,10):
          for y2 in range(0,10):
            tile = hextile.copyTo(dummyNode)

it might be nececssary to get all children of dummyNode to make flatten strong work.
dummy.analyze() should tell you more.

Also, note that flattenStrong() isn’t doing anything anyway in this situation. It won’t flatten across a ModelNode, and there’s a ModelNode at the top of every egg file. This means all of your individual tiles–which each came from an egg file–won’t get flattened together.

To avoid this, you can get the node just below the ModelNode, and use that to construct your grid. That is, do something like this:

hextile = loader.loadModel("hextiles/3dHexTile_Grass.egg")
hextile = hextile.getChild(0)

Then use hextile to populate your grid normally.

Future versions of Panda will provide NodePath.clearModelNodes(), which can be used before a call to flattenStrong() to make these sort of shenanigans unnececssary.


I attempted this and I only get 2 hextiles on the display, the first tile in it’s correct position and one in the center of the screen.


When I remove RBC I go from 34 fps to 26 fps so I know it is doing something useful (At this stage at least).


The RBC is serving as a poor-man’s flattenStrong(), so it’s giving you some benefit, but not nearly as much as you’d get from successfully flattening.

Furthermore, the RBC is also breaking your models when you followed my suggestion above–this is what caused all of your tiles to collapse in the center. Remove it.