About Store Forum Documentation Contact



Post Reply 
Attaching Cloth
Author Message
Brainache Offline
Member

Post: #1
Attaching Cloth
Hey there... finally getting back around to working with cloth.. and I can attach it to the world using:

cloth.attachVtx(0, Vec(16,2,16));
cloth.attachVtx(7, Vec(15.5,2,16));

But I am not having much luck getting it to attach to an Actor...

This is where it sits atm... can you point me to the proper way?

Cloth::Param param;
Mshb mshb;
mshb .createPlane(8,32,VTX_TX0).matrix(Matrix().setRotateX(PI_2).move( Vec(-0.5,1,-0.5) ));
cloth.create(mshb,Materials("../data/mtrl/ground/0.mtrl"),param);
cloth.attachVtx(0, Vec(16,2,16), &bodies[c-1].ctrl.actor);
cloth.attachVtx(7, Vec(15,2,16), &bodies[c-1].ctrl.actor);

(bodies is an array of chr classes)


Thanks in advance for your help!
12-24-2008 03:11 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
Re: Attaching Cloth
I've modified slightly the main cloth tutorial, and it works

Code:
/******************************************************************************/
#include "stdafx.h"
/******************************************************************************/
Actor ground,
      box   ,
      ball  ;
Cloth cloth ; // Physical Cloth
Controller ctrl;
/******************************************************************************/
void InitPre()
{
   App.name="Physical Clothes";
   App.flag=APP_MS_EXCLUSIVE;
   PakAdd("../data/engine.pak");
   D.mode(1024,768).sync(true);
}
Bool Init()
{
   Cam.dist =4;
   Cam.pitch=-PI_4;

   Physics.create().precision(120);

   ground.create(Box (15,1,15,Vec(0 ,-2,0)), 0);
   box   .create(Box (0.3    ,Vec(-1, 0,0)));
   ball  .create(Ball(0.3    ,Vec( 1, 0,0)));

   // create controller
   ctrl.create(Capsule(0.3f,1.8f));
  
   // create cloth
   Cloth::Param param; // parameters for cloth creation
   Mshb         mshb ; // clothes are created from meshes, so create a mesh for it
   mshb .createPlane(8,32,VTX_TX0)                                   // create mesh as 32x32 vertex plane with texture coordinates set
        .matrix(Matrix(Vec(ctrl.actor.pos()+Vec(-0.5f,0,-0.31f))));  // transform mesh by matrix
   cloth.create(mshb,Materials("../data/mtrl/ground/0.mtrl"),param); // create cloth from mesh
   cloth.attachVtx(0,ctrl.actor.pos()+Vec(-0.3f,1,-0.3f),&ctrl.actor);
   cloth.attachVtx(7,ctrl.actor.pos()+Vec( 0.3f,1,-0.3f),&ctrl.actor);

   return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
Bool Main()
{
   if(Kb.bp(KB_ESC))return false;
   CamHandle(0.1,10,CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));
   ctrl.update(Vec(Kb.b(KB_D)-Kb.b(KB_A),0,Kb.b(KB_W)-Kb.b(KB_S)),Kb.ctrl,Kb.bp(KB_SPACE) ? 3.5f : 0);
   Physics.sim().get();
   return true;
}
/******************************************************************************/
void Draw()
{
   LightDir(1,Cam.matrix.z).set();
   D      .clear();
   Physics.draw ();
   cloth  .draw (); // draw cloth
}
/******************************************************************************/

however due to contoller actor crouching, and since the controller actor isn't rotating when looking in different directions, you could try attaching the cloth each frame to world position near actor, instead of the actor
I'm not yet sure which setting would be best so you would have to experiment, Cloth is PhysX based, and I'm providing every functions for PhysX cloth available
12-24-2008 04:58 PM
Find all posts by this user Quote this message in a reply
Brainache Offline
Member

Post: #3
Re: Attaching Cloth
Cool.. thanks for the example.. I'll play around with it a bit more...
12-24-2008 06:04 PM
Find all posts by this user Quote this message in a reply
Seba Offline
Member

