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-05-02 12:35:24 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2018-05-02 12:35:24 +0300
commit77ac911b3c47546a8564b00e5c482a59142689e4 (patch)
treecdd4aa4e1c60b71bb7b1f6233d9d73625baf599d /source/blender/makesrna/intern/rna_object.c
parent43f9b6ba451a5d9feb02fa2e4d01fb9122a9e575 (diff)
Static Override: Add proper 'apply' callback for object constraints insertion.
Seems to be working fine, still need to figure out how to make inserted constraints fully overridable... ;)
Diffstat (limited to 'source/blender/makesrna/intern/rna_object.c')
-rw-r--r--source/blender/makesrna/intern/rna_object.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 581ff354a90..7359b7d7158 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -174,6 +174,7 @@ const EnumPropertyItem rna_enum_object_axis_items[] = {
#include "DNA_key_types.h"
#include "DNA_constraint_types.h"
+#include "DNA_ID.h"
#include "DNA_lattice_types.h"
#include "DNA_node_types.h"
@@ -1142,8 +1143,43 @@ bool rna_Object_constraints_override_apply(
BLI_assert(opop->operation == IDOVERRIDESTATIC_OP_INSERT_AFTER &&
"Unsupported RNA override operation on constraints collection");
- printf("%s: We are supposed to insert a constraint...\n", __func__);
- return false;
+ Object *ob_dst = (Object *)ptr_dst->id.data;
+ Object *ob_src = (Object *)ptr_src->id.data;
+
+ /* Remember that insertion operations are defined and stored in correct order, which means that
+ * even if we insert several items in a row, we alays insert first one, then second one, etc.
+ * So we should always find 'anchor' constraint in both _src *and* _dst> */
+ bConstraint *con_anchor = NULL;
+ if (opop->subitem_local_name && opop->subitem_local_name[0]) {
+ con_anchor = BLI_findstring(&ob_dst->constraints, opop->subitem_local_name, offsetof(bConstraint, name));
+ }
+ if (con_anchor == NULL && opop->subitem_local_index >= 0) {
+ con_anchor = BLI_findlink(&ob_dst->constraints, opop->subitem_local_index);
+ }
+ /* Otherwise we just insert in first position. */
+
+ bConstraint *con_src = NULL;
+ if (opop->subitem_local_name && opop->subitem_local_name[0]) {
+ con_src = BLI_findstring(&ob_src->constraints, opop->subitem_local_name, offsetof(bConstraint, name));
+ }
+ if (con_src == NULL && opop->subitem_local_index >= 0) {
+ con_src = BLI_findlink(&ob_src->constraints, opop->subitem_local_index);
+ }
+ con_src = con_src ? con_src->next : ob_src->constraints.first;
+
+ BLI_assert(con_src != NULL);
+
+ bConstraint *con_dst = BKE_constraint_duplicate_ex(con_src, 0, true);
+
+ /* This handles NULL anchor as expected by adding at head of list. */
+ BLI_insertlinkafter(&ob_dst->constraints, con_anchor, con_dst);
+
+ /* This should actually *not* be needed in typical cases. However, if overridden source was edited,
+ * we *may* have some new conflicting names. */
+ BKE_constraint_unique_name(con_dst, &ob_dst->constraints);
+
+// printf("%s: We inserted a constraint...\n", __func__);
+ return true;
#if 0
/* AnimData is a special case, since you cannot edit/replace it, it's either existent or not. */
AnimData *adt_dst = RNA_property_pointer_get(ptr_dst, prop_dst).data;