About Store Forum Documentation Contact
Donations:
392$/mo



Post Reply 
Cloth problem
Author Message
3DRaddict Offline
Member

Post: #1
Cloth problem
I've been experimenting with the Esenthel cloth functionality and come up with a problem...
There is extremely scant documentation on this and no examples whatsoever on its implementation, so its been long trial-and-error for me.
Here is vid of my first test:




My problem is that I am unable to anchor any of the particles comprising the cloth to a fixed position or a moving actor, by using the struct from the EE Physics/Cloth API documention:
PHP Code:
// methods for PhysX 3 only
      
struct Particle
      
{
         
Vec pos         // position of a single particle
         
Flt inverse_mass// set 0 for static or 1 for dynamic particle (static will not move at all, dynamic will move according to physics simulation)
      
}; 

In the video the cloth appears to be anchored at the start, but that is only by applying a wind acceleration Vec(0.0, 9.8, 0.0) in the exact opposite to gravity acceleration i.e Vec(0.0,-9.8, 0.0). If I had not done this, the cloths would all start falling immediately I ran the test. Also, I had to stop the cloths downward slide after they had encompassed the the three primitive actors, by putting them to sleep at a certain height!

I understand from the documentation that by setting the 'inverse_mass' to 0 for selected particles then those particles will become static and not move. However, with many attempts at this I could not get it to work.
Here is some of the code I'm using:
PHP Code:
Cloth.Particle clothparticle[2486]; 
   
   
int  NNflag_cloth.vtxs();

   for(
int i=0i<flag_cloth.vtxs(); i++)
   {
      
Vec V flag_cloth.lockRead()[i].pos;
      
     
/*--------------------------------------------------------*/ 
     /* Test changing the cloth particles pos and inverse_mass */
     /*--------------------------------------------------------*/
       //  V.y+=0.1;
       //  clothparticle[i].inverse_mass=0.0;
     /*--------------------------------------------------------*/
     
      
clothparticle[i].pos=Vec(V.xV.yV.z);
      
   }
   
   
flag_cloth.set(clothparticleNN);
   
flag_cloth.unlock(); 

If I can get this working, then my intention is to demonstrate a flag which can be raised and lowered on a flagpole.
06-16-2015 07:49 AM
Visit this user's website Find all posts by this user Quote this message in a reply
3DRaddict Offline
Member

Post: #2
RE: Cloth problem
46 views and no replies...most noticeably from the man himself!

If Esenthel is unable to confirm or refute my problem then please could someone else?
I may be doing something wrong, and I just want to find out whether I am or not.
06-19-2015 05:29 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: Cloth problem
Hi,

Sorry I haven't touched cloth in a long while.
One thing that looks suspicious is that you're doing:
1. lockRead
2. set
3. unlock

perhaps you should do:
1. lockRead
2. unlock
3. set

You can always check the source code:
https://github.com/Esenthel/EsenthelEngi.../Cloth.cpp
06-20-2015 12:38 AM
Find all posts by this user Quote this message in a reply
3DRaddict Offline
Member

Post: #4
RE: Cloth problem
So that we are all talking the same, I've put together a small project which demonstrates the problem I'm having. If so inclined, please play around with my code and see if you can get the cloth particle 'inverse_mass=0' to work (without using the tricks that I've used!)

https://dl.dropboxusercontent.com/u/2104...roblem.rar

(I had to zip the .EsenthelProject file to a .rar file so that it would be able to download from my dropbox)
06-20-2015 10:11 AM
Visit this user's website Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Bronze Supporter

Post: #5
RE: Cloth problem
never touched the cloth sorry pfft

but im def. interested =p
06-20-2015 07:36 PM
Find all posts by this user Quote this message in a reply
3DRaddict Offline
Member

Post: #6
RE: Cloth problem
I'm having no success with this whatsoever.
So until Esenthel produces the Physx3 cloth tutorial (see RoadMap).......
06-23-2015 09:20 AM
Visit this user's website Find all posts by this user Quote this message in a reply
georgatos7 Offline
Member

Post: #7
RE: Cloth problem
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.

EDIT2 :
Quote:PhysX 3 removed features:
-no softbodies
-cloth does not interact with world actors, only with manually specified shapes (balls/capsules/planes)

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);
  
}
/******************************************************************************/
(This post was last modified: 06-23-2015 11:01 PM by georgatos7.)
06-23-2015 09:31 PM
Find all posts by this user Quote this message in a reply
3DRaddict Offline
Member

Post: #8
RE: Cloth problem
Thank you, Georgatos7, for taking an interest in this. At least, we now have two of us on the same wavelength. wink

Well done on at least discovering how to fix selected particles at set positions by resetting them at those positions (even if you think its a rather 'lame' method) smile

I had also tried doing that (prior to your post) and it would not work. I have now discovered why (after your post).... I had the statement
PHP Code:
Physics.precision(360); 
in the 'Init' section of my code, which was buggering things up. (This was left over from some previous code I had been working on). I took it away, and everything is now ok

I agree that there is still a problem in that
Quote:Also "inverse_mass" doesn't seem to have an effect and it seems like it resets to 1 after each simulation call.

Also, I see that you agree that there is a necessity to stop the physics simulation in the 'Update' section so as to avoid the runtime error which pops up.You also helped me here, as I was stopping and restarting the physics without realizing that
PHP Code:
Game.World.update(Cam.at); 
did the same job.

Thanks once again for your assistance, and lets hope that Esenthel can get all this working 100% grin
06-24-2015 06:11 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
RE: Cloth problem
Hello,

Either the inverse_mass is broken in PhysX, or it needs some additional work of setting up some motion constraints:
PxCloth::setMotionConstraints
Or perhaps something else entirely.

I've added this to the roadmap.
If you need it now, I recommend diving into:
https://github.com/Esenthel/EsenthelEngi.../Cloth.cpp
https://github.com/Esenthel/EsenthelEngi.../PxCloth.h

Btw. in your project there are multiple start/stop simulation calls because otherwise there are physx errors.
Please call only one startSimulation per frame (since Game.World.update already does that, then don't call startSimulation at all). To avoid physx errors, you should just call stopSimulation before calling cloth methods.

Thanks!
06-25-2015 11:31 PM
Find all posts by this user Quote this message in a reply
Post Reply