Skip to content

A spring-model cloth physics simulator made using C/C++ and rendered in OpenGL

License

Notifications You must be signed in to change notification settings

ranaxdev/Cloth-Sim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Logo

Cloth-Simulator

A spring-model cloth physics simulator made using C/C++

Report Bug


Preview

demo.mp4

As of 30/12/2021, Cloth-Sim features a cloth mesh importer (in the form of a WaveFront obj file), a cloth mesh exporter, a cloth-sphere and cloth-plane collision simulation with options to apply forces such as angular velocity and a cloth free-fall simulation with options to apply forces such as wind direction

Future Releases

Features that I would like to work towards implementing

  • Adding textures/lighting and face triangulation
  • Improving the spring-model
  • Increasing performance (less load with more springs)
  • More simulation scenarios

Feel free to suggest some in the issues tab!

How

To create a cloth mesh, you simply need an easy WaveFront obj editor so that you can import the obj file. The simplest way is to just create a plane in blender and add equal number of cut loops on both the horizontal and vertical. Export as quads.

Cloth Mesh

The program uses the mass-spring-damper model to model the cloth. In this case, each vertex in the mesh would be considered a mass (particle with a fixed weight). After loading in the cloth mesh, springs are created using adjacent and diagonal connections between the particles as shown in the following diagram.

Spring Model

Then to simulate the cloth, you apply the spring force and gravity to all of the created springs (and additional ones depending on the simulation such as friction or wind)

Force

The parameters that worked for me were

mass = 0.5
ks = 10
kd = 5
g = -0.981

Installation

Linux

Dependencies include OpenGL 4.50, libdl, glfw3, pthread, glm

git clone https://github.com/ranaxdev/Masters/
cd Animation_Simulation/Cloth-Sim
mkdir Release
cd Release
cmake -DCMAKE_BUILD_TYPE=Release ../
make

Windows

I'm currently working on releasing an executable so that you don't have to use cmake to build it on windows

Libraries Used

  • GLAD : OpenGL Loading Library

  • GLM : OpenGL Mathematics

  • GLFW : A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input

  • Dear ImGui : Bloat-free Graphical User interface for C++ with minimal dependencies

License

Distributed under the Apache 2.0 License. See LICENSE for more information.

Contact

S.R. Qaiser - @pitu_dev - sc21srq@leeds.ac.uk

Project Link: https://github.com/ranaxdev/Cloth-Sim

Releases

No releases published

Packages

No packages published

Languages