Help with Egg File Parsing in Python

Hi all,

So I have been trying to parse through an egg file of a simple plane with subdivisions using the EggData, EggGroupNode… classes.

I wish to get each vertex value printed out.

Here is the code:

import direct.directbase.DirectStart
from pandac.PandaModules import *
class MyApp():
    def __init__(self):
        egg = EggData() 
        fname = Filename('fullMeshMax.egg') 
        egg.resolveEggFilename(fname), "full")
        model = NodePath(loadEggData(egg))

    def handleVertexPool(self, vpool):
      print "Vertex Pool for node ..."
      for i in range(vpool.getHighestIndex() + 1): 
        vertex = vpool.getVertex(i) 
        if vertex: 
          print vertex
    def iterateEgg(self, egg): 
      print "Iterating ...."
      if isinstance(egg, EggVertexPool): 

      print "Group nodes."
      if isinstance(egg, EggGroupNode): 
        child = egg.getFirstChild() 
        while child != None: 
          child = egg.getNextChild()
        print "child = null"
app = MyApp()

Unfortunately, the output doesn’t reach the handleVertexPool function at all.

It just prints :

**** End of process output ****
DirectStart: Starting the game.
Known pipe types:
(all display modules loaded.)
Iterating egg ....
Group nodes ....
child = null

Here is the corresponding egg file structure:

<CoordinateSystem> { Z-Up }

<Group> character {
  <Dart> { 1 }
  <Group> Plane01 {
    <VertexPool> Plane01.verts {
      <Vertex> 0 {
        -48.7817 -28.2246 0
        <Normal> { 0 0 1 }
      <Vertex> 1 {
        -48.7817 -58.2246 0
        <Normal> { 0 0 1 }
      <Vertex> 2 {
        -18.7817 -28.2246 0
        <Normal> { 0 0 1 }
      <Vertex> 3 {
        -18.7817 -58.2246 0
        <Normal> { 0 0 1 }
      <Vertex> 4 {
        11.2183 -28.2246 0
        <Normal> { 0 0 1 }
      <Vertex> 5 {
        11.2183 -58.2246 0
        <Normal> { 0 0 1 }


Any help would be great!


Is there a utility to access the vertex pool per EggGroupNode ?

Maybe I have not looked deep enough but am unable to find it.

loadEggData() is destructive. Avoid calling it until after you have processed the egg file. If you must call it first, then reload the egg file afterwards.


Ah that fixed it…Thanks a lot!

With respect to EggData and EggGroupNode

I need to find the triangles in the egg file. Is there already a utility to find this ? I am unable to locate one.

If not, is the alternative to construct a list of triangles based on edges. Is there a utility to get edges ?

Rather than start off on a wrong path, I would like some advice on how to proceed.

You can discover the EggPolygons by recursively traversing through the egg file, the same way you are discovering the EggVertexPool, above. These polygons are not necessarily triangles; the egg syntax allows higher-order polygons as well. If you want to insist on only triangles, you can call EggGroupNode::triangulate_polygons() before you begin to convert higher-order polygons to triangles.

There’s no explicit function to extract edges for you, but this is easy to do with STL. There are several examples of the egg code itself doing this, for instance in EggGroupNode::recompute_vertex_normals().


Awesome. I will try these options out.

Hi David,

Thanks for the help with the Egg Parsing.

I was able to rewrite the Mesh Generator using this and get it working with Blender.

I have updated our original PandAI post for reference : … ght=#60750