Textures are discarded when writing EggData to disk

Dear Panda3d community members,

I’m struggeling with parsing an .egg file and writing a modified version to disk (using EggData structure through the Panda3d API, as desribed here: https://docs.panda3d.org/1.10/python/programming/internal-structures/other-manipulation/writing-models-to-disk).

The problem is that, while elements such as the and the are correctly saved, the block seems to be discarded during writing. Moreover, this block seems to get removed from the EggData object itself.

This is a minimal example to reproduce the described behaviour:

        egg = EggData()

        cs = EggCoordinateSystem()
        cs.setValue(CSZupRight)
        egg.addChild(cs)

        matrix = LMatrix3d()
        texture = EggTexture('lambert5SG', Filename("ground.jpg"))
        transform = EggTransform()
        transform.setTransform3d(matrix)
        texture.setMinfilter(5)
        texture.setMagfilter(2)
        texture.setFormat(7)
        texture.setWrapU(2)
        texture.setWrapV(2)
        texture.setTransform2d(matrix)
        egg.addChild(texture)

        print('Content of EggData before saving to disk:')
        print(egg)

        egg.writeEgg(Filename("wedge_new.egg"))

        print('Content of EggData after saving to disk:')
        print(egg)

And this is the output:

Content of EggData before saving to disk:

<CoordinateSystem> { Z-Up }
 
<Texture> lambert5SG {
  ground.jpg
  <Scalar> format { rgb }
  <Scalar> wrapu { repeat }
  <Scalar> wrapv { repeat }
  <Scalar> minfilter { nearest_mipmap_linear }
  <Scalar> magfilter { linear }
  <Transform> {
    <Matrix3> {
      1 0 0
      0 1 0
      0 0 1
    }
  }
}

Content of EggData after saving to disk:

<CoordinateSystem> { Z-Up }

I am rather new to Panda3d, so I probably just missed something important. I also tried another method to save the file, which produces the same result:

        model = NodePath(loadEggData(egg))
        loader.saveModel('wedge_new2.egg', model)

Maybe the issue is related to destructive behaviour of some EggData methods, as described here: loadEggData destructive
I would be grateful if anyone could give me a hint.

Cheers, Michael

PS: I use panda3d 1.10.7 on Windows 10

The problem may lie in the absence of a primitive that has this texture. It’s just a guess.

1 Like

Excellent, that was indeed the cause! This actually makes perfect sense, too.
Adding a Polygon and applying a texture via

        poly.setTexture(texture)

yields the desired output.
Thanks @serega-kkz!

Cheers, Michael