Implemeting Cutting of Softbodies with volume preservation

PolyFlo
Posts: 17
Joined: Fri Apr 03, 2009 9:12 am

Implemeting Cutting of Softbodies with volume preservation

Post by PolyFlo »

Hello Bullet developers.

I work on a project where I have to render volumetric soft bodies. The main task of the project is to cut those soft bodies in a way that the soft bodies keep their volume. In other words when I cut a model partially or completely this model (or models if I cut them in two or more pieces) must have a closed mesh after the cut. The different parts together must have the same volume as the original body.

In this thread I want to post my progress and ask questions if I have any. Suggestions or ideas are also welcome of course. Is anyone working on a similar project?

Best regards,
Florian
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Implemeting Cutting of Softbodies with volume preservation

Post by Erwin Coumans »

Right now, you can cut volumetric soft bodies into pieces, but volumetric preservation is very poor in that case.

There is some implementation using tetrahedral meshes, not in the latest trunk, but in an older SVN revision
(See Init_TetraCube in http://code.google.com/p/bullet/source/ ... ftDemo.cpp)

We should recover that code and make a demo.
Hope this helps,
Erwin
PolyFlo
Posts: 17
Joined: Fri Apr 03, 2009 9:12 am

Re: Implemeting Cutting of Softbodies with volume preservation

Post by PolyFlo »

Sorry for so long not answering, but first I had to check out how to cut a mesh ;)

Now I have a question: Why was the tetrahedral meshes taken out of Bullet? Were there any problems with them?

Another question that came up while reading some papers is: Can Bullet detect and solve self-collissions of soft bodies?

Best regards,
Florian
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Implemeting Cutting of Softbodies with volume preservation

Post by Flix »

Now I have a question: Why was the tetrahedral meshes taken out of Bullet? Were there any problems with them?
I remember that the support was present in the past too (and with the possibility of importing files with some specific extensions).

Anyway, as far as I remember, I think that it's still possible to use it in some way in the current SVN: just add additional vertices (nodes) and add links to them, without adding the new vertices to any face (face are used for raycasting and collision detection, and nodes as edges of elastic links AFAIK). But you can't model them in extern programs and import them into Bullet any more.

Another question that came up while reading some papers is: Can Bullet detect and solve self-collissions of soft bodies
I don't think so.

Hope it helps.
PolyFlo
Posts: 17
Joined: Fri Apr 03, 2009 9:12 am

Re: Implemeting Cutting of Softbodies with volume preservation

Post by PolyFlo »

:oops: I know it's not very nice to ignore the forum for long times but trust me: Implementing cutting of volumetric meshes is not as easy as it sounds in the first place. Even without physics.

First of all:
@Flix: Thank you very much for your answer. Loading the mesh and giving it more vertices would be no problem. The more complicated issue then is how to check if Bullet is working right with the modified data set. But i'll try this.

And for my second question i got a hint:
http://code.google.com/p/bullet/issues/detail?id=163#c1
So Bullet - at least partly - seems able to handle self collison from soft bodies.


But now i got two new problems:
At the moment i try to integrate Bullet to my workspace where i've implemented my cutting approach. I started with integrating rigid bodys because i need them to for my programm (especially for my cutting tool). As suggested in the manual i first tried the btDefaultMotionState to render my objects (i use OpenGl for that).

But i got the problem, that every second simulation step i got the initial value for the position from the MotionState. So it looks like there would be two objects in the scene, one that remains at starting point and one moving around. I tried to write an own motion state but the problem remains. Can someone give me an advice to fix that?

The second problem is about the position of the collision shape. I try to show it in the attached sketch:
sketch.jpg
I wanted to create a floor so i set the y value of the startTrasform to -5 but it seems to have different effects on the MotionState and the collision shape. Any suggestions to solve this problem?

Eventually one last question for now: In future i may have to simulate large objects as soft bodies. But the deformation would be only very local on small areas. Iss there a way to configure Bullet to only calculate soft body dynamics on specific areas of an object?

I realy hope you can help me and looking forward to answers.

Flo
You do not have the required permissions to view the files attached to this post.
PolyFlo
Posts: 17
Joined: Fri Apr 03, 2009 9:12 am

Re: Implemeting Cutting of Softbodies with volume preservation

Post by PolyFlo »

Has Nobody a idea what can be wrong?

Here iss my Code. I realy hope someone can find my mistake. I need that for my study thats why its realy important for me.

MotionState:

Code: Select all

QtTetraMotionState::QtTetraMotionState(const btTransform &initialpos)
{
	m_PosInit = initialpos;
	m_Pos = initialpos.getOrigin();
	m_RotAngle = 0.0;
	m_RotAxis = btVector3(1,0,0);
}

void QtTetraMotionState::getWorldTransform(btTransform &worldTrans)const
{
	worldTrans = m_PosInit;
}

void QtTetraMotionState::setWorldTransform(const btTransform &worldTrans) 
{
	m_PosInit = worldTrans;
	btQuaternion rot = worldTrans.getRotation();
	m_RotAngle = rot.getAngle();
	m_RotAxis = rot.getAxis();
	m_Pos = worldTrans.getOrigin();

	return;
}
Object Class:

Code: Select all

