rigid bodies violently jumping away

Post Reply
jochemspek
Posts: 5
Joined: Thu Feb 01, 2018 3:00 pm

rigid bodies violently jumping away

Post by jochemspek » Thu Feb 01, 2018 3:07 pm

Image

I'm having some issues with simulating certain rigid bodies using bullet physics in the python blender module. I've tried doing the same thing in c++ bullet, and pybullet, with the same results. The above gif illustrates what happens. I've gone through every fix/workaround I can think of, including:
  • check objects for holes, degenerate triangles, etc. everything seems fine.
  • perturbed physics parameters, including 0 friction, 100% bounciness, and vice versa, different mass settings, various damping parameters, etc.
  • increased solver iterations, reduced gravity, reduced timestep, etc.
  • fix one object in place using a constraint to a passive cube and remove the floor to eliminate possible problems with floor object
  • toggled use of collision margin
  • used trimesh to accurately calculate the center of gravity and mass

This assembly is a reduced version that I need to evaluate for clients, and it's quite important we get it right. I have *no* idea why this object keeps failing, and other objects seem to have the same problem.

I have prepared a git with all the relevant code and models here:

https://github.com/jochemborges/blender_pathology

the only requirement is the blender module.

If anyone could have a look and possibly shed some light on this, I'd much appreciate it!

thanks!

Jochem

ps, this is a copy of the post here: https://blender.stackexchange.com/quest ... mping-away
sorry for cross-posting, but I'm kinda stuck.

User avatar
drleviathan
Posts: 405
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: rigid bodies violently jumping away

Post by drleviathan » Thu Feb 01, 2018 4:22 pm

Your blender_pathology github repository appears to be empty. Maybe you forgot to push to it?

You have two rigid bodies connected by a constraint? If so, it looks like the constraint is unstable. I have a few theories about how it could get that way but I wouldn't want to speculate very far without more info.

User avatar
Erwin Coumans
Site Admin
Posts: 4101
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: rigid bodies violently jumping away

Post by Erwin Coumans » Thu Feb 01, 2018 4:38 pm

Please file a very simple PyBullet repro case and use the github issue tracker.

Keep it simple, no Blender, just plain PyBullet.

Also check out the PyBullet Quickstart Guide and examples and try to understand why the PyBullet examples work fine and your setup doesn't.

jochemspek
Posts: 5
Joined: Thu Feb 01, 2018 3:00 pm

Re: rigid bodies violently jumping away

Post by jochemspek » Thu Feb 01, 2018 6:13 pm

drleviathan wrote:
Thu Feb 01, 2018 4:22 pm
Your blender_pathology github repository appears to be empty. Maybe you forgot to push to it?

You have two rigid bodies connected by a constraint? If so, it looks like the constraint is unstable. I have a few theories about how it could get that way but I wouldn't want to speculate very far without more info.
i did push, but failed to notice a 403. fixed now, thanks.

there are no constraints in the setup, just separate bodies.

jochemspek
Posts: 5
Joined: Thu Feb 01, 2018 3:00 pm

Re: rigid bodies violently jumping away

Post by jochemspek » Thu Feb 01, 2018 6:13 pm

Erwin Coumans wrote:
Thu Feb 01, 2018 4:38 pm
Please file a very simple PyBullet repro case and use the github issue tracker.

Keep it simple, no Blender, just plain PyBullet.

Also check out the PyBullet Quickstart Guide and examples and try to understand why the PyBullet examples work fine and your setup doesn't.
I'll have a look tomorrow, thanks, i'll report back.

jochemspek
Posts: 5
Joined: Thu Feb 01, 2018 3:00 pm

Re: rigid bodies violently jumping away

Post by jochemspek » Fri Feb 02, 2018 8:24 am

@erwin couwmans, I see that in pybullet, there is only support for concave geometry in static objects. This unfortunately does not apply to my need to simulate the 'pin in hole' simulation that I describe in my original post. From the pybullet examples i understand that the only way to get concave geometry working for dynamic objects, is to do a convex decomposition first f.i. using V-HACD. However, my client requires more precision than V-HACD offers, and surprisingly, simulating concave meshes in blender works quite well except for my example of course. So I have 2 questions:
  • is bullet doing an inexact convex decomposition under the hood in the blender context and is that the reason for the problem I see ?
  • is there a way to use the concave geometry directly in a bullet simulation using python ?
I've updated my git repo with a pybullet example, where it's now obvious to me that bullet uses the convex hull for collisions. Also, here is a more elaborate showcase of the problem. As you can see, the spindles around the vertical beams of the lower assembly are simulated correctly, but the central pin that sits in the hole of the upper assembly comes loose although it should not due to the flange on top of the pin. The repo does not contain the larger assembly because of copyrights.

Image

thanks,

Jochem

User avatar
drleviathan
Posts: 405
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: rigid bodies violently jumping away

Post by drleviathan » Sat Feb 03, 2018 2:13 am

I'll offer some info:

Blender must be using a btCompoundShape under the hood for that simulation. There is no way it would bounce like that otherwise.

When using Bullet there is no way to use a fundamentally concave shape type for simulation of a dynamic object. The only solution is to use a convex shape, or btCompoundShape with many convex sub-shapes.

As to your specific task at hand:

You might be able to get better results with some tricks:

(1) Understand the collision margin. There are some default collision margins in the Bullet simulation and if the dimensions of the important details of your model are near those margins then you'll get unexpected results and easier tunneling. If you haven't heard about these margins yet you could watch this video. The default margin is around 0.04m (as I recall, dunno if Blender messes with that), which means your smallest important "flange" must be several multiples of that dimension before the simulation will start to look "correct".

