|
A simple example is provided in the directory sdk/syForce.
It shows a simple collision force on the horizontal plane y=-10 .

To compile the plugin:
- Windows
open the workspace in VisualC++:
sdk/syForce/win/win.dsw
press F7
it requires the library syLib.lib located in the lib/ directory.
- Linux
cd sdk/syForce/src
make
It requires the library syLib.a located in the lib/ directory
The compiled plugin (syForce.dll or syForce.so) can be loaded in XSI through:
File > Add-on > Plugins
To test it: load the scene Syflex_simple.scn
or copy/paste the following commands:
CreatePrim "Grid", "MeshSurface"
SetValue "grid.grid.ulength", 20
SetValue "grid.grid.vlength", 20
SetValue "grid.polymsh.geom.subdivu", 20
SetValue "grid.polymsh.geom.subdivv", 20
SelectObj "grid", , True
SyCreateCloth
SetValue "grid.polymsh.syCloth.syProperties.StretchStiffness", 1
SetValue "grid.polymsh.syCloth.syProperties.ShearStiffness", 1
SetValue "grid.polymsh.syCloth.syProperties.BendStiffness", 0.2
SetValue "grid.polymsh.syCloth.syProperties.StretchDamping", 0.01
SetValue "grid.polymsh.syCloth.syProperties.ShearDamping", 0.01
SetValue "grid.polymsh.syCloth.syProperties.BendDamping", 0.002
SyCreateGravity
SetValue "grid.polymsh.syCloth.syGravity.Gy", -0.1
SyCreateDamp
SetValue "grid.polymsh.syCloth.syDamp.Damp", 0.002
SetSelFilter "Vertex"
SelectGeometryComponents "grid.pnt[LAST]"
AddToSelection "grid.pnt[420]", , True
SyCreateNail
To add your new force to this cloth, apply the force on it:
applyOperator "syForce", "grid.polymsh.syCloth"
You can check in the explorer window that the force has indeed been added to the cloth:

Run the simulation: the cloth now bounces on the plane y=-10.
You can create a command that applies the syForce operator to the selected cloth. Then add
a new item to the Syflex menu.
The scripts in the directory syflex/sdk/scripts will help you do that.
|
|
A cloth in the simulator is represented by particles associated to each vertex,
linked together by springs.
The particle class contains informations for each particle, such as its position and velocity.
// particle class
class sySparticle {
public:
sySparticle();
~sySparticle();
int nbParticle; number of particles
float3* position; position of each particle
float3* normal; normal of each particle
float3* velocity; velocity of each particle
float3* force; force at each particle
float* mass; mass of each particle
};
Position is initialized from the XSI shape.
Velocity is computed at each frame.
Force is the sum of all forces applied on each vertex.
Your force class needs to compute a force for each particle, and add it to this 'force' array.
This computation is based on the position, speed and mass of the particles.
This is done through the compute method of the syForceS class.
// force class
class syForceS : public class sySforce{
public:
sySforce();
virtual ~syforceS();
int type() { return 32; }
void compute( sySparticle &p, sySsolver &s );
float k;
};
You can add additional parameters used by the force in this class.
In this example, there is only one parameter: 'k'.
The base class contains only one useful variable:
'active' is used to mute or activate the force.
syForceS::syForceS() {
active = 1;
plan = 0;
k = 0.01f;
}
syForceS::~syForceS() {}
void syForceS::compute( sySparticle &p, sySsolver &s ) {
int i,n;
float3 *F, *P;
n = p.nbParticle;
F = p.force;
P = p.position;
for(i=0;i<n;i++) {
if( P[i][1]<-10 )
F[i][1] += k;
}
}
The compute method calculates the force for each vertex.
If the position along the Y axis of a particle becomes smaller than -10
(P[i][1]<-10 ), then this particle is added a constant force
along the +Y axis, pulling the vertex above the plane Y=-10.
The syForce_Update is called by XSI at each frame. It transfers the parameters from the UI
to the computational layer:
CStatus syForce_Update(...) {
...
bool mute = op.GetParameterValue(L"mute");
float k = op.GetParameterValue(L"K");
force->active = !mute;
force->k = k;
...
}
|