void BulletTestQuad::initBullet(Vertex initPos)
{
	btTransform transform;
	transform.setIdentity();
	transform.setOrigin(btVector3(initPos.x,initPos.y,initPos.z));
	
	m_MotionState = new QtTetraMotionState(transform);

	m_Shape = new btBoxShape(btVector3(btScalar(m_Kantenlaenge),btScalar(m_Kantenlaenge),btScalar(m_Kantenlaenge)));

	btVector3 localInertia(0,0,0);
	if (m_Mass>PERCESION)
	{
		m_Shape->calculateLocalInertia(m_Mass,localInertia);
	}

	btRigidBody::btRigidBodyConstructionInfo rbInfo(m_Mass,m_MotionState,m_Shape,localInertia);
	m_Body = new btRigidBody(rbInfo);

	return;
}

void BulletTestQuad::render(Rendermode mode, bool renderNormals, bool showAABB)
{
	glPushMatrix(); 
	{
		glColor3d(m_Color.x,m_Color.y,m_Color.z);
		if(m_Mass<PERCESION)
		{
			btScalar m[16];
			m_MotionState->m_PosInit.getOpenGLMatrix(m);
			glMultMatrixf(m);
		}
		else
		{
			/////////////////////
			glRotated(m_MotionState->m_RotAngle, m_MotionState->m_RotAxis.x(),m_MotionState->m_RotAxis.y(),m_MotionState->m_RotAxis.z());
			glTranslated(m_MotionState->m_Pos.x(),m_MotionState->m_Pos.y(),m_MotionState->m_Pos.z());
			/////////////////////
		}
		glutSolidCube(m_Kantenlaenge);
	}
	glPopMatrix();
}
Main initialisation:

Code: Select all

void GlWidget::initBullet()
{
	m_collisionConfiguration = new btDefaultCollisionConfiguration();
	m_dispatcher = new	btCollisionDispatcher(m_collisionConfiguration);
	m_broadphase = new btDbvtBroadphase();
	btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver();
	m_solver = sol;
	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
	m_dynamicsWorld->setGravity(btVector3(0,-10,0));
}

void GlWidget::initRenderObjects()
{
	BulletTestQuad* wuerfel = new BulletTestQuad(0.1f, Vertex(0,4,0),1.0);
	wuerfel->setColor(Vertex(1.0,0,0));
	BulletTestQuad* wuerfel2 = new BulletTestQuad(0.1f, Vertex(0,6,0),0.5);
	wuerfel2->setColor(Vertex(1.0,0,0));
	BulletTestQuad* boden = new BulletTestQuad(0.0f, Vertex(0,0.0,0),2.0);
	boden->setColor(Vertex(0,1.0,1.0));

	renderObjects.push_back(dynamic_cast<OGLRenderObject*>(wuerfel));
	renderObjects.push_back(dynamic_cast<OGLRenderObject*>(wuerfel2));
	renderObjects.push_back(dynamic_cast<OGLRenderObject*>(boden));

	this->m_dynamicsWorld->addRigidBody(wuerfel->getRigidBody());
	this->m_dynamicsWorld->addRigidBody(wuerfel2->getRigidBody());
	this->m_dynamicsWorld->addRigidBody(boden->getRigidBody());
}
I hope for your help.

regards
Flo
PolyFlo
Posts: 17
Joined: Fri Apr 03, 2009 9:12 am

Re: Implemeting Cutting of Softbodies with volume preservation

Post by PolyFlo »

Ok, the two problems are solved.

First i missunderstood the parameter for the collision-shape. And the second one was a mistake in my program. My init-method was called twice what condused Bullet.
PolyFlo
Posts: 17
Joined: Fri Apr 03, 2009 9:12 am

Re: Implemeting Cutting of Softbodies with volume preservation

Post by PolyFlo »

Now i have another "problem". In my application are two diffrent objects: The ground, which is a rigid body, and a soft body cube. And the problem is that the soft body is continuously moving. Just a little bit but it don't hold its position. For both objetcs the friction is 1.0, the gravity is (0,-60,0). Why can this happen?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Implemeting Cutting of Softbodies with volume preservation

Post by Erwin Coumans »

The soft body friction model is not perfect so some small motion/jitter is expected, especially when using increased gravity.

It would be good if this gets improved at some stage. Can you reproduce it in the existing SoftBody demo?
Thanks,
Erwin
PolyFlo
Posts: 17
Joined: Fri Apr 03, 2009 9:12 am

Re: Implemeting Cutting of Softbodies with volume preservation

Post by PolyFlo »

Erwin Coumans wrote:The soft body friction model is not perfect so some small motion/jitter is expected, especially when using increased gravity.

It would be good if this gets improved at some stage. Can you reproduce it in the existing SoftBody demo?
Thanks,
Erwin
I haven' t tried it so far. I'll chek this later, but now I'm a little short in time because currently I'm writing my master thesis (although Bullet is part of it).
Last edited by PolyFlo on Thu Aug 27, 2009 11:08 am, edited 1 time in total.
PolyFlo
Posts: 17
Joined: Fri Apr 03, 2009 9:12 am

Re: Implemeting Cutting of Softbodies with volume preservation

Post by PolyFlo »

I have abother question about soft bodies, in special the generateBendingConstraints()-method.
If the first parameter of this method is less two my soft body collapses. In past I only used soft bodies that have a surface but no real interior. Now I changed the soft body to a tetrahedral model. And this Model doesn't collapse, even if i set the first parameter of generateBendingConstraints to one.
My suggestion is, that it is this way because of the additional links inside the soft body but I am not sure. Does anybody knows that? Or can correct me if I'm wrong?