Getting material on a loaded model

I have a model which has a material assigned to it exported from Blender. I’d like to be able to modify the model’s material after loading it from an egg file. However, for some reason I can’t get to it.

Here’s what I do:

self.modelDir = "/home/coppertop/Development/art/"
self.model = loader.loadModel(self.modelDir+"box_test.egg")
print self.model.getMaterial() # prints None
print self.model.hasMaterial() # prints 0

# It came to my mind I need to go a little deeper into the graph, but that didn't work either
print self.model.getChild(0).getMaterial() # prints None
print self.model.getChild(0).hasMaterial() # prints 0

The egg is very, very simple. It’s just a cube with color/specular and normal map. I don’t want to paste it here, for size reasons, so you can take a look at it here:

The material works fine. I have the expected colors, bumps and specularity. When I modify any of the values in the egg (like diff or spec color or shininess), I get expected results too. However, I can’t get to the material from the code level.

model.hasMaterial() returns false for the same reason that model.hasTexture() returns false: the material is not applied at the root of the model, but rather directly to the geometry. But you can use model.findMaterial(’*’) or model.findAllMaterials() to retrieve it.

Note that modifying an existing Material after it has been applied to geometry is a little bit unsupported: if you are using the auto-shader, making changes like this might not show up on the geometry (because the Material properties get baked into the generated shader). It’s better to create a new Material and apply that instead.


That’s what I thought. I wonder why I haven’t tried using findMaterial, though… :/. Anyhow, it obviously works this way.

Oh, I didn’t think about that.

Thanks for your help!