Small issue I can’t seem to find a solution to:
I’m using a billboard effect on a nodepath using a cardmaker.
To animate this node (it represents a character in my game) I’m using a task and switching the textures.
My problem: I’m using a set of textures to animate the “walk left”. I’d like to use these same textures to animate the “walk right” (simply flip them around the y axis) but I’m not sure how to achieve this (keep in mind that the node has a billboard effect on it).
scale the UV-map to -1 (i think the U-coords, not sure thought).
read the manual chapter about texture transforms. it’s all in there.
I actually read that part of the manual prior to posting and got pretty confused with the u,v,texturestage,etc…
I’m relatively new to Panda and am trying to gradually get a grasp of the engine. I’m still struggling with the basic concepts and I felt that to understand that part of the tutorial would be a bit too soon (There are simpler things that I want to fully understand before the advanced topics).
As this is the case - I was hoping that perhaps someone could explain a bit more in depth the way to achieve this effect.
model.setTexScale(TextureStage.getDefault(), -1, 1)
The thing is that I’m using a single node to animate both the “walk right” and the “walk left” so I can’t really set the texture scale to the model (which by the way is the cardmaker).
Is there a way to flip the texture itself?
Or perhaps the node/nodepath?
You can flip the texture in Photoshop or Gimp, and load it into texture memory twice.
Or, you can call setTexScale() on the card when you want to flip it, and call clearTexTransform() when you want to flip it back.
Or, you can call setTexScale() to either (-1, 1) or (1, 1) each time you apply a texture.
Or, you can create multiple copies of your card, and show or hide the appropriate one at the appropriate time.
Or, you can create multiple copies of your card and put them all under a SwitchNode, and let Panda handle the showing and hiding automatically.
There are numerous ways to tackle this problem. But “flipping” a texture usually means to flip its UV’s, which means a change to the model, not to the texture itself. So you have to apply the change to the card, which is to say, the card’s NodePath. (You can’t directly flip the pixels of a texture without reloading the texture into graphics memory, which is why flipping is usually done on the UV’s, and not on the texture.)
Thank you for the elaborative explanation.
one more thing, after rereading your reply.
Actually, I wouldn’t mind having two sets of textures in memory as long as I don’t have to have the two sets on disk (enlarging my setup program) - I hope I didn’t misunderstand your point there.
Is there a way to achieve that?
You could do it, but it’s probably more trouble than it’s worth. You’d have to load each texture, then flip the pixels in-memory by hand, and reload it. It would be something like:
tex = loader.loadTexture('tex.png')
p = PNMImage()
p2 = PNMImage(p)
for yi in range(p.getYSize()):
for xi in range(p.getXSize()):
c = p.getXelVal(xi, yi)
p2.setXelVal(p.getXSize() - 1 - xi, yi, c)
a = p.getAlphaVal(xi, yi)
p2.setAlphaVal(p.getXSize() - 1 - xi, yi, a)
t2 = Texture()
Now you can apply t2 as a mirror image of tex. I don’t really recommend this approach, though. Better just to flip the UV’s.