[Resolved] Retrieve Textures & Materials of 1 model's Ge


I’m currently coding some kind of exporter for my egg models. I load them into Panda and run through the NodePath, GeomNode and Geoms to retrieve the informations I need. (I don’t want to parse the egg file)

But I encountered 2 problems in this process.
Let’s say I have a NodePath which has 1 GeomNode and that this GeomNode has X Geoms. Each Geom has 1 or more Textures and 1 Material applied.

Calling “findAllTextures()” on the NodePath gvies me all the textures but I can’t find the link Geom <-> Texture. And I don’t find how to get this info from the Geom.
I had a quick look on the Materials too and I don’t find the way to catch them neither.

Does someone know how I could do that?


Do you want to read the data exactly as it appears in the egg file? The best way to do this is to use the egg library to read the egg file (you don’t have to write your own parser, you have access to Panda’s parser).

You start this by creating an EggData and calling data.read(). Then you can recursively walk through the children of the data, which will be all of the , , , entries and whatnot, with getFirstChild()/getNextChild(). See the auto-generated API specs for details.

If you load the egg file via loadModel(), then Panda will post-process the vertices, groups, and so on to optimize it for rendering, but then it might not be easy to correlate it with the original egg file.


Thanks for the answer !

I didn’t want to create a parser indeed. I use loadModel. I didn’t know EggDatas can be used like you explain. Very interesting to keep the data structure ! I’ll try it !

But to come back to what i’m doing at the moment (and see if this can work like this because it eats my mind :slight_smile: ), the “problem” is that i’m doing a kind of 2-ways exporter in some format and i’d like to use quite the same code for the 2 ways.
I export egg files AND i export complete scenes too (with different models loaded at the same time). That is for the “2-ways”
Like that, when i export scenes, instead of exporting all the geometries, i reference the converted files of my models.

So I created some kind of Visitor that does different things when it encounters NodePaths, depending on the exporting mode (model or scene). It allows me to keep the same interface.
That’s why i’d like to use this method (that plus the fact that i didn’t know for the EggData :wink:).

i achieved to export all the geometries, normals, texture coords and colors from the GeomNodes and Geoms. (Panda seems to create 1 GeomNode for each one of the egg group, but i didn’t think of optimizations)
I have the textures and materials too (from the NodePath).

So i have almost everything i need. The only thing i miss is knowing which texture(s) and material(s) are applied to each GeomNode. Can’t i get these information (as i have access to all the others) ?

i didn’t find anything about that ! Maybe it’s doable with the “getAttrib” function of the GeomNodes ? If it’s that, i don’t understand how to use this function as it returns me None all the time.

And if it’s not that, i don’t see how to do it. But there has to be a way because Panda knows these links (quite smart this panda).

Any idea ?


Yes, it’s possible. You can iterate through the Geoms of a GeomNode, and get each state:

for i in range(geomNode.getNumGeoms()):
  state = geomNode.getGeomState(i)
  texAttrib = state.getAttrib(TextureAttrib.getClassType())
  if texAttrib:
    tex = texAttrib.getTexture()
    print i, tex

Note that this is very low-level code, so it’s a little clumsy to use. The above example assumes the existence of single-texturing only; in the presence of multitexture, the texAttrib.getTexture() call will have to be replaced with a loop to iterate through all of the textures on the texAttrib.


Thanks, your answer really helped and now it’s good ! All my models are exported in no time !