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:
authorCampbell Barton <ideasman42@gmail.com>2009-11-11 22:58:30 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-11-11 22:58:30 +0300
commit53250f85dbecdc4cdd6eded772972b137f3f8c6c (patch)
tree2deea82dca566fd752753d34b7df3e38ba4d0216 /source/blender/blenkernel
parent047ee04418a5a785177258dd965f94571d553b57 (diff)
object.constraints.add()/remove()/active, same for PoseChannel
modified internal api for minimal rna wrapper functions. TODO - missing updates for pose channels - typecheck for pose/object constraints
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_constraint.h3
-rw-r--r--source/blender/blenkernel/intern/constraint.c85
2 files changed, 88 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_constraint.h b/source/blender/blenkernel/BKE_constraint.h
index f957c5e17d4..7e0bb9fa08e 100644
--- a/source/blender/blenkernel/BKE_constraint.h
+++ b/source/blender/blenkernel/BKE_constraint.h
@@ -102,6 +102,9 @@ typedef struct bConstraintTypeInfo {
bConstraintTypeInfo *constraint_get_typeinfo(struct bConstraint *con);
bConstraintTypeInfo *get_constraint_typeinfo(int type);
+struct bConstraint *add_ob_constraint(struct Object *ob, const char *name, short type);
+struct bConstraint *add_pose_constraint(struct Object *ob, struct bPoseChannel *pchan, const char *name, short type);
+
/* ---------------------------------------------------------------------------- */
/* Useful macros for testing various common flag combinations */
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 55001f58d2f..6fce9a29962 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -3601,6 +3601,91 @@ bConstraintTypeInfo *constraint_get_typeinfo (bConstraint *con)
return NULL;
}
+/* Creates a new constraint, initialises its data, and returns it */
+static bConstraint *add_new_constraint_internal(const char *name, short type)
+{
+ bConstraint *con;
+ bConstraintTypeInfo *cti;
+
+ con = MEM_callocN(sizeof(bConstraint), "Constraint");
+
+ /* Set up a generic constraint datablock */
+ con->type = type;
+ con->flag |= CONSTRAINT_EXPAND;
+ con->enforce = 1.0f;
+
+ /* Load the data for it */
+ cti = constraint_get_typeinfo(con);
+ if (cti) {
+ con->data = MEM_callocN(cti->size, cti->structName);
+
+ /* only constraints that change any settings need this */
+ if (cti->new_data)
+ cti->new_data(con->data);
+
+ /* set the name based on the type of constraint */
+ name= name ? name : cti->name;
+ }
+ else
+ name= name ? name : "Const";
+
+ strcpy(con->name, name);
+
+ return con;
+}
+
+/* if pchan is not NULL then assume we're adding a pose constraint */
+static bConstraint *add_new_constraint(Object *ob, bPoseChannel *pchan, const char *name, short type)
+{
+ bConstraint *con;
+ ListBase *list;
+
+ con= add_new_constraint_internal(name, type);
+
+ if(pchan) list= &pchan->constraints;
+ else list= &ob->constraints;
+
+ if (list) {
+ bConstraint *coniter;
+
+ /* add new constraint to end of list of constraints before ensuring that it has a unique name
+ * (otherwise unique-naming code will fail, since it assumes element exists in list)
+ */
+ BLI_addtail(list, con);
+ unique_constraint_name(con, list);
+
+ /* if the target list is a list on some PoseChannel belonging to a proxy-protected
+ * Armature layer, we must tag newly added constraints with a flag which allows them
+ * to persist after proxy syncing has been done
+ */
+ if (proxylocked_constraints_owner(ob, pchan))
+ con->flag |= CONSTRAINT_PROXY_LOCAL;
+
+ /* make this constraint the active one
+ * - since constraint was added at end of stack, we can just go
+ * through deactivating all previous ones
+ */
+ con->flag |= CONSTRAINT_ACTIVE;
+ for (coniter= con->prev; coniter; coniter= coniter->prev)
+ coniter->flag &= ~CONSTRAINT_ACTIVE;
+ }
+
+ return con;
+}
+
+bConstraint *add_pose_constraint(Object *ob, bPoseChannel *pchan, const char *name, short type)
+{
+ if(pchan==NULL)
+ return NULL;
+
+ return add_new_constraint(ob, pchan, name, type);
+}
+
+bConstraint *add_ob_constraint(Object *ob, const char *name, short type)
+{
+ return add_new_constraint(ob, NULL, name, type);
+}
+
/* ************************* General Constraints API ************************** */
/* The functions here are called by various parts of Blender. Very few (should be none if possible)
* constraint-specific code should occur here.