Implementation:CARLA simulator Carla Python LightManager Bindings
| Knowledge Sources | |
|---|---|
| Domains | Python Bindings, Lighting, Scene Management |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
LightManager.cpp provides Boost.Python bindings for CARLA's light management system, exposing functions to control scene lighting properties (on/off state, color, intensity, light group, and light state) from Python.
Description
This binding file wraps the carla::client::LightManager class with Python-compatible helper functions organized into functional groups:
Active State Management
- LightManagerTurnOn / LightManagerTurnOff -- Turn lights on or off, converting Python iterables to
std::vector<cc::Light>. - LightManagerSetActive -- Sets active state per light using paired lists of lights and booleans.
- LightManagerIsActive -- Returns a Python list of boolean active states, using explicit
static_cast<bool>to avoid bit_ref conversion issues.
Color Management
- LightManagerSetColor -- Sets a uniform color for all specified lights.
- LightManagerSetVectorColor -- Sets individual colors per light from paired lists.
- LightManagerGetColor -- Returns a Python list of colors for specified lights.
Intensity Management
- LightManagerSetIntensity -- Sets a uniform intensity for all specified lights.
- LightManagerSetVectorIntensity -- Sets individual intensities per light from paired lists.
- LightManagerGetIntensity -- Returns a Python list of intensity values.
Light Group Management
- LightManagerSetLightGroup -- Sets a uniform light group for all specified lights.
- LightManagerSetVectorLightGroup -- Sets individual light groups per light.
- LightManagerGetLightGroup -- Returns a Python list of light group values.
Light State Management
- LightManagerSetLightState -- Sets a uniform light state for all specified lights.
- LightManagerSetVectorLightState -- Sets individual light states per light.
- LightManagerGetLightState -- Returns a Python list of light state objects.
All helper functions follow a consistent pattern: extract Python iterables into C++ vectors using boost::python::stl_input_iterator, then delegate to the corresponding C++ LightManager method.
Usage
Access the light manager from a CARLA world instance in Python to query and modify scene lighting. The bindings support bulk operations on multiple lights simultaneously.
Code Reference
Source Location
- Repository: CARLA
- File:
PythonAPI/carla/src/LightManager.cpp(353 lines)
Signature
namespace cc = carla::client;
namespace cr = carla::rpc;
namespace csd = carla::sensor::data;
// Active state
static void LightManagerTurnOn(cc::LightManager& self, const boost::python::object& py_lights);
static void LightManagerTurnOff(cc::LightManager& self, const boost::python::object& py_lights);
static void LightManagerSetActive(cc::LightManager& self, const boost::python::object& py_lights,
const boost::python::object& py_active);
static boost::python::list LightManagerIsActive(cc::LightManager& self, const boost::python::object& py_lights);
// Color
static void LightManagerSetColor(cc::LightManager& self, const boost::python::object& py_lights,
const csd::Color color);
static void LightManagerSetVectorColor(cc::LightManager& self, const boost::python::object& py_lights,
const boost::python::object& py_colors);
static boost::python::list LightManagerGetColor(cc::LightManager& self, const boost::python::object& py_lights);
// Intensity
static void LightManagerSetIntensity(cc::LightManager& self, const boost::python::object& py_lights,
const float intensity);
static void LightManagerSetVectorIntensity(cc::LightManager& self, const boost::python::object& py_lights,
const boost::python::object& py_intensities);
static boost::python::list LightManagerGetIntensity(cc::LightManager& self, const boost::python::object& py_lights);
Import
#include <PythonAPI.h>
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| self | cc::LightManager& | Yes | The LightManager instance to operate on |
| py_lights | boost::python::object (iterable) | Yes | Python iterable of Light objects |
| color | csd::Color | No | Single color to apply uniformly |
| py_colors | boost::python::object (iterable) | No | Python iterable of Color objects for per-light assignment |
| intensity | float | No | Single intensity value to apply uniformly |
| py_active | boost::python::object (iterable) | No | Python iterable of booleans for per-light active state |
Outputs
| Name | Type | Description |
|---|---|---|
| result | boost::python::list | Python list of queried values (colors, intensities, active states, etc.) |
Usage Examples
import carla
client = carla.Client('localhost', 2000)
world = client.get_world()
light_manager = world.get_lightmanager()
# Get all street lights
lights = light_manager.get_all_lights(carla.LightGroup.Street)
# Turn all lights on
light_manager.turn_on(lights)
# Set uniform color
light_manager.set_color(lights, carla.Color(255, 200, 150))
# Set uniform intensity
light_manager.set_intensity(lights, 1000.0)
# Query active states
active_states = light_manager.is_active(lights)
Related Pages
- Environment:CARLA_simulator_Carla_Simulation_Runtime
- CARLA_simulator_Carla_PythonAPI_Header - Master header included by this file
- CARLA_simulator_Carla_LightManager_Class - C++ LightManager class being wrapped
- CARLA_simulator_Carla_Python_World_Bindings - World bindings that expose the light manager