I have gone through every PhysX 3 cloth method and i can't get the cloth particles to be static.
Also "inverse_mass" doesn't seem to have an effect and it seems like it resets to 1 after each simulation call. The only way to fake particle anchoring seems to be to manually reset the static particle's position before (or after) each simulation run which is a bit of a lame method.
Anyway just change "_case" to 1 or 2 for the two examples.
EDIT: Also i can't seem to find how to enable collision with other objects other than with the "sphere_cloth.setCollision..." method and Collision groups seem to be a PhysX 2 method.
Code:
ClothMesh sphere_clothmesh;
Cloth sphere_cloth;
Cloth.Particle clothparticle[1107]; // 1107 particles comprising cloth
Actor myBallActor;
/******************************************************************************/
void InitPre() // init before engine inits
{
EE_INIT(); // call auto-generated function that will setup application name, load engine and project data
App.flag=APP_MS_EXCLUSIVE;// initialize mouse in exclusive mode (which hides cursor and clips it to the application window)
D.mode(800, 600);
Cam.dist =6; // dist of camera from look-at location
Cam.yaw =0.0;
Cam.pitch=0.0;
Cam.at.set(0, 3, 0); // look-at location
}
/******************************************************************************/
bool Init() // initialize after engine is ready
{
Physics.create(EE_PHYSX_DLL_PATH);
// WORLD
Game.World.activeRange(D.viewRange());
Game.World.New(UID(74260766, 1118171862, 1840723101, 2500176485));
if(Game.World.settings().environment) Game.World.settings().environment->set();
// BALL ACTOR
Ball myBall;
myBall.set(0.5, Vec(0, 2, 0));
myBallActor.create(myBall);
myBallActor.gravity(false);
// CLOTHMESH CREATION
MaterialPtr mat;
mat.require(UID(411076986, 1316419555, 1358389125, 1315404549));
Game.ObjParamsPtr obj=UID(4065380602, 1228302859, 1211434118, 534123206);
MeshBase myBase;
myBase.create(obj().mesh()().setBase());
sphere_clothmesh.create(myBase, mat);
// CLOTH CREATION
Matrix clothMatrix;
clothMatrix.setPos(Vec(0, 2.8, 0));
sphere_cloth.create(sphere_clothmesh, clothMatrix);
sphere_cloth.damping(0.1);
sphere_cloth.setCollisionBalls(myBall);
///*
// INITIAL CLOTH PARTICLE POS
for(int i=0; i<1107; i++)
{
Vec myPos = sphere_cloth.lockRead()[i].pos;
sphere_cloth.unlock();
clothparticle[i].pos = myPos;
clothparticle[i].inverse_mass = 0.0f;
}
//*/
return true;
}
/******************************************************************************/
void Shut() // shut down at exit
{
// this is called when the engine is about to exit
}
/******************************************************************************/
bool Update() // main updating
{
// CAMERA
Cam.transformByMouse(0.1, 100, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));
int _case = 1; // Change to 1 or 2
if(_case == 1)
{
// RESET POSITION OF SOME VTXS
for(int i=200; i<1107; i++)
{
Vec myPos = sphere_cloth.lockRead()[i].pos;
sphere_cloth.unlock();
clothparticle[i].pos = myPos;
clothparticle[i].inverse_mass = 0.0f;
}
sphere_cloth.set(clothparticle, sphere_cloth.vtxs());
Game.World.update(Cam.at);
//Physics.startSimulation(); // required after stopping simulation
Physics.stopSimulation(); // required, else error
}
// [inverse_mass] RESETS TO 1 AFTER THE SIMULATION
if(_case == 2)
{
// SET [inverse_mass] TO 0 FOR ALL VTXS
for(int i=0; i<1107; i++)
{
Vec myPos = sphere_cloth.lockRead()[i].pos;
sphere_cloth.unlock();
clothparticle[i].pos = myPos;
clothparticle[i].inverse_mass = 0.0f;
}
sphere_cloth.set(clothparticle, sphere_cloth.vtxs());
Game.World.update(Cam.at);
//Physics.startSimulation(); // required after stopping simulation
Physics.stopSimulation(); // required, else error
/*
// SET [inverse_mass] TO 0 FOR ALL VTXS
for(int i=0; i<1107; i++)
{
Vec myPos = sphere_cloth.lockRead()[i].pos;
sphere_cloth.unlock();
clothparticle[i].pos = myPos;
clothparticle[i].inverse_mass = 0.0f;
}
sphere_cloth.set(clothparticle, sphere_cloth.vtxs());
//*/
}
if(Kb.bp(KB_ESC))return false; // exit if escape on the keyboard pressed
return true; // continue
}
/******************************************************************************/
void Render()
{
Game.World.draw(); // draw world (this is done outside of 'switch(Renderer())' because world automatically detects active rendering mode)
switch(Renderer())
{
case RM_PREPARE:
{
// draw cloth
sphere_cloth.drawPhysical();
}break;
case RM_SHADOW:
{
// draw cloth shadow
sphere_cloth.drawPhysicalShadow();
}break;
}
}
/******************************************************************************/
void Draw()
{
// here you have to tell engine what to draw on the screen
Renderer(Render);
Physics.draw();
D.text (0, 0.9, S+"FPS: "+Time.fps());
D.text (0, 0.8, S+"CLOTH VTXS: "+sphere_cloth.vtxs());
D.text (0, 0.7, S+"CLOTH VTX 1 POS: "+sphere_cloth.vtxPos(1));
D.text (0, 0.6, S+"CLOTH PARTICLE 1 POS: "+sphere_cloth.lockRead()[1].pos);
sphere_cloth.unlock();
D.text (0, 0.5, S+"CLOTH PARTICLE 1 INV: "+sphere_cloth.lockRead()[1].inverse_mass);
sphere_cloth.unlock();
D.text (0, 0.4, S+"ARRAY 1 INV: "+clothparticle[1].inverse_mass);
}
/******************************************************************************/