diff options
author | Joshua Leung <aligorith@gmail.com> | 2010-02-06 14:50:39 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2010-02-06 14:50:39 +0300 |
commit | b28033d53f9f876cc2132cfe9dc46ef1c204b063 (patch) | |
tree | 52ec096da3f8e1672fd6b69c8994010832136187 /source | |
parent | ae22d97c4546c89bc827dc05a5b0fe357a94d949 (diff) |
Constraints Loading:
Refactored the constraints reading code to take advantage of the new ID loopers. Now, adding a new constraint type will not require much effort with the file loading code, unless the constraint uses any special direct data which needs to be handled differently.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 371 |
1 files changed, 67 insertions, 304 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index e9cbbb95b02..084f29e7d55 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2137,10 +2137,24 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) /* ************ READ ARMATURE ***************** */ +/* temp struct used to transport needed info to lib_link_constraint_cb() */ +typedef struct tConstraintLinkData { + FileData *fd; + ID *id; +} tConstraintLinkData; +/* callback function used to relink constraint ID-links */ +static void lib_link_constraint_cb(bConstraint *con, ID **idpoin, void *userdata) +{ + tConstraintLinkData *cld= (tConstraintLinkData *)userdata; + *idpoin = newlibadr(cld->fd, cld->id->lib, *idpoin); +} + static void lib_link_constraints(FileData *fd, ID *id, ListBase *conlist) { + tConstraintLinkData cld; bConstraint *con; - + + /* legacy fixes */ for (con = conlist->first; con; con=con->next) { /* patch for error introduced by changing constraints (dunno how) */ /* if con->data type changes, dna cannot resolve the pointer! (ton) */ @@ -2149,184 +2163,48 @@ static void lib_link_constraints(FileData *fd, ID *id, ListBase *conlist) } /* own ipo, all constraints have it */ con->ipo= newlibadr_us(fd, id->lib, con->ipo); // XXX depreceated - old animation system + } + + /* relink all ID-blocks used by the constraints */ + cld.fd= fd; + cld.id= id; + + id_loop_constraints(conlist, lib_link_constraint_cb, &cld); +} + +static void direct_link_constraints(FileData *fd, ListBase *lb) +{ + bConstraint *con; + + link_list(fd, lb); + for (con=lb->first; con; con=con->next) { + con->data = newdataadr(fd, con->data); switch (con->type) { - case CONSTRAINT_TYPE_PYTHON: + case CONSTRAINT_TYPE_PYTHON: { - bPythonConstraint *data= (bPythonConstraint*)con->data; - bConstraintTarget *ct; + bPythonConstraint *data= con->data; - 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); - } - break; - case CONSTRAINT_TYPE_ACTION: - { - bActionConstraint *data; - data= ((bActionConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - data->act = newlibadr(fd, id->lib, data->act); - } - break; - case CONSTRAINT_TYPE_LOCLIKE: - { - bLocateLikeConstraint *data; - data= ((bLocateLikeConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_ROTLIKE: - { - bRotateLikeConstraint *data; - data= ((bRotateLikeConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); + link_list(fd, &data->targets); + + data->prop = newdataadr(fd, data->prop); + if (data->prop) + IDP_DirectLinkProperty(data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); } - break; - case CONSTRAINT_TYPE_SIZELIKE: + break; + case CONSTRAINT_TYPE_SPLINEIK: { - bSizeLikeConstraint *data; - data= ((bSizeLikeConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); + bSplineIKConstraint *data= con->data; + + data->points= newdataadr(fd, data->points); } - break; - case CONSTRAINT_TYPE_KINEMATIC: + break; + case CONSTRAINT_TYPE_KINEMATIC: { - bKinematicConstraint *data; - data = ((bKinematicConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - data->poletar = newlibadr(fd, id->lib, data->poletar); con->lin_error = 0.f; con->rot_error = 0.f; } - break; - case CONSTRAINT_TYPE_TRACKTO: - { - bTrackToConstraint *data; - data = ((bTrackToConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_MINMAX: - { - bMinMaxConstraint *data; - data = ((bMinMaxConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_LOCKTRACK: - { - bLockTrackConstraint *data; - data= ((bLockTrackConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_FOLLOWPATH: - { - bFollowPathConstraint *data; - data= ((bFollowPathConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_STRETCHTO: - { - bStretchToConstraint *data; - data= ((bStretchToConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_RIGIDBODYJOINT: - { - bRigidBodyJointConstraint *data; - data= ((bRigidBodyJointConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_CLAMPTO: - { - bClampToConstraint *data; - data= ((bClampToConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_CHILDOF: - { - bChildOfConstraint *data; - data= ((bChildOfConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_TRANSFORM: - { - bTransformConstraint *data; - data= ((bTransformConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_DISTLIMIT: - { - bDistLimitConstraint *data; - data= ((bDistLimitConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_SHRINKWRAP: - { - bShrinkwrapConstraint *data; - data= ((bShrinkwrapConstraint*)con->data); - data->target = newlibadr(fd, id->lib, data->target); - } - break; - case CONSTRAINT_TYPE_DAMPTRACK: - { - bDampTrackConstraint *data; - data= ((bDampTrackConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_SPLINEIK: - { - bSplineIKConstraint *data; - data= ((bSplineIKConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_TRANSLIKE: - { - bTransLikeConstraint *data; - data= ((bTransLikeConstraint*)con->data); - data->tar = newlibadr(fd, id->lib, data->tar); - } - break; - case CONSTRAINT_TYPE_NULL: - break; - } - } -} - -static void direct_link_constraints(FileData *fd, ListBase *lb) -{ - bConstraint *cons; - - link_list(fd, lb); - for (cons=lb->first; cons; cons=cons->next) { - cons->data = newdataadr(fd, cons->data); - - if (cons->type == CONSTRAINT_TYPE_PYTHON) { - bPythonConstraint *data= cons->data; - - link_list(fd, &data->targets); - - data->prop = newdataadr(fd, data->prop); - if (data->prop) - IDP_DirectLinkProperty(data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); - } - else if (cons->type == CONSTRAINT_TYPE_SPLINEIK) { - bSplineIKConstraint *data= cons->data; - - data->points= newdataadr(fd, data->points); + break; } } } @@ -11317,148 +11195,33 @@ static void expand_mesh(FileData *fd, Main *mainvar, Mesh *me) } } +/* temp struct used to transport needed info to expand_constraint_cb() */ +typedef struct tConstraintExpandData { + FileData *fd; + Main *mainvar; +} tConstraintExpandData; +/* callback function used to expand constraint ID-links */ +static void expand_constraint_cb(bConstraint *con, ID **idpoin, void *userdata) +{ + tConstraintExpandData *ced= (tConstraintExpandData *)userdata; + expand_doit(ced->fd, ced->mainvar, *idpoin); +} + static void expand_constraints(FileData *fd, Main *mainvar, ListBase *lb) { + tConstraintExpandData ced; bConstraint *curcon; - + + /* relink all ID-blocks used by the constraints */ + ced.fd= fd; + ced.mainvar= mainvar; + + id_loop_constraints(lb, expand_constraint_cb, &ced); + + /* depreceated manual expansion stuff */ for (curcon=lb->first; curcon; curcon=curcon->next) { - if (curcon->ipo) expand_doit(fd, mainvar, curcon->ipo); // XXX depreceated - old animation system - - switch (curcon->type) { - case CONSTRAINT_TYPE_NULL: - break; - case CONSTRAINT_TYPE_PYTHON: - { - bPythonConstraint *data = (bPythonConstraint*)curcon->data; - bConstraintTarget *ct; - - for (ct= data->targets.first; ct; ct= ct->next) - expand_doit(fd, mainvar, ct->tar); - - expand_doit(fd, mainvar, data->text); - } - break; - case CONSTRAINT_TYPE_ACTION: - { - bActionConstraint *data = (bActionConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - expand_doit(fd, mainvar, data->act); - } - break; - case CONSTRAINT_TYPE_LOCLIKE: - { - bLocateLikeConstraint *data = (bLocateLikeConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_ROTLIKE: - { - bRotateLikeConstraint *data = (bRotateLikeConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_SIZELIKE: - { - bSizeLikeConstraint *data = (bSizeLikeConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_KINEMATIC: - { - bKinematicConstraint *data = (bKinematicConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - expand_doit(fd, mainvar, data->poletar); - } - break; - case CONSTRAINT_TYPE_TRACKTO: - { - bTrackToConstraint *data = (bTrackToConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_MINMAX: - { - bMinMaxConstraint *data = (bMinMaxConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_LOCKTRACK: - { - bLockTrackConstraint *data = (bLockTrackConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_FOLLOWPATH: - { - bFollowPathConstraint *data = (bFollowPathConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_STRETCHTO: - { - bStretchToConstraint *data = (bStretchToConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_RIGIDBODYJOINT: - { - bRigidBodyJointConstraint *data = (bRigidBodyJointConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_CLAMPTO: - { - bClampToConstraint *data = (bClampToConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_CHILDOF: - { - bChildOfConstraint *data = (bChildOfConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_TRANSFORM: - { - bTransformConstraint *data = (bTransformConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_DISTLIMIT: - { - bDistLimitConstraint *data = (bDistLimitConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_SHRINKWRAP: - { - bShrinkwrapConstraint *data = (bShrinkwrapConstraint*)curcon->data; - expand_doit(fd, mainvar, data->target); - } - break; - case CONSTRAINT_TYPE_DAMPTRACK: - { - bDampTrackConstraint *data = (bDampTrackConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_SPLINEIK: - { - bSplineIKConstraint *data = (bSplineIKConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - case CONSTRAINT_TYPE_TRANSLIKE: - { - bTransLikeConstraint *data = (bTransLikeConstraint*)curcon->data; - expand_doit(fd, mainvar, data->tar); - } - break; - default: - break; - } } } |