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>2019-07-16 17:04:22 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2019-07-16 17:08:32 +0300
commit105ae3be9993a646615499bf793cb14549e4104d (patch)
treeb21dc56f3ae11611a3f7e93007e831f976dca62e /source/blender/blenkernel/intern/rigidbody.c
parente6e69a28ab28631b2b1b99f55fb618459e7671ad (diff)
Fix T66944: Rigid Body Constraint in duplicated collection is not added to RigidBodyConstraints collection.
We only had a very limited, specific handling of that in collection duplication code, but this has to be handled at a much more general level in Object copy code itself, since it makes no sense to duplicate rigidbody object data without adding new copy to relevant rigidbody collections... WARNING: This is a fairly risky rework of rigidbody handling logic when copying an Object data-block. It is *NOT* considered safe enough for 2.80 release. I tried to take into account copy flags to not mess with other IDs (collections) when we are copying outside of Main, and also not do deg tags when this is forbidden, but risk of something going wrong here is too high...
Diffstat (limited to 'source/blender/blenkernel/intern/rigidbody.c')
-rw-r--r--source/blender/blenkernel/intern/rigidbody.c60
1 files changed, 52 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index a3a0ebd6cb3..c9b18dfc7e6 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -34,6 +34,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_math.h"
+#include "BLI_listbase.h"
#ifdef WITH_BULLET
# include "RBI_api.h"
@@ -228,7 +229,7 @@ void BKE_rigidbody_free_constraint(Object *ob)
* be added to relevant groups later...
*/
-RigidBodyOb *BKE_rigidbody_copy_object(const Object *ob, const int flag)
+static RigidBodyOb *rigidbody_copy_object(const Object *ob, const int flag)
{
RigidBodyOb *rboN = NULL;
@@ -249,7 +250,7 @@ RigidBodyOb *BKE_rigidbody_copy_object(const Object *ob, const int flag)
return rboN;
}
-RigidBodyCon *BKE_rigidbody_copy_constraint(const Object *ob, const int UNUSED(flag))
+static RigidBodyCon *rigidbody_copy_constraint(const Object *ob, const int UNUSED(flag))
{
RigidBodyCon *rbcN = NULL;
@@ -268,6 +269,54 @@ RigidBodyCon *BKE_rigidbody_copy_constraint(const Object *ob, const int UNUSED(f
return rbcN;
}
+void BKE_rigidbody_object_copy(Main *bmain, Object *ob_dst, const Object *ob_src, const int flag)
+{
+ ob_dst->rigidbody_object = rigidbody_copy_object(ob_src, flag);
+ ob_dst->rigidbody_constraint = rigidbody_copy_constraint(ob_src, flag);
+
+ if (flag & LIB_ID_CREATE_NO_MAIN) {
+ return;
+ }
+
+ /* We have to ensure that duplicated object ends up in relevant rigidbody collections...
+ * Otherwise duplicating the RB data itself is meaningless. */
+ LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
+ RigidBodyWorld *rigidbody_world = scene->rigidbody_world;
+
+ if (rigidbody_world != NULL) {
+ bool need_objects_update = false;
+ bool need_constraints_update = false;
+
+ if (ob_dst->rigidbody_object) {
+ if (BKE_collection_has_object(rigidbody_world->group, ob_src)) {
+ BKE_collection_object_add(bmain, rigidbody_world->group, ob_dst);
+ need_objects_update = true;
+ }
+ }
+ if (ob_dst->rigidbody_constraint) {
+ if (BKE_collection_has_object(rigidbody_world->constraints, ob_src)) {
+ BKE_collection_object_add(bmain, rigidbody_world->constraints, ob_dst);
+ need_constraints_update = true;
+ }
+ }
+
+ if ((flag & LIB_ID_CREATE_NO_DEG_TAG) == 0 &&
+ (need_objects_update || need_constraints_update)) {
+ BKE_rigidbody_cache_reset(rigidbody_world);
+
+ DEG_relations_tag_update(bmain);
+ if (need_objects_update) {
+ DEG_id_tag_update(&rigidbody_world->group->id, ID_RECALC_COPY_ON_WRITE);
+ }
+ if (need_constraints_update) {
+ DEG_id_tag_update(&rigidbody_world->constraints->id, ID_RECALC_COPY_ON_WRITE);
+ }
+ DEG_id_tag_update(&ob_dst->id, ID_RECALC_TRANSFORM);
+ }
+ }
+ }
+}
+
/* ************************************** */
/* Setup Utilities - Validate Sim Instances */
@@ -1983,13 +2032,8 @@ void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime
# pragma GCC diagnostic ignored "-Wunused-parameter"
# endif
-struct RigidBodyOb *BKE_rigidbody_copy_object(const Object *ob, const int flag)
-{
- return NULL;
-}
-struct RigidBodyCon *BKE_rigidbody_copy_constraint(const Object *ob, const int flag)
+void BKE_rigidbody_object_copy(Main *bmain, Object *ob_dst, const Object *ob_src, const int flag)
{
- return NULL;
}
void BKE_rigidbody_validate_sim_world(Scene *scene, RigidBodyWorld *rbw, bool rebuild)
{