@@ -1273,6 +1273,8 @@ RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type)
12731273 rbo->lin_damping = 0 .04f ;
12741274 rbo->ang_damping = 0 .1f ;
12751275
1276+ rbo->gravity = 1 .0f ; /* full gravity influence by default */
1277+
12761278 rbo->col_groups = 0 ;
12771279
12781280 /* use triangle meshes for passive objects
@@ -2014,13 +2016,38 @@ static void rigidbody_update_external_forces(Depsgraph *depsgraph,
20142016 Scene *scene,
20152017 RigidBodyWorld *rbw)
20162018{
2019+ /* get world gravity */
2020+ float world_gravity[3 ];
2021+ if (rbw->shared ->runtime ->physics_world ) {
2022+ RB_dworld_get_gravity (rbw->shared ->runtime ->physics_world , world_gravity);
2023+ }
2024+ else {
2025+ zero_v3 (world_gravity);
2026+ }
2027+
20172028 FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (rbw->group , ob) {
20182029 /* only update if rigid body exists */
20192030 RigidBodyOb *rbo = ob->rigidbody_object ;
20202031 if (ob->type != OB_MESH || rbo->shared ->physics_object == nullptr ) {
20212032 continue ;
20222033 }
20232034
2035+ /* Apply per-body gravity weight */
2036+ if (rbo->type == RBO_TYPE_ACTIVE && (rbo->flag & RBO_FLAG_DISABLED) == 0 &&
2037+ rbo->gravity != 1 .0f && !is_zero_v3 (world_gravity))
2038+ {
2039+ float gravity_force[3 ];
2040+ float mass = RB_body_get_mass (static_cast <rbRigidBody *>(rbo->shared ->physics_object ));
2041+ /* Calculate the additional gravity force needed to achieve the desired gravity influence */
2042+ /* If gravity < 1.0, we need to reduce the effective gravity */
2043+ /* If gravity > 1.0, we need to increase the effective gravity */
2044+ float gravity_factor = rbo->gravity - 1 .0f ;
2045+ copy_v3_v3 (gravity_force, world_gravity);
2046+ mul_v3_fl (gravity_force, gravity_factor * mass);
2047+ RB_body_apply_central_force (static_cast <rbRigidBody *>(rbo->shared ->physics_object ),
2048+ gravity_force);
2049+ }
2050+
20242051 /* update influence of effectors - but don't do it on an effector */
20252052 /* only dynamic bodies need effector update */
20262053 if (rbo->type == RBO_TYPE_ACTIVE &&
0 commit comments