Sei sulla pagina 1di 14

Cloth Animation & Dynamics

K.L.V.NagaRaju,
M050013CS.

National Institute of Technology,Calicut,


Kerala -673601.
CERTIFICATE

This is to certify that mini project Cloth Animation & Dynamics is a bonafide record of
the mini-project done by Mr. K.L.V.NagaRaju(M050013CS) under my supervision and
guidance. The project report has been submitted to Department of Computer Engineering
of National Institute of Technology, Calicut in partial fulfillment of Degree of Master of
Technology in Computer Science and Engineering.

Dr. Vineeth Kumar P,


Professor,
Dept. of Computer Engineering.

2
ACKNOWLEDGEMENT

I have been very fortunate to have Dr. Vineeth Kumar P, Professor, Department of
Computer Engineering, as my guide whose timely guidance, advice and inspiration
helped me in preparation of this Mini Project. I express my sincere gratitude for having
guided me through this work. I am thankful to Dr. M.P.Sebastian, Head of the Computer
Engineering Department for his encouragement and for giving me this opportunity.

K.L.V.Naga Raju.

3
Contents:

1. Introduction 6

2. Implementation 7

a. Vertices 7

b. Springs 7

c. Collision Detection 9

d. Collision Response 9

e. Friction 10

3. Screen shots 12

4. Conclusion 13

4
Abstract

This project simulates a cloth in a 3D environment using the fundamentals of physics.


The goal of this project is to reduce the complexity, so that this can be used in other
programs that require more interactivity (like games).

5
1. Introduction:

A cloth is a 3D mesh comprising of number of vertices, indices and triangles. Each vertex
has different attributes of its own (this include positions, color etc). The cloth moves
according to the forces that are applied on it, some of these forces are gravitation,
friction, forces between adjacent points etc. All these forces are applied on the vertices
so the movement of the vertices reflects the shape of the cloth.

The gravitation is a force that is in a single direction and it is in a constant magnitude.


Gravitation pulls all the vertices to a specific direction. A major force, which opposes this
force, is the force between the points. This force can be simulated by using the spring
forces, which is covered later. And there are other things that affect the dynamics of the
cloth such as collision detection and collision response. There are two types of collisions
internal collision and external collision in which only external collision is implemented in
this project. To detect collision we can use many types of objects such as bounding box,
bounding sphere or the mesh of the collision object. Bounding box and bounding sphere
are the various types of approximating the collision objects. Taking into account the
complexity and the ease of programming I have taken bounding sphere as collision
object. And collision response is seen in the next section. And friction is the force that
opposes the cloth points to flow from the surface of the collision object.

6
2. Implementation:

Vertices:

As we have said earlier cloth is a 3D mesh of vertices, these vertices have to be moved to
get the desired cloth output. These vertices have to move according to the forces applied
on them and the velocities they have at each and every point of time. So the each and
every vertex has the following attributes:

• Position
• Velocity vector
• Mass
• Force vector
• Coefficient of friction (for friction)
• A Boolean for saying it is movable or not.

All the attributes to each and every point are assumed to be initialized to a proper value.
And the force, velocity and position will vary according to the time. The force vector will
be initialized to the gravitation vector at the start of every iteration, and other forces will
be added to this vector later when they are computed. Finally, after the force is stabilized
we will calculate the velocity and the positions using the following equations.

Velocity = Force * time.

Position = Velocity * time + ½ * Force/Mass * time * time.

= Velocity * time. (Can be approximated to... because time interval is small)

Springs:

The vertices of the cloth will have some force between the adjacent vertices. These forces
keep the vertices in relatively correct positions. This can be implemented with the spring
model in the physics. From here we will refer the adjacency between the vertices as cloth
springs. Each cloth spring will be associated with two vertices. We can have 4-adjacency
or 8-adjacency for each single vertex and correspondingly the number of springs differs.

7
Each and every spring has the following attributes:

• Point 1.
• Point 2.
• Resting Length.
• Stiffness of the spring.
• Damping value.

