An open API service indexing awesome lists of open source software.

https://github.com/m3str3/rust3d

An interactive 3D viewer written in Rust, for .obj models.
https://github.com/m3str3/rust3d

geometry rust

Last synced: 8 days ago
JSON representation

An interactive 3D viewer written in Rust, for .obj models.

Awesome Lists containing this project

README

          

# Rust3D

A basic 3D viewer written in Rust for rotating, zooming, and loading `.obj` files.

## Features

- Rotate the 3D model.
- Zoom in and out.
- Load `.obj` files dynamically.

## Controls

| **Key/Mouse** | **Action** |
|------------------------|-------------------------|
| **Left Click + Drag** | Rotate the model |
| **Space** | Toggle auto-rotation |
| **B** | Change background color |
| **M** | Change object color |
| **Up / +** | Zoom in |
| **Down / -** | Zoom out |
| **L** | Load a new `.obj` file |
| **Escape** | Exit the program |

## How It Works
https://github.com/user-attachments/assets/ac892f1e-226b-4b58-ac04-caeccd5660a2
### Rotation Matrices
The 3D point \((x, y, z)\) is rotated using standard rotation matrices:

- **X-axis Rotation**:
```math
\begin{cases}
x' = x \
y' = y \cos\theta - z \sin\theta \
z' = y \sin\theta + z \cos\theta
\end{cases}
```

- **Perspective Projection**:
```math
\begin{cases}
u = x \cdot \frac{\text{scale}}{z + \text{distance}} + \frac{\text{screen\_width}}{2} \
v = -y \cdot \frac{\text{scale}}{z + \text{distance}} + \frac{\text{screen\_height}}{2}
\end{cases}
```