Deforming mesh physics simulation

Post Reply
Brejlounek
Posts: 2
Joined: Tue Jul 05, 2016 12:17 pm

Deforming mesh physics simulation

Post by Brejlounek »

Hi! I am trying move rigidbody by changing its vertices positions. I update rigid body collision frame every frame like this:

Code: Select all

	dynamicsWorld->stepSimulation(1.0 / FPS);
	dynamicsWorld->removeRigidBody(fallRigidBody);
	
	delete fallShape;
	fallShape = new btConvexHullShape(&vertices[0], vertices.size(), sizeof(btScalar) * 3);

	btShapeHull* hull = new btShapeHull(fallShape);
	btScalar margin = 0.001;// fallShape->getMargin();
	hull->buildHull(margin);

	vector<btScalar> vertDec;
	//filling in vertDec

	delete fallShape;
	delete hull;
	fallShape = new btConvexHullShape(&vertDec[0], vertDec.size()/3, sizeof(btScalar) * 3);

	fallRigidBody->setCollisionShape(fallShape);
	btScalar mass = 1;
	btVector3 fallInertia(0, 0, 0);
	fallShape->calculateLocalInertia(mass, fallInertia);
	fallRigidBody->setMassProps(1, fallInertia);

	dynamicsWorld->addRigidBody(fallRigidBody);
This works ok, mesh shifts around the world so it doesn't collide with ground and wobbles a bit but it doesn't do much more. This is what I got: https://www.youtube.com/watch?v=hi59t4Bj0H0

I would expect it to launch itself into air a bit and roll around, I would like it to have much more interesting movement. I tried setting different friction/rolling friction/restitution values, but neither worked well. I even tried to push the rigid body upward on every push-up by the ground, but it either didn't do anything or launched it into furious rotating spasms somewhere far away. :(

What am I doing wrong? Is something like this possible to do with bullet? I don't really want to write my own physics engine for this small thing... :(
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Deforming mesh physics simulation

Post by benelot »

What you are doing sounds more lilke a softbody application, since rigidbodies are meant to be rigid as the name says. Are you sure that you are really deforming the collision shape of the bullet rigidbody? It might be that you only deform your graphics.. You could try to use a softbody instead. Look at the example browser to see how you build one.
Brejlounek
Posts: 2
Joined: Tue Jul 05, 2016 12:17 pm

Re: Deforming mesh physics simulation

Post by Brejlounek »

benelot wrote:What you are doing sounds more lilke a softbody application, since rigidbodies are meant to be rigid as the name says. Are you sure that you are really deforming the collision shape of the bullet rigidbody? It might be that you only deform your graphics.. You could try to use a softbody instead. Look at the example browser to see how you build one.
Yes, I create new mesh with its collision convex hull every step using btShapeHull and later assign it to my rigidbody using fallRigidBody->setCollisionShape. I could create softbody instead but I am not sure if it would solve my problem or even work correctly: I am explicitly defining object's shape every simulation step and I don't need any softbody deformation calculated for me... I would just like my rigid body to react to changes of its mesh so it hops around, rolls and so on, not just stay in one place.
inzombiak
Posts: 16
Joined: Wed Nov 25, 2015 3:34 pm

Re: Deforming mesh physics simulation

Post by inzombiak »

I've been trying to do the same thing, but started by using a soft body first. I thought it would be cool to have the mesh deform when other objects came into contact with it. While pick and changing vertices of a soft body is possible and works well, the soft bodies in Bullet aren't very well documented and I ran into a lot of issues with things like the mesh exploding or friction. I wouldn't recommend them for anything more than basic object that you want to look cool.

As for what you have now, I think the issue is you are moving vertices around by changing the positions. When something like a popcorn kernel pops, what causes it to jump up or roll around is the force expanded on the pot. I think if you apply a force to the object at the vertex in the opposite direction of its position change you should get the desired effect. Dont forget to make sure that there is some solid surface in the direction of expansion before applying the force.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Deforming mesh physics simulation

Post by benelot »

I think for your case inzombiak is on the right track. Since you change the collision shape instantly in between two physics steps, meaning that you do not actually create an expansion as with a popcorn, but the popcorn is just suddenly a lot larger than before (within 0 time). In physics, this would cause the object to reach infinite velocity. In bullet physics, if you are lucky, it would jump a little as your terrain and the object resolve the penetration, however this might not look as desired. I would recommend as well to apply a slight force in the direction from the contact point with the ground to the center of mass. Scale it with the vertex displacement until it looks the way you want it (if you increase the distance between the vertex and the center of mass, apply a force which scales with this change).

Tell me if you did not understand it, I will try to explain again. And make another video of it if it works, I want so see the popcorn pop!
Post Reply