import unreal from .camera import look_at def _setup(actor, component_class, intensity, color): light = actor.get_component_by_class(component_class) light.set_mobility(unreal.ComponentMobility.MOVABLE) light.set_editor_property("intensity", float(intensity)) light.set_light_color(unreal.LinearColor(*color, 1.0)) return light def area(scene, name="Light", location=(200, -200, 350), target=(0, 0, 100), intensity=12000, color=(1, 1, 1), size=180): actor = scene.spawn(unreal.RectLight, name, location) light = _setup(actor, unreal.RectLightComponent, intensity, color) light.set_editor_property("source_width", float(size)) light.set_editor_property("source_height", float(size)) light.set_editor_property("attenuation_radius", 2000.0) look_at(actor, target) return actor def point(scene, name="Point", location=(0, 0, 250), intensity=10000, color=(1, 1, 1)): """Bulb shining in all directions.""" actor = scene.spawn(unreal.PointLight, name, location) light = _setup(actor, unreal.PointLightComponent, intensity, color) light.set_editor_property("attenuation_radius", 2000.0) return actor def spot(scene, name="Spot", location=(200, -200, 400), target=(0, 0, 100), intensity=20000, color=(1, 1, 1), angle=30): """Cone of light; angle is measured in degrees from the cone axis.""" actor = scene.spawn(unreal.SpotLight, name, location) light = _setup(actor, unreal.SpotLightComponent, intensity, color) light.set_editor_property("attenuation_radius", 2000.0) light.set_editor_property("outer_cone_angle", float(angle)) light.set_editor_property("inner_cone_angle", float(angle) * 0.7) look_at(actor, target) return actor def sun(scene, name="Sun", location=(300, -300, 500), target=(0, 0, 0), intensity=500, color=(1, 1, 1)): """Parallel light for the whole scene; only the location-target direction matters.""" actor = scene.spawn(unreal.DirectionalLight, name, location) _setup(actor, unreal.DirectionalLightComponent, intensity, color) look_at(actor, target) return actor def studio(scene, key_color=(1.0, 0.82, 0.65), fill_color=(0.5, 0.7, 1.0)): return [area(scene, "Key", (200, -500, 350), color=key_color), area(scene, "Fill", (100, 300, 250), intensity=7000, color=fill_color), area(scene, "Rim", (-200, 0, 300), intensity=15000)]