Can't read nested groups inside egg files

Hi,

I’m trying to understand how to read and iterate inside nested groups in an egg file.

In order to test, I made an egg file containing 6 groups, one for each face of a cube. I added two new groups and I nested the first original groups in the two new ones.
If I search for the nested groups using find and findAllMatches, I have no results.

Here’s the egg:

<CoordinateSystem> { Z-up }
<Group> Cube {
  <VertexPool> Cube {
    <Vertex> 0 {
      1.0 0.999999940395 -0.20000000298
    }
    <Vertex> 1 {
      1.0 -1.0 -0.20000000298
    }
    <Vertex> 2 {
      -1.00000011921 -0.999999821186 -0.20000000298
    }
    <Vertex> 3 {
      -0.999999642372 1.00000035763 -0.20000000298
    }
    <Vertex> 4 {
      1.00000047684 0.999999463558 0.20000000298
    }
    <Vertex> 5 {
      -0.999999940395 1.0 0.20000000298
    }
    <Vertex> 6 {
      -1.00000035763 -0.999999642372 0.20000000298
    }
    <Vertex> 7 {
      0.999999344349 -1.00000059605 0.20000000298
    }
    <Vertex> 8 {
      1.0 0.999999940395 -0.20000000298
    }
    <Vertex> 9 {
      1.00000047684 0.999999463558 0.20000000298
    }
    <Vertex> 10 {
      0.999999344349 -1.00000059605 0.20000000298
    }
    <Vertex> 11 {
      1.0 -1.0 -0.20000000298
    }
    <Vertex> 12 {
      1.0 -1.0 -0.20000000298
    }
    <Vertex> 13 {
      0.999999344349 -1.00000059605 0.20000000298
    }
    <Vertex> 14 {
      -1.00000035763 -0.999999642372 0.20000000298
    }
    <Vertex> 15 {
      -1.00000011921 -0.999999821186 -0.20000000298
    }
    <Vertex> 16 {
      -1.00000011921 -0.999999821186 -0.20000000298
    }
    <Vertex> 17 {
      -1.00000035763 -0.999999642372 0.20000000298
    }
    <Vertex> 18 {
      -0.999999940395 1.0 0.20000000298
    }
    <Vertex> 19 {
      -0.999999642372 1.00000035763 -0.20000000298
    }
    <Vertex> 20 {
      1.00000047684 0.999999463558 0.20000000298
    }
    <Vertex> 21 {
      1.0 0.999999940395 -0.20000000298
    }
    <Vertex> 22 {
      -0.999999642372 1.00000035763 -0.20000000298
    }
    <Vertex> 23 {
      -0.999999940395 1.0 0.20000000298
    }
  }
}
<Group> root {
  <Group> child {
    <Group> aa {
      <Polygon> {
        <VertexRef> { 0 1 2 3 <Ref> { Cube } }
      }
    }
  }
}
<Group> bb {
  <Polygon> {
    <VertexRef> { 4 5 6 7 <Ref> { Cube } }
  }
}
<Group> cc {
  <Polygon> {
    <VertexRef> { 8 9 10 11 <Ref> { Cube } }
  }
}
<Group> dd {
  <Polygon> {
    <VertexRef> { 12 13 14 15 <Ref> { Cube } }
  }
}
<Group> ee {
  <Polygon> {
    <VertexRef> { 16 17 18 19 <Ref> { Cube } }
  }
}
<Group> ff {
  <Polygon> {
    <VertexRef> { 20 21 22 23 <Ref> { Cube } }
  }
}

And the python file:

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
import sys

base.accept("escape", sys.exit)

cube = loader.loadModel("cube.egg")
cube.reparentTo(render)
cube.setPos(0,20,-2)

# print all hierarchy except nested groups
cube.ls() 

# print all nodes except nested groups
print cube.findAllMatches("**/**") 

# print only the root group
print cube.find("**/root").findAllMatches("**/**")

# print **not found**
print cube.find("**/root/child") 

run()

So, is this the expected behaviour or something 's wrong ? In the manual it’s not written that the group must absolutely contain a vertex pool or a polygon so I’m expecting this to work. Any ideas?

This is expected behavior. You’re not actually iterating through the egg file, you’re iterating through the nodes that are created when the egg file is loaded. There’s a big difference.

The egg loader will only create nodes corresponding to groups that seem to be important. This excludes groups that don’t contain any geometry, or meaninglessly nested groups. This is an important optimization, because a lot of times unneeded groups are created by a model converter, but you have to pay a cost for every node in the scene graph, so fewer unneeded nodes is better.

However, if you really want to keep a particular group, you can put the syntax:

<Model> { 1 }

within the group. This tells the egg loader that this particular node will be expected to be present in the resulting model, and can be searched for by name.

If you really don’t want to lose any groups at all, you can put:

egg-flatten 0

in your Config.prc file.

David

Thanks David, this fix works perfectly.