# Problem To Understand Simple Cloth Simulation

Hello,
I am trying to understand simple cloth animation using three.js . I am facing some problems regarding the clothfunction.
A function plane is defined in such way so that it returns an entire function.

It does not return anything like an object but an entire function.

1. How this is possible ?
I searched it as a javascript topic but could not find any answer.
2. plane() returns a function which takes target as an argument. What is target here?
target.set(x,y,z);
What does it mean ? Now clothFunction takes a function which is returned by plane() function.
Now I am passing clothFunction as an argument to ParametricBufferGeometry( , , ) This time clothFunction does not take any argument .
3. If I assume clothFunction is a function then why it doesn’t take any argument?
4. If I assume clothFunction is an object then where am I passing target argument ?
5. If the function is defined and returned at the same time then when is it called ?
function (u,v,target){…};
The aforesaid function is referred here.
6. If the function is called at some point then where the target argument is passed ?
[As per my knowledge the scope of target is limited within the definition. It can’t be accessed from anywhere]
Source: Simple_cloth_simulation
1 Like

Well, in JavaScript functions are objects. That makes it possible to return the anonymous function inside `plane()`.

The anonymous function is a so called parametric function representing a plane. Based on the given `u` and `v` scalar values, it computes a vector. Because object creation is expensive in JavaScript, parametric functions always have a `target` parameter. In this way, a single vector object can be reused when calling `plane()` multiple times.

Well, if you understand that functions are objects, this question will be obsolete. `clothFunction` is just a reference to the function object.

When it is finally invocated by `ParametricBufferGeometry`. This class is a geometry generator and uses the given parametric function to generate vertex data.

TBH, I don’t understand what you mean here.

This happens in `ParametricBufferGeometry` here. `p0` is the target vector.

1 Like