diff options
author | Martin Poirier <theeth@yahoo.com> | 2003-10-21 17:22:07 +0400 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2003-10-21 17:22:07 +0400 |
commit | 4efdabfbbc3f4f79328241e8b59002d869ae247a (patch) | |
tree | 5d3dae23f261a779e552520c4224a147090dabe4 /source/blender/src/editconstraint.c | |
parent | 2da9cb5db284e16d95ff7e65dda9174c6b668950 (diff) |
Constraint stuff from tuhopuu including (but probably not limited too):
Axis options for TrackTo
LockTrack
FollowPath
Auto creation of TrackTo constraint from Ctrl-T (old track still an option)
Auto creation of FollowPath when parenting to path (Normal parent still an option)
Backward compatibility stuff to convert the per object axis settings to per constraint when a Track constraint is present.
Function to convert old track to constraint (commented out)
Revamped the constraints interface with Matt's work from tuhopuu and the stuff we were discussing earlier.
--------------------
For coders:
unique_constraint_name and *new_constraint_data moved to the kernel (constraint.c)
new Projf function in arithb gives the projection of a vector on another vector
add_new_constraint now takes a constraint type (int) parameter
add_constraint_to_object(bConstraint *con, Object *ob) to link a constraint to an object
add_constraint_to_client(bConstraint *con) to link constraint to current client (object or bone)
add_influence_key_to_constraint (bConstraint *con) to (eventually) add a keyframe to the influence IPO of a constraint
Diffstat (limited to 'source/blender/src/editconstraint.c')
-rw-r--r-- | source/blender/src/editconstraint.c | 210 |
1 files changed, 101 insertions, 109 deletions
diff --git a/source/blender/src/editconstraint.c b/source/blender/src/editconstraint.c index 60798fe0b8b..55fa3593140 100644 --- a/source/blender/src/editconstraint.c +++ b/source/blender/src/editconstraint.c @@ -81,50 +81,6 @@ const char *g_conString; Object *g_conObj; -void unique_constraint_name (bConstraint *con, ListBase *list){ - char tempname[64]; - int number; - char *dot; - int exists = 0; - bConstraint *curcon; - - /* See if we even need to do this */ - for (curcon = list->first; curcon; curcon=curcon->next){ - if (curcon!=con){ - if (!strcmp(curcon->name, con->name)){ - exists = 1; - break; - } - } - } - - if (!exists) - return; - - /* Strip off the suffix */ - dot=strchr(con->name, '.'); - if (dot) - *dot=0; - - for (number = 1; number <=999; number++){ - sprintf (tempname, "%s.%03d", con->name, number); - - exists = 0; - for (curcon=list->first; curcon; curcon=curcon->next){ - if (con!=curcon){ - if (!strcmp (curcon->name, tempname)){ - exists = 1; - break; - } - } - } - if (!exists){ - strcpy (con->name, tempname); - return; - } - } -} - static int is_child_of_ex(Object *owner, const char *ownersubstr, Object *parent, const char *parsubstr) { Object *curob; @@ -549,6 +505,79 @@ static short detect_constraint_loop (Object *owner, const char* substring, int d break; // return 1; } + if (data->reserved2==data->reserved1){ + curcon->flag |= CONSTRAINT_DISABLE; + result = 1; + break; + // return 1; + } + if (data->reserved2+3==data->reserved1){ + curcon->flag |= CONSTRAINT_DISABLE; + result = 1; + break; + // return 1; + } + } + break; + case CONSTRAINT_TYPE_LOCKTRACK: + { + bLockTrackConstraint *data = curcon->data; + + if (!exist_object(data->tar)){ + data->tar = NULL; + break; + } + + if (add_constraint_element (data->tar, data->subtarget, owner, substring)){ + curcon->flag |= CONSTRAINT_DISABLE; + result = 1; + break; + // return 1; + } + if (detect_constraint_loop (data->tar, data->subtarget, disable)){ + curcon->flag |= CONSTRAINT_DISABLE; + result = 1; + break; + // return 1; + } + if (data->lockflag==data->trackflag){ + curcon->flag |= CONSTRAINT_DISABLE; + result = 1; + break; + // return 1; + } + if (data->lockflag+3==data->trackflag){ + curcon->flag |= CONSTRAINT_DISABLE; + result = 1; + break; + // return 1; + } + } + break; + case CONSTRAINT_TYPE_FOLLOWPATH: + { + bFollowPathConstraint *data = curcon->data; + + if (!exist_object(data->tar)){ + data->tar = NULL; + break; + } + if (data->tar->type != OB_CURVE){ + data->tar = NULL; + break; + } + if (data->upflag==data->trackflag){ + curcon->flag |= CONSTRAINT_DISABLE; + result = 1; + break; + // return 1; + } + if (data->upflag+3==data->trackflag){ + curcon->flag |= CONSTRAINT_DISABLE; + result = 1; + break; + // return 1; + } } break; } @@ -666,77 +695,14 @@ ListBase *get_constraint_client(char *name, short *clientType, void **clientdata return list; } -void *new_constraint_data (short type) -{ - void *result; - - switch (type){ - case CONSTRAINT_TYPE_KINEMATIC: - { - bKinematicConstraint *data; - data = MEM_callocN(sizeof(bKinematicConstraint), "kinematicConstraint"); - - data->tolerance = 0.001; - data->iterations = 500; - - result = data; - } - break; - case CONSTRAINT_TYPE_NULL: - { - result = NULL; - } - break; - case CONSTRAINT_TYPE_TRACKTO: - { - bTrackToConstraint *data; - data = MEM_callocN(sizeof(bTrackToConstraint), "tracktoConstraint"); - - result = data; - - } - break; - case CONSTRAINT_TYPE_ROTLIKE: - { - bRotateLikeConstraint *data; - data = MEM_callocN(sizeof(bRotateLikeConstraint), "rotlikeConstraint"); - - result = data; - } - break; - case CONSTRAINT_TYPE_LOCLIKE: - { - bLocateLikeConstraint *data; - data = MEM_callocN(sizeof(bLocateLikeConstraint), "loclikeConstraint"); - - data->flag |= LOCLIKE_X|LOCLIKE_Y|LOCLIKE_Z; - result = data; - } - break; - case CONSTRAINT_TYPE_ACTION: - { - bActionConstraint *data; - data = MEM_callocN(sizeof(bActionConstraint), "actionConstraint"); - - result = data; - } - break; - default: - result = NULL; - break; - } - - return result; -} - -bConstraint * add_new_constraint(void) +bConstraint * add_new_constraint(int type) { bConstraint *con; con = MEM_callocN(sizeof(bConstraint), "constraint"); /* Set up a generic constraint datablock */ - con->type = CONSTRAINT_TYPE_TRACKTO; + con->type = type; con->flag |= CONSTRAINT_EXPAND; con->enforce=1.0F; /* Load the data for it */ @@ -745,6 +711,29 @@ bConstraint * add_new_constraint(void) return con; } +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); + } +} + +void add_constraint_to_client(bConstraint *con) +{ + ListBase *list; + short type; + list = get_constraint_client(NULL, &type, NULL); + if (list) + { + unique_constraint_name(con, list); + BLI_addtail(list, con); + } +} + bConstraintChannel *add_new_constraint_channel(const char* name) { bConstraintChannel *chan = NULL; @@ -755,3 +744,6 @@ bConstraintChannel *add_new_constraint_channel(const char* name) return chan; } +void add_influence_key_to_constraint (bConstraint *con){ + printf("doesn't do anything yet\n"); +}
\ No newline at end of file |