Skip to content

widgetwalker/3d-viewer

Repository files navigation

๐ŸŽฎ 3D OBJ Viewer

Python Pygame NumPy OpenGL License

A powerful Python-based 3D model viewer with interactive controls, texture support, custom shaders, and multiple view modes for seamless 3D model visualization.

3D Viewer Screenshot


โœจ Features

  • ๐ŸŽฏ 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

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • OpenGL-compatible graphics card

Installation

# Clone the repository
git clone https://github.com/widgetwalker/3d-viewer.git
cd 3d-viewer

# Install dependencies
pip install pygame numpy

Run the Viewer

python main.py

๐ŸŽฎ Controls

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

๐Ÿ“‚ Project Structure

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

๐Ÿ“ฆ Supported File Formats

3D Models

  • .obj - Wavefront OBJ files (vertices, faces, normals, UVs)
  • .mtl - Material definition files

Textures

  • PNG, JPG, BMP, TGA (any format supported by Pygame)

๐ŸŽจ Customization

Modify Shaders

Edit the shader files to customize rendering:

Vertex Shader (shadersvertex.glsl.txt):

// Customize vertex transformations

Fragment Shader (shadersfragment.glsl.txt):

// Customize pixel colors and lighting

Change Display Settings

Modify 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)

๐Ÿ”ง Loading Custom Models

  1. Place your .obj file in the project directory
  2. If you have textures, place the .mtl file alongside
  3. Ensure texture image files are in the correct path
  4. Run the viewer - it will auto-detect available models

Example OBJ File Structure

mymodel.obj          # 3D geometry
mymodel.mtl          # Materials
texture.png          # Texture image

๐Ÿ—๏ธ Architecture

Model Loading Pipeline

OBJ File โ†’ Parser โ†’ Vertex Data โ†’ GPU Buffer โ†’ Renderer
                โ†“
            MTL File โ†’ Material Data โ†’ Texture Loader

Rendering Pipeline

Input Events โ†’ Camera Update โ†’ Shader Compilation โ†’ 
Vertex Processing โ†’ Fragment Processing โ†’ Display

๐Ÿ› Troubleshooting

Model Not Loading

# Check file format
# Ensure .obj file is valid
# Verify file path is correct

Textures Not Showing

  • Check .mtl file texture paths
  • Ensure texture files exist
  • Verify texture format is supported

Performance Issues

  • Reduce polygon count of model
  • Disable vertex/edge display
  • Lower screen resolution

Shader Errors

# Check shader syntax
# Verify GLSL version compatibility
# Review error messages in console

๐Ÿ’ก Advanced Features

Camera System

  • Orbit Mode - Rotate around model center
  • Pan Mode - Move camera position
  • Zoom Mode - Adjust camera distance

Rendering Modes

  • Solid - Standard filled polygons
  • Wireframe - Edge-only display
  • Vertex - Point cloud visualization
  • Textured - Full material rendering

๐Ÿค Contributing

Contributions are welcome! Here's how:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • Pygame Community - For the excellent game development framework
  • OpenGL Community - For graphics programming resources
  • Wavefront OBJ Format - For the standard 3D model format

๐Ÿ”— Links


๐Ÿ“ง Contact

Dheeraj Pilli


โญ Star this repo if you find it helpful!

Built with โค๏ธ using Python, Pygame, and OpenGL

About

"A Python-based 3D OBJ viewer with interactive controls, texture support, and custom shaders. Features real-time model manipulation, material support, and multiple view modes for seamless 3D model visualization."

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages