# Physics Simulation Forum

 All times are UTC

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Softbody: texture coordinates for rendering?Posted: Sun Sep 11, 2011 2:35 pm

Joined: Sun Sep 11, 2011 2:02 pm
Posts: 13
Hi,

I recently decided to try out bullet, mainly the soft-body part of the libary. I managed to asign a piece of clothing using btSoftBodyHelpers::CreatePatch(), and render its faces with Direct3D. However, I've got a question: How do I calculate the texture coordinates of every face? I'm reading the face-data like this:

Code:
for(int i=0;i<Faces.size();++i)
{
btSoftBody::Node*   node_0=Faces[i].m_n[0];
btSoftBody::Node*   node_1=Faces[i].m_n[1];
btSoftBody::Node*   node_2=Faces[i].m_n[2];
Data[j].fX = node_0->m_x.x();
Data[j].fY = node_0->m_x.y();
Data[j].fZ = node_0->m_x.z();
Data[j].tex0 = ???;
Data[j].tex1 = ???;
j+=1;
Data[j].fX = node_1->m_x.x();
Data[j].fY = node_1->m_x.y();
Data[j].fZ = node_1->m_x.z();
Data[j].tex0 = ???;
Data[j].tex1 = ???;
j+=1;
Data[j].fX = node_2->m_x.x();
Data[j].fY = node_2->m_x.y();
Data[j].fZ = node_2->m_x.z();
Data[j].tex0 = ???;
Data[j].tex1 = ???;
j+=1;
}

Is there any method or variable where texture coordinates are stored? Or do I have to calculate them myself? If so, can somebody tell me or give me some advice how to do so? I tried figuring it out myself, but can't really get it to work.. Thanks in Advance!

Top

 Post subject: Re: Softbody: texture coordinates for rendering?Posted: Mon Sep 12, 2011 12:34 pm

Joined: Wed Aug 25, 2010 12:57 am
Posts: 8
You'll have to create your own, for a patch it's easy, just use the vertex positions from the major axis's in which the patch is created e.t.c.

btSoftBodyHelpers.h
/* Create a patch with UV Texture Coordinates */
static btSoftBody* CreatePatchUV(btSoftBodyWorldInfo& worldInfo,
const btVector3& corner00,
const btVector3& corner10,
const btVector3& corner01,
const btVector3& corner11,
int resx,
int resy,
int fixeds,
bool gendiags,
float* tex_coords=0);

Top

 Post subject: Re: Softbody: texture coordinates for rendering?Posted: Sun Sep 18, 2011 1:58 am

Joined: Thu Sep 08, 2011 1:59 am
Posts: 23
I've tried using this to create a cloth but it renders nothing but a black screen any ideas?

Top

 Post subject: Re: Softbody: texture coordinates for rendering?Posted: Sun Sep 18, 2011 12:47 pm

Joined: Sun Sep 11, 2011 2:02 pm
Posts: 13
@Skuzz: Thanks for telling me this function, but I already managed to calculate the coordinates myself! As you said it isn't really hard. But for more complicated tasks, I'll keep the CreatePatchUV in mind.

@shomy2k11: There could be multiple issues. Despite your graphics-api, try disabling face culling, thats the first issue I had. Otherwise, I can't over you much help except that you should check how you render the faces of your soft bodies... maybe there is some issue in your rendering cycle anyway!

Top

 Post subject: Re: Softbody: texture coordinates for rendering?Posted: Wed Dec 21, 2011 8:38 pm

Joined: Mon Dec 05, 2011 8:36 pm
Posts: 12
@TheKing Can you let me know how you did it?? I am trying to do it but I am getting a weird texture. I am rendering a .obj file from Maya. It falls down due o gravity but the texture is weird. I think it is because of the texture coordinates. Please let me know. My code for rendering is as follows. I am using OpenGL

