[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24510] trunk/blender/source/blender: object.constraints.add()/remove()/active, same for PoseChannel
Campbell Barton
ideasman42 at gmail.com
Wed Nov 11 20:58:30 CET 2009
Revision: 24510
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24510
Author: campbellbarton
Date: 2009-11-11 20:58:30 +0100 (Wed, 11 Nov 2009)
Log Message:
-----------
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
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/BKE_constraint.h
trunk/blender/source/blender/blenkernel/intern/constraint.c
trunk/blender/source/blender/editors/include/ED_object.h
trunk/blender/source/blender/editors/object/object_constraint.c
trunk/blender/source/blender/editors/object/object_relations.c
trunk/blender/source/blender/editors/transform/transform_conversions.c
trunk/blender/source/blender/makesrna/intern/rna_internal.h
trunk/blender/source/blender/makesrna/intern/rna_object.c
trunk/blender/source/blender/makesrna/intern/rna_object_api.c
trunk/blender/source/blender/makesrna/intern/rna_pose.c
trunk/blender/source/blender/makesrna/intern/rna_pose_api.c
trunk/blender/source/blender/makesrna/intern/rna_scene.c
Modified: trunk/blender/source/blender/blenkernel/BKE_constraint.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_constraint.h 2009-11-11 19:12:52 UTC (rev 24509)
+++ trunk/blender/source/blender/blenkernel/BKE_constraint.h 2009-11-11 19:58:30 UTC (rev 24510)
@@ -102,6 +102,9 @@
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 */
Modified: trunk/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/constraint.c 2009-11-11 19:12:52 UTC (rev 24509)
+++ trunk/blender/source/blender/blenkernel/intern/constraint.c 2009-11-11 19:58:30 UTC (rev 24510)
@@ -3601,6 +3601,91 @@
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.
Modified: trunk/blender/source/blender/editors/include/ED_object.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_object.h 2009-11-11 19:12:52 UTC (rev 24509)
+++ trunk/blender/source/blender/editors/include/ED_object.h 2009-11-11 19:58:30 UTC (rev 24510)
@@ -91,9 +91,6 @@
int object_data_is_libdata(struct Object *ob);
/* constraints */
-struct bConstraint *add_new_constraint(short type);
-void add_constraint_to_object(struct bConstraint *con, struct Object *ob);
-
struct ListBase *get_active_constraints(struct Object *ob);
struct bConstraint *get_active_constraint(struct Object *ob);
Modified: trunk/blender/source/blender/editors/object/object_constraint.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_constraint.c 2009-11-11 19:12:52 UTC (rev 24509)
+++ trunk/blender/source/blender/editors/object/object_constraint.c 2009-11-11 19:58:30 UTC (rev 24510)
@@ -187,56 +187,6 @@
#endif
}
-/* Creates a new constraint, initialises its data, and returns it */
-bConstraint *add_new_constraint (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 */
- strcpy(con->name, cti->name);
- }
- else
- strcpy(con->name, "Const");
-
- return con;
-}
-
-/* Adds the given constraint to the Object-level set of constraints for the given Object */
-void add_constraint_to_object (bConstraint *con, Object *ob)
-{
- ListBase *list;
- list = &ob->constraints;
-
- if (list) {
- unique_constraint_name(con, list);
- BLI_addtail(list, con);
-
- if (proxylocked_constraints_owner(ob, NULL))
- con->flag |= CONSTRAINT_PROXY_LOCAL;
-
- con->flag |= CONSTRAINT_ACTIVE;
- for (con= con->prev; con; con= con->prev)
- con->flag &= ~CONSTRAINT_ACTIVE;
- }
-}
-
/* helper function for add_constriant - sets the last target for the active constraint */
static void set_constraint_nth_target (bConstraint *con, Object *target, char subtarget[], int index)
{
@@ -1076,9 +1026,14 @@
static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase *list, int type, short setTarget)
{
Scene *scene= CTX_data_scene(C);
- bPoseChannel *pchan= get_active_posechannel(ob);
+ bPoseChannel *pchan;
bConstraint *con;
+ if(list == &ob->constraints)
+ pchan= NULL;
+ else
+ pchan= get_active_posechannel(ob);
+
/* check if constraint to be added is valid for the given constraints stack */
if (type == CONSTRAINT_TYPE_NULL) {
return OPERATOR_CANCELLED;
@@ -1097,33 +1052,11 @@
}
/* create a new constraint of the type requried, and add it to the active/given constraints list */
- con = add_new_constraint(type);
+ if(pchan)
+ con = add_pose_constraint(ob, pchan, NULL, type);
+ else
+ con = add_ob_constraint(ob, NULL, type);
- 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;
- }
-
/* get the first selected object/bone, and make that the target
* - apart from the buttons-window add buttons, we shouldn't add in this way
*/
Modified: trunk/blender/source/blender/editors/object/object_relations.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_relations.c 2009-11-11 19:12:52 UTC (rev 24509)
+++ trunk/blender/source/blender/editors/object/object_relations.c 2009-11-11 19:58:30 UTC (rev 24510)
@@ -608,14 +608,11 @@
bFollowPathConstraint *data;
float cmat[4][4], vec[3];
- con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
- strcpy (con->name, "AutoPath");
+ con = add_ob_constraint(ob, "AutoPath", CONSTRAINT_TYPE_FOLLOWPATH);
data = con->data;
data->tar = par;
- add_constraint_to_object(con, ob);
-
get_constraint_target_matrix(scene, con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, scene->r.cfra - give_timeoffset(ob));
sub_v3_v3v3(vec, ob->obmat[3], cmat[3]);
@@ -923,8 +920,7 @@
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(ob!=obact) {
- con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
- strcpy (con->name, "AutoTrack");
+ con = add_ob_constraint(ob, "AutoTrack", CONSTRAINT_TYPE_TRACKTO);
data = con->data;
data->tar = obact;
@@ -935,8 +931,6 @@
data->reserved1 = TRACK_nZ;
data->reserved2 = UP_Y;
}
-
- add_constraint_to_object(con, ob);
}
}
CTX_DATA_END;
@@ -947,8 +941,7 @@
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(ob!=obact) {
- con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
- strcpy (con->name, "AutoTrack");
+ con = add_ob_constraint(ob, "AutoTrack", CONSTRAINT_TYPE_LOCKTRACK);
data = con->data;
data->tar = obact;
@@ -959,8 +952,6 @@
data->trackflag = TRACK_nZ;
data->lockflag = LOCK_Y;
}
-
- add_constraint_to_object(con, ob);
}
}
CTX_DATA_END;
Modified: trunk/blender/source/blender/editors/transform/transform_conversions.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform_conversions.c 2009-11-11 19:12:52 UTC (rev 24509)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list