Project 4: Clothsim


Overview

For this project, we’ve built the simulator of a cloth piece, expressed as a system of point masses and springs. Using this system, we were able to apply physical constraints on the cloth and use Verlet integration to simulate its movement over time. To decorate our cloth and primitives, we’ve worked on multiple shaders using GLSL. Additionally, we’ve implemented cloth collision with other primitives, took care of cloth’s self-collision and simulated the cloth’s behavior when the wind effect is applied. The main challenges came from properly approximating the wind effect and making sure that cloth stays above the surface of collision objects. We were able to address them through careful debugging and tweaking the small offsets for point mass positions.

Built by Raiymbek Akshulakov & Yersultan Sapar.

Part 1: Masses and springs

In this part, we’ve worked on building the grid that represents the cloth. Firstly, we’ve put together the point masses on their respective positions and then connected them using springs. We’ve added all of the springs given by 3 different type constraints and simply enable/disable them using buttons on the interface.

Part 2: Simulation via numerical integration

This part allows external forces and internal spring tensions to affect our cloth-grid. We’ve firstly computed the total force from external accelerations (gravity) and also applied spring connection forces using Hooke’s law. Afterwards, we’ve used numerical integration to compute the change of position of each point mass. Finally, we constrain spring lengths (using deformation constraint from SIGGRAPH 1995 Provot paper) to prevent their unreasonable deformation.

Part 3: Handling collisions with other objects

Here we’ve explored collisions of the cloth with two 3D primitives: sphere and plane. Both of these objects have their respective functions for rendering and collision with a single point mass. The implementation of the latter was up to us, where we’ve calculate the correction vector for the position of a single point mass from the cloth, so it would be located on the surface of the collision object after collision.

Part 4: Handling self-collisions

The self-collision occurs when a point mass on the cloth is too close to the other point masses. To fix that, we apply a modifying force to push that point mass away from the others. To quickly lookup the nearest point masses, we divide the space into discrete bounding boxes and use spatial hash map to store point masses that are in the respective bounding box.

For our hash function, we’ve used Cantor pairing function to map three coordinates that represent a position of the point mass into a single integer. After successfully building a hash map, we run through all point masses and check if each collides with ones that are in its bounding box. If that is the case, we compute the correction force that pushes the point mass away.

Part 5: Shaders

We’ve learned about shader programming using GLSL and implemented various shaders that use lighting, normals, mirror effects, textures, and height maps. While working, we usually used inputs provided by vertex shaders and performed our computation on the fragment shaders.

Part 6: Extra Credit

This was the most fun and exciting part of the project for us. We’ve implemented collision with a new cube primitive and added the wind effect simulation (with GUI controls to change wind speed and direction).

1. Cube Primitive

2. Wind Force

The website link

The website link is https://cal-cs184-student.github.io/sp22-project-webpages-yersultan-17/