diff options
author | Joshua Leung <aligorith@gmail.com> | 2007-10-22 03:00:29 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2007-10-22 03:00:29 +0400 |
commit | 6422a740c25d33c7e7dcc008d215ae983be00a30 (patch) | |
tree | dddeca774208da69659dfbc6f75616dcc6deadd7 /source/blender/blenloader/intern | |
parent | a4e8e87983829e05d33b2c5aa39f88ca24d48cdd (diff) |
== Constraints System - Recode 2 ==
Once again, I've recoded the constraints system. This time, the goals were:
* To make it more future-proof by 'modernising' the coding style. The long functions filled with switch statements, have given way to function-pointers with smaller functions for specific purposes.
* To make it support constraints which use multiple targets more readily that it did. In the past, it was assumed that constraints could only have at most one target.
As a result, a lot of code has been shuffled around, and modified. Also, the subversion number has been bumped up.
Known issues:
* PyConstraints, which were the main motivation for supporting multiple-targets, are currently broken. There are some bimport() error that keeps causing problems. I've also temporarily removed the doDriver support, although it may return in another form soon.
* Constraints BPy-API is currently has a few features which currently don't work yet
* Outliner currently only displays the names of the constraints instead of the fancy subtarget/target/constraint-name display it used to do. What gets displayed here needs further investigation, as the old way was certainly not that great (and is not compatible with the new system too)
Diffstat (limited to 'source/blender/blenloader/intern')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 93 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 89 |
2 files changed, 102 insertions, 80 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index d07f05ddab1..7b0cdedddf2 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1620,9 +1620,12 @@ static void lib_link_constraints(FileData *fd, ID *id, ListBase *conlist) switch (con->type) { case CONSTRAINT_TYPE_PYTHON: { - bPythonConstraint *data; - data= (bPythonConstraint*)con->data; - data->tar = newlibadr(fd, id->lib, data->tar); + bPythonConstraint *data= (bPythonConstraint*)con->data; + bConstraintTarget *ct; + + for (ct= data->targets.first; ct; ct= ct->next) + ct->tar = newlibadr(fd, id->lib, ct->tar); + data->text = newlibadr(fd, id->lib, data->text); //IDP_LibLinkProperty(data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); } @@ -5257,7 +5260,9 @@ static void do_versions(FileData *fd, Library *lib, Main *main) if (ob->track){ bConstraint *con; + bConstraintTypeInfo *cti; bTrackToConstraint *data; + void *cdata; list = &ob->constraints; if (list) @@ -5268,9 +5273,12 @@ static void do_versions(FileData *fd, Library *lib, Main *main) con->flag |= CONSTRAINT_EXPAND; con->enforce=1.0F; con->type = CONSTRAINT_TYPE_TRACKTO; - data = (bTrackToConstraint *) - new_constraint_data(CONSTRAINT_TYPE_TRACKTO); - + + cti= get_constraint_typeinfo(CONSTRAINT_TYPE_TRACKTO); + cdata= MEM_callocN(cti->size, cti->structName); + cti->new_data(cdata); + data = (bTrackToConstraint *)cdata; + data->tar = ob->track; data->reserved1 = ob->trackflag; data->reserved2 = ob->upflag; @@ -5279,7 +5287,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } ob->track = 0; } - + ob = ob->id.next; } @@ -6757,14 +6765,16 @@ static void do_versions(FileData *fd, Library *lib, Main *main) bArmature *arm; ModifierData *md; Object *ob; - + for(arm= main->armature.first; arm; arm= arm->id.next) arm->deformflag |= ARM_DEF_B_BONE_REST; - - for(ob = main->object.first; ob; ob= ob->id.next) - for(md=ob->modifiers.first; md; md=md->next) + + for(ob = main->object.first; ob; ob= ob->id.next) { + for(md=ob->modifiers.first; md; md=md->next) { if(md->type==eModifierType_Armature) ((ArmatureModifierData*)md)->deformflag |= ARM_DEF_B_BONE_REST; + } + } } if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 5)) { @@ -6785,6 +6795,61 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } } } + + if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 7)) { + Object *ob; + bPoseChannel *pchan; + bConstraint *con; + bConstraintTarget *ct; + + for(ob = main->object.first; ob; ob= ob->id.next) { + if(ob->pose) { + for(pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next) { + for(con=pchan->constraints.first; con; con=con->next) { + if(con->type==CONSTRAINT_TYPE_PYTHON) { + bPythonConstraint *data= (bPythonConstraint *)con->data; + if (data->tar) { + /* version patching needs to be done */ + ct= MEM_callocN(sizeof(bConstraintTarget), "PyConTarget"); + + ct->tar = data->tar; + strcpy(ct->subtarget, data->subtarget); + ct->space = con->tarspace; + + BLI_addtail(&data->targets, ct); + data->tarnum++; + + /* clear old targets to avoid problems */ + data->tar = NULL; + strcpy(data->subtarget, ""); + } + } + } + } + } + + for(con=ob->constraints.first; con; con=con->next) { + if(con->type==CONSTRAINT_TYPE_PYTHON) { + bPythonConstraint *data= (bPythonConstraint *)con->data; + if (data->tar) { + /* version patching needs to be done */ + ct= MEM_callocN(sizeof(bConstraintTarget), "PyConTarget"); + + ct->tar = data->tar; + strcpy(ct->subtarget, data->subtarget); + ct->space = con->tarspace; + + BLI_addtail(&data->targets, ct); + data->tarnum++; + + /* clear old targets to avoid problems */ + data->tar = NULL; + strcpy(data->subtarget, ""); + } + } + } + } + } /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ @@ -7185,7 +7250,11 @@ static void expand_constraints(FileData *fd, Main *mainvar, ListBase *lb) case CONSTRAINT_TYPE_PYTHON: { bPythonConstraint *data = (bPythonConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); + bConstraintTarget *ct; + + for (ct= data->targets.first; ct; ct= ct->next) + expand_doit(fd, mainvar, ct->tar); + expand_doit(fd, mainvar, data->text); } break; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 4f09f51bc87..a059bf2a2c5 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -698,74 +698,27 @@ static void write_constraints(WriteData *wd, ListBase *conlist) bConstraint *con; for (con=conlist->first; con; con=con->next) { + bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + /* Write the specific data */ - switch (con->type) { - case CONSTRAINT_TYPE_NULL: - break; - case CONSTRAINT_TYPE_PYTHON: - { - bPythonConstraint *data = (bPythonConstraint*) con->data; - writestruct(wd, DATA, "bPythonConstraint", 1, data); - - /* Write ID Properties -- and copy this comment EXACTLY for easy finding - of library blocks that implement this.*/ - IDP_WriteProperty(data->prop, wd); + if (cti && con->data) { + /* firstly, just write the plain con->data struct */ + writestruct(wd, DATA, cti->structName, 1, con->data); + + /* do any constraint specific stuff */ + switch (con->type) { + case CONSTRAINT_TYPE_PYTHON: + { + bPythonConstraint *data = (bPythonConstraint*) con->data; + + /* Write ID Properties -- and copy this comment EXACTLY for easy finding + of library blocks that implement this.*/ + IDP_WriteProperty(data->prop, wd); + } + break; } - break; - case CONSTRAINT_TYPE_CHILDOF: - writestruct(wd, DATA, "bChildOfConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_TRACKTO: - writestruct(wd, DATA, "bTrackToConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_KINEMATIC: - writestruct(wd, DATA, "bKinematicConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_ROTLIKE: - writestruct(wd, DATA, "bRotateLikeConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_LOCLIKE: - writestruct(wd, DATA, "bLocateLikeConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_SIZELIKE: - writestruct(wd, DATA, "bSizeLikeConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_ACTION: - writestruct(wd, DATA, "bActionConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_LOCKTRACK: - writestruct(wd, DATA, "bLockTrackConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_FOLLOWPATH: - writestruct(wd, DATA, "bFollowPathConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_STRETCHTO: - writestruct(wd, DATA, "bStretchToConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_MINMAX: - writestruct(wd, DATA, "bMinMaxConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_LOCLIMIT: - writestruct(wd, DATA, "bLocLimitConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_ROTLIMIT: - writestruct(wd, DATA, "bRotLimitConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_SIZELIMIT: - writestruct(wd, DATA, "bSizeLimitConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_RIGIDBODYJOINT: - writestruct(wd, DATA, "bRigidBodyJointConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_CLAMPTO: - writestruct(wd, DATA, "bClampToConstraint", 1, con->data); - break; - case CONSTRAINT_TYPE_TRANSFORM: - writestruct(wd, DATA, "bTransformConstraint", 1, con->data); - break; - default: - break; } + /* Write the constraint */ writestruct(wd, DATA, "bConstraint", 1, con); } @@ -819,12 +772,12 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) for (md=modbase->first; md; md= md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); if (mti == NULL) return; - + writestruct(wd, DATA, mti->structName, 1, md); - + if (md->type==eModifierType_Hook) { HookModifierData *hmd = (HookModifierData*) md; - + writedata(wd, DATA, sizeof(int)*hmd->totindex, hmd->indexar); } } |