From 1e4b612d6a63ce781f229ddd6e3073a5d6951950 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 7 Feb 2018 11:14:08 +1100 Subject: Cleanup: add _types.h suffix to DNA headers --- source/blender/blenkernel/intern/rigidbody.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenkernel/intern/rigidbody.c') diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 03eb83376e7..39b0668f0b9 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -50,7 +50,7 @@ #include "DNA_group_types.h" #include "DNA_meshdata_types.h" #include "DNA_object_types.h" -#include "DNA_object_force.h" +#include "DNA_object_force_types.h" #include "DNA_rigidbody_types.h" #include "DNA_scene_types.h" -- cgit v1.2.3 From fe1a508e551bc8309f552d69da0b74f7f5f5d46f Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 21 Feb 2018 10:44:36 +0100 Subject: Depsgraph: Split debug flags Now it's possible to have debug messages for following things: - Graph construction - Graph evaluation - Graph tagging --- source/blender/blenkernel/intern/rigidbody.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/blender/blenkernel/intern/rigidbody.c') diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 39b0668f0b9..56e65b6f2c5 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -1690,7 +1690,7 @@ void BKE_rigidbody_rebuild_sim(EvaluationContext *UNUSED(eval_ctx), { float ctime = BKE_scene_frame_get(scene); - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { printf("%s at %f\n", __func__, ctime); } @@ -1705,7 +1705,7 @@ void BKE_rigidbody_eval_simulation(EvaluationContext *UNUSED(eval_ctx), { float ctime = BKE_scene_frame_get(scene); - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { printf("%s at %f\n", __func__, ctime); } @@ -1722,7 +1722,7 @@ void BKE_rigidbody_object_sync_transforms(EvaluationContext *UNUSED(eval_ctx), RigidBodyWorld *rbw = scene->rigidbody_world; float ctime = BKE_scene_frame_get(scene); - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { printf("%s on %s\n", __func__, ob->id.name); } -- cgit v1.2.3 From f02af0407fbcb4924a1a1f938629c814259ce086 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 7 Mar 2018 20:46:27 +1100 Subject: Cleanup: use _BEGIN suffix for group iterators --- source/blender/blenkernel/intern/rigidbody.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source/blender/blenkernel/intern/rigidbody.c') diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 011971b6677..d61cb0c9369 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -92,7 +92,7 @@ void BKE_rigidbody_free_world(RigidBodyWorld *rbw) if (rbw->physics_world) { /* free physics references, we assume that all physics objects in will have been added to the world */ if (rbw->constraints) { - FOREACH_GROUP_OBJECT(rbw->constraints, object) + FOREACH_GROUP_OBJECT_BEGIN(rbw->constraints, object) { if (object->rigidbody_constraint) { RigidBodyCon *rbc = object->rigidbody_constraint; @@ -105,7 +105,7 @@ void BKE_rigidbody_free_world(RigidBodyWorld *rbw) } if (rbw->group) { - FOREACH_GROUP_OBJECT(rbw->group, object) + FOREACH_GROUP_OBJECT_BEGIN(rbw->group, object) { if (object->rigidbody_object) { RigidBodyOb *rbo = object->rigidbody_object; @@ -1148,7 +1148,7 @@ void BKE_rigidbody_remove_object(Scene *scene, Object *ob) /* remove object from rigid body constraints */ if (rbw->constraints) { - FOREACH_GROUP_OBJECT(rbw->constraints, obt) + FOREACH_GROUP_OBJECT_BEGIN(rbw->constraints, obt) { if (obt && obt->rigidbody_constraint) { rbc = obt->rigidbody_constraint; @@ -1201,7 +1201,7 @@ static void rigidbody_update_ob_array(RigidBodyWorld *rbw) } i = 0; - FOREACH_GROUP_OBJECT(rbw->group, object) + FOREACH_GROUP_OBJECT_BEGIN(rbw->group, object) { rbw->objects[i] = object; i++; @@ -1332,7 +1332,7 @@ static void rigidbody_update_simulation(const struct EvaluationContext *eval_ctx * Memory management needs redesign here, this is just a dirty workaround. */ if (rebuild && rbw->constraints) { - FOREACH_GROUP_OBJECT(rbw->constraints, ob) + FOREACH_GROUP_OBJECT_BEGIN(rbw->constraints, ob) { RigidBodyCon *rbc = ob->rigidbody_constraint; if (rbc && rbc->physics_constraint) { @@ -1345,7 +1345,7 @@ static void rigidbody_update_simulation(const struct EvaluationContext *eval_ctx } /* update objects */ - FOREACH_GROUP_OBJECT(rbw->group, ob) + FOREACH_GROUP_OBJECT_BEGIN(rbw->group, ob) { if (ob->type == OB_MESH) { /* validate that we've got valid object set up here... */ @@ -1394,7 +1394,7 @@ static void rigidbody_update_simulation(const struct EvaluationContext *eval_ctx if (rbw->constraints == NULL) /* no constraints, move on */ return; - FOREACH_GROUP_OBJECT(rbw->constraints, ob) + FOREACH_GROUP_OBJECT_BEGIN(rbw->constraints, ob) { /* validate that we've got valid object set up here... */ RigidBodyCon *rbc = ob->rigidbody_constraint; @@ -1427,7 +1427,7 @@ static void rigidbody_update_simulation(const struct EvaluationContext *eval_ctx static void rigidbody_update_simulation_post_step(RigidBodyWorld *rbw) { - FOREACH_GROUP_BASE(rbw->group, base) + FOREACH_GROUP_BASE_BEGIN(rbw->group, base) { Object *ob = base->object; RigidBodyOb *rbo = ob->rigidbody_object; -- cgit v1.2.3 From f47a41a3d9f9850f852abb3d76bea2c8b281bb45 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 9 Mar 2018 11:44:42 +1100 Subject: Cleanup: iterator macros - put render iterator in own scope (would shadow it's own variable if used multiple times). - enforce semicolon at end of iterator macros. - no need to typedef one-off macro structs. --- source/blender/blenkernel/intern/rigidbody.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source/blender/blenkernel/intern/rigidbody.c') diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index d61cb0c9369..12a53f5f3e5 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -101,7 +101,7 @@ void BKE_rigidbody_free_world(RigidBodyWorld *rbw) } } } - FOREACH_GROUP_OBJECT_END + FOREACH_GROUP_OBJECT_END; } if (rbw->group) { @@ -114,7 +114,7 @@ void BKE_rigidbody_free_world(RigidBodyWorld *rbw) } } } - FOREACH_GROUP_OBJECT_END + FOREACH_GROUP_OBJECT_END; } /* free dynamics world */ RB_dworld_delete(rbw->physics_world); @@ -1157,7 +1157,7 @@ void BKE_rigidbody_remove_object(Scene *scene, Object *ob) } } } - FOREACH_GROUP_OBJECT_END + FOREACH_GROUP_OBJECT_END; } } @@ -1206,7 +1206,7 @@ static void rigidbody_update_ob_array(RigidBodyWorld *rbw) rbw->objects[i] = object; i++; } - FOREACH_GROUP_OBJECT_END + FOREACH_GROUP_OBJECT_END; } static void rigidbody_update_sim_world(Scene *scene, RigidBodyWorld *rbw) @@ -1341,7 +1341,7 @@ static void rigidbody_update_simulation(const struct EvaluationContext *eval_ctx rbc->physics_constraint = NULL; } } - FOREACH_GROUP_OBJECT_END + FOREACH_GROUP_OBJECT_END; } /* update objects */ @@ -1388,7 +1388,7 @@ static void rigidbody_update_simulation(const struct EvaluationContext *eval_ctx rigidbody_update_sim_ob(eval_ctx, scene, rbw, ob, rbo); } } - FOREACH_GROUP_OBJECT_END + FOREACH_GROUP_OBJECT_END; /* update constraints */ if (rbw->constraints == NULL) /* no constraints, move on */ @@ -1422,7 +1422,7 @@ static void rigidbody_update_simulation(const struct EvaluationContext *eval_ctx rbc->flag &= ~RBC_FLAG_NEEDS_VALIDATE; } } - FOREACH_GROUP_OBJECT_END + FOREACH_GROUP_OBJECT_END; } static void rigidbody_update_simulation_post_step(RigidBodyWorld *rbw) -- cgit v1.2.3 From 3baf31e73a7176fac8081b6648ce768b9504c2b1 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 16 Mar 2018 11:14:38 +0100 Subject: Depsgraph: Move evaluation debug prints to depsgraph This way we can easily control format and keep it consistent. And also possibly do other trickery, like coloring addresses! --- source/blender/blenkernel/intern/rigidbody.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'source/blender/blenkernel/intern/rigidbody.c') diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 56e65b6f2c5..c10f54a99eb 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -66,6 +66,8 @@ #include "BKE_rigidbody.h" #include "BKE_scene.h" +#include "DEG_depsgraph.h" + /* ************************************** */ /* Memory Management */ @@ -1689,11 +1691,7 @@ void BKE_rigidbody_rebuild_sim(EvaluationContext *UNUSED(eval_ctx), Scene *scene) { float ctime = BKE_scene_frame_get(scene); - - if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { - printf("%s at %f\n", __func__, ctime); - } - + DEG_debug_print_eval_time(__func__, scene->id.name, scene, ctime); /* rebuild sim data (i.e. after resetting to start of timeline) */ if (BKE_scene_check_rigidbody_active(scene)) { BKE_rigidbody_rebuild_world(scene, ctime); @@ -1704,11 +1702,7 @@ void BKE_rigidbody_eval_simulation(EvaluationContext *UNUSED(eval_ctx), Scene *scene) { float ctime = BKE_scene_frame_get(scene); - - if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { - printf("%s at %f\n", __func__, ctime); - } - + DEG_debug_print_eval_time(__func__, scene->id.name, scene, ctime); /* evaluate rigidbody sim */ if (BKE_scene_check_rigidbody_active(scene)) { BKE_rigidbody_do_simulation(scene, ctime); @@ -1721,11 +1715,7 @@ void BKE_rigidbody_object_sync_transforms(EvaluationContext *UNUSED(eval_ctx), { RigidBodyWorld *rbw = scene->rigidbody_world; float ctime = BKE_scene_frame_get(scene); - - if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { - printf("%s on %s\n", __func__, ob->id.name); - } - + DEG_debug_print_eval_time(__func__, ob->id.name, ob, ctime); /* read values pushed into RBO from sim/cache... */ BKE_rigidbody_sync_transforms(rbw, ob, ctime); } -- cgit v1.2.3 From 26a283deae7a3b78a197d4bcf4bfd288c598aedc Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sat, 31 Mar 2018 12:08:16 +0300 Subject: Use the newer version of the bullet 6dof spring constraint for rigidbody. The new constraint is slower and not backward compatible, but should be better, especially in the damping side. The new constraint also has a different valid range of the damping coefficient, and a limit implementation that bounces instead of making the object stationary. Reviewers: sergof Differential Revision: https://developer.blender.org/D3125 --- source/blender/blenkernel/intern/rigidbody.c | 70 +++++++++++++++------------- 1 file changed, 38 insertions(+), 32 deletions(-) (limited to 'source/blender/blenkernel/intern/rigidbody.c') diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index c10f54a99eb..b8873cca0fb 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -700,6 +700,39 @@ static void rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, bool /* --------------------- */ +static void rigidbody_constraint_set_limits(RigidBodyCon *rbc, void (*set_limits)(rbConstraint*,int,float,float)) +{ + if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_X) + set_limits(rbc->physics_constraint, RB_LIMIT_LIN_X, rbc->limit_lin_x_lower, rbc->limit_lin_x_upper); + else + set_limits(rbc->physics_constraint, RB_LIMIT_LIN_X, 0.0f, -1.0f); + + if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_Y) + set_limits(rbc->physics_constraint, RB_LIMIT_LIN_Y, rbc->limit_lin_y_lower, rbc->limit_lin_y_upper); + else + set_limits(rbc->physics_constraint, RB_LIMIT_LIN_Y, 0.0f, -1.0f); + + if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_Z) + set_limits(rbc->physics_constraint, RB_LIMIT_LIN_Z, rbc->limit_lin_z_lower, rbc->limit_lin_z_upper); + else + set_limits(rbc->physics_constraint, RB_LIMIT_LIN_Z, 0.0f, -1.0f); + + if (rbc->flag & RBC_FLAG_USE_LIMIT_ANG_X) + set_limits(rbc->physics_constraint, RB_LIMIT_ANG_X, rbc->limit_ang_x_lower, rbc->limit_ang_x_upper); + else + set_limits(rbc->physics_constraint, RB_LIMIT_ANG_X, 0.0f, -1.0f); + + if (rbc->flag & RBC_FLAG_USE_LIMIT_ANG_Y) + set_limits(rbc->physics_constraint, RB_LIMIT_ANG_Y, rbc->limit_ang_y_lower, rbc->limit_ang_y_upper); + else + set_limits(rbc->physics_constraint, RB_LIMIT_ANG_Y, 0.0f, -1.0f); + + if (rbc->flag & RBC_FLAG_USE_LIMIT_ANG_Z) + set_limits(rbc->physics_constraint, RB_LIMIT_ANG_Z, rbc->limit_ang_z_lower, rbc->limit_ang_z_upper); + else + set_limits(rbc->physics_constraint, RB_LIMIT_ANG_Z, 0.0f, -1.0f); +} + /** * Create physics sim representation of constraint given rigid body constraint settings * @@ -818,40 +851,13 @@ static void rigidbody_validate_sim_constraint(RigidBodyWorld *rbw, Object *ob, b RB_constraint_set_damping_6dof_spring(rbc->physics_constraint, RB_LIMIT_ANG_Z, rbc->spring_damping_ang_z); RB_constraint_set_equilibrium_6dof_spring(rbc->physics_constraint); - ATTR_FALLTHROUGH; - case RBC_TYPE_6DOF: - if (rbc->type == RBC_TYPE_6DOF) /* a litte awkward but avoids duplicate code for limits */ - rbc->physics_constraint = RB_constraint_new_6dof(loc, rot, rb1, rb2); - - if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_X) - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_LIN_X, rbc->limit_lin_x_lower, rbc->limit_lin_x_upper); - else - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_LIN_X, 0.0f, -1.0f); - - if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_Y) - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_LIN_Y, rbc->limit_lin_y_lower, rbc->limit_lin_y_upper); - else - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_LIN_Y, 0.0f, -1.0f); - - if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_Z) - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_LIN_Z, rbc->limit_lin_z_lower, rbc->limit_lin_z_upper); - else - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_LIN_Z, 0.0f, -1.0f); - - if (rbc->flag & RBC_FLAG_USE_LIMIT_ANG_X) - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_X, rbc->limit_ang_x_lower, rbc->limit_ang_x_upper); - else - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_X, 0.0f, -1.0f); - if (rbc->flag & RBC_FLAG_USE_LIMIT_ANG_Y) - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_Y, rbc->limit_ang_y_lower, rbc->limit_ang_y_upper); - else - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_Y, 0.0f, -1.0f); + rigidbody_constraint_set_limits(rbc, RB_constraint_set_limits_6dof_spring); + break; + case RBC_TYPE_6DOF: + rbc->physics_constraint = RB_constraint_new_6dof(loc, rot, rb1, rb2); - if (rbc->flag & RBC_FLAG_USE_LIMIT_ANG_Z) - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_Z, rbc->limit_ang_z_lower, rbc->limit_ang_z_upper); - else - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_Z, 0.0f, -1.0f); + rigidbody_constraint_set_limits(rbc, RB_constraint_set_limits_6dof); break; case RBC_TYPE_MOTOR: rbc->physics_constraint = RB_constraint_new_motor(loc, rot, rb1, rb2); -- cgit v1.2.3