A Python application for rendering 3D scenes with Mitsuba 3, focusing on batch processing of OBJ files and creating animations.
- Render sequences of OBJ files with Mitsuba 3
- Create videos and GIFs from rendered frames
- Support for both CPU and CUDA GPU rendering
- Configurable rendering parameters (resolution, samples per pixel)
- Multi-threaded rendering for improved performance
- Detailed timing reports and performance statistics
- Python 3.8 or higher
- Mitsuba 3
- FFmpeg (for video and GIF creation)
-
Clone this repository:
git clone https://github.com/ETSim/MistubaVideo cd mitsuba -
Install dependencies:
pip install -r requirements.txt
Render multiple OBJ files from a folder:
python main.py multi --folder exports --regex "\d+\.obj"Options:
-f, --folder TEXT Folder containing OBJ files [required]
-r, --regex TEXT Regex pattern for OBJ filenames [default: \d+\.obj]
-n, --name TEXT Base name for output files [default: multi_obj]
-t, --threaded Enable multi-threading
-w, --workers INTEGER Max worker threads (if threaded)
--video / --no-video Enable video creation [default: video]
--gif / --no-gif Enable GIF creation [default: gif]
-d, --device TEXT Rendering device (cpu/cuda) [default: cpu]
-s, --spp INTEGER Samples per pixel [default: 256]
--width INTEGER Output image width [default: 1920]
--height INTEGER Output image height [default: 1080]
-o, --output TEXT Output directory [default: output]
--max-depth INTEGER Maximum ray bounces [default: 8]
Show information about the Mitsuba configuration:
python main.py infoThe application can be configured through a config.json file:
{
"OUTPUT_FOLDER": "output",
"EXR_FOLDER": "exr",
"PNG_FOLDER": "png",
"VIDEO_FOLDER": "video",
"GIF_FOLDER": "gif",
"SCENE_FOLDER": "scenes",
"MESH_FOLDER": "meshes",
"FRAMERATE": 30,
"MULTI_THREADED": false,
"ENABLE_GIF": true,
"ENABLE_VIDEO": true,
"ENABLE_EXR": true,
"ENABLE_PNG": true
}mitsuba/
βββ main.py # Main CLI entry point
βββ config.json # Application configuration
βββ src/
β βββ assets/ # Static assets (scenes, schemas)
β βββ env/ # Environment map handling
β βββ processing/ # Processing utilities
β β βββ ffmpeg.py # FFmpeg video processing
β β βββ image.py # Image conversion
β β βββ meshes.py # Mesh file handling
β β βββ scene.py # Scene XML generation
β β βββ xml.py # XML processing
β βββ renderers/ # Renderer implementations
β β βββ base.py # Base renderer class
β β βββ multi.py # Multi-object renderer
β βββ utils/ # Utility modules
β βββ config.py # Configuration handling
β βββ constants.py # Application constants
β βββ environment.py # Environment setup
β βββ folder.py # Folder operations
β βββ logger.py # Logging utilities
β βββ mitsuba.py # Mitsuba interface
β βββ timing.py # Performance timing
β βββ zip.py # ZIP file handling
βββ tests/ # Unit tests
A Dockerfile and docker-compose.yml are provided for containerized execution:
# Build the container
docker-compose build
# Run the application
docker-compose run mitsuba python main.py multi --folder /data/exportsThis guide explains how to render objects from multiple camera angles using the Mitsuba renderer.
The following camera views are available:
front- View from the front (positive Z axis)back- View from the back (negative Z axis)left- View from the left side (negative X axis)right- View from the right side (positive X axis)top- View from above (positive Y axis)bottom- View from below (negative Y axis)perspective- Default 3/4 perspective view (from a corner)
To render with specific camera views, use the --view option (can be specified multiple times):
python main.py multi --folder models --view front --view top --view rightTo render all standard camera views in one command:
python main.py multi --folder models --all-viewsTo generate orthographic views for technical documentation:
python main.py multi --folder models --view front --view top --view right --view leftTo create a complete 360Β° visualization:
python main.py multi --folder models --all-viewsThe default camera distance is 4.0 units. You can adjust this in the code by modifying the CameraUtils.get_camera_transform function.
You can also use the camera view functionality in your Python code:
from src.mitsuba.camera import CameraUtils
# Get a camera transform for a specific view
transform = CameraUtils.get_camera_transform("front", distance=5.0)
# Format the transform for XML
xml_transform = CameraUtils.format_transform_for_xml(transform)For each camera view, the renderer will create separate output files with the view name in the filename. For example:
multi_obj_frame_0_front.pngmulti_obj_frame_0_top.pngmulti_obj_frame_0_right.png