This isn’t directly related, but I have a script/blender addon stored away on my computer that converts lights in a scene into empties containing various properties. Here’s the script:
#This is a blender addon that will convert lights into empties and visa-versa
#It will store the information about the lights in game properties, so they
#Can be used by a game engine light managing script.
#
#
# Written by sdfgeoff
# Updated: 14-02-2015
# Script Version: 2.0
import bpy
scene = bpy.context.scene
print('------------------ New Runthrough --------------------')
def create_string_property(ob, prop, value):
override = {'active_object': ob}
#bpy.ops.object.game_property_new(override, type='FLOAT', name="my_float")
bpy.ops.object.game_property_new(override, type='STRING', name=prop)
prop = ob.game.properties[prop]
prop.value = value
def create_float_property(ob, prop, value):
override = {'active_object': ob}
bpy.ops.object.game_property_new(override, type='FLOAT', name=prop)
prop = ob.game.properties[prop]
prop.value = value
def get_property_value(ob, prop):
'''Returns a properties value'''
prop = ob.game.properties[prop]
value = prop.value
return value
def create_empty(lam):
'''Creates an empty with all the properties of the lamp lam'''
#print(dir(lam.data))
#bpy.ops.object.add( type='EMPTY', location=lam.location)
#ob = bpy.context.object
name = lam.name
lam.name = 'Wastenot'
ob = bpy.data.objects.new(name, None)
ob.location = lam.location
ob.rotation_euler = lam.rotation_euler
ob.parent = lam.parent
create_string_property(ob, 'Managed Light', '')
create_string_property(ob, 'type', lam.data.type)
create_string_property(ob, 'light color', str(list(lam.data.color)))
create_float_property(ob, 'energy', lam.data.energy)
create_float_property(ob, 'distance', lam.data.distance)
create_float_property(ob, 'lin_attenuation', lam.data.linear_attenuation)
create_float_property(ob, 'quad_attenuation', lam.data.quadratic_attenuation)
if lam.data.type == 'SPOT':
create_float_property(ob, 'spotsize', lam.data.spot_size)
create_float_property(ob, 'spotblend', lam.data.spot_blend)
#xdelete_object(lam)
bpy.context.scene.objects.link(ob)
def create_lamp(emp):
'''Creates a lamp with all the properties of the empty emp'''
name = emp.name
emp.name = 'Wastenot'
data = bpy.data.lamps.new("la_" + name,get_property_value(emp, 'type'))
ob = bpy.data.objects.new(name, data)
ob.location = emp.location
ob.rotation_euler = emp.rotation_euler
ob.parent = emp.parent
ob.data.color = eval(get_property_value(emp, 'light color'))
ob.data.energy = get_property_value(emp, 'energy')
ob.data.distance = get_property_value(emp, 'distance')
ob.data.linear_attenuation = get_property_value(emp, 'lin_attenuation')
ob.data.quadratic_attenuation = get_property_value(emp, 'quad_attenuation')
if ob.data.type == 'SPOT':
ob.spot_size = get_property_value(emp, 'spotsize')
ob.spot_blend = get_property_value(emp, 'spotblend')
bpy.context.scene.objects.link(ob)
def convert_to_empties():
#print(bpy.context.selected_objects)
for ob in bpy.context.selected_objects:
if ob.type == 'LAMP':
if ob.data.type in ['SPOT', 'POINT']:
create_empty(ob)
for ob in bpy.context.selected_objects:
if ob.type == 'LAMP':
if ob.data.type in ['SPOT', 'POINT']:
ob.select = True
else:
ob.select = False
else:
ob.select = False
bpy.ops.object.delete()
def convert_to_lights():
'''Undoes convert_to_empties to allow visualization'''
for ob in bpy.context.selected_objects:
if ob.type == 'EMPTY':
if 'Managed Light' in ob.game.properties:
create_lamp(ob)
for ob in bpy.context.selected_objects:
if ob.type == 'EMPTY':
if 'Managed Light' in ob.game.properties:
ob.select = True
else:
ob.select = False
else:
ob.select = False
bpy.ops.object.delete()
class ObjectPanel(bpy.types.Panel):
bl_label = "Lighting Manager"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "render"
def draw(self, context):
self.layout.operator("lighting.convert_to_empties", text='Convert Selected To Empties')
self.layout.operator("lighting.convert_to_lights", text='Convert Selected To Lights')
class OBJECT_OT_LightingButton(bpy.types.Operator):
bl_idname = "lighting.convert_to_empties"
bl_label = "Convert Selected To Empties"
def execute(self, context):
print('Converting to Empties')
convert_to_empties()
return{'FINISHED'}
class OBJECT_OT_LightingButton(bpy.types.Operator):
bl_idname = "lighting.convert_to_lights"
bl_label = "Convert Selected To Lights"
def execute(self, context):
print('Converting to Lights')
convert_to_lights()
return{'FINISHED'}
bpy.utils.register_module(__name__)
It creates a small dialog in the world properties with some buttons on it for converting objects to/from empties and lights