A sophisticated Python-based cloth simulation system featuring the OGC (Offset Geometric Contact) Model with advanced OpenGL visualization and real-time contact force analysis.
- OGC Contact Model: State-of-the-art offset geometric contact algorithm for precise collision handling
- Verlet Integration: Numerically stable particle-based cloth simulation
- Multi-layer Constraints: Structural, diagonal, and bending constraints for realistic cloth behavior
- Real-time Collision Detection: Efficient collision detection with cylinders, spheres, and planes
- ModernGL Rendering: High-performance OpenGL 3.3+ rendering pipeline
- Interactive 3D Camera: Orbit controls with smooth mouse and keyboard navigation
- Contact Force Visualization: Real-time display of contact points, normals, and force vectors
- Multiple Render Modes: Wireframe, solid, particle, and hybrid visualization modes
- PyCharm Integration: Optimized project structure for PyCharm IDE
- Configuration Management: JSON-based configuration with validation and presets
- Performance Profiling: Built-in performance monitoring and statistics
- Export Capabilities: Export simulation data and meshes in various formats
- Python 3.8+
- PyCharm IDE (recommended)
- OpenGL 3.3+ compatible graphics card
-
Clone the repository
git clone https://github.com/chchlin1018/Python-OGC-Cloth-Test2.git cd Python-OGC-Cloth-Test2 -
Install dependencies
pip install -r requirements.txt
-
Run the simulation
python main.py
- Open PyCharm and select "Open Project"
- Navigate to the
Python-OGC-Cloth-Test2directory - PyCharm will automatically detect the project configuration
- Run the simulation using the pre-configured run configuration "Main Simulation"
# Run with default settings
python main.py
# Run with custom configuration
python main.py configs/high_quality.json
# Run with a preset
python main.py --preset high_quality
# Create a default configuration file
python main.py --create-config my_config.json| Control | Action |
|---|---|
| Mouse Drag | Orbit camera around scene |
| Mouse Wheel | Zoom in/out |
| W | Toggle wireframe mode |
| P | Toggle particle display |
| C | Toggle contact point display |
| F | Toggle force vector display |
| Space | Pause/Resume simulation |
| R | Reset simulation |
| ESC | Exit application |
| Preset | Description | Use Case |
|---|---|---|
default |
Balanced settings | General use |
high_quality |
High resolution, detailed simulation | Research and analysis |
performance |
Optimized for speed | Real-time applications |
windy |
Strong wind effects | Environmental simulation |
bouncy |
High restitution settings | Interactive demonstrations |
Python-OGC-Cloth-Test2/
βββ π src/ # Source code
β βββ π physics/ # Physics simulation
β β βββ ogc_contact_model.py # OGC contact algorithm
β β βββ cloth_simulation.py # Cloth physics core
β β βββ __init__.py
β βββ π rendering/ # OpenGL rendering
β β βββ opengl_renderer.py # Main renderer
β β βββ __init__.py
β βββ π visualization/ # Contact visualization
β β βββ contact_visualizer.py # Force visualization
β β βββ __init__.py
β βββ π utils/ # Utilities
β β βββ config_manager.py # Configuration management
β β βββ profiler.py # Performance profiling
β β βββ math_utils.py # Mathematical utilities
β β βββ __init__.py
β βββ simulation_app.py # Main application
βββ π .idea/ # PyCharm configuration
βββ π configs/ # Configuration files
βββ π docs/ # Documentation
βββ π tests/ # Unit tests
βββ π examples/ # Example scripts
βββ π§ requirements.txt # Python dependencies
βββ π main.py # Main entry point
βββ π README.md # This file
βββ π LICENSE # MIT License
The Offset Geometric Contact (OGC) Model is a state-of-the-art contact handling algorithm that provides:
- Sub-millimeter Precision: Accurate contact detection and resolution
- Guaranteed Non-penetration: Mathematically proven collision-free simulation
- Orthogonal Contact Forces: Physically accurate force computation
- Offset Surface Geometry: Advanced geometric representation for contact
- Contact Detection: Efficient spatial hashing and broad-phase collision detection
- Force Calculation: OGC-specific force computation with proper orthogonality
- Constraint Solving: Iterative constraint satisfaction with convergence guarantees
- Stability Analysis: Built-in numerical stability monitoring
- Cloth Resolution: Up to 50Γ50 particles at 60 FPS
- Contact Points: 500+ simultaneous contacts
- Memory Usage: < 200MB for typical scenes
- Startup Time: < 2 seconds
- Spatial Partitioning: Efficient collision detection using spatial hashing
- Adaptive Time Stepping: Dynamic time step adjustment for stability
- Multi-threading: Parallel constraint solving (where applicable)
- Memory Pooling: Efficient memory management for contact objects
# Run all tests
python -m pytest tests/
# Run specific test category
python -m pytest tests/test_physics.py
python -m pytest tests/test_rendering.py# Run integration tests
python -m pytest tests/integration/
# Performance benchmarks
python tests/benchmark_simulation.py{
"cloth_width": 20,
"cloth_height": 20,
"rest_length": 0.1,
"particle_mass": 1.0,
"gravity": [0.0, -9.81, 0.0],
"contact_radius": 0.05,
"contact_stiffness": 1000.0,
"window_width": 1200,
"window_height": 800
}{
"ogc_parameters": {
"offset_distance": 0.02,
"contact_damping": 10.0,
"friction_coefficient": 0.3,
"restitution": 0.1
},
"visualization": {
"show_contacts": true,
"show_forces": true,
"force_scale": 0.1,
"contact_point_size": 0.03
}
}-
Clone and setup
git clone https://github.com/chchlin1018/Python-OGC-Cloth-Test2.git cd Python-OGC-Cloth-Test2 pip install -r requirements.txt pip install -r requirements-dev.txt # Development dependencies
-
Code formatting
black src/ isort src/
-
Type checking
mypy src/
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Physics Module - Cloth simulation and OGC contact model
- Rendering Module - OpenGL rendering and visualization
- Configuration Guide - Detailed configuration options
- Performance Guide - Optimization tips and benchmarks
OpenGL Context Creation Failed
# Install OpenGL libraries (Ubuntu/Debian)
sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev
# macOS - Install XQuartz
brew install --cask xquartzModernGL Import Error
# Reinstall ModernGL
pip uninstall moderngl
pip install modernglPerformance Issues
- Reduce cloth resolution in configuration
- Disable force visualization for better performance
- Use the "performance" preset
# Run with debug information
python main.py --debug --verboseThis project is licensed under the MIT License - see the LICENSE file for details.
- OGC Research Team - For the original OGC contact model research
- ModernGL Community - For the excellent OpenGL Python bindings
- NumPy/SciPy Teams - For fundamental scientific computing tools
- PyCharm Team - For the outstanding Python IDE
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: [email protected]
Made with β€οΈ for the computational physics community