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.
This commit is contained in:
Sybren A. Stüvel 2018-07-03 18:20:44 +02:00
parent 13ec4be594
commit 75b5ff6698
3 changed files with 12 additions and 18 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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));