A powerful Python-based 3D model viewer with interactive controls, texture support, custom shaders, and multiple view modes for seamless 3D model visualization.
- ๐ฏ OBJ File Support - Load and display standard .obj 3D models
- ๐จ Texture Mapping - Full texture support with material files (.mtl)
- ๐ฑ๏ธ Interactive Controls - Rotate, pan, and zoom with mouse
- ๐ญ Custom Shaders - Vertex and fragment shader support
- ๐ Multiple View Modes - Switch between different rendering modes
- ๐ Vertex/Edge Display - Toggle vertex and edge visualization
- ๐จ Material Support - Load and apply materials from .mtl files
- โก Real-time Rendering - Smooth, responsive 3D visualization
- ๐ Model Manipulation - Real-time rotation, scaling, and positioning
- Python 3.8 or higher
- OpenGL-compatible graphics card
# Clone the repository
git clone https://github.com/widgetwalker/3d-viewer.git
cd 3d-viewer
# Install dependencies
pip install pygame numpypython main.py| Control | Action |
|---|---|
| Left Mouse Button | Rotate model |
| Right Mouse Button | Pan camera |
| Mouse Wheel | Zoom in/out |
| Space | Toggle view modes |
| C | Change background color |
| V | Toggle vertex display |
| E | Toggle edge display |
| ESC | Exit viewer |
3d-viewer/
โโโ main.py # Main application entry point
โโโ model_loader.py # OBJ/MTL file parser
โโโ model_camera.py.py # Camera and view controls
โโโ shader.py # Shader implementation
โโโ shadersvertex.glsl.txt # Vertex shader code
โโโ shadersfragment.glsl.txt # Fragment shader code
โโโ airplane.obj # Sample 3D model
โโโ lll.obj # Sample 3D model
โโโ models.obj.txt # Model metadata
โโโ README.md # This file
- .obj - Wavefront OBJ files (vertices, faces, normals, UVs)
- .mtl - Material definition files
- PNG, JPG, BMP, TGA (any format supported by Pygame)
Edit the shader files to customize rendering:
Vertex Shader (shadersvertex.glsl.txt):
// Customize vertex transformationsFragment Shader (shadersfragment.glsl.txt):
// Customize pixel colors and lightingModify in main.py:
# Background colors
background_color = (0.1, 0.1, 0.1)
# Edge colors
edge_color = (1.0, 1.0, 1.0)
# Vertex colors
vertex_color = (1.0, 0.0, 0.0)- Place your
.objfile in the project directory - If you have textures, place the
.mtlfile alongside - Ensure texture image files are in the correct path
- Run the viewer - it will auto-detect available models
mymodel.obj # 3D geometry
mymodel.mtl # Materials
texture.png # Texture image
OBJ File โ Parser โ Vertex Data โ GPU Buffer โ Renderer
โ
MTL File โ Material Data โ Texture Loader
Input Events โ Camera Update โ Shader Compilation โ
Vertex Processing โ Fragment Processing โ Display
# Check file format
# Ensure .obj file is valid
# Verify file path is correct- Check
.mtlfile texture paths - Ensure texture files exist
- Verify texture format is supported
- Reduce polygon count of model
- Disable vertex/edge display
- Lower screen resolution
# Check shader syntax
# Verify GLSL version compatibility
# Review error messages in console- Orbit Mode - Rotate around model center
- Pan Mode - Move camera position
- Zoom Mode - Adjust camera distance
- Solid - Standard filled polygons
- Wireframe - Edge-only display
- Vertex - Point cloud visualization
- Textured - Full material rendering
Contributions are welcome! Here's how:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Pygame Community - For the excellent game development framework
- OpenGL Community - For graphics programming resources
- Wavefront OBJ Format - For the standard 3D model format
- Repository: github.com/widgetwalker/3d-viewer
- Issues: Report a bug
- Author: @widgetwalker
Dheeraj Pilli
- GitHub: @widgetwalker
- Email: dheeraj5765483@gmail.com
โญ Star this repo if you find it helpful!
Built with โค๏ธ using Python, Pygame, and OpenGL
