Lamp Control Through Python?

Is it possible to control a lamp’s energy in a game by using a python script?
Thanks, :smiley:

Not with a specific function, but you can IPO the lamp’s energy then use an IPO actuator.

But material IPO don’t work on this version…

Well yes, but lamp IPO does.

But not in GLSL, just tested it…

According to the Python API docs, there is an “energy” property of a light object, look here, also see the example at the top:
Class KX_Light

Mmm… gonna check it up…
But the idea is to do it with IPO.

Edit: didn’t work either!

Works for me in 2.48.

Check the attached blend, just press P.

Also, when you talk about ‘not in GLSL’ do you mean enabling GLSL materials? I don’t have a supported graphics card so I can’t check that out.

Attachments

lamp_ipo.blend (141 KB)

DartGuy asked about controlling lamp energy through Python, not about IPOs specifically, and this works with the function I mentioned, I just tested.

If anybody wants to look, here’s a blend:
lightenergy.blend

AKEY activates light energy toggle.

@Sanne thank you very much

Any idea if I can control lamps colour in GLSL mode?

fobsta, you should be able to change the lamp color when you add two lines to the script in my blend file that sets the light color. It works for me also in GLSL mode. Here’s the whole changed script:

# Toggle light energy by hitting AKEY

co = GameLogic.getCurrentController() 
light = co.getOwner()
toggle = co.getSensor("toggle")

if toggle.isPositive():
	light.energy = 2.0
	light.colour = [1.0, 0.0, 0.0]
else:
	light.energy = 1.0
	light.colour = [1.0, 1.0, 1.0]

Sanne:
Ah! I saw the problem I encountered, the GLSL materials don’t support the changes on the light sources, but on objetcs without materials it will work even on GLSL mode, meaning that shadows and shaders won’t be affected/applied on those objets.

Andrew_101:
Yeah I was referring on “Blender GLSL materials” on, and inside GLSL material settings, all of them on.

You’re right, I hadn’t checked it with materials on objects in GLSL mode. I did now and they don’t react to the light changes, as you said. I wonder if this is intended? It doesn’t seem right to me, but maybe it has a sensible reason.

EDIT: Turns out that it is indeed intended or at least it is a known limitation right now. From the blender.org release logs, GLSL page:

Unlike multitexture materials, most material and light settings are currently not animateable with GLSL materials.

Didn’t know that… now I do. :slight_smile:

Thanks, I havent checked this post in a while, and there will be a lot of info to chew over. :slight_smile:

@Sanne, thanks for the code snippet. It’s reassuring for me to know that you can change the GLSL colours in real time. I was worried because changing the lamp parameters in the buttons window in a complicated scene can freeze Blender up for ten seconds or so.

If we can’t control the lamp properties via IPOs then Python is a great alternative

thank you

Ahh bugger. Your right. Fancy GLSL materials are not reacting to the changed light source :frowning: