A real-time 3D renderer for the terminal that displays OBJ files using ASCII characters. Built with Rust for performance and cross-platform compatibility.
- Real-time 3D rendering in the terminal using ASCII characters
- OBJ file support with automatic model centering and normalization
- Interactive controls for rotation and scaling
- Lighting system with brightness-based ASCII shading
- Perspective projection with configurable camera
- Back-face culling for performance optimization
- Rust (1.70 or later)
- Cargo package manager
git clone <repository-url>
cd console_renderer
cargo build --release
Run the renderer with an OBJ file:
cargo run -- -f <path-to-obj-file>
The project includes sample models in the resources/
directory:
# Simple cube
cargo run -- -f resources/cube.obj
# Pyramid shapes
cargo run -- -f resources/pyramids.obj
# Complex model
cargo run -- -f resources/Rafale.obj
Key | Action |
---|---|
a |
Rotate counterclockwise around Z-axis |
e |
Rotate clockwise around Z-axis |
q |
Rotate clockwise around Y-axis |
d |
Rotate counterclockwise around Y-axis |
r |
Rotate clockwise around X-axis |
f |
Rotate counterclockwise around X-axis |
z |
Scale up |
s |
Scale down |
Esc |
Exit application |
- Model Loading: OBJ files are parsed and vertices are extracted
- Normalization: Models are centered and scaled to fit the viewport
- Triangle Generation: Vertices are grouped into triangles with normal calculation
- Culling: Back-facing triangles are removed for performance
- Projection: 3D coordinates are projected to 2D screen space
- Lighting: Brightness is calculated using the dot product of surface normals and light direction
- Rasterization: ASCII characters are selected based on brightness levels
The renderer uses 6 brightness levels to create depth perception:
@
- Brightest (230-255)#
- Very bright (200-229)*
- Bright (160-199)+
- Medium (120-159)-
- Dim (80-119).
- Darkest (0-79)
- clap - Command-line argument parsing
- console_engine - Terminal rendering and input handling
- crossterm - Cross-platform terminal manipulation
- nalgebra - Linear algebra operations for 3D math
The codebase is organized into several key modules:
main.rs
- Application loop and rendering logicloader.rs
- OBJ file parserstructures/
- Core 3D mathematicstriangle.rs
- Triangle primitive with transformationscamera.rs
- Perspective projection cameralight.rs
- Point light sourcerotation_matrix.rs
- Pre-computed rotation matrices
The renderer is optimized for real-time performance:
- Back-face culling reduces triangle count
- Pre-computed rotation matrices
- Efficient triangle rasterization
- Runs at approximately 30 FPS on modern hardware
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
cargo test
- Submit a pull request
This project is open source. See the LICENSE file for details.
Created by AlexVplle
- Built with the Rust programming language
- Uses nalgebra for linear algebra operations
- Terminal rendering powered by console_engine