Bug in setAlphaScale()?

from panda3d.core import *
from direct.showbase.ShowBase import ShowBase

base = ShowBase()

parent = loader.loadModel("smiley")

child = loader.loadModel("smiley")



It seems like setAlphaScale(value, 1) not only overwrites Alpha value from parent node, but also color values. This shouldn’t be the case as I haven’t called setColorScale(values, 1) on the child node.

Also, I’m not sure why NodePath has a clearColorScale() method but doesn’t have a clearAlphaScale() method. Maybe should be added? Sure, there’s ways around it but this is just cleaner.

setAlphaScale is just a convenience method for setColorScale with the color components set to 1, 1, 1. That’s also why there is no clearAlphaScale.

In this case if you want to override just the alpha component then you need to either reproduce the color scale that was on the parent, like setColorScale(1, 0, 0, 1, 1) or undo multiplicatively, with setAlphaScale(10.0).

Okay let me rephrase how I feel about this:

setAlphaScale(value) behaving like setColorScale(1,1,1, value) instead of setColorScale(getColorScale()[0], getColorScale()[1], getColorScale()[2], value) is as logical as setX behaving like setPos(1,1,value), or setH behaving like setHpr(value,1,1), it doesn’t make sense logically, practically or considering API consistency. It also favors implicit behavior over explicit naming: name of the method should tell you its functionality, there shouldn’t be more functionality which is not clear from its name.

Sorry, I wasn’t clear, it does work like setColorScale(getColorScale()[0], getColorScale()[1], getColorScale()[2], value), but in this case that’s the same as setColorScale(1, 1, 1, value) because the node in question has no color scale.

We have lots of methods to manipulate only individual components, see setX and friends.

The problem you’re bumping into is that you were expecting that the override value applied only to the alpha channel, rather than being shared for the entire color scale attribute.

I still don’t believe that’s the correct way to handle this. Override does not work like that for any other individual component setting method, so why should it act like that for setAlphaScale()?

You should be able to override Alpha component with a method designed for setting the Alpha component, without it overriding anything else. What it overrides should be only what is explicitly stated in the name of the method.

It’s just not logical and consistent.