Confusion about inheritance and nodes

As a noob, I’m having some trouble understanding how inheritance of properties between nodes in the scene graph work.

Example 1: I import a model with no texture and use setColorScale to tint its default gray to a more pleasing color. Then I parent another object to it, also with no texture and the default (from Blender) gray color. The child inherits the new, tinted color from the parent. Great. But how do I set it to a totally new color? Using “setColor” only tints in relation to its parent color. E.g.:

parent.setColor(1, 0, 0, 1)
#parent is now a pleasing red
child.setColor(0, 0, 1, 1)

Child is not blue, but blue-tinted red (i.e., purple)

How can I set the child’s color regardless of the parent’s? (Using a number for priority didn’t change anything.)

Example 2:
I create a simple cube from a model, then parent a node containing a TextNode to it. I modify the child using setPos - as I would expect, it modifies it relative to its parent. But when I then modify the parent, for example, rotate it using setH(90), the child does not rotate relative to the parent, or move at all. I have to adjust its location manually (but relative to the parent). This seems odd to me, as I’d expect the child to move with the parent automatically, but okay. Then I set the parent back to its original heading, and manually reset the child to its original settings - but now it’s in a different place relative to the parent. Again with the code:

parent.setPos(0, 0, 0)
child.setPos(2.5, 0, 0)
#child now just to the right
parent.setH(270)
#parent rotates but child doesn’t change
child.setH(0)
child.setPos(0, -1, 0)
#child is back to its original position and orientation relative to parent.
parent.setPos(0, 0, 0)
child.setPos(2.5, 0, 0)
child.setH(0)
#parent is fine, but child is off by 0.8 on x axis

I “calculated” the 0.8 by changing the 2.5 value until it looked right, which was at x = 1.7 for the child.

This doesn’t make sense. I’m setting the parent to the same position (it in turn is parented to render) and the child to the same offset, but getting a pretty different result.

Sorry this is so long, but any explanation of some fundamental Pandaness I’m missing would be much appreciated! (I’m a noob to 3D as well as Panda, so I could just be totally confused.)

Thanks and Happy New Year,
Dan

For your colour problem, does this help?:

panda3d.org/reference/python … c4bd05a744

Cheers,
Gary

Thanks for the suggestion, but no. Doing setColorOff still sets the model to the color of its parent.

Dan

There must be a problem either somewhere else in your code, in the models you are applying the colour to, or with the version of Panda you are using.
With the following code I get one red ball and one blue ball:

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject

class Game(DirectObject):
    def __init__(self):
        self.accept('escape', __import__('sys').exit)
        self.parent = loader.loadModel('smiley')
        self.parent.reparentTo(render)
        self.child = loader.loadModel('smiley')
        self.child.reparentTo(self.parent)
        self.parent.setColor(1, 0, 0, 1)
        self.child.setColor(0, 0, 1, 1)
        self.parent.setPos(-0.5, 5, 0)
        self.child.setPos(1, 0, 0)

Game()
run()

Right, the general rule is, setColor() replaces the parent’s color completely, while setColorScale() applies the parent and the child color together.

But even if you were using setColorScale(), red * blue => black, not purple. So I don’t know how you could possibly be getting a purple child.

David