ReparentTo() changes texture of reparented model [solved]

I’m reparenting a model to another model. What i’m doing is having one model rotate around another (follow) it by reparenting model B to model A.

But model B displays the texture of model A.

How do I get it not to do this?

    m_texture = loader.loadTexture("eve_rts/textures/planets/moon.jpg")
    moon = loader.loadModel("eve_rts/models/planets/p_sphere_spin.egg")
    moon.setTexture(m_texture, 1)

    loop_moon = moon.hprInterval(280, Vec3(360, 0, 0))


    gallente_tower = loader.loadModel("eve_rts/models/towers/gallente_tower.egg")

In the above example when I reparent the moon to the planet the moons texture stays what its suppose to be.

But when I reparent the tower to the moon it takes on the moons texture??? why is that and how can i stop it from happening.

It’s because of this line:

moon.setTexture(m_texture, 1) 

This line means “apply m_texture to moon, and to every node parented to moon.” The ,1 means it gets applied to every node parented to moon, even replacing any existing textures that are already there.

There are lots of ways to avoid this. The minimal change is to replace this with:

moon.setTexture(m_texture, 1)

The flattenLight() call applies all attributes, including the setTexture() attribute, onto the vertices, and removes it from the moon itself. Thus, it will no longer be inherited by child nodes that you subsequently attach.

Another approach would be to attach the moon to another node, call it moon_root, and animate the position of moon_root instead of animating the moon directly. But still only call setTexture() on moon. Then you can attach the tower to moon_root to inherit the moon’s position without also inheriting the texture.


Thanks worked out great using the flatten! :smiley: