Detect if model has vertex colors?[solved]

Hi, I have been writting my own shaders, how can I detect if a model has vertex colors or texture colors in panda3d side, so I can apply or vertexcolor.sha or texcolor.sha?

I know this is possible since automatic shader generation would need this feature, and which maybe it involves the model egg file, the “texture” comment which appears sometimes if the file has texture, i would only need to check if this comment is present, so if not, I could just use an else statement to use vertex colors.

Thanks in advance for any help

You can check whether a texture is applied fairly easily:

if model.findTexture('*'):
  print "texture is applied"

Checking whether vertex color is applied is more difficult. Strictly speaking, vertex color is always applied, but often the color is just white. So in order to determine whether vertex color is relevant, you will have to examine all of the vertex colors and see if any of them are non-white.

Note that the use of texture doesn’t preclude the use of vertex color. One model might have both applied simultaneously.


Hi, thanks for the help. How would I check if findTexture returns none?

I tried “== 0”, “== 1”, “!= ‘none’”, “!= ‘None’” and other ways, but I haven´t been sucefull, I always receive in terminal “Tex”, which means the value comparation is wrong, since some character parts are only vertex colored(i checked the egg file, they have no texture):

for part in playerParts:
	x = part.findTexture('*')

	if x != 0:
		print "Tex"
		print "Vtx"

Try without the quotes around None.
If you want to test only if the return value is None:

if x is None:

If you want to test for a “False” value, which could be 0, None, False, or an empty list:

if not x:

Easiest thing to do is print out the actual return value from the function, then you can see what to check for:

for part in playerParts:
    x = part.findTexture('*')
    print x

Hi teedee, thanks! I would take a long time to figure “if x is None”

This is what I wanted, since when the model has no texture, print outputs “None”. I think None is what in API reference is said as “NULL”

Yes, “NULL” is the C++ equivalent of Python’s “None”.