Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla Apply Texture Tool

From Leeroopedia
Knowledge Sources
Domains Simulation, Texturing, Utility
Last Updated 2026-02-15 05:00 GMT

Overview

Command-line utility script that applies custom textures (diffuse, normal, AO/roughness/metallic/emissive) to objects in a running CARLA simulation.

Description

This script (apply_texture.py) enables runtime texture modification of scene objects in the CARLA simulator. It provides two helper functions: get_8bit_texture() converts image data into a carla.TextureColor object (8-bit RGBA), and get_float_texture() converts image data into a carla.TextureFloatColor object (normalized float RGBA with 5x brightness scaling). The script uses the imageio library to read texture image files and applies them via world.apply_textures_to_object(). It supports listing objects in the scene (filtered for 'Apartment' objects), applying diffuse textures, normal maps, and AO/roughness/metallic/emissive maps. Command-line arguments include --host, -p/--port, -l/--list, -d/--diffuse, -o/--object-name, -n/--normal, and --ao_roughness_metallic_emissive.

Usage

Use this tool to customize the visual appearance of simulation objects at runtime, such as changing building facades, road textures, or vehicle skins without modifying the map assets.

Code Reference

Source Location

  • Repository: CARLA
  • File: PythonAPI/util/apply_texture.py

Signature

def get_8bit_texture(image):
    """Convert image array to carla.TextureColor (8-bit RGBA)."""

def get_float_texture(image):
    """Convert image array to carla.TextureFloatColor (float RGBA)."""

def main():
    """Parse args and apply textures to named object."""

Import

# Run as a command-line tool:
python apply_texture.py --host 127.0.0.1 -p 2000 -o "ObjectName" -d diffuse.png -n normal.png

I/O Contract

Argument Type Default Description
--host str 127.0.0.1 CARLA server IP address
-p, --port int 2000 CARLA server TCP port
-l, --list flag False List all objects containing 'Apartment' in name
-d, --diffuse str Path to diffuse texture image
-o, --object-name str required Name of the object to apply textures to
-n, --normal str Path to normal map image
--ao_roughness_metallic_emissive str Path to AO/roughness/metallic/emissive map

Usage Examples

# List available objects
python apply_texture.py -l

# Apply a diffuse texture to an object
python apply_texture.py -o "Apartment_01" -d /path/to/diffuse.png

# Apply all texture maps
python apply_texture.py -o "Apartment_01" \
    -d /path/to/diffuse.png \
    -n /path/to/normal.png \
    --ao_roughness_metallic_emissive /path/to/ao_r_m_e.png

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment