diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-11-02 20:17:05 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-11-02 20:17:05 +0400 |
commit | 2f453773f6b4cd0a03f5e2d9876ee250b87871f0 (patch) | |
tree | 08c4bb2c1c3ee3fe5131e46a4e39b9224ba5c251 /source/blender/blenkernel/intern | |
parent | 02fae3440c8b4b89aa0f9412bc4e0db60a787c13 (diff) | |
parent | e1594ebb3c52f573a8a6c90f3d30acfb3de6e8a5 (diff) |
Cycles: svn merge -r41266:41467 ^/trunk/blender
Diffstat (limited to 'source/blender/blenkernel/intern')
28 files changed, 696 insertions, 486 deletions
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index e46e2df8353..944f7c6a0b6 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -43,6 +43,7 @@ #include "DNA_object_types.h" #include "BLI_blenlib.h" +#include "BLI_bpath.h" #include "BLI_math.h" #include "BLI_utildefines.h" #include "BLI_ghash.h" @@ -94,8 +95,8 @@ typedef struct tMakeLocalActionContext { bAction *act; /* original action */ bAction *actn; /* new action */ - int lib; /* some action users were libraries */ - int local; /* some action users were not libraries */ + int is_lib; /* some action users were libraries */ + int is_local; /* some action users were not libraries */ } tMakeLocalActionContext; /* helper function for make_local_action() - local/lib init step */ @@ -104,10 +105,8 @@ static void make_localact_init_cb(ID *id, AnimData *adt, void *mlac_ptr) tMakeLocalActionContext *mlac = (tMakeLocalActionContext *)mlac_ptr; if (adt->action == mlac->act) { - if (id->lib) - mlac->lib = 1; - else - mlac->local = 1; + if (id->lib) mlac->is_lib= TRUE; + else mlac->is_local= TRUE; } } @@ -129,7 +128,7 @@ static void make_localact_apply_cb(ID *id, AnimData *adt, void *mlac_ptr) // does copy_fcurve... void make_local_action(bAction *act) { - tMakeLocalActionContext mlac = {act, NULL, 0, 0}; + tMakeLocalActionContext mlac = {act, NULL, FALSE, FALSE}; Main *bmain= G.main; if (act->id.lib==NULL) @@ -137,24 +136,21 @@ void make_local_action(bAction *act) // XXX: double-check this; it used to be just single-user check, but that was when fake-users were still default if ((act->id.flag & LIB_FAKEUSER) && (act->id.us<=1)) { - act->id.lib= NULL; - act->id.flag= LIB_LOCAL; - new_id(&bmain->action, (ID *)act, NULL); + id_clear_lib_data(bmain, &act->id); return; } BKE_animdata_main_cb(bmain, make_localact_init_cb, &mlac); - if (mlac.local && mlac.lib==0) { - act->id.lib= NULL; - act->id.flag= LIB_LOCAL; - //make_local_action_channels(act); - new_id(&bmain->action, (ID *)act, NULL); + if (mlac.is_local && mlac.is_lib==FALSE) { + id_clear_lib_data(bmain, &act->id); } - else if (mlac.local && mlac.lib) { + else if (mlac.is_local && mlac.is_lib) { mlac.actn= copy_action(act); mlac.actn->id.us= 0; - + + BKE_id_lib_local_paths(bmain, &mlac.actn->id); + BKE_animdata_main_cb(bmain, make_localact_apply_cb, &mlac); } } @@ -648,12 +644,12 @@ static void copy_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *chan { bConstraint *pcon, *con; - VECCOPY(pchan->loc, chan->loc); - VECCOPY(pchan->size, chan->size); - VECCOPY(pchan->eul, chan->eul); - VECCOPY(pchan->rotAxis, chan->rotAxis); + copy_v3_v3(pchan->loc, chan->loc); + copy_v3_v3(pchan->size, chan->size); + copy_v3_v3(pchan->eul, chan->eul); + copy_v3_v3(pchan->rotAxis, chan->rotAxis); pchan->rotAngle= chan->rotAngle; - QUATCOPY(pchan->quat, chan->quat); + copy_qt_qt(pchan->quat, chan->quat); pchan->rotmode= chan->rotmode; copy_m4_m4(pchan->chan_mat, (float(*)[4])chan->chan_mat); copy_m4_m4(pchan->pose_mat, (float(*)[4])chan->pose_mat); @@ -682,9 +678,9 @@ void duplicate_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *pchan_ /* ik (dof) settings */ pchan->ikflag = pchan_from->ikflag; - VECCOPY(pchan->limitmin, pchan_from->limitmin); - VECCOPY(pchan->limitmax, pchan_from->limitmax); - VECCOPY(pchan->stiffness, pchan_from->stiffness); + copy_v3_v3(pchan->limitmin, pchan_from->limitmin); + copy_v3_v3(pchan->limitmax, pchan_from->limitmax); + copy_v3_v3(pchan->stiffness, pchan_from->stiffness); pchan->ikstretch= pchan_from->ikstretch; pchan->ikrotweight= pchan_from->ikrotweight; pchan->iklinweight= pchan_from->iklinweight; @@ -1119,13 +1115,13 @@ void copy_pose_result(bPose *to, bPose *from) copy_m4_m4(pchanto->chan_mat, pchanfrom->chan_mat); /* used for local constraints */ - VECCOPY(pchanto->loc, pchanfrom->loc); - QUATCOPY(pchanto->quat, pchanfrom->quat); - VECCOPY(pchanto->eul, pchanfrom->eul); - VECCOPY(pchanto->size, pchanfrom->size); + copy_v3_v3(pchanto->loc, pchanfrom->loc); + copy_qt_qt(pchanto->quat, pchanfrom->quat); + copy_v3_v3(pchanto->eul, pchanfrom->eul); + copy_v3_v3(pchanto->size, pchanfrom->size); - VECCOPY(pchanto->pose_head, pchanfrom->pose_head); - VECCOPY(pchanto->pose_tail, pchanfrom->pose_tail); + copy_v3_v3(pchanto->pose_head, pchanfrom->pose_head); + copy_v3_v3(pchanto->pose_tail, pchanfrom->pose_tail); pchanto->rotmode= pchanfrom->rotmode; pchanto->flag= pchanfrom->flag; diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 716f3ed2726..2ef13318af4 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -363,10 +363,10 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets) if (mpt->pchan) { /* heads or tails */ if (mpath->flag & MOTIONPATH_FLAG_BHEAD) { - VECCOPY(mpv->co, mpt->pchan->pose_head); + copy_v3_v3(mpv->co, mpt->pchan->pose_head); } else { - VECCOPY(mpv->co, mpt->pchan->pose_tail); + copy_v3_v3(mpv->co, mpt->pchan->pose_tail); } /* result must be in worldspace */ @@ -374,7 +374,7 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets) } else { /* worldspace object location */ - VECCOPY(mpv->co, mpt->ob->obmat[3]); + copy_v3_v3(mpv->co, mpt->ob->obmat[3]); } } } @@ -654,15 +654,15 @@ int where_on_path(Object *ob, float ctime, float *vec, float *dir, float *quat, totfac= data[0]+data[3]; if(totfac>FLT_EPSILON) interp_qt_qtqt(q1, p0->quat, p3->quat, data[3] / totfac); - else QUATCOPY(q1, p1->quat); + else copy_qt_qt(q1, p1->quat); totfac= data[1]+data[2]; if(totfac>FLT_EPSILON) interp_qt_qtqt(q2, p1->quat, p2->quat, data[2] / totfac); - else QUATCOPY(q2, p3->quat); + else copy_qt_qt(q2, p3->quat); totfac = data[0]+data[1]+data[2]+data[3]; if(totfac>FLT_EPSILON) interp_qt_qtqt(quat, q1, q2, (data[1]+data[2]) / totfac); - else QUATCOPY(quat, q2); + else copy_qt_qt(quat, q2); } if(radius) @@ -842,7 +842,7 @@ static void vertex_dupli__mapFunc(void *userData, int index, float *co, float *n add_v3_v3(vec, vdd->obmat[3]); copy_m4_m4(obmat, vdd->obmat); - VECCOPY(obmat[3], vec); + copy_v3_v3(obmat[3], vec); if(vdd->par->transflag & OB_DUPLIROT) { if(no_f) { @@ -867,7 +867,7 @@ static void vertex_dupli__mapFunc(void *userData, int index, float *co, float *n vdd->ob->lay = origlay; if(vdd->orco) - VECCOPY(dob->orco, vdd->orco[index]); + copy_v3_v3(dob->orco, vdd->orco[index]); if(vdd->ob->transflag & OB_DUPLI) { float tmpmat[4][4]; @@ -1119,7 +1119,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa copy_m4_m4(obmat, ob__obmat); - VECCOPY(obmat[3], cent); + copy_v3_v3(obmat[3], cent); /* rotation */ tri_to_quat( quat,v1, v2, v3); @@ -1378,7 +1378,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p psys_get_dupli_path_transform(&sim, NULL, cpa, cache, pamat, &scale); } - VECCOPY(pamat[3], cache->co); + copy_v3_v3(pamat[3], cache->co); pamat[3][3]= 1.0f; } @@ -1426,7 +1426,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p /* to give ipos in object correct offset */ where_is_object_time(scene, ob, ctime-pa_time); - VECCOPY(vec, obmat[3]); + copy_v3_v3(vec, obmat[3]); obmat[3][0] = obmat[3][1] = obmat[3][2] = 0.0f; /* particle rotation uses x-axis as the aligned axis, so pre-rotate the object accordingly */ @@ -1546,7 +1546,7 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int level, i mul_m4_v3(pmat, vec); copy_m4_m4(obmat, par->obmat); - VECCOPY(obmat[3], vec); + copy_v3_v3(obmat[3], vec); new_dupli_object(lb, ob, obmat, par->lay, a, OB_DUPLIVERTS, animated); } diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 1149d8eee25..e9a19b50a81 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -37,6 +37,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_bpath.h" #include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_utildefines.h" @@ -136,33 +137,32 @@ void free_armature(bArmature *arm) void make_local_armature(bArmature *arm) { Main *bmain= G.main; - int local=0, lib=0; + int is_local= FALSE, is_lib= FALSE; Object *ob; if (arm->id.lib==NULL) return; if (arm->id.us==1) { - arm->id.lib= NULL; - arm->id.flag= LIB_LOCAL; - new_id(&bmain->armature, (ID*)arm, NULL); + id_clear_lib_data(bmain, &arm->id); return; } - for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) { + for(ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) { if(ob->data == arm) { - if(ob->id.lib) lib= 1; - else local= 1; + if(ob->id.lib) is_lib= TRUE; + else is_local= TRUE; } } - if(local && lib==0) { - arm->id.lib= NULL; - arm->id.flag= LIB_LOCAL; - new_id(&bmain->armature, (ID *)arm, NULL); + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &arm->id); } - else if(local && lib) { + else if(is_local && is_lib) { bArmature *armn= copy_armature(arm); armn->id.us= 0; - + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &armn->id); + for(ob= bmain->object.first; ob; ob= ob->id.next) { if(ob->data == arm) { if(ob->id.lib==NULL) { @@ -389,11 +389,11 @@ static void equalize_bezier(float *data, int desired) pdist[0]= 0.0f; for(a=0, fp= data; a<MAX_BBONE_SUBDIV; a++, fp+=4) { - QUATCOPY(temp[a], fp); + copy_qt_qt(temp[a], fp); pdist[a+1]= pdist[a]+len_v3v3(fp, fp+4); } /* do last point */ - QUATCOPY(temp[a], fp); + copy_qt_qt(temp[a], fp); totdist= pdist[a]; /* go over distances and calculate new points */ @@ -419,7 +419,7 @@ static void equalize_bezier(float *data, int desired) fp[3]= fac1*temp[nr-1][3]+ fac2*temp[nr][3]; } /* set last point, needed for orientation calculus */ - QUATCOPY(fp, temp[MAX_BBONE_SUBDIV]); + copy_qt_qt(fp, temp[MAX_BBONE_SUBDIV]); } /* returns pointer to static array, filled with desired amount of bone->segments elements */ @@ -487,9 +487,9 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) /* transform previous point inside this bone space */ if(rest) - VECCOPY(h1, prev->bone->arm_head) + copy_v3_v3(h1, prev->bone->arm_head); else - VECCOPY(h1, prev->pose_head) + copy_v3_v3(h1, prev->pose_head); mul_m4_v3(imat, h1); if(prev->bone->segments>1) { @@ -526,9 +526,9 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) /* transform next point inside this bone space */ if(rest) - VECCOPY(h2, next->bone->arm_tail) + copy_v3_v3(h2, next->bone->arm_tail); else - VECCOPY(h2, next->pose_tail) + copy_v3_v3(h2, next->pose_tail); mul_m4_v3(imat, h2); /* if next bone is B-bone too, use average handle direction */ if(next->bone->segments>1); @@ -574,7 +574,7 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) vec_roll_to_mat3(h1, fp[3], mat3); // fp[3] is roll copy_m4_m3(result_array[a].mat, mat3); - VECCOPY(result_array[a].mat[3], fp); + copy_v3_v3(result_array[a].mat[3], fp); if(doscale) { /* correct for scaling when this matrix is used in scaled space */ @@ -736,7 +736,7 @@ static float dist_bone_deform(bPoseChannel *pchan, bPoseChanDeform *pdef_info, f if(bone==NULL) return 0.0f; - VECCOPY (cop, co); + copy_v3_v3(cop, co); fac= distfactor_to_bone(cop, bone->arm_head, bone->arm_tail, bone->rad_head, bone->rad_tail, bone->dist); @@ -781,7 +781,7 @@ static void pchan_bone_deform(bPoseChannel *pchan, bPoseChanDeform *pdef_info, f if (!weight) return; - VECCOPY(cop, co); + copy_v3_v3(cop, co); if(vec) { if(pchan->bone->segments>1) @@ -1018,7 +1018,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, normalize_dq(dq, contrib); if(armature_weight != 1.0f) { - VECCOPY(dco, co); + copy_v3_v3(dco, co); mul_v3m3_dq( dco, (defMats)? summat: NULL,dq); sub_v3_v3(dco, co); mul_v3_fl(dco, armature_weight); @@ -1114,11 +1114,11 @@ void armature_loc_world_to_pose(Object *ob, float *inloc, float *outloc) float nLocMat[4][4]; /* build matrix for location */ - VECCOPY(xLocMat[3], inloc); + copy_v3_v3(xLocMat[3], inloc); /* get bone-space cursor matrix and extract location */ armature_mat_world_to_pose(ob, xLocMat, nLocMat); - VECCOPY(outloc, nLocMat[3]); + copy_v3_v3(outloc, nLocMat[3]); } /* Convert Pose-Space Matrix to Bone-Space Matrix @@ -1193,11 +1193,11 @@ void armature_loc_pose_to_bone(bPoseChannel *pchan, float *inloc, float *outloc) float nLocMat[4][4]; /* build matrix for location */ - VECCOPY(xLocMat[3], inloc); + copy_v3_v3(xLocMat[3], inloc); /* get bone-space cursor matrix and extract location */ armature_mat_pose_to_bone(pchan, xLocMat, nLocMat); - VECCOPY(outloc, nLocMat[3]); + copy_v3_v3(outloc, nLocMat[3]); } /* same as object_mat3_to_rot() */ @@ -1402,7 +1402,7 @@ void where_is_armature_bone(Bone *bone, Bone *prevbone) copy_m4_m3(offs_bone, bone->bone_mat); /* The bone's root offset (is in the parent's coordinate system) */ - VECCOPY(offs_bone[3], bone->head); + copy_v3_v3(offs_bone[3], bone->head); /* Get the length translation of parent (length along y axis) */ offs_bone[3][1]+= prevbone->length; @@ -1412,7 +1412,7 @@ void where_is_armature_bone(Bone *bone, Bone *prevbone) } else { copy_m4_m3(bone->arm_mat, bone->bone_mat); - VECCOPY(bone->arm_mat[3], bone->head); + copy_v3_v3(bone->arm_mat[3], bone->head); } /* and the kiddies */ @@ -1848,8 +1848,8 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o /* firstly, calculate the bone matrix the standard way, since this is needed for roll control */ where_is_pose_bone(scene, ob, pchan, ctime, 1); - VECCOPY(poseHead, pchan->pose_head); - VECCOPY(poseTail, pchan->pose_tail); + copy_v3_v3(poseHead, pchan->pose_head); + copy_v3_v3(poseTail, pchan->pose_tail); /* step 1: determine the positions for the endpoints of the bone */ { @@ -1893,7 +1893,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o /* store the position, and convert it to pose space */ mul_m4_v3(ob->imat, vec); - VECCOPY(poseHead, vec); + copy_v3_v3(poseHead, vec); /* set the new radius (it should be the average value) */ radius = (radius+rad) / 2; @@ -1917,9 +1917,9 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o /* compute the raw rotation matrix from the bone's current matrix by extracting only the * orientation-relevant axes, and normalising them */ - VECCOPY(rmat[0], pchan->pose_mat[0]); - VECCOPY(rmat[1], pchan->pose_mat[1]); - VECCOPY(rmat[2], pchan->pose_mat[2]); + copy_v3_v3(rmat[0], pchan->pose_mat[0]); + copy_v3_v3(rmat[1], pchan->pose_mat[1]); + copy_v3_v3(rmat[2], pchan->pose_mat[2]); normalize_m3(rmat); /* also, normalise the orientation imposed by the bone, now that we've extracted the scale factor */ @@ -2010,7 +2010,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o /* when the 'no-root' option is affected, the chain can retain * the shape but be moved elsewhere */ - VECCOPY(poseHead, pchan->pose_head); + copy_v3_v3(poseHead, pchan->pose_head); } else if (tree->con->enforce < 1.0f) { /* when the influence is too low @@ -2018,18 +2018,18 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o * - stick to the parent for any other */ if (pchan->parent) { - VECCOPY(poseHead, pchan->pose_head); + copy_v3_v3(poseHead, pchan->pose_head); } else { // FIXME: this introduces popping artifacts when we reach 0.0 interp_v3_v3v3(poseHead, pchan->pose_head, poseHead, tree->con->enforce); } } - VECCOPY(poseMat[3], poseHead); + copy_v3_v3(poseMat[3], poseHead); /* finally, store the new transform */ copy_m4_m4(pchan->pose_mat, poseMat); - VECCOPY(pchan->pose_head, poseHead); + copy_v3_v3(pchan->pose_head, poseHead); /* recalculate tail, as it's now outdated after the head gets adjusted above! */ where_is_pose_bone_tail(pchan); @@ -2108,7 +2108,7 @@ void pchan_to_mat4(bPoseChannel *pchan, float chan_mat[4][4]) /* prevent action channels breaking chains */ /* need to check for bone here, CONSTRAINT_TYPE_ACTION uses this call */ if ((pchan->bone==NULL) || !(pchan->bone->flag & BONE_CONNECTED)) { - VECCOPY(chan_mat[3], pchan->loc); + copy_v3_v3(chan_mat[3], pchan->loc); } } @@ -2194,11 +2194,11 @@ static void do_strip_modifiers(Scene *scene, Object *armob, Bone *bone, bPoseCha ofs = amod->turbul / 200.0f; /* make a copy of starting conditions */ - VECCOPY(loc, pchan->pose_mat[3]); + copy_v3_v3(loc, pchan->pose_mat[3]); mat4_to_eul( eul,pchan->pose_mat); mat4_to_size( size,pchan->pose_mat); - VECCOPY(eulo, eul); - VECCOPY(sizeo, size); + copy_v3_v3(eulo, eul); + copy_v3_v3(sizeo, size); /* apply noise to each set of channels */ if (amod->channels & 4) { @@ -2249,7 +2249,7 @@ void where_is_pose_bone_tail(bPoseChannel *pchan) { float vec[3]; - VECCOPY(vec, pchan->pose_mat[1]); + copy_v3_v3(vec, pchan->pose_mat[1]); mul_v3_fl(vec, pchan->bone->length); add_v3_v3v3(pchan->pose_tail, pchan->pose_head, vec); } @@ -2283,7 +2283,7 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti copy_m4_m3(offs_bone, bone->bone_mat); /* The bone's root offset (is in the parent's coordinate system) */ - VECCOPY(offs_bone[3], bone->head); + copy_v3_v3(offs_bone[3], bone->head); /* Get the length translation of parent (length along y axis) */ offs_bone[3][1]+= parbone->length; @@ -2361,7 +2361,7 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti bConstraintOb *cob; /* make a copy of location of PoseChannel for later */ - VECCOPY(vec, pchan->pose_mat[3]); + copy_v3_v3(vec, pchan->pose_mat[3]); /* prepare PoseChannel for Constraint solving * - makes a copy of matrix, and creates temporary struct to use @@ -2378,13 +2378,13 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti /* prevent constraints breaking a chain */ if(pchan->bone->flag & BONE_CONNECTED) { - VECCOPY(pchan->pose_mat[3], vec); + copy_v3_v3(pchan->pose_mat[3], vec); } } } /* calculate head */ - VECCOPY(pchan->pose_head, pchan->pose_mat[3]); + copy_v3_v3(pchan->pose_head, pchan->pose_mat[3]); /* calculate tail */ where_is_pose_bone_tail(pchan); } @@ -2415,8 +2415,8 @@ void where_is_pose (Scene *scene, Object *ob) bone= pchan->bone; if(bone) { copy_m4_m4(pchan->pose_mat, bone->arm_mat); - VECCOPY(pchan->pose_head, bone->arm_head); - VECCOPY(pchan->pose_tail, bone->arm_tail); + copy_v3_v3(pchan->pose_head, bone->arm_head); + copy_v3_v3(pchan->pose_tail, bone->arm_tail); } } } diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 4cbdbeb890d..d68b0b361d1 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -160,22 +160,19 @@ static void clear_global(void) G.main= NULL; } +static int clean_paths_visit_cb(void *UNUSED(userdata), char *path_dst, const char *path_src) +{ + strcpy(path_dst, path_src); + BLI_clean(path_dst); + return (strcmp(path_dst, path_src) == 0) ? FALSE : TRUE; +} + /* make sure path names are correct for OS */ static void clean_paths(Main *main) { - struct BPathIterator *bpi; - char filepath_expanded[1024]; Scene *scene; - for(BLI_bpathIterator_init(&bpi, main, main->name, BPATH_USE_PACKED); !BLI_bpathIterator_isDone(bpi); BLI_bpathIterator_step(bpi)) { - BLI_bpathIterator_getPath(bpi, filepath_expanded); - - BLI_clean(filepath_expanded); - - BLI_bpathIterator_setPath(bpi, filepath_expanded); - } - - BLI_bpathIterator_free(bpi); + bpath_traverse_main(main, clean_paths_visit_cb, BPATH_TRAVERSE_SKIP_MULTIFILE, NULL); for(scene= main->scene.first; scene; scene= scene->id.next) { BLI_clean(scene->r.pic); diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index b5cdbc58807..e78b89441c9 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -45,6 +45,7 @@ #include "RNA_access.h" +#include "BLI_bpath.h" #include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_rand.h" @@ -181,6 +182,7 @@ void free_brush(Brush *brush) static void extern_local_brush(Brush *brush) { id_lib_extern((ID *)brush->mtex.tex); + id_lib_extern((ID *)brush->clone.image); } void make_local_brush(Brush *brush) @@ -193,29 +195,26 @@ void make_local_brush(Brush *brush) Main *bmain= G.main; Scene *scene; - int local= 0, lib= 0; + int is_local= FALSE, is_lib= FALSE; if(brush->id.lib==NULL) return; if(brush->clone.image) { - /* special case: ima always local immediately */ - brush->clone.image->id.lib= NULL; - brush->clone.image->id.flag= LIB_LOCAL; - new_id(&bmain->brush, (ID *)brush->clone.image, NULL); + /* special case: ima always local immediately. Clone image should only + have one user anyway. */ + id_clear_lib_data(bmain, &brush->clone.image->id); extern_local_brush(brush); } - for(scene= bmain->scene.first; scene && ELEM(0, lib, local); scene=scene->id.next) { + for(scene= bmain->scene.first; scene && ELEM(0, is_lib, is_local); scene=scene->id.next) { if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) { - if(scene->id.lib) lib= 1; - else local= 1; + if(scene->id.lib) is_lib= TRUE; + else is_local= TRUE; } } - if(local && lib==0) { - brush->id.lib= NULL; - brush->id.flag= LIB_LOCAL; - new_id(&bmain->brush, (ID *)brush, NULL); + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &brush->id); extern_local_brush(brush); /* enable fake user by default */ @@ -224,10 +223,13 @@ void make_local_brush(Brush *brush) brush->id.us++; } } - else if(local && lib) { + else if(is_local && is_lib) { Brush *brushn= copy_brush(brush); brushn->id.us= 1; /* only keep fake user */ brushn->id.flag |= LIB_FAKEUSER; + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &brush->id); for(scene= bmain->scene.first; scene; scene=scene->id.next) { if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) { diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index c244c26ad7f..aebf3198cf4 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -703,7 +703,7 @@ static void default_get_tarmat (bConstraint *con, bConstraintOb *UNUSED(cob), bC ct->type = CONSTRAINT_OBTYPE_BONE; \ ct->rotOrder= (pchan) ? (pchan->rotmode) : EULER_ORDER_DEFAULT; \ }\ - else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) && (ct->subtarget[0])) { \ + else if (OB_TYPE_SUPPORT_VGROUP(ct->tar->type) && (ct->subtarget[0])) { \ ct->type = CONSTRAINT_OBTYPE_VERT; \ ct->rotOrder = EULER_ORDER_DEFAULT; \ } \ diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index b6fb776d801..5d2180fe702 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -36,6 +36,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_bpath.h" #include "BLI_blenlib.h" #include "BLI_math.h" #include "BLI_utildefines.h" @@ -245,7 +246,7 @@ void make_local_curve(Curve *cu) { Main *bmain= G.main; Object *ob; - int local=0, lib=0; + int is_local= FALSE, is_lib= FALSE; /* - when there are only lib users: don't do * - when there are only local users: set flag @@ -255,32 +256,28 @@ void make_local_curve(Curve *cu) if(cu->id.lib==NULL) return; if(cu->id.us==1) { - cu->id.lib= NULL; - cu->id.flag= LIB_LOCAL; - - new_id(&bmain->curve, (ID *)cu, NULL); + id_clear_lib_data(bmain, &cu->id); extern_local_curve(cu); return; } - for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) { + for(ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) { if(ob->data == cu) { - if(ob->id.lib) lib= 1; - else local= 1; + if(ob->id.lib) is_lib= TRUE; + else is_local= TRUE; } } - if(local && lib==0) { - cu->id.lib= NULL; - cu->id.flag= LIB_LOCAL; - - new_id(&bmain->curve, (ID *)cu, NULL); + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &cu->id); extern_local_curve(cu); } - else if(local && lib) { + else if(is_local && is_lib) { Curve *cun= copy_curve(cu); cun->id.us= 0; + BKE_id_lib_local_paths(bmain, &cun->id); + for(ob= bmain->object.first; ob; ob= ob->id.next) { if(ob->data==cu) { if(ob->id.lib==NULL) { @@ -1229,7 +1226,7 @@ float *make_orco_curve(Scene *scene, Object *ob) fp[1]= 0.0; fp[2]= 0.0; } else { - VECCOPY(fp, &dl->verts[u*3]); + copy_v3_v3(fp, &dl->verts[u*3]); fp[0]= (fp[0]-cu->loc[0])/cu->size[0]; fp[1]= (fp[1]-cu->loc[1])/cu->size[1]; @@ -1258,7 +1255,7 @@ float *make_orco_curve(Scene *scene, Object *ob) int realu= u % dl->parts; vert= dl->verts + 3*(dl->nr*realu + realv); - VECCOPY(fp, vert); + copy_v3_v3(fp, vert); fp[0]= (fp[0]-cu->loc[0])/cu->size[0]; fp[1]= (fp[1]-cu->loc[1])/cu->size[1]; @@ -1519,7 +1516,7 @@ static short bevelinside(BevList *bl1,BevList *bl2) hvec1[0]= bevp->vec[0]; hvec1[1]= bevp->vec[1]; hvec1[2]= 0.0; - VECCOPY(hvec2,hvec1); + copy_v3_v3(hvec2,hvec1); hvec2[0]+=1000; /* test it with all edges of potential surounding poly */ @@ -1690,15 +1687,15 @@ static void bevel_list_cyclic_fix_3D(BevList *bl) bevp= (BevPoint *)(bl+1); bevp1= bevp+1; - QUATCOPY(bevp->quat, bevp1->quat); - VECCOPY(bevp->dir, bevp1->dir); - VECCOPY(bevp->tan, bevp1->tan); + copy_qt_qt(bevp->quat, bevp1->quat); + copy_v3_v3(bevp->dir, bevp1->dir); + copy_v3_v3(bevp->tan, bevp1->tan); bevp= (BevPoint *)(bl+1); bevp+= (bl->nr-1); bevp1= bevp-1; - QUATCOPY(bevp->quat, bevp1->quat); - VECCOPY(bevp->dir, bevp1->dir); - VECCOPY(bevp->tan, bevp1->tan); + copy_qt_qt(bevp->quat, bevp1->quat); + copy_v3_v3(bevp->dir, bevp1->dir); + copy_v3_v3(bevp->tan, bevp1->tan); } /* utility for make_bevel_list_3D_* funcs */ static void bevel_list_calc_bisect(BevList *bl) @@ -1791,7 +1788,7 @@ static void bevel_list_smooth(BevList *bl, int smooth_iter) } - QUATCOPY(bevp0_quat, bevp0->quat); + copy_qt_qt(bevp0_quat, bevp0->quat); while(nr--) { /* interpolate quats */ @@ -1804,7 +1801,7 @@ static void bevel_list_smooth(BevList *bl, int smooth_iter) axis_angle_to_quat(q2, cross, angle_normalized_v3v3(zaxis, bevp1->dir)); normalize_qt(q2); - QUATCOPY(bevp0_quat, bevp1->quat); + copy_qt_qt(bevp0_quat, bevp1->quat); mul_qt_qtqt(q, q2, q); interp_qt_qtqt(bevp1->quat, bevp1->quat, q, 0.5); normalize_qt(bevp1->quat); @@ -1866,7 +1863,7 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) mul_qt_qtqt(bevp1->quat, q, bevp0->quat); } else { - QUATCOPY(bevp1->quat, bevp0->quat); + copy_qt_qt(bevp1->quat, bevp0->quat); } } @@ -1975,7 +1972,7 @@ static void make_bevel_list_3D_tangent(BevList *bl) bevp1= bevp2+(bl->nr-1); bevp0= bevp1-1; - VECCOPY(bevp0_tan, bevp0->tan); + copy_v3_v3(bevp0_tan, bevp0->tan); nr= bl->nr; while(nr--) { @@ -2035,8 +2032,8 @@ static void make_bevel_list_segment_3D(BevList *bl) axis_angle_to_quat(q, bevp1->dir, bevp1->alfa); mul_qt_qtqt(bevp1->quat, q, bevp1->quat); normalize_qt(bevp1->quat); - VECCOPY(bevp2->dir, bevp1->dir); - QUATCOPY(bevp2->quat, bevp1->quat); + copy_v3_v3(bevp2->dir, bevp1->dir); + copy_qt_qt(bevp2->quat, bevp1->quat); } @@ -2106,7 +2103,7 @@ void makeBevelList(Object *ob) bp= nu->bp; while(len--) { - VECCOPY(bevp->vec, bp->vec); + copy_v3_v3(bevp->vec, bp->vec); bevp->alfa= bp->alfa; bevp->radius= bp->radius; bevp->weight= bp->weight; @@ -2139,7 +2136,7 @@ void makeBevelList(Object *ob) while(a--) { if(prevbezt->h2==HD_VECT && bezt->h1==HD_VECT) { - VECCOPY(bevp->vec, prevbezt->vec[1]); + copy_v3_v3(bevp->vec, prevbezt->vec[1]); bevp->alfa= prevbezt->alfa; bevp->radius= prevbezt->radius; bevp->weight= prevbezt->weight; @@ -2191,7 +2188,7 @@ void makeBevelList(Object *ob) } if((nu->flagu & CU_NURB_CYCLIC)==0) { /* not cyclic: endpoint */ - VECCOPY(bevp->vec, prevbezt->vec[1]); + copy_v3_v3(bevp->vec, prevbezt->vec[1]); bevp->alfa= prevbezt->alfa; bevp->radius= prevbezt->radius; bevp->weight= prevbezt->weight; @@ -3011,15 +3008,15 @@ float (*curve_getVertexCos(Curve *UNUSED(cu), ListBase *lb, int *numVerts_r))[3] BezTriple *bezt = nu->bezt; for (i=0; i<nu->pntsu; i++,bezt++) { - VECCOPY(co, bezt->vec[0]); co+=3; - VECCOPY(co, bezt->vec[1]); co+=3; - VECCOPY(co, bezt->vec[2]); co+=3; + copy_v3_v3(co, bezt->vec[0]); co+=3; + copy_v3_v3(co, bezt->vec[1]); co+=3; + copy_v3_v3(co, bezt->vec[2]); co+=3; } } else { BPoint *bp = nu->bp; for (i=0; i<nu->pntsu*nu->pntsv; i++,bp++) { - VECCOPY(co, bp->vec); co+=3; + copy_v3_v3(co, bp->vec); co+=3; } } } @@ -3038,15 +3035,15 @@ void curve_applyVertexCos(Curve *UNUSED(cu), ListBase *lb, float (*vertexCos)[3] BezTriple *bezt = nu->bezt; for (i=0; i<nu->pntsu; i++,bezt++) { - VECCOPY(bezt->vec[0], co); co+=3; - VECCOPY(bezt->vec[1], co); co+=3; - VECCOPY(bezt->vec[2], co); co+=3; + copy_v3_v3(bezt->vec[0], co); co+=3; + copy_v3_v3(bezt->vec[1], co); co+=3; + copy_v3_v3(bezt->vec[2], co); co+=3; } } else { BPoint *bp = nu->bp; for (i=0; i<nu->pntsu*nu->pntsv; i++,bp++) { - VECCOPY(bp->vec, co); co+=3; + copy_v3_v3(bp->vec, co); co+=3; } } } @@ -3064,9 +3061,9 @@ float (*curve_getKeyVertexCos(Curve *UNUSED(cu), ListBase *lb, float *key))[3] BezTriple *bezt = nu->bezt; for (i=0; i<nu->pntsu; i++,bezt++) { - VECCOPY(co, key); co+=3; key+=3; - VECCOPY(co, key); co+=3; key+=3; - VECCOPY(co, key); co+=3; key+=3; + copy_v3_v3(co, key); co+=3; key+=3; + copy_v3_v3(co, key); co+=3; key+=3; + copy_v3_v3(co, key); co+=3; key+=3; key+=3; /* skip tilt */ } } @@ -3074,7 +3071,7 @@ float (*curve_getKeyVertexCos(Curve *UNUSED(cu), ListBase *lb, float *key))[3] BPoint *bp = nu->bp; for(i=0; i<nu->pntsu*nu->pntsv; i++,bp++) { - VECCOPY(co, key); co+=3; key+=3; + copy_v3_v3(co, key); co+=3; key+=3; key++; /* skip tilt */ } } diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 0f6828cc358..0c3c78f6eef 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -42,6 +42,7 @@ #include "BKE_deform.h" #include "BLI_blenlib.h" +#include "BLI_utildefines.h" void defgroup_copy_list (ListBase *outbase, ListBase *inbase) @@ -103,8 +104,8 @@ void defvert_sync (MDeformVert *dvert_r, const MDeformVert *dvert, int use_verif MDeformWeight *dw; for(i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++) { MDeformWeight *dw_r; - if(use_verify) dw_r= defvert_find_index(dvert_r, dw->def_nr); - else dw_r= defvert_verify_index(dvert_r, dw->def_nr); + if(use_verify) dw_r= defvert_verify_index(dvert_r, dw->def_nr); + else dw_r= defvert_find_index(dvert_r, dw->def_nr); if(dw_r) { dw_r->weight= dw->weight; @@ -114,18 +115,20 @@ void defvert_sync (MDeformVert *dvert_r, const MDeformVert *dvert, int use_verif } /* be sure all flip_map values are valid */ -void defvert_sync_mapped (MDeformVert *dvert_r, const MDeformVert *dvert, const int *flip_map, int use_verify) +void defvert_sync_mapped (MDeformVert *dvert_r, const MDeformVert *dvert, const int *flip_map, const int flip_map_len, const int use_verify) { - if(dvert->totweight && dvert_r->totweight) { + if (dvert->totweight && dvert_r->totweight) { int i; MDeformWeight *dw; - for(i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++) { - MDeformWeight *dw_r; - if(use_verify) dw_r= defvert_find_index(dvert_r, flip_map[dw->def_nr]); - else dw_r= defvert_verify_index(dvert_r, flip_map[dw->def_nr]); - - if(dw_r) { - dw_r->weight= dw->weight; + for (i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++) { + if (dw->def_nr < flip_map_len) { + MDeformWeight *dw_r; + if(use_verify) dw_r= defvert_verify_index(dvert_r, flip_map[dw->def_nr]); + else dw_r= defvert_find_index(dvert_r, flip_map[dw->def_nr]); + + if(dw_r) { + dw_r->weight= dw->weight; + } } } } @@ -163,14 +166,16 @@ void defvert_normalize (MDeformVert *dvert) } } -void defvert_flip (MDeformVert *dvert, const int *flip_map) +void defvert_flip (MDeformVert *dvert, const int *flip_map, const int flip_map_len) { MDeformWeight *dw; int i; - for(dw= dvert->dw, i=0; i<dvert->totweight; dw++, i++) - if(flip_map[dw->def_nr] >= 0) + for(dw= dvert->dw, i=0; i<dvert->totweight; dw++, i++) { + if((dw->def_nr < flip_map_len) && (flip_map[dw->def_nr] >= 0)) { dw->def_nr= flip_map[dw->def_nr]; + } + } } @@ -250,19 +255,21 @@ int defgroup_find_index (Object *ob, bDeformGroup *dg) } /* note, must be freed */ -int *defgroup_flip_map(Object *ob, int use_default) +int *defgroup_flip_map(Object *ob, int *flip_map_len, int use_default) { - bDeformGroup *dg; - int totdg= BLI_countlist(&ob->defbase); + int totdg= *flip_map_len= BLI_countlist(&ob->defbase); if(totdg==0) { return NULL; } else { + bDeformGroup *dg; char name[sizeof(dg->name)]; - int i, flip_num, *map= MEM_mallocN(totdg * sizeof(int), "get_defgroup_flip_map"); + int i, flip_num, *map= MEM_mallocN(totdg * sizeof(int), __func__); - memset(map, -1, totdg * sizeof(int)); + for (i=0; i < totdg; i++) { + map[i]= -1; + } for (dg=ob->defbase.first, i=0; dg; dg=dg->next, i++) { if(map[i] == -1) { /* may be calculated previously */ @@ -271,7 +278,7 @@ int *defgroup_flip_map(Object *ob, int use_default) if(use_default) map[i]= i; - flip_side_name(name, dg->name, 0); + flip_side_name(name, dg->name, FALSE); if(strcmp(name, dg->name)) { flip_num= defgroup_name_index(ob, name); if(flip_num >= 0) { @@ -285,6 +292,40 @@ int *defgroup_flip_map(Object *ob, int use_default) } } +/* note, must be freed */ +int *defgroup_flip_map_single(Object *ob, int *flip_map_len, int use_default, int defgroup) +{ + int totdg= *flip_map_len= BLI_countlist(&ob->defbase); + + if(totdg==0) { + return NULL; + } + else { + bDeformGroup *dg; + char name[sizeof(dg->name)]; + int i, flip_num, *map= MEM_mallocN(totdg * sizeof(int), __func__); + + for (i=0; i < totdg; i++) { + if (use_default) map[i]= i; + else map[i]= -1; + } + + dg= BLI_findlink(&ob->defbase, defgroup); + + flip_side_name(name, dg->name, FALSE); + if(strcmp(name, dg->name)) { + flip_num= defgroup_name_index(ob, name); + + if(flip_num >= 0) { + map[defgroup]= flip_num; + map[flip_num]= defgroup; + } + } + + return map; + } +} + int defgroup_flip_index(Object *ob, int index, int use_default) { bDeformGroup *dg= BLI_findlink(&ob->defbase, index); @@ -482,25 +523,25 @@ MDeformWeight *defvert_verify_index(MDeformVert *dv, const int defgroup) MDeformWeight *newdw; /* do this check always, this function is used to check for it */ - if(!dv || defgroup<0) + if(!dv || defgroup < 0) return NULL; - newdw = defvert_find_index(dv, defgroup); + newdw= defvert_find_index(dv, defgroup); if(newdw) return newdw; - newdw = MEM_callocN(sizeof(MDeformWeight)*(dv->totweight+1), "deformWeight"); - if(dv->dw) { + newdw= MEM_callocN(sizeof(MDeformWeight)*(dv->totweight+1), "deformWeight"); + if (dv->dw) { memcpy(newdw, dv->dw, sizeof(MDeformWeight)*dv->totweight); MEM_freeN(dv->dw); } - dv->dw=newdw; - - dv->dw[dv->totweight].weight=0.0f; - dv->dw[dv->totweight].def_nr=defgroup; + dv->dw= newdw; + newdw += dv->totweight; + newdw->weight= 0.0f; + newdw->def_nr= defgroup; /* Group index */ dv->totweight++; - return dv->dw+(dv->totweight-1); + return newdw; } diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index c4543df0d16..bb14a1ddeaf 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -91,12 +91,12 @@ #include "RE_shader_ext.h" /* fluid sim particle import */ -#ifndef DISABLE_ELBEEM +#ifdef WITH_MOD_FLUID #include "DNA_object_fluidsim.h" #include "LBM_fluidsim.h" #include <zlib.h> #include <string.h> -#endif // DISABLE_ELBEEM +#endif // WITH_MOD_FLUID //XXX #include "BIF_screen.h" diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 3529b7b9e6d..474b3a5ce63 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -1178,16 +1178,16 @@ static float dvar_eval_locDiff (ChannelDriver *driver, DriverVar *dvar) constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL); /* ... and from that, we get our transform */ - VECCOPY(tmp_loc, mat[3]); + copy_v3_v3(tmp_loc, mat[3]); } else { /* transform space (use transform values directly) */ - VECCOPY(tmp_loc, pchan->loc); + copy_v3_v3(tmp_loc, pchan->loc); } } else { /* convert to worldspace */ - VECCOPY(tmp_loc, pchan->pose_head); + copy_v3_v3(tmp_loc, pchan->pose_head); mul_m4_v3(ob->obmat, tmp_loc); } } @@ -1203,25 +1203,25 @@ static float dvar_eval_locDiff (ChannelDriver *driver, DriverVar *dvar) constraint_mat_convertspace(ob, NULL, mat, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL); /* ... and from that, we get our transform */ - VECCOPY(tmp_loc, mat[3]); + copy_v3_v3(tmp_loc, mat[3]); } else { /* transform space (use transform values directly) */ - VECCOPY(tmp_loc, ob->loc); + copy_v3_v3(tmp_loc, ob->loc); } } else { /* worldspace */ - VECCOPY(tmp_loc, ob->obmat[3]); + copy_v3_v3(tmp_loc, ob->obmat[3]); } } /* copy the location to the right place */ if (tarIndex) { - VECCOPY(loc2, tmp_loc); + copy_v3_v3(loc2, tmp_loc); } else { - VECCOPY(loc1, tmp_loc); + copy_v3_v3(loc1, tmp_loc); } } DRIVER_TARGETS_LOOPER_END @@ -1262,7 +1262,7 @@ static float dvar_eval_transChan (ChannelDriver *driver, DriverVar *dvar) if (pchan) { /* bone */ if (pchan->rotmode > 0) { - VECCOPY(oldEul, pchan->eul); + copy_v3_v3(oldEul, pchan->eul); rotOrder= pchan->rotmode; useEulers = 1; } @@ -1289,7 +1289,7 @@ static float dvar_eval_transChan (ChannelDriver *driver, DriverVar *dvar) else { /* object */ if (ob->rotmode > 0) { - VECCOPY(oldEul, ob->rot); + copy_v3_v3(oldEul, ob->rot); rotOrder= ob->rotmode; useEulers = 1; } diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index f16b1e6b4ec..08440849a4e 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -60,10 +60,14 @@ #include "DNA_camera_types.h" #include "DNA_sequence_types.h" #include "DNA_userdef_types.h" +#include "DNA_brush_types.h" +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" #include "BLI_blenlib.h" #include "BLI_threads.h" #include "BLI_utildefines.h" +#include "BLI_bpath.h" #include "BKE_bmfont.h" #include "BKE_global.h" @@ -313,6 +317,133 @@ Image *copy_image(Image *ima) return nima; } +static void extern_local_image(Image *UNUSED(ima)) +{ + /* Nothing to do: images don't link to other IDs. This function exists to + match id_make_local pattern. */ +} + +void make_local_image(struct Image *ima) +{ + Main *bmain= G.main; + Tex *tex; + Brush *brush; + Mesh *me; + int is_local= FALSE, is_lib= FALSE; + + /* - only lib users: do nothing + * - only local users: set flag + * - mixed: make copy + */ + + if(ima->id.lib==NULL) return; + + /* Can't take short cut here: must check meshes at least because of bogus + texface ID refs. - z0r */ +#if 0 + if(ima->id.us==1) { + id_clear_lib_data(bmain, &ima->id); + extern_local_image(ima); + return; + } +#endif + + for(tex= bmain->tex.first; tex; tex= tex->id.next) { + if(tex->ima == ima) { + if(tex->id.lib) is_lib= TRUE; + else is_local= TRUE; + } + } + for(brush= bmain->brush.first; brush; brush= brush->id.next) { + if(brush->clone.image == ima) { + if(brush->id.lib) is_lib= TRUE; + else is_local= TRUE; + } + } + for(me= bmain->mesh.first; me; me= me->id.next) { + if(me->mtface) { + MTFace *tface; + int a, i; + + for(i=0; i<me->fdata.totlayer; i++) { + if(me->fdata.layers[i].type == CD_MTFACE) { + tface= (MTFace*)me->fdata.layers[i].data; + + for(a=0; a<me->totface; a++, tface++) { + if(tface->tpage == ima) { + if(me->id.lib) is_lib= TRUE; + else is_local= TRUE; + } + } + } + } + } + } + + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &ima->id); + extern_local_image(ima); + } + else if(is_local && is_lib) { + Image *iman= copy_image(ima); + + iman->id.us= 0; + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &iman->id); + + tex= bmain->tex.first; + while(tex) { + if(tex->id.lib==NULL) { + if(tex->ima==ima) { + tex->ima = iman; + iman->id.us++; + ima->id.us--; + } + } + tex= tex->id.next; + } + brush= bmain->brush.first; + while(brush) { + if(brush->id.lib==NULL) { + if(brush->clone.image==ima) { + brush->clone.image = iman; + iman->id.us++; + ima->id.us--; + } + } + brush= brush->id.next; + } + /* Transfer references in texfaces. Texfaces don't add to image ID + user count *unless* there are no other users. See + readfile.c:lib_link_mtface. */ + me= bmain->mesh.first; + while(me) { + if(me->mtface) { + MTFace *tface; + int a, i; + + for(i=0; i<me->fdata.totlayer; i++) { + if(me->fdata.layers[i].type == CD_MTFACE) { + tface= (MTFace*)me->fdata.layers[i].data; + + for(a=0; a<me->totface; a++, tface++) { + if(tface->tpage == ima) { + tface->tpage = iman; + if(iman->id.us == 0) { + tface->tpage->id.us= 1; + } + id_lib_extern((ID*)iman); + } + } + } + } + } + me= me->id.next; + } + } +} + void BKE_image_merge(Image *dest, Image *source) { ImBuf *ibuf; @@ -849,7 +980,7 @@ int BKE_add_image_extension(char *string, int imtype) || (G.have_quicktime && BLI_testextensie_array(string, imb_ext_image_qt))) { return BLI_replace_extension(string, FILE_MAX, extension); } else { - strcat(string, extension); + return BLI_ensure_extension(string, FILE_MAX, extension); return TRUE; } @@ -1368,7 +1499,7 @@ void BKE_makepicstring(char *string, const char *base, int frame, int imtype, co } /* used by sequencer too */ -struct anim *openanim(char *name, int flags, int streamindex) +struct anim *openanim(const char *name, int flags, int streamindex) { struct anim *anim; struct ImBuf *ibuf; @@ -1816,7 +1947,7 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) flag = IB_rect|IB_multilayer; if(ima->flag & IMA_DO_PREMUL) flag |= IB_premul; - ibuf = IMB_ibImageFromMemory((unsigned char*)ima->packedfile->data, ima->packedfile->size, flag); + ibuf = IMB_ibImageFromMemory((unsigned char*)ima->packedfile->data, ima->packedfile->size, flag, "<packed data>"); } else { flag= IB_rect|IB_multilayer|IB_metadata; diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index 85e00bcea06..034f4a96879 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -703,14 +703,7 @@ static const char *world_adrcodes_to_paths (int adrcode, int *array_index) return "mist.start"; case WO_MISTHI: return "mist.height"; - - /* Star Color is unused -- recommend removal */ - /* case WO_STAR_R: - *array_index= 0; return "stars.color"; - case WO_STAR_G: - *array_index= 1; return "stars.color"; - case WO_STAR_B: - *array_index= 2; return "stars.color"; */ + case WO_STAR_R: case WO_STAR_G: case WO_STAR_B: diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 5ac8780e4a2..6d095117136 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -181,7 +181,7 @@ void make_local_key(Key *key) if(key==NULL) return; key->id.lib= NULL; - new_id(NULL, (ID *)key, NULL); + new_id(NULL, &key->id, NULL); } /* Sort shape keys and Ipo curves after a change. This assumes that at most @@ -505,7 +505,7 @@ static char *key_block_get_data(Key *key, KeyBlock *actkb, KeyBlock *kb, char ** co= MEM_callocN(sizeof(float)*3*me->edit_mesh->totvert, "key_block_get_data"); for(eve=me->edit_mesh->verts.first; eve; eve=eve->next, a++) - VECCOPY(co[a], eve->co); + copy_v3_v3(co[a], eve->co); *freedata= (char*)co; return (char*)co; @@ -1381,7 +1381,7 @@ float *do_ob_key(Scene *scene, Object *ob) ob->shapenr= 1; } - if(ELEM(ob->type, OB_MESH, OB_LATTICE)) { + if (OB_TYPE_SUPPORT_VGROUP(ob->type)) { float *weights= get_weights_array(ob, kb->vgroup); cp_key(0, tot, tot, out, key, actkb, kb, weights, 0); @@ -1568,7 +1568,7 @@ void latt_to_key(Lattice *lt, KeyBlock *kb) bp= lt->def; fp= kb->data; for(a=0; a<kb->totelem; a++, fp+=3, bp++) { - VECCOPY(fp, bp->vec); + copy_v3_v3(fp, bp->vec); } } @@ -1585,7 +1585,7 @@ void key_to_latt(KeyBlock *kb, Lattice *lt) tot= MIN2(kb->totelem, tot); for(a=0; a<tot; a++, fp+=3, bp++) { - VECCOPY(bp->vec, fp); + copy_v3_v3(bp->vec, fp); } } @@ -1615,11 +1615,11 @@ void curve_to_key(Curve *cu, KeyBlock *kb, ListBase *nurb) bezt= nu->bezt; a= nu->pntsu; while(a--) { - VECCOPY(fp, bezt->vec[0]); + copy_v3_v3(fp, bezt->vec[0]); fp+= 3; - VECCOPY(fp, bezt->vec[1]); + copy_v3_v3(fp, bezt->vec[1]); fp+= 3; - VECCOPY(fp, bezt->vec[2]); + copy_v3_v3(fp, bezt->vec[2]); fp+= 3; fp[0]= bezt->alfa; fp+= 3; /* alphas */ @@ -1630,7 +1630,7 @@ void curve_to_key(Curve *cu, KeyBlock *kb, ListBase *nurb) bp= nu->bp; a= nu->pntsu*nu->pntsv; while(a--) { - VECCOPY(fp, bp->vec); + copy_v3_v3(fp, bp->vec); fp[3]= bp->alfa; fp+= 4; @@ -1662,11 +1662,11 @@ void key_to_curve(KeyBlock *kb, Curve *UNUSED(cu), ListBase *nurb) bezt= nu->bezt; a= nu->pntsu; while(a-- && tot>0) { - VECCOPY(bezt->vec[0], fp); + copy_v3_v3(bezt->vec[0], fp); fp+= 3; - VECCOPY(bezt->vec[1], fp); + copy_v3_v3(bezt->vec[1], fp); fp+= 3; - VECCOPY(bezt->vec[2], fp); + copy_v3_v3(bezt->vec[2], fp); fp+= 3; bezt->alfa= fp[0]; fp+= 3; /* alphas */ @@ -1679,7 +1679,7 @@ void key_to_curve(KeyBlock *kb, Curve *UNUSED(cu), ListBase *nurb) bp= nu->bp; a= nu->pntsu*nu->pntsv; while(a-- && tot>0) { - VECCOPY(bp->vec, fp); + copy_v3_v3(bp->vec, fp); bp->alfa= fp[3]; fp+= 4; @@ -1708,7 +1708,7 @@ void mesh_to_key(Mesh *me, KeyBlock *kb) mvert= me->mvert; fp= kb->data; for(a=0; a<kb->totelem; a++, fp+=3, mvert++) { - VECCOPY(fp, mvert->co); + copy_v3_v3(fp, mvert->co); } } @@ -1725,7 +1725,7 @@ void key_to_mesh(KeyBlock *kb, Mesh *me) tot= MIN2(kb->totelem, me->totvert); for(a=0; a<tot; a++, fp+=3, mvert++) { - VECCOPY(mvert->co, fp); + copy_v3_v3(mvert->co, fp); } } diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 84f9829a639..47878242604 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -39,6 +39,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" +#include "BLI_bpath.h" #include "BLI_math.h" #include "BLI_utildefines.h" @@ -246,7 +247,7 @@ void make_local_lattice(Lattice *lt) { Main *bmain= G.main; Object *ob; - int local=0, lib=0; + int is_local= FALSE, is_lib= FALSE; /* - only lib users: do nothing * - only local users: set flag @@ -255,28 +256,27 @@ void make_local_lattice(Lattice *lt) if(lt->id.lib==NULL) return; if(lt->id.us==1) { - lt->id.lib= NULL; - lt->id.flag= LIB_LOCAL; - new_id(&bmain->latt, (ID *)lt, NULL); + id_clear_lib_data(bmain, <->id); return; } - for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) { + for(ob= bmain->object.first; ob && ELEM(FALSE, is_lib, is_local); ob= ob->id.next) { if(ob->data==lt) { - if(ob->id.lib) lib= 1; - else local= 1; + if(ob->id.lib) is_lib= TRUE; + else is_local= TRUE; } } - if(local && lib==0) { - lt->id.lib= NULL; - lt->id.flag= LIB_LOCAL; - new_id(&bmain->latt, (ID *)lt, NULL); + if(is_local && is_lib==FALSE) { + id_clear_lib_data(bmain, <->id); } - else if(local && lib) { + else if(is_local && is_lib) { Lattice *ltn= copy_lattice(lt); ltn->id.us= 0; + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, <n->id); + for(ob= bmain->object.first; ob; ob= ob->id.next) { if(ob->data==lt) { if(ob->id.lib==NULL) { diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index c44ccd7aa57..35b50730a31 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -74,7 +74,7 @@ #include "BLI_blenlib.h" #include "BLI_dynstr.h" #include "BLI_utildefines.h" - +#include "BLI_bpath.h" #include "BKE_animsys.h" #include "BKE_context.h" @@ -108,6 +108,7 @@ #include "BKE_gpencil.h" #include "BKE_fcurve.h" #include "BKE_speaker.h" +#include "BKE_utildefines.h" #include "RNA_access.h" @@ -126,6 +127,21 @@ /* ************* general ************************ */ + +/* this has to be called from each make_local_* func, we could call + * from id_make_local() but then the make local functions would not be self + * contained. + * also note that the id _must_ have a library - campbell */ +void BKE_id_lib_local_paths(Main *bmain, ID *id) +{ + char *bpath_user_data[2]= {bmain->name, (id)->lib->filepath}; + + bpath_traverse_id(bmain, id, + bpath_relocate_visitor, + BPATH_TRAVERSE_SKIP_MULTIFILE, + bpath_user_data); +} + void id_lib_extern(ID *id) { if(id) { @@ -194,7 +210,8 @@ int id_make_local(ID *id, int test) if(!test) make_local_texture((Tex*)id); return 1; case ID_IM: - return 0; /* not implemented */ + if(!test) make_local_image((Image*)id); + return 1; case ID_LT: if(!test) { make_local_lattice((Lattice*)id); @@ -1246,6 +1263,17 @@ int new_id(ListBase *lb, ID *id, const char *tname) return result; } +/* Pull an ID out of a library (make it local). Only call this for IDs that + don't have other library users. */ +void id_clear_lib_data(Main *bmain, ID *id) +{ + BKE_id_lib_local_paths(bmain, id); + + id->lib= NULL; + id->flag= LIB_LOCAL; + new_id(which_libbase(bmain, GS(id->name)), id, NULL); +} + /* next to indirect usage in read/writefile also in editobject.c scene.c */ void clear_id_newpoins(void) { @@ -1264,16 +1292,6 @@ void clear_id_newpoins(void) } } -/* only for library fixes */ -static void image_fix_relative_path(Image *ima) -{ - if(ima->id.lib==NULL) return; - if(strncmp(ima->name, "//", 2)==0) { - BLI_path_abs(ima->name, ima->id.lib->filepath); - BLI_path_rel(ima->name, G.main->name); - } -} - #define LIBTAG(a) if(a && a->id.lib) {a->id.flag &=~LIB_INDIRECT; a->id.flag |= LIB_EXTERN;} static void lib_indirect_test_id(ID *id, Library *lib) @@ -1348,14 +1366,15 @@ void tag_main(struct Main *mainvar, const short tag) } } -/* if lib!=NULL, only all from lib local */ -void all_local(Library *lib, int untagged_only) +/* if lib!=NULL, only all from lib local + * bmain is almost certainly G.main */ +void BKE_library_make_local(Main *bmain, Library *lib, int untagged_only) { ListBase *lbarray[MAX_LIBARRAY], tempbase={NULL, NULL}; ID *id, *idn; int a; - a= set_listbasepointers(G.main, lbarray); + a= set_listbasepointers(bmain, lbarray); while(a--) { id= lbarray[a]->first; @@ -1372,17 +1391,16 @@ void all_local(Library *lib, int untagged_only) (untagged_only==0 || !(id->flag & LIB_PRE_EXISTING))) { if(lib==NULL || id->lib==lib) { - id->flag &= ~(LIB_EXTERN|LIB_INDIRECT|LIB_NEW); - if(id->lib) { - /* relative file patch */ - if(GS(id->name)==ID_IM) - image_fix_relative_path((Image *)id); - - id->lib= NULL; - new_id(lbarray[a], id, NULL); /* new_id only does it with double names */ + id_clear_lib_data(bmain, id); /* sets 'id->flag' */ + + /* why sort alphabetically here but not in + * id_clear_lib_data() ? - campbell */ sort_alpha_id(lbarray[a], id); } + else { + id->flag &= ~(LIB_EXTERN|LIB_INDIRECT|LIB_NEW); + } } } id= idn; @@ -1397,7 +1415,7 @@ void all_local(Library *lib, int untagged_only) } /* patch 3: make sure library data isn't indirect falsely... */ - a= set_listbasepointers(G.main, lbarray); + a= set_listbasepointers(bmain, lbarray); while(a--) { for(id= lbarray[a]->first; id; id=id->next) lib_indirect_test_id(id, lib); @@ -1464,7 +1482,12 @@ void name_uiprefix_id(char *name, ID *id) void BKE_library_filepath_set(Library *lib, const char *filepath) { - BLI_strncpy(lib->name, filepath, sizeof(lib->name)); + /* in some cases this is used to update the absolute path from the + * relative */ + if (lib->name != filepath) { + BLI_strncpy(lib->name, filepath, sizeof(lib->name)); + } + BLI_strncpy(lib->filepath, filepath, sizeof(lib->filepath)); /* not essential but set filepath is an absolute copy of value which diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 190df040bf4..7be3514e0f2 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -50,6 +50,7 @@ #include "BLI_math.h" #include "BLI_listbase.h" #include "BLI_utildefines.h" +#include "BLI_bpath.h" #include "BKE_animsys.h" #include "BKE_displist.h" @@ -285,8 +286,7 @@ void make_local_material(Material *ma) Mesh *me; Curve *cu; MetaBall *mb; - Material *man; - int a, local=0, lib=0; + int a, is_local= FALSE, is_lib= FALSE; /* - only lib users: do nothing * - only local users: set flag @@ -294,23 +294,24 @@ void make_local_material(Material *ma) */ if(ma->id.lib==NULL) return; - if(ma->id.us==1) { - ma->id.lib= NULL; - ma->id.flag= LIB_LOCAL; - new_id(&bmain->mat, (ID *)ma, NULL); + /* One local user; set flag and return. */ + if(ma->id.us==1) { + id_clear_lib_data(bmain, &ma->id); extern_local_material(ma); return; } - + + /* Check which other IDs reference this one to determine if it's used by + lib or local */ /* test objects */ ob= bmain->object.first; while(ob) { if(ob->mat) { for(a=0; a<ob->totcol; a++) { if(ob->mat[a]==ma) { - if(ob->id.lib) lib= 1; - else local= 1; + if(ob->id.lib) is_lib= TRUE; + else is_local= TRUE; } } } @@ -322,8 +323,8 @@ void make_local_material(Material *ma) if(me->mat) { for(a=0; a<me->totcol; a++) { if(me->mat[a]==ma) { - if(me->id.lib) lib= 1; - else local= 1; + if(me->id.lib) is_lib= TRUE; + else is_local= TRUE; } } } @@ -335,8 +336,8 @@ void make_local_material(Material *ma) if(cu->mat) { for(a=0; a<cu->totcol; a++) { if(cu->mat[a]==ma) { - if(cu->id.lib) lib= 1; - else local= 1; + if(cu->id.lib) is_lib= TRUE; + else is_local= TRUE; } } } @@ -348,26 +349,28 @@ void make_local_material(Material *ma) if(mb->mat) { for(a=0; a<mb->totcol; a++) { if(mb->mat[a]==ma) { - if(mb->id.lib) lib= 1; - else local= 1; + if(mb->id.lib) is_lib= TRUE; + else is_local= TRUE; } } } mb= mb->id.next; } - - if(local && lib==0) { - ma->id.lib= NULL; - ma->id.flag= LIB_LOCAL; - new_id(&bmain->mat, (ID *)ma, NULL); + /* Only local users. */ + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &ma->id); extern_local_material(ma); } - else if(local && lib) { - - man= copy_material(ma); + /* Both user and local, so copy. */ + else if(is_local && is_lib) { + Material *man= copy_material(ma); + man->id.us= 0; - + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &man->id); + /* do objects */ ob= bmain->object.first; while(ob) { diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index b9ca6dda4cf..327306b32ee 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -50,7 +50,7 @@ #include "BLI_blenlib.h" #include "BLI_math.h" #include "BLI_utildefines.h" - +#include "BLI_bpath.h" #include "BKE_global.h" @@ -147,7 +147,7 @@ void make_local_mball(MetaBall *mb) { Main *bmain= G.main; Object *ob; - int local=0, lib=0; + int is_local= FALSE, is_lib= FALSE; /* - only lib users: do nothing * - only local users: set flag @@ -156,32 +156,30 @@ void make_local_mball(MetaBall *mb) if(mb->id.lib==NULL) return; if(mb->id.us==1) { - mb->id.lib= NULL; - mb->id.flag= LIB_LOCAL; - new_id(&bmain->mball, (ID *)mb, NULL); + id_clear_lib_data(bmain, &mb->id); extern_local_mball(mb); return; } - for(ob= G.main->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) { + for(ob= G.main->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) { if(ob->data == mb) { - if(ob->id.lib) lib= 1; - else local= 1; + if(ob->id.lib) is_lib= TRUE; + else is_local= TRUE; } } - if(local && lib==0) { - mb->id.lib= NULL; - mb->id.flag= LIB_LOCAL; - - new_id(&bmain->mball, (ID *)mb, NULL); + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &mb->id); extern_local_mball(mb); } - else if(local && lib) { + else if(is_local && is_lib) { MetaBall *mbn= copy_mball(mb); mbn->id.us= 0; + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &mbn->id); + for(ob= G.main->object.first; ob; ob= ob->id.next) { if(ob->data == mb) { if(ob->id.lib==NULL) { diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 2b92cdf005d..a96d3a3a217 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -43,6 +43,7 @@ #include "DNA_ipo_types.h" #include "BLI_blenlib.h" +#include "BLI_bpath.h" #include "BLI_editVert.h" #include "BLI_math.h" #include "BLI_edgehash.h" @@ -240,39 +241,26 @@ Mesh *copy_mesh(Mesh *me) return men; } -static void make_local_tface(Main *bmain, Mesh *me) +static void expand_local_mesh(Mesh *me) { - MTFace *tface; - Image *ima; - int a, i; - - for(i=0; i<me->fdata.totlayer; i++) { - if(me->fdata.layers[i].type == CD_MTFACE) { - tface= (MTFace*)me->fdata.layers[i].data; - - for(a=0; a<me->totface; a++, tface++) { - /* special case: ima always local immediately */ - if(tface->tpage) { - ima= tface->tpage; - if(ima->id.lib) { - ima->id.lib= NULL; - ima->id.flag= LIB_LOCAL; - new_id(&bmain->image, (ID *)ima, NULL); + id_lib_extern((ID *)me->texcomesh); + + if(me->mtface) { + MTFace *tface; + int a, i; + + for(i=0; i<me->fdata.totlayer; i++) { + if(me->fdata.layers[i].type == CD_MTFACE) { + tface= (MTFace*)me->fdata.layers[i].data; + + for(a=0; a<me->totface; a++, tface++) { + if(tface->tpage) { + id_lib_extern((ID *)tface->tpage); } } } } } -} - -static void expand_local_mesh(Main *bmain, Mesh *me) -{ - id_lib_extern((ID *)me->texcomesh); - - if(me->mtface) { - /* why is this an exception? - should not really make local when extern'ing - campbell */ - make_local_tface(bmain, me); - } if(me->mat) { extern_local_matarar(me->mat, me->totcol); @@ -283,7 +271,7 @@ void make_local_mesh(Mesh *me) { Main *bmain= G.main; Object *ob; - int local=0, lib=0; + int is_local= FALSE, is_lib= FALSE; /* - only lib users: do nothing * - only local users: set flag @@ -292,32 +280,30 @@ void make_local_mesh(Mesh *me) if(me->id.lib==NULL) return; if(me->id.us==1) { - me->id.lib= NULL; - me->id.flag= LIB_LOCAL; - - new_id(&bmain->mesh, (ID *)me, NULL); - expand_local_mesh(bmain, me); + id_clear_lib_data(bmain, &me->id); + expand_local_mesh(me); return; } - for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) { + for(ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) { if(me == ob->data) { - if(ob->id.lib) lib= 1; - else local= 1; + if(ob->id.lib) is_lib= TRUE; + else is_local= TRUE; } } - if(local && lib==0) { - me->id.lib= NULL; - me->id.flag= LIB_LOCAL; - - new_id(&bmain->mesh, (ID *)me, NULL); - expand_local_mesh(bmain, me); + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &me->id); + expand_local_mesh(me); } - else if(local && lib) { + else if(is_local && is_lib) { Mesh *men= copy_mesh(me); men->id.us= 0; + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &men->id); + for(ob= bmain->object.first; ob; ob= ob->id.next) { if(me == ob->data) { if(ob->id.lib==NULL) { @@ -1329,7 +1315,6 @@ UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned UvVertMap *vmap; UvMapVert *buf; MFace *mf; - MTFace *tf; unsigned int a; int i, totuv, nverts; @@ -1337,8 +1322,7 @@ UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned /* generate UvMapVert array */ mf= mface; - tf= tface; - for(a=0; a<totface; a++, mf++, tf++) + for(a=0; a<totface; a++, mf++) if(!selected || (!(mf->flag & ME_HIDE) && (mf->flag & ME_FACE_SEL))) totuv += (mf->v4)? 4: 3; @@ -1358,8 +1342,7 @@ UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned } mf= mface; - tf= tface; - for(a=0; a<totface; a++, mf++, tf++) { + for(a=0; a<totface; a++, mf++) { if(!selected || (!(mf->flag & ME_HIDE) && (mf->flag & ME_FACE_SEL))) { nverts= (mf->v4)? 4: 3; @@ -1375,7 +1358,6 @@ UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned } /* sort individual uvs for each vert */ - tf= tface; for(a=0; a<totvert; a++) { UvMapVert *newvlist= NULL, *vlist=vmap->vert[a]; UvMapVert *iterv, *v, *lastv, *next; @@ -1387,14 +1369,14 @@ UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned v->next= newvlist; newvlist= v; - uv= (tf+v->f)->uv[v->tfindex]; + uv= tface[v->f].uv[v->tfindex]; lastv= NULL; iterv= vlist; while(iterv) { next= iterv->next; - uv2= (tf+iterv->f)->uv[iterv->tfindex]; + uv2= tface[iterv->f].uv[iterv->tfindex]; sub_v2_v2v2(uvdiff, uv2, uv); diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c index 6b40c0d8f25..0dac4b8cd80 100644 --- a/source/blender/blenkernel/intern/mesh_validate.c +++ b/source/blender/blenkernel/intern/mesh_validate.c @@ -115,9 +115,10 @@ static int search_face_cmp(const void *v1, const void *v2) } +#define PRINT if(do_verbose) printf + int BKE_mesh_validate_arrays(Mesh *me, MVert *UNUSED(mverts), unsigned int totvert, MEdge *medges, unsigned int totedge, MFace *mfaces, unsigned int totface, const short do_verbose, const short do_fixes) { -# define PRINT if(do_verbose) printf # define REMOVE_EDGE_TAG(_med) { _med->v2= _med->v1; do_edge_free= 1; } # define REMOVE_FACE_TAG(_mf) { _mf->v3=0; do_face_free= 1; } @@ -282,7 +283,6 @@ int BKE_mesh_validate_arrays(Mesh *me, MVert *UNUSED(mverts), unsigned int totve PRINT("BKE_mesh_validate: finished\n\n"); -# undef PRINT # undef REMOVE_EDGE_TAG # undef REMOVE_FACE_TAG @@ -303,12 +303,57 @@ int BKE_mesh_validate_arrays(Mesh *me, MVert *UNUSED(mverts), unsigned int totve return (do_face_free || do_edge_free || do_edge_recalc); } +static int mesh_validate_customdata(CustomData *data, short do_verbose, const short do_fixes) +{ + int i= 0, has_fixes= 0; + + while(i<data->totlayer) { + CustomDataLayer *layer= &data->layers[i]; + int mask= 1 << layer->type; + int ok= 1; + + if((mask&CD_MASK_MESH)==0) { + PRINT("CustomDataLayer type %d which isn't in CD_MASK_MESH is stored in Mehs structure\n", layer->type); + + if(do_fixes) { + CustomData_free_layer(data, layer->type, 0, i); + ok= 0; + has_fixes= 1; + } + } + + if(ok) + i++; + } + + return has_fixes; +} + +#undef PRINT + +int BKE_mesh_validate_all_customdata(CustomData *vdata, CustomData *edata, CustomData *fdata, short do_verbose, const short do_fixes) +{ + int vfixed= 0, efixed= 0, ffixed= 0; + + vfixed= mesh_validate_customdata(vdata, do_verbose, do_fixes); + efixed= mesh_validate_customdata(edata, do_verbose, do_fixes); + ffixed= mesh_validate_customdata(fdata, do_verbose, do_fixes); + + return vfixed || efixed || ffixed; +} + int BKE_mesh_validate(Mesh *me, int do_verbose) { + int layers_fixed= 0, arrays_fixed= 0; + if(do_verbose) { printf("MESH: %s\n", me->id.name+2); } - return BKE_mesh_validate_arrays(me, me->mvert, me->totvert, me->medge, me->totedge, me->mface, me->totface, do_verbose, TRUE); + + layers_fixed= BKE_mesh_validate_all_customdata(&me->vdata, &me->edata, &me->fdata, do_verbose, TRUE); + arrays_fixed= BKE_mesh_validate_arrays(me, me->mvert, me->totvert, me->medge, me->totedge, me->mface, me->totface, do_verbose, TRUE); + + return layers_fixed || arrays_fixed; } int BKE_mesh_validate_dm(DerivedMesh *dm) diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 1b5af94fb25..9c2b6cae751 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1040,6 +1040,7 @@ static void ntreeMakeLocal_LinkNew(void *calldata, ID *owner_id, bNodeTree *ntre void ntreeMakeLocal(bNodeTree *ntree) { + Main *bmain= G.main; bNodeTreeType *treetype= ntreeGetType(ntree->type); MakeLocalCallData cd; @@ -1050,9 +1051,7 @@ void ntreeMakeLocal(bNodeTree *ntree) if(ntree->id.lib==NULL) return; if(ntree->id.us==1) { - ntree->id.lib= NULL; - ntree->id.flag= LIB_LOCAL; - new_id(NULL, (ID *)ntree, NULL); + id_clear_lib_data(bmain, (ID *)ntree); return; } @@ -1066,9 +1065,7 @@ void ntreeMakeLocal(bNodeTree *ntree) /* if all users are local, we simply make tree local */ if(cd.local && cd.lib==0) { - ntree->id.lib= NULL; - ntree->id.flag= LIB_LOCAL; - new_id(NULL, (ID *)ntree, NULL); + id_clear_lib_data(bmain, (ID *)ntree); } else if(cd.local && cd.lib) { /* this is the mixed case, we copy the tree and assign it to local users */ diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 27f40aa6d6a..a5edd569bc2 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -56,6 +56,7 @@ #include "DNA_world_types.h" #include "BLI_blenlib.h" +#include "BLI_bpath.h" #include "BLI_editVert.h" #include "BLI_math.h" #include "BLI_pbvh.h" @@ -748,7 +749,7 @@ void make_local_camera(Camera *cam) { Main *bmain= G.main; Object *ob; - int local=0, lib=0; + int is_local= FALSE, is_lib= FALSE; /* - only lib users: do nothing * - only local users: set flag @@ -757,28 +758,28 @@ void make_local_camera(Camera *cam) if(cam->id.lib==NULL) return; if(cam->id.us==1) { - cam->id.lib= NULL; - cam->id.flag= LIB_LOCAL; - new_id(&bmain->camera, (ID *)cam, NULL); + id_clear_lib_data(bmain, &cam->id); return; } - for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) { + for(ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) { if(ob->data==cam) { - if(ob->id.lib) lib= 1; - else local= 1; + if(ob->id.lib) is_lib= TRUE; + else is_local= TRUE; } } - if(local && lib==0) { - cam->id.lib= NULL; - cam->id.flag= LIB_LOCAL; - new_id(&bmain->camera, (ID *)cam, NULL); + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &cam->id); } - else if(local && lib) { + else if(is_local && is_lib) { Camera *camn= copy_camera(cam); + camn->id.us= 0; - + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &camn->id); + for(ob= bmain->object.first; ob; ob= ob->id.next) { if(ob->data == cam) { if(ob->id.lib==NULL) { @@ -918,8 +919,7 @@ void make_local_lamp(Lamp *la) { Main *bmain= G.main; Object *ob; - Lamp *lan; - int local=0, lib=0; + int is_local= FALSE, is_lib= FALSE; /* - only lib users: do nothing * - only local users: set flag @@ -928,30 +928,29 @@ void make_local_lamp(Lamp *la) if(la->id.lib==NULL) return; if(la->id.us==1) { - la->id.lib= NULL; - la->id.flag= LIB_LOCAL; - new_id(&bmain->lamp, (ID *)la, NULL); + id_clear_lib_data(bmain, &la->id); return; } ob= bmain->object.first; while(ob) { if(ob->data==la) { - if(ob->id.lib) lib= 1; - else local= 1; + if(ob->id.lib) is_lib= TRUE; + else is_local= TRUE; } ob= ob->id.next; } - if(local && lib==0) { - la->id.lib= NULL; - la->id.flag= LIB_LOCAL; - new_id(&bmain->lamp, (ID *)la, NULL); + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &la->id); } - else if(local && lib) { - lan= copy_lamp(la); + else if(is_local && is_lib) { + Lamp *lan= copy_lamp(la); lan->id.us= 0; - + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &lan->id); + ob= bmain->object.first; while(ob) { if(ob->data==la) { @@ -1469,7 +1468,7 @@ void make_local_object(Object *ob) Main *bmain= G.main; Scene *sce; Base *base; - int local=0, lib=0; + int is_local= FALSE, is_lib= FALSE; /* - only lib users: do nothing * - only local users: set flag @@ -1481,27 +1480,29 @@ void make_local_object(Object *ob) ob->proxy= ob->proxy_from= NULL; if(ob->id.us==1) { - ob->id.lib= NULL; - ob->id.flag= LIB_LOCAL; - new_id(&bmain->object, (ID *)ob, NULL); + id_clear_lib_data(bmain, &ob->id); + extern_local_object(ob); } else { - for(sce= bmain->scene.first; sce && ELEM(0, lib, local); sce= sce->id.next) { + for(sce= bmain->scene.first; sce && ELEM(0, is_lib, is_local); sce= sce->id.next) { if(object_in_scene(ob, sce)) { - if(sce->id.lib) lib= 1; - else local= 1; + if(sce->id.lib) is_lib= TRUE; + else is_local= TRUE; } } - if(local && lib==0) { - ob->id.lib= NULL; - ob->id.flag= LIB_LOCAL; - new_id(&bmain->object, (ID *)ob, NULL); + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &ob->id); + extern_local_object(ob); } - else if(local && lib) { + else if(is_local && is_lib) { Object *obn= copy_object(ob); + obn->id.us= 0; + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &obn->id); + sce= bmain->scene.first; while(sce) { if(sce->id.lib==NULL) { @@ -1519,8 +1520,6 @@ void make_local_object(Object *ob) } } } - - extern_local_object(ob); } /* @@ -2043,7 +2042,7 @@ static void give_parvert(Object *par, int nr, float *vec) while(a--) { if(count==nr) { found= 1; - VECCOPY(vec, bezt->vec[1]); + copy_v3_v3(vec, bezt->vec[1]); break; } count++; @@ -2111,7 +2110,7 @@ static void ob_parvert3(Object *ob, Object *par, float mat[][4]) copy_m4_m3(mat, cmat); if(ob->type==OB_CURVE) { - VECCOPY(mat[3], v1); + copy_v3_v3(mat[3], v1); } else { add_v3_v3v3(mat[3], v1, v2); @@ -2235,7 +2234,7 @@ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[ case PARVERT1: unit_m4(totmat); if (simul){ - VECCOPY(totmat[3], par->obmat[3]); + copy_v3_v3(totmat[3], par->obmat[3]); } else{ give_parvert(par, ob->par1, vec); @@ -2269,10 +2268,10 @@ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[ // origin, voor help line if( (ob->partype & PARTYPE)==PARSKEL ) { - VECCOPY(ob->orig, par->obmat[3]); + copy_v3_v3(ob->orig, par->obmat[3]); } else { - VECCOPY(ob->orig, totmat[3]); + copy_v3_v3(ob->orig, totmat[3]); } } diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index e5f802c5675..7678da1c7c4 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -53,6 +53,7 @@ #include "BLI_rand.h" #include "BLI_threads.h" #include "BLI_linklist.h" +#include "BLI_bpath.h" #include "BKE_anim.h" #include "BKE_animsys.h" @@ -3601,7 +3602,7 @@ void make_local_particlesettings(ParticleSettings *part) { Main *bmain= G.main; Object *ob; - int local=0, lib=0; + int is_local= FALSE, is_lib= FALSE; /* - only lib users: do nothing * - only local users: set flag @@ -3610,34 +3611,34 @@ void make_local_particlesettings(ParticleSettings *part) if(part->id.lib==0) return; if(part->id.us==1) { - part->id.lib= 0; - part->id.flag= LIB_LOCAL; - new_id(&bmain->particle, (ID *)part, 0); + id_clear_lib_data(bmain, &part->id); expand_local_particlesettings(part); return; } /* test objects */ - for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) { + for(ob= bmain->object.first; ob && ELEM(FALSE, is_lib, is_local); ob= ob->id.next) { ParticleSystem *psys=ob->particlesystem.first; for(; psys; psys=psys->next){ if(psys->part==part) { - if(ob->id.lib) lib= 1; - else local= 1; + if(ob->id.lib) is_lib= TRUE; + else is_local= TRUE; } } } - if(local && lib==0) { - part->id.lib= 0; - part->id.flag= LIB_LOCAL; - new_id(&bmain->particle, (ID *)part, 0); + if(is_local && is_lib==FALSE) { + id_clear_lib_data(bmain, &part->id); expand_local_particlesettings(part); } - else if(local && lib) { + else if(is_local && is_lib) { ParticleSettings *partn= psys_copy_settings(part); + partn->id.us= 0; - + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &partn->id); + /* do objects */ for(ob= bmain->object.first; ob; ob= ob->id.next) { ParticleSystem *psys; diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index c28bbfa0554..ec058b23050 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -95,13 +95,13 @@ #include "RE_shader_ext.h" /* fluid sim particle import */ -#ifndef DISABLE_ELBEEM +#ifdef WITH_MOD_FLUID #include "DNA_object_fluidsim.h" #include "LBM_fluidsim.h" #include <zlib.h> #include <string.h> -#endif // DISABLE_ELBEEM +#endif // WITH_MOD_FLUID /************************************************/ /* Reacting to system events */ @@ -3853,8 +3853,9 @@ static void update_children(ParticleSimulationData *sim) else if(sim->psys->part->childtype) { if(sim->psys->totchild != get_psys_tot_child(sim->scene, sim->psys)) distribute_particles(sim, PART_FROM_CHILD); - else - ; /* Children are up to date, nothing to do. */ + else { + /* Children are up to date, nothing to do. */ + } } else psys_free_children(sim->psys); @@ -3915,7 +3916,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) } /* fluid sim particle import handling, actual loading of particles from file */ - #ifndef DISABLE_ELBEEM + #ifdef WITH_MOD_FLUID { FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(sim->ob, eModifierType_Fluidsim); @@ -4008,7 +4009,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) } // fluid sim particles done } - #endif // DISABLE_ELBEEM + #endif // WITH_MOD_FLUID } static int emit_particles(ParticleSimulationData *sim, PTCacheID *pid, float UNUSED(cfra)) diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index ac2a840c95a..7174126a00c 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -77,6 +77,8 @@ #include "BKE_smoke.h" +#ifdef WITH_SMOKE + #ifdef _WIN32 #include <time.h> #include <stdio.h> @@ -131,12 +133,13 @@ struct SmokeModifierData; #define TRI_UVOFFSET (1./4.) -#ifdef WITH_SMOKE /* forward declerations */ static void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *tris, int numfaces, int numtris, int **tridivs, float cell_len); static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct); static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs); + #else /* WITH_SMOKE */ + /* Stubs to use when smoke is disabled */ struct WTURBULENCE *smoke_turbulence_init(int *UNUSED(res), int UNUSED(amplify), int UNUSED(noisetype)) { return NULL; } struct FLUID_3D *smoke_init(int *UNUSED(res), float *UNUSED(p0)) { return NULL; } @@ -146,9 +149,11 @@ void smoke_initWaveletBlenderRNA(struct WTURBULENCE *UNUSED(wt), float *UNUSED(s void smoke_initBlenderRNA(struct FLUID_3D *UNUSED(fluid), float *UNUSED(alpha), float *UNUSED(beta), float *UNUSED(dt_factor), float *UNUSED(vorticity), int *UNUSED(border_colli)) {} long long smoke_get_mem_req(int UNUSED(xres), int UNUSED(yres), int UNUSED(zres), int UNUSED(amplify)) { return 0; } void smokeModifier_do(SmokeModifierData *UNUSED(smd), Scene *UNUSED(scene), Object *UNUSED(ob), DerivedMesh *UNUSED(dm)) {} + #endif /* WITH_SMOKE */ #ifdef WITH_SMOKE + static int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, DerivedMesh *dm) { if((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain && !smd->domain->fluid) diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c index b743f847bb7..018c7a197ff 100644 --- a/source/blender/blenkernel/intern/speaker.c +++ b/source/blender/blenkernel/intern/speaker.c @@ -34,6 +34,8 @@ #include "DNA_speaker_types.h" #include "BLI_math.h" +#include "BLI_utildefines.h" +#include "BLI_bpath.h" #include "BKE_animsys.h" #include "BKE_global.h" @@ -78,7 +80,7 @@ void make_local_speaker(Speaker *spk) { Main *bmain= G.main; Object *ob; - int local=0, lib=0; + int is_local= FALSE, is_lib= FALSE; /* - only lib users: do nothing * - only local users: set flag @@ -87,30 +89,29 @@ void make_local_speaker(Speaker *spk) if(spk->id.lib==NULL) return; if(spk->id.us==1) { - spk->id.lib= NULL; - spk->id.flag= LIB_LOCAL; - new_id(&bmain->speaker, (ID *)spk, NULL); + id_clear_lib_data(bmain, &spk->id); return; } ob= bmain->object.first; while(ob) { if(ob->data==spk) { - if(ob->id.lib) lib= 1; - else local= 1; + if(ob->id.lib) is_lib= TRUE; + else is_local= TRUE; } ob= ob->id.next; } - if(local && lib==0) { - spk->id.lib= NULL; - spk->id.flag= LIB_LOCAL; - new_id(&bmain->speaker, (ID *)spk, NULL); + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &spk->id); } - else if(local && lib) { + else if(is_local && is_lib) { Speaker *spkn= copy_speaker(spk); spkn->id.us= 0; + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &spkn->id); + ob= bmain->object.first; while(ob) { if(ob->data==spk) { diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 42415248bdc..d3bd7d7b766 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -42,6 +42,7 @@ #include "BLI_math.h" #include "BLI_kdopbvh.h" #include "BLI_utildefines.h" +#include "BLI_bpath.h" #include "DNA_key_types.h" #include "DNA_object_types.h" @@ -814,16 +815,20 @@ Tex *localize_texture(Tex *tex) /* ------------------------------------------------------------------------- */ +static void extern_local_texture(Tex *tex) +{ + id_lib_extern((ID *)tex->ima); +} + void make_local_texture(Tex *tex) { Main *bmain= G.main; - Tex *texn; Material *ma; World *wrld; Lamp *la; Brush *br; ParticleSettings *pa; - int a, local=0, lib=0; + int a, is_local= FALSE, is_lib= FALSE; /* - only lib users: do nothing * - only local users: set flag @@ -832,18 +837,9 @@ void make_local_texture(Tex *tex) if(tex->id.lib==NULL) return; - /* special case: ima always local immediately */ - if(tex->ima) { - tex->ima->id.lib= NULL; - tex->ima->id.flag= LIB_LOCAL; - new_id(&bmain->image, (ID *)tex->ima, NULL); - } - if(tex->id.us==1) { - tex->id.lib= NULL; - tex->id.flag= LIB_LOCAL; - new_id(&bmain->tex, (ID *)tex, NULL); - + id_clear_lib_data(bmain, &tex->id); + extern_local_texture(tex); return; } @@ -851,8 +847,8 @@ void make_local_texture(Tex *tex) while(ma) { for(a=0; a<MAX_MTEX; a++) { if(ma->mtex[a] && ma->mtex[a]->tex==tex) { - if(ma->id.lib) lib= 1; - else local= 1; + if(ma->id.lib) is_lib= TRUE; + else is_local= TRUE; } } ma= ma->id.next; @@ -861,8 +857,8 @@ void make_local_texture(Tex *tex) while(la) { for(a=0; a<MAX_MTEX; a++) { if(la->mtex[a] && la->mtex[a]->tex==tex) { - if(la->id.lib) lib= 1; - else local= 1; + if(la->id.lib) is_lib= TRUE; + else is_local= TRUE; } } la= la->id.next; @@ -871,8 +867,8 @@ void make_local_texture(Tex *tex) while(wrld) { for(a=0; a<MAX_MTEX; a++) { if(wrld->mtex[a] && wrld->mtex[a]->tex==tex) { - if(wrld->id.lib) lib= 1; - else local= 1; + if(wrld->id.lib) is_lib= TRUE; + else is_local= TRUE; } } wrld= wrld->id.next; @@ -880,8 +876,8 @@ void make_local_texture(Tex *tex) br= bmain->brush.first; while(br) { if(br->mtex.tex==tex) { - if(br->id.lib) lib= 1; - else local= 1; + if(br->id.lib) is_lib= TRUE; + else is_local= TRUE; } br= br->id.next; } @@ -889,21 +885,24 @@ void make_local_texture(Tex *tex) while(pa) { for(a=0; a<MAX_MTEX; a++) { if(pa->mtex[a] && pa->mtex[a]->tex==tex) { - if(pa->id.lib) lib= 1; - else local= 1; + if(pa->id.lib) is_lib= TRUE; + else is_local= TRUE; } } pa= pa->id.next; } - if(local && lib==0) { - tex->id.lib= NULL; - tex->id.flag= LIB_LOCAL; - new_id(&bmain->tex, (ID *)tex, NULL); + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &tex->id); + extern_local_texture(tex); } - else if(local && lib) { - texn= copy_texture(tex); + else if(is_local && is_lib) { + Tex *texn= copy_texture(tex); + texn->id.us= 0; + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &texn->id); ma= bmain->mat.first; while(ma) { diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index c972f8e1c5c..9a26cc61cfd 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -40,6 +40,7 @@ #include "BLI_listbase.h" #include "BLI_utildefines.h" +#include "BLI_bpath.h" #include "BKE_world.h" #include "BKE_library.h" @@ -165,7 +166,7 @@ void make_local_world(World *wrld) { Main *bmain= G.main; Scene *sce; - int local=0, lib=0; + int is_local= FALSE, is_lib= FALSE; /* - only lib users: do nothing * - only local users: set flag @@ -174,28 +175,27 @@ void make_local_world(World *wrld) if(wrld->id.lib==NULL) return; if(wrld->id.us==1) { - wrld->id.lib= NULL; - wrld->id.flag= LIB_LOCAL; - new_id(NULL, (ID *)wrld, NULL); + id_clear_lib_data(bmain, &wrld->id); return; } - for(sce= bmain->scene.first; sce && ELEM(0, lib, local); sce= sce->id.next) { + for(sce= bmain->scene.first; sce && ELEM(FALSE, is_lib, is_local); sce= sce->id.next) { if(sce->world == wrld) { - if(sce->id.lib) lib= 1; - else local= 1; + if(sce->id.lib) is_lib= TRUE; + else is_local= TRUE; } } - if(local && lib==0) { - wrld->id.lib= NULL; - wrld->id.flag= LIB_LOCAL; - new_id(NULL, (ID *)wrld, NULL); + if(is_local && is_lib==FALSE) { + id_clear_lib_data(bmain, &wrld->id); } - else if(local && lib) { + else if(is_local && is_lib) { World *wrldn= copy_world(wrld); wrldn->id.us= 0; - + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &wrldn->id); + for(sce= bmain->scene.first; sce; sce= sce->id.next) { if(sce->world == wrld) { if(sce->id.lib==NULL) { diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index bdca3c8e618..da1412dac0d 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -1102,7 +1102,7 @@ IDProperty *ffmpeg_property_add(RenderData *rd, char * type, int opt_index, int idp_type = IDP_FLOAT; break; case FF_OPT_TYPE_STRING: - val.str = " "; + val.str = (char *)" "; idp_type = IDP_STRING; break; case FF_OPT_TYPE_CONST: @@ -1377,4 +1377,3 @@ void ffmpeg_verify_image_type(RenderData *rd) } #endif - |