Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Soft body vanishes
PostPosted: Wed Apr 06, 2011 11:44 pm 
Offline

Joined: Wed Apr 06, 2011 7:48 pm
Posts: 8
I'm trying to create a soft body sphere using code from the Soft Body Demo. I got it loaded and could see it in the debug drawer, but once I started stepping the simulation it vanished. I've tried disabling the simulation on "brush", my soft body variable, using setActivationState but that didn't seem to change anything.

I'm fairly certain that "brush" isn't moving anywhere since my simulation has no gravity and it's the only object in the world, but I'm not sure how to check its position since getWorldTransform().getOrigin() always returns btVector3(0, 0, 0).

Loading code
Code:
void loadObj(const char* fileName, btVector3 &position, btScalar scaling)
{
   ConvexDecomposition::WavefrontObj wo;
   int loadedWO = wo.loadObj(fileName);

   if(loadedWO)
   {
      btVector3* d = new btVector3[wo.mTriCount * 3];

      btVector3 localScaling(scaling, scaling, scaling);
      
      int i;
      for ( i = 0; i < wo.mTriCount;i++)
      {
         int index0 = wo.mIndices[i*3];
         int index1 = wo.mIndices[i*3+1];
         int index2 = wo.mIndices[i*3+2];

         btVector3 vertex0(wo.mVertices[index0*3], wo.mVertices[index0*3+1],wo.mVertices[index0*3+2]);
         btVector3 vertex1(wo.mVertices[index1*3], wo.mVertices[index1*3+1],wo.mVertices[index1*3+2]);
         btVector3 vertex2(wo.mVertices[index2*3], wo.mVertices[index2*3+1],wo.mVertices[index2*3+2]);
         
         vertex0 *= localScaling;
         vertex1 *= localScaling;
         vertex2 *= localScaling;

         d[i * 3] = vertex0;
         d[i * 3 + 1] = vertex1;
         d[i * 3 + 2] = vertex2;

      }

      brush = btSoftBodyHelpers::CreateFromConvexHull(worldInfo, d, wo.mTriCount * 3);
      brush->generateBendingConstraints(2);
      btTransform trans;
      trans.setIdentity();
      trans.setOrigin(position);
      brush->transform(trans);

      dynamicsWorld->addSoftBody(brush);

   }
}


Update method
Code:
void update(double elapsed)
{
   dynamicsWorld->stepSimulation(elapsed);
   btVector3 pos = brush->getWorldTransform().getOrigin();
   std::cout << pos.x() << " " << pos.y() << " " << pos.z() << std::endl;
}


Top
 Profile  
 
 Post subject: Re: Soft body vanishes
PostPosted: Thu Apr 07, 2011 12:38 am 
Offline
User avatar

Joined: Tue Jun 29, 2010 10:27 pm
Posts: 237
I'm not sure why your soft body is disappearing, but as for the issue with printing the origin... From my experience (I had the same problem with the softBody origin returning (0,0,0)), and from what I understand from soft body source code, soft bodies do not do anything with their transform. Origin and orientation are both zero-initialized, and that's it. This is because the soft body does not have the same notion of a single transform as a rigid body. Instead, its nodes all just store world coordinates, and any time transforms are applied to a soft body, it just directly modifies the nodes' world coordinates (see the softBody transform(...) function). To check node positions, I do this:

Code:
btSoftBody::tNodeArray& btNodes = softBody->m_nodes;
for (int i = 0; i < btNodes.size(); ++i)
{
   printf("Soft body node %d: (%f, %f, %f)\n", i, btNodes[i].m_x.x(), btNodes[i].m_x.y(), btNodes[i].m_x.z());
}


So you could try that to see if the soft body nodes are at least where they should be.


Top
 Profile  
 
 Post subject: Re: Soft body vanishes
PostPosted: Thu Apr 07, 2011 12:58 am 
Offline

Joined: Wed Apr 06, 2011 7:48 pm
Posts: 8
Thanks, that showed I was wrong about it "vanishing". It's just moving out of the scene at an extremely high velocity for some reason. Now to figure out why :?.

My first thought was self-collision, but changing "m_cfg.collisions" doesn't seem to do much.


Top
 Profile  
 
 Post subject: Re: Soft body vanishes
PostPosted: Fri Apr 08, 2011 10:35 pm 
Offline

Joined: Wed Apr 06, 2011 7:48 pm
Posts: 8
Alright I fixed the problem. Turns out while I set the gravity to 0 in the dynamicsWorld, I hadn't set it in my world info variable as well. One added line was all I needed :roll:
Code:
worldInfo.m_gravity.setValue(0, 0, 0);


Top
 Profile  
 
 Post subject: Re: Soft body vanishes
PostPosted: Fri Apr 08, 2011 11:03 pm 
Offline
User avatar

Joined: Tue Jun 29, 2010 10:27 pm
Posts: 237
Ah :) , yeah soft bodies have their own gravity separate from the dynamics world for some reason. This duplication of gravities tripped me up a little while ago as well. I don't see why soft bodies don't just use the dynamicsWorld gravity like the other collision object types. Maybe I'll file a bug report about it since I'm patching some other soft body stuff at the same time.


Top
 Profile  
 
 Post subject: Re: Soft body vanishes
PostPosted: Wed Dec 21, 2011 6:55 pm 
Offline

Joined: Mon Dec 05, 2011 8:36 pm
Posts: 12
Can anyone tell me how to update texture coordinates for soft body?? I am rendering a customized .obj file which falls down due to gravity but the texture is not at all as it is supposed to be. I am passing the texture coordinates but they are not updated since world transform doesn't work for soft body. I am using the soft bodys node structure to render the soft body. All this is done using OpenGL. Please any help would be appreciated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group