The point 1 and point 2 are the values that identify the end points of that spring. Resting
length is the length that is intended to be between the points 1 and 2. Usually, the resting
length will be initialized with the original distance between the points at the starting
point. It is assumed that the cloth points are at correct distances at the starting point. The
stiffness of the spring is the value, which reflects the amount of stiffness that the points
should contain. Usually, the stiffness values of the points is high because the spring
motion of the cloth depends on this value and to get realism the stiffness should be more.
And finally, the damping value is the value, which produces the damping effect on the
spring. This damping value will reduce the velocity by some fraction for realism in the
cloth motion.

V2 V3
V1
Spring with
less length
Spring with than resting
less length length
than resting V5
length V4 V6

Reflection Attraction

Cloth springs

The equations corresponding to the cloth springs are given by:

Vertex 1.force += stiffness of the spring * difference between the current and
original length

Vertex 2.force -= stiffness of the spring * difference between the current and
original length

8
Collision Detection:

Before going into the details of collision detection we will see what a collision object is.
A collision object is a mesh with which the cloth should not overlap with. This mesh can
be in different shapes. Doing the collision detection for complex shapes include the
collision between every triangle of the mesh, which is a complex operation and it is not
desirable to programs with greater interactivity. To do the task simple we go for
bounding box or bounding sphere. With any complex mesh we can compute its bounding
box or bounding sphere. In this mini project I have chosen to do the collision detection
with the sphere. Every collision object (i.e. a sphere) has these attributes:

• Center position
• Radius

A cloth is said to have collision with a sphere if any of its points go inside the sphere.
This can be easily captured by the following condition:

For all cloth points and all collision objects:


If ( distance between point and the center position ≤ radius )
Collision is detected.
If ( no cloth point is collided )
No Collision is detected.

Collision Response:

If a collision has occurred between a cloth point and a collision object then this will
happen if and only if the velocity is towards the cloth and the force is towards the cloth.
So when a collision occurs then the point has to be moved out of the sphere and the cloth
velocity and the forces are to be adjusted in such a way that the movement towards the
collision objects reduces. This can be done by cutting down the velocity and force
components towards the center, and hence only the perpendicular component to the
sphere exists and hence the cloth resides on the collision object. This is illustrated in the
figure below.

9
Velocity

Point Point
Velocity

Velocity that will


be cut-down

Center

Before Collision Response After Collision Response

Friction:

If a point is on the collision object the frictional forces work on the opposite to the force
on the point and the hence the velocity also decreases. The friction depends on the
magnitude of the force exerted on the collision object. The amount of the force that
opposes is given by:

Collision force = coefficient of friction * force exerted on the collision Surface.


If ( Collision force > force parallel to collision surface )
Force parallel to collision surface = 0.
Else
Force parallel to collision surface -= Collision force.

The force exerted on the surface is the force component of force into (perpendicular to)
the surface. And the force parallel to collision surface is the force component on the
surface. This is illustrated the diagram below.

10
Body

Component
perpendicular to surface

Force

Component parallel
to surface

Illustration of friction of a body on a surface.

11
3. Screenshots:

Cloth falling due to gravity

Collision detection

12
4. Conclusion:

This project simulates a simple cloth animation, which can be used in many applications
such as games. The project is a simple implementation of basic physics formulas. And
hence is simple, correct and computationally less complex. The scope of improving the
project is very high because improving can be done in two different ways, the first is
complexity wise where the whole process is done faster by using approximated formulas
which are less accurate but computationally faster. The second way is accuracy wise
where the overall simulation can be done more accurately at the cost of lesser
interactivity.

13
References:

[1] Frank D Luna, 2003. Introduction to 3D game programming with DirectX 9.0,
Wordware Publishing, Inc.
[2] Jim Adams, 2003. Advanced Animation with DirectX, PREMIER PRESS.
[3] BRIDSON, R., FEDKIW, R. ANDERSON, J. 2002. Robust Treatment of
Collisions, Contact and Friction for Cloth Animation. In Proceedings of
SIGGRAPH 2002, 594–603.

14

Potrebbero piacerti anche