Using DirectWaitBar as health bar.

I’m having a little trouble getting DirectWaitBar to display properly when it’s parented to a 3d object. The odd thing is, sometimes it works fine, and others it just freaks out.

Most of the time, all I see is a grey bar hanging above my character’s heads. Occasionally the code will somewhat work right and I’ll get red and grey health bar, but the text disappears behind the wait bar. The bar works fine when parented to render2d, but as I want it to follow my character around…

Anyone had this problem or a similar one and come up with a workaround?

Just so you have an idea of what’s going on:

And loaded more or less under the same conditions:

[/img]

The exact same code that runs the health bar in the upper left hand portion of the screen creates the health bar over the character. The one difference being the health bar over the character is parented to the character. I’ve tried bar.setHpr(180,0,0) but that didn’t seem to make a difference. I’ve also tried to mess with the scale and I can’t get a response.

K, I’ve turned the billboard effect off and from what I can tell it’s just some Z-Fighting. I can’t seem to scale the bar large enough to get it to stop though. Still working on the problem and still accepting solutions.

You’re getting what’s called Z-fighting, with two exactly coplanar polygons in 3-D space. This happens because neither polygon is in front of the other, so it’s random which one you see. It doesn’t happen in the 2-d scene, because we don’t need to perform depth testing there.

To solve it, try this:

bar.setBin('fixed', 0)
bar.setDepthWrite(False)

The first line moves the bar into the ‘fixed’ bin, so it is drawn last in the scene; the second line turns off depth writing, so it won’t interfere with itself. (We have to move it last in the scene when we turn off depth writing, or it might end up obscured by things that should be behind it.)

David

Yeah, that did it. Thanks!

I’ve set bar.setLightOff() and that fixes the color on the bar itself, but for whatever reason the text is still black.

Not that it matters too much, I’m likely to do away with the text.

The text color is black by default for a DirectWaitBar. You can set it to the color you like with the text_fg keyword on the constructor, for instance text_fg = (0, 0, 1, 1) to make it blue.

David

No, I did that, but the text is rendering black:

self.bar = DirectWaitBar(text = "",
				value = 0,
				range = 500,
				pos = ( 0,0,0), 
				barColor = (0.97,0,0,1), 
				frameSize = (-0.3,0.3,0,0.025),
				text_mayChange = 1,
				text_shadow =(0,0,0,0.8),
				text_fg = (0.9,0.9,0.9,1),
				text_scale = 0.025, 
				text_pos = (0,0.01,0))

Its more or less the same code that creates the bar in the upper left hand corner. The bar is red now, but the text is still black. Without

bar.setLightOff()

both the bar and the text are black, which leads me to believe the call doesn’t trickle down to the text node created by DirectWaitBar

Hmm, maybe that’s just the drop shadow behind the text rendering in the wrong order. Try replacing the setBin call with:

bar.setBin('unsorted', 0)

This puts the bar in the unsorted bin instead of the fixed bin; both bins are drawn at the end of the frame, but the unsorted bin preserves the same drawing order that is observed under render2d.

David

Nope, didn’t work. I set the text to blue and the shadow to green and got black for both.

Huh, that baffles me. It works fine for me. Try:

bar.setLightOff(1)

to emphasize the override.

Still nothing :confused:

I’m telling you, for whatever reason, setLightOff isn’t reaching the TextNode. I’ll take a look into DirectWaitBar tomorrow, see if there are any clues.

You know what… I remember encountering this problem before. It has something to do with render.setShaderAuto()

If you have that on, for some reason all text nodes not in render2d render black when you have setLightOff() set on them. My previous workaround was just to tie a full on ambient light to it. But if you have a better suggestion, I’m all ears.

So I figured out the work around:

bar.setShaderOff()

Problem solved.

Ah, interesting. So something in the auto-shader isn’t properly handling this case, how strange. I’ll investigate, thanks!

David

Hmm, what version of Panda are you using? This might be an issue with 1.6.x, which was fixed in 1.7.0.

David

I’ve been in 1.6.2 for this project for over a year. I’ve decided to wait to upgrade to 1.7.0 until after I finish with it. Since I’m working alone, it was a hassle to switch.