Changing opacity with python?

Is it possible to get objects to fade out with python, rather than using Ipo’s? I thought setRGBA() might make it possible, but it doesn’t seem to recognize the Alpha value. Is this a bug that should be dealt with, or is there a way around it? A quick search didn’t turn up much.

I’ve never tried it with Python, but setRGBA() should work. Have you followed the rules for alpha fade? If you are using Blender Materials, the object you are trying to fade must have a material assigned to it (and it may need to have its faces set to “Alpha”, though I’m not sure whether that’s necessary). If you are not using Blender Materials, you must set the object’s faces to “Alpha” and “Tex” (You don’t need a texture, it just needs to be set).

hmm then i think it should return an error if the uv settings are not right

heres an example file that works, as blendenzo said notice the uv settings: here

Awesome. thanks guys.

So here’s the script I came up with. My fading object has 2 properties:

alpha:1.000
fadetime:1.000 (time it takes to fade out, in seconds.)

There’s also an End object actuator that ends the object when it dissapears. I’d like to get rid of the alpha property on the object and just have it defined in the script, since it will be the same for any object. Any suggestions?

Thanks.


import GameLogic as g
cont = g.getCurrentController()
own = cont.getOwner()

if own.alpha > 0.01:
    own.alpha -= 1/(60*own.fadetime)
for x in [0,1,2,3]:
    own.getMesh().getVertex(0,x).setRGBA([1,1,1,own.alpha])
    
if own.alpha < .01:
    g.addActiveActuator(cont.getActuator("end"),1)

hi could you post a blend with the script applied to an object in it please.

http://christopherschons.com/temp/blender/alphatest.blend

This file has 4 different objects with different fadetimes. It’s not a big deal if I have to put the alpha property on the object. It just seems redundant to me, but I don’t know my Python well enough yet to alter it.

hey thanks for posting that!

I found a solution for removing prop:alpha and work directly with the alpha value of the vertex, but it doesn’t work the same on all computers so I won’t use it. My friend helped me set up a script using getRGBA() to get the alpha, and then alter it, but there’s a problem with how different processors unpack the RGBA data, so I guess the version I posted is what I’ll go with.

hi skullbunny how would you go about making a fade in script… I get the -= thing… but I dunno what value to += to the alpha in order for it to fade in from 0… any ideas on how to make it blink/fade in an out… by the way it’s a very useful script!

What graphics card do you have? Maybe i have a more elegant solution:p

I think this should work for a fade in. Set the alpha property to 0.


if own.alpha < 1-1/(60*own.fadetime):
    own.alpha += 1/(60*own.fadetime)
for x in [0,1,2,3]:
    own.getMesh().getVertex(0,x).setRGBA([1,1,1,own.alpha])

3d penguin I have a card that supports GLSL if you’re thinking of writing a shader :eyebrowlift2:… please do. .everyone/me would appreciate it thanks!!:wink:

Skullbunny thanks for the reply/help… I will try I out…okay it worked it made the object fade in… but how would I write the script to fade it out… pause… then fade it in… and have it keep looping over and over? I suppose I could use a timer somehow?? thanks again for your help