0
$\begingroup$

I wanted to know where exactly in sources, Blender implements the Bullet Physics for its rigid body constraint solving. That is, where does it pass the arguments such as Rigid Bodies, their orientation, mass, so on in order to set-up the constraint.

Thanks in advance.

$\endgroup$
0
$\begingroup$

The following files contain the implementation of the rigid bodies:

For the parts of code that use the Bullet Physics, search for the WITH_BULLET macro.


Setting the properties and executing the rigid body simulation are separate operations.

Adding a rigid body simulation to an object in the UI results in call to ED_rigidbody_object_add (rigidbody_object.c) which in turn calls BKE_rigidbody_add_object (rigidbody.c). This functions creates the rigid body world by calling rigidbody_add_object_to_scene() (rigidbody.c) in case it doesn't exist and allocates the memory for RigidBodyOb through BKE_rigidbody_create_object() (rigidbody.c) and assigns default values.

For instance the mass property is displayed in the PHYSICS_PT_rigid_body_settings panel (properties_physics_rigidbody.py). It references the RNA property defined in rna_rigidbody.c which calls rna_RigidBodyOb_mass_set() when a new value is assigned through the UI. This stores the value in RigidBodyOb of the object and updates the state of the Bullet Physics through RB_body_set_mass() (rb_bullet_api.cpp).

Adding a rigid body constraint results in a call to ED_rigidbody_constraint_add() (rigidbody_constraint.c). A constraint collection is created if it doesn't already exist. The constraint is created through BKE_rigidbody_create_constraint (rigidbody.c) and added to the constraint collection through BKE_collection_object_add() (rigidbody.c).

When starting the simulation it executes the function BKE_rigidbody_eval_simulation (deg_builder_nodes.cc) which calls BKE_rigidbody_do_simulation (rigidbody.c). It uses the properties for the world, objects and constraints that were previously assigned.


The explanation of the call stack is a simplification of all the operations that happen during configuration and simulation. They are meant as an overview for where certain steps can be found in the code and not a complete explanation of the performed operations.

$\endgroup$
  • $\begingroup$ Thank you very much ;-) $\endgroup$ – QuantumCoderQC Oct 30 '19 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.