Texture paths [SOLVED]

The answer is different depending on whether you’re talking about Actors or ordinary models. With an Actor, you need to “flag” all the pieces that you will modify individually; otherwise all the pieces will all be combined into a single GeomNode. You would do this by passing the egg file through egg-optchar, with the -flag option. I believe this is described in the manual. With an ordinary model, you (usually) don’t have to do this.

That being said, it is also possible to iterate through the model and find just the textures, as you suggested, and replace them one-at-a-time, even if you have not flagged any pieces. It is a little complicated, though, because you have to use the low-level state interface to pull out the individual states within a single GeomNode. Still, this code (untested) ought to do the trick. It should work equally well for an Actor or for an ordinary model.

for np in model.findAllMatches('**/+GeomNode'):
    gn = np.node()
    for gi in range(gn.getNumGeoms()):
        state = gn.getGeomState(gi)
        ta = state.getAttrib(TextureAttrib.getClassType())
        if ta:
            for si in range(ta.getNumOnstages()):
                stage = ta.getOnStage(si)
                tex = ta.getOnTexture(stage)
                filename = tex.getFilename()
                filename2 = Filename('/my/new/path', filename.getBasename())
                tex2 = loader.loadTexture(filename2)
                ta = ta.addOnStage(ta.addOnStage(stage, tex2))
            state = state.setAttrib(ta)
            gn.setGeomState(gi, state)
            

David