[Bf-blender-cvs] [75b5ff6698f] blender2.8: Softbody: unified copy functions

Sybren A. Stüvel noreply at git.blender.org
Wed Jul 4 11:45:29 CEST 2018


Commit: 75b5ff6698f5c1d50152cfb68530ac6a4ead999e
Author: Sybren A. Stüvel
Date:   Tue Jul 3 18:20:44 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB75b5ff6698f5c1d50152cfb68530ac6a4ead999e

Softbody: unified copy functions

This unifies two almost-identical functions at the expense of having to
add one single 'flag' value at one call.

This makes copy_softbody() aware of the source/dest objects, allowing it
to make a distinction between doing depsgraph evaluation copies and real
object copies. This will be used in an upcoming commit to ensure that
the pointcache is shared between CoW copies, similar to the current
approach for rigidbody simulation.

===================================================================

M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/object.c
M	source/blender/editors/object/object_edit.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index a54b244f5fd..0122185fd2a 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -56,10 +56,9 @@ void BKE_object_workob_clear(struct Object *workob);
 void BKE_object_workob_calc_parent(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct Object *workob);
 
 void BKE_object_transform_copy(struct Object *ob_tar, const struct Object *ob_src);
-struct SoftBody *copy_softbody(const struct SoftBody *sb, const int flag);
+void BKE_object_copy_softbody(struct Object *ob_dst, const struct Object *ob_src, const int flag);
 struct ParticleSystem *BKE_object_copy_particlesystem(struct ParticleSystem *psys, const int flag);
 void BKE_object_copy_particlesystems(struct Object *ob_dst, const struct Object *ob_src, const int flag);
-void BKE_object_copy_softbody(struct Object *ob_dst, const struct Object *ob_src);
 void BKE_object_free_particlesystems(struct Object *ob);
 void BKE_object_free_softbody(struct Object *ob);
 void BKE_object_free_curve_cache(struct Object *ob);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 8295fccc810..09e1ca62b92 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -275,7 +275,7 @@ void BKE_object_link_modifiers(Scene *scene, struct Object *ob_dst, const struct
 
 		switch (md->type) {
 			case eModifierType_Softbody:
-				BKE_object_copy_softbody(ob_dst, ob_src);
+				BKE_object_copy_softbody(ob_dst, ob_src, 0);
 				break;
 			case eModifierType_Skin:
 				/* ensure skin-node customdata exists */
@@ -836,11 +836,16 @@ Object *BKE_object_add_from(
 	return ob;
 }
 
-SoftBody *copy_softbody(const SoftBody *sb, const int flag)
+void BKE_object_copy_softbody(struct Object *ob_dst, const struct Object *ob_src, const int flag)
 {
+	SoftBody *sb = ob_src->soft;
 	SoftBody *sbn;
 
-	if (sb == NULL) return(NULL);
+	ob_dst->softflag = ob_src->softflag;
+	if (sb == NULL) {
+		ob_dst->soft = NULL;
+		return;
+	}
 
 	sbn = MEM_dupallocN(sb);
 
@@ -878,7 +883,7 @@ SoftBody *copy_softbody(const SoftBody *sb, const int flag)
 	if (sb->effector_weights)
 		sbn->effector_weights = MEM_dupallocN(sb->effector_weights);
 
-	return sbn;
+	ob_dst->soft = sbn;
 }
 
 ParticleSystem *BKE_object_copy_particlesystem(ParticleSystem *psys, const int flag)
@@ -967,14 +972,6 @@ void BKE_object_copy_particlesystems(Object *ob_dst, const Object *ob_src, const
 	}
 }
 
-void BKE_object_copy_softbody(Object *ob_dst, const Object *ob_src)
-{
-	if (ob_src->soft) {
-		ob_dst->softflag = ob_src->softflag;
-		ob_dst->soft = copy_softbody(ob_src->soft, 0);
-	}
-}
-
 static void copy_object_pose(Object *obn, const Object *ob, const int flag)
 {
 	bPoseChannel *chan;
@@ -1202,7 +1199,7 @@ void BKE_object_copy_data(Main *UNUSED(bmain), Object *ob_dst, const Object *ob_
 			ob_dst->pd->rng = MEM_dupallocN(ob_src->pd->rng);
 		}
 	}
-	ob_dst->soft = copy_softbody(ob_src->soft, flag_subdata);
+	BKE_object_copy_softbody(ob_dst, ob_src, flag_subdata);
 	ob_dst->rigidbody_object = BKE_rigidbody_copy_object(ob_src, flag_subdata);
 	ob_dst->rigidbody_constraint = BKE_rigidbody_copy_constraint(ob_src, flag_subdata);
 
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index ef9d32f7148..7dc4aa1d1b3 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -1050,10 +1050,8 @@ static void copy_attr(Main *bmain, Scene *scene, ViewLayer *view_layer, short ev
 					DEG_relations_tag_update(bmain);
 				}
 				else if (event == 23) {
-					base->object->softflag = ob->softflag;
 					if (base->object->soft) sbFree(base->object->soft);
-
-					base->object->soft = copy_softbody(ob->soft, 0);
+					BKE_object_copy_softbody(base->object, ob, 0);
 
 					if (!modifiers_findByType(base->object, eModifierType_Softbody)) {
 						BLI_addhead(&base->object->modifiers, modifier_new(eModifierType_Softbody));



More information about the Bf-blender-cvs mailing list