Undesired truncated egg precision with EggData

Something I noticed when reading+writing eggs through EggData is that the precision of decimals is often greatly trunicated. I noticed that this is the case even before exporting the EggData to disk (via write()) This also seems to happen regardless if I modify the egg-precision config value.

Is there an intentional reason as to why these values become truncated?

Here’s some sample code that replicates my situation:

from panda3d.egg import *
import os
from panda3d.core import Filename

target_egg_file = Filename.fromOsSpecific(os.path.join(os.getcwd(), "test_model.egg"))
output_egg_file = Filename.fromOsSpecific(os.path.join(os.getcwd(), "test_model_out.egg"))

egg_data = EggData()
egg_data.read(target_egg_file)

with open(output_egg_file, "w") as egg_file:
    print(str(egg_data))
    egg_file.write(str(egg_data))

test_model.egg (246.4 KB)

Hi loonaticx,

I’ve had a look into your issue and have found a way to get what you’re after.

Instead of writing out the string representation of the EggData str(egg_data), if you use EggData::write_egg/writeEgg() then it seems to respect the egg-precision.
https://docs.panda3d.org/1.10/python/reference/panda3d.egg.EggData#panda3d.egg.EggData.writeEgg

The following without any egg-precision gives almost the same file output as the input.

egg_data = EggData()
egg_data.read(target_egg_file)
egg_data.writeEgg(output_egg_file)

There’s a few lines where the last digit/s are ever so slightly different, like the following:

    <Normal> { 0.0253209799905412 -0.99963346311501 0.00958057373076304 }

becomes (Z component last digit 4 becomes 5)

    <Normal> { 0.0253209799905412 -0.99963346311501 0.00958057373076305 }

I had a quick look and wasn’t able to find a way to get your way to work.
I suspect it’s the str(egg_data) that’s the issue and not the open()/egg_file.write().

Hope that’s helpful :slight_smile:

Cheers,
H3LLB0Y.

2 Likes

Works for me!! Thank you very much :slight_smile:

1 Like