Post: #4
RE: Attaching Cloth
I make a tent using Cloths. I add code from tutorials but i cant make vertex with no physics to don't move. I try use that code:
Quote:if(ClothMesh *cloth_mesh=C_cloth.clothMesh ()) // access cloth mesh from which the cloth has been created
if(const Vec *vtx_pos =C_cloth_mesh.pos ()) // access cloth mesh source vertex positions
if(const Byte *vtx_flag =C_cloth_mesh.flag ()) // access cloth mesh source vertex flags
if(const VecB4 *vtx_matrix=C_cloth_mesh.matrix()) // access cloth mesh source vertex matrix indexes
{
But i can't pass that if:
Quote:if(const Byte *vtx_flag =C_cloth_mesh.flag ())
if(const VecB4 *vtx_matrix=C_cloth_mesh.matrix())
10-24-2009 03:33 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
RE: Attaching Cloth
if(const Byte *vtx_flag =C_cloth_mesh.flag ())

this is specified in the Mesh Editor, Vtx/Face vtx cloth flag editing
10-24-2009 04:50 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #6
RE: Attaching Cloth
I don't see this option. I only have ClothEdit mode. I check vertexes and export mesh to .clms file.
10-24-2009 05:22 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: Attaching Cloth
yes, thats it, once you set some vertexes the mesh will have the .flag enabled
10-25-2009 12:24 AM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #8
RE: Attaching Cloth
And what with Matrix and Blend options? Where can I set them?
10-25-2009 11:06 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Seba Offline
Member

Post: #9
RE: Attaching Cloth
In our models in cloth edit mode and selected part of mesh we have:
Quote:Vtx: Pos Nrm Tng Bin Tex Flag
In cap model we have:
Quote:Vtx: Pos Nrm Tex Matrix Blend Flag
So maybe becouse we don't have the same options We can't pass that ifs using ours models. But we don't know how to change that options, so any one can help?

//Found some errors in my code anyway I cant pass that ifs .
(This post was last modified: 10-25-2009 02:36 PM by Seba.)
10-25-2009 02:24 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #10
RE: Attaching Cloth
(10-25-2009 11:06 AM)Harry Wrote:  And what with Matrix and Blend options? Where can I set them?

this is just skinning, its just used to know to which bone actor attach the cloth vertexes, but since you dont attach the tent to ragdoll bone actors, but only tent actor, you don't need them, modify your code to dont use skinning and attach only to tent actor
10-25-2009 06:43 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #11
RE: Attaching Cloth
Please, check his model ad tell us what's wrong with it. We still can't pass this line:

if(const Byte *vtx_flag =C_cloth_mesh.flag ())

Link: http://odsiebie.com/pokaz/6492852---dc7c.html
(This post was last modified: 10-27-2009 09:05 PM by Harry.)
10-27-2009 09:00 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #12
RE: Attaching Cloth
I've fixed this, update will be in ~10 minutes
10-29-2009 01:04 AM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #13
RE: Attaching Cloth
Now it's working smile Thanks.
10-29-2009 02:28 PM
Visit this user's website Find all posts by this user Quote this message in a reply
b1s Offline
Member

Post: #14
RE: Attaching Cloth
Code:
if(const VecB4 *vtx_matrix=cloth_mesh->matrix()) // access cloth mesh source vertex matrix indexes

im not getting over this one.
What does this mean exactly? is it something that should be set in mesh editor?
Im trying to run the physical cloth tutorial with a custom mesh but this if fails and no vertices gets attached.
Flags should be ok as far as i know.
02-15-2010 07:18 PM
Find all posts by this user Quote this message in a reply
b1s Offline
Member

Post: #15
RE: Attaching Cloth
are there any directions how to setup a physcloth mesh?
i cant figure out what am I doing wrong here.
I have exported a mesh, clms file and the cloth edit mode has some of the vertices flagged.
something else needs to be done. i have tried to check the cape file and theres not much i have found there.
only thing is that there seems to be some skinning information there?
whats that for?
02-15-2010 08:24 PM
Find all posts by this user Quote this message in a reply
Post Reply