Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2018-12-10 17:01:32 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2018-12-10 17:10:29 +0300
commit7f98ba4725f992e7f982ed4f0f7e910790380de3 (patch)
tree8dd0cc2da5e362749c766c83091131757a7adaba /source/blender/blenkernel/intern/rigidbody.c
parent073a011f91a52cf1648b2d76606f0f2fff412098 (diff)
Proper fix for rigidbody collections's objects missing rb data.
We cannot let those data be generated on-the-fly in RBW evaluation anymore, since those would be added to CoW eval object and never ported back to orig objects. We *could* get orig objects in eval code, of course, but as in constratints, this is not really threadsafe and future proof, depsgraph evaluation should really write back to orig data as little as possible. So instead, add code to ensure required data is generated to objects when their collection is added to rigidbody world. Note that we *may* want to clean that up once collection is no more used by RB? On the other hand, people might want to keep those data around to be able to switch between different setups easily... So think it's OK to keep them at least for now.
Diffstat (limited to 'source/blender/blenkernel/intern/rigidbody.c')
-rw-r--r--source/blender/blenkernel/intern/rigidbody.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 9ca8c834bb9..2d035c271d2 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1069,6 +1069,7 @@ RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type)
/* flag cache as outdated */
BKE_rigidbody_cache_reset(rbw);
+ rbo->flag |= (RBO_FLAG_NEEDS_VALIDATE | RBO_FLAG_NEEDS_RESHAPE);
/* return this object */
return rbo;
@@ -1099,6 +1100,7 @@ RigidBodyCon *BKE_rigidbody_create_constraint(Scene *scene, Object *ob, short ty
rbc->flag |= RBC_FLAG_ENABLED;
rbc->flag |= RBC_FLAG_DISABLE_COLLISIONS;
+ rbc->flag |= RBC_FLAG_NEEDS_VALIDATE;
rbc->spring_type = RBC_SPRING_TYPE2;
@@ -1143,6 +1145,35 @@ RigidBodyCon *BKE_rigidbody_create_constraint(Scene *scene, Object *ob, short ty
return rbc;
}
+void BKE_rigidbody_objects_collection_validate(Scene *scene, RigidBodyWorld *rbw)
+{
+ if (rbw->group != NULL) {
+ FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(rbw->group, object)
+ {
+ if (object->type != OB_MESH || object->rigidbody_object != NULL) {
+ continue;
+ }
+ object->rigidbody_object = BKE_rigidbody_create_object(scene, object, RBO_TYPE_ACTIVE);
+ }
+ FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
+ }
+}
+
+void BKE_rigidbody_constraints_collection_validate(Scene *scene, RigidBodyWorld *rbw)
+{
+ if (rbw->constraints != NULL) {
+ FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(rbw->constraints, object)
+ {
+ if (object->rigidbody_constraint != NULL) {
+ continue;
+ }
+ object->rigidbody_constraint = BKE_rigidbody_create_constraint(scene, object, RBC_TYPE_FIXED);
+ }
+ FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
+ }
+}
+
+
/* ************************************** */
/* Utilities API */
@@ -1395,7 +1426,10 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph, Scene *scene, Rigi
/* update transformation matrix of the object so we don't get a frame of lag for simple animations */
BKE_object_where_is_calc(depsgraph, scene, ob);
+ /* TODO remove this whole block once we are sure we never get NULL rbo here anymore. */
+ /* This cannot be done in CoW evaluation context anymore... */
if (rbo == NULL) {
+ BLI_assert(!"CoW object part of RBW object collection without RB object data, should not happen.\n");
/* Since this object is included in the sim group but doesn't have
* rigid body settings (perhaps it was added manually), add!
* - assume object to be active? That is the default for newly added settings...
@@ -1426,8 +1460,8 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph, Scene *scene, Rigi
// XXX: we assume that this can only get applied for active/passive shapes that will be included as rigidbodies
RB_body_set_collision_shape(rbo->shared->physics_object, rbo->shared->physics_shape);
}
- rbo->flag &= ~(RBO_FLAG_NEEDS_VALIDATE | RBO_FLAG_NEEDS_RESHAPE);
}
+ rbo->flag &= ~(RBO_FLAG_NEEDS_VALIDATE | RBO_FLAG_NEEDS_RESHAPE);
/* update simulation object... */
rigidbody_update_sim_ob(depsgraph, scene, rbw, ob, rbo);
@@ -1446,7 +1480,10 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph, Scene *scene, Rigi
/* update transformation matrix of the object so we don't get a frame of lag for simple animations */
BKE_object_where_is_calc(depsgraph, scene, ob);
+ /* TODO remove this whole block once we are sure we never get NULL rbo here anymore. */
+ /* This cannot be done in CoW evaluation context anymore... */
if (rbc == NULL) {
+ BLI_assert(!"CoW object part of RBW constraints collection without RB constraint data, should not happen.\n");
/* Since this object is included in the group but doesn't have
* constraint settings (perhaps it was added manually), add!
*/
@@ -1464,8 +1501,8 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph, Scene *scene, Rigi
else if (rbc->flag & RBC_FLAG_NEEDS_VALIDATE) {
rigidbody_validate_sim_constraint(rbw, ob, false);
}
- rbc->flag &= ~RBC_FLAG_NEEDS_VALIDATE;
}
+ rbc->flag &= ~RBC_FLAG_NEEDS_VALIDATE;
}
FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
}