CS184 Final Project Report
description
Transcript of CS184 Final Project Report
Simulating the Physical Effects of External Forces on Cloth Juan de Joya (cs184-‐ax)
CS184 Fall 2011 Final Project
Figure 1: The simulated cloth piece colliding with the sphere: the first three images show different patterned cloth materials, and the fourth image shows the demo’s wireframe mode. 1 Introduction Robust physics remains a popular topic in the field of computer graphics. The real-‐time and offline demands of film, gaming, and research necessitate more realistic representation of computer-‐generated simulations, and as such further studies in the field are no less relevant than they were in the last few decades. Building on previous research and development, it is now possible to create isolated realistic physical simulation without investing in a full-‐fledged physics engine. In my report I present the techniques behind the implementation of my cloth simulator, the goal of which is to showcase the physics of wind and gravity on the simulated cloth as well as collision detection when said cloth interacts with the sphere. 2 Background Soft body dynamics is the study and development of techniques to simulate visually realistic physical motion and properties of deformable objects (or soft bodies). Unlike rigid bodies, soft bodies have a malleable shape when subject to physical effects. While this means that the relative distance of any two points that comprise a given soft body are not fixed, the body is expected to relatively maintain its shape. Cloth simulation in the context of computer graphics is the simulation of two-‐dimensional soft bodies that serve as a representation of cloth in the 3D space. A common method of simulating cloth is to represent the material as a grid of particles connected to each other by springs. The mass-‐spring model determines the spring forces acting on the particles at each time step, in combination with gravity and other effective forces. Collision detection is an important prerequisite in creating a realistic cloth simulation; the detection algorithm between cloth and most objects is relatively straightforward given an object with a well-‐defined shape. 3 Implementation In the mass-‐spring model, a continuous cloth surface is discretized into a finite number of particles for drawing; the particles are then connected in an orderly fashion with springs. Each particle in the grid contains the data necessary to calculate its motion. We can then find the new positions and velocities of cloth particles using Newton’s Second Law and a numerical integration method.
Newton’s Second Law states that the acceleration 𝑎 of an object is directly proportional to the net force 𝐹 and indirectly proportional to the mass 𝑚, 𝑎 = !
!. Using this we can solve the
differential equations of 𝑎 to find velocity 𝑣 and position 𝑝 of a particle. Since 𝑎 = !!!" and
𝑣 = !!!", we can integrate the acceleration to find the new velocity of a given particle, which
in turn we can integrate to find its [the particle’s] new position. There are several numerical integration methods that can be used; for future implementation (see Limitations and Conclusion and Future Work, below), Verlet Integration offers greater stability and accuracy with no computational cost in comparison to the Euler method. For the purposes of this cloth simulation however, we will use a modified Euler Integration.
Figure 2: Cloth simulation using basic Euler Integration results in severe calculation errors over time. Within seconds of running, earlier builds of my cloth simulation exhibited gross inaccuracies leading to the final picture shown above. Euler Integration on its own leads to very inaccurate results; there will always be an integration error that accumulates over time. In response, there are two modifications in my code that help mitigate error accumulation. First, oversampling to decrease the time step to 𝑑𝑡 = !
!""𝑡ℎ of a second each Euler integration will lead to results much closer to the
ideal solution. More importantly, damping, which is the proportional velocity lost, is factored into the calculation of velocity at each time step. In this simulation, damping is introduced to tweak the look of the cloth material and make the simulation stable. A high damping factor makes the cloth material more rigid, while a low damping factor results in a lightweight cloth material.
Default
Damping: 0.6 Time: 16.0 seconds
Slightly Lighter Damping: 0.55
Time: 12.0 seconds
Slightly Rigid Damping: 0.7
Time: 22 seconds
More Rigid Damping: 0.9
Time: 34 Seconds Table 1: The following cloth materials available in the cloth simulator, listed with their respective damping factors and the time it took for them to reach the rest position shown above.
Because the mass-‐spring system of my cloth simulator is implemented as a particle system, each particle is connected to 24 neighboring particles; these interconnections represent the “stretch”, “bend”, and “shear” springs. The “stretch” and “bend” springs prevent the cloth from stretching too much and folding in on itself respectively, while the “shear” springs allow the cloth to resist shearing movement by maintaining the diagonal shape of the cloth. For my cloth body, I have generated a 7x7 rectangular cloth piece made out of 50x50 particles, resulting in 60000 spring connections. Two triangles are produced for every four particles forming a grid square.
Figure 3: The cloth simulator’s wireframe mode. When rendering this surface, the masses and springs are not typically drawn; instead they are used to generate triangle vertices. The nature of cloth simulation is essentially a constraint-‐solving problem. It involves solving for the positions of the particles in the grid at each frame of the simulation, where the positions are affected by the springs keeping the particles together as well as external forces acting on the particles. In my cloth simulator, I implemented my cloth patch to react to the external forces of gravity, wind, and collision with the sphere. When releasing the cloth from its inert state, gravity naturally pulls downward on the particles. Wind forces can be applied to push the cloth towards any direction in the 3D space; given enough wind pushing upwards (in the +y direction in 3D space), the cloth patch will float and defy the initial gravity forces pulling it downward. Both wind and gravity are altered and added to the net force (accumulatedForce in the source code) affecting the particle, which will then be used to offset the new positions and velocities. Implementing collision detection between the cloth patch and the sphere is easy considering that the method is not dissimilar from the circle-‐ray intersection methods for ray tracing. Our sphere is defined by a center and radius; as such, we can detect collision by asking whether a particle is inside the radius of the sphere. If it is, the simulation resolves the collision by moving the particle outside of the sphere along the vector from the center to the particle; the resulting position of the particle will be the distance equal to the radius of the sphere. To provide user interactivity with the simulation, I implemented a basic user interface that informs the user of the features that allow them to manipulate the external forces affecting the cloth, and the type of cloth being used in the simulation. Several other features include switching between shaded and wireframe mode, switching between window sizes, rotation and zooming, and the ability to pause or un-‐pause the animation.
Figure 4: This image shows the basic user interface available with the program. 4 Results The keyboard functions listed in the simulation’s user interface can be directly used to generate the physical effects of wind and gravity. Available at the end of this report are pictures showcasing my results. The source code, additional photos, and a supplementary video are included in the attached CD. 5 Limitations Although my project showcases the appropriate realistic dynamic behavior, I would like to use a different numerical integration method when I do future cloth simulations. While the modified Euler Integration used in the project does its job, it would be better to use more accurate methods for more complicated simulations. The damping factor works well in differentiating the type of cloth and mitigating errors, but a damping factor less than 0.5 leads to marginally diminishing accuracy; at a damping factor of 0.2, for example, the particles near the edge of the grid continue to jump around even when the cloth is at rest. That being said, the method I initially used for this project was Verlet Integration; unfortunately, I discovered bugs in my implementation that would require adjusting the entire source code. Given the time constraints of working alone, I opted to use a modified Euler Integration that, while not ideal for complicated simulations, works appropriately for the scope of this project. 6 Conclusion and Future Work I have written above the implementation techniques I used to create a cloth simulation with a focus on reproducing realistic physical effects generated by wind, gravity, and collision. The results of the simulation produce striking imagery and animations showcasing the effects of these external forces when enacted on the cloth patch. Working on the project on my own, while challenging, was immeasurably gratifying. Having received an underprivileged education, I have always felt intimidated by the level of competency of the rest of my peers in the class. Being able to do this project on my own and successfully opened my eyes to how far I’ve gotten since at the beginning of this course. When I saw my cloth patch realistically react to the wind and gravity I realized how much I
enjoyed what I have been doing in this class, and I want to continue pursuing other projects that stimulate me on the same level as this experience has. Looking into the future, I’m looking forward to further improving my cloth simulation by solving existing technical limitations. I am interested in implementing a more accurate integration method as well as more complicated physical effects such as cloth tearing, multiple collisions with other types of objects, and self-‐intersection collision detection. References Baraff, D., and Witkin, A. 1998. Large Steps in Cloth Simulation. Computer Graphics Proceedings, Annual Conference Series, SIGGRAPH 98, 43-‐54. Lander, J. 1999. Devil in the Blue Faceted Dress: Real-‐time Cloth Animation. Game Developer Magazine, 17-‐22. http://www.darwin3d.com/gamedev/articles/col0599.pdf Lee, S. 2008. Real-‐Time Cloth Simulation. CG: Skeelogy, Skeel’s CG, Games & Tech Portfolio. http://cg.skeelogy.com/real-‐time-‐cloth-‐simulation/ Mosegaard, J. 2009. Mosegaards Cloth Simulation Coding Tutorial. Computer Graphics Lab at the Alexandra Institute. http://cg.alexandra.dk/2009/06/02/mosegaards-‐cloth-‐simulation-‐coding-‐tutorial/ Rotenberg, S. 2005. Cloth Simulation. CSE 169: Computer Animation, UCSD Winter 2005. graphics.ucsd.edu/courses/cse169_w05/CSE169_16.ppt
Figure 5-‐7: More results from the final project. Please note the realistic cloth folds and
wrinkles exhibit as a result of wind and collision effects.