Writing then reading an .egg file rotates model

I created a flat square model (in the xz plane) and wrote it to an egg file. I then loaded that model in a different script. When loaded, the model “sticks up” as if it were modeled in the xy plane instead. Is there a problem in the code writing out the model?

      eggData = EggData()
      vp = EggVertexPool("square")
      eggData.addChild(vp)
      poly = EggPolygon()
      eggData.addChild(poly)
      v = EggVertex()
      v.setPos(Point3D(0, 0, 0))
      v.setUv(Point2D(0,0))
      poly.addVertex(vp.addVertex(v))
      v = EggVertex()
      v.setPos(Point3D(1, 0, 0))
      v.setUv(Point2D(1,0))
      poly.addVertex(vp.addVertex(v))
      v = EggVertex()
      v.setPos(Point3D(1, 0, 1))
      v.setUv(Point2D(1,1))
      poly.addVertex(vp.addVertex(v))
      v = EggVertex()
      v.setPos(Point3D(0, 0, 1))
      v.setUv(Point2D(0,1))
      poly.addVertex(vp.addVertex(v))
      eggData.recomputePolygonNormals()
      eggData.writeEgg(Filename("square.egg"))

The .egg file itself seems to have the right information:

<VertexPool> square {
  <Vertex> 0 {
    0 0 0
    <UV> { 0 0 }
  }
  <Vertex> 1 {
    1 0 0
    <UV> { 1 0 }
  }
  <Vertex> 2 {
    1 0 1
    <UV> { 1 1 }
  }
  <Vertex> 3 {
    0 0 1
    <UV> { 0 1 }
  }
}
<Polygon> {
  <Normal> { 0 -1 0 }
  <VertexRef> { 0 1 2 3 <Ref> { square } }
}

The .egg file didn’t specify a coordinate system. The default coordinate system in an .egg file is Y-up, while the default coordinate system in Panda is Z-up (for historic reasons). This is what’s causing the 90-degree rotation: the Panda loader your data was in the Y-up coordinate system, while the data you wrote was Z-up.

To fix, you can simply tell the Egg loader that your data is in z-up, by putting the following at the top of your .egg file:

<CoordinateSystem> { Z-Up }

How can I tell the egg data to put that in the .egg file for me when it writes it out?

eggData.setCoordinateSystem(CSZupRight)

Excellent, thanks.