Access to the Bullet engine via Blender python API

Hello everyone,

I am part of a research group and we want to create a magnet simulation in Blender.
Unfortunately, the existing force fields and the simulation zone are not powerful enough to achieve a correct simulation and integrate it into the rigid body dynamics or other simulations.
To our knowledge, it is not possible to apply forces/torque to bodies in the python API either. (Please correct me if we are wrong here).

Our approach would be to make parts of the bullet engine used in Blender accessible for the Python API. And then add the simulation via plugin. This way one can create all kinds of simulations that are still connected to the central blender physics.
Alternatively, we could certainly also use pyBullet, like bpyBullet.
but then, as we understand it, you would have 2 physics engines that would have to coexist, calculate and be synchronized somehow. If you have several simulation plugins then even more.

For now, we will limit ourselves to RBD. This means that only applyCentralForce, applyTorque, applyForce, applyCentralImpulse, applyTorqueImpulse and applyImpulse from the btRigidBody class should be required. Possibly later some collision detection things for acceleration/adaptive discretization.

Can anyone tell us if this is a way that is likely to be accepted or does it contradict any development plans? And ideally: Does anyone have an entry point for us to implement?

Best regards
Sebastian

1 Like

I think this type of API should not be accepted, as I think trying to provide API stability for this kind of functionality is going to limit for future changes and be too much of a maintenance burden. It’s too low level.

I think ideally geometry nodes gain support for rigid body simulation in the future, in a way that provides more control over these quantities.

Let me interpret your statement like this:

  1. the old simulation system will sooner or later be replaced by the geometry nodes?
  2. we would either have to code the whole simulation directly into the C++ part (which I now assume is too specific to be of general use and therefore not accepted). Or we have to contribute a ton to the geometry nodes or wait until the geometry nodes are ready to do real RBD/SBD etc.?

Even if we were to accept a API like this, I don’t think it would help you much as the interactions we have between our different simulation systems are very rudimentary and in most cases does not play well together at all.

To me it seems like we are running into the XY problem because using our bullet backend to try to simulate magnets (and I’m guessing magnetic fields) seems like a very strange solution if simulating accurate magnetic forces is what you want to achieve.

So what is it exactly that you are trying to achieve here? What problem are you researching that would benefit from this?
Simulating magnetic forces is one thing, but then extrapolating and stating that you want to have it potentially integrate with fluid/cloth and/or rigidbody simulation is quite a leap. Especially if rudimentary force fields are not enough to fake it if this is only for aesthetics.

1 Like

It’s not about aesthetics. Basically, several professors are trying to achieve their own goals through this simulation. One of them wants to simulate the properties of rotating magnetic systems (like here (yt video)) and “play around” with them. Another group is trying to develop effective protection against magnetic fields for medical devices (so that devices that measure magnetic fields and devices that generate magnetic fields can exist relatively close to each other). To do this, however, they also have to experiment with different materials and arrangements. So it’s definitely about achieving a scientific simulation that is relatively accurate.

We know, Blender is not designed as a scientific simulation system. Basically we want to use Blender for its ease in use. It would be really fun to play around and easy to create and change new setups both in UI and via code. Which would be much nicer then having to code it, compile it test it and so on.
And we thought at least some niche people in the comunity would be happy to have such type of simulation (such as: 1 and i am not allowed to post mor than two links ;)). We can also create a plugin version with some simplifications, so that it can be used by people that have no degree in physics. And the ability to add forces/momentum on objects via python would also allow for other kinds of simulations.

The XY problem could be. Maybe we’re on the wrong track, so I’m grateful for the discussion.

However, we do not want to use the bullet engine to simulate the magnetic forces/fields. We only want to pass the forces and torques of the fields calculated by us in a python/cython plugin to the engine to let them interact with the existing simulations (first RBD, later if possible fluid/cloth/SBD).

So what you are saying is that your simulation systems dont work together nicely and adding one access point to insert forces/momentum would add more points of failure.
So your recommendation would be: dont use Blender for that?
Or should we calculate all simulations ourselves (or via frameworks) externally and just visualize and modify it inside blender using the python API?

I have to say, that I like the geometry nodes, but they are at least in the current state not capable in doing what we want. But if you say so, we can discuss what is missing and if it would be realistic that we code that…

Edit:
We could also try to extend the bullet engine itself if this would be a better way. But then we would have to integrate the whole extension in Blender. If you prefere that, we can try that, but since you said the simulation parts already dont work together smoothly and you seem to want to shift away from the conventional simulation anyhow, I dont think this is the way (Mandalorian emoji)

Yes, that’s the long term goal.

Yes, or have a Blender fork specifically for your research where you add such APIs. At least to prove that the concept works. It would not surprise me that you find out you need more control anyway, over e.g. time stepping, collisions, constraints.

1 Like

Hmm, I think it might be better to build up the geometry of what you want to simulate inside of Blender and not have Blender do any of the simulation at all. You can add tags or special properties to the geometry and then export this data to a simulation program you have written that is outside of Blender.

You could then use the output of the simulation program and import it back into Blender to visualize it.

I would recommend to not use Blender for this kind of simulation, yes. Our physics systems are not built to be accurate, so you will most likely not get the results you want if you try to uses them for scientific research.

Of course you could try to do a fork for yourself and see what you can do.
But if you do a fork, I would recommend looking into doing this by introducing new nodes and/or improving the simulation node system.

1 Like