Adding texture makes model black

This problem has got me stumped. I’m using a development build a few months old on windows 7 and with python 3. I have a terrain mesh generated from a height map using L3DT which I converted to egg via a somewhat convoluted process. The egg file looks good but the only sections are vertices and polygons. The vertices do have UV information which also looks fine. I import the model into panda and add some lights which seem to work correctly, giving shadows as it should. But when I use setTexture, passing it my texture file, the entire model becomes black with no shading visible if it is there at all. I have tried adding a material to the model, setting it’s emission to full white. Adding/removing the lines for material and lights has no effect on the result. Only removing the line which sets the texture has any effect. I can upload the model/height-map and texture if required.

Here’s my code:

from math import pi, sin, cos

import direct.directbase.DirectStart
from panda3d.core import *

# Load the environment model.
environ = loader.loadModel("Autumn_C12.egg")
# Reparent the model to render.
# Apply scale and position transforms on the model.
environ.setScale(0.25, 0.25, 0.25)
environ.setPos(0, 0, -10000)
environ.setColor(VBase4(1, 1, 1, 1))

myMaterial = Material()
myMaterial.setEmission(VBase4(1, 1, 1, 1))


plight = PointLight('plight')
plight.setColor(VBase4(0.8, 0.8, 0.8, 1))
plnp = render.attachNewNode(plight)
plnp.setPos(0, 0, 0)

alight = AmbientLight('alight')
alight.setColor(VBase4(0.8, 0.8, 0.8, 1))
alnp = render.attachNewNode(alight)


Hmm… I’m not sure that this is the problem, but should the “setTexture” line not be given a Texture object, rather than a string?

In other words, instead of the following (as you have it now):


Have you tried it as below?


That’s probably it - due to an unfortunate oversight, Panda’s parameter coercion system tries to be overly smart in coercing parameters. The setTexture method in particular takes a Texture object, and you’re passing it a string, so Panda3D calls the following under the hood:


…which merely creates an empty Texture with the name “Autumn_C12_TX.jpg” instead of loading it from disk.

This will be solved in a future version of Panda3D, which means it will actually produce an error message rather than merely a confusing result.

Thank you Thaumaturge, I had a feeling it was a simple mistake on my part. However, I’ve changed it to what you suggested which causes python to stop working. An error message pops up asking to check online for a solution, close the program or debug it with details mentioning an exception. I suspect the C code in panda is generating an exception that isn’t being handled. It is definitely the setting of the texture that is causing the crash. I tried with a different texture and it works but is significantly smaller in dimension and colour depth. So… is there a size limit? Is there a preferred format? I’ve tried jpg and png with the same result. What could cause one image to crash the program when another image doesn’t?

Thank you for both of your help so far, the explanation from rdb is really helpful for me to predict how panda might function in the future.

You say that the texure that doesn’t cause a crash is smaller and has a lower colour-depth; in that case, how big is the bigger texture, and what colour-depth does it use?

That would be a bug. Please attach a test case to a bug report.

Here is the bug report. Let me know if you need anymore information.