void ViewManager::renderSoftbodyMeshes(btSoftBody* sBody)
{
btTransform meshTransform = sBody->getWorldTransform();

int j = 0;

static btScalar tempForm[16];
meshTransform.getOpenGLMatrix(tempForm);

glBindTexture(GL_TEXTURE_2D, GLuint(imageData));
glTexImage2D(GL_TEXTURE_2D, 0, 3, imageCols, imageRows, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

glPushMatrix();
glMultMatrixf(tempForm);
glBegin(GL_TRIANGLES);
int numFaces = sBody->m_faces.size();
for (int i=0; i< numFaces; i++)
{
glNormal3fv(sBody->m_faces[i].m_n[0]->m_n);
glTexCoord2fv(&objmodel->texcoords[objmodel->triangles[i].tindices[0]]);
glVertex3fv(sBody->m_faces[i].m_n[0]->m_q);

glNormal3fv(sBody->m_faces[i].m_n[1]->m_n);
glTexCoord2fv(&objmodel->texcoords[objmodel->triangles[i].tindices[1]]);
glVertex3fv(sBody->m_faces[i].m_n[1]->m_q);

glNormal3fv(sBody->m_faces[i].m_n[2]->m_n);
glTexCoord2fv(&objmodel->texcoords[objmodel->triangles[i].tindices[2]]);
glVertex3fv(sBody->m_faces[i].m_n[2]->m_q);
}

glEnd();
glPopMatrix();

glDisable(GL_TEXTURE_2D);
}

Top

 Post subject: Re: Softbody: texture coordinates for rendering?Posted: Wed Dec 21, 2011 8:42 pm

Joined: Mon Dec 05, 2011 8:36 pm
Posts: 12
I am adding the soft body as follows

btSoftBody* PhysicsManager::addSoftBodyMesh(int numAllVertices, float *allVerts , int numTriangles, int *indices, btVector3 position, float mass)
{

int maxidx=0;
int i,j,ni;

for(i=0,ni=numTriangles * 3;i<ni;++i)
{
maxidx=btMax((int)indices[i],maxidx);
}/*qDebug() << "2";*/
++maxidx;
btAlignedObjectArray<bool> chks;
btAlignedObjectArray<btVector3> vtx;
chks.resize(maxidx*maxidx,false);
vtx.resize(maxidx);
for(i=0,j=0,ni=maxidx*3;i<ni; ++j,i+=3)
{
vtx[j]=btVector3(allVerts[i],allVerts[i+1],allVerts[i+2]);
btSoftBody* psb = new btSoftBody(&m_softBodyWorldInfo,vtx.size(),&vtx[0],0);
for( i=0,ni=/*numIndices*/ numTriangles * 3;i<ni;i+=3)
{
const int idx[]={indices[i],indices[i+1],indices[i+2]};
#define IDX(_x_,_y_) ((_y_)*maxidx+(_x_))
for(int j=2,k=0;k<3;j=k++)
{
if(!chks[IDX(idx[j],idx[k])])
{
chks[IDX(idx[j],idx[k])]=true;
chks[IDX(idx[k],idx[j])]=true;
}
}
#undef IDX
psb->appendFace(idx[0],idx[1],idx[2]);
}

// psb->setMass( 100, 0); psb->setMass( 120, 0); psb->setMass( 200, 0); psb->setMass( 300, 0);
btSoftBody::Material* pm=psb->appendMaterial();
pm->m_kLST = 0.3;
pm->m_kAST = 0.2;
pm->m_kVST = 0.5;

psb->generateBendingConstraints(2,pm);
psb->m_cfg.piterations = 7;
psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RS+btSoftBody::fCollision::CL_SS + btSoftBody::fCollision::CL_SELF;

psb->m_cfg.kDF = 1.0;
psb->randomizeConstraints();
btTransform trans;
trans.setIdentity();
trans.setOrigin( position );
psb->transform(trans);
psb->setTotalMass(1.5,true);
psb->generateClusters(8);

return psb;
}

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 6 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: Bing [Bot] and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ BULLET PHYSICS LIBRARY USERS    General Bullet Physics Support and Feedback    Release Announcements    Applications, Games, Demos or Movies using Bullet PHYSICS AUTHORING TOOLS, SERIALIZATION AND STANDARDS    Physics authoring tools, serialization, standards and related topics RESEARCH AND DEVELOPMENT IN COLLISION DETECTION & PHYSICS. Don't post Bullet support questions here!    Research and development discussion about Collision Detection and Physics Simulation    Links, Papers, Libraries, Demos, Movies, Comparisons       Non-technical forum and license/patent discussion    Career Opportunities