(2) Artificially scale the dimensions AND time units. If your mechanism is naturally "small" then maybe you should artificially increase the dimension of the model to be 10x or 100x. You could adjust the acceleration of gravity and the unit of time accordingly to still get a realistic simulation, however under this scenario you might not be able to run the simulation in real-time: it might fall slower than real time. This might be ok if you're trying to make a movie of he result rather than have the object be interactive. However, if you run the simulation at 1000Hz (with double-precision, dunno what precision Blender would be using) and you didn't have too many other objects in the simulation I don't see why you couldn't make a 100x scaled version run in real-time on a modern machine.

(3) Use a Good convex decomposition shape approximation. The default VHACD algorithm produces convex hulls. By necessity convex hulls have a finite number of points that define their hull and as such their quality is limited for parts that do not have any facets (such as a round dowel). If you were to use an explici btCylinderShape for key subshapes of your collision shape then you would have better results. There are other subtler tricks about avoiding "hidden" faces between two neighboring convex hulls of the same shape that can help make your approximate shape more correct. I believe a hand-tuned convex decomposition of your model could improve the simulation a lot.

(4) Use a hinge constraint, or a sliding hinge constraint at pivot points. If it is an indisputable fact that your mechanism must spin at a particular point then you could create a constraint to assert that truth.

(5) Finally I'll point out that if you want "correct as possible" physics then you need to compute the correct inertia tensors for your RigidBodies. This means you would need to supply offset transforms to orient your local intertia tensor such that its eigenvectors align with the local cardinal axes (e.g. along local X, Y, and Z -- Bullet assumes this is true, so you must make it so). This isn't a concern if you just need it to look good enough to fool the human eye.

jochemspek
Posts: 5
Joined: Thu Feb 01, 2018 3:00 pm

Re: rigid bodies violently jumping away

Post by jochemspek » Mon Feb 05, 2018 5:31 am

Thank you your kind reply. The problem is that this simulation is to perform in an automated process where human-designed but random assemblies are put through a physics simulation, so it's impossible to fit the correct collision shapes by hand. Fortunately, I have made some progress. The (at least partial) solution was (indeed) to do a convex decomposition of the mesh, after chopping the entire thing up into manageable blocks.The whole process is this:
  • split the mesh into its components (mechanical separate parts)
  • subdivide those components into 3x3x3 blocks
  • split those blocks up into isolated parts
  • perform an approximate convex decomposition on those parts.
  • finally, assemble all the convex hulls into groups that approximate the original components
Image

Although it requires a lot of processing, the results are quite stunning. Using pybullet, you can now *interactively* manipulate one of the more complex assemblies in the set. I haven't tested this on other production models yet, but at least there is some real improvement in the quality of the simulation.

Thanks again for thinking with me here!

lazenby
Posts: 1
Joined: Sat Feb 10, 2018 7:31 am

Re: rigid bodies violently jumping away

Post by lazenby » Sat Feb 10, 2018 7:36 am

drleviathan wrote:
Sat Feb 03, 2018 2:13 am
I'll offer some info:

Blender must be using a btCompoundShape under the hood for that simulation. There is no way it would bounce like that otherwise.

When using Bullet there is no way to use a fundamentally concave shape type for simulation of a dynamic object. The only solution is to use a convex shape, or btCompoundShape with many convex sub-shapes.

As to your specific task at hand:

You might be able to get better results with some tricks:

(1) Understand the collision margin. There are some default collision margins in the Bullet simulation and if the dimensions of the important details of your model are near those margins then you'll get unexpected results and easier tunneling. If you haven't heard about these margins yet you could watch this video. The default margin is around 0.04m (as I recall, dunno if Blender messes with that), which means your smallest important "flange" must be several multiples of that dimension before the simulation will start to look "correct". Spanish dictionary

(2) Artificially scale the dimensions AND time units. If your mechanism is naturally "small" then maybe you should artificially increase the dimension of the model to be 10x or 100x. You could adjust the acceleration of gravity and the unit of time accordingly to still get a realistic simulation, however under this scenario you might not be able to run the simulation in real-time: it might fall slower than real time. bullet force. This might be ok if you're trying to make a movie of he result rather than have the object be interactive. However, if you run the simulation at 1000Hz (with double-precision, dunno what precision Blender would be using) and you didn't have too many other objects in the simulation I don't see why you couldn't make a 100x scaled version run in real-time on a modern machine.

(3) Use a Good convex decomposition shape approximation. The default VHACD algorithm produces convex hulls. By necessity convex hulls have a finite number of points that define their hull and as such their quality is limited for parts that do not have any facets (such as a round dowel). If you were to use an explici btCylinderShape for key subshapes of your collision shape then you would have better results. There are other subtler tricks about avoiding "hidden" faces between two neighboring convex hulls of the same shape that can help make your approximate shape more correct. I believe a hand-tuned convex decomposition of your model could improve the simulation a lot.

(4) Use a hinge constraint, or a sliding hinge constraint at pivot points. If it is an indisputable fact that your mechanism must spin at a particular point then you could create a constraint to assert that truth.

(5) Finally I'll point out that if you want "correct as possible" physics then you need to compute the correct inertia tensors for your RigidBodies. This means you would need to supply offset transforms to orient your local intertia tensor such that its eigenvectors align with the local cardinal axes (e.g. along local X, Y, and Z -- Bullet assumes this is true, so you must make it so). This isn't a concern if you just need it to look good enough to fool the human eye.
Blender must be using a btCompoundShape under the hood for that simulation

Post Reply