Cloth SimulationCSE169: Computer AnimationInstructor: Steve RotenbergUCSD, Winter 2008Cloth Simulation Cloth simulation has been an important topic in computer animation since the early 1980’s It has been extensively researched, and has reached a point where it is *basically* a solved problem Today, we will look at a very basic method of cloth simulation. It is relatively easy to implement and can achieve good results. It will also serve as an introduction to some more advanced cloth simulation topics.Cloth Simulation with Springs We will treat the cloth as a system of particles interconnected with spring-dampers Each spring-damper connects two particles, and generates a force based on their positions and velocities Each particle is also influenced by the force of gravity With those three simple forces (gravity, spring, & damping), we form the foundation of the cloth system Then, we can add some fancier forces such as aerodynamics, bending resistance, and collisions, plus additional features such as plastic deformation and tearingCloth Simulation••••••••••ParticleSpring-damperParticle•fam1=vr∑=iffforcemomentummassmonaccelerativelocityposition::::::fpavrvp m=Euler Integration Once we’ve computed all of the forces in the system, we can use Newton’s Second Law (f=ma) to compute the acceleration Then, we use the acceleration to advance the simulation forward by some time step Δt, using the simple Euler integration schemettnnnnnnΔ+=Δ+=+++111vrravvnnmfa1=Physics SimulationGeneral Physics Simulation:1. Compute forces2. Integrate motion- RepeatCloth Simulation1. Compute ForcesFor each particle: Apply gravityFor each spring-damper: Compute & apply forcesFor each triangle: Compute & apply aerodynamic forces2. Integrate MotionFor each particle: Apply forward Euler integrationUniform Gravity[]20008.90smmgravity−==ggfSpring-Dampers••1r2r2v1v The basic spring-damper connects two particles and has three constants defining its behavior Spring constant: ks Damping factor: kd Rest length: l0Spring-Damper A simple spring-damper class might look like:class SpringDamper {float SpringConstant,DampingFactor;float RestLength;Particle *P1,*P2;public:void ComputeForce();};Spring-Dampers The basic linear spring force in one dimension is: The linear damping force is: We can define a spring-damper by just adding the two:()llkxkfssspring−−=−=0()21vvkvkfdddamp−−=−=()()210vvkllkfdssd−−−−=Spring-Dampers To compute the forces in 3D: Turn 3D distances & velocities into 1D Compute spring force in 1D Turn 1D force back into 3D forceSpring-Damper Force We start by computing the unit length vector e from r1to r2 We can compute the distance lbetween the two points in the process••1r2rll***12eeerre==−=elSpring-Dampers Next, we find the 1D velocities••1r2r2v1ve22ve⋅=v11ve⋅=vSpring-Dampers Now, we can find the 1D force and map it back into 3D••efsdf=1e()()121210ffef−==−−−−=sddssdfvvkllkf12ff−=Aerodynamic Force In the last lecture, we defined a simple aerodynamic drag force on an object as:ρ: density of the air (or water…)cd: coefficient of drag for the objecta: cross sectional area of the objecte: unit vector in the opposite direction of the velocityevf acdaero221ρ=vve −=Aerodynamic Force Today we will extend that to a simple flat surface Instead of opposing the velocity, the force pushes against the normal of the surface Note: This is a major simplification of real aerodynamic interactions, but it’s a good place to startnvf acdaero221ρ−=Aerodynamic Force In order to compute the aerodynamic forces, we need surfaces to apply it to We will add some triangles to our cloth definition, where each triangle connects three particles1r2r3rAerodynamic Force In order to compute our force:we will need find the velocity, normal, and area of the triangle (we can assume that ρ and cdare constants)1r2r3rnvf acdaero221ρ−=Aerodynamic Force For the velocity of the triangle, we can use the average of the three particle velocities We actually want the relative velocity, so we will then subtract off the velocity of the air1v2v3v3321vvvv++=surfaceairsurfacevvv−=surfacevAerodynamic Force The normal of the triangle is:1r2r3rn()()()()13121312rrrrrrrrn−×−−×−=Aerodynamic Force The area of the triangle is: But we really want the cross-sectional area (the area exposed to the air flow)()()1312021rrrr −×−=avnv⋅=0aanvvAerodynamic Force As the final equation requires |v|2an, we can reduce the math a little bit: Also, notice that:()()()**2**21312nnnvvnvrrrrn⋅=−×−=a22**nvnv=Aerodynamic Force The final aerodynamic force is assumed to apply to the entire triangle We can turn this into a force on each particle by simply dividing by 3, and splitting the total force between themBending Forces If we arrange our cloth springs as they are in the picture, there will be nothing preventing the cloth from bending This may be find for simulating softer cloth, but for stiffer materials, we may want some resistance to bending•••••••••Bending Forces A simple solution is to add more springs, arranged in various configurations, such as the one in the picture The spring constants and damping factors of this layer might need to be tuned differently…•••••••••Collisions We will talk about collision detection & response in the next lecture… In the mean time, here’s a very basic way to collide with a y=y0planeIf(r.y < y0) {r.y= y0 -r.y;v.y= - elasticity * v.y;v.x= (1-friction) * v.x; // cheezyv.z= (1-friction) * v.z; // cheezy}Plastic Deformation An elastic deformation will restore back to its un-deformed state when all external forces are removed (such as the deformation in a spring, or in a rubber ball) A plastic deformation is a permanent adjustment of the material structure (such as the buckling of metal)Plastic Deformation We can add a simple plastic deformation rule to the spring-dampers We do so by modifying the rest length Several possible rules can be used, but one simple way is to start by defining an elastic limit and plastic limit The elastic limit is the maximum deformation distance allowed before a plastic deformation occurs If the elastic limit is reached, the rest length of the spring is adjusted so that meets the elastic limit
View Full Document