Commit: 3b4aca10c7b5e4130a22337dbca86d6784904a0f Author: Alexander Gavrilov Date: Mon Nov 23 23:42:05 2020 +0300 Branches: temp-angavrilov https://developer.blender.org/rB3b4aca10c7b5e4130a22337dbca86d6784904a0f
Constraints: refactor the D7437 patch adding Custom Space for constraints. As mentioned in the comments to that patch, I had an idea for a different way to do some technical aspects, but it was too complicated to force changes in the original patch. Thus I submit this follow up patch. First, instead of modifying all the get_constraint_targets and flush_constraint_targets callbacks, introduce wrapper functions for accessing constraint targets, convert all code to use them, and handle the new reference there uniformly for all constraints. This incidentally revealed a place in the Collada exporter that didn't clean up after retrieving the targets. Also, tag the special target with a flag so other code can handle it appropriately where necessary. This for instance allows dependency graph to know that the Use B-Bone Shape option doesn't affect this specific target. Finally, rename and simplify the function for initializing the custom space, and make sure it is called everywhere necessary. Differential Revision: https://developer.blender.org/D9732 =================================================================== M source/blender/blenkernel/BKE_constraint.h M source/blender/blenkernel/intern/action.c M source/blender/blenkernel/intern/armature.c M source/blender/blenkernel/intern/constraint.c M source/blender/blenkernel/intern/object.c M source/blender/depsgraph/intern/builder/deg_builder_relations.cc M source/blender/draw/engines/overlay/overlay_extra.c M source/blender/editors/armature/armature_add.c M source/blender/editors/armature/armature_naming.c M source/blender/editors/armature/armature_relations.c M source/blender/editors/armature/pose_select.c M source/blender/editors/object/object_constraint.c M source/blender/editors/transform/transform_mode.c M source/blender/io/collada/BCAnimationSampler.cpp M source/blender/io/collada/SceneExporter.cpp M source/blender/makesdna/DNA_constraint_types.h M source/blender/makesrna/intern/rna_constraint.c =================================================================== diff --git a/source/blender/blenkernel/BKE_constraint.h b/source/blender/blenkernel/BKE_constraint.h index 784b395dfa5..3fb0db680fd 100644 --- a/source/blender/blenkernel/BKE_constraint.h +++ b/source/blender/blenkernel/BKE_constraint.h @@ -236,6 +236,8 @@ void BKE_constraint_mat_convertspace(struct Object *ob, short to, const bool keep_scale); +int BKE_constraint_targets_get(struct bConstraint *con, struct ListBase *list); +void BKE_constraint_targets_flush(struct bConstraint *con, struct ListBase *list, bool no_copy); void BKE_constraint_target_matrix_get(struct Depsgraph *depsgraph, struct Scene *scene, struct bConstraint *con, @@ -249,7 +251,7 @@ void BKE_constraint_targets_for_solving_get(struct Depsgraph *depsgraph, struct bConstraintOb *ob, struct ListBase *targets, float ctime); -void BKE_constraint_custom_object_space_get(float r_mat[4][4], struct bConstraint *con); +void BKE_constraint_custom_object_space_init(struct bConstraintOb *cob, struct bConstraint *con); void BKE_constraints_solve(struct Depsgraph *depsgraph, struct ListBase *conlist, struct bConstraintOb *cob, diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index d609247a2c1..4b25412523a 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -1014,13 +1014,10 @@ void BKE_pose_channels_remove(Object *ob, else { /* Maybe something the bone references is being removed instead? */ for (con = pchan->constraints.first; con; con = con->next) { - const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; - if (cti && cti->get_constraint_targets) { - cti->get_constraint_targets(con, &targets); - + if (BKE_constraint_targets_get(con, &targets)) { for (ct = targets.first; ct; ct = ct->next) { if (ct->tar == ob) { if (ct->subtarget[0]) { @@ -1032,9 +1029,7 @@ void BKE_pose_channels_remove(Object *ob, } } - if (cti->flush_constraint_targets) { - cti->flush_constraint_targets(con, &targets, 0); - } + BKE_constraint_targets_flush(con, &targets, 0); } } diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 65fdc9278e1..5bf5bbbf501 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -2469,22 +2469,17 @@ static void pose_proxy_sync(Object *ob, Object *from, int layer_protected) /* constraints - set target ob pointer to own object */ for (con = pchanw.constraints.first; con; con = con->next) { - const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; - if (cti && cti->get_constraint_targets) { - cti->get_constraint_targets(con, &targets); - + if (BKE_constraint_targets_get(con, &targets)) { for (ct = targets.first; ct; ct = ct->next) { if (ct->tar == from) { ct->tar = ob; } } - if (cti->flush_constraint_targets) { - cti->flush_constraint_targets(con, &targets, 0); - } + BKE_constraint_targets_flush(con, &targets, 0); } } diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index b2b03d28483..78755c52ecc 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -972,30 +972,9 @@ static void default_get_tarmat_full_bbone(struct Depsgraph *UNUSED(depsgraph), } \ (void)0 -static void custom_space_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) +static bool is_custom_space_needed(bConstraint *con) { - func(con, (ID **)&con->space_object, false, userdata); -} - -static int get_space_tar(bConstraint *con, ListBase *list) -{ - if (!con || !list || - (con->ownspace != CONSTRAINT_SPACE_CUSTOM && con->tarspace != CONSTRAINT_SPACE_CUSTOM)) { - return 0; - } - bConstraintTarget *ct; - SINGLETARGET_GET_TARS(con, con->space_object, con->space_subtarget, ct, list); - return 1; -} - -static void flush_space_tar(bConstraint *con, ListBase *list, bool no_copy) -{ - if (!con || !list || - (con->ownspace != CONSTRAINT_SPACE_CUSTOM && con->tarspace != CONSTRAINT_SPACE_CUSTOM)) { - return; - } - bConstraintTarget *ct = (bConstraintTarget *)list->last; - SINGLETARGET_FLUSH_TARS(con, con->space_object, con->space_subtarget, ct, list, no_copy); + return con->ownspace == CONSTRAINT_SPACE_CUSTOM || con->tarspace == CONSTRAINT_SPACE_CUSTOM; } /* --------- ChildOf Constraint ------------ */ @@ -1184,8 +1163,6 @@ static void trackto_id_looper(bConstraint *con, ConstraintIDFunc func, void *use /* target only */ func(con, (ID **)&data->tar, false, userdata); - - custom_space_id_looper(con, func, userdata); } static int trackto_get_tars(bConstraint *con, ListBase *list) @@ -1197,7 +1174,7 @@ static int trackto_get_tars(bConstraint *con, ListBase *list) /* standard target-getting macro for single-target constraints */ SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list); - return 1 + get_space_tar(con, list); + return 1; } return 0; @@ -1211,7 +1188,6 @@ static void trackto_flush_tars(bConstraint *con, ListBase *list, bool no_copy) /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, no_copy); - flush_space_tar(con, list, no_copy); } } @@ -1684,11 +1660,11 @@ static bConstraintTypeInfo CTI_LOCLIMIT = { "Limit Location", /* name */ "bLocLimitConstraint", /* struct name */ NULL, /* free data */ - custom_space_id_looper, /* id looper */ + NULL, /* id looper */ NULL, /* copy data */ NULL, /* new data */ - get_space_tar, /* get constraint targets */ - flush_space_tar, /* flush constraint targets */ + NULL, /* get constraint targets */ + NULL, /* flush constraint targets */ NULL, /* get target matrix */ loclimit_evaluate, /* evaluate */ }; @@ -1765,11 +1741,11 @@ static bConstraintTypeInfo CTI_ROTLIMIT = { "Limit Rotation", /* name */ "bRotLimitConstraint", /* struct name */ NULL, /* free data */ - custom_space_id_looper, /* id looper */ + NULL, /* id looper */ NULL, /* copy data */ NULL, /* new data */ - get_space_tar, /* get constraint targets */ - flush_space_tar, /* flush constraint targets */ + NULL, /* get constraint targets */ + NULL, /* flush constraint targets */ NULL, /* get target matrix */ rotlimit_evaluate, /* evaluate */ }; @@ -1832,11 +1808,11 @@ static bConstraintTypeInfo CTI_SIZELIMIT = { "Limit Scale", /* name */ "bSizeLimitConstraint", /* struct name */ NULL, /* free data */ - custom_space_id_looper, /* id looper */ + NULL, /* id looper */ NULL, /* copy data */ NULL, /* new data */ - get_space_tar, /* get constraint targets */ - flush_space_tar, /* flush constraint targets */ + NULL, /* get constraint targets */ + NULL, /* flush constraint targets */ NULL, /* get target matrix */ sizelimit_evaluate, /* evaluate */ }; @@ -1856,8 +1832,6 @@ static void loclike_id_looper(bConstraint *con, ConstraintIDFunc func, void *use /* target only */ func(con, (ID **)&data->tar, false, userdata); - - custom_space_id_looper(con, func, userdata); } static int loclike_get_tars(bConstraint *con, ListBase *list) @@ -1869,7 +1843,7 @@ static int loclike_get_tars(bConstraint *con, ListBase *list) /* standard target-getting macro for single-target constraints */ SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list); - return 1 + get_space_tar(con, list); + return 1; } return 0; @@ -1883,7 +1857,6 @@ static void loclike_flush_tars(bConstraint *con, ListBase *list, bool no_copy) /* the following macro is used for all standard single-target constraints */ SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, no_copy); - flush_space_tar(con, list, no_copy); } } @@ -1956,8 +1929,6 @@ static void rotlike_id_looper(bConstraint *con, ConstraintIDFunc func, void *use /* target only */ func(con, (ID **)&data->tar, false, userdata); - - custom_space_id_looper(con, func, userdata); } static int rotlike_get_tars(bConstraint *con, ListBase *list) @@ -1969,7 +1940,7 @@ static int rotlike_get_tars(bConstraint *con, ListBase *list) /* standard target-getting macro for single-target constraints */ SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list); - return 1 + get_space_tar(con, list); + return 1; } return 0; @@ -1983,7 +1954,6 @@ static void rotlike_flush_tars(bConstraint *con, ListBase *list, bool no_copy) /* the following macro is used for all standard single-target constraints @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs