diff options
Diffstat (limited to 'source/blender/blenkernel/intern')
25 files changed, 9287 insertions, 9282 deletions
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 90cfb9a1d82..9e46d03a3ab 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -83,7 +83,7 @@ bAction *add_empty_action(const char name[]) { bAction *act; - act= BKE_libblock_alloc(&G.main->action, ID_AC, name); + act = BKE_libblock_alloc(&G.main->action, ID_AC, name); return act; } @@ -105,8 +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->is_lib= TRUE; - else mlac->is_local= TRUE; + if (id->lib) mlac->is_lib = TRUE; + else mlac->is_local = TRUE; } } @@ -129,25 +129,25 @@ static void make_localact_apply_cb(ID *id, AnimData *adt, void *mlac_ptr) void BKE_action_make_local(bAction *act) { tMakeLocalActionContext mlac = {act, NULL, FALSE, FALSE}; - Main *bmain= G.main; + Main *bmain = G.main; - if (act->id.lib==NULL) + if (act->id.lib == NULL) return; // 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)) { + if ((act->id.flag & LIB_FAKEUSER) && (act->id.us <= 1)) { id_clear_lib_data(bmain, &act->id); return; } BKE_animdata_main_cb(bmain, make_localact_init_cb, &mlac); - if (mlac.is_local && mlac.is_lib==FALSE) { + if (mlac.is_local && mlac.is_lib == FALSE) { id_clear_lib_data(bmain, &act->id); } else if (mlac.is_local && mlac.is_lib) { - mlac.act_new= BKE_action_copy(act); - mlac.act_new->id.us= 0; + mlac.act_new = BKE_action_copy(act); + mlac.act_new->id.us = 0; BKE_id_lib_local_paths(bmain, act->id.lib, &mlac.act_new->id); @@ -177,7 +177,7 @@ void BKE_action_free(bAction *act) /* .................................. */ -bAction *BKE_action_copy (bAction *src) +bAction *BKE_action_copy(bAction *src) { bAction *dst = NULL; bActionGroup *dgrp, *sgrp; @@ -185,29 +185,29 @@ bAction *BKE_action_copy (bAction *src) if (src == NULL) return NULL; - dst= BKE_libblock_copy(&src->id); + dst = BKE_libblock_copy(&src->id); /* duplicate the lists of groups and markers */ BLI_duplicatelist(&dst->groups, &src->groups); BLI_duplicatelist(&dst->markers, &src->markers); /* copy F-Curves, fixing up the links as we go */ - dst->curves.first= dst->curves.last= NULL; + dst->curves.first = dst->curves.last = NULL; - for (sfcu= src->curves.first; sfcu; sfcu= sfcu->next) { + for (sfcu = src->curves.first; sfcu; sfcu = sfcu->next) { /* duplicate F-Curve */ - dfcu= copy_fcurve(sfcu); + dfcu = copy_fcurve(sfcu); BLI_addtail(&dst->curves, dfcu); /* fix group links (kindof bad list-in-list search, but this is the most reliable way) */ - for (dgrp=dst->groups.first, sgrp=src->groups.first; dgrp && sgrp; dgrp=dgrp->next, sgrp=sgrp->next) { + for (dgrp = dst->groups.first, sgrp = src->groups.first; dgrp && sgrp; dgrp = dgrp->next, sgrp = sgrp->next) { if (sfcu->grp == sgrp) { - dfcu->grp= dgrp; + dfcu->grp = dgrp; if (dgrp->channels.first == sfcu) - dgrp->channels.first= dfcu; + dgrp->channels.first = dfcu; if (dgrp->channels.last == sfcu) - dgrp->channels.last= dfcu; + dgrp->channels.last = dfcu; break; } @@ -220,12 +220,12 @@ bAction *BKE_action_copy (bAction *src) /* *************** Action Groups *************** */ /* Get the active action-group for an Action */ -bActionGroup *get_active_actiongroup (bAction *act) +bActionGroup *get_active_actiongroup(bAction *act) { - bActionGroup *agrp= NULL; + bActionGroup *agrp = NULL; if (act && act->groups.first) { - for (agrp= act->groups.first; agrp; agrp= agrp->next) { + for (agrp = act->groups.first; agrp; agrp = agrp->next) { if (agrp->flag & AGRP_ACTIVE) break; } @@ -244,8 +244,8 @@ void set_active_action_group(bAction *act, bActionGroup *agrp, short select) return; /* Deactive all others */ - for (grp= act->groups.first; grp; grp= grp->next) { - if ((grp==agrp) && (select)) + for (grp = act->groups.first; grp; grp = grp->next) { + if ((grp == agrp) && (select)) grp->flag |= AGRP_ACTIVE; else grp->flag &= ~AGRP_ACTIVE; @@ -253,7 +253,7 @@ void set_active_action_group(bAction *act, bActionGroup *agrp, short select) } /* Add a new action group with the given name to the action */ -bActionGroup *action_groups_add_new (bAction *act, const char name[]) +bActionGroup *action_groups_add_new(bAction *act, const char name[]) { bActionGroup *agrp; @@ -303,7 +303,7 @@ void action_groups_add_channel(bAction *act, bActionGroup *agrp, FCurve *fcurve) * the lists will be in sync after linking */ if (agrp->channels.last == act->curves.last) - act->curves.last= fcurve; + act->curves.last = fcurve; /* link in the given F-Curve after the last F-Curve in the group, * which means that it should be able to fit in with the rest of the @@ -320,7 +320,7 @@ void action_groups_add_channel(bAction *act, bActionGroup *agrp, FCurve *fcurve) agrp->channels.first = agrp->channels.last = fcurve; /* step through the groups preceding this one, finding the F-Curve there to attach this one after */ - for (grp= agrp->prev; grp; grp= grp->prev) { + for (grp = agrp->prev; grp; grp = grp->prev) { /* if this group has F-Curves, we want weave the given one in right after the last channel there, * but via the Action's list not this group's list * - this is so that the F-Curve is in the right place in the Action, @@ -342,7 +342,7 @@ void action_groups_add_channel(bAction *act, bActionGroup *agrp, FCurve *fcurve) } /* set the F-Curve's new group */ - fcurve->grp= agrp; + fcurve->grp = agrp; } /* Remove the given channel from all groups */ @@ -354,28 +354,28 @@ void action_groups_remove_channel(bAction *act, FCurve *fcu) /* check if any group used this directly */ if (fcu->grp) { - bActionGroup *agrp= fcu->grp; + bActionGroup *agrp = fcu->grp; if (agrp->channels.first == agrp->channels.last) { if (agrp->channels.first == fcu) { - agrp->channels.first= NULL; - agrp->channels.last= NULL; + agrp->channels.first = NULL; + agrp->channels.last = NULL; } } else if (agrp->channels.first == fcu) { - if ((fcu->next) && (fcu->next->grp==agrp)) - agrp->channels.first= fcu->next; + if ((fcu->next) && (fcu->next->grp == agrp)) + agrp->channels.first = fcu->next; else - agrp->channels.first= NULL; + agrp->channels.first = NULL; } else if (agrp->channels.last == fcu) { - if ((fcu->prev) && (fcu->prev->grp==agrp)) - agrp->channels.last= fcu->prev; + if ((fcu->prev) && (fcu->prev->grp == agrp)) + agrp->channels.last = fcu->prev; else - agrp->channels.last= NULL; + agrp->channels.last = NULL; } - fcu->grp= NULL; + fcu->grp = NULL; } /* now just remove from list */ @@ -383,7 +383,7 @@ void action_groups_remove_channel(bAction *act, FCurve *fcu) } /* Find a group with the given name */ -bActionGroup *BKE_action_group_find_name (bAction *act, const char name[]) +bActionGroup *BKE_action_group_find_name(bAction *act, const char name[]) { /* sanity checks */ if (ELEM3(NULL, act, act->groups.first, name) || (name[0] == 0)) @@ -431,7 +431,7 @@ bPoseChannel *BKE_pose_channel_verify(bPose *pose, const char *name) return NULL; /* See if this channel exists */ - chan= BLI_findstring(&pose->chanbase, name, offsetof(bPoseChannel, name)); + chan = BLI_findstring(&pose->chanbase, name, offsetof(bPoseChannel, name)); if (chan) { return chan; } @@ -445,13 +445,13 @@ bPoseChannel *BKE_pose_channel_verify(bPose *pose, const char *name) unit_axis_angle(chan->rotAxis, &chan->rotAngle); chan->size[0] = chan->size[1] = chan->size[2] = 1.0f; - chan->limitmin[0]= chan->limitmin[1]= chan->limitmin[2]= -180.0f; - chan->limitmax[0]= chan->limitmax[1]= chan->limitmax[2]= 180.0f; - chan->stiffness[0]= chan->stiffness[1]= chan->stiffness[2]= 0.0f; + chan->limitmin[0] = chan->limitmin[1] = chan->limitmin[2] = -180.0f; + chan->limitmax[0] = chan->limitmax[1] = chan->limitmax[2] = 180.0f; + chan->stiffness[0] = chan->stiffness[1] = chan->stiffness[2] = 0.0f; chan->ikrotweight = chan->iklinweight = 0.0f; unit_m4(chan->constinv); - chan->protectflag = OB_LOCK_ROT4D; /* lock by components by default */ + chan->protectflag = OB_LOCK_ROT4D; /* lock by components by default */ BLI_addtail(&pose->chanbase, chan); BKE_pose_channels_hash_free(pose); @@ -460,9 +460,9 @@ bPoseChannel *BKE_pose_channel_verify(bPose *pose, const char *name) } /* Find the active posechannel for an object (we can't just use pose, as layer info is in armature) */ -bPoseChannel *BKE_pose_channel_active (Object *ob) +bPoseChannel *BKE_pose_channel_active(Object *ob) { - bArmature *arm= (ob) ? ob->data : NULL; + bArmature *arm = (ob) ? ob->data : NULL; bPoseChannel *pchan; if (ELEM3(NULL, ob, ob->pose, arm)) { @@ -470,7 +470,7 @@ bPoseChannel *BKE_pose_channel_active (Object *ob) } /* find active */ - for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { if ((pchan->bone) && (pchan->bone == arm->act_bone) && (pchan->bone->layer & arm->layer)) return pchan; } @@ -482,10 +482,10 @@ const char *BKE_pose_ikparam_get_name(bPose *pose) { if (pose) { switch (pose->iksolver) { - case IKSOLVER_LEGACY: - return NULL; - case IKSOLVER_ITASC: - return "bItasc"; + case IKSOLVER_LEGACY: + return NULL; + case IKSOLVER_ITASC: + return "bItasc"; } } return NULL; @@ -498,17 +498,17 @@ void BKE_pose_copy_data(bPose **dst, bPose *src, int copycon) ListBase listb; if (!src) { - *dst=NULL; + *dst = NULL; return; } - if (*dst==src) { + if (*dst == src) { printf("BKE_pose_copy_data source and target are the same\n"); - *dst=NULL; + *dst = NULL; return; } - outPose= MEM_callocN(sizeof(bPose), "pose"); + outPose = MEM_callocN(sizeof(bPose), "pose"); BLI_duplicatelist(&outPose->chanbase, &src->chanbase); @@ -516,16 +516,16 @@ void BKE_pose_copy_data(bPose **dst, bPose *src, int copycon) outPose->ikdata = NULL; outPose->ikparam = MEM_dupallocN(src->ikparam); - for (pchan=outPose->chanbase.first; pchan; pchan=pchan->next) { + for (pchan = outPose->chanbase.first; pchan; pchan = pchan->next) { // TODO: rename this argument... if (copycon) { copy_constraints(&listb, &pchan->constraints, TRUE); // copy_constraints NULLs listb - pchan->constraints= listb; - pchan->mpath= NULL; /* motion paths should not get copied yet... */ + pchan->constraints = listb; + pchan->mpath = NULL; /* motion paths should not get copied yet... */ } if (pchan->prop) { - pchan->prop= IDP_CopyProperty(pchan->prop); + pchan->prop = IDP_CopyProperty(pchan->prop); } } @@ -533,7 +533,7 @@ void BKE_pose_copy_data(bPose **dst, bPose *src, int copycon) if (copycon) BLI_duplicatelist(&outPose->agroups, &src->agroups); - *dst=outPose; + *dst = outPose; } void BKE_pose_itasc_init(bItasc *itasc) @@ -545,7 +545,7 @@ void BKE_pose_itasc_init(bItasc *itasc) itasc->numiter = 100; itasc->numstep = 4; itasc->precision = 0.005f; - itasc->flag = ITASC_AUTO_STEP|ITASC_INITIAL_REITERATION; + itasc->flag = ITASC_AUTO_STEP | ITASC_INITIAL_REITERATION; itasc->feedback = 20.0f; itasc->maxvel = 50.0f; itasc->solver = ITASC_SOLVER_SDLS; @@ -557,15 +557,15 @@ void BKE_pose_ikparam_init(bPose *pose) { bItasc *itasc; switch (pose->iksolver) { - case IKSOLVER_ITASC: - itasc = MEM_callocN(sizeof(bItasc), "itasc"); - BKE_pose_itasc_init(itasc); - pose->ikparam = itasc; - break; - case IKSOLVER_LEGACY: - default: - pose->ikparam = NULL; - break; + case IKSOLVER_ITASC: + itasc = MEM_callocN(sizeof(bItasc), "itasc"); + BKE_pose_itasc_init(itasc); + pose->ikparam = itasc; + break; + case IKSOLVER_LEGACY: + default: + pose->ikparam = NULL; + break; } } @@ -574,8 +574,8 @@ void BKE_pose_channels_hash_make(bPose *pose) if (!pose->chanhash) { bPoseChannel *pchan; - pose->chanhash= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "make_pose_chan gh"); - for (pchan=pose->chanbase.first; pchan; pchan=pchan->next) + pose->chanhash = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "make_pose_chan gh"); + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) BLI_ghash_insert(pose->chanhash, pchan->name, pchan); } } @@ -584,7 +584,7 @@ void BKE_pose_channels_hash_free(bPose *pose) { if (pose->chanhash) { BLI_ghash_free(pose->chanhash, NULL, NULL); - pose->chanhash= NULL; + pose->chanhash = NULL; } } @@ -594,7 +594,7 @@ void BKE_pose_channel_free(bPoseChannel *pchan) if (pchan->mpath) { animviz_free_motionpath(pchan->mpath); - pchan->mpath= NULL; + pchan->mpath = NULL; } free_constraints(&pchan->constraints); @@ -610,7 +610,7 @@ void BKE_pose_channels_free(bPose *pose) bPoseChannel *pchan; if (pose->chanbase.first) { - for (pchan = pose->chanbase.first; pchan; pchan=pchan->next) + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) BKE_pose_channel_free(pchan); BLI_freelistN(&pose->chanbase); @@ -649,17 +649,17 @@ static void copy_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *chan 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; + pchan->rotAngle = chan->rotAngle; copy_qt_qt(pchan->quat, chan->quat); - pchan->rotmode= chan->rotmode; + 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); - pchan->flag= chan->flag; + pchan->flag = chan->flag; - con= chan->constraints.first; - for (pcon= pchan->constraints.first; pcon && con; pcon= pcon->next, con= con->next) { - pcon->enforce= con->enforce; - pcon->headtail= con->headtail; + con = chan->constraints.first; + for (pcon = pchan->constraints.first; pcon && con; pcon = pcon->next, con = con->next) { + pcon->enforce = con->enforce; + pcon->headtail = con->headtail; } } @@ -675,16 +675,16 @@ void BKE_pose_channel_copy_data(bPoseChannel *pchan, const bPoseChannel *pchan_f pchan->rotmode = pchan_from->rotmode; /* copy bone group */ - pchan->agrp_index= pchan_from->agrp_index; + pchan->agrp_index = pchan_from->agrp_index; /* ik (dof) settings */ pchan->ikflag = pchan_from->ikflag; 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; + pchan->ikstretch = pchan_from->ikstretch; + pchan->ikrotweight = pchan_from->ikrotweight; + pchan->iklinweight = pchan_from->iklinweight; /* constraints */ copy_constraints(&pchan->constraints, &pchan_from->constraints, TRUE); @@ -694,14 +694,14 @@ void BKE_pose_channel_copy_data(bPoseChannel *pchan, const bPoseChannel *pchan_f /* unlikely but possible it exists */ IDP_FreeProperty(pchan->prop); MEM_freeN(pchan->prop); - pchan->prop= NULL; + pchan->prop = NULL; } if (pchan_from->prop) { - pchan->prop= IDP_CopyProperty(pchan_from->prop); + pchan->prop = IDP_CopyProperty(pchan_from->prop); } /* custom shape */ - pchan->custom= pchan_from->custom; + pchan->custom = pchan_from->custom; } @@ -715,39 +715,39 @@ void BKE_pose_update_constraint_flags(bPose *pose) bConstraint *con; /* clear */ - for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) { - pchan->constflag= 0; + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { + pchan->constflag = 0; } pose->flag &= ~POSE_CONSTRAINTS_TIMEDEPEND; /* detect */ - for (pchan= pose->chanbase.first; pchan; pchan=pchan->next) { - for (con= pchan->constraints.first; con; con= con->next) { - if (con->type==CONSTRAINT_TYPE_KINEMATIC) { - bKinematicConstraint *data = (bKinematicConstraint*)con->data; + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { + for (con = pchan->constraints.first; con; con = con->next) { + if (con->type == CONSTRAINT_TYPE_KINEMATIC) { + bKinematicConstraint *data = (bKinematicConstraint *)con->data; pchan->constflag |= PCHAN_HAS_IK; - if (data->tar==NULL || (data->tar->type==OB_ARMATURE && data->subtarget[0]==0)) + if (data->tar == NULL || (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0)) pchan->constflag |= PCHAN_HAS_TARGET; /* negative rootbone = recalc rootbone index. used in do_versions */ - if (data->rootbone<0) { - data->rootbone= 0; + if (data->rootbone < 0) { + data->rootbone = 0; - if (data->flag & CONSTRAINT_IK_TIP) parchan= pchan; - else parchan= pchan->parent; + if (data->flag & CONSTRAINT_IK_TIP) parchan = pchan; + else parchan = pchan->parent; while (parchan) { data->rootbone++; - if ((parchan->bone->flag & BONE_CONNECTED)==0) + if ((parchan->bone->flag & BONE_CONNECTED) == 0) break; - parchan= parchan->parent; + parchan = parchan->parent; } } } else if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) { - bFollowPathConstraint *data= (bFollowPathConstraint *)con->data; + bFollowPathConstraint *data = (bFollowPathConstraint *)con->data; /* for drawing constraint colors when color set allows this */ pchan->constflag |= PCHAN_HAS_CONST; @@ -755,7 +755,7 @@ void BKE_pose_update_constraint_flags(bPose *pose) /* if we have a valid target, make sure that this will get updated on frame-change * (needed for when there is no anim-data for this pose) */ - if ((data->tar) && (data->tar->type==OB_CURVE)) + if ((data->tar) && (data->tar->type == OB_CURVE)) pose->flag |= POSE_CONSTRAINTS_TIMEDEPEND; } else if (con->type == CONSTRAINT_TYPE_SPLINEIK) @@ -778,10 +778,10 @@ void framechange_poses_clear_unkeyed(void) /* This needs to be done for each object that has a pose */ // TODO: proxies may/may not be correctly handled here... (this needs checking) - for (ob= G.main->object.first; ob; ob= ob->id.next) { + for (ob = G.main->object.first; ob; ob = ob->id.next) { /* we only need to do this on objects with a pose */ - if ( (pose= ob->pose) ) { - for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) { + if ( (pose = ob->pose) ) { + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { if (pchan->bone) pchan->bone->flag &= ~BONE_UNKEYED; } @@ -794,24 +794,24 @@ void framechange_poses_clear_unkeyed(void) /* Adds a new bone-group */ void BKE_pose_add_group(Object *ob) { - bPose *pose= (ob) ? ob->pose : NULL; + bPose *pose = (ob) ? ob->pose : NULL; bActionGroup *grp; if (ELEM(NULL, ob, ob->pose)) return; - grp= MEM_callocN(sizeof(bActionGroup), "PoseGroup"); + grp = MEM_callocN(sizeof(bActionGroup), "PoseGroup"); BLI_strncpy(grp->name, "Group", sizeof(grp->name)); BLI_addtail(&pose->agroups, grp); BLI_uniquename(&pose->agroups, grp, "Group", '.', offsetof(bActionGroup, name), sizeof(grp->name)); - pose->active_group= BLI_countlist(&pose->agroups); + pose->active_group = BLI_countlist(&pose->agroups); } /* Remove the active bone-group */ void BKE_pose_remove_group(Object *ob) { - bPose *pose= (ob) ? ob->pose : NULL; + bPose *pose = (ob) ? ob->pose : NULL; bActionGroup *grp = NULL; bPoseChannel *pchan; @@ -822,15 +822,15 @@ void BKE_pose_remove_group(Object *ob) return; /* get group to remove */ - grp= BLI_findlink(&pose->agroups, pose->active_group-1); + grp = BLI_findlink(&pose->agroups, pose->active_group - 1); if (grp) { /* adjust group references (the trouble of using indices!): * - firstly, make sure nothing references it * - also, make sure that those after this item get corrected */ - for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) { + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { if (pchan->agrp_index == pose->active_group) - pchan->agrp_index= 0; + pchan->agrp_index = 0; else if (pchan->agrp_index > pose->active_group) pchan->agrp_index--; } @@ -839,7 +839,7 @@ void BKE_pose_remove_group(Object *ob) BLI_freelinkN(&pose->agroups, grp); pose->active_group--; if (pose->active_group < 0 || pose->agroups.first == NULL) { - pose->active_group= 0; + pose->active_group = 0; } } } @@ -853,7 +853,7 @@ short action_has_motion(const bAction *act) /* return on the first F-Curve that has some keyframes/samples defined */ if (act) { - for (fcu= act->curves.first; fcu; fcu= fcu->next) { + for (fcu = act->curves.first; fcu; fcu = fcu->next) { if (fcu->totvert) return 1; } @@ -867,11 +867,11 @@ short action_has_motion(const bAction *act) void calc_action_range(const bAction *act, float *start, float *end, short incl_modifiers) { FCurve *fcu; - float min=999999999.0f, max=-999999999.0f; - short foundvert=0, foundmod=0; + float min = 999999999.0f, max = -999999999.0f; + short foundvert = 0, foundmod = 0; if (act) { - for (fcu= act->curves.first; fcu; fcu= fcu->next) { + for (fcu = act->curves.first; fcu; fcu = fcu->next) { /* if curve has keyframes, consider them first */ if (fcu->totvert) { float nmin, nmax; @@ -881,65 +881,65 @@ void calc_action_range(const bAction *act, float *start, float *end, short incl_ calc_fcurve_range(fcu, &nmin, &nmax, FALSE, TRUE); /* compare to the running tally */ - min= MIN2(min, nmin); - max= MAX2(max, nmax); + min = MIN2(min, nmin); + max = MAX2(max, nmax); - foundvert= 1; + foundvert = 1; } /* if incl_modifiers is enabled, need to consider modifiers too * - only really care about the last modifier */ if ((incl_modifiers) && (fcu->modifiers.last)) { - FModifier *fcm= fcu->modifiers.last; + FModifier *fcm = fcu->modifiers.last; /* only use the maximum sensible limits of the modifiers if they are more extreme */ switch (fcm->type) { case FMODIFIER_TYPE_LIMITS: /* Limits F-Modifier */ { - FMod_Limits *fmd= (FMod_Limits *)fcm->data; + FMod_Limits *fmd = (FMod_Limits *)fcm->data; if (fmd->flag & FCM_LIMIT_XMIN) { - min= MIN2(min, fmd->rect.xmin); + min = MIN2(min, fmd->rect.xmin); } if (fmd->flag & FCM_LIMIT_XMAX) { - max= MAX2(max, fmd->rect.xmax); + max = MAX2(max, fmd->rect.xmax); } } - break; + break; case FMODIFIER_TYPE_CYCLES: /* Cycles F-Modifier */ { - FMod_Cycles *fmd= (FMod_Cycles *)fcm->data; + FMod_Cycles *fmd = (FMod_Cycles *)fcm->data; if (fmd->before_mode != FCM_EXTRAPOLATE_NONE) - min= MINAFRAMEF; + min = MINAFRAMEF; if (fmd->after_mode != FCM_EXTRAPOLATE_NONE) - max= MAXFRAMEF; + max = MAXFRAMEF; } - break; + break; // TODO: function modifier may need some special limits default: /* all other standard modifiers are on the infinite range... */ - min= MINAFRAMEF; - max= MAXFRAMEF; + min = MINAFRAMEF; + max = MAXFRAMEF; break; } - foundmod= 1; + foundmod = 1; } } } if (foundvert || foundmod) { - if (min==max) max+= 1.0f; - *start= min; - *end= max; + if (min == max) max += 1.0f; + *start = min; + *end = max; } else { - *start= 0.0f; - *end= 1.0f; + *start = 0.0f; + *end = 1.0f; } } @@ -950,8 +950,8 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, { PointerRNA ptr; FCurve *fcu; - char *basePath=NULL; - short flags=0; + char *basePath = NULL; + short flags = 0; /* build PointerRNA from provided data to obtain the paths to use */ if (pchan) @@ -962,15 +962,15 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, return 0; /* get the basic path to the properties of interest */ - basePath= RNA_path_from_ID_to_struct(&ptr); + basePath = RNA_path_from_ID_to_struct(&ptr); if (basePath == NULL) return 0; /* search F-Curves for the given properties * - we cannot use the groups, since they may not be grouped in that way... */ - for (fcu= act->curves.first; fcu; fcu= fcu->next) { - char *bPtr=NULL, *pPtr=NULL; + for (fcu = act->curves.first; fcu; fcu = fcu->next) { + char *bPtr = NULL, *pPtr = NULL; /* if enough flags have been found, we can stop checking unless we're also getting the curves */ if ((flags == ACT_TRANS_ALL) && (curves == NULL)) @@ -981,7 +981,7 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, continue; /* step 1: check for matching base path */ - bPtr= strstr(fcu->rna_path, basePath); + bPtr = strstr(fcu->rna_path, basePath); if (bPtr) { /* we must add len(basePath) bytes to the match so that we are at the end of the @@ -991,13 +991,13 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, /* step 2: check for some property with transforms * - to speed things up, only check for the ones not yet found - * unless we're getting the curves too + * unless we're getting the curves too * - if we're getting the curves, the BLI_genericNodeN() creates a LinkData * node wrapping the F-Curve, which then gets added to the list * - once a match has been found, the curve cannot possibly be any other one */ if ((curves) || (flags & ACT_TRANS_LOC) == 0) { - pPtr= strstr(bPtr, "location"); + pPtr = strstr(bPtr, "location"); if (pPtr) { flags |= ACT_TRANS_LOC; @@ -1008,7 +1008,7 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, } if ((curves) || (flags & ACT_TRANS_SCALE) == 0) { - pPtr= strstr(bPtr, "scale"); + pPtr = strstr(bPtr, "scale"); if (pPtr) { flags |= ACT_TRANS_SCALE; @@ -1019,7 +1019,7 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, } if ((curves) || (flags & ACT_TRANS_ROT) == 0) { - pPtr= strstr(bPtr, "rotation"); + pPtr = strstr(bPtr, "rotation"); if (pPtr) { flags |= ACT_TRANS_ROT; @@ -1031,7 +1031,7 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, if ((curves) || (flags & ACT_TRANS_PROP) == 0) { /* custom properties only */ - pPtr= strstr(bPtr, "[\""); /* extra '"' comment here to keep my texteditor functionlist working :) */ + pPtr = strstr(bPtr, "[\""); /* extra '"' comment here to keep my texteditor functionlist working :) */ if (pPtr) { flags |= ACT_TRANS_PROP; @@ -1059,14 +1059,14 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, void extract_pose_from_pose(bPose *pose, const bPose *src) { const bPoseChannel *schan; - bPoseChannel *pchan= pose->chanbase.first; + bPoseChannel *pchan = pose->chanbase.first; - if (pose==src) { + if (pose == src) { printf("extract_pose_from_pose source and target are the same\n"); return; } - for (schan=src->chanbase.first; (schan && pchan); schan=schan->next, pchan= pchan->next) { + for (schan = src->chanbase.first; (schan && pchan); schan = schan->next, pchan = pchan->next) { copy_pose_channel_data(pchan, schan); } } @@ -1082,14 +1082,14 @@ void BKE_pose_rest(bPose *pose) memset(pose->stride_offset, 0, sizeof(pose->stride_offset)); memset(pose->cyclic_offset, 0, sizeof(pose->cyclic_offset)); - for (pchan=pose->chanbase.first; pchan; pchan= pchan->next) { + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { zero_v3(pchan->loc); zero_v3(pchan->eul); unit_qt(pchan->quat); unit_axis_angle(pchan->rotAxis, &pchan->rotAngle); - pchan->size[0]= pchan->size[1]= pchan->size[2]= 1.0f; + pchan->size[0] = pchan->size[1] = pchan->size[2] = 1.0f; - pchan->flag &= ~(POSE_LOC|POSE_ROT|POSE_SIZE); + pchan->flag &= ~(POSE_LOC | POSE_ROT | POSE_SIZE); } } @@ -1098,19 +1098,19 @@ void BKE_pose_copy_result(bPose *to, bPose *from) { bPoseChannel *pchanto, *pchanfrom; - if (to==NULL || from==NULL) { + if (to == NULL || from == NULL) { printf("pose result copy error to:%p from:%p\n", (void *)to, (void *)from); // debug temp return; } - if (to==from) { + if (to == from) { printf("BKE_pose_copy_result source and target are the same\n"); return; } - for (pchanfrom= from->chanbase.first; pchanfrom; pchanfrom= pchanfrom->next) { - pchanto= BKE_pose_channel_find_name(to, pchanfrom->name); + for (pchanfrom = from->chanbase.first; pchanfrom; pchanfrom = pchanfrom->next) { + pchanto = BKE_pose_channel_find_name(to, pchanfrom->name); if (pchanto) { copy_m4_m4(pchanto->pose_mat, pchanfrom->pose_mat); copy_m4_m4(pchanto->chan_mat, pchanfrom->chan_mat); @@ -1124,9 +1124,9 @@ void BKE_pose_copy_result(bPose *to, bPose *from) 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; - pchanto->protectflag= pchanfrom->protectflag; + pchanto->rotmode = pchanfrom->rotmode; + pchanto->flag = pchanfrom->flag; + pchanto->protectflag = pchanfrom->protectflag; } } } @@ -1136,7 +1136,7 @@ void BKE_pose_copy_result(bPose *to, bPose *from) */ void what_does_obaction(Object *ob, Object *workob, bPose *pose, bAction *act, char groupname[], float cframe) { - bActionGroup *agrp= BKE_action_group_find_name(act, groupname); + bActionGroup *agrp = BKE_action_group_find_name(act, groupname); /* clear workob */ BKE_object_workob_clear(workob); @@ -1145,22 +1145,22 @@ void what_does_obaction(Object *ob, Object *workob, bPose *pose, bAction *act, c copy_m4_m4(workob->obmat, ob->obmat); copy_m4_m4(workob->parentinv, ob->parentinv); copy_m4_m4(workob->constinv, ob->constinv); - workob->parent= ob->parent; + workob->parent = ob->parent; - workob->rotmode= ob->rotmode; + workob->rotmode = ob->rotmode; - workob->trackflag= ob->trackflag; - workob->upflag= ob->upflag; + workob->trackflag = ob->trackflag; + workob->upflag = ob->upflag; - workob->partype= ob->partype; - workob->par1= ob->par1; - workob->par2= ob->par2; - workob->par3= ob->par3; + workob->partype = ob->partype; + workob->par1 = ob->par1; + workob->par2 = ob->par2; + workob->par3 = ob->par3; workob->constraints.first = ob->constraints.first; workob->constraints.last = ob->constraints.last; - workob->pose= pose; /* need to set pose too, since this is used for both types of Action Constraint */ + workob->pose = pose; /* need to set pose too, since this is used for both types of Action Constraint */ BLI_strncpy(workob->parsubstr, ob->parsubstr, sizeof(workob->parsubstr)); BLI_strncpy(workob->id.name, "OB<ConstrWorkOb>", sizeof(workob->id.name)); /* we don't use real object name, otherwise RNA screws with the real thing */ @@ -1177,13 +1177,13 @@ void what_does_obaction(Object *ob, Object *workob, bPose *pose, bAction *act, c animsys_evaluate_action_group(&id_ptr, act, agrp, NULL, cframe); } else { - AnimData adt= {NULL}; + AnimData adt = {NULL}; /* init animdata, and attach to workob */ - workob->adt= &adt; + workob->adt = &adt; - adt.recalc= ADT_RECALC_ANIM; - adt.action= act; + adt.recalc = ADT_RECALC_ANIM; + adt.action = act; /* execute effects of Action on to workob (or it's PoseChannels) */ BKE_animsys_evaluate_animdata(NULL, &workob->id, &adt, cframe, ADT_RECALC_ANIM); @@ -1207,7 +1207,7 @@ static void blend_pose_strides(bPose *dst, bPose *src, float srcweight, short mo case ACTSTRIPMODE_ADD: dstweight = 1.0F; break; - default : + default: dstweight = 1.0F; } @@ -1238,30 +1238,30 @@ static void blend_pose_offset_bone(bActionStrip *strip, bPose *dst, bPose *src, /* matching offset bones */ /* take dst offset, and put src on on that location */ - if (strip->offs_bone[0]==0) + if (strip->offs_bone[0] == 0) return; /* are we also blending with matching bones? */ - if (strip->prev && strip->start>=strip->prev->start) { - bPoseChannel *dpchan= BKE_pose_channel_find_name(dst, strip->offs_bone); + if (strip->prev && strip->start >= strip->prev->start) { + bPoseChannel *dpchan = BKE_pose_channel_find_name(dst, strip->offs_bone); if (dpchan) { - bPoseChannel *spchan= BKE_pose_channel_find_name(src, strip->offs_bone); + bPoseChannel *spchan = BKE_pose_channel_find_name(src, strip->offs_bone); if (spchan) { float vec[3]; /* dst->ctime has the internal strip->prev action time */ /* map this time to nla time */ - float ctime= get_actionstrip_frame(strip, src->ctime, 1); + float ctime = get_actionstrip_frame(strip, src->ctime, 1); - if ( ctime > strip->prev->end) { + if (ctime > strip->prev->end) { bActionChannel *achan; /* add src to dest, minus the position of src on strip->prev->end */ - ctime= get_actionstrip_frame(strip, strip->prev->end, 0); + ctime = get_actionstrip_frame(strip, strip->prev->end, 0); - achan= get_action_channel(strip->act, strip->offs_bone); + achan = get_action_channel(strip->act, strip->offs_bone); if (achan && achan->ipo) { bPoseChannel pchan; /* Evaluates and sets the internal ipo value */ @@ -1298,63 +1298,63 @@ static void blend_pose_offset_bone(bActionStrip *strip, bPose *dst, bPose *src, */ static float stridechannel_frame(Object *ob, float sizecorr, bActionStrip *strip, Path *path, float pathdist, float *stride_offset) { - bAction *act= strip->act; - const char *name= strip->stridechannel; - bActionChannel *achan= get_action_channel(act, name); - int stride_axis= strip->stride_axis; + bAction *act = strip->act; + const char *name = strip->stridechannel; + bActionChannel *achan = get_action_channel(act, name); + int stride_axis = strip->stride_axis; if (achan && achan->ipo) { - IpoCurve *icu= NULL; - float minx=0.0f, maxx=0.0f, miny=0.0f, maxy=0.0f; - int foundvert= 0; - - if (stride_axis==0) stride_axis= AC_LOC_X; - else if (stride_axis==1) stride_axis= AC_LOC_Y; - else stride_axis= AC_LOC_Z; + IpoCurve *icu = NULL; + float minx = 0.0f, maxx = 0.0f, miny = 0.0f, maxy = 0.0f; + int foundvert = 0; + + if (stride_axis == 0) stride_axis = AC_LOC_X; + else if (stride_axis == 1) stride_axis = AC_LOC_Y; + else stride_axis = AC_LOC_Z; /* calculate the min/max */ - for (icu=achan->ipo->curve.first; icu; icu=icu->next) { - if (icu->adrcode==stride_axis) { - if (icu->totvert>1) { - foundvert= 1; - minx= icu->bezt[0].vec[1][0]; - maxx= icu->bezt[icu->totvert-1].vec[1][0]; + for (icu = achan->ipo->curve.first; icu; icu = icu->next) { + if (icu->adrcode == stride_axis) { + if (icu->totvert > 1) { + foundvert = 1; + minx = icu->bezt[0].vec[1][0]; + maxx = icu->bezt[icu->totvert - 1].vec[1][0]; - miny= icu->bezt[0].vec[1][1]; - maxy= icu->bezt[icu->totvert-1].vec[1][1]; + miny = icu->bezt[0].vec[1][1]; + maxy = icu->bezt[icu->totvert - 1].vec[1][1]; } break; } } - if (foundvert && miny!=maxy) { - float stridelen= sizecorr*fabs(maxy-miny), striptime; + if (foundvert && miny != maxy) { + float stridelen = sizecorr * fabs(maxy - miny), striptime; float actiondist, pdist, pdistNewNormalized, offs; float vec1[4], vec2[4], dir[3]; /* internal cycling, actoffs is in frames */ - offs= stridelen*strip->actoffs/(maxx-minx); + offs = stridelen * strip->actoffs / (maxx - minx); /* amount path moves object */ - pdist = (float)fmod (pathdist+offs, stridelen); - striptime= pdist/stridelen; + pdist = (float)fmod(pathdist + offs, stridelen); + striptime = pdist / stridelen; /* amount stride bone moves */ - actiondist= sizecorr*eval_icu(icu, minx + striptime*(maxx-minx)) - miny; + actiondist = sizecorr * eval_icu(icu, minx + striptime * (maxx - minx)) - miny; pdist = fabs(actiondist) - pdist; - pdistNewNormalized = (pathdist+pdist)/path->totdist; + pdistNewNormalized = (pathdist + pdist) / path->totdist; /* now we need to go pdist further (or less) on cu path */ - where_on_path(ob, (pathdist)/path->totdist, vec1, dir); /* vec needs size 4 */ + where_on_path(ob, (pathdist) / path->totdist, vec1, dir); /* vec needs size 4 */ if (pdistNewNormalized <= 1) { // search for correction in positive path-direction - where_on_path(ob, pdistNewNormalized, vec2, dir); /* vec needs size 4 */ + where_on_path(ob, pdistNewNormalized, vec2, dir); /* vec needs size 4 */ sub_v3_v3v3(stride_offset, vec2, vec1); } else { // we reached the end of the path, search backwards instead - where_on_path(ob, (pathdist-pdist)/path->totdist, vec2, dir); /* vec needs size 4 */ + where_on_path(ob, (pathdist - pdist) / path->totdist, vec2, dir); /* vec needs size 4 */ sub_v3_v3v3(stride_offset, vec1, vec2); } mul_mat3_m4_v3(ob->obmat, stride_offset); @@ -1368,52 +1368,52 @@ static void cyclic_offs_bone(Object *ob, bPose *pose, bActionStrip *strip, float { /* only called when strip has cyclic, so >= 1.0f works... */ if (time >= 1.0f) { - bActionChannel *achan= get_action_channel(strip->act, strip->offs_bone); + bActionChannel *achan = get_action_channel(strip->act, strip->offs_bone); if (achan && achan->ipo) { - IpoCurve *icu= NULL; + IpoCurve *icu = NULL; Bone *bone; - float min[3]={0.0f, 0.0f, 0.0f}, max[3]={0.0f, 0.0f, 0.0f}; - int index=0, foundvert= 0; + float min[3] = {0.0f, 0.0f, 0.0f}, max[3] = {0.0f, 0.0f, 0.0f}; + int index = 0, foundvert = 0; /* calculate the min/max */ - for (icu=achan->ipo->curve.first; icu; icu=icu->next) { - if (icu->totvert>1) { + for (icu = achan->ipo->curve.first; icu; icu = icu->next) { + if (icu->totvert > 1) { - if (icu->adrcode==AC_LOC_X) - index= 0; - else if (icu->adrcode==AC_LOC_Y) - index= 1; - else if (icu->adrcode==AC_LOC_Z) - index= 2; + if (icu->adrcode == AC_LOC_X) + index = 0; + else if (icu->adrcode == AC_LOC_Y) + index = 1; + else if (icu->adrcode == AC_LOC_Z) + index = 2; else continue; - foundvert= 1; - min[index]= icu->bezt[0].vec[1][1]; - max[index]= icu->bezt[icu->totvert-1].vec[1][1]; + foundvert = 1; + min[index] = icu->bezt[0].vec[1][1]; + max[index] = icu->bezt[icu->totvert - 1].vec[1][1]; } } if (foundvert) { /* bring it into armature space */ sub_v3_v3v3(min, max, min); - bone= BKE_armature_find_bone_name(ob->data, strip->offs_bone); /* weak */ + bone = BKE_armature_find_bone_name(ob->data, strip->offs_bone); /* weak */ if (bone) { mul_mat3_m4_v3(bone->arm_mat, min); /* dominant motion, cyclic_offset was cleared in BKE_pose_rest */ if (strip->flag & (ACTSTRIP_CYCLIC_USEX | ACTSTRIP_CYCLIC_USEY | ACTSTRIP_CYCLIC_USEZ)) { - if (strip->flag & ACTSTRIP_CYCLIC_USEX) pose->cyclic_offset[0]= time*min[0]; - if (strip->flag & ACTSTRIP_CYCLIC_USEY) pose->cyclic_offset[1]= time*min[1]; - if (strip->flag & ACTSTRIP_CYCLIC_USEZ) pose->cyclic_offset[2]= time*min[2]; + if (strip->flag & ACTSTRIP_CYCLIC_USEX) pose->cyclic_offset[0] = time * min[0]; + if (strip->flag & ACTSTRIP_CYCLIC_USEY) pose->cyclic_offset[1] = time * min[1]; + if (strip->flag & ACTSTRIP_CYCLIC_USEZ) pose->cyclic_offset[2] = time * min[2]; } else { - if ( fabs(min[0]) >= fabs(min[1]) && fabs(min[0]) >= fabs(min[2])) - pose->cyclic_offset[0]= time*min[0]; - else if ( fabs(min[1]) >= fabs(min[0]) && fabs(min[1]) >= fabs(min[2])) - pose->cyclic_offset[1]= time*min[1]; + if (fabs(min[0]) >= fabs(min[1]) && fabs(min[0]) >= fabs(min[2])) + pose->cyclic_offset[0] = time * min[0]; + else if (fabs(min[1]) >= fabs(min[0]) && fabs(min[1]) >= fabs(min[2])) + pose->cyclic_offset[1] = time * min[1]; else - pose->cyclic_offset[2]= time*min[2]; + pose->cyclic_offset[2] = time * min[2]; } } } @@ -1427,13 +1427,13 @@ static Object *get_parent_path(Object *ob) { bConstraint *con; - if (ob->parent && ob->parent->type==OB_CURVE) + if (ob->parent && ob->parent->type == OB_CURVE) return ob->parent; - for (con = ob->constraints.first; con; con=con->next) { - if (con->type==CONSTRAINT_TYPE_FOLLOWPATH) { - if (con->enforce>0.5f) { - bFollowPathConstraint *data= con->data; + for (con = ob->constraints.first; con; con = con->next) { + if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) { + if (con->enforce > 0.5f) { + bFollowPathConstraint *data = con->data; return data->tar; } } @@ -1447,71 +1447,71 @@ static Object *get_parent_path(Object *ob) static void do_nla(Scene *scene, Object *ob, int blocktype) { - bPose *tpose= NULL; - Key *key= NULL; - ListBase tchanbase={NULL, NULL}, chanbase={NULL, NULL}; - bActionStrip *strip, *striplast=NULL, *stripfirst=NULL; + bPose *tpose = NULL; + Key *key = NULL; + ListBase tchanbase = {NULL, NULL}, chanbase = {NULL, NULL}; + bActionStrip *strip, *striplast = NULL, *stripfirst = NULL; float striptime, frametime, length, actlength; float blendfac, stripframe; - float scene_cfra= BKE_scene_frame_get(scene); - int doit, dostride; + float scene_cfra = BKE_scene_frame_get(scene); + int doit, dostride; - if (blocktype==ID_AR) { + if (blocktype == ID_AR) { BKE_pose_copy_data(&tpose, ob->pose, 1); - BKE_pose_rest(ob->pose); // potentially destroying current not-keyed pose + BKE_pose_rest(ob->pose); // potentially destroying current not-keyed pose } else { - key= ob_get_key(ob); + key = ob_get_key(ob); } /* check on extend to left or right, when no strip is hit by 'cfra' */ - for (strip=ob->nlastrips.first; strip; strip=strip->next) { + for (strip = ob->nlastrips.first; strip; strip = strip->next) { /* escape loop on a hit */ - if ( scene_cfra >= strip->start && scene_cfra <= strip->end + 0.1f) /* note 0.1 comes back below */ + if (scene_cfra >= strip->start && scene_cfra <= strip->end + 0.1f) /* note 0.1 comes back below */ break; if (scene_cfra < strip->start) { - if (stripfirst==NULL) - stripfirst= strip; + if (stripfirst == NULL) + stripfirst = strip; else if (stripfirst->start > strip->start) - stripfirst= strip; + stripfirst = strip; } else if (scene_cfra > strip->end) { - if (striplast==NULL) - striplast= strip; + if (striplast == NULL) + striplast = strip; else if (striplast->end < strip->end) - striplast= strip; + striplast = strip; } } - if (strip==NULL) { /* extend */ + if (strip == NULL) { /* extend */ if (striplast) - scene_cfra= striplast->end; + scene_cfra = striplast->end; else if (stripfirst) - scene_cfra= stripfirst->start; + scene_cfra = stripfirst->start; } /* and now go over all strips */ - for (strip=ob->nlastrips.first; strip; strip=strip->next) { - doit=dostride= 0; + for (strip = ob->nlastrips.first; strip; strip = strip->next) { + doit = dostride = 0; - if (strip->act && !(strip->flag & ACTSTRIP_MUTE)) { /* so theres an action */ + if (strip->act && !(strip->flag & ACTSTRIP_MUTE)) { /* so theres an action */ /* Determine if the current frame is within the strip's range */ - length = strip->end-strip->start; - actlength = strip->actend-strip->actstart; + length = strip->end - strip->start; + actlength = strip->actend - strip->actstart; striptime = (scene_cfra - strip->start) / length; stripframe = (scene_cfra - strip->start); - if (striptime>=0.0) { + if (striptime >= 0.0) { - if (blocktype==ID_AR) + if (blocktype == ID_AR) BKE_pose_rest(tpose); /* To handle repeat, we add 0.1 frame extra to make sure the last frame is included */ - if (striptime < 1.0f + 0.1f/length) { + if (striptime < 1.0f + 0.1f / length) { /* Handle path */ - if ((strip->flag & ACTSTRIP_USESTRIDE) && (blocktype==ID_AR) && (ob->ipoflag & OB_DISABLE_PATH)==0) { - Object *parent= get_parent_path(ob); + if ((strip->flag & ACTSTRIP_USESTRIDE) && (blocktype == ID_AR) && (ob->ipoflag & OB_DISABLE_PATH) == 0) { + Object *parent = get_parent_path(ob); if (parent) { Curve *cu = parent->data; @@ -1519,43 +1519,43 @@ static void do_nla(Scene *scene, Object *ob, int blocktype) if (cu->flag & CU_PATH) { /* Ensure we have a valid path */ - if (cu->path==NULL || cu->path->data==NULL) makeDispListCurveTypes(scene, parent, 0); + if (cu->path == NULL || cu->path->data == NULL) makeDispListCurveTypes(scene, parent, 0); if (cu->path) { /* Find the position on the path */ - ctime= bsystem_time(scene, ob, scene_cfra, 0.0); + ctime = bsystem_time(scene, ob, scene_cfra, 0.0); - if (calc_ipo_spec(cu->ipo, CU_SPEED, &ctime)==0) { + if (calc_ipo_spec(cu->ipo, CU_SPEED, &ctime) == 0) { /* correct for actions not starting on zero */ - ctime= (ctime - strip->actstart)/cu->pathlen; + ctime = (ctime - strip->actstart) / cu->pathlen; CLAMP(ctime, 0.0, 1.0); } - pdist = ctime*cu->path->totdist; + pdist = ctime * cu->path->totdist; if (tpose && strip->stridechannel[0]) { - striptime= stridechannel_frame(parent, ob->size[0], strip, cu->path, pdist, tpose->stride_offset); + striptime = stridechannel_frame(parent, ob->size[0], strip, cu->path, pdist, tpose->stride_offset); } else { if (strip->stridelen) { striptime = pdist / strip->stridelen; - striptime = (float)fmod (striptime+strip->actoffs, 1.0); + striptime = (float)fmod(striptime + strip->actoffs, 1.0); } else striptime = 0; } frametime = (striptime * actlength) + strip->actstart; - frametime= bsystem_time(scene, ob, frametime, 0.0); + frametime = bsystem_time(scene, ob, frametime, 0.0); - if (blocktype==ID_AR) { - extract_pose_from_action (tpose, strip->act, frametime); + if (blocktype == ID_AR) { + extract_pose_from_action(tpose, strip->act, frametime); } - else if (blocktype==ID_OB) { + else if (blocktype == ID_OB) { extract_ipochannels_from_action(&tchanbase, &ob->id, strip->act, "Object", frametime); if (key) extract_ipochannels_from_action(&tchanbase, &key->id, strip->act, "Shape", frametime); } - doit=dostride= 1; + doit = dostride = 1; } } } @@ -1564,29 +1564,29 @@ static void do_nla(Scene *scene, Object *ob, int blocktype) else { /* Mod to repeat */ - if (strip->repeat!=1.0f) { - float cycle= striptime*strip->repeat; + if (strip->repeat != 1.0f) { + float cycle = striptime * strip->repeat; - striptime = (float)fmod (cycle, 1.0f + 0.1f/length); - cycle-= striptime; + striptime = (float)fmod(cycle, 1.0f + 0.1f / length); + cycle -= striptime; - if (blocktype==ID_AR) + if (blocktype == ID_AR) cyclic_offs_bone(ob, tpose, strip, cycle); } frametime = (striptime * actlength) + strip->actstart; - frametime= nla_time(scene, frametime, (float)strip->repeat); + frametime = nla_time(scene, frametime, (float)strip->repeat); - if (blocktype==ID_AR) { - extract_pose_from_action (tpose, strip->act, frametime); + if (blocktype == ID_AR) { + extract_pose_from_action(tpose, strip->act, frametime); } - else if (blocktype==ID_OB) { + else if (blocktype == ID_OB) { extract_ipochannels_from_action(&tchanbase, &ob->id, strip->act, "Object", frametime); if (key) extract_ipochannels_from_action(&tchanbase, &key->id, strip->act, "Shape", frametime); } - doit=1; + doit = 1; } } /* Handle extend */ @@ -1594,25 +1594,25 @@ static void do_nla(Scene *scene, Object *ob, int blocktype) if (strip->flag & ACTSTRIP_HOLDLASTFRAME) { /* we want the strip to hold on the exact fraction of the repeat value */ - frametime = actlength * (strip->repeat-(int)strip->repeat); - if (frametime<=0.000001f) frametime= actlength; /* rounding errors... */ - frametime= bsystem_time(scene, ob, frametime+strip->actstart, 0.0); - - if (blocktype==ID_AR) - extract_pose_from_action (tpose, strip->act, frametime); - else if (blocktype==ID_OB) { + frametime = actlength * (strip->repeat - (int)strip->repeat); + if (frametime <= 0.000001f) frametime = actlength; /* rounding errors... */ + frametime = bsystem_time(scene, ob, frametime + strip->actstart, 0.0); + + if (blocktype == ID_AR) + extract_pose_from_action(tpose, strip->act, frametime); + else if (blocktype == ID_OB) { extract_ipochannels_from_action(&tchanbase, &ob->id, strip->act, "Object", frametime); if (key) extract_ipochannels_from_action(&tchanbase, &key->id, strip->act, "Shape", frametime); } /* handle cycle hold */ - if (strip->repeat!=1.0f) { - if (blocktype==ID_AR) - cyclic_offs_bone(ob, tpose, strip, strip->repeat-1.0f); + if (strip->repeat != 1.0f) { + if (blocktype == ID_AR) + cyclic_offs_bone(ob, tpose, strip, strip->repeat - 1.0f); } - doit=1; + doit = 1; } } @@ -1620,22 +1620,22 @@ static void do_nla(Scene *scene, Object *ob, int blocktype) if (doit) { /* Handle blendin */ - if (strip->blendin>0.0 && stripframe<=strip->blendin && scene_cfra>=strip->start) { - blendfac = stripframe/strip->blendin; + if (strip->blendin > 0.0 && stripframe <= strip->blendin && scene_cfra >= strip->start) { + blendfac = stripframe / strip->blendin; } - else if (strip->blendout>0.0 && stripframe>=(length-strip->blendout) && scene_cfra<=strip->end) { - blendfac = (length-stripframe)/(strip->blendout); + else if (strip->blendout > 0.0 && stripframe >= (length - strip->blendout) && scene_cfra <= strip->end) { + blendfac = (length - stripframe) / (strip->blendout); } else blendfac = 1; - if (blocktype==ID_AR) {/* Blend this pose with the accumulated pose */ + if (blocktype == ID_AR) { /* Blend this pose with the accumulated pose */ /* offset bone, for matching cycles */ - blend_pose_offset_bone (strip, ob->pose, tpose, blendfac, strip->mode); + blend_pose_offset_bone(strip, ob->pose, tpose, blendfac, strip->mode); - blend_poses (ob->pose, tpose, blendfac, strip->mode); + blend_poses(ob->pose, tpose, blendfac, strip->mode); if (dostride) - blend_pose_strides (ob->pose, tpose, blendfac, strip->mode); + blend_pose_strides(ob->pose, tpose, blendfac, strip->mode); } else { blend_ipochannels(&chanbase, &tchanbase, blendfac, strip->mode); @@ -1646,10 +1646,10 @@ static void do_nla(Scene *scene, Object *ob, int blocktype) } } - if (blocktype==ID_OB) { + if (blocktype == ID_OB) { execute_ipochannels(&chanbase); } - else if (blocktype==ID_AR) { + else if (blocktype == ID_AR) { /* apply stride offset to object */ add_v3_v3(ob->obmat[3], ob->pose->stride_offset); } diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 814e9d53503..59ac1604e29 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -79,8 +79,8 @@ bArmature *BKE_armature_add(const char *name) { bArmature *arm; - arm = BKE_libblock_alloc (&G.main->armature, ID_AR, name); - arm->deformflag = ARM_DEF_VGROUP|ARM_DEF_ENVELOPE; + arm = BKE_libblock_alloc(&G.main->armature, ID_AR, name); + arm->deformflag = ARM_DEF_VGROUP | ARM_DEF_ENVELOPE; arm->flag = ARM_COL_CUSTOM; /* custom bone-group colors */ arm->layer = 1; return arm; @@ -179,7 +179,7 @@ void BKE_armature_make_local(bArmature *arm) } } -static void copy_bonechildren(Bone* newBone, Bone* oldBone, Bone* actBone, Bone **newActBone) +static void copy_bonechildren(Bone *newBone, Bone *oldBone, Bone *actBone, Bone **newActBone) { Bone *curBone, *newChildBone; @@ -205,7 +205,7 @@ bArmature *BKE_armature_copy(bArmature *arm) { bArmature *newArm; Bone *oldBone, *newBone; - Bone *newActBone= NULL; + Bone *newActBone = NULL; newArm = BKE_libblock_copy(&arm->id); BLI_duplicatelist(&newArm->bonebase, &arm->bonebase); @@ -340,27 +340,27 @@ int bone_autoside_name(char name[MAXBONENAME], int UNUSED(strip_number), short a while (change) { /* remove extensions */ change = 0; - if (len > 2 && basename[len-2] == '.') { - if (basename[len-1] == 'L' || basename[len-1] == 'R') { /* L R */ - basename[len-2] = '\0'; + if (len > 2 && basename[len - 2] == '.') { + if (basename[len - 1] == 'L' || basename[len - 1] == 'R') { /* L R */ + basename[len - 2] = '\0'; len -= 2; change = 1; } } - else if (len > 3 && basename[len-3] == '.') { - if ((basename[len-2] == 'F' && basename[len-1] == 'r') || /* Fr */ - (basename[len-2] == 'B' && basename[len-1] == 'k')) /* Bk */ + else if (len > 3 && basename[len - 3] == '.') { + if ((basename[len - 2] == 'F' && basename[len - 1] == 'r') || /* Fr */ + (basename[len - 2] == 'B' && basename[len - 1] == 'k')) /* Bk */ { - basename[len-3] = '\0'; + basename[len - 3] = '\0'; len -= 3; change = 1; } } - else if (len > 4 && basename[len-4] == '.') { - if ((basename[len-3] == 'T' && basename[len-2] == 'o' && basename[len-1] == 'p') || /* Top */ - (basename[len-3] == 'B' && basename[len-2] == 'o' && basename[len-1] == 't')) /* Bot */ + else if (len > 4 && basename[len - 4] == '.') { + if ((basename[len - 3] == 'T' && basename[len - 2] == 'o' && basename[len - 1] == 'p') || /* Top */ + (basename[len - 3] == 'B' && basename[len - 2] == 'o' && basename[len - 1] == 't')) /* Bot */ { - basename[len-4] = '\0'; + basename[len - 4] = '\0'; len -= 4; change = 1; } @@ -368,7 +368,7 @@ int bone_autoside_name(char name[MAXBONENAME], int UNUSED(strip_number), short a } if ((MAXBONENAME - len) < strlen(extension) + 1) { /* add 1 for the '.' */ - strncpy(name, basename, len-strlen(extension)); + strncpy(name, basename, len - strlen(extension)); } BLI_snprintf(name, MAXBONENAME, "%s.%s", basename, extension); @@ -382,44 +382,44 @@ int bone_autoside_name(char name[MAXBONENAME], int UNUSED(strip_number), short a /* ************* B-Bone support ******************* */ -#define MAX_BBONE_SUBDIV 32 +#define MAX_BBONE_SUBDIV 32 /* data has MAX_BBONE_SUBDIV+1 interpolated points, will become desired amount with equal distances */ static void equalize_bezier(float *data, int desired) { float *fp, totdist, ddist, dist, fac1, fac2; - float pdist[MAX_BBONE_SUBDIV+1]; - float temp[MAX_BBONE_SUBDIV+1][4]; + float pdist[MAX_BBONE_SUBDIV + 1]; + float temp[MAX_BBONE_SUBDIV + 1][4]; int a, nr; pdist[0] = 0.0f; for (a = 0, fp = data; a < MAX_BBONE_SUBDIV; a++, fp += 4) { copy_qt_qt(temp[a], fp); - pdist[a+1] = pdist[a] + len_v3v3(fp, fp+4); + pdist[a + 1] = pdist[a] + len_v3v3(fp, fp + 4); } /* do last point */ copy_qt_qt(temp[a], fp); totdist = pdist[a]; /* go over distances and calculate new points */ - ddist = totdist/((float)desired); + ddist = totdist / ((float)desired); nr = 1; - for (a = 1, fp = data+4; a < desired; a++, fp += 4) { - dist = ((float)a)*ddist; + for (a = 1, fp = data + 4; a < desired; a++, fp += 4) { + dist = ((float)a) * ddist; /* we're looking for location (distance) 'dist' in the array */ while ((dist >= pdist[nr]) && nr < MAX_BBONE_SUBDIV) nr++; - fac1 = pdist[nr] - pdist[nr-1]; + fac1 = pdist[nr] - pdist[nr - 1]; fac2 = pdist[nr] - dist; fac1 = fac2 / fac1; fac2 = 1.0f - fac1; - fp[0] = fac1*temp[nr-1][0] + fac2*temp[nr][0]; - fp[1] = fac1*temp[nr-1][1] + fac2*temp[nr][1]; - fp[2] = fac1*temp[nr-1][2] + fac2*temp[nr][2]; - fp[3] = fac1*temp[nr-1][3] + fac2*temp[nr][3]; + fp[0] = fac1 * temp[nr - 1][0] + fac2 * temp[nr][0]; + fp[1] = fac1 * temp[nr - 1][1] + fac2 * temp[nr][1]; + fp[2] = fac1 * temp[nr - 1][2] + fac2 * temp[nr][2]; + fp[3] = fac1 * temp[nr - 1][3] + fac2 * temp[nr][3]; } /* set last point, needed for orientation calculus */ copy_qt_qt(fp, temp[MAX_BBONE_SUBDIV]); @@ -436,7 +436,7 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) Bone *bone = pchan->bone; float h1[3], h2[3], scale[3], length, hlength1, hlength2, roll1 = 0.0f, roll2; float mat3[3][3], imat[4][4], posemat[4][4], scalemat[4][4], iscalemat[4][4]; - float data[MAX_BBONE_SUBDIV+1][4], *fp; + float data[MAX_BBONE_SUBDIV + 1][4], *fp; int a, doscale = 0; length = bone->length; @@ -459,8 +459,8 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) } } - hlength1 = bone->ease1*length*0.390464f; /* 0.5*sqrt(2)*kappa, the handle length for near-perfect circles */ - hlength2 = bone->ease2*length*0.390464f; + hlength1 = bone->ease1 * length * 0.390464f; /* 0.5*sqrt(2)*kappa, the handle length for near-perfect circles */ + hlength2 = bone->ease2 * length * 0.390464f; /* evaluate next and prev bones */ if (bone->flag & BONE_CONNECTED) @@ -494,7 +494,7 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) copy_v3_v3(h1, prev->pose_head); mul_m4_v3(imat, h1); - if (prev->bone->segments>1) { + if (prev->bone->segments > 1) { /* if previous bone is B-bone too, use average handle direction */ h1[1] -= length; roll1 = 0.0f; @@ -534,10 +534,10 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) mul_m4_v3(imat, h2); /* if next bone is B-bone too, use average handle direction */ - if (next->bone->segments>1) + if (next->bone->segments > 1) ; else - h2[1]-= length; + h2[1] -= length; normalize_v3(h2); /* find the next roll to interpolate as well */ @@ -579,7 +579,7 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) /* make transformation matrices for the segments for drawing */ for (a = 0, fp = data[0]; a < bone->segments; a++, fp += 4) { - sub_v3_v3v3(h1, fp+4, fp); + sub_v3_v3v3(h1, fp + 4, fp); vec_roll_to_mat3(h1, fp[3], mat3); /* fp[3] is roll */ copy_m4_m3(result_array[a].mat, mat3); @@ -613,11 +613,11 @@ static void pchan_b_bone_defmats(bPoseChannel *pchan, bPoseChanDeform *pdef_info int a; /* allocate b_bone matrices and dual quats */ - b_bone_mats = MEM_mallocN((1+bone->segments)*sizeof(Mat4), "BBone defmats"); + b_bone_mats = MEM_mallocN((1 + bone->segments) * sizeof(Mat4), "BBone defmats"); pdef_info->b_bone_mats = b_bone_mats; if (use_quaternion) { - b_bone_dual_quats = MEM_mallocN((bone->segments)*sizeof(DualQuat), "BBone dqs"); + b_bone_dual_quats = MEM_mallocN((bone->segments) * sizeof(DualQuat), "BBone dqs"); pdef_info->b_bone_dual_quats = b_bone_dual_quats; } @@ -634,11 +634,11 @@ static void pchan_b_bone_defmats(bPoseChannel *pchan, bPoseChanDeform *pdef_info for (a = 0; a < bone->segments; a++) { invert_m4_m4(tmat, b_bone_rest[a].mat); - mul_serie_m4(b_bone_mats[a+1].mat, pchan->chan_mat, bone->arm_mat, b_bone[a].mat, tmat, b_bone_mats[0].mat, + mul_serie_m4(b_bone_mats[a + 1].mat, pchan->chan_mat, bone->arm_mat, b_bone[a].mat, tmat, b_bone_mats[0].mat, NULL, NULL, NULL); if (use_quaternion) - mat4_to_dquat(&b_bone_dual_quats[a], bone->arm_mat, b_bone_mats[a+1].mat); + mat4_to_dquat(&b_bone_dual_quats[a], bone->arm_mat, b_bone_mats[a + 1].mat); } } @@ -650,24 +650,24 @@ static void b_bone_deform(bPoseChanDeform *pdef_info, Bone *bone, float co[3], D int a; /* need to transform co back to bonespace, only need y */ - y = mat[0][1]*co[0] + mat[1][1]*co[1] + mat[2][1]*co[2] + mat[3][1]; + y = mat[0][1] * co[0] + mat[1][1] * co[1] + mat[2][1] * co[2] + mat[3][1]; /* now calculate which of the b_bones are deforming this */ - segment = bone->length/((float)bone->segments); - a = (int)(y/segment); + segment = bone->length / ((float)bone->segments); + a = (int)(y / segment); /* note; by clamping it extends deform at endpoints, goes best with * straight joints in restpos. */ - CLAMP(a, 0, bone->segments-1); + CLAMP(a, 0, bone->segments - 1); if (dq) { copy_dq_dq(dq, &(pdef_info->b_bone_dual_quats)[a]); } else { - mul_m4_v3(b_bone[a+1].mat, co); + mul_m4_v3(b_bone[a + 1].mat, co); if (defmat) { - copy_m3_m4(defmat, b_bone[a+1].mat); + copy_m3_m4(defmat, b_bone[a + 1].mat); } } } @@ -699,27 +699,27 @@ float distfactor_to_bone(const float vec[3], const float b1[3], const float b2[3 rad = rad2; } else { - dist = (hsqr - (a*a)); + dist = (hsqr - (a * a)); if (l != 0.0f) { - rad = a/l; - rad = rad*rad2 + (1.0f-rad)*rad1; + rad = a / l; + rad = rad * rad2 + (1.0f - rad) * rad1; } else rad = rad1; } - a = rad*rad; + a = rad * rad; if (dist < a) return 1.0f; else { - l = rad+rdist; + l = rad + rdist; l *= l; if (rdist == 0.0f || dist >= l) return 0.0f; else { - a = sqrtf(dist)-rad; - return 1.0f-( a*a )/( rdist*rdist ); + a = sqrtf(dist) - rad; + return 1.0f - (a * a) / (rdist * rdist); } } } @@ -796,15 +796,15 @@ static void pchan_bone_deform(bPoseChannel *pchan, bPoseChanDeform *pdef_info, f copy_v3_v3(cop, co); if (vec) { - if (pchan->bone->segments>1) + if (pchan->bone->segments > 1) /* applies on cop and bbonemat */ b_bone_deform(pdef_info, pchan->bone, cop, NULL, (mat) ? bbonemat : NULL); else mul_m4_v3(pchan->chan_mat, cop); - vec[0] += (cop[0]-co[0])*weight; - vec[1] += (cop[1]-co[1])*weight; - vec[2] += (cop[2]-co[2])*weight; + vec[0] += (cop[0] - co[0]) * weight; + vec[1] += (cop[1] - co[1]) * weight; + vec[2] += (cop[2] - co[2]) * weight; if (mat) pchan_deform_mat_add(pchan, weight, bbonemat, mat); @@ -856,10 +856,10 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float totchan = BLI_countlist(&armOb->pose->chanbase); if (use_quaternion) { - dualquats = MEM_callocN(sizeof(DualQuat)*totchan, "dualquats"); + dualquats = MEM_callocN(sizeof(DualQuat) * totchan, "dualquats"); } - pdef_info_array = MEM_callocN(sizeof(bPoseChanDeform)*totchan, "bPoseChanDeform"); + pdef_info_array = MEM_callocN(sizeof(bPoseChanDeform) * totchan, "bPoseChanDeform"); totchan = 0; pdef_info = pdef_info_array; @@ -891,7 +891,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float Lattice *lt = target->data; dverts = lt->dvert; if (dverts) - target_totvert = lt->pntsu*lt->pntsv*lt->pntsw; + target_totvert = lt->pntsu * lt->pntsv * lt->pntsw; } } @@ -963,7 +963,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float armature_weight = defvert_find_weight(dvert, armature_def_nr); if (invert_vgroup) - armature_weight = 1.0f-armature_weight; + armature_weight = 1.0f - armature_weight; /* hackish: the blending factor can be used for blending with prevCos too */ if (prevCos) { @@ -1039,7 +1039,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float smat = summat; } else { - mul_v3_fl(vec, armature_weight/contrib); + mul_v3_fl(vec, armature_weight / contrib); add_v3_v3v3(co, vec, co); } @@ -1051,7 +1051,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float copy_m3_m3(tmpmat, defMats[i]); if (!use_quaternion) /* quaternion already is scale corrected */ - mul_m3_fl(smat, armature_weight/contrib); + mul_m3_fl(smat, armature_weight / contrib); mul_serie_m3(defMats[i], tmpmat, pre, smat, post, NULL, NULL, NULL, NULL); } @@ -1063,9 +1063,9 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float /* interpolate with previous modifier position using weight group */ if (prevCos) { float mw = 1.0f - prevco_weight; - vertexCos[i][0] = prevco_weight*vertexCos[i][0] + mw*co[0]; - vertexCos[i][1] = prevco_weight*vertexCos[i][1] + mw*co[1]; - vertexCos[i][2] = prevco_weight*vertexCos[i][2] + mw*co[2]; + vertexCos[i][0] = prevco_weight * vertexCos[i][0] + mw * co[0]; + vertexCos[i][1] = prevco_weight * vertexCos[i][1] + mw * co[1]; + vertexCos[i][2] = prevco_weight * vertexCos[i][2] + mw * co[2]; } } @@ -1090,7 +1090,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float /* ************ END Armature Deform ******************* */ -void get_objectspace_bone_matrix(struct Bone* bone, float M_accumulatedMatrix[][4], int UNUSED(root), +void get_objectspace_bone_matrix(struct Bone *bone, float M_accumulatedMatrix[][4], int UNUSED(root), int UNUSED(posed)) { copy_m4_m4(M_accumulatedMatrix, bone->arm_mat); @@ -1229,7 +1229,7 @@ void BKE_pchan_to_pose_mat(bPoseChannel *pchan, float rotscale_mat[][4], float l mult_m4_m4m4(loc_mat, bone_loc, tmat4); } /* Those flags do not affect position, use plain parent transform space! */ - else if (bone->flag & (BONE_HINGE|BONE_NO_SCALE)) { + else if (bone->flag & (BONE_HINGE | BONE_NO_SCALE)) { mult_m4_m4m4(loc_mat, parchan->pose_mat, offs_bone); } /* Else (i.e. default, usual case), just use the same matrix for rotation/scaling, and location. */ @@ -1576,10 +1576,10 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected BKE_pose_rest(frompose); /* copy over all of the proxy's bone groups */ - /* TODO for later - * - implement 'local' bone groups as for constraints - * Note: this isn't trivial, as bones reference groups by index not by pointer, - * so syncing things correctly needs careful attention */ + /* TODO for later + * - implement 'local' bone groups as for constraints + * Note: this isn't trivial, as bones reference groups by index not by pointer, + * so syncing things correctly needs careful attention */ BLI_freelistN(&pose->agroups); BLI_duplicatelist(&pose->agroups, &frompose->agroups); pose->active_group = frompose->active_group; @@ -1739,7 +1739,7 @@ void BKE_pose_rebuild(Object *ob, bArmature *arm) BKE_pose_update_constraint_flags(ob->pose); /* for IK detection for example */ /* the sorting */ - if (counter>1) + if (counter > 1) DAG_pose_sort(ob); ob->pose->flag &= ~POSE_RECALC; @@ -1792,7 +1792,7 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos if ((ikData->tar == NULL) || (ikData->tar->type != OB_CURVE)) continue; /* skip if disabled */ - if ((con->enforce == 0.0f) || (con->flag & (CONSTRAINT_DISABLE|CONSTRAINT_OFF))) + if ((con->enforce == 0.0f) || (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF))) continue; /* otherwise, constraint is ok... */ @@ -1831,7 +1831,7 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos if (segcount == 0) return; else - pchanRoot = pchanChain[segcount-1]; + pchanRoot = pchanChain[segcount - 1]; /* perform binding step if required */ if ((ikData->flag & CONSTRAINT_SPLINEIK_BOUND) == 0) { @@ -1841,8 +1841,8 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos /* setup new empty array for the points list */ if (ikData->points) MEM_freeN(ikData->points); - ikData->numpoints = ikData->chainlen+1; - ikData->points = MEM_callocN(sizeof(float)*ikData->numpoints, "Spline IK Binding"); + ikData->numpoints = ikData->chainlen + 1; + ikData->points = MEM_callocN(sizeof(float) * ikData->numpoints, "Spline IK Binding"); /* bind 'tip' of chain (i.e. first joint = tip of bone with the Spline IK Constraint) */ ikData->points[0] = 1.0f; @@ -1856,13 +1856,13 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos */ if ((ikData->flag & CONSTRAINT_SPLINEIK_EVENSPLITS) || (totLength == 0.0f)) { /* 1) equi-spaced joints */ - ikData->points[i+1] = ikData->points[i] - segmentLen; + ikData->points[i + 1] = ikData->points[i] - segmentLen; } else { /* 2) to find this point on the curve, we take a step from the previous joint * a distance given by the proportion that this bone takes */ - ikData->points[i+1] = ikData->points[i] - (boneLengths[i] / totLength); + ikData->points[i + 1] = ikData->points[i] - (boneLengths[i] / totLength); } } @@ -1916,8 +1916,8 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos tree->chainlen = segcount; /* copy over the array of links to bones in the chain (from tip to root) */ - tree->chain = MEM_callocN(sizeof(bPoseChannel*)*segcount, "SplineIK Chain"); - memcpy(tree->chain, pchanChain, sizeof(bPoseChannel*)*segcount); + tree->chain = MEM_callocN(sizeof(bPoseChannel *) * segcount, "SplineIK Chain"); + memcpy(tree->chain, pchanChain, sizeof(bPoseChannel *) * segcount); /* store reference to joint position array */ tree->points = jointPoints; @@ -1956,7 +1956,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o { bSplineIKConstraint *ikData = tree->ikData; float poseHead[3], poseTail[3], poseMat[4][4]; - float splineVec[3], scaleFac, radius =1.0f; + float splineVec[3], scaleFac, radius = 1.0f; /* firstly, calculate the bone matrix the standard way, since this is needed for roll control */ BKE_pose_where_is_bone(scene, ob, pchan, ctime, 1); @@ -1970,14 +1970,14 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o float tailBlendFac = 1.0f; /* determine if the bone should still be affected by SplineIK */ - if (tree->points[index+1] >= 1.0f) { + if (tree->points[index + 1] >= 1.0f) { /* spline doesn't affect the bone anymore, so done... */ pchan->flag |= POSE_DONE; return; } - else if ((tree->points[index] >= 1.0f) && (tree->points[index+1] < 1.0f)) { + else if ((tree->points[index] >= 1.0f) && (tree->points[index + 1] < 1.0f)) { /* blending factor depends on the amount of the bone still left on the chain */ - tailBlendFac = (1.0f - tree->points[index+1]) / (tree->points[index] - tree->points[index+1]); + tailBlendFac = (1.0f - tree->points[index + 1]) / (tree->points[index] - tree->points[index + 1]); } /* tail endpoint */ @@ -1997,7 +1997,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o } /* head endpoint */ - if (where_on_path(ikData->tar, tree->points[index+1], vec, dir, NULL, &rad, NULL)) { + if (where_on_path(ikData->tar, tree->points[index + 1], vec, dir, NULL, &rad, NULL)) { /* apply curve's object-mode transforms to the position * unless the option to allow curve to be positioned elsewhere is activated (i.e. no root) */ @@ -2009,7 +2009,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o copy_v3_v3(poseHead, vec); /* set the new radius (it should be the average value) */ - radius = (radius+rad) / 2; + radius = (radius + rad) / 2; } } @@ -2083,7 +2083,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o scale = len_v3(pchan->pose_mat[2]); mul_v3_fl(poseMat[2], scale); } - break; + break; case CONSTRAINT_SPLINEIK_XZS_VOLUMETRIC: { /* 'volume preservation' */ @@ -2106,7 +2106,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o mul_v3_fl(poseMat[0], scale); mul_v3_fl(poseMat[2], scale); } - break; + break; } /* finally, multiply the x and z scaling by the radius of the curve too, @@ -2164,7 +2164,7 @@ static void splineik_execute_tree(Scene *scene, Object *ob, bPoseChannel *pchan_ * - the chain is traversed in the opposite order to storage order (i.e. parent to children) * so that dependencies are correct */ - for (i = tree->chainlen-1; i >= 0; i--) { + for (i = tree->chainlen - 1; i >= 0; i--) { bPoseChannel *pchan = tree->chain[i]; splineik_evaluate_bone(tree, scene, ob, pchan, i, ctime); } @@ -2241,116 +2241,116 @@ static void do_strip_modifiers(Scene *scene, Object *armob, Bone *bone, bPoseCha { bActionModifier *amod; bActionStrip *strip, *strip2; - float scene_cfra= (float)scene->r.cfra; + float scene_cfra = (float)scene->r.cfra; int do_modif; - for (strip=armob->nlastrips.first; strip; strip=strip->next) { - do_modif=0; + for (strip = armob->nlastrips.first; strip; strip = strip->next) { + do_modif = 0; - if (scene_cfra>=strip->start && scene_cfra<=strip->end) - do_modif=1; + if (scene_cfra >= strip->start && scene_cfra <= strip->end) + do_modif = 1; if ((scene_cfra > strip->end) && (strip->flag & ACTSTRIP_HOLDLASTFRAME)) { - do_modif=1; + do_modif = 1; /* if there are any other strips active, ignore modifiers for this strip - * 'hold' option should only hold action modifiers if there are * no other active strips */ - for (strip2=strip->next; strip2; strip2=strip2->next) { + for (strip2 = strip->next; strip2; strip2 = strip2->next) { if (strip2 == strip) continue; - if (scene_cfra>=strip2->start && scene_cfra<=strip2->end) { + if (scene_cfra >= strip2->start && scene_cfra <= strip2->end) { if (!(strip2->flag & ACTSTRIP_MUTE)) - do_modif=0; + do_modif = 0; } } /* if there are any later, activated, strips with 'hold' set, they take precedence, * so ignore modifiers for this strip */ - for (strip2=strip->next; strip2; strip2=strip2->next) { + for (strip2 = strip->next; strip2; strip2 = strip2->next) { if (scene_cfra < strip2->start) continue; if ((strip2->flag & ACTSTRIP_HOLDLASTFRAME) && !(strip2->flag & ACTSTRIP_MUTE)) { - do_modif=0; + do_modif = 0; } } } if (do_modif) { /* temporal solution to prevent 2 strips accumulating */ - if (scene_cfra==strip->end && strip->next && strip->next->start==scene_cfra) + if (scene_cfra == strip->end && strip->next && strip->next->start == scene_cfra) continue; - for (amod= strip->modifiers.first; amod; amod= amod->next) { + for (amod = strip->modifiers.first; amod; amod = amod->next) { switch (amod->type) { - case ACTSTRIP_MOD_DEFORM: - { - /* validate first */ - if (amod->ob && amod->ob->type==OB_CURVE && amod->channel[0]) { + case ACTSTRIP_MOD_DEFORM: + { + /* validate first */ + if (amod->ob && amod->ob->type == OB_CURVE && amod->channel[0]) { - if ( strcmp(pchan->name, amod->channel)==0 ) { - float mat4[4][4], mat3[3][3]; + if (strcmp(pchan->name, amod->channel) == 0) { + float mat4[4][4], mat3[3][3]; - curve_deform_vector(scene, amod->ob, armob, bone->arm_mat[3], pchan->pose_mat[3], mat3, amod->no_rot_axis); - copy_m4_m4(mat4, pchan->pose_mat); - mul_m4_m3m4(pchan->pose_mat, mat3, mat4); + curve_deform_vector(scene, amod->ob, armob, bone->arm_mat[3], pchan->pose_mat[3], mat3, amod->no_rot_axis); + copy_m4_m4(mat4, pchan->pose_mat); + mul_m4_m3m4(pchan->pose_mat, mat3, mat4); + } } } - } break; - case ACTSTRIP_MOD_NOISE: - { - if ( strcmp(pchan->name, amod->channel)==0 ) { - float nor[3], loc[3], ofs; - float eul[3], size[3], eulo[3], sizeo[3]; - - /* calculate turbulance */ - ofs = amod->turbul / 200.0f; - - /* make a copy of starting conditions */ - copy_v3_v3(loc, pchan->pose_mat[3]); - mat4_to_eul(eul, pchan->pose_mat); - mat4_to_size(size, pchan->pose_mat); - copy_v3_v3(eulo, eul); - copy_v3_v3(sizeo, size); - - /* apply noise to each set of channels */ - if (amod->channels & 4) { - /* for scaling */ - nor[0] = BLI_gNoise(amod->noisesize, size[0]+ofs, size[1], size[2], 0, 0) - ofs; - nor[1] = BLI_gNoise(amod->noisesize, size[0], size[1]+ofs, size[2], 0, 0) - ofs; - nor[2] = BLI_gNoise(amod->noisesize, size[0], size[1], size[2]+ofs, 0, 0) - ofs; - add_v3_v3(size, nor); - - if (sizeo[0] != 0) - mul_v3_fl(pchan->pose_mat[0], size[0] / sizeo[0]); - if (sizeo[1] != 0) - mul_v3_fl(pchan->pose_mat[1], size[1] / sizeo[1]); - if (sizeo[2] != 0) - mul_v3_fl(pchan->pose_mat[2], size[2] / sizeo[2]); - } - if (amod->channels & 2) { - /* for rotation */ - nor[0] = BLI_gNoise(amod->noisesize, eul[0]+ofs, eul[1], eul[2], 0, 0) - ofs; - nor[1] = BLI_gNoise(amod->noisesize, eul[0], eul[1]+ofs, eul[2], 0, 0) - ofs; - nor[2] = BLI_gNoise(amod->noisesize, eul[0], eul[1], eul[2]+ofs, 0, 0) - ofs; - - compatible_eul(nor, eulo); - add_v3_v3(eul, nor); - compatible_eul(eul, eulo); - - loc_eul_size_to_mat4(pchan->pose_mat, loc, eul, size); - } - if (amod->channels & 1) { - /* for location */ - nor[0] = BLI_gNoise(amod->noisesize, loc[0]+ofs, loc[1], loc[2], 0, 0) - ofs; - nor[1] = BLI_gNoise(amod->noisesize, loc[0], loc[1]+ofs, loc[2], 0, 0) - ofs; - nor[2] = BLI_gNoise(amod->noisesize, loc[0], loc[1], loc[2]+ofs, 0, 0) - ofs; - - add_v3_v3v3(pchan->pose_mat[3], loc, nor); + case ACTSTRIP_MOD_NOISE: + { + if (strcmp(pchan->name, amod->channel) == 0) { + float nor[3], loc[3], ofs; + float eul[3], size[3], eulo[3], sizeo[3]; + + /* calculate turbulance */ + ofs = amod->turbul / 200.0f; + + /* make a copy of starting conditions */ + copy_v3_v3(loc, pchan->pose_mat[3]); + mat4_to_eul(eul, pchan->pose_mat); + mat4_to_size(size, pchan->pose_mat); + copy_v3_v3(eulo, eul); + copy_v3_v3(sizeo, size); + + /* apply noise to each set of channels */ + if (amod->channels & 4) { + /* for scaling */ + nor[0] = BLI_gNoise(amod->noisesize, size[0] + ofs, size[1], size[2], 0, 0) - ofs; + nor[1] = BLI_gNoise(amod->noisesize, size[0], size[1] + ofs, size[2], 0, 0) - ofs; + nor[2] = BLI_gNoise(amod->noisesize, size[0], size[1], size[2] + ofs, 0, 0) - ofs; + add_v3_v3(size, nor); + + if (sizeo[0] != 0) + mul_v3_fl(pchan->pose_mat[0], size[0] / sizeo[0]); + if (sizeo[1] != 0) + mul_v3_fl(pchan->pose_mat[1], size[1] / sizeo[1]); + if (sizeo[2] != 0) + mul_v3_fl(pchan->pose_mat[2], size[2] / sizeo[2]); + } + if (amod->channels & 2) { + /* for rotation */ + nor[0] = BLI_gNoise(amod->noisesize, eul[0] + ofs, eul[1], eul[2], 0, 0) - ofs; + nor[1] = BLI_gNoise(amod->noisesize, eul[0], eul[1] + ofs, eul[2], 0, 0) - ofs; + nor[2] = BLI_gNoise(amod->noisesize, eul[0], eul[1], eul[2] + ofs, 0, 0) - ofs; + + compatible_eul(nor, eulo); + add_v3_v3(eul, nor); + compatible_eul(eul, eulo); + + loc_eul_size_to_mat4(pchan->pose_mat, loc, eul, size); + } + if (amod->channels & 1) { + /* for location */ + nor[0] = BLI_gNoise(amod->noisesize, loc[0] + ofs, loc[1], loc[2], 0, 0) - ofs; + nor[1] = BLI_gNoise(amod->noisesize, loc[0], loc[1] + ofs, loc[2], 0, 0) - ofs; + nor[2] = BLI_gNoise(amod->noisesize, loc[0], loc[1], loc[2] + ofs, 0, 0) - ofs; + + add_v3_v3v3(pchan->pose_mat[3], loc, nor); + } } } - } break; } } @@ -2394,7 +2394,7 @@ void BKE_pose_where_is_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float } if (do_extra) { -#if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */ +#if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */ /* do NLA strip modifiers - i.e. curve follow */ do_strip_modifiers(scene, ob, bone, pchan); #endif @@ -2413,7 +2413,7 @@ void BKE_pose_where_is_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cob = constraints_make_evalob(scene, ob, pchan, CONSTRAINT_OBTYPE_BONE); /* Solve PoseChannel's Constraints */ - solve_constraints(&pchan->constraints, cob, ctime); /* ctime doesnt alter objects */ + solve_constraints(&pchan->constraints, cob, ctime); /* ctime doesnt alter objects */ /* cleanup after Constraint Solving * - applies matrix back to pchan, and frees temporary struct used @@ -2470,7 +2470,7 @@ void BKE_pose_where_is(Scene *scene, Object *ob) /* 1. clear flags */ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { - pchan->flag &= ~(POSE_DONE|POSE_CHAIN|POSE_IKTREE|POSE_IKSPLINE); + pchan->flag &= ~(POSE_DONE | POSE_CHAIN | POSE_IKTREE | POSE_IKSPLINE); } /* 2a. construct the IK tree (standard IK) */ diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index a1e8a11e9ff..dc13404dfaf 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -75,49 +75,49 @@ static void brush_defaults(Brush *brush) brush->ob_mode = OB_MODE_ALL_PAINT; /* BRUSH SCULPT TOOL SETTINGS */ - brush->weight= 1.0f; /* weight of brush 0 - 1.0 */ - brush->size= 35; /* radius of the brush in pixels */ - brush->alpha= 0.5f; /* brush strength/intensity probably variable should be renamed? */ - brush->autosmooth_factor= 0.0f; - brush->crease_pinch_factor= 0.5f; + brush->weight = 1.0f; /* weight of brush 0 - 1.0 */ + brush->size = 35; /* radius of the brush in pixels */ + brush->alpha = 0.5f; /* brush strength/intensity probably variable should be renamed? */ + brush->autosmooth_factor = 0.0f; + brush->crease_pinch_factor = 0.5f; brush->sculpt_plane = SCULPT_DISP_DIR_AREA; - brush->plane_offset= 0.0f; /* how far above or below the plane that is found by averaging the faces */ - brush->plane_trim= 0.5f; - brush->clone.alpha= 0.5f; - brush->normal_weight= 0.0f; + brush->plane_offset = 0.0f; /* how far above or below the plane that is found by averaging the faces */ + brush->plane_trim = 0.5f; + brush->clone.alpha = 0.5f; + brush->normal_weight = 0.0f; brush->flag |= BRUSH_ALPHA_PRESSURE; /* BRUSH PAINT TOOL SETTINGS */ - brush->rgb[0]= 1.0f; /* default rgb color of the brush when painting - white */ - brush->rgb[1]= 1.0f; - brush->rgb[2]= 1.0f; + brush->rgb[0] = 1.0f; /* default rgb color of the brush when painting - white */ + brush->rgb[1] = 1.0f; + brush->rgb[2] = 1.0f; /* BRUSH STROKE SETTINGS */ - brush->flag |= (BRUSH_SPACE|BRUSH_SPACE_ATTEN); - brush->spacing= 10; /* how far each brush dot should be spaced as a percentage of brush diameter */ + brush->flag |= (BRUSH_SPACE | BRUSH_SPACE_ATTEN); + brush->spacing = 10; /* how far each brush dot should be spaced as a percentage of brush diameter */ - brush->smooth_stroke_radius= 75; - brush->smooth_stroke_factor= 0.9f; + brush->smooth_stroke_radius = 75; + brush->smooth_stroke_factor = 0.9f; - brush->rate= 0.1f; /* time delay between dots of paint or sculpting when doing airbrush mode */ + brush->rate = 0.1f; /* time delay between dots of paint or sculpting when doing airbrush mode */ - brush->jitter= 0.0f; + brush->jitter = 0.0f; /* BRUSH TEXTURE SETTINGS */ default_mtex(&brush->mtex); - brush->texture_sample_bias= 0; /* value to added to texture samples */ - brush->texture_overlay_alpha= 33; + brush->texture_sample_bias = 0; /* value to added to texture samples */ + brush->texture_overlay_alpha = 33; /* brush appearance */ - brush->add_col[0]= 1.00; /* add mode color is light red */ - brush->add_col[1]= 0.39; - brush->add_col[2]= 0.39; + brush->add_col[0] = 1.00; /* add mode color is light red */ + brush->add_col[1] = 0.39; + brush->add_col[2] = 0.39; - brush->sub_col[0]= 0.39; /* subtract mode color is light blue */ - brush->sub_col[1]= 0.39; - brush->sub_col[2]= 1.00; + brush->sub_col[0] = 0.39; /* subtract mode color is light blue */ + brush->sub_col[1] = 0.39; + brush->sub_col[2] = 1.00; } /* Datablock add/copy/free/make_local */ @@ -126,7 +126,7 @@ Brush *BKE_brush_add(const char *name) { Brush *brush; - brush= BKE_libblock_alloc(&G.main->brush, ID_BR, name); + brush = BKE_libblock_alloc(&G.main->brush, ID_BR, name); /* enable fake user by default */ brush->id.flag |= LIB_FAKEUSER; @@ -135,7 +135,7 @@ Brush *BKE_brush_add(const char *name) brush->sculpt_tool = SCULPT_TOOL_DRAW; /* sculpting defaults to the draw tool for new brushes */ - /* the default alpha falloff curve */ + /* the default alpha falloff curve */ BKE_brush_curve_preset(brush, CURVE_PRESET_SMOOTH); return brush; @@ -145,17 +145,17 @@ Brush *BKE_brush_copy(Brush *brush) { Brush *brushn; - brushn= BKE_libblock_copy(&brush->id); + brushn = BKE_libblock_copy(&brush->id); if (brush->mtex.tex) - id_us_plus((ID*)brush->mtex.tex); + id_us_plus((ID *)brush->mtex.tex); if (brush->icon_imbuf) - brushn->icon_imbuf= IMB_dupImBuf(brush->icon_imbuf); + brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf); brushn->preview = NULL; - brushn->curve= curvemapping_copy(brush->curve); + brushn->curve = curvemapping_copy(brush->curve); /* enable fake user by default */ if (!(brushn->id.flag & LIB_FAKEUSER)) { @@ -194,11 +194,11 @@ void BKE_brush_make_local(Brush *brush) * - mixed: make copy */ - Main *bmain= G.main; + Main *bmain = G.main; Scene *scene; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; - if (brush->id.lib==NULL) return; + if (brush->id.lib == NULL) return; if (brush->clone.image) { /* special case: ima always local immediately. Clone image should only @@ -207,10 +207,10 @@ void BKE_brush_make_local(Brush *brush) extern_local_brush(brush); } - 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) is_lib= TRUE; - else is_local= TRUE; + 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) is_lib = TRUE; + else is_local = TRUE; } } @@ -225,16 +225,16 @@ void BKE_brush_make_local(Brush *brush) } } else if (is_local && is_lib) { - Brush *brush_new= BKE_brush_copy(brush); - brush_new->id.us= 1; /* only keep fake user */ + Brush *brush_new = BKE_brush_copy(brush); + brush_new->id.us = 1; /* only keep fake user */ brush_new->id.flag |= LIB_FAKEUSER; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->id); - for (scene= bmain->scene.first; scene; scene=scene->id.next) { - if (paint_brush(&scene->toolsettings->imapaint.paint)==brush) { - if (scene->id.lib==NULL) { + for (scene = bmain->scene.first; scene; scene = scene->id.next) { + if (paint_brush(&scene->toolsettings->imapaint.paint) == brush) { + if (scene->id.lib == NULL) { paint_brush_set(&scene->toolsettings->imapaint.paint, brush_new); } } @@ -245,16 +245,16 @@ void BKE_brush_make_local(Brush *brush) void BKE_brush_debug_print_state(Brush *br) { /* create a fake brush and set it to the defaults */ - Brush def= {{NULL}}; + Brush def = {{NULL}}; brush_defaults(&def); #define BR_TEST(field, t) \ if (br->field != def.field) \ printf("br->" #field " = %" #t ";\n", br->field) -#define BR_TEST_FLAG(_f) \ +#define BR_TEST_FLAG(_f) \ if ((br->flag & _f) && !(def.flag & _f)) \ - printf("br->flag |= " #_f ";\n"); \ + printf("br->flag |= " #_f ";\n"); \ else if (!(br->flag & _f) && (def.flag & _f)) \ printf("br->flag &= ~" #_f ";\n") @@ -339,77 +339,77 @@ void BKE_brush_sculpt_reset(Brush *br) BKE_brush_curve_preset(br, CURVE_PRESET_SMOOTH); switch (br->sculpt_tool) { - case SCULPT_TOOL_CLAY: - br->flag |= BRUSH_FRONTFACE; - break; - case SCULPT_TOOL_CREASE: - br->flag |= BRUSH_DIR_IN; - br->alpha = 0.25; - break; - case SCULPT_TOOL_FILL: - br->add_col[1] = 1; - br->sub_col[0] = 0.25; - br->sub_col[1] = 1; - break; - case SCULPT_TOOL_FLATTEN: - br->add_col[1] = 1; - br->sub_col[0] = 0.25; - br->sub_col[1] = 1; - break; - case SCULPT_TOOL_INFLATE: - br->add_col[0] = 0.750000; - br->add_col[1] = 0.750000; - br->add_col[2] = 0.750000; - br->sub_col[0] = 0.250000; - br->sub_col[1] = 0.250000; - br->sub_col[2] = 0.250000; - break; - case SCULPT_TOOL_NUDGE: - br->add_col[0] = 0.250000; - br->add_col[1] = 1.000000; - br->add_col[2] = 0.250000; - break; - case SCULPT_TOOL_PINCH: - br->add_col[0] = 0.750000; - br->add_col[1] = 0.750000; - br->add_col[2] = 0.750000; - br->sub_col[0] = 0.250000; - br->sub_col[1] = 0.250000; - br->sub_col[2] = 0.250000; - break; - case SCULPT_TOOL_SCRAPE: - br->add_col[1] = 1.000000; - br->sub_col[0] = 0.250000; - br->sub_col[1] = 1.000000; - break; - case SCULPT_TOOL_ROTATE: - br->alpha = 1.0; - break; - case SCULPT_TOOL_SMOOTH: - br->flag &= ~BRUSH_SPACE_ATTEN; - br->spacing = 5; - br->add_col[0] = 0.750000; - br->add_col[1] = 0.750000; - br->add_col[2] = 0.750000; - break; - case SCULPT_TOOL_GRAB: - case SCULPT_TOOL_SNAKE_HOOK: - case SCULPT_TOOL_THUMB: - br->size = 75; - br->flag &= ~BRUSH_ALPHA_PRESSURE; - br->flag &= ~BRUSH_SPACE; - br->flag &= ~BRUSH_SPACE_ATTEN; - br->add_col[0] = 0.250000; - br->add_col[1] = 1.000000; - br->add_col[2] = 0.250000; - break; - default: - break; + case SCULPT_TOOL_CLAY: + br->flag |= BRUSH_FRONTFACE; + break; + case SCULPT_TOOL_CREASE: + br->flag |= BRUSH_DIR_IN; + br->alpha = 0.25; + break; + case SCULPT_TOOL_FILL: + br->add_col[1] = 1; + br->sub_col[0] = 0.25; + br->sub_col[1] = 1; + break; + case SCULPT_TOOL_FLATTEN: + br->add_col[1] = 1; + br->sub_col[0] = 0.25; + br->sub_col[1] = 1; + break; + case SCULPT_TOOL_INFLATE: + br->add_col[0] = 0.750000; + br->add_col[1] = 0.750000; + br->add_col[2] = 0.750000; + br->sub_col[0] = 0.250000; + br->sub_col[1] = 0.250000; + br->sub_col[2] = 0.250000; + break; + case SCULPT_TOOL_NUDGE: + br->add_col[0] = 0.250000; + br->add_col[1] = 1.000000; + br->add_col[2] = 0.250000; + break; + case SCULPT_TOOL_PINCH: + br->add_col[0] = 0.750000; + br->add_col[1] = 0.750000; + br->add_col[2] = 0.750000; + br->sub_col[0] = 0.250000; + br->sub_col[1] = 0.250000; + br->sub_col[2] = 0.250000; + break; + case SCULPT_TOOL_SCRAPE: + br->add_col[1] = 1.000000; + br->sub_col[0] = 0.250000; + br->sub_col[1] = 1.000000; + break; + case SCULPT_TOOL_ROTATE: + br->alpha = 1.0; + break; + case SCULPT_TOOL_SMOOTH: + br->flag &= ~BRUSH_SPACE_ATTEN; + br->spacing = 5; + br->add_col[0] = 0.750000; + br->add_col[1] = 0.750000; + br->add_col[2] = 0.750000; + break; + case SCULPT_TOOL_GRAB: + case SCULPT_TOOL_SNAKE_HOOK: + case SCULPT_TOOL_THUMB: + br->size = 75; + br->flag &= ~BRUSH_ALPHA_PRESSURE; + br->flag &= ~BRUSH_SPACE; + br->flag &= ~BRUSH_SPACE_ATTEN; + br->add_col[0] = 0.250000; + br->add_col[1] = 1.000000; + br->add_col[2] = 0.250000; + break; + default: + break; } } /* Library Operations */ -void BKE_brush_curve_preset(Brush *b, /*CurveMappingPreset*/int preset) +void BKE_brush_curve_preset(Brush *b, /*CurveMappingPreset*/ int preset) { CurveMap *cm = NULL; @@ -426,20 +426,20 @@ void BKE_brush_curve_preset(Brush *b, /*CurveMappingPreset*/int preset) int BKE_brush_texture_set_nr(Brush *brush, int nr) { - ID *idtest, *id=NULL; + ID *idtest, *id = NULL; - id= (ID *)brush->mtex.tex; + id = (ID *)brush->mtex.tex; - idtest= (ID*)BLI_findlink(&G.main->tex, nr-1); - if (idtest==NULL) { /* new tex */ - if (id) idtest= (ID *)BKE_texture_copy((Tex *)id); - else idtest= (ID *)add_texture("Tex"); + idtest = (ID *)BLI_findlink(&G.main->tex, nr - 1); + if (idtest == NULL) { /* new tex */ + if (id) idtest = (ID *)BKE_texture_copy((Tex *)id); + else idtest = (ID *)add_texture("Tex"); idtest->us--; } - if (idtest!=id) { + if (idtest != id) { BKE_brush_texture_delete(brush); - brush->mtex.tex= (Tex*)idtest; + brush->mtex.tex = (Tex *)idtest; id_us_plus(idtest); return 1; @@ -459,13 +459,13 @@ int BKE_brush_texture_delete(Brush *brush) int BKE_brush_clone_image_set_nr(Brush *brush, int nr) { if (brush && nr > 0) { - Image *ima= (Image*)BLI_findlink(&G.main->image, nr-1); + Image *ima = (Image *)BLI_findlink(&G.main->image, nr - 1); if (ima) { BKE_brush_clone_image_delete(brush); - brush->clone.image= ima; + brush->clone.image = ima; id_us_plus(&ima->id); - brush->clone.offset[0]= brush->clone.offset[1]= 0.0f; + brush->clone.offset[0] = brush->clone.offset[1] = 0.0f; return 1; } @@ -478,7 +478,7 @@ int BKE_brush_clone_image_delete(Brush *brush) { if (brush && brush->clone.image) { brush->clone.image->id.us--; - brush->clone.image= NULL; + brush->clone.image = NULL; return 1; } @@ -488,34 +488,34 @@ int BKE_brush_clone_image_delete(Brush *brush) /* Brush Sampling */ void BKE_brush_sample_tex(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], const int thread) { - MTex *mtex= &brush->mtex; + MTex *mtex = &brush->mtex; if (mtex && mtex->tex) { float co[3], tin, tr, tg, tb, ta; int hasrgb; - const int radius= BKE_brush_size_get(scene, brush); + const int radius = BKE_brush_size_get(scene, brush); - co[0]= xy[0]/radius; - co[1]= xy[1]/radius; - co[2]= 0.0f; + co[0] = xy[0] / radius; + co[1] = xy[1] / radius; + co[2] = 0.0f; - hasrgb= externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, thread); + hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, thread); if (hasrgb) { - rgba[0]= tr; - rgba[1]= tg; - rgba[2]= tb; - rgba[3]= ta; + rgba[0] = tr; + rgba[1] = tg; + rgba[2] = tb; + rgba[3] = ta; } else { - rgba[0]= tin; - rgba[1]= tin; - rgba[2]= tin; - rgba[3]= 1.0f; + rgba[0] = tin; + rgba[1] = tin; + rgba[2] = tin; + rgba[3] = 1.0f; } } else { - rgba[0]= rgba[1]= rgba[2]= rgba[3]= 1.0f; + rgba[0] = rgba[1] = rgba[2] = rgba[3] = 1.0f; } } @@ -525,20 +525,20 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf ImBuf *ibuf; float xy[2], rgba[4], *dstf; int x, y, rowbytes, xoff, yoff, imbflag; - const int radius= BKE_brush_size_get(scene, brush); + const int radius = BKE_brush_size_get(scene, brush); unsigned char *dst, crgb[3]; - const float alpha= BKE_brush_alpha_get(scene, brush); + const float alpha = BKE_brush_alpha_get(scene, brush); float brush_rgb[3]; - imbflag= (flt)? IB_rectfloat: IB_rect; - xoff = -bufsize/2.0f + 0.5f; - yoff = -bufsize/2.0f + 0.5f; - rowbytes= bufsize*4; + imbflag = (flt) ? IB_rectfloat : IB_rect; + xoff = -bufsize / 2.0f + 0.5f; + yoff = -bufsize / 2.0f + 0.5f; + rowbytes = bufsize * 4; if (*outbuf) - ibuf= *outbuf; + ibuf = *outbuf; else - ibuf= IMB_allocImBuf(bufsize, bufsize, 32, imbflag); + ibuf = IMB_allocImBuf(bufsize, bufsize, 32, imbflag); if (flt) { copy_v3_v3(brush_rgb, brush->rgb); @@ -546,16 +546,16 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf srgb_to_linearrgb_v3_v3(brush_rgb, brush_rgb); } - for (y=0; y < ibuf->y; y++) { - dstf = ibuf->rect_float + y*rowbytes; + for (y = 0; y < ibuf->y; y++) { + dstf = ibuf->rect_float + y * rowbytes; - for (x=0; x < ibuf->x; x++, dstf+=4) { + for (x = 0; x < ibuf->x; x++, dstf += 4) { xy[0] = x + xoff; xy[1] = y + yoff; if (texfall == 0) { copy_v3_v3(dstf, brush_rgb); - dstf[3]= alpha*BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); + dstf[3] = alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); } else if (texfall == 1) { BKE_brush_sample_tex(scene, brush, xy, dstf, 0); @@ -563,7 +563,7 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf else { BKE_brush_sample_tex(scene, brush, xy, rgba, 0); mul_v3_v3v3(dstf, rgba, brush_rgb); - dstf[3] = rgba[3]*alpha*BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); + dstf[3] = rgba[3] *alpha *BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); } } } @@ -572,10 +572,10 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf float alpha_f; /* final float alpha to convert to char */ rgb_float_to_uchar(crgb, brush->rgb); - for (y=0; y < ibuf->y; y++) { - dst = (unsigned char *)ibuf->rect + y*rowbytes; + for (y = 0; y < ibuf->y; y++) { + dst = (unsigned char *)ibuf->rect + y * rowbytes; - for (x=0; x < ibuf->x; x++, dst+=4) { + for (x = 0; x < ibuf->x; x++, dst += 4) { xy[0] = x + xoff; xy[1] = y + yoff; @@ -594,7 +594,7 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf else if (texfall == 2) { BKE_brush_sample_tex(scene, brush, xy, rgba, 0); mul_v3_v3(rgba, brush->rgb); - alpha_f = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); + alpha_f = rgba[3] *alpha *BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); rgb_float_to_uchar(dst, rgba); @@ -602,7 +602,7 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf } else { BKE_brush_sample_tex(scene, brush, xy, rgba, 0); - alpha_f = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); + alpha_f = rgba[3] *alpha *BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); dst[0] = crgb[0]; dst[1] = crgb[1]; @@ -613,7 +613,7 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf } } - *outbuf= ibuf; + *outbuf = ibuf; } /* Unified Size and Strength */ @@ -636,9 +636,9 @@ void BKE_brush_size_set(Scene *scene, Brush *brush, int size) UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; if (ups->flag & UNIFIED_PAINT_SIZE) - ups->size= size; + ups->size = size; else - brush->size= size; + brush->size = size; } int BKE_brush_size_get(const Scene *scene, Brush *brush) @@ -653,8 +653,8 @@ int BKE_brush_use_locked_size(const Scene *scene, Brush *brush) const short us_flag = scene->toolsettings->unified_paint_settings.flag; return (us_flag & UNIFIED_PAINT_SIZE) ? - (us_flag & UNIFIED_PAINT_BRUSH_LOCK_SIZE) : - (brush->flag & BRUSH_LOCK_SIZE); + (us_flag & UNIFIED_PAINT_BRUSH_LOCK_SIZE) : + (brush->flag & BRUSH_LOCK_SIZE); } int BKE_brush_use_size_pressure(const Scene *scene, Brush *brush) @@ -662,8 +662,8 @@ int BKE_brush_use_size_pressure(const Scene *scene, Brush *brush) const short us_flag = scene->toolsettings->unified_paint_settings.flag; return (us_flag & UNIFIED_PAINT_SIZE) ? - (us_flag & UNIFIED_PAINT_BRUSH_SIZE_PRESSURE) : - (brush->flag & BRUSH_SIZE_PRESSURE); + (us_flag & UNIFIED_PAINT_BRUSH_SIZE_PRESSURE) : + (brush->flag & BRUSH_SIZE_PRESSURE); } int BKE_brush_use_alpha_pressure(const Scene *scene, Brush *brush) @@ -671,8 +671,8 @@ int BKE_brush_use_alpha_pressure(const Scene *scene, Brush *brush) const short us_flag = scene->toolsettings->unified_paint_settings.flag; return (us_flag & UNIFIED_PAINT_ALPHA) ? - (us_flag & UNIFIED_PAINT_BRUSH_ALPHA_PRESSURE) : - (brush->flag & BRUSH_ALPHA_PRESSURE); + (us_flag & UNIFIED_PAINT_BRUSH_ALPHA_PRESSURE) : + (brush->flag & BRUSH_ALPHA_PRESSURE); } void BKE_brush_unprojected_radius_set(Scene *scene, Brush *brush, float unprojected_radius) @@ -680,9 +680,9 @@ void BKE_brush_unprojected_radius_set(Scene *scene, Brush *brush, float unprojec UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; if (ups->flag & UNIFIED_PAINT_SIZE) - ups->unprojected_radius= unprojected_radius; + ups->unprojected_radius = unprojected_radius; else - brush->unprojected_radius= unprojected_radius; + brush->unprojected_radius = unprojected_radius; } float BKE_brush_unprojected_radius_get(const Scene *scene, Brush *brush) @@ -690,8 +690,8 @@ float BKE_brush_unprojected_radius_get(const Scene *scene, Brush *brush) UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; return (ups->flag & UNIFIED_PAINT_SIZE) ? - ups->unprojected_radius : - brush->unprojected_radius; + ups->unprojected_radius : + brush->unprojected_radius; } static void brush_alpha_set(Scene *scene, Brush *brush, float alpha) @@ -699,9 +699,9 @@ static void brush_alpha_set(Scene *scene, Brush *brush, float alpha) UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; if (ups->flag & UNIFIED_PAINT_ALPHA) - ups->alpha= alpha; + ups->alpha = alpha; else - brush->alpha= alpha; + brush->alpha = alpha; } float BKE_brush_alpha_get(const Scene *scene, Brush *brush) @@ -722,7 +722,7 @@ void BKE_brush_weight_set(const Scene *scene, Brush *brush, float value) { UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; - if(ups->flag & UNIFIED_PAINT_WEIGHT) + if (ups->flag & UNIFIED_PAINT_WEIGHT) ups->weight = value; else brush->weight = value; @@ -749,7 +749,7 @@ void BKE_brush_scale_size(int *BKE_brush_size_get, /* avoid division by zero */ if (old_unprojected_radius != 0) scale /= new_unprojected_radius; - (*BKE_brush_size_get)= (int)((float)(*BKE_brush_size_get) * scale); + (*BKE_brush_size_get) = (int)((float)(*BKE_brush_size_get) * scale); } /* Brush Painting */ @@ -757,9 +757,9 @@ void BKE_brush_scale_size(int *BKE_brush_size_get, typedef struct BrushPainterCache { short enabled; - int size; /* size override, if 0 uses 2*BKE_brush_size_get(brush) */ - short flt; /* need float imbuf? */ - short texonly; /* no alpha, color or fallof, only texture in imbuf */ + int size; /* size override, if 0 uses 2*BKE_brush_size_get(brush) */ + short flt; /* need float imbuf? */ + short texonly; /* no alpha, color or fallof, only texture in imbuf */ int lastsize; float lastalpha; @@ -774,18 +774,18 @@ struct BrushPainter { Scene *scene; Brush *brush; - float lastmousepos[2]; /* mouse position of last paint call */ + float lastmousepos[2]; /* mouse position of last paint call */ - float accumdistance; /* accumulated distance of brush since last paint op */ - float lastpaintpos[2]; /* position of last paint op */ + float accumdistance; /* accumulated distance of brush since last paint op */ + float lastpaintpos[2]; /* position of last paint op */ float startpaintpos[2]; /* position of first paint */ - double accumtime; /* accumulated time since last paint op (airbrush) */ - double lasttime; /* time of last update */ + double accumtime; /* accumulated time since last paint op (airbrush) */ + double lasttime; /* time of last update */ float lastpressure; - short firsttouch; /* first paint op */ + short firsttouch; /* first paint op */ float startsize; float startalpha; @@ -797,12 +797,12 @@ struct BrushPainter { BrushPainter *BKE_brush_painter_new(Scene *scene, Brush *brush) { - BrushPainter *painter= MEM_callocN(sizeof(BrushPainter), "BrushPainter"); + BrushPainter *painter = MEM_callocN(sizeof(BrushPainter), "BrushPainter"); - painter->brush= brush; - painter->scene= scene; - painter->firsttouch= 1; - painter->cache.lastsize= -1; /* force ibuf create in refresh */ + painter->brush = brush; + painter->scene = scene; + painter->firsttouch = 1; + painter->cache.lastsize = -1; /* force ibuf create in refresh */ painter->startsize = BKE_brush_size_get(scene, brush); painter->startalpha = BKE_brush_alpha_get(scene, brush); @@ -815,23 +815,24 @@ BrushPainter *BKE_brush_painter_new(Scene *scene, Brush *brush) void BKE_brush_painter_require_imbuf(BrushPainter *painter, short flt, short texonly, int size) { if ((painter->cache.flt != flt) || (painter->cache.size != size) || - ((painter->cache.texonly != texonly) && texonly)) { + ((painter->cache.texonly != texonly) && texonly)) + { if (painter->cache.ibuf) IMB_freeImBuf(painter->cache.ibuf); if (painter->cache.maskibuf) IMB_freeImBuf(painter->cache.maskibuf); - painter->cache.ibuf= painter->cache.maskibuf= NULL; - painter->cache.lastsize= -1; /* force ibuf create in refresh */ + painter->cache.ibuf = painter->cache.maskibuf = NULL; + painter->cache.lastsize = -1; /* force ibuf create in refresh */ } if (painter->cache.flt != flt) { if (painter->cache.texibuf) IMB_freeImBuf(painter->cache.texibuf); - painter->cache.texibuf= NULL; - painter->cache.lastsize= -1; /* force ibuf create in refresh */ + painter->cache.texibuf = NULL; + painter->cache.lastsize = -1; /* force ibuf create in refresh */ } - painter->cache.size= size; - painter->cache.flt= flt; - painter->cache.texonly= texonly; - painter->cache.enabled= 1; + painter->cache.size = size; + painter->cache.flt = flt; + painter->cache.texonly = texonly; + painter->cache.enabled = 1; } void BKE_brush_painter_free(BrushPainter *painter) @@ -853,13 +854,13 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, int x, int y, int w, int h, int xt, int yt, const float pos[2]) { - Scene *scene= painter->scene; - Brush *brush= painter->brush; + Scene *scene = painter->scene; + Brush *brush = painter->brush; ImBuf *ibuf, *maskibuf, *texibuf; - float *bf, *mf, *tf, *otf=NULL, xoff, yoff, xy[2], rgba[4]; - unsigned char *b, *m, *t, *ot= NULL; - int dotexold, origx= x, origy= y; - const int radius= BKE_brush_size_get(painter->scene, brush); + float *bf, *mf, *tf, *otf = NULL, xoff, yoff, xy[2], rgba[4]; + unsigned char *b, *m, *t, *ot = NULL; + int dotexold, origx = x, origy = y; + const int radius = BKE_brush_size_get(painter->scene, brush); xoff = -radius + 0.5f; yoff = -radius + 0.5f; @@ -880,14 +881,14 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, if (painter->cache.flt) { for (; y < h; y++) { - bf = ibuf->rect_float + (y*ibuf->x + origx)*4; - tf = texibuf->rect_float + (y*texibuf->x + origx)*4; - mf = maskibuf->rect_float + (y*maskibuf->x + origx)*4; + bf = ibuf->rect_float + (y * ibuf->x + origx) * 4; + tf = texibuf->rect_float + (y * texibuf->x + origx) * 4; + mf = maskibuf->rect_float + (y * maskibuf->x + origx) * 4; if (dotexold) - otf = oldtexibuf->rect_float + ((y - origy + yt)*oldtexibuf->x + xt)*4; + otf = oldtexibuf->rect_float + ((y - origy + yt) * oldtexibuf->x + xt) * 4; - for (x=origx; x < w; x++, bf+=4, mf+=4, tf+=4) { + for (x = origx; x < w; x++, bf += 4, mf += 4, tf += 4) { if (dotexold) { copy_v3_v3(tf, otf); tf[3] = otf[3]; @@ -900,23 +901,23 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, BKE_brush_sample_tex(scene, brush, xy, tf, 0); } - bf[0] = tf[0]*mf[0]; - bf[1] = tf[1]*mf[1]; - bf[2] = tf[2]*mf[2]; - bf[3] = tf[3]*mf[3]; + bf[0] = tf[0] * mf[0]; + bf[1] = tf[1] * mf[1]; + bf[2] = tf[2] * mf[2]; + bf[3] = tf[3] * mf[3]; } } } else { for (; y < h; y++) { - b = (unsigned char *)ibuf->rect + (y*ibuf->x + origx)*4; - t = (unsigned char *)texibuf->rect + (y*texibuf->x + origx)*4; - m = (unsigned char *)maskibuf->rect + (y*maskibuf->x + origx)*4; + b = (unsigned char *)ibuf->rect + (y * ibuf->x + origx) * 4; + t = (unsigned char *)texibuf->rect + (y * texibuf->x + origx) * 4; + m = (unsigned char *)maskibuf->rect + (y * maskibuf->x + origx) * 4; if (dotexold) - ot = (unsigned char *)oldtexibuf->rect + ((y - origy + yt)*oldtexibuf->x + xt)*4; + ot = (unsigned char *)oldtexibuf->rect + ((y - origy + yt) * oldtexibuf->x + xt) * 4; - for (x=origx; x < w; x++, b+=4, m+=4, t+=4) { + for (x = origx; x < w; x++, b += 4, m += 4, t += 4) { if (dotexold) { t[0] = ot[0]; t[1] = ot[1]; @@ -932,10 +933,10 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, rgba_float_to_uchar(t, rgba); } - b[0] = t[0]*m[0]/255; - b[1] = t[1]*m[1]/255; - b[2] = t[2]*m[2]/255; - b[3] = t[3]*m[3]/255; + b[0] = t[0] * m[0] / 255; + b[1] = t[1] * m[1] / 255; + b[2] = t[2] * m[2] / 255; + b[3] = t[3] * m[3] / 255; } } } @@ -943,40 +944,40 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, static void brush_painter_fixed_tex_partial_update(BrushPainter *painter, const float pos[2]) { - const Scene *scene= painter->scene; - Brush *brush= painter->brush; - BrushPainterCache *cache= &painter->cache; + const Scene *scene = painter->scene; + Brush *brush = painter->brush; + BrushPainterCache *cache = &painter->cache; ImBuf *oldtexibuf, *ibuf; int imbflag, destx, desty, srcx, srcy, w, h, x1, y1, x2, y2; - const int diameter= 2*BKE_brush_size_get(scene, brush); + const int diameter = 2 * BKE_brush_size_get(scene, brush); - imbflag= (cache->flt)? IB_rectfloat: IB_rect; + imbflag = (cache->flt) ? IB_rectfloat : IB_rect; if (!cache->ibuf) - cache->ibuf= IMB_allocImBuf(diameter, diameter, 32, imbflag); - ibuf= cache->ibuf; + cache->ibuf = IMB_allocImBuf(diameter, diameter, 32, imbflag); + ibuf = cache->ibuf; - oldtexibuf= cache->texibuf; - cache->texibuf= IMB_allocImBuf(diameter, diameter, 32, imbflag); + oldtexibuf = cache->texibuf; + cache->texibuf = IMB_allocImBuf(diameter, diameter, 32, imbflag); if (oldtexibuf) { - srcx= srcy= 0; - destx= (int)painter->lastpaintpos[0] - (int)pos[0]; - desty= (int)painter->lastpaintpos[1] - (int)pos[1]; - w= oldtexibuf->x; - h= oldtexibuf->y; + srcx = srcy = 0; + destx = (int)painter->lastpaintpos[0] - (int)pos[0]; + desty = (int)painter->lastpaintpos[1] - (int)pos[1]; + w = oldtexibuf->x; + h = oldtexibuf->y; IMB_rectclip(cache->texibuf, oldtexibuf, &destx, &desty, &srcx, &srcy, &w, &h); } else { - srcx= srcy= 0; - destx= desty= 0; - w= h= 0; + srcx = srcy = 0; + destx = desty = 0; + w = h = 0; } - x1= destx; - y1= desty; - x2= destx+w; - y2= desty+h; + x1 = destx; + y1 = desty; + x2 = destx + w; + y2 = desty + h; /* blend existing texture in new position */ if ((x1 < x2) && (y1 < y2)) @@ -998,30 +999,30 @@ static void brush_painter_fixed_tex_partial_update(BrushPainter *painter, const static void brush_painter_refresh_cache(BrushPainter *painter, const float pos[2], int use_color_correction) { - const Scene *scene= painter->scene; - Brush *brush= painter->brush; - BrushPainterCache *cache= &painter->cache; - MTex *mtex= &brush->mtex; + const Scene *scene = painter->scene; + Brush *brush = painter->brush; + BrushPainterCache *cache = &painter->cache; + MTex *mtex = &brush->mtex; int size; short flt; - const int diameter= 2*BKE_brush_size_get(scene, brush); - const float alpha= BKE_brush_alpha_get(scene, brush); + const int diameter = 2 * BKE_brush_size_get(scene, brush); + const float alpha = BKE_brush_alpha_get(scene, brush); if (diameter != cache->lastsize || - alpha != cache->lastalpha || - brush->jitter != cache->lastjitter) + alpha != cache->lastalpha || + brush->jitter != cache->lastjitter) { if (cache->ibuf) { IMB_freeImBuf(cache->ibuf); - cache->ibuf= NULL; + cache->ibuf = NULL; } if (cache->maskibuf) { IMB_freeImBuf(cache->maskibuf); - cache->maskibuf= NULL; + cache->maskibuf = NULL; } - flt= cache->flt; - size= (cache->size)? cache->size: diameter; + flt = cache->flt; + size = (cache->size) ? cache->size : diameter; if (brush->flag & BRUSH_FIXED_TEX) { BKE_brush_imbuf_new(scene, brush, flt, 3, size, &cache->maskibuf, use_color_correction); @@ -1030,9 +1031,9 @@ static void brush_painter_refresh_cache(BrushPainter *painter, const float pos[2 else BKE_brush_imbuf_new(scene, brush, flt, 2, size, &cache->ibuf, use_color_correction); - cache->lastsize= diameter; - cache->lastalpha= alpha; - cache->lastjitter= brush->jitter; + cache->lastsize = diameter; + cache->lastalpha = alpha; + cache->lastjitter = brush->jitter; } else if ((brush->flag & BRUSH_FIXED_TEX) && mtex && mtex->tex) { int dx = (int)painter->lastpaintpos[0] - (int)pos[0]; @@ -1045,42 +1046,42 @@ static void brush_painter_refresh_cache(BrushPainter *painter, const float pos[2 void BKE_brush_painter_break_stroke(BrushPainter *painter) { - painter->firsttouch= 1; + painter->firsttouch = 1; } static void brush_pressure_apply(BrushPainter *painter, Brush *brush, float pressure) { if (BKE_brush_use_alpha_pressure(painter->scene, brush)) - brush_alpha_set(painter->scene, brush, MAX2(0.0f, painter->startalpha*pressure)); + brush_alpha_set(painter->scene, brush, MAX2(0.0f, painter->startalpha * pressure)); if (BKE_brush_use_size_pressure(painter->scene, brush)) - BKE_brush_size_set(painter->scene, brush, MAX2(1.0f, painter->startsize*pressure)); + BKE_brush_size_set(painter->scene, brush, MAX2(1.0f, painter->startsize * pressure)); if (brush->flag & BRUSH_JITTER_PRESSURE) - brush->jitter = MAX2(0.0f, painter->startjitter*pressure); + brush->jitter = MAX2(0.0f, painter->startjitter * pressure); if (brush->flag & BRUSH_SPACING_PRESSURE) - brush->spacing = MAX2(1.0f, painter->startspacing*(1.5f-pressure)); + brush->spacing = MAX2(1.0f, painter->startspacing * (1.5f - pressure)); } void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], float jitterpos[2]) { - int use_jitter= brush->jitter != 0; + int use_jitter = brush->jitter != 0; /* jitter-ed brush gives weird and unpredictable result for this * kinds of stroke, so manyally disable jitter usage (sergey) */ - use_jitter &= (brush->flag & (BRUSH_RESTORE_MESH|BRUSH_ANCHORED)) == 0; + use_jitter &= (brush->flag & (BRUSH_RESTORE_MESH | BRUSH_ANCHORED)) == 0; if (use_jitter) { float rand_pos[2]; - const int radius= BKE_brush_size_get(scene, brush); - const int diameter= 2*radius; + const int radius = BKE_brush_size_get(scene, brush); + const int diameter = 2 * radius; // find random position within a circle of diameter 1 do { - rand_pos[0] = BLI_frand()-0.5f; - rand_pos[1] = BLI_frand()-0.5f; + rand_pos[0] = BLI_frand() - 0.5f; + rand_pos[1] = BLI_frand() - 0.5f; } while (len_v2(rand_pos) > 0.5f); - jitterpos[0] = pos[0] + 2*rand_pos[0]*diameter*brush->jitter; - jitterpos[1] = pos[1] + 2*rand_pos[1]*diameter*brush->jitter; + jitterpos[0] = pos[0] + 2 * rand_pos[0] * diameter * brush->jitter; + jitterpos[1] = pos[1] + 2 * rand_pos[1] * diameter * brush->jitter; } else { copy_v2_v2(jitterpos, pos); @@ -1090,92 +1091,92 @@ void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2], double time, float pressure, void *user, int use_color_correction) { - Scene *scene= painter->scene; - Brush *brush= painter->brush; - int totpaintops= 0; + Scene *scene = painter->scene; + Brush *brush = painter->brush; + int totpaintops = 0; if (pressure == 0.0f) { if (painter->lastpressure) // XXX - hack, operator misses - pressure= painter->lastpressure; + pressure = painter->lastpressure; else - pressure = 1.0f; /* zero pressure == not using tablet */ + pressure = 1.0f; /* zero pressure == not using tablet */ } if (painter->firsttouch) { /* paint exactly once on first touch */ - painter->startpaintpos[0]= pos[0]; - painter->startpaintpos[1]= pos[1]; + painter->startpaintpos[0] = pos[0]; + painter->startpaintpos[1] = pos[1]; brush_pressure_apply(painter, brush, pressure); if (painter->cache.enabled) brush_painter_refresh_cache(painter, pos, use_color_correction); totpaintops += func(user, painter->cache.ibuf, pos, pos); - painter->lasttime= time; - painter->firsttouch= 0; - painter->lastpaintpos[0]= pos[0]; - painter->lastpaintpos[1]= pos[1]; + painter->lasttime = time; + painter->firsttouch = 0; + painter->lastpaintpos[0] = pos[0]; + painter->lastpaintpos[1] = pos[1]; } #if 0 else if (painter->brush->flag & BRUSH_AIRBRUSH) { float spacing, step, paintpos[2], dmousepos[2], len; - double starttime, curtime= time; + double starttime, curtime = time; /* compute brush spacing adapted to brush size */ - spacing= brush->rate; //radius*brush->spacing*0.01f; + spacing = brush->rate; //radius*brush->spacing*0.01f; /* setup starting time, direction vector and accumulated time */ - starttime= painter->accumtime; + starttime = painter->accumtime; sub_v2_v2v2(dmousepos, pos, painter->lastmousepos); - len= normalize_v2(dmousepos); + len = normalize_v2(dmousepos); painter->accumtime += curtime - painter->lasttime; /* do paint op over unpainted time distance */ while (painter->accumtime >= spacing) { - step= (spacing - starttime)*len; - paintpos[0]= painter->lastmousepos[0] + dmousepos[0]*step; - paintpos[1]= painter->lastmousepos[1] + dmousepos[1]*step; + step = (spacing - starttime) * len; + paintpos[0] = painter->lastmousepos[0] + dmousepos[0] * step; + paintpos[1] = painter->lastmousepos[1] + dmousepos[1] * step; if (painter->cache.enabled) brush_painter_refresh_cache(painter); totpaintops += func(user, painter->cache.ibuf, - painter->lastpaintpos, paintpos); + painter->lastpaintpos, paintpos); - painter->lastpaintpos[0]= paintpos[0]; - painter->lastpaintpos[1]= paintpos[1]; + painter->lastpaintpos[0] = paintpos[0]; + painter->lastpaintpos[1] = paintpos[1]; painter->accumtime -= spacing; starttime -= spacing; } - painter->lasttime= curtime; + painter->lasttime = curtime; } #endif else { float startdistance, spacing, step, paintpos[2], dmousepos[2], finalpos[2]; float t, len, press; - const int radius= BKE_brush_size_get(scene, brush); + const int radius = BKE_brush_size_get(scene, brush); /* compute brush spacing adapted to brush radius, spacing may depend * on pressure, so update it */ brush_pressure_apply(painter, brush, painter->lastpressure); - spacing= MAX2(1.0f, radius)*brush->spacing*0.01f; + spacing = MAX2(1.0f, radius) * brush->spacing * 0.01f; /* setup starting distance, direction vector and accumulated distance */ - startdistance= painter->accumdistance; + startdistance = painter->accumdistance; sub_v2_v2v2(dmousepos, pos, painter->lastmousepos); - len= normalize_v2(dmousepos); + len = normalize_v2(dmousepos); painter->accumdistance += len; if (brush->flag & BRUSH_SPACE) { /* do paint op over unpainted distance */ while ((len > 0.0f) && (painter->accumdistance >= spacing)) { - step= spacing - startdistance; - paintpos[0]= painter->lastmousepos[0] + dmousepos[0]*step; - paintpos[1]= painter->lastmousepos[1] + dmousepos[1]*step; + step = spacing - startdistance; + paintpos[0] = painter->lastmousepos[0] + dmousepos[0] * step; + paintpos[1] = painter->lastmousepos[1] + dmousepos[1] * step; - t = step/len; - press= (1.0f-t)*painter->lastpressure + t*pressure; + t = step / len; + press = (1.0f - t) * painter->lastpressure + t * pressure; brush_pressure_apply(painter, brush, press); - spacing= MAX2(1.0f, radius)*brush->spacing*0.01f; + spacing = MAX2(1.0f, radius) * brush->spacing * 0.01f; BKE_brush_jitter_pos(scene, brush, paintpos, finalpos); @@ -1183,10 +1184,10 @@ int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float p brush_painter_refresh_cache(painter, finalpos, use_color_correction); totpaintops += - func(user, painter->cache.ibuf, painter->lastpaintpos, finalpos); + func(user, painter->cache.ibuf, painter->lastpaintpos, finalpos); - painter->lastpaintpos[0]= paintpos[0]; - painter->lastpaintpos[1]= paintpos[1]; + painter->lastpaintpos[0] = paintpos[0]; + painter->lastpaintpos[1] = paintpos[1]; painter->accumdistance -= spacing; startdistance -= spacing; } @@ -1199,21 +1200,21 @@ int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float p totpaintops += func(user, painter->cache.ibuf, pos, finalpos); - painter->lastpaintpos[0]= pos[0]; - painter->lastpaintpos[1]= pos[1]; - painter->accumdistance= 0; + painter->lastpaintpos[0] = pos[0]; + painter->lastpaintpos[1] = pos[1]; + painter->accumdistance = 0; } /* do airbrush paint ops, based on the number of paint ops left over * from regular painting. this is a temporary solution until we have * accurate time stamps for mouse move events */ if (brush->flag & BRUSH_AIRBRUSH) { - double curtime= time; - double painttime= brush->rate*totpaintops; + double curtime = time; + double painttime = brush->rate * totpaintops; painter->accumtime += curtime - painter->lasttime; if (painter->accumtime <= painttime) - painter->accumtime= 0.0; + painter->accumtime = 0.0; else painter->accumtime -= painttime; @@ -1226,17 +1227,17 @@ int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float p brush_painter_refresh_cache(painter, finalpos, use_color_correction); totpaintops += - func(user, painter->cache.ibuf, painter->lastmousepos, finalpos); + func(user, painter->cache.ibuf, painter->lastmousepos, finalpos); painter->accumtime -= (double)brush->rate; } - painter->lasttime= curtime; + painter->lasttime = curtime; } } - painter->lastmousepos[0]= pos[0]; - painter->lastmousepos[1]= pos[1]; - painter->lastpressure= pressure; + painter->lastmousepos[0] = pos[0]; + painter->lastmousepos[1] = pos[1]; + painter->lastpressure = pressure; brush_alpha_set(scene, brush, painter->startalpha); BKE_brush_size_set(scene, brush, painter->startsize); @@ -1249,12 +1250,12 @@ int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float p /* Uses the brush curve control to find a strength value between 0 and 1 */ float BKE_brush_curve_strength_clamp(Brush *br, float p, const float len) { - if (p >= len) return 0; - else p= p/len; + if (p >= len) return 0; + else p = p / len; - p= curvemapping_evaluateF(br->curve, 0, p); - if (p < 0.0f) p= 0.0f; - else if (p > 1.0f) p= 1.0f; + p = curvemapping_evaluateF(br->curve, 0, p); + if (p < 0.0f) p = 0.0f; + else if (p > 1.0f) p = 1.0f; return p; } /* same as above but can return negative values if the curve enables @@ -1262,9 +1263,9 @@ float BKE_brush_curve_strength_clamp(Brush *br, float p, const float len) float BKE_brush_curve_strength(Brush *br, float p, const float len) { if (p >= len) - p= 1.0f; + p = 1.0f; else - p= p/len; + p = p / len; return curvemapping_evaluateF(br->curve, 0, p); } @@ -1274,7 +1275,7 @@ unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side) { unsigned int *texcache = NULL; MTex *mtex = &br->mtex; - TexResult texres= {0}; + TexResult texres = {0}; int hasrgb, ix, iy; int side = half_side * 2; @@ -1286,11 +1287,11 @@ unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side) BKE_image_get_ibuf(mtex->tex->ima, NULL); /*do normalized cannonical view coords for texture*/ - for (y=-1.0, iy=0; iy<side; iy++, y += step) { - for (x=-1.0, ix=0; ix<side; ix++, x += step) { - co[0]= x; - co[1]= y; - co[2]= 0.0f; + for (y = -1.0, iy = 0; iy < side; iy++, y += step) { + for (x = -1.0, ix = 0; ix < side; ix++, x += step) { + co[0] = x; + co[1] = y; + co[2] = 0.0f; /* This is copied from displace modifier code */ hasrgb = multitex_ext(mtex->tex, co, NULL, NULL, 0, &texres); @@ -1301,13 +1302,13 @@ unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side) */ if (hasrgb & TEX_RGB) texres.tin = (0.35f * texres.tr + 0.45f * - texres.tg + 0.2f * texres.tb); + texres.tg + 0.2f * texres.tb); texres.tin = texres.tin * 255.0f; - ((char*)texcache)[(iy*side+ix)*4] = (char)texres.tin; - ((char*)texcache)[(iy*side+ix)*4+1] = (char)texres.tin; - ((char*)texcache)[(iy*side+ix)*4+2] = (char)texres.tin; - ((char*)texcache)[(iy*side+ix)*4+3] = (char)texres.tin; + ((char *)texcache)[(iy * side + ix) * 4] = (char)texres.tin; + ((char *)texcache)[(iy * side + ix) * 4 + 1] = (char)texres.tin; + ((char *)texcache)[(iy * side + ix) * 4 + 2] = (char)texres.tin; + ((char *)texcache)[(iy * side + ix) * 4 + 3] = (char)texres.tin; } } } @@ -1328,19 +1329,19 @@ struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br) im->rect_float = MEM_callocN(sizeof(float) * side * side, "radial control rect"); im->x = im->y = side; - for (i=0; i<side; ++i) { - for (j=0; j<side; ++j) { - float magn= sqrt(pow(i - half, 2) + pow(j - half, 2)); - im->rect_float[i*side + j]= BKE_brush_curve_strength_clamp(br, magn, half); + for (i = 0; i < side; ++i) { + for (j = 0; j < side; ++j) { + float magn = sqrt(pow(i - half, 2) + pow(j - half, 2)); + im->rect_float[i * side + j] = BKE_brush_curve_strength_clamp(br, magn, half); } } /* Modulate curve with texture */ if (texcache) { - for (i=0; i<side; ++i) { - for (j=0; j<side; ++j) { - const int col= texcache[i*side+j]; - im->rect_float[i*side+j]*= (((char*)&col)[0]+((char*)&col)[1]+((char*)&col)[2])/3.0f/255.0f; + for (i = 0; i < side; ++i) { + for (j = 0; j < side; ++j) { + const int col = texcache[i * side + j]; + im->rect_float[i * side + j] *= (((char *)&col)[0] + ((char *)&col)[1] + ((char *)&col)[2]) / 3.0f / 255.0f; } } diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index efede6bbae7..e1cfcee1367 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -54,15 +54,15 @@ void *BKE_camera_add(const char *name) { Camera *cam; - cam= BKE_libblock_alloc(&G.main->camera, ID_CA, name); - - cam->lens= 35.0f; - cam->sensor_x= 32.0f; - cam->sensor_y= 18.0f; - cam->clipsta= 0.1f; - cam->clipend= 100.0f; - cam->drawsize= 0.5f; - cam->ortho_scale= 6.0; + cam = BKE_libblock_alloc(&G.main->camera, ID_CA, name); + + cam->lens = 35.0f; + cam->sensor_x = 32.0f; + cam->sensor_y = 18.0f; + cam->clipsta = 0.1f; + cam->clipend = 100.0f; + cam->drawsize = 0.5f; + cam->ortho_scale = 6.0; cam->flag |= CAM_SHOWPASSEPARTOUT; cam->passepartalpha = 0.5f; @@ -73,7 +73,7 @@ Camera *BKE_camera_copy(Camera *cam) { Camera *camn; - camn= BKE_libblock_copy(&cam->id); + camn = BKE_libblock_copy(&cam->id); id_lib_extern((ID *)camn->dof_ob); @@ -82,25 +82,25 @@ Camera *BKE_camera_copy(Camera *cam) void BKE_camera_make_local(Camera *cam) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (cam->id.lib==NULL) return; - if (cam->id.us==1) { + if (cam->id.lib == NULL) return; + if (cam->id.us == 1) { id_clear_lib_data(bmain, &cam->id); return; } - for (ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) { - if (ob->data==cam) { - if (ob->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (ob = bmain->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) { + if (ob->data == cam) { + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } @@ -108,17 +108,17 @@ void BKE_camera_make_local(Camera *cam) id_clear_lib_data(bmain, &cam->id); } else if (is_local && is_lib) { - Camera *cam_new= BKE_camera_copy(cam); + Camera *cam_new = BKE_camera_copy(cam); - cam_new->id.us= 0; + cam_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, cam->id.lib, &cam_new->id); - for (ob= bmain->object.first; ob; ob= ob->id.next) { + for (ob = bmain->object.first; ob; ob = ob->id.next) { if (ob->data == cam) { - if (ob->id.lib==NULL) { - ob->data= cam_new; + if (ob->id.lib == NULL) { + ob->data = cam_new; cam_new->id.us++; cam->id.us--; } @@ -136,10 +136,10 @@ void BKE_camera_free(Camera *ca) void BKE_camera_object_mode(RenderData *rd, Object *cam_ob) { - rd->mode &= ~(R_ORTHO|R_PANORAMA); + rd->mode &= ~(R_ORTHO | R_PANORAMA); - if (cam_ob && cam_ob->type==OB_CAMERA) { - Camera *cam= cam_ob->data; + if (cam_ob && cam_ob->type == OB_CAMERA) { + Camera *cam = cam_ob->data; if (cam->type == CAM_ORTHO) rd->mode |= R_ORTHO; if (cam->type == CAM_PANO) rd->mode |= R_PANORAMA; } @@ -193,11 +193,11 @@ void BKE_camera_params_init(CameraParams *params) memset(params, 0, sizeof(CameraParams)); /* defaults */ - params->sensor_x= DEFAULT_SENSOR_WIDTH; - params->sensor_y= DEFAULT_SENSOR_HEIGHT; - params->sensor_fit= CAMERA_SENSOR_FIT_AUTO; + params->sensor_x = DEFAULT_SENSOR_WIDTH; + params->sensor_y = DEFAULT_SENSOR_HEIGHT; + params->sensor_fit = CAMERA_SENSOR_FIT_AUTO; - params->zoom= 1.0f; + params->zoom = 1.0f; } void BKE_camera_params_from_object(CameraParams *params, Object *ob) @@ -205,73 +205,73 @@ void BKE_camera_params_from_object(CameraParams *params, Object *ob) if (!ob) return; - if (ob->type==OB_CAMERA) { + if (ob->type == OB_CAMERA) { /* camera object */ - Camera *cam= ob->data; + Camera *cam = ob->data; if (cam->type == CAM_ORTHO) - params->is_ortho= TRUE; - params->lens= cam->lens; - params->ortho_scale= cam->ortho_scale; + params->is_ortho = TRUE; + params->lens = cam->lens; + params->ortho_scale = cam->ortho_scale; - params->shiftx= cam->shiftx; - params->shifty= cam->shifty; + params->shiftx = cam->shiftx; + params->shifty = cam->shifty; - params->sensor_x= cam->sensor_x; - params->sensor_y= cam->sensor_y; - params->sensor_fit= cam->sensor_fit; + params->sensor_x = cam->sensor_x; + params->sensor_y = cam->sensor_y; + params->sensor_fit = cam->sensor_fit; - params->clipsta= cam->clipsta; - params->clipend= cam->clipend; + params->clipsta = cam->clipsta; + params->clipend = cam->clipend; } - else if (ob->type==OB_LAMP) { + else if (ob->type == OB_LAMP) { /* lamp object */ - Lamp *la= ob->data; - float fac= cosf((float)M_PI*la->spotsize/360.0f); - float phi= acos(fac); + Lamp *la = ob->data; + float fac = cosf((float)M_PI * la->spotsize / 360.0f); + float phi = acos(fac); - params->lens= 16.0f*fac/sinf(phi); - if (params->lens==0.0f) - params->lens= 35.0f; + params->lens = 16.0f * fac / sinf(phi); + if (params->lens == 0.0f) + params->lens = 35.0f; - params->clipsta= la->clipsta; - params->clipend= la->clipend; + params->clipsta = la->clipsta; + params->clipend = la->clipend; } } void BKE_camera_params_from_view3d(CameraParams *params, View3D *v3d, RegionView3D *rv3d) { /* common */ - params->lens= v3d->lens; - params->clipsta= v3d->near; - params->clipend= v3d->far; + params->lens = v3d->lens; + params->clipsta = v3d->near; + params->clipend = v3d->far; - if (rv3d->persp==RV3D_CAMOB) { + if (rv3d->persp == RV3D_CAMOB) { /* camera view */ BKE_camera_params_from_object(params, v3d->camera); - params->zoom= BKE_screen_view3d_zoom_to_fac((float)rv3d->camzoom); + params->zoom = BKE_screen_view3d_zoom_to_fac((float)rv3d->camzoom); - params->offsetx= 2.0f*rv3d->camdx*params->zoom; - params->offsety= 2.0f*rv3d->camdy*params->zoom; + params->offsetx = 2.0f * rv3d->camdx * params->zoom; + params->offsety = 2.0f * rv3d->camdy * params->zoom; params->shiftx *= params->zoom; params->shifty *= params->zoom; - params->zoom= 1.0f/params->zoom; + params->zoom = 1.0f / params->zoom; } - else if (rv3d->persp==RV3D_ORTHO) { + else if (rv3d->persp == RV3D_ORTHO) { /* orthographic view */ - params->clipend *= 0.5f; // otherwise too extreme low zbuffer quality - params->clipsta= - params->clipend; + params->clipend *= 0.5f; // otherwise too extreme low zbuffer quality + params->clipsta = -params->clipend; - params->is_ortho= TRUE; + params->is_ortho = TRUE; params->ortho_scale = rv3d->dist; - params->zoom= 2.0f; + params->zoom = 2.0f; } else { /* perspective view */ - params->zoom= 2.0f; + params->zoom = 2.0f; } } @@ -282,28 +282,28 @@ void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int win int sensor_fit; /* fields rendering */ - params->ycor= yasp/xasp; + params->ycor = yasp / xasp; if (params->use_fields) params->ycor *= 2.0f; if (params->is_ortho) { /* orthographic camera */ /* scale == 1.0 means exact 1 to 1 mapping */ - pixsize= params->ortho_scale; + pixsize = params->ortho_scale; } else { /* perspective camera */ - sensor_size= BKE_camera_sensor_size(params->sensor_fit, params->sensor_x, params->sensor_y); - pixsize= (sensor_size * params->clipsta)/params->lens; + sensor_size = BKE_camera_sensor_size(params->sensor_fit, params->sensor_x, params->sensor_y); + pixsize = (sensor_size * params->clipsta) / params->lens; } /* determine sensor fit */ - sensor_fit = BKE_camera_sensor_fit(params->sensor_fit, xasp*winx, yasp*winy); + sensor_fit = BKE_camera_sensor_fit(params->sensor_fit, xasp * winx, yasp * winy); - if (sensor_fit==CAMERA_SENSOR_FIT_HOR) - viewfac= winx; + if (sensor_fit == CAMERA_SENSOR_FIT_HOR) + viewfac = winx; else - viewfac= params->ycor * winy; + viewfac = params->ycor * winy; pixsize /= viewfac; @@ -312,14 +312,14 @@ void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int win /* compute view plane: * fully centered, zbuffer fills in jittered between -.5 and +.5 */ - viewplane.xmin = -0.5f*(float)winx; - viewplane.ymin = -0.5f*params->ycor*(float)winy; - viewplane.xmax = 0.5f*(float)winx; - viewplane.ymax = 0.5f*params->ycor*(float)winy; + viewplane.xmin = -0.5f * (float)winx; + viewplane.ymin = -0.5f * params->ycor * (float)winy; + viewplane.xmax = 0.5f * (float)winx; + viewplane.ymax = 0.5f * params->ycor * (float)winy; /* lens shift and offset */ - dx= params->shiftx*viewfac + winx*params->offsetx; - dy= params->shifty*viewfac + winy*params->offsety; + dx = params->shiftx * viewfac + winx * params->offsetx; + dy = params->shifty * viewfac + winy * params->offsety; viewplane.xmin += dx; viewplane.ymin += dy; @@ -329,12 +329,12 @@ void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int win /* fields offset */ if (params->field_second) { if (params->field_odd) { - viewplane.ymin-= 0.5f * params->ycor; - viewplane.ymax-= 0.5f * params->ycor; + viewplane.ymin -= 0.5f * params->ycor; + viewplane.ymax -= 0.5f * params->ycor; } else { - viewplane.ymin+= 0.5f * params->ycor; - viewplane.ymax+= 0.5f * params->ycor; + viewplane.ymin += 0.5f * params->ycor; + viewplane.ymax += 0.5f * params->ycor; } } @@ -345,9 +345,9 @@ void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int win viewplane.ymin *= pixsize; viewplane.ymax *= pixsize; - params->viewdx= pixsize; - params->viewdy= params->ycor * pixsize; - params->viewplane= viewplane; + params->viewdx = pixsize; + params->viewdy = params->ycor * pixsize; + params->viewplane = viewplane; } /* viewplane is assumed to be already computed */ @@ -374,61 +374,61 @@ void BKE_camera_view_frame_ex(Scene *scene, Camera *camera, float drawsize, cons /* aspect correcton */ if (scene) { - float aspx= (float) scene->r.xsch*scene->r.xasp; - float aspy= (float) scene->r.ysch*scene->r.yasp; - int sensor_fit= BKE_camera_sensor_fit(camera->sensor_fit, aspx, aspy); + float aspx = (float) scene->r.xsch * scene->r.xasp; + float aspy = (float) scene->r.ysch * scene->r.yasp; + int sensor_fit = BKE_camera_sensor_fit(camera->sensor_fit, aspx, aspy); - if (sensor_fit==CAMERA_SENSOR_FIT_HOR) { - r_asp[0]= 1.0; - r_asp[1]= aspy / aspx; + if (sensor_fit == CAMERA_SENSOR_FIT_HOR) { + r_asp[0] = 1.0; + r_asp[1] = aspy / aspx; } else { - r_asp[0]= aspx / aspy; - r_asp[1]= 1.0; + r_asp[0] = aspx / aspy; + r_asp[1] = 1.0; } } else { - r_asp[0]= 1.0f; - r_asp[1]= 1.0f; + r_asp[0] = 1.0f; + r_asp[1] = 1.0f; } - if (camera->type==CAM_ORTHO) { - facx= 0.5f * camera->ortho_scale * r_asp[0] * scale[0]; - facy= 0.5f * camera->ortho_scale * r_asp[1] * scale[1]; - r_shift[0]= camera->shiftx * camera->ortho_scale * scale[0]; - r_shift[1]= camera->shifty * camera->ortho_scale * scale[1]; - depth= do_clip ? -((camera->clipsta * scale[2]) + 0.1f) : - drawsize * camera->ortho_scale * scale[2]; + if (camera->type == CAM_ORTHO) { + facx = 0.5f * camera->ortho_scale * r_asp[0] * scale[0]; + facy = 0.5f * camera->ortho_scale * r_asp[1] * scale[1]; + r_shift[0] = camera->shiftx * camera->ortho_scale * scale[0]; + r_shift[1] = camera->shifty * camera->ortho_scale * scale[1]; + depth = do_clip ? -((camera->clipsta * scale[2]) + 0.1f) : -drawsize * camera->ortho_scale * scale[2]; - *r_drawsize= 0.5f * camera->ortho_scale; + *r_drawsize = 0.5f * camera->ortho_scale; } else { /* that way it's always visible - clipsta+0.1 */ float fac; - float half_sensor= 0.5f*((camera->sensor_fit==CAMERA_SENSOR_FIT_VERT) ? (camera->sensor_y) : (camera->sensor_x)); + float half_sensor = 0.5f * ((camera->sensor_fit == CAMERA_SENSOR_FIT_VERT) ? (camera->sensor_y) : (camera->sensor_x)); - *r_drawsize= drawsize / ((scale[0] + scale[1] + scale[2]) / 3.0f); + *r_drawsize = drawsize / ((scale[0] + scale[1] + scale[2]) / 3.0f); if (do_clip) { /* fixed depth, variable size (avoids exceeding clipping range) */ depth = -(camera->clipsta + 0.1f); - fac = depth / (camera->lens/(-half_sensor) * scale[2]); + fac = depth / (camera->lens / (-half_sensor) * scale[2]); } else { /* fixed size, variable depth (stays a reasonable size in the 3D view) */ - depth= *r_drawsize * camera->lens/(-half_sensor) * scale[2]; - fac= *r_drawsize; + depth = *r_drawsize * camera->lens / (-half_sensor) * scale[2]; + fac = *r_drawsize; } - facx= fac * r_asp[0] * scale[0]; - facy= fac * r_asp[1] * scale[1]; - r_shift[0]= camera->shiftx*fac*2 * scale[0]; - r_shift[1]= camera->shifty*fac*2 * scale[1]; + facx = fac * r_asp[0] * scale[0]; + facy = fac * r_asp[1] * scale[1]; + r_shift[0] = camera->shiftx * fac * 2 * scale[0]; + r_shift[1] = camera->shifty * fac * 2 * scale[1]; } - r_vec[0][0]= r_shift[0] + facx; r_vec[0][1]= r_shift[1] + facy; r_vec[0][2]= depth; - r_vec[1][0]= r_shift[0] + facx; r_vec[1][1]= r_shift[1] - facy; r_vec[1][2]= depth; - r_vec[2][0]= r_shift[0] - facx; r_vec[2][1]= r_shift[1] - facy; r_vec[2][2]= depth; - r_vec[3][0]= r_shift[0] - facx; r_vec[3][1]= r_shift[1] + facy; r_vec[3][2]= depth; + r_vec[0][0] = r_shift[0] + facx; r_vec[0][1] = r_shift[1] + facy; r_vec[0][2] = depth; + r_vec[1][0] = r_shift[0] + facx; r_vec[1][1] = r_shift[1] - facy; r_vec[1][2] = depth; + r_vec[2][0] = r_shift[0] - facx; r_vec[2][1] = r_shift[1] - facy; r_vec[2][2] = depth; + r_vec[3][0] = r_shift[0] - facx; r_vec[3][1] = r_shift[1] + facy; r_vec[3][2] = depth; } void BKE_camera_view_frame(Scene *scene, Camera *camera, float r_vec[4][3]) @@ -436,10 +436,10 @@ void BKE_camera_view_frame(Scene *scene, Camera *camera, float r_vec[4][3]) float dummy_asp[2]; float dummy_shift[2]; float dummy_drawsize; - const float dummy_scale[3]= {1.0f, 1.0f, 1.0f}; + const float dummy_scale[3] = {1.0f, 1.0f, 1.0f}; BKE_camera_view_frame_ex(scene, camera, FALSE, 1.0, dummy_scale, - dummy_asp, dummy_shift, &dummy_drawsize, r_vec); + dummy_asp, dummy_shift, &dummy_drawsize, r_vec); } @@ -452,13 +452,13 @@ typedef struct CameraViewFrameData { static void BKE_camera_to_frame_view_cb(const float co[3], void *user_data) { - CameraViewFrameData *data= (CameraViewFrameData *)user_data; + CameraViewFrameData *data = (CameraViewFrameData *)user_data; unsigned int i; - for (i= 0; i < 4; i++) { - float nd= dist_to_plane_v3(co, data->frame_tx[i], data->normal_tx[i]); + for (i = 0; i < 4; i++) { + float nd = dist_to_plane_v3(co, data->frame_tx[i], data->normal_tx[i]); if (nd < data->dist_vals[i]) { - data->dist_vals[i]= nd; + data->dist_vals[i] = nd; } } @@ -472,7 +472,7 @@ int BKE_camera_view_frame_fit_to_scene(Scene *scene, struct View3D *v3d, Object float shift[2]; float plane_tx[4][3]; float rot_obmat[3][3]; - const float zero[3]= {0, 0, 0}; + const float zero[3] = {0, 0, 0}; CameraViewFrameData data_cb; unsigned int i; @@ -482,36 +482,36 @@ int BKE_camera_view_frame_fit_to_scene(Scene *scene, struct View3D *v3d, Object copy_m3_m4(rot_obmat, camera_ob->obmat); normalize_m3(rot_obmat); - for (i= 0; i < 4; i++) { + for (i = 0; i < 4; i++) { /* normalize so Z is always 1.0f*/ - mul_v3_fl(data_cb.frame_tx[i], 1.0f/data_cb.frame_tx[i][2]); + mul_v3_fl(data_cb.frame_tx[i], 1.0f / data_cb.frame_tx[i][2]); } /* get the shift back out of the frame */ - shift[0]= (data_cb.frame_tx[0][0] + - data_cb.frame_tx[1][0] + - data_cb.frame_tx[2][0] + - data_cb.frame_tx[3][0]) / 4.0f; - shift[1]= (data_cb.frame_tx[0][1] + - data_cb.frame_tx[1][1] + - data_cb.frame_tx[2][1] + - data_cb.frame_tx[3][1]) / 4.0f; - - for (i= 0; i < 4; i++) { + shift[0] = (data_cb.frame_tx[0][0] + + data_cb.frame_tx[1][0] + + data_cb.frame_tx[2][0] + + data_cb.frame_tx[3][0]) / 4.0f; + shift[1] = (data_cb.frame_tx[0][1] + + data_cb.frame_tx[1][1] + + data_cb.frame_tx[2][1] + + data_cb.frame_tx[3][1]) / 4.0f; + + for (i = 0; i < 4; i++) { mul_m3_v3(rot_obmat, data_cb.frame_tx[i]); } - for (i= 0; i < 4; i++) { + for (i = 0; i < 4; i++) { normal_tri_v3(data_cb.normal_tx[i], zero, data_cb.frame_tx[i], data_cb.frame_tx[(i + 1) % 4]); } /* initialize callback data */ - data_cb.dist_vals[0]= - data_cb.dist_vals[1]= - data_cb.dist_vals[2]= - data_cb.dist_vals[3]= FLT_MAX; - data_cb.tot= 0; + data_cb.dist_vals[0] = + data_cb.dist_vals[1] = + data_cb.dist_vals[2] = + data_cb.dist_vals[3] = FLT_MAX; + data_cb.tot = 0; /* run callback on all visible points */ BKE_scene_foreach_display_point(scene, v3d, BA_SELECT, BKE_camera_to_frame_view_cb, &data_cb); @@ -526,7 +526,7 @@ int BKE_camera_view_frame_fit_to_scene(Scene *scene, struct View3D *v3d, Object float plane_isect_pt_1[3], plane_isect_pt_2[3]; /* apply the dist-from-plane's to the transformed plane points */ - for (i= 0; i < 4; i++) { + for (i = 0; i < 4; i++) { mul_v3_v3fl(plane_tx[i], data_cb.normal_tx[i], data_cb.dist_vals[i]); } @@ -547,14 +547,14 @@ int BKE_camera_view_frame_fit_to_scene(Scene *scene, struct View3D *v3d, Object return FALSE; } else { - float cam_plane_no[3]= {0.0f, 0.0f, -1.0f}; + float cam_plane_no[3] = {0.0f, 0.0f, -1.0f}; float plane_isect_delta[3]; float plane_isect_delta_len; mul_m3_v3(rot_obmat, cam_plane_no); sub_v3_v3v3(plane_isect_delta, plane_isect_pt_2, plane_isect_pt_1); - plane_isect_delta_len= len_v3(plane_isect_delta); + plane_isect_delta_len = len_v3(plane_isect_delta); if (dot_v3v3(plane_isect_delta, cam_plane_no) > 0.0f) { copy_v3_v3(r_co, plane_isect_pt_1); diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 0f12b79e05d..190d9f654f6 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -74,31 +74,31 @@ void BKE_curve_unlink(Curve *cu) { int a; - for (a=0; a<cu->totcol; a++) { + for (a = 0; a < cu->totcol; a++) { if (cu->mat[a]) cu->mat[a]->id.us--; - cu->mat[a]= NULL; + cu->mat[a] = NULL; } if (cu->vfont) cu->vfont->id.us--; - cu->vfont= NULL; + cu->vfont = NULL; if (cu->vfontb) cu->vfontb->id.us--; - cu->vfontb= NULL; + cu->vfontb = NULL; if (cu->vfonti) cu->vfonti->id.us--; - cu->vfonti= NULL; + cu->vfonti = NULL; if (cu->vfontbi) cu->vfontbi->id.us--; - cu->vfontbi= NULL; + cu->vfontbi = NULL; if (cu->key) cu->key->id.us--; - cu->key= NULL; + cu->key = NULL; } /* frees editcurve entirely */ void BKE_curve_editfont_free(Curve *cu) { if (cu->editfont) { - EditFont *ef= cu->editfont; + EditFont *ef = cu->editfont; if (ef->oldstr) MEM_freeN(ef->oldstr); if (ef->oldstrinfo) MEM_freeN(ef->oldstrinfo); @@ -108,7 +108,7 @@ void BKE_curve_editfont_free(Curve *cu) if (ef->copybufinfo) MEM_freeN(ef->copybufinfo); MEM_freeN(ef); - cu->editfont= NULL; + cu->editfont = NULL; } } @@ -118,7 +118,7 @@ void BKE_curve_editNurb_keyIndex_free(EditNurb *editnurb) return; } BLI_ghash_free(editnurb->keyindex, NULL, (GHashValFreeFP)MEM_freeN); - editnurb->keyindex= NULL; + editnurb->keyindex = NULL; } void BKE_curve_editNurb_free(Curve *cu) @@ -127,7 +127,7 @@ void BKE_curve_editNurb_free(Curve *cu) BKE_nurbList_free(&cu->editnurb->nurbs); BKE_curve_editNurb_keyIndex_free(cu->editnurb); MEM_freeN(cu->editnurb); - cu->editnurb= NULL; + cu->editnurb = NULL; } } @@ -157,32 +157,32 @@ Curve *BKE_curve_add(const char *name, int type) cu = BKE_libblock_alloc(&G.main->curve, ID_CU, name); copy_v3_fl(cu->size, 1.0f); - cu->flag= CU_FRONT|CU_BACK|CU_DEFORM_BOUNDS_OFF|CU_PATH_RADIUS; - cu->pathlen= 100; - cu->resolu= cu->resolv= (type == OB_SURF) ? 4 : 12; - cu->width= 1.0; + cu->flag = CU_FRONT | CU_BACK | CU_DEFORM_BOUNDS_OFF | CU_PATH_RADIUS; + cu->pathlen = 100; + cu->resolu = cu->resolv = (type == OB_SURF) ? 4 : 12; + cu->width = 1.0; cu->wordspace = 1.0; - cu->spacing= cu->linedist= 1.0; - cu->fsize= 1.0; + cu->spacing = cu->linedist = 1.0; + cu->fsize = 1.0; cu->ulheight = 0.05; - cu->texflag= CU_AUTOSPACE; - cu->smallcaps_scale= 0.75f; - cu->twist_mode= CU_TWIST_MINIMUM; // XXX: this one seems to be the best one in most cases, at least for curve deform... - cu->type= type; - cu->bevfac1= 0.0f; - cu->bevfac2= 1.0f; - - cu->bb= BKE_boundbox_alloc_unit(); - - if (type==OB_FONT) { - cu->vfont= cu->vfontb= cu->vfonti= cu->vfontbi= BKE_vfont_builtin_get(); - cu->vfont->id.us+=4; - cu->str= MEM_mallocN(12, "str"); + cu->texflag = CU_AUTOSPACE; + cu->smallcaps_scale = 0.75f; + cu->twist_mode = CU_TWIST_MINIMUM; // XXX: this one seems to be the best one in most cases, at least for curve deform... + cu->type = type; + cu->bevfac1 = 0.0f; + cu->bevfac2 = 1.0f; + + cu->bb = BKE_boundbox_alloc_unit(); + + if (type == OB_FONT) { + cu->vfont = cu->vfontb = cu->vfonti = cu->vfontbi = BKE_vfont_builtin_get(); + cu->vfont->id.us += 4; + cu->str = MEM_mallocN(12, "str"); BLI_strncpy(cu->str, "Text", 12); - cu->len= cu->pos= 4; - cu->strinfo= MEM_callocN(12*sizeof(CharInfo), "strinfo new"); - cu->totbox= cu->actbox= 1; - cu->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "textbox"); + cu->len = cu->pos = 4; + cu->strinfo = MEM_callocN(12 * sizeof(CharInfo), "strinfo new"); + cu->totbox = cu->actbox = 1; + cu->tb = MEM_callocN(MAXTEXTBOX * sizeof(TextBox), "textbox"); cu->tb[0].w = cu->tb[0].h = 0.0; } @@ -194,34 +194,34 @@ Curve *BKE_curve_copy(Curve *cu) Curve *cun; int a; - cun= BKE_libblock_copy(&cu->id); - cun->nurb.first= cun->nurb.last= NULL; + cun = BKE_libblock_copy(&cu->id); + cun->nurb.first = cun->nurb.last = NULL; BKE_nurbList_duplicate(&(cun->nurb), &(cu->nurb)); - cun->mat= MEM_dupallocN(cu->mat); - for (a=0; a<cun->totcol; a++) { + cun->mat = MEM_dupallocN(cu->mat); + for (a = 0; a < cun->totcol; a++) { id_us_plus((ID *)cun->mat[a]); } - cun->str= MEM_dupallocN(cu->str); - cun->strinfo= MEM_dupallocN(cu->strinfo); - cun->tb= MEM_dupallocN(cu->tb); - cun->bb= MEM_dupallocN(cu->bb); - - cun->key= BKE_key_copy(cu->key); - if (cun->key) cun->key->from= (ID *)cun; - - cun->disp.first= cun->disp.last= NULL; - cun->bev.first= cun->bev.last= NULL; - cun->path= NULL; + cun->str = MEM_dupallocN(cu->str); + cun->strinfo = MEM_dupallocN(cu->strinfo); + cun->tb = MEM_dupallocN(cu->tb); + cun->bb = MEM_dupallocN(cu->bb); - cun->editnurb= NULL; - cun->editfont= NULL; - cun->selboxes= NULL; + cun->key = BKE_key_copy(cu->key); + if (cun->key) cun->key->from = (ID *)cun; -#if 0 // XXX old animation system + cun->disp.first = cun->disp.last = NULL; + cun->bev.first = cun->bev.last = NULL; + cun->path = NULL; + + cun->editnurb = NULL; + cun->editfont = NULL; + cun->selboxes = NULL; + +#if 0 // XXX old animation system /* single user ipo too */ - if (cun->ipo) cun->ipo= copy_ipo(cun->ipo); + if (cun->ipo) cun->ipo = copy_ipo(cun->ipo); #endif // XXX old animation system id_us_plus((ID *)cun->vfont); @@ -246,27 +246,27 @@ static void extern_local_curve(Curve *cu) void BKE_curve_make_local(Curve *cu) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - when there are only lib users: don't do * - when there are only local users: set flag * - mixed: do a copy */ - if (cu->id.lib==NULL) return; + if (cu->id.lib == NULL) return; - if (cu->id.us==1) { + if (cu->id.us == 1) { id_clear_lib_data(bmain, &cu->id); extern_local_curve(cu); return; } - for (ob= bmain->object.first; ob && ELEM(0, is_lib, is_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) is_lib= TRUE; - else is_local= TRUE; + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } @@ -275,15 +275,15 @@ void BKE_curve_make_local(Curve *cu) extern_local_curve(cu); } else if (is_local && is_lib) { - Curve *cu_new= BKE_curve_copy(cu); - cu_new->id.us= 0; + Curve *cu_new = BKE_curve_copy(cu); + cu_new->id.us = 0; BKE_id_lib_local_paths(bmain, cu->id.lib, &cu_new->id); - for (ob= bmain->object.first; ob; ob= ob->id.next) { - if (ob->data==cu) { - if (ob->id.lib==NULL) { - ob->data= cu_new; + for (ob = bmain->object.first; ob; ob = ob->id.next) { + if (ob->data == cu) { + if (ob->id.lib == NULL) { + ob->data = cu_new; cu_new->id.us++; cu->id.us--; } @@ -305,18 +305,18 @@ ListBase *BKE_curve_editNurbs_get(Curve *cu) short BKE_curve_type_get(Curve *cu) { Nurb *nu; - int type= cu->type; + int type = cu->type; if (cu->vfont) { return OB_FONT; } if (!cu->type) { - type= OB_CURVE; + type = OB_CURVE; - for (nu= cu->nurb.first; nu; nu= nu->next) { - if (nu->pntsv>1) { - type= OB_SURF; + for (nu = cu->nurb.first; nu; nu = nu->next) { + if (nu->pntsv > 1) { + type = OB_SURF; } } } @@ -326,16 +326,16 @@ short BKE_curve_type_get(Curve *cu) void BKE_curve_curve_dimension_update(Curve *cu) { - ListBase *nurbs= BKE_curve_nurbs_get(cu); - Nurb *nu= nurbs->first; + ListBase *nurbs = BKE_curve_nurbs_get(cu); + Nurb *nu = nurbs->first; - if (cu->flag&CU_3D) { - for ( ; nu; nu= nu->next) { + if (cu->flag & CU_3D) { + for (; nu; nu = nu->next) { nu->flag &= ~CU_2D; } } else { - for ( ; nu; nu= nu->next) { + for (; nu; nu = nu->next) { nu->flag |= CU_2D; BKE_nurb_test2D(nu); @@ -348,9 +348,9 @@ void BKE_curve_curve_dimension_update(Curve *cu) void BKE_curve_type_test(Object *ob) { - ob->type= BKE_curve_type_get(ob->data); + ob->type = BKE_curve_type_get(ob->data); - if (ob->type==OB_CURVE) + if (ob->type == OB_CURVE) BKE_curve_curve_dimension_update((Curve *)ob->data); } @@ -359,25 +359,25 @@ void BKE_curve_texspace_calc(Curve *cu) DispList *dl; BoundBox *bb; float *fp, min[3], max[3]; - int tot, doit= 0; + int tot, doit = 0; - if (cu->bb==NULL) cu->bb= MEM_callocN(sizeof(BoundBox), "boundbox"); - bb= cu->bb; + if (cu->bb == NULL) cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); + bb = cu->bb; INIT_MINMAX(min, max); - dl= cu->disp.first; + dl = cu->disp.first; while (dl) { tot = ELEM(dl->type, DL_INDEX3, DL_INDEX4) ? dl->nr : dl->nr * dl->parts; - if (tot) doit= 1; - fp= dl->verts; + if (tot) doit = 1; + fp = dl->verts; while (tot--) { DO_MINMAX(fp, min, max); fp += 3; } - dl= dl->next; + dl = dl->next; } if (!doit) { @@ -389,23 +389,23 @@ void BKE_curve_texspace_calc(Curve *cu) if (cu->texflag & CU_AUTOSPACE) { mid_v3_v3v3(cu->loc, min, max); - cu->size[0]= (max[0]-min[0])/2.0f; - cu->size[1]= (max[1]-min[1])/2.0f; - cu->size[2]= (max[2]-min[2])/2.0f; + cu->size[0] = (max[0] - min[0]) / 2.0f; + cu->size[1] = (max[1] - min[1]) / 2.0f; + cu->size[2] = (max[2] - min[2]) / 2.0f; zero_v3(cu->rot); - if (cu->size[0]==0.0f) cu->size[0]= 1.0f; - else if (cu->size[0]>0.0f && cu->size[0]<0.00001f) cu->size[0]= 0.00001f; - else if (cu->size[0]<0.0f && cu->size[0]> -0.00001f) cu->size[0]= -0.00001f; - - if (cu->size[1]==0.0f) cu->size[1]= 1.0f; - else if (cu->size[1]>0.0f && cu->size[1]<0.00001f) cu->size[1]= 0.00001f; - else if (cu->size[1]<0.0f && cu->size[1]> -0.00001f) cu->size[1]= -0.00001f; - - if (cu->size[2]==0.0f) cu->size[2]= 1.0f; - else if (cu->size[2]>0.0f && cu->size[2]<0.00001f) cu->size[2]= 0.00001f; - else if (cu->size[2]<0.0f && cu->size[2]> -0.00001f) cu->size[2]= -0.00001f; + if (cu->size[0] == 0.0f) cu->size[0] = 1.0f; + else if (cu->size[0] > 0.0f && cu->size[0] < 0.00001f) cu->size[0] = 0.00001f; + else if (cu->size[0] < 0.0f && cu->size[0] > -0.00001f) cu->size[0] = -0.00001f; + + if (cu->size[1] == 0.0f) cu->size[1] = 1.0f; + else if (cu->size[1] > 0.0f && cu->size[1] < 0.00001f) cu->size[1] = 0.00001f; + else if (cu->size[1] < 0.0f && cu->size[1] > -0.00001f) cu->size[1] = -0.00001f; + + if (cu->size[2] == 0.0f) cu->size[2] = 1.0f; + else if (cu->size[2] > 0.0f && cu->size[2] < 0.00001f) cu->size[2] = 0.00001f; + else if (cu->size[2] < 0.0f && cu->size[2] > -0.00001f) cu->size[2] = -0.00001f; } } @@ -413,14 +413,14 @@ void BKE_curve_texspace_calc(Curve *cu) int BKE_nurbList_verts_count(ListBase *nurb) { Nurb *nu; - int tot=0; + int tot = 0; - nu= nurb->first; + nu = nurb->first; while (nu) { - if (nu->bezt) tot+= 3*nu->pntsu; - else if (nu->bp) tot+= nu->pntsu*nu->pntsv; + if (nu->bezt) tot += 3 * nu->pntsu; + else if (nu->bp) tot += nu->pntsu * nu->pntsv; - nu= nu->next; + nu = nu->next; } return tot; } @@ -428,14 +428,14 @@ int BKE_nurbList_verts_count(ListBase *nurb) int BKE_nurbList_verts_count_without_handles(ListBase *nurb) { Nurb *nu; - int tot=0; + int tot = 0; - nu= nurb->first; + nu = nurb->first; while (nu) { - if (nu->bezt) tot+= nu->pntsu; - else if (nu->bp) tot+= nu->pntsu*nu->pntsv; + if (nu->bezt) tot += nu->pntsu; + else if (nu->bp) tot += nu->pntsu * nu->pntsv; - nu= nu->next; + nu = nu->next; } return tot; } @@ -445,16 +445,16 @@ int BKE_nurbList_verts_count_without_handles(ListBase *nurb) void BKE_nurb_free(Nurb *nu) { - if (nu==NULL) return; + if (nu == NULL) return; if (nu->bezt) MEM_freeN(nu->bezt); - nu->bezt= NULL; + nu->bezt = NULL; if (nu->bp) MEM_freeN(nu->bp); - nu->bp= NULL; + nu->bp = NULL; if (nu->knotsu) MEM_freeN(nu->knotsu); - nu->knotsu= NULL; + nu->knotsu = NULL; if (nu->knotsv) MEM_freeN(nu->knotsv); - nu->knotsv= NULL; + nu->knotsv = NULL; /* if (nu->trim.first) freeNurblist(&(nu->trim)); */ MEM_freeN(nu); @@ -466,15 +466,15 @@ void BKE_nurbList_free(ListBase *lb) { Nurb *nu, *next; - if (lb==NULL) return; + if (lb == NULL) return; - nu= lb->first; + nu = lb->first; while (nu) { - next= nu->next; + next = nu->next; BKE_nurb_free(nu); - nu= next; + nu = next; } - lb->first= lb->last= NULL; + lb->first = lb->last = NULL; } Nurb *BKE_nurb_duplicate(Nurb *nu) @@ -482,35 +482,35 @@ Nurb *BKE_nurb_duplicate(Nurb *nu) Nurb *newnu; int len; - newnu= (Nurb*)MEM_mallocN(sizeof(Nurb), "duplicateNurb"); - if (newnu==NULL) return NULL; + newnu = (Nurb *)MEM_mallocN(sizeof(Nurb), "duplicateNurb"); + if (newnu == NULL) return NULL; memcpy(newnu, nu, sizeof(Nurb)); if (nu->bezt) { - newnu->bezt= - (BezTriple*)MEM_mallocN((nu->pntsu)* sizeof(BezTriple), "duplicateNurb2"); - memcpy(newnu->bezt, nu->bezt, nu->pntsu*sizeof(BezTriple)); + newnu->bezt = + (BezTriple *)MEM_mallocN((nu->pntsu) * sizeof(BezTriple), "duplicateNurb2"); + memcpy(newnu->bezt, nu->bezt, nu->pntsu * sizeof(BezTriple)); } else { - len= nu->pntsu*nu->pntsv; - newnu->bp= - (BPoint*)MEM_mallocN((len)* sizeof(BPoint), "duplicateNurb3"); - memcpy(newnu->bp, nu->bp, len*sizeof(BPoint)); + len = nu->pntsu * nu->pntsv; + newnu->bp = + (BPoint *)MEM_mallocN((len) * sizeof(BPoint), "duplicateNurb3"); + memcpy(newnu->bp, nu->bp, len * sizeof(BPoint)); - newnu->knotsu= newnu->knotsv= NULL; + newnu->knotsu = newnu->knotsv = NULL; if (nu->knotsu) { - len= KNOTSU(nu); + len = KNOTSU(nu); if (len) { - newnu->knotsu= MEM_mallocN(len*sizeof(float), "duplicateNurb4"); - memcpy(newnu->knotsu, nu->knotsu, sizeof(float)*len); + newnu->knotsu = MEM_mallocN(len * sizeof(float), "duplicateNurb4"); + memcpy(newnu->knotsu, nu->knotsu, sizeof(float) * len); } } - if (nu->pntsv>1 && nu->knotsv) { - len= KNOTSV(nu); + if (nu->pntsv > 1 && nu->knotsv) { + len = KNOTSV(nu); if (len) { - newnu->knotsv= MEM_mallocN(len*sizeof(float), "duplicateNurb5"); - memcpy(newnu->knotsv, nu->knotsv, sizeof(float)*len); + newnu->knotsv = MEM_mallocN(len * sizeof(float), "duplicateNurb5"); + memcpy(newnu->knotsv, nu->knotsv, sizeof(float) * len); } } } @@ -523,12 +523,12 @@ void BKE_nurbList_duplicate(ListBase *lb1, ListBase *lb2) BKE_nurbList_free(lb1); - nu= lb2->first; + nu = lb2->first; while (nu) { - nun= BKE_nurb_duplicate(nu); + nun = BKE_nurb_duplicate(nu); BLI_addtail(lb1, nun); - nu= nu->next; + nu = nu->next; } } @@ -538,24 +538,24 @@ void BKE_nurb_test2D(Nurb *nu) BPoint *bp; int a; - if ((nu->flag & CU_2D)==0) + if ((nu->flag & CU_2D) == 0) return; if (nu->type == CU_BEZIER) { - a= nu->pntsu; - bezt= nu->bezt; + a = nu->pntsu; + bezt = nu->bezt; while (a--) { - bezt->vec[0][2]= 0.0; - bezt->vec[1][2]= 0.0; - bezt->vec[2][2]= 0.0; + bezt->vec[0][2] = 0.0; + bezt->vec[1][2] = 0.0; + bezt->vec[2][2] = 0.0; bezt++; } } else { - a= nu->pntsu*nu->pntsv; - bp= nu->bp; + a = nu->pntsu * nu->pntsv; + bp = nu->bp; while (a--) { - bp->vec[2]= 0.0; + bp->vec[2] = 0.0; bp++; } } @@ -568,8 +568,8 @@ void BKE_nurb_minmax(Nurb *nu, float *min, float *max) int a; if (nu->type == CU_BEZIER) { - a= nu->pntsu; - bezt= nu->bezt; + a = nu->pntsu; + bezt = nu->bezt; while (a--) { DO_MINMAX(bezt->vec[0], min, max); DO_MINMAX(bezt->vec[1], min, max); @@ -578,8 +578,8 @@ void BKE_nurb_minmax(Nurb *nu, float *min, float *max) } } else { - a= nu->pntsu*nu->pntsv; - bp= nu->bp; + a = nu->pntsu * nu->pntsv; + bp = nu->bp; while (a--) { DO_MINMAX(bp->vec, min, max); bp++; @@ -590,9 +590,9 @@ void BKE_nurb_minmax(Nurb *nu, float *min, float *max) /* be sure to call makeknots after this */ void BKE_nurb_points_add(Nurb *nu, int number) { - BPoint *tmp= nu->bp; + BPoint *tmp = nu->bp; int i; - nu->bp= (BPoint *)MEM_mallocN((nu->pntsu + number) * sizeof(BPoint), "rna_Curve_spline_points_add"); + nu->bp = (BPoint *)MEM_mallocN((nu->pntsu + number) * sizeof(BPoint), "rna_Curve_spline_points_add"); if (tmp) { memmove(nu->bp, tmp, nu->pntsu * sizeof(BPoint)); @@ -601,8 +601,8 @@ void BKE_nurb_points_add(Nurb *nu, int number) memset(nu->bp + nu->pntsu, 0, number * sizeof(BPoint)); - for (i=0, tmp= nu->bp + nu->pntsu; i < number; i++, tmp++) { - tmp->radius= 1.0f; + for (i = 0, tmp = nu->bp + nu->pntsu; i < number; i++, tmp++) { + tmp->radius = 1.0f; } nu->pntsu += number; @@ -610,9 +610,9 @@ void BKE_nurb_points_add(Nurb *nu, int number) void BKE_nurb_bezierPoints_add(Nurb *nu, int number) { - BezTriple *tmp= nu->bezt; + BezTriple *tmp = nu->bezt; int i; - nu->bezt= (BezTriple *)MEM_mallocN((nu->pntsu + number) * sizeof(BezTriple), "rna_Curve_spline_points_add"); + nu->bezt = (BezTriple *)MEM_mallocN((nu->pntsu + number) * sizeof(BezTriple), "rna_Curve_spline_points_add"); if (tmp) { memmove(nu->bezt, tmp, nu->pntsu * sizeof(BezTriple)); @@ -621,8 +621,8 @@ void BKE_nurb_bezierPoints_add(Nurb *nu, int number) memset(nu->bezt + nu->pntsu, 0, number * sizeof(BezTriple)); - for (i=0, tmp= nu->bezt + nu->pntsu; i < number; i++, tmp++) { - tmp->radius= 1.0f; + for (i = 0, tmp = nu->bezt + nu->pntsu; i < number; i++, tmp++) { + tmp->radius = 1.0f; } nu->pntsu += number; @@ -634,44 +634,44 @@ void BKE_nurb_bezierPoints_add(Nurb *nu, int number) static void calcknots(float *knots, const short pnts, const short order, const short flag) { /* knots: number of pnts NOT corrected for cyclic */ - const int pnts_order= pnts + order; + const int pnts_order = pnts + order; float k; int a; - switch (flag & (CU_NURB_ENDPOINT|CU_NURB_BEZIER)) { - case CU_NURB_ENDPOINT: - k= 0.0; - for (a=1; a <= pnts_order; a++) { - knots[a-1]= k; - if (a >= order && a <= pnts) k+= 1.0f; - } - break; - case CU_NURB_BEZIER: - /* Warning, the order MUST be 2 or 4, - * if this is not enforced, the displist will be corrupt */ - if (order==4) { - k= 0.34; - for (a=0; a < pnts_order; a++) { - knots[a]= floorf(k); - k+= (1.0f/3.0f); + switch (flag & (CU_NURB_ENDPOINT | CU_NURB_BEZIER)) { + case CU_NURB_ENDPOINT: + k = 0.0; + for (a = 1; a <= pnts_order; a++) { + knots[a - 1] = k; + if (a >= order && a <= pnts) k += 1.0f; } - } - else if (order==3) { - k= 0.6f; - for (a=0; a < pnts_order; a++) { - if (a >= order && a <= pnts) k+= 0.5f; - knots[a]= floorf(k); + break; + case CU_NURB_BEZIER: + /* Warning, the order MUST be 2 or 4, + * if this is not enforced, the displist will be corrupt */ + if (order == 4) { + k = 0.34; + for (a = 0; a < pnts_order; a++) { + knots[a] = floorf(k); + k += (1.0f / 3.0f); + } } - } - else { - printf("bez nurb curve order is not 3 or 4, should never happen\n"); - } - break; - default: - for (a=0; a < pnts_order; a++) { - knots[a]= (float)a; - } - break; + else if (order == 3) { + k = 0.6f; + for (a = 0; a < pnts_order; a++) { + if (a >= order && a <= pnts) k += 0.5f; + knots[a] = floorf(k); + } + } + else { + printf("bez nurb curve order is not 3 or 4, should never happen\n"); + } + break; + default: + for (a = 0; a < pnts_order; a++) { + knots[a] = (float)a; + } + break; } } @@ -680,23 +680,23 @@ static void makecyclicknots(float *knots, short pnts, short order) { int a, b, order2, c; - if (knots==NULL) return; + if (knots == NULL) return; - order2=order-1; + order2 = order - 1; /* do first long rows (order -1), remove identical knots at endpoints */ - if (order>2) { - b= pnts+order2; - for (a=1; a<order2; a++) { - if (knots[b]!= knots[b-a]) break; + if (order > 2) { + b = pnts + order2; + for (a = 1; a < order2; a++) { + if (knots[b] != knots[b - a]) break; } - if (a==order2) knots[pnts+order-2]+= 1.0f; + if (a == order2) knots[pnts + order - 2] += 1.0f; } - b= order; - c=pnts + order + order2; - for (a=pnts+order2; a<c; a++) { - knots[a]= knots[a-1]+ (knots[b]-knots[b-1]); + b = order; + c = pnts + order + order2; + for (a = pnts + order2; a < c; a++) { + knots[a] = knots[a - 1] + (knots[b] - knots[b - 1]); b--; } } @@ -709,7 +709,7 @@ static void makeknots(Nurb *nu, short uv) if (uv == 1) { if (nu->knotsu) MEM_freeN(nu->knotsu); if (BKE_nurb_check_valid_u(nu)) { - nu->knotsu= MEM_callocN(4+sizeof(float)*KNOTSU(nu), "makeknots"); + nu->knotsu = MEM_callocN(4 + sizeof(float) * KNOTSU(nu), "makeknots"); if (nu->flagu & CU_NURB_CYCLIC) { calcknots(nu->knotsu, nu->pntsu, nu->orderu, 0); /* cyclic should be uniform */ makecyclicknots(nu->knotsu, nu->pntsu, nu->orderu); @@ -718,13 +718,13 @@ static void makeknots(Nurb *nu, short uv) calcknots(nu->knotsu, nu->pntsu, nu->orderu, nu->flagu); } } - else nu->knotsu= NULL; + else nu->knotsu = NULL; } else if (uv == 2) { if (nu->knotsv) MEM_freeN(nu->knotsv); if (BKE_nurb_check_valid_v(nu)) { - nu->knotsv= MEM_callocN(4+sizeof(float)*KNOTSV(nu), "makeknots"); + nu->knotsv = MEM_callocN(4 + sizeof(float) * KNOTSV(nu), "makeknots"); if (nu->flagv & CU_NURB_CYCLIC) { calcknots(nu->knotsv, nu->pntsv, nu->orderv, 0); /* cyclic should be uniform */ makecyclicknots(nu->knotsv, nu->pntsv, nu->orderv); @@ -733,7 +733,7 @@ static void makeknots(Nurb *nu, short uv) calcknots(nu->knotsv, nu->pntsv, nu->orderv, nu->flagv); } } - else nu->knotsv= NULL; + else nu->knotsv = NULL; } } } @@ -753,59 +753,59 @@ static void basisNurb(float t, short order, short pnts, float *knots, float *bas float d, e; int i, i1 = 0, i2 = 0, j, orderpluspnts, opp2, o2; - orderpluspnts= order+pnts; - opp2 = orderpluspnts-1; + orderpluspnts = order + pnts; + opp2 = orderpluspnts - 1; /* this is for float inaccuracy */ - if (t < knots[0]) t= knots[0]; - else if (t > knots[opp2]) t= knots[opp2]; + if (t < knots[0]) t = knots[0]; + else if (t > knots[opp2]) t = knots[opp2]; /* this part is order '1' */ - o2 = order + 1; - for (i=0;i<opp2;i++) { - if (knots[i]!=knots[i+1] && t>= knots[i] && t<=knots[i+1]) { - basis[i]= 1.0; - i1= i-o2; - if (i1<0) i1= 0; - i2= i; + o2 = order + 1; + for (i = 0; i < opp2; i++) { + if (knots[i] != knots[i + 1] && t >= knots[i] && t <= knots[i + 1]) { + basis[i] = 1.0; + i1 = i - o2; + if (i1 < 0) i1 = 0; + i2 = i; i++; - while (i<opp2) { - basis[i]= 0.0; + while (i < opp2) { + basis[i] = 0.0; i++; } break; } - else basis[i]= 0.0; + else basis[i] = 0.0; } - basis[i]= 0.0; + basis[i] = 0.0; /* this is order 2, 3, ... */ - for (j=2; j<=order; j++) { + for (j = 2; j <= order; j++) { - if (i2+j>= orderpluspnts) i2= opp2-j; + if (i2 + j >= orderpluspnts) i2 = opp2 - j; - for (i= i1; i<=i2; i++) { - if (basis[i]!=0.0f) - d= ((t-knots[i])*basis[i]) / (knots[i+j-1]-knots[i]); + for (i = i1; i <= i2; i++) { + if (basis[i] != 0.0f) + d = ((t - knots[i]) * basis[i]) / (knots[i + j - 1] - knots[i]); else - d= 0.0f; + d = 0.0f; - if (basis[i+1] != 0.0f) - e= ((knots[i+j]-t)*basis[i+1]) / (knots[i+j]-knots[i+1]); + if (basis[i + 1] != 0.0f) + e = ((knots[i + j] - t) * basis[i + 1]) / (knots[i + j] - knots[i + 1]); else - e= 0.0; + e = 0.0; - basis[i]= d+e; + basis[i] = d + e; } } - *start= 1000; - *end= 0; + *start = 1000; + *end = 0; - for (i=i1; i<=i2; i++) { + for (i = i1; i <= i2; i++) { if (basis[i] > 0.0f) { - *end= i; - if (*start==1000) *start= i; + *end = i; + if (*start == 1000) *start = i; } } } @@ -820,150 +820,150 @@ void BKE_nurb_makeFaces(Nurb *nu, float *coord_array, int rowstride, int resolu, int i, j, iofs, jofs, cycl, len, curu, curv; int istart, iend, jsta, jen, *jstart, *jend, ratcomp; - int totu = nu->pntsu*resolu, totv = nu->pntsv*resolv; + int totu = nu->pntsu * resolu, totv = nu->pntsv * resolv; - if (nu->knotsu==NULL || nu->knotsv==NULL) return; - if (nu->orderu>nu->pntsu) return; - if (nu->orderv>nu->pntsv) return; - if (coord_array==NULL) return; + if (nu->knotsu == NULL || nu->knotsv == NULL) return; + if (nu->orderu > nu->pntsu) return; + if (nu->orderv > nu->pntsv) return; + if (coord_array == NULL) return; /* allocate and initialize */ len = totu * totv; - if (len==0) return; + if (len == 0) return; - sum= (float *)MEM_callocN(sizeof(float)*len, "makeNurbfaces1"); + sum = (float *)MEM_callocN(sizeof(float) * len, "makeNurbfaces1"); - len= totu*totv; - if (len==0) { + len = totu * totv; + if (len == 0) { MEM_freeN(sum); return; } - bp= nu->bp; - i= nu->pntsu*nu->pntsv; - ratcomp=0; + bp = nu->bp; + i = nu->pntsu * nu->pntsv; + ratcomp = 0; while (i--) { if (bp->vec[3] != 1.0f) { - ratcomp= 1; + ratcomp = 1; break; } bp++; } - fp= nu->knotsu; - ustart= fp[nu->orderu-1]; - if (nu->flagu & CU_NURB_CYCLIC) uend= fp[nu->pntsu+nu->orderu-1]; - else uend= fp[nu->pntsu]; - ustep= (uend-ustart)/((nu->flagu & CU_NURB_CYCLIC) ? totu : totu - 1); - - basisu= (float *)MEM_mallocN(sizeof(float)*KNOTSU(nu), "makeNurbfaces3"); + fp = nu->knotsu; + ustart = fp[nu->orderu - 1]; + if (nu->flagu & CU_NURB_CYCLIC) uend = fp[nu->pntsu + nu->orderu - 1]; + else uend = fp[nu->pntsu]; + ustep = (uend - ustart) / ((nu->flagu & CU_NURB_CYCLIC) ? totu : totu - 1); - fp= nu->knotsv; - vstart= fp[nu->orderv-1]; - - if (nu->flagv & CU_NURB_CYCLIC) vend= fp[nu->pntsv+nu->orderv-1]; - else vend= fp[nu->pntsv]; - vstep= (vend-vstart)/((nu->flagv & CU_NURB_CYCLIC) ? totv : totv - 1); - - len= KNOTSV(nu); - basisv= (float *)MEM_mallocN(sizeof(float)*len*totv, "makeNurbfaces3"); - jstart= (int *)MEM_mallocN(sizeof(float)*totv, "makeNurbfaces4"); - jend= (int *)MEM_mallocN(sizeof(float)*totv, "makeNurbfaces5"); + basisu = (float *)MEM_mallocN(sizeof(float) * KNOTSU(nu), "makeNurbfaces3"); + + fp = nu->knotsv; + vstart = fp[nu->orderv - 1]; + + if (nu->flagv & CU_NURB_CYCLIC) vend = fp[nu->pntsv + nu->orderv - 1]; + else vend = fp[nu->pntsv]; + vstep = (vend - vstart) / ((nu->flagv & CU_NURB_CYCLIC) ? totv : totv - 1); + + len = KNOTSV(nu); + basisv = (float *)MEM_mallocN(sizeof(float) * len * totv, "makeNurbfaces3"); + jstart = (int *)MEM_mallocN(sizeof(float) * totv, "makeNurbfaces4"); + jend = (int *)MEM_mallocN(sizeof(float) * totv, "makeNurbfaces5"); /* precalculation of basisv and jstart, jend */ - if (nu->flagv & CU_NURB_CYCLIC) cycl= nu->orderv-1; - else cycl= 0; - v= vstart; - basis= basisv; - curv= totv; + if (nu->flagv & CU_NURB_CYCLIC) cycl = nu->orderv - 1; + else cycl = 0; + v = vstart; + basis = basisv; + curv = totv; while (curv--) { - basisNurb(v, nu->orderv, (short)(nu->pntsv+cycl), nu->knotsv, basis, jstart+curv, jend+curv); - basis+= KNOTSV(nu); - v+= vstep; + basisNurb(v, nu->orderv, (short)(nu->pntsv + cycl), nu->knotsv, basis, jstart + curv, jend + curv); + basis += KNOTSV(nu); + v += vstep; } - if (nu->flagu & CU_NURB_CYCLIC) cycl= nu->orderu-1; - else cycl= 0; - in= coord_array; - u= ustart; - curu= totu; + if (nu->flagu & CU_NURB_CYCLIC) cycl = nu->orderu - 1; + else cycl = 0; + in = coord_array; + u = ustart; + curu = totu; while (curu--) { - basisNurb(u, nu->orderu, (short)(nu->pntsu+cycl), nu->knotsu, basisu, &istart, &iend); + basisNurb(u, nu->orderu, (short)(nu->pntsu + cycl), nu->knotsu, basisu, &istart, &iend); - basis= basisv; - curv= totv; + basis = basisv; + curv = totv; while (curv--) { - jsta= jstart[curv]; - jen= jend[curv]; + jsta = jstart[curv]; + jen = jend[curv]; /* calculate sum */ - sumdiv= 0.0; - fp= sum; + sumdiv = 0.0; + fp = sum; - for (j= jsta; j<=jen; j++) { + for (j = jsta; j <= jen; j++) { - if (j>=nu->pntsv) jofs= (j - nu->pntsv); - else jofs= j; - bp= nu->bp+ nu->pntsu*jofs+istart-1; + if (j >= nu->pntsv) jofs = (j - nu->pntsv); + else jofs = j; + bp = nu->bp + nu->pntsu * jofs + istart - 1; - for (i= istart; i<=iend; i++, fp++) { + for (i = istart; i <= iend; i++, fp++) { - if (i>= nu->pntsu) { - iofs= i- nu->pntsu; - bp= nu->bp+ nu->pntsu*jofs+iofs; + if (i >= nu->pntsu) { + iofs = i - nu->pntsu; + bp = nu->bp + nu->pntsu * jofs + iofs; } else bp++; if (ratcomp) { - *fp= basisu[i]*basis[j]*bp->vec[3]; - sumdiv+= *fp; + *fp = basisu[i] * basis[j] * bp->vec[3]; + sumdiv += *fp; } - else *fp= basisu[i]*basis[j]; + else *fp = basisu[i] * basis[j]; } } if (ratcomp) { - fp= sum; - for (j= jsta; j<=jen; j++) { - for (i= istart; i<=iend; i++, fp++) { - *fp/= sumdiv; + fp = sum; + for (j = jsta; j <= jen; j++) { + for (i = istart; i <= iend; i++, fp++) { + *fp /= sumdiv; } } } /* one! (1.0) real point now */ - fp= sum; - for (j= jsta; j<=jen; j++) { + fp = sum; + for (j = jsta; j <= jen; j++) { - if (j>=nu->pntsv) jofs= (j - nu->pntsv); - else jofs= j; - bp= nu->bp+ nu->pntsu*jofs+istart-1; + if (j >= nu->pntsv) jofs = (j - nu->pntsv); + else jofs = j; + bp = nu->bp + nu->pntsu * jofs + istart - 1; - for (i= istart; i<=iend; i++, fp++) { + for (i = istart; i <= iend; i++, fp++) { - if (i>= nu->pntsu) { - iofs= i- nu->pntsu; - bp= nu->bp+ nu->pntsu*jofs+iofs; + if (i >= nu->pntsu) { + iofs = i - nu->pntsu; + bp = nu->bp + nu->pntsu * jofs + iofs; } else bp++; if (*fp != 0.0f) { - in[0]+= (*fp) * bp->vec[0]; - in[1]+= (*fp) * bp->vec[1]; - in[2]+= (*fp) * bp->vec[2]; + in[0] += (*fp) * bp->vec[0]; + in[1] += (*fp) * bp->vec[1]; + in[2] += (*fp) * bp->vec[2]; } } } - in+=3; - basis+= KNOTSV(nu); + in += 3; + basis += KNOTSV(nu); } - u+= ustep; - if (rowstride!=0) in = (float*) (((unsigned char*) in) + (rowstride - 3*totv*sizeof(*in))); + u += ustep; + if (rowstride != 0) in = (float *) (((unsigned char *) in) + (rowstride - 3 * totv * sizeof(*in))); } /* free */ @@ -981,73 +981,73 @@ void BKE_nurb_makeCurve(Nurb *nu, float *coord_array, float *tilt_array, float * BPoint *bp; float u, ustart, uend, ustep, sumdiv; float *basisu, *sum, *fp; - float *coord_fp= coord_array, *tilt_fp= tilt_array, *radius_fp= radius_array, *weight_fp= weight_array; + float *coord_fp = coord_array, *tilt_fp = tilt_array, *radius_fp = radius_array, *weight_fp = weight_array; int i, len, istart, iend, cycl; - if (nu->knotsu==NULL) return; - if (nu->orderu>nu->pntsu) return; - if (coord_array==NULL) return; + if (nu->knotsu == NULL) return; + if (nu->orderu > nu->pntsu) return; + if (coord_array == NULL) return; /* allocate and initialize */ - len= nu->pntsu; - if (len==0) return; - sum= (float *)MEM_callocN(sizeof(float)*len, "makeNurbcurve1"); + len = nu->pntsu; + if (len == 0) return; + sum = (float *)MEM_callocN(sizeof(float) * len, "makeNurbcurve1"); - resolu= (resolu*SEGMENTSU(nu)); + resolu = (resolu * SEGMENTSU(nu)); - if (resolu==0) { + if (resolu == 0) { MEM_freeN(sum); return; } - fp= nu->knotsu; - ustart= fp[nu->orderu-1]; - if (nu->flagu & CU_NURB_CYCLIC) uend= fp[nu->pntsu+nu->orderu-1]; - else uend= fp[nu->pntsu]; - ustep= (uend-ustart)/(resolu - ((nu->flagu & CU_NURB_CYCLIC) ? 0 : 1)); + fp = nu->knotsu; + ustart = fp[nu->orderu - 1]; + if (nu->flagu & CU_NURB_CYCLIC) uend = fp[nu->pntsu + nu->orderu - 1]; + else uend = fp[nu->pntsu]; + ustep = (uend - ustart) / (resolu - ((nu->flagu & CU_NURB_CYCLIC) ? 0 : 1)); - basisu= (float *)MEM_mallocN(sizeof(float)*KNOTSU(nu), "makeNurbcurve3"); + basisu = (float *)MEM_mallocN(sizeof(float) * KNOTSU(nu), "makeNurbcurve3"); - if (nu->flagu & CU_NURB_CYCLIC) cycl= nu->orderu-1; - else cycl= 0; + if (nu->flagu & CU_NURB_CYCLIC) cycl = nu->orderu - 1; + else cycl = 0; - u= ustart; + u = ustart; while (resolu--) { - basisNurb(u, nu->orderu, (short)(nu->pntsu+cycl), nu->knotsu, basisu, &istart, &iend); + basisNurb(u, nu->orderu, (short)(nu->pntsu + cycl), nu->knotsu, basisu, &istart, &iend); /* calc sum */ - sumdiv= 0.0; - fp= sum; - bp= nu->bp+ istart-1; - for (i= istart; i<=iend; i++, fp++) { + sumdiv = 0.0; + fp = sum; + bp = nu->bp + istart - 1; + for (i = istart; i <= iend; i++, fp++) { - if (i>=nu->pntsu) bp= nu->bp+(i - nu->pntsu); + if (i >= nu->pntsu) bp = nu->bp + (i - nu->pntsu); else bp++; - *fp= basisu[i]*bp->vec[3]; - sumdiv+= *fp; + *fp = basisu[i] * bp->vec[3]; + sumdiv += *fp; } if (sumdiv != 0.0f) if (sumdiv < 0.999f || sumdiv > 1.001f) { - /* is normalizing needed? */ - fp= sum; - for (i= istart; i<=iend; i++, fp++) { - *fp/= sumdiv; + /* is normalizing needed? */ + fp = sum; + for (i = istart; i <= iend; i++, fp++) { + *fp /= sumdiv; + } } - } /* one! (1.0) real point */ - fp= sum; - bp= nu->bp+ istart-1; - for (i= istart; i<=iend; i++, fp++) { + fp = sum; + bp = nu->bp + istart - 1; + for (i = istart; i <= iend; i++, fp++) { - if (i>=nu->pntsu) bp= nu->bp+(i - nu->pntsu); + if (i >= nu->pntsu) bp = nu->bp + (i - nu->pntsu); else bp++; if (*fp != 0.0f) { - coord_fp[0]+= (*fp) * bp->vec[0]; - coord_fp[1]+= (*fp) * bp->vec[1]; - coord_fp[2]+= (*fp) * bp->vec[2]; + coord_fp[0] += (*fp) * bp->vec[0]; + coord_fp[1] += (*fp) * bp->vec[1]; + coord_fp[2] += (*fp) * bp->vec[2]; if (tilt_fp) (*tilt_fp) += (*fp) * bp->alfa; @@ -1063,11 +1063,11 @@ void BKE_nurb_makeCurve(Nurb *nu, float *coord_array, float *tilt_array, float * coord_fp = (float *)(((char *)coord_fp) + stride); - if (tilt_fp) tilt_fp = (float *)(((char *)tilt_fp) + stride); - if (radius_fp) radius_fp = (float *)(((char *)radius_fp) + stride); - if (weight_fp) weight_fp = (float *)(((char *)weight_fp) + stride); + if (tilt_fp) tilt_fp = (float *)(((char *)tilt_fp) + stride); + if (radius_fp) radius_fp = (float *)(((char *)radius_fp) + stride); + if (weight_fp) weight_fp = (float *)(((char *)weight_fp) + stride); - u+= ustep; + u += ustep; } /* free */ @@ -1081,25 +1081,25 @@ void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float float rt0, rt1, rt2, rt3, f; int a; - f= (float)it; - rt0= q0; - rt1= 3.0f*(q1-q0)/f; - f*= f; - rt2= 3.0f*(q0-2.0f*q1+q2)/f; - f*= it; - rt3= (q3-q0+3.0f*(q1-q2))/f; + f = (float)it; + rt0 = q0; + rt1 = 3.0f * (q1 - q0) / f; + f *= f; + rt2 = 3.0f * (q0 - 2.0f * q1 + q2) / f; + f *= it; + rt3 = (q3 - q0 + 3.0f * (q1 - q2)) / f; - q0= rt0; - q1= rt1+rt2+rt3; - q2= 2*rt2+6*rt3; - q3= 6*rt3; + q0 = rt0; + q1 = rt1 + rt2 + rt3; + q2 = 2 * rt2 + 6 * rt3; + q3 = 6 * rt3; - for (a=0; a<=it; a++) { - *p= q0; - p = (float *)(((char *)p)+stride); - q0+= q1; - q1+= q2; - q2+= q3; + for (a = 0; a <= it; a++) { + *p = q0; + p = (float *)(((char *)p) + stride); + q0 += q1; + q1 += q2; + q2 += q3; } } @@ -1110,15 +1110,15 @@ static void forward_diff_bezier_cotangent(float *p0, float *p1, float *p2, float * * This could also be optimized like forward_diff_bezier */ int a; - for (a=0; a<=it; a++) { + for (a = 0; a <= it; a++) { float t = (float)a / (float)it; int i; - for (i=0; i<3; i++) { - p[i]= (-6*t + 6)*p0[i] + (18*t - 12)*p1[i] + (-18*t + 6)*p2[i] + (6*t)*p3[i]; + for (i = 0; i < 3; i++) { + p[i] = (-6 * t + 6) * p0[i] + (18 * t - 12) * p1[i] + (-18 * t + 6) * p2[i] + (6 * t) * p3[i]; } normalize_v3(p); - p = (float *)(((char *)p)+stride); + p = (float *)(((char *)p) + stride); } } @@ -1128,15 +1128,15 @@ float *BKE_curve_surf_make_orco(Object *ob) { /* Note: this function is used in convertblender only atm, so * suppose nonzero curve's render resolution should always be used */ - Curve *cu= ob->data; + Curve *cu = ob->data; Nurb *nu; - int a, b, tot=0; + int a, b, tot = 0; int sizeu, sizev; int resolu, resolv; float *fp, *coord_array; /* first calculate the size of the datablock */ - nu= cu->nurb.first; + nu = cu->nurb.first; while (nu) { /* as we want to avoid the seam in a cyclic nurbs * texture wrapping, reserve extra orco data space to save these extra needed @@ -1147,85 +1147,85 @@ float *BKE_curve_surf_make_orco(Object *ob) * See also convertblender.c: init_render_surf() */ - resolu= cu->resolu_ren ? cu->resolu_ren : nu->resolu; - resolv= cu->resolv_ren ? cu->resolv_ren : nu->resolv; + resolu = cu->resolu_ren ? cu->resolu_ren : nu->resolu; + resolv = cu->resolv_ren ? cu->resolv_ren : nu->resolv; - sizeu = nu->pntsu*resolu; - sizev = nu->pntsv*resolv; + sizeu = nu->pntsu * resolu; + sizev = nu->pntsv * resolv; if (nu->flagu & CU_NURB_CYCLIC) sizeu++; if (nu->flagv & CU_NURB_CYCLIC) sizev++; - if (nu->pntsv>1) tot+= sizeu * sizev; + if (nu->pntsv > 1) tot += sizeu * sizev; - nu= nu->next; + nu = nu->next; } /* makeNurbfaces wants zeros */ - fp= coord_array= MEM_callocN(3*sizeof(float)*tot, "make_orco"); + fp = coord_array = MEM_callocN(3 * sizeof(float) * tot, "make_orco"); - nu= cu->nurb.first; + nu = cu->nurb.first; while (nu) { - resolu= cu->resolu_ren ? cu->resolu_ren : nu->resolu; - resolv= cu->resolv_ren ? cu->resolv_ren : nu->resolv; + resolu = cu->resolu_ren ? cu->resolu_ren : nu->resolu; + resolv = cu->resolv_ren ? cu->resolv_ren : nu->resolv; - if (nu->pntsv>1) { - sizeu = nu->pntsu*resolu; - sizev = nu->pntsv*resolv; + if (nu->pntsv > 1) { + sizeu = nu->pntsu * resolu; + sizev = nu->pntsv * resolv; if (nu->flagu & CU_NURB_CYCLIC) sizeu++; if (nu->flagv & CU_NURB_CYCLIC) sizev++; if (cu->flag & CU_UV_ORCO) { - for (b=0; b< sizeu; b++) { - for (a=0; a< sizev; a++) { + for (b = 0; b < sizeu; b++) { + for (a = 0; a < sizev; a++) { - if (sizev <2) fp[0]= 0.0f; - else fp[0]= -1.0f + 2.0f*((float)a)/(sizev - 1); + if (sizev < 2) fp[0] = 0.0f; + else fp[0] = -1.0f + 2.0f * ((float)a) / (sizev - 1); - if (sizeu <2) fp[1]= 0.0f; - else fp[1]= -1.0f + 2.0f*((float)b)/(sizeu - 1); + if (sizeu < 2) fp[1] = 0.0f; + else fp[1] = -1.0f + 2.0f * ((float)b) / (sizeu - 1); - fp[2]= 0.0; + fp[2] = 0.0; - fp+= 3; + fp += 3; } } } else { - float *_tdata= MEM_callocN((nu->pntsu*resolu) * (nu->pntsv*resolv) *3*sizeof(float), "temp data"); - float *tdata= _tdata; + float *_tdata = MEM_callocN((nu->pntsu * resolu) * (nu->pntsv * resolv) * 3 * sizeof(float), "temp data"); + float *tdata = _tdata; BKE_nurb_makeFaces(nu, tdata, 0, resolu, resolv); - for (b=0; b<sizeu; b++) { - int use_b= b; - if (b==sizeu-1 && (nu->flagu & CU_NURB_CYCLIC)) - use_b= 0; - - for (a=0; a<sizev; a++) { - int use_a= a; - if (a==sizev-1 && (nu->flagv & CU_NURB_CYCLIC)) - use_a= 0; - - tdata = _tdata + 3 * (use_b * (nu->pntsv*resolv) + use_a); - - fp[0]= (tdata[0]-cu->loc[0])/cu->size[0]; - fp[1]= (tdata[1]-cu->loc[1])/cu->size[1]; - fp[2]= (tdata[2]-cu->loc[2])/cu->size[2]; - fp+= 3; + for (b = 0; b < sizeu; b++) { + int use_b = b; + if (b == sizeu - 1 && (nu->flagu & CU_NURB_CYCLIC)) + use_b = 0; + + for (a = 0; a < sizev; a++) { + int use_a = a; + if (a == sizev - 1 && (nu->flagv & CU_NURB_CYCLIC)) + use_a = 0; + + tdata = _tdata + 3 * (use_b * (nu->pntsv * resolv) + use_a); + + fp[0] = (tdata[0] - cu->loc[0]) / cu->size[0]; + fp[1] = (tdata[1] - cu->loc[1]) / cu->size[1]; + fp[2] = (tdata[2] - cu->loc[2]) / cu->size[2]; + fp += 3; } } MEM_freeN(_tdata); } } - nu= nu->next; + nu = nu->next; } return coord_array; } - /* NOTE: This routine is tied to the order of vertex - * built by displist and as passed to the renderer. - */ +/* NOTE: This routine is tied to the order of vertex + * built by displist and as passed to the renderer. + */ float *BKE_curve_make_orco(Scene *scene, Object *ob) { Curve *cu = ob->data; @@ -1237,43 +1237,43 @@ float *BKE_curve_make_orco(Scene *scene, Object *ob) makeDispListCurveTypes_forOrco(scene, ob, &disp); numVerts = 0; - for (dl=disp.first; dl; dl=dl->next) { - if (dl->type==DL_INDEX3) { + for (dl = disp.first; dl; dl = dl->next) { + if (dl->type == DL_INDEX3) { numVerts += dl->nr; } - else if (dl->type==DL_SURF) { + else if (dl->type == DL_SURF) { /* convertblender.c uses the Surface code for creating renderfaces when cyclic U only (closed circle beveling) */ if (dl->flag & DL_CYCL_U) { if (dl->flag & DL_CYCL_V) - numVerts += (dl->parts+1)*(dl->nr+1); + numVerts += (dl->parts + 1) * (dl->nr + 1); else - numVerts += dl->parts*(dl->nr+1); + numVerts += dl->parts * (dl->nr + 1); } else - numVerts += dl->parts*dl->nr; + numVerts += dl->parts * dl->nr; } } - fp= coord_array= MEM_mallocN(3*sizeof(float)*numVerts, "cu_orco"); - for (dl=disp.first; dl; dl=dl->next) { - if (dl->type==DL_INDEX3) { - for (u=0; u<dl->nr; u++, fp+=3) { + fp = coord_array = MEM_mallocN(3 * sizeof(float) * numVerts, "cu_orco"); + for (dl = disp.first; dl; dl = dl->next) { + if (dl->type == DL_INDEX3) { + for (u = 0; u < dl->nr; u++, fp += 3) { if (cu->flag & CU_UV_ORCO) { - fp[0]= 2.0f*u/(dl->nr-1) - 1.0f; - fp[1]= 0.0; - fp[2]= 0.0; + fp[0] = 2.0f * u / (dl->nr - 1) - 1.0f; + fp[1] = 0.0; + fp[2] = 0.0; } else { - copy_v3_v3(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]; - fp[2]= (fp[2]-cu->loc[2])/cu->size[2]; + fp[0] = (fp[0] - cu->loc[0]) / cu->size[0]; + fp[1] = (fp[1] - cu->loc[1]) / cu->size[1]; + fp[2] = (fp[2] - cu->loc[2]) / cu->size[2]; } } } - else if (dl->type==DL_SURF) { - int sizeu= dl->nr, sizev= dl->parts; + else if (dl->type == DL_SURF) { + int sizeu = dl->nr, sizev = dl->parts; /* exception as handled in convertblender.c too */ if (dl->flag & DL_CYCL_U) { @@ -1282,24 +1282,24 @@ float *BKE_curve_make_orco(Scene *scene, Object *ob) sizev++; } - for (u=0; u<sizev; u++) { - for (v=0; v<sizeu; v++, fp+=3) { + for (u = 0; u < sizev; u++) { + for (v = 0; v < sizeu; v++, fp += 3) { if (cu->flag & CU_UV_ORCO) { - fp[0]= 2.0f*u/(sizev - 1) - 1.0f; - fp[1]= 2.0f*v/(sizeu - 1) - 1.0f; - fp[2]= 0.0; + fp[0] = 2.0f * u / (sizev - 1) - 1.0f; + fp[1] = 2.0f * v / (sizeu - 1) - 1.0f; + fp[2] = 0.0; } else { float *vert; - int realv= v % dl->nr; - int realu= u % dl->parts; + int realv = v % dl->nr; + int realu = u % dl->parts; - vert= dl->verts + 3*(dl->nr*realu + realv); + vert = dl->verts + 3 * (dl->nr * realu + realv); 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]; - fp[2]= (fp[2]-cu->loc[2])/cu->size[2]; + fp[0] = (fp[0] - cu->loc[0]) / cu->size[0]; + fp[1] = (fp[1] - cu->loc[1]) / cu->size[1]; + fp[2] = (fp[2] - cu->loc[2]) / cu->size[2]; } } } @@ -1321,99 +1321,99 @@ void BKE_curve_bevel_make(Scene *scene, Object *ob, ListBase *disp, int forRende float *fp, facx, facy, angle, dangle; int nr, a; - cu= ob->data; + cu = ob->data; disp->first = disp->last = NULL; /* if a font object is being edited, then do nothing */ // XXX if ( ob == obedit && ob->type == OB_FONT ) return; if (cu->bevobj) { - if (cu->bevobj->type!=OB_CURVE) return; + if (cu->bevobj->type != OB_CURVE) return; - bevcu= cu->bevobj->data; - if (bevcu->ext1==0.0f && bevcu->ext2==0.0f) { - ListBase bevdisp= {NULL, NULL}; - facx= cu->bevobj->size[0]; - facy= cu->bevobj->size[1]; + bevcu = cu->bevobj->data; + if (bevcu->ext1 == 0.0f && bevcu->ext2 == 0.0f) { + ListBase bevdisp = {NULL, NULL}; + facx = cu->bevobj->size[0]; + facy = cu->bevobj->size[1]; if (forRender) { makeDispListCurveTypes_forRender(scene, cu->bevobj, &bevdisp, NULL, 0); - dl= bevdisp.first; + dl = bevdisp.first; } else { - dl= cu->bevobj->disp.first; - if (dl==NULL) { + dl = cu->bevobj->disp.first; + if (dl == NULL) { makeDispListCurveTypes(scene, cu->bevobj, 0); - dl= cu->bevobj->disp.first; + dl = cu->bevobj->disp.first; } } while (dl) { if (ELEM(dl->type, DL_POLY, DL_SEGM)) { - dlnew= MEM_mallocN(sizeof(DispList), "makebevelcurve1"); - *dlnew= *dl; - dlnew->verts= MEM_mallocN(3*sizeof(float)*dl->parts*dl->nr, "makebevelcurve1"); - memcpy(dlnew->verts, dl->verts, 3*sizeof(float)*dl->parts*dl->nr); + dlnew = MEM_mallocN(sizeof(DispList), "makebevelcurve1"); + *dlnew = *dl; + dlnew->verts = MEM_mallocN(3 * sizeof(float) * dl->parts * dl->nr, "makebevelcurve1"); + memcpy(dlnew->verts, dl->verts, 3 * sizeof(float) * dl->parts * dl->nr); - if (dlnew->type==DL_SEGM) dlnew->flag |= (DL_FRONT_CURVE|DL_BACK_CURVE); + if (dlnew->type == DL_SEGM) dlnew->flag |= (DL_FRONT_CURVE | DL_BACK_CURVE); BLI_addtail(disp, dlnew); - fp= dlnew->verts; - nr= dlnew->parts*dlnew->nr; + fp = dlnew->verts; + nr = dlnew->parts * dlnew->nr; while (nr--) { - fp[2]= fp[1]*facy; - fp[1]= -fp[0]*facx; - fp[0]= 0.0; - fp+= 3; + fp[2] = fp[1] * facy; + fp[1] = -fp[0] * facx; + fp[0] = 0.0; + fp += 3; } } - dl= dl->next; + dl = dl->next; } freedisplist(&bevdisp); } } - else if (cu->ext1==0.0f && cu->ext2==0.0f) { + else if (cu->ext1 == 0.0f && cu->ext2 == 0.0f) { ; } - else if (cu->ext2==0.0f) { - dl= MEM_callocN(sizeof(DispList), "makebevelcurve2"); - dl->verts= MEM_mallocN(2*3*sizeof(float), "makebevelcurve2"); + else if (cu->ext2 == 0.0f) { + dl = MEM_callocN(sizeof(DispList), "makebevelcurve2"); + dl->verts = MEM_mallocN(2 * 3 * sizeof(float), "makebevelcurve2"); BLI_addtail(disp, dl); - dl->type= DL_SEGM; - dl->parts= 1; - dl->flag= DL_FRONT_CURVE|DL_BACK_CURVE; - dl->nr= 2; - - fp= dl->verts; - fp[0]= fp[1]= 0.0; - fp[2]= -cu->ext1; - fp[3]= fp[4]= 0.0; - fp[5]= cu->ext1; - } - else if ( (cu->flag & (CU_FRONT|CU_BACK))==0 && cu->ext1==0.0f) { // we make a full round bevel in that case + dl->type = DL_SEGM; + dl->parts = 1; + dl->flag = DL_FRONT_CURVE | DL_BACK_CURVE; + dl->nr = 2; + + fp = dl->verts; + fp[0] = fp[1] = 0.0; + fp[2] = -cu->ext1; + fp[3] = fp[4] = 0.0; + fp[5] = cu->ext1; + } + else if ( (cu->flag & (CU_FRONT | CU_BACK)) == 0 && cu->ext1 == 0.0f) { // we make a full round bevel in that case - nr= 4+ 2*cu->bevresol; + nr = 4 + 2 * cu->bevresol; - dl= MEM_callocN(sizeof(DispList), "makebevelcurve p1"); - dl->verts= MEM_mallocN(nr*3*sizeof(float), "makebevelcurve p1"); + dl = MEM_callocN(sizeof(DispList), "makebevelcurve p1"); + dl->verts = MEM_mallocN(nr * 3 * sizeof(float), "makebevelcurve p1"); BLI_addtail(disp, dl); - dl->type= DL_POLY; - dl->parts= 1; - dl->flag= DL_BACK_CURVE; - dl->nr= nr; + dl->type = DL_POLY; + dl->parts = 1; + dl->flag = DL_BACK_CURVE; + dl->nr = nr; /* a circle */ - fp= dl->verts; - dangle= (2.0f*(float)M_PI/(nr)); - angle= -(nr-1)*dangle; - - for (a=0; a<nr; a++) { - fp[0]= 0.0; - fp[1]= (cosf(angle)*(cu->ext2)); - fp[2]= (sinf(angle)*(cu->ext2)) - cu->ext1; - angle+= dangle; - fp+= 3; + fp = dl->verts; + dangle = (2.0f * (float)M_PI / (nr)); + angle = -(nr - 1) * dangle; + + for (a = 0; a < nr; a++) { + fp[0] = 0.0; + fp[1] = (cosf(angle) * (cu->ext2)); + fp[2] = (sinf(angle) * (cu->ext2)) - cu->ext1; + angle += dangle; + fp += 3; } } else { @@ -1423,87 +1423,87 @@ void BKE_curve_bevel_make(Scene *scene, Object *ob, ListBase *disp, int forRende /* part 1, back */ if ((cu->flag & CU_BACK) || !(cu->flag & CU_FRONT)) { - dnr= nr= 2+ cu->bevresol; - if ( (cu->flag & (CU_FRONT|CU_BACK))==0) - nr= 3+ 2*cu->bevresol; + dnr = nr = 2 + cu->bevresol; + if ( (cu->flag & (CU_FRONT | CU_BACK)) == 0) + nr = 3 + 2 * cu->bevresol; - dl= MEM_callocN(sizeof(DispList), "makebevelcurve p1"); - dl->verts= MEM_mallocN(nr*3*sizeof(float), "makebevelcurve p1"); + dl = MEM_callocN(sizeof(DispList), "makebevelcurve p1"); + dl->verts = MEM_mallocN(nr * 3 * sizeof(float), "makebevelcurve p1"); BLI_addtail(disp, dl); - dl->type= DL_SEGM; - dl->parts= 1; - dl->flag= DL_BACK_CURVE; - dl->nr= nr; + dl->type = DL_SEGM; + dl->parts = 1; + dl->flag = DL_BACK_CURVE; + dl->nr = nr; /* half a circle */ - fp= dl->verts; - dangle= (0.5*M_PI/(dnr-1)); - angle= -(nr-1)*dangle; + fp = dl->verts; + dangle = (0.5 * M_PI / (dnr - 1)); + angle = -(nr - 1) * dangle; - for (a=0; a<nr; a++) { - fp[0]= 0.0; - fp[1]= (float)(cosf(angle)*(cu->ext2)); - fp[2]= (float)(sinf(angle)*(cu->ext2)) - cu->ext1; - angle+= dangle; - fp+= 3; + for (a = 0; a < nr; a++) { + fp[0] = 0.0; + fp[1] = (float)(cosf(angle) * (cu->ext2)); + fp[2] = (float)(sinf(angle) * (cu->ext2)) - cu->ext1; + angle += dangle; + fp += 3; } } /* part 2, sidefaces */ - if (cu->ext1!=0.0f) { - nr= 2; + if (cu->ext1 != 0.0f) { + nr = 2; - dl= MEM_callocN(sizeof(DispList), "makebevelcurve p2"); - dl->verts= MEM_callocN(nr*3*sizeof(float), "makebevelcurve p2"); + dl = MEM_callocN(sizeof(DispList), "makebevelcurve p2"); + dl->verts = MEM_callocN(nr * 3 * sizeof(float), "makebevelcurve p2"); BLI_addtail(disp, dl); - dl->type= DL_SEGM; - dl->parts= 1; - dl->nr= nr; - - fp= dl->verts; - fp[1]= cu->ext2; - fp[2]= -cu->ext1; - fp[4]= cu->ext2; - fp[5]= cu->ext1; - - if ( (cu->flag & (CU_FRONT|CU_BACK))==0) { - dl= MEM_dupallocN(dl); - dl->verts= MEM_dupallocN(dl->verts); + dl->type = DL_SEGM; + dl->parts = 1; + dl->nr = nr; + + fp = dl->verts; + fp[1] = cu->ext2; + fp[2] = -cu->ext1; + fp[4] = cu->ext2; + fp[5] = cu->ext1; + + if ( (cu->flag & (CU_FRONT | CU_BACK)) == 0) { + dl = MEM_dupallocN(dl); + dl->verts = MEM_dupallocN(dl->verts); BLI_addtail(disp, dl); - fp= dl->verts; - fp[1]= -fp[1]; - fp[2]= -fp[2]; - fp[4]= -fp[4]; - fp[5]= -fp[5]; + fp = dl->verts; + fp[1] = -fp[1]; + fp[2] = -fp[2]; + fp[4] = -fp[4]; + fp[5] = -fp[5]; } } /* part 3, front */ if ((cu->flag & CU_FRONT) || !(cu->flag & CU_BACK)) { - dnr= nr= 2+ cu->bevresol; - if ( (cu->flag & (CU_FRONT|CU_BACK))==0) - nr= 3+ 2*cu->bevresol; + dnr = nr = 2 + cu->bevresol; + if ( (cu->flag & (CU_FRONT | CU_BACK)) == 0) + nr = 3 + 2 * cu->bevresol; - dl= MEM_callocN(sizeof(DispList), "makebevelcurve p3"); - dl->verts= MEM_mallocN(nr*3*sizeof(float), "makebevelcurve p3"); + dl = MEM_callocN(sizeof(DispList), "makebevelcurve p3"); + dl->verts = MEM_mallocN(nr * 3 * sizeof(float), "makebevelcurve p3"); BLI_addtail(disp, dl); - dl->type= DL_SEGM; - dl->flag= DL_FRONT_CURVE; - dl->parts= 1; - dl->nr= nr; + dl->type = DL_SEGM; + dl->flag = DL_FRONT_CURVE; + dl->parts = 1; + dl->nr = nr; /* half a circle */ - fp= dl->verts; - angle= 0.0; - dangle= (0.5*M_PI/(dnr-1)); + fp = dl->verts; + angle = 0.0; + dangle = (0.5 * M_PI / (dnr - 1)); - for (a=0; a<nr; a++) { - fp[0]= 0.0; - fp[1]= (float)(cosf(angle)*(cu->ext2)); - fp[2]= (float)(sinf(angle)*(cu->ext2)) + cu->ext1; - angle+= dangle; - fp+= 3; + for (a = 0; a < nr; a++) { + fp[0] = 0.0; + fp[1] = (float)(cosf(angle) * (cu->ext2)); + fp[2] = (float)(sinf(angle) * (cu->ext2)) + cu->ext1; + angle += dangle; + fp += 3; } } } @@ -1521,25 +1521,25 @@ static int cu_isectLL(const float v1[3], const float v2[3], const float v3[3], c */ float deler; - deler= (v1[cox]-v2[cox])*(v3[coy]-v4[coy])-(v3[cox]-v4[cox])*(v1[coy]-v2[coy]); - if (deler==0.0f) return -1; + deler = (v1[cox] - v2[cox]) * (v3[coy] - v4[coy]) - (v3[cox] - v4[cox]) * (v1[coy] - v2[coy]); + if (deler == 0.0f) return -1; - *labda= (v1[coy]-v3[coy])*(v3[cox]-v4[cox])-(v1[cox]-v3[cox])*(v3[coy]-v4[coy]); - *labda= -(*labda/deler); + *labda = (v1[coy] - v3[coy]) * (v3[cox] - v4[cox]) - (v1[cox] - v3[cox]) * (v3[coy] - v4[coy]); + *labda = -(*labda / deler); - deler= v3[coy]-v4[coy]; - if (deler==0) { - deler=v3[cox]-v4[cox]; - *mu= -(*labda*(v2[cox]-v1[cox])+v1[cox]-v3[cox])/deler; + deler = v3[coy] - v4[coy]; + if (deler == 0) { + deler = v3[cox] - v4[cox]; + *mu = -(*labda * (v2[cox] - v1[cox]) + v1[cox] - v3[cox]) / deler; } else { - *mu= -(*labda*(v2[coy]-v1[coy])+v1[coy]-v3[coy])/deler; + *mu = -(*labda * (v2[coy] - v1[coy]) + v1[coy] - v3[coy]) / deler; } - vec[cox]= *labda*(v2[cox]-v1[cox])+v1[cox]; - vec[coy]= *labda*(v2[coy]-v1[coy])+v1[coy]; + vec[cox] = *labda * (v2[cox] - v1[cox]) + v1[cox]; + vec[coy] = *labda * (v2[coy] - v1[coy]) + v1[coy]; - if (*labda>=0.0f && *labda<=1.0f && *mu>=0.0f && *mu<=1.0f) { - if (*labda==0.0f || *labda==1.0f || *mu==0.0f || *mu==1.0f) return 1; + if (*labda >= 0.0f && *labda <= 1.0f && *mu >= 0.0f && *mu <= 1.0f) { + if (*labda == 0.0f || *labda == 1.0f || *mu == 0.0f || *mu == 1.0f) return 1; return 2; } return 0; @@ -1552,45 +1552,45 @@ static short bevelinside(BevList *bl1, BevList *bl2) /* returns '1' if correct hole */ BevPoint *bevp, *prevbevp; float min, max, vec[3], hvec1[3], hvec2[3], lab, mu; - int nr, links=0, rechts=0, mode; + int nr, links = 0, rechts = 0, mode; /* take first vertex of possible hole */ - bevp= (BevPoint *)(bl2+1); - hvec1[0]= bevp->vec[0]; - hvec1[1]= bevp->vec[1]; - hvec1[2]= 0.0; + bevp = (BevPoint *)(bl2 + 1); + hvec1[0] = bevp->vec[0]; + hvec1[1] = bevp->vec[1]; + hvec1[2] = 0.0; copy_v3_v3(hvec2, hvec1); - hvec2[0]+=1000; + hvec2[0] += 1000; /* test it with all edges of potential surounding poly */ /* count number of transitions left-right */ - bevp= (BevPoint *)(bl1+1); - nr= bl1->nr; - prevbevp= bevp+(nr-1); + bevp = (BevPoint *)(bl1 + 1); + nr = bl1->nr; + prevbevp = bevp + (nr - 1); while (nr--) { - min= prevbevp->vec[1]; - max= bevp->vec[1]; - if (max<min) { - min= max; - max= prevbevp->vec[1]; - } - if (min!=max) { - if (min<=hvec1[1] && max>=hvec1[1]) { + min = prevbevp->vec[1]; + max = bevp->vec[1]; + if (max < min) { + min = max; + max = prevbevp->vec[1]; + } + if (min != max) { + if (min <= hvec1[1] && max >= hvec1[1]) { /* there's a transition, calc intersection point */ - mode= cu_isectLL(prevbevp->vec, bevp->vec, hvec1, hvec2, 0, 1, &lab, &mu, vec); + mode = cu_isectLL(prevbevp->vec, bevp->vec, hvec1, hvec2, 0, 1, &lab, &mu, vec); /* if lab==0.0 or lab==1.0 then the edge intersects exactly a transition * only allow for one situation: we choose lab= 1.0 */ if (mode >= 0 && lab != 0.0f) { - if (vec[0]<hvec1[0]) links++; + if (vec[0] < hvec1[0]) links++; else rechts++; } } } - prevbevp= bevp; + prevbevp = bevp; bevp++; } @@ -1607,10 +1607,10 @@ struct bevelsort { static int vergxcobev(const void *a1, const void *a2) { - const struct bevelsort *x1=a1, *x2=a2; + const struct bevelsort *x1 = a1, *x2 = a2; - if ( x1->left > x2->left ) return 1; - else if ( x1->left < x2->left) return -1; + if (x1->left > x2->left) return 1; + else if (x1->left < x2->left) return -1; return 0; } @@ -1620,37 +1620,37 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si { float t01, t02, x3, y3; - t01= (float)sqrt(x1*x1+y1*y1); - t02= (float)sqrt(x2*x2+y2*y2); - if (t01==0.0f) t01= 1.0f; - if (t02==0.0f) t02= 1.0f; + t01 = (float)sqrt(x1 * x1 + y1 * y1); + t02 = (float)sqrt(x2 * x2 + y2 * y2); + if (t01 == 0.0f) t01 = 1.0f; + if (t02 == 0.0f) t02 = 1.0f; - x1/=t01; - y1/=t01; - x2/=t02; - y2/=t02; + x1 /= t01; + y1 /= t01; + x2 /= t02; + y2 /= t02; - t02= x1*x2+y1*y2; - if (fabs(t02)>=1.0) t02= .5*M_PI; - else t02= (saacos(t02))/2.0f; + t02 = x1 * x2 + y1 * y2; + if (fabs(t02) >= 1.0) t02 = .5 * M_PI; + else t02 = (saacos(t02)) / 2.0f; - t02= (float)sin(t02); - if (t02==0.0f) t02= 1.0f; + t02 = (float)sin(t02); + if (t02 == 0.0f) t02 = 1.0f; - x3= x1-x2; - y3= y1-y2; - if (x3==0 && y3==0) { - x3= y1; - y3= -x1; + x3 = x1 - x2; + y3 = y1 - y2; + if (x3 == 0 && y3 == 0) { + x3 = y1; + y3 = -x1; } else { - t01= (float)sqrt(x3*x3+y3*y3); - x3/=t01; - y3/=t01; + t01 = (float)sqrt(x3 * x3 + y3 * y3); + x3 /= t01; + y3 /= t01; } - *sina= -y3/t02; - *cosa= x3/t02; + *sina = -y3 / t02; + *cosa = x3 / t02; } @@ -1660,55 +1660,55 @@ static void alfa_bezpart(BezTriple *prevbezt, BezTriple *bezt, Nurb *nu, float * float fac, dfac, t[4]; int a; - if (tilt_array==NULL && radius_array==NULL) + if (tilt_array == NULL && radius_array == NULL) return; - last= nu->bezt+(nu->pntsu-1); + last = nu->bezt + (nu->pntsu - 1); /* returns a point */ - if (prevbezt==nu->bezt) { - if (nu->flagu & CU_NURB_CYCLIC) pprev= last; - else pprev= prevbezt; + if (prevbezt == nu->bezt) { + if (nu->flagu & CU_NURB_CYCLIC) pprev = last; + else pprev = prevbezt; } - else pprev= prevbezt-1; + else pprev = prevbezt - 1; /* next point */ - if (bezt==last) { - if (nu->flagu & CU_NURB_CYCLIC) next= nu->bezt; - else next= bezt; + if (bezt == last) { + if (nu->flagu & CU_NURB_CYCLIC) next = nu->bezt; + else next = bezt; } - else next= bezt+1; + else next = bezt + 1; - fac= 0.0; - dfac= 1.0f/(float)resolu; + fac = 0.0; + dfac = 1.0f / (float)resolu; - for (a=0; a<resolu; a++, fac+= dfac) { + for (a = 0; a < resolu; a++, fac += dfac) { if (tilt_array) { - if (nu->tilt_interp==KEY_CU_EASE) { /* May as well support for tilt also 2.47 ease interp */ - *tilt_array = prevbezt->alfa + (bezt->alfa - prevbezt->alfa)*(3.0f*fac*fac - 2.0f*fac*fac*fac); + if (nu->tilt_interp == KEY_CU_EASE) { /* May as well support for tilt also 2.47 ease interp */ + *tilt_array = prevbezt->alfa + (bezt->alfa - prevbezt->alfa) * (3.0f * fac * fac - 2.0f * fac * fac * fac); } else { key_curve_position_weights(fac, t, nu->tilt_interp); - *tilt_array= t[0]*pprev->alfa + t[1]*prevbezt->alfa + t[2]*bezt->alfa + t[3]*next->alfa; + *tilt_array = t[0] * pprev->alfa + t[1] * prevbezt->alfa + t[2] * bezt->alfa + t[3] * next->alfa; } tilt_array = (float *)(((char *)tilt_array) + stride); } if (radius_array) { - if (nu->radius_interp==KEY_CU_EASE) { + if (nu->radius_interp == KEY_CU_EASE) { /* Support 2.47 ease interp * Note! - this only takes the 2 points into account, * giving much more localized results to changes in radius, sometimes you want that */ - *radius_array = prevbezt->radius + (bezt->radius - prevbezt->radius)*(3.0f*fac*fac - 2.0f*fac*fac*fac); + *radius_array = prevbezt->radius + (bezt->radius - prevbezt->radius) * (3.0f * fac * fac - 2.0f * fac * fac * fac); } else { /* reuse interpolation from tilt if we can */ - if (tilt_array==NULL || nu->tilt_interp != nu->radius_interp) { + if (tilt_array == NULL || nu->tilt_interp != nu->radius_interp) { key_curve_position_weights(fac, t, nu->radius_interp); } - *radius_array= t[0]*pprev->radius + t[1]*prevbezt->radius + t[2]*bezt->radius + t[3]*next->radius; + *radius_array = t[0] * pprev->radius + t[1] * prevbezt->radius + t[2] * bezt->radius + t[3] * next->radius; } radius_array = (float *)(((char *)radius_array) + stride); @@ -1716,7 +1716,7 @@ static void alfa_bezpart(BezTriple *prevbezt, BezTriple *bezt, Nurb *nu, float * if (weight_array) { /* basic interpolation for now, could copy tilt interp too */ - *weight_array = prevbezt->weight + (bezt->weight - prevbezt->weight)*(3.0f*fac*fac - 2.0f*fac*fac*fac); + *weight_array = prevbezt->weight + (bezt->weight - prevbezt->weight) * (3.0f * fac * fac - 2.0f * fac * fac * fac); weight_array = (float *)(((char *)weight_array) + stride); } @@ -1732,14 +1732,14 @@ static void bevel_list_cyclic_fix_3D(BevList *bl) { BevPoint *bevp, *bevp1; - bevp= (BevPoint *)(bl+1); - bevp1= bevp+1; + bevp = (BevPoint *)(bl + 1); + bevp1 = bevp + 1; 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; + bevp = (BevPoint *)(bl + 1); + bevp += (bl->nr - 1); + bevp1 = bevp - 1; copy_qt_qt(bevp->quat, bevp1->quat); copy_v3_v3(bevp->dir, bevp1->dir); copy_v3_v3(bevp->tan, bevp1->tan); @@ -1750,17 +1750,17 @@ static void bevel_list_calc_bisect(BevList *bl) BevPoint *bevp2, *bevp1, *bevp0; int nr; - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { /* totally simple */ bisect_v3_v3v3v3(bevp1->dir, bevp0->vec, bevp1->vec, bevp2->vec); - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } } @@ -1769,17 +1769,17 @@ static void bevel_list_flip_tangents(BevList *bl) BevPoint *bevp2, *bevp1, *bevp0; int nr; - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { if (RAD2DEGF(angle_v2v2(bevp0->tan, bevp1->tan)) > 90.0f) negate_v3(bevp1->tan); - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } } @@ -1790,16 +1790,16 @@ static void bevel_list_apply_tilt(BevList *bl) int nr; float q[4]; - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); - nr= bl->nr; + nr = bl->nr; while (nr--) { axis_angle_to_quat(q, bevp1->dir, bevp1->alfa); mul_qt_qtqt(bevp1->quat, q, bevp1->quat); normalize_qt(bevp1->quat); - bevp1= bevp2; + bevp1 = bevp2; bevp2++; } } @@ -1813,23 +1813,23 @@ static void bevel_list_smooth(BevList *bl, int smooth_iter) float bevp0_quat[4]; int a; - for (a=0; a < smooth_iter; a++) { + for (a = 0; a < smooth_iter; a++) { - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; - if (bl->poly== -1) { /* check its not cyclic */ + if (bl->poly == -1) { /* check its not cyclic */ /* skip the first point */ /* bevp0= bevp1; */ - bevp1= bevp2; + bevp1 = bevp2; bevp2++; nr--; - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; nr--; @@ -1855,7 +1855,7 @@ static void bevel_list_smooth(BevList *bl, int smooth_iter) /* bevp0= bevp1; */ /* UNUSED */ - bevp1= bevp2; + bevp1 = bevp2; bevp2++; } } @@ -1866,18 +1866,18 @@ static void make_bevel_list_3D_zup(BevList *bl) BevPoint *bevp2, *bevp1, *bevp0; /* standard for all make_bevel_list_3D_* funcs */ int nr; - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { /* totally simple */ bisect_v3_v3v3v3(bevp1->dir, bevp0->vec, bevp1->vec, bevp2->vec); vec_to_quat(bevp1->quat, bevp1->dir, 5, 1); - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } } @@ -1890,18 +1890,18 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) bevel_list_calc_bisect(bl); - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { - if (nr+4 > bl->nr) { /* first time and second time, otherwise first point adjusts last */ + if (nr + 4 > bl->nr) { /* first time and second time, otherwise first point adjusts last */ vec_to_quat(bevp1->quat, bevp1->dir, 5, 1); } else { - float angle= angle_normalized_v3v3(bevp0->dir, bevp1->dir); + float angle = angle_normalized_v3v3(bevp0->dir, bevp1->dir); if (angle > 0.0f) { /* otherwise we can keep as is */ float cross_tmp[3]; @@ -1914,8 +1914,8 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) } } - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } @@ -1932,14 +1932,14 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) * * this is why we compare last with second last * */ - float vec_1[3]= {0, 1, 0}, vec_2[3]= {0, 1, 0}, angle, ang_fac, cross_tmp[3]; + float vec_1[3] = {0, 1, 0}, vec_2[3] = {0, 1, 0}, angle, ang_fac, cross_tmp[3]; BevPoint *bevp_first; BevPoint *bevp_last; - bevp_first= (BevPoint *)(bl+1); - bevp_first+= bl->nr-1; + bevp_first = (BevPoint *)(bl + 1); + bevp_first += bl->nr - 1; bevp_last = bevp_first; bevp_last--; @@ -1950,7 +1950,7 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) normalize_v3(vec_2); /* align the vector, can avoid this and it looks 98% OK but - * better to align the angle quat roll's before comparing */ + * better to align the angle quat roll's before comparing */ { cross_v3_v3v3(cross_tmp, bevp_last->dir, bevp_first->dir); angle = angle_normalized_v3v3(bevp_first->dir, bevp_last->dir); @@ -1958,7 +1958,7 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) mul_qt_v3(q, vec_2); } - angle= angle_normalized_v3v3(vec_1, vec_2); + angle = angle_normalized_v3v3(vec_1, vec_2); /* flip rotation if needs be */ cross_v3_v3v3(cross_tmp, vec_1, vec_2); @@ -1966,19 +1966,19 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) if (angle_normalized_v3v3(bevp_first->dir, cross_tmp) < DEG2RADF(90.0f)) angle = -angle; - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { - ang_fac= angle * (1.0f-((float)nr/bl->nr)); /* also works */ + ang_fac = angle * (1.0f - ((float)nr / bl->nr)); /* also works */ axis_angle_to_quat(q, bevp1->dir, ang_fac); mul_qt_qtqt(bevp1->quat, q, bevp1->quat); - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } } @@ -1992,36 +1992,36 @@ static void make_bevel_list_3D_tangent(BevList *bl) float bevp0_tan[3], cross_tmp[3]; bevel_list_calc_bisect(bl); - if (bl->poly== -1) /* check its not cyclic */ - bevel_list_cyclic_fix_3D(bl); // XXX - run this now so tangents will be right before doing the flipping + if (bl->poly == -1) /* check its not cyclic */ + bevel_list_cyclic_fix_3D(bl); // XXX - run this now so tangents will be right before doing the flipping bevel_list_flip_tangents(bl); /* correct the tangents */ - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { cross_v3_v3v3(cross_tmp, bevp1->tan, bevp1->dir); cross_v3_v3v3(bevp1->tan, cross_tmp, bevp1->dir); normalize_v3(bevp1->tan); - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } /* now for the real twist calc */ - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; copy_v3_v3(bevp0_tan, bevp0->tan); - nr= bl->nr; + nr = bl->nr; while (nr--) { /* make perpendicular, modify tan in place, is ok */ @@ -2033,7 +2033,7 @@ static void make_bevel_list_3D_tangent(BevList *bl) tri_to_quat(bevp1->quat, zero, cross_tmp, bevp1->tan); /* XXX - could be faster */ /* bevp0= bevp1; */ /* UNUSED */ - bevp1= bevp2; + bevp1 = bevp2; bevp2++; } } @@ -2041,17 +2041,17 @@ static void make_bevel_list_3D_tangent(BevList *bl) static void make_bevel_list_3D(BevList *bl, int smooth_iter, int twist_mode) { switch (twist_mode) { - case CU_TWIST_TANGENT: - make_bevel_list_3D_tangent(bl); - break; - case CU_TWIST_MINIMUM: - make_bevel_list_3D_minimum_twist(bl); - break; - default: /* CU_TWIST_Z_UP default, pre 2.49c */ - make_bevel_list_3D_zup(bl); + case CU_TWIST_TANGENT: + make_bevel_list_3D_tangent(bl); + break; + case CU_TWIST_MINIMUM: + make_bevel_list_3D_minimum_twist(bl); + break; + default: /* CU_TWIST_Z_UP default, pre 2.49c */ + make_bevel_list_3D_zup(bl); } - if (bl->poly== -1) /* check its not cyclic */ + if (bl->poly == -1) /* check its not cyclic */ bevel_list_cyclic_fix_3D(bl); if (smooth_iter) @@ -2067,8 +2067,8 @@ static void make_bevel_list_segment_3D(BevList *bl) { float q[4]; - BevPoint *bevp2= (BevPoint *)(bl+1); - BevPoint *bevp1= bevp2+1; + BevPoint *bevp2 = (BevPoint *)(bl + 1); + BevPoint *bevp1 = bevp2 + 1; /* simple quat/dir */ sub_v3_v3v3(bevp1->dir, bevp1->vec, bevp2->vec); @@ -2105,7 +2105,7 @@ void BKE_curve_bevelList_make(Object *ob) int do_tilt, do_radius, do_weight; /* this function needs an object, because of tflag and upflag */ - cu= ob->data; + cu = ob->data; /* do we need to calculate the radius for each point? */ /* do_radius = (cu->bevobj || cu->taperobj || (cu->flag & CU_FRONT) || (cu->flag & CU_BACK)) ? 0 : 1; */ @@ -2113,8 +2113,8 @@ void BKE_curve_bevelList_make(Object *ob) /* STEP 1: MAKE POLYS */ BLI_freelistN(&(cu->bev)); - if (cu->editnurb && ob->type!=OB_FONT) { - ListBase *nurbs= BKE_curve_editNurbs_get(cu); + if (cu->editnurb && ob->type != OB_FONT) { + ListBase *nurbs = BKE_curve_editNurbs_get(cu); nu = nurbs->first; } else { @@ -2131,78 +2131,78 @@ void BKE_curve_bevelList_make(Object *ob) /* check we are a single point? also check we are not a surface and that the orderu is sane, * enforced in the UI but can go wrong possibly */ if (!BKE_nurb_check_valid_u(nu)) { - bl= MEM_callocN(sizeof(BevList)+1*sizeof(BevPoint), "makeBevelList1"); + bl = MEM_callocN(sizeof(BevList) + 1 * sizeof(BevPoint), "makeBevelList1"); BLI_addtail(&(cu->bev), bl); - bl->nr= 0; + bl->nr = 0; } else { - if (G.rendering && cu->resolu_ren!=0) - resolu= cu->resolu_ren; + if (G.rendering && cu->resolu_ren != 0) + resolu = cu->resolu_ren; else - resolu= nu->resolu; + resolu = nu->resolu; if (nu->type == CU_POLY) { - len= nu->pntsu; - bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelList2"); + len = nu->pntsu; + bl = MEM_callocN(sizeof(BevList) + len * sizeof(BevPoint), "makeBevelList2"); BLI_addtail(&(cu->bev), bl); - if (nu->flagu & CU_NURB_CYCLIC) bl->poly= 0; - else bl->poly= -1; - bl->nr= len; - bl->dupe_nr= 0; - bevp= (BevPoint *)(bl+1); - bp= nu->bp; + if (nu->flagu & CU_NURB_CYCLIC) bl->poly = 0; + else bl->poly = -1; + bl->nr = len; + bl->dupe_nr = 0; + bevp = (BevPoint *)(bl + 1); + bp = nu->bp; while (len--) { copy_v3_v3(bevp->vec, bp->vec); - bevp->alfa= bp->alfa; - bevp->radius= bp->radius; - bevp->weight= bp->weight; - bevp->split_tag= TRUE; + bevp->alfa = bp->alfa; + bevp->radius = bp->radius; + bevp->weight = bp->weight; + bevp->split_tag = TRUE; bevp++; bp++; } } else if (nu->type == CU_BEZIER) { - len= resolu*(nu->pntsu+ (nu->flagu & CU_NURB_CYCLIC) -1)+1; /* in case last point is not cyclic */ - bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelBPoints"); + len = resolu * (nu->pntsu + (nu->flagu & CU_NURB_CYCLIC) - 1) + 1; /* in case last point is not cyclic */ + bl = MEM_callocN(sizeof(BevList) + len * sizeof(BevPoint), "makeBevelBPoints"); BLI_addtail(&(cu->bev), bl); - if (nu->flagu & CU_NURB_CYCLIC) bl->poly= 0; - else bl->poly= -1; - bevp= (BevPoint *)(bl+1); + if (nu->flagu & CU_NURB_CYCLIC) bl->poly = 0; + else bl->poly = -1; + bevp = (BevPoint *)(bl + 1); - a= nu->pntsu-1; - bezt= nu->bezt; + a = nu->pntsu - 1; + bezt = nu->bezt; if (nu->flagu & CU_NURB_CYCLIC) { a++; - prevbezt= nu->bezt+(nu->pntsu-1); + prevbezt = nu->bezt + (nu->pntsu - 1); } else { - prevbezt= bezt; + prevbezt = bezt; bezt++; } while (a--) { - if (prevbezt->h2==HD_VECT && bezt->h1==HD_VECT) { + if (prevbezt->h2 == HD_VECT && bezt->h1 == HD_VECT) { copy_v3_v3(bevp->vec, prevbezt->vec[1]); - bevp->alfa= prevbezt->alfa; - bevp->radius= prevbezt->radius; - bevp->weight= prevbezt->weight; - bevp->split_tag= TRUE; - bevp->dupe_tag= FALSE; + bevp->alfa = prevbezt->alfa; + bevp->radius = prevbezt->radius; + bevp->weight = prevbezt->weight; + bevp->split_tag = TRUE; + bevp->dupe_tag = FALSE; bevp++; bl->nr++; - bl->dupe_nr= 1; + bl->dupe_nr = 1; } else { /* always do all three, to prevent data hanging around */ int j; /* BevPoint must stay aligned to 4 so sizeof(BevPoint)/sizeof(float) works */ - for (j=0; j<3; j++) { + for (j = 0; j < 3; j++) { BKE_curve_forward_diff_bezier(prevbezt->vec[1][j], prevbezt->vec[2][j], bezt->vec[0][j], bezt->vec[1][j], &(bevp->vec[j]), resolu, sizeof(BevPoint)); @@ -2210,52 +2210,52 @@ void BKE_curve_bevelList_make(Object *ob) /* if both arrays are NULL do nothiong */ alfa_bezpart(prevbezt, bezt, nu, - do_tilt ? &bevp->alfa : NULL, - do_radius ? &bevp->radius : NULL, - do_weight ? &bevp->weight : NULL, + do_tilt ? &bevp->alfa : NULL, + do_radius ? &bevp->radius : NULL, + do_weight ? &bevp->weight : NULL, resolu, sizeof(BevPoint)); - if (cu->twist_mode==CU_TWIST_TANGENT) { + if (cu->twist_mode == CU_TWIST_TANGENT) { forward_diff_bezier_cotangent(prevbezt->vec[1], prevbezt->vec[2], bezt->vec[0], bezt->vec[1], bevp->tan, resolu, sizeof(BevPoint)); } /* indicate with handlecodes double points */ - if (prevbezt->h1==prevbezt->h2) { - if (prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->split_tag= TRUE; + if (prevbezt->h1 == prevbezt->h2) { + if (prevbezt->h1 == 0 || prevbezt->h1 == HD_VECT) bevp->split_tag = TRUE; } else { - if (prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->split_tag= TRUE; - else if (prevbezt->h2==0 || prevbezt->h2==HD_VECT) bevp->split_tag= TRUE; + if (prevbezt->h1 == 0 || prevbezt->h1 == HD_VECT) bevp->split_tag = TRUE; + else if (prevbezt->h2 == 0 || prevbezt->h2 == HD_VECT) bevp->split_tag = TRUE; } - bl->nr+= resolu; - bevp+= resolu; + bl->nr += resolu; + bevp += resolu; } - prevbezt= bezt; + prevbezt = bezt; bezt++; } - if ((nu->flagu & CU_NURB_CYCLIC)==0) { /* not cyclic: endpoint */ + if ((nu->flagu & CU_NURB_CYCLIC) == 0) { /* not cyclic: endpoint */ copy_v3_v3(bevp->vec, prevbezt->vec[1]); - bevp->alfa= prevbezt->alfa; - bevp->radius= prevbezt->radius; - bevp->weight= prevbezt->weight; + bevp->alfa = prevbezt->alfa; + bevp->radius = prevbezt->radius; + bevp->weight = prevbezt->weight; bl->nr++; } } else if (nu->type == CU_NURBS) { - if (nu->pntsv==1) { - len= (resolu*SEGMENTSU(nu)); + if (nu->pntsv == 1) { + len = (resolu * SEGMENTSU(nu)); - bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelList3"); + bl = MEM_callocN(sizeof(BevList) + len * sizeof(BevPoint), "makeBevelList3"); BLI_addtail(&(cu->bev), bl); - bl->nr= len; - bl->dupe_nr= 0; - if (nu->flagu & CU_NURB_CYCLIC) bl->poly= 0; - else bl->poly= -1; - bevp= (BevPoint *)(bl+1); + bl->nr = len; + bl->dupe_nr = 0; + if (nu->flagu & CU_NURB_CYCLIC) bl->poly = 0; + else bl->poly = -1; + bevp = (BevPoint *)(bl + 1); BKE_nurb_makeCurve(nu, &bevp->vec[0], do_tilt ? &bevp->alfa : NULL, @@ -2265,47 +2265,47 @@ void BKE_curve_bevelList_make(Object *ob) } } } - nu= nu->next; + nu = nu->next; } /* STEP 2: DOUBLE POINTS AND AUTOMATIC RESOLUTION, REDUCE DATABLOCKS */ - bl= cu->bev.first; + bl = cu->bev.first; while (bl) { if (bl->nr) { /* null bevel items come from single points */ - nr= bl->nr; - bevp1= (BevPoint *)(bl+1); - bevp0= bevp1+(nr-1); + nr = bl->nr; + bevp1 = (BevPoint *)(bl + 1); + bevp0 = bevp1 + (nr - 1); nr--; while (nr--) { - if ( fabs(bevp0->vec[0]-bevp1->vec[0])<0.00001 ) { - if ( fabs(bevp0->vec[1]-bevp1->vec[1])<0.00001 ) { - if ( fabs(bevp0->vec[2]-bevp1->vec[2])<0.00001 ) { - bevp0->dupe_tag= TRUE; + if (fabs(bevp0->vec[0] - bevp1->vec[0]) < 0.00001) { + if (fabs(bevp0->vec[1] - bevp1->vec[1]) < 0.00001) { + if (fabs(bevp0->vec[2] - bevp1->vec[2]) < 0.00001) { + bevp0->dupe_tag = TRUE; bl->dupe_nr++; } } } - bevp0= bevp1; + bevp0 = bevp1; bevp1++; } } - bl= bl->next; + bl = bl->next; } - bl= cu->bev.first; + bl = cu->bev.first; while (bl) { - blnext= bl->next; + blnext = bl->next; if (bl->nr && bl->dupe_nr) { - nr= bl->nr- bl->dupe_nr+1; /* +1 because vectorbezier sets flag too */ - blnew= MEM_mallocN(sizeof(BevList)+nr*sizeof(BevPoint), "makeBevelList4"); + nr = bl->nr - bl->dupe_nr + 1; /* +1 because vectorbezier sets flag too */ + blnew = MEM_mallocN(sizeof(BevList) + nr * sizeof(BevPoint), "makeBevelList4"); memcpy(blnew, bl, sizeof(BevList)); - blnew->nr= 0; + blnew->nr = 0; BLI_remlink(&(cu->bev), bl); - BLI_insertlinkbefore(&(cu->bev), blnext, blnew); /* to make sure bevlijst is tuned with nurblist */ - bevp0= (BevPoint *)(bl+1); - bevp1= (BevPoint *)(blnew+1); - nr= bl->nr; + BLI_insertlinkbefore(&(cu->bev), blnext, blnew); /* to make sure bevlijst is tuned with nurblist */ + bevp0 = (BevPoint *)(bl + 1); + bevp1 = (BevPoint *)(blnew + 1); + nr = bl->nr; while (nr--) { - if (bevp0->dupe_tag==0) { + if (bevp0->dupe_tag == 0) { memcpy(bevp1, bevp0, sizeof(BevPoint)); bevp1++; blnew->nr++; @@ -2313,84 +2313,84 @@ void BKE_curve_bevelList_make(Object *ob) bevp0++; } MEM_freeN(bl); - blnew->dupe_nr= 0; + blnew->dupe_nr = 0; } - bl= blnext; + bl = blnext; } /* STEP 3: POLYS COUNT AND AUTOHOLE */ - bl= cu->bev.first; - poly= 0; + bl = cu->bev.first; + poly = 0; while (bl) { - if (bl->nr && bl->poly>=0) { + if (bl->nr && bl->poly >= 0) { poly++; - bl->poly= poly; - bl->hole= 0; + bl->poly = poly; + bl->hole = 0; } - bl= bl->next; + bl = bl->next; } /* find extreme left points, also test (turning) direction */ - if (poly>0) { - sd= sortdata= MEM_mallocN(sizeof(struct bevelsort)*poly, "makeBevelList5"); - bl= cu->bev.first; + if (poly > 0) { + sd = sortdata = MEM_mallocN(sizeof(struct bevelsort) * poly, "makeBevelList5"); + bl = cu->bev.first; while (bl) { - if (bl->poly>0) { + if (bl->poly > 0) { - min= 300000.0; - bevp= (BevPoint *)(bl+1); - nr= bl->nr; + min = 300000.0; + bevp = (BevPoint *)(bl + 1); + nr = bl->nr; while (nr--) { - if (min>bevp->vec[0]) { - min= bevp->vec[0]; - bevp1= bevp; + if (min > bevp->vec[0]) { + min = bevp->vec[0]; + bevp1 = bevp; } bevp++; } - sd->bl= bl; - sd->left= min; + sd->bl = bl; + sd->left = min; - bevp= (BevPoint *)(bl+1); - if (bevp1== bevp) bevp0= bevp+ (bl->nr-1); - else bevp0= bevp1-1; - bevp= bevp+ (bl->nr-1); - if (bevp1== bevp) bevp2= (BevPoint *)(bl+1); - else bevp2= bevp1+1; + bevp = (BevPoint *)(bl + 1); + if (bevp1 == bevp) bevp0 = bevp + (bl->nr - 1); + else bevp0 = bevp1 - 1; + bevp = bevp + (bl->nr - 1); + if (bevp1 == bevp) bevp2 = (BevPoint *)(bl + 1); + else bevp2 = bevp1 + 1; - inp= (bevp1->vec[0]- bevp0->vec[0]) * (bevp0->vec[1]- bevp2->vec[1]) + (bevp0->vec[1]- bevp1->vec[1]) * (bevp0->vec[0]- bevp2->vec[0]); + inp = (bevp1->vec[0] - bevp0->vec[0]) * (bevp0->vec[1] - bevp2->vec[1]) + (bevp0->vec[1] - bevp1->vec[1]) * (bevp0->vec[0] - bevp2->vec[0]); - if (inp > 0.0f) sd->dir= 1; - else sd->dir= 0; + if (inp > 0.0f) sd->dir = 1; + else sd->dir = 0; sd++; } - bl= bl->next; + bl = bl->next; } qsort(sortdata, poly, sizeof(struct bevelsort), vergxcobev); - sd= sortdata+1; - for (a=1; a<poly; a++, sd++) { - bl= sd->bl; /* is bl a hole? */ - sd1= sortdata+ (a-1); - for (b=a-1; b>=0; b--, sd1--) { /* all polys to the left */ + sd = sortdata + 1; + for (a = 1; a < poly; a++, sd++) { + bl = sd->bl; /* is bl a hole? */ + sd1 = sortdata + (a - 1); + for (b = a - 1; b >= 0; b--, sd1--) { /* all polys to the left */ if (bevelinside(sd1->bl, bl)) { - bl->hole= 1- sd1->bl->hole; + bl->hole = 1 - sd1->bl->hole; break; } } } /* turning direction */ - if ((cu->flag & CU_3D)==0) { - sd= sortdata; - for (a=0; a<poly; a++, sd++) { - if (sd->bl->hole==sd->dir) { - bl= sd->bl; - bevp1= (BevPoint *)(bl+1); - bevp2= bevp1+ (bl->nr-1); - nr= bl->nr/2; + if ((cu->flag & CU_3D) == 0) { + sd = sortdata; + for (a = 0; a < poly; a++, sd++) { + if (sd->bl->hole == sd->dir) { + bl = sd->bl; + bevp1 = (BevPoint *)(bl + 1); + bevp2 = bevp1 + (bl->nr - 1); + nr = bl->nr / 2; while (nr--) { SWAP(BevPoint, *bevp1, *bevp2); bevp1++; @@ -2403,40 +2403,40 @@ void BKE_curve_bevelList_make(Object *ob) } /* STEP 4: 2D-COSINES or 3D ORIENTATION */ - if ((cu->flag & CU_3D)==0) { + if ((cu->flag & CU_3D) == 0) { /* note: bevp->dir and bevp->quat are not needed for beveling but are * used when making a path from a 2D curve, therefor they need to be set - Campbell */ - bl= cu->bev.first; + bl = cu->bev.first; while (bl) { if (bl->nr < 2) { /* do nothing */ } - else if (bl->nr==2) { /* 2 pnt, treat separate */ - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+1; + else if (bl->nr == 2) { /* 2 pnt, treat separate */ + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + 1; - x1= bevp1->vec[0]- bevp2->vec[0]; - y1= bevp1->vec[1]- bevp2->vec[1]; + x1 = bevp1->vec[0] - bevp2->vec[0]; + y1 = bevp1->vec[1] - bevp2->vec[1]; calc_bevel_sin_cos(x1, y1, -x1, -y1, &(bevp1->sina), &(bevp1->cosa)); - bevp2->sina= bevp1->sina; - bevp2->cosa= bevp1->cosa; + bevp2->sina = bevp1->sina; + bevp2->cosa = bevp1->cosa; /* fill in dir & quat */ make_bevel_list_segment_3D(bl); } else { - bevp2= (BevPoint *)(bl+1); - bevp1= bevp2+(bl->nr-1); - bevp0= bevp1-1; + bevp2 = (BevPoint *)(bl + 1); + bevp1 = bevp2 + (bl->nr - 1); + bevp0 = bevp1 - 1; - nr= bl->nr; + nr = bl->nr; while (nr--) { - x1= bevp1->vec[0]- bevp0->vec[0]; - x2= bevp1->vec[0]- bevp2->vec[0]; - y1= bevp1->vec[1]- bevp0->vec[1]; - y2= bevp1->vec[1]- bevp2->vec[1]; + x1 = bevp1->vec[0] - bevp0->vec[0]; + x2 = bevp1->vec[0] - bevp2->vec[0]; + y1 = bevp1->vec[1] - bevp0->vec[1]; + y2 = bevp1->vec[1] - bevp2->vec[1]; calc_bevel_sin_cos(x1, y1, x2, y2, &(bevp1->sina), &(bevp1->cosa)); @@ -2446,44 +2446,44 @@ void BKE_curve_bevelList_make(Object *ob) vec_to_quat(bevp1->quat, bevp1->dir, 5, 1); /* done with inline make_bevel_list_3D_zup */ - bevp0= bevp1; - bevp1= bevp2; + bevp0 = bevp1; + bevp1 = bevp2; bevp2++; } /* correct non-cyclic cases */ - if (bl->poly== -1) { - bevp= (BevPoint *)(bl+1); - bevp1= bevp+1; - bevp->sina= bevp1->sina; - bevp->cosa= bevp1->cosa; - bevp= (BevPoint *)(bl+1); - bevp+= (bl->nr-1); - bevp1= bevp-1; - bevp->sina= bevp1->sina; - bevp->cosa= bevp1->cosa; + if (bl->poly == -1) { + bevp = (BevPoint *)(bl + 1); + bevp1 = bevp + 1; + bevp->sina = bevp1->sina; + bevp->cosa = bevp1->cosa; + bevp = (BevPoint *)(bl + 1); + bevp += (bl->nr - 1); + bevp1 = bevp - 1; + bevp->sina = bevp1->sina; + bevp->cosa = bevp1->cosa; /* correct for the dir/quat, see above why its needed */ bevel_list_cyclic_fix_3D(bl); } } - bl= bl->next; + bl = bl->next; } } else { /* 3D Curves */ - bl= cu->bev.first; + bl = cu->bev.first; while (bl) { if (bl->nr < 2) { /* do nothing */ } - else if (bl->nr==2) { /* 2 pnt, treat separate */ + else if (bl->nr == 2) { /* 2 pnt, treat separate */ make_bevel_list_segment_3D(bl); } else { - make_bevel_list_3D(bl, (int)(resolu*cu->twist_smooth), cu->twist_mode); + make_bevel_list_3D(bl, (int)(resolu * cu->twist_smooth), cu->twist_mode); } - bl= bl->next; + bl = bl->next; } } } @@ -2501,111 +2501,111 @@ static void calchandleNurb_intern(BezTriple *bezt, BezTriple *prev, BezTriple *n float *p1, *p2, *p3, pt[3]; float dvec_a[3], dvec_b[3]; float len, len_a, len_b; - const float eps= 1e-5; + const float eps = 1e-5; - if (bezt->h1==0 && bezt->h2==0) { + if (bezt->h1 == 0 && bezt->h2 == 0) { return; } - p2= bezt->vec[1]; + p2 = bezt->vec[1]; - if (prev==NULL) { - p3= next->vec[1]; - pt[0]= 2.0f*p2[0] - p3[0]; - pt[1]= 2.0f*p2[1] - p3[1]; - pt[2]= 2.0f*p2[2] - p3[2]; - p1= pt; + if (prev == NULL) { + p3 = next->vec[1]; + pt[0] = 2.0f * p2[0] - p3[0]; + pt[1] = 2.0f * p2[1] - p3[1]; + pt[2] = 2.0f * p2[2] - p3[2]; + p1 = pt; } else { - p1= prev->vec[1]; + p1 = prev->vec[1]; } - if (next==NULL) { - pt[0]= 2.0f*p2[0] - p1[0]; - pt[1]= 2.0f*p2[1] - p1[1]; - pt[2]= 2.0f*p2[2] - p1[2]; - p3= pt; + if (next == NULL) { + pt[0] = 2.0f * p2[0] - p1[0]; + pt[1] = 2.0f * p2[1] - p1[1]; + pt[2] = 2.0f * p2[2] - p1[2]; + p3 = pt; } else { - p3= next->vec[1]; + p3 = next->vec[1]; } sub_v3_v3v3(dvec_a, p2, p1); sub_v3_v3v3(dvec_b, p3, p2); if (mode != 0) { - len_a= dvec_a[0]; - len_b= dvec_b[0]; + len_a = dvec_a[0]; + len_b = dvec_b[0]; } else { - len_a= len_v3(dvec_a); - len_b= len_v3(dvec_b); + len_a = len_v3(dvec_a); + len_b = len_v3(dvec_b); } - if (len_a==0.0f) len_a=1.0f; - if (len_b==0.0f) len_b=1.0f; + if (len_a == 0.0f) len_a = 1.0f; + if (len_b == 0.0f) len_b = 1.0f; if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM) || ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) { /* auto */ float tvec[3]; - tvec[0]= dvec_b[0]/len_b + dvec_a[0]/len_a; - tvec[1]= dvec_b[1]/len_b + dvec_a[1]/len_a; - tvec[2]= dvec_b[2]/len_b + dvec_a[2]/len_a; - len= len_v3(tvec) * 2.5614f; + tvec[0] = dvec_b[0] / len_b + dvec_a[0] / len_a; + tvec[1] = dvec_b[1] / len_b + dvec_a[1] / len_a; + tvec[2] = dvec_b[2] / len_b + dvec_a[2] / len_a; + len = len_v3(tvec) * 2.5614f; - if (len!=0.0f) { - int leftviolate=0, rightviolate=0; /* for mode==2 */ + if (len != 0.0f) { + int leftviolate = 0, rightviolate = 0; /* for mode==2 */ - if (len_a>5.0f*len_b) len_a= 5.0f*len_b; - if (len_b>5.0f*len_a) len_b= 5.0f*len_a; + if (len_a > 5.0f * len_b) len_a = 5.0f * len_b; + if (len_b > 5.0f * len_a) len_b = 5.0f * len_a; if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM)) { - len_a/=len; - madd_v3_v3v3fl(p2-3, p2, tvec, -len_a); + len_a /= len; + madd_v3_v3v3fl(p2 - 3, p2, tvec, -len_a); - if ((bezt->h1==HD_AUTO_ANIM) && next && prev) { /* keep horizontal if extrema */ - float ydiff1= prev->vec[1][1] - bezt->vec[1][1]; - float ydiff2= next->vec[1][1] - bezt->vec[1][1]; + if ((bezt->h1 == HD_AUTO_ANIM) && next && prev) { /* keep horizontal if extrema */ + float ydiff1 = prev->vec[1][1] - bezt->vec[1][1]; + float ydiff2 = next->vec[1][1] - bezt->vec[1][1]; if ( (ydiff1 <= 0.0f && ydiff2 <= 0.0f) || (ydiff1 >= 0.0f && ydiff2 >= 0.0f) ) { - bezt->vec[0][1]= bezt->vec[1][1]; + bezt->vec[0][1] = bezt->vec[1][1]; } else { /* handles should not be beyond y coord of two others */ if (ydiff1 <= 0.0f) { if (prev->vec[1][1] > bezt->vec[0][1]) { - bezt->vec[0][1]= prev->vec[1][1]; - leftviolate= 1; + bezt->vec[0][1] = prev->vec[1][1]; + leftviolate = 1; } } else { if (prev->vec[1][1] < bezt->vec[0][1]) { - bezt->vec[0][1]= prev->vec[1][1]; - leftviolate= 1; + bezt->vec[0][1] = prev->vec[1][1]; + leftviolate = 1; } } } } } if (ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) { - len_b/=len; - madd_v3_v3v3fl(p2+3, p2, tvec, len_b); + len_b /= len; + madd_v3_v3v3fl(p2 + 3, p2, tvec, len_b); - if ((bezt->h2==HD_AUTO_ANIM) && next && prev) { /* keep horizontal if extrema */ - float ydiff1= prev->vec[1][1] - bezt->vec[1][1]; - float ydiff2= next->vec[1][1] - bezt->vec[1][1]; + if ((bezt->h2 == HD_AUTO_ANIM) && next && prev) { /* keep horizontal if extrema */ + float ydiff1 = prev->vec[1][1] - bezt->vec[1][1]; + float ydiff2 = next->vec[1][1] - bezt->vec[1][1]; if ( (ydiff1 <= 0.0f && ydiff2 <= 0.0f) || (ydiff1 >= 0.0f && ydiff2 >= 0.0f) ) { - bezt->vec[2][1]= bezt->vec[1][1]; + bezt->vec[2][1] = bezt->vec[1][1]; } else { /* andles should not be beyond y coord of two others */ if (ydiff1 <= 0.0f) { if (next->vec[1][1] < bezt->vec[2][1]) { - bezt->vec[2][1]= next->vec[1][1]; - rightviolate= 1; + bezt->vec[2][1] = next->vec[1][1]; + rightviolate = 1; } } else { if (next->vec[1][1] > bezt->vec[2][1]) { - bezt->vec[2][1]= next->vec[1][1]; - rightviolate= 1; + bezt->vec[2][1] = next->vec[1][1]; + rightviolate = 1; } } } @@ -2615,32 +2615,32 @@ static void calchandleNurb_intern(BezTriple *bezt, BezTriple *prev, BezTriple *n float h1[3], h2[3]; float dot; - sub_v3_v3v3(h1, p2-3, p2); - sub_v3_v3v3(h2, p2, p2+3); + sub_v3_v3v3(h1, p2 - 3, p2); + sub_v3_v3v3(h2, p2, p2 + 3); - len_a= normalize_v3(h1); - len_b= normalize_v3(h2); + len_a = normalize_v3(h1); + len_b = normalize_v3(h2); - dot= dot_v3v3(h1, h2); + dot = dot_v3v3(h1, h2); if (leftviolate) { mul_v3_fl(h1, dot * len_b); - sub_v3_v3v3(p2+3, p2, h1); + sub_v3_v3v3(p2 + 3, p2, h1); } else { mul_v3_fl(h2, dot * len_a); - add_v3_v3v3(p2-3, p2, h2); + add_v3_v3v3(p2 - 3, p2, h2); } } } } - if (bezt->h1==HD_VECT) { /* vector */ - madd_v3_v3v3fl(p2-3, p2, dvec_a, -1.0f/3.0f); + if (bezt->h1 == HD_VECT) { /* vector */ + madd_v3_v3v3fl(p2 - 3, p2, dvec_a, -1.0f / 3.0f); } - if (bezt->h2==HD_VECT) { - madd_v3_v3v3fl(p2+3, p2, dvec_b, 1.0f/3.0f); + if (bezt->h2 == HD_VECT) { + madd_v3_v3v3fl(p2 + 3, p2, dvec_b, 1.0f / 3.0f); } if (skip_align) { @@ -2650,44 +2650,44 @@ static void calchandleNurb_intern(BezTriple *bezt, BezTriple *prev, BezTriple *n return; } - len_b= len_v3v3(p2, p2+3); - len_a= len_v3v3(p2, p2-3); - if (len_a==0.0f) len_a= 1.0f; - if (len_b==0.0f) len_b= 1.0f; + len_b = len_v3v3(p2, p2 + 3); + len_a = len_v3v3(p2, p2 - 3); + if (len_a == 0.0f) len_a = 1.0f; + if (len_b == 0.0f) len_b = 1.0f; if (bezt->f1 & SELECT) { /* order of calculation */ - if (bezt->h2==HD_ALIGN) { /* aligned */ - if (len_a>eps) { - len= len_b/len_a; - p2[3]= p2[0]+len*(p2[0] - p2[-3]); - p2[4]= p2[1]+len*(p2[1] - p2[-2]); - p2[5]= p2[2]+len*(p2[2] - p2[-1]); + if (bezt->h2 == HD_ALIGN) { /* aligned */ + if (len_a > eps) { + len = len_b / len_a; + p2[3] = p2[0] + len * (p2[0] - p2[-3]); + p2[4] = p2[1] + len * (p2[1] - p2[-2]); + p2[5] = p2[2] + len * (p2[2] - p2[-1]); } } - if (bezt->h1==HD_ALIGN) { - if (len_b>eps) { - len= len_a/len_b; - p2[-3]= p2[0]+len*(p2[0] - p2[3]); - p2[-2]= p2[1]+len*(p2[1] - p2[4]); - p2[-1]= p2[2]+len*(p2[2] - p2[5]); + if (bezt->h1 == HD_ALIGN) { + if (len_b > eps) { + len = len_a / len_b; + p2[-3] = p2[0] + len * (p2[0] - p2[3]); + p2[-2] = p2[1] + len * (p2[1] - p2[4]); + p2[-1] = p2[2] + len * (p2[2] - p2[5]); } } } else { - if (bezt->h1==HD_ALIGN) { - if (len_b>eps) { - len= len_a/len_b; - p2[-3]= p2[0]+len*(p2[0] - p2[3]); - p2[-2]= p2[1]+len*(p2[1] - p2[4]); - p2[-1]= p2[2]+len*(p2[2] - p2[5]); + if (bezt->h1 == HD_ALIGN) { + if (len_b > eps) { + len = len_a / len_b; + p2[-3] = p2[0] + len * (p2[0] - p2[3]); + p2[-2] = p2[1] + len * (p2[1] - p2[4]); + p2[-1] = p2[2] + len * (p2[2] - p2[5]); } } - if (bezt->h2==HD_ALIGN) { /* aligned */ - if (len_a>eps) { - len= len_b/len_a; - p2[3]= p2[0]+len*(p2[0] - p2[-3]); - p2[4]= p2[1]+len*(p2[1] - p2[-2]); - p2[5]= p2[2]+len*(p2[2] - p2[-1]); + if (bezt->h2 == HD_ALIGN) { /* aligned */ + if (len_a > eps) { + len = len_b / len_a; + p2[3] = p2[0] + len * (p2[0] - p2[-3]); + p2[4] = p2[1] + len * (p2[1] - p2[-2]); + p2[5] = p2[2] + len * (p2[2] - p2[-1]); } } } @@ -2699,20 +2699,20 @@ static void calchandlesNurb_intern(Nurb *nu, int skip_align) short a; if (nu->type != CU_BEZIER) return; - if (nu->pntsu<2) return; + if (nu->pntsu < 2) return; - a= nu->pntsu; - bezt= nu->bezt; - if (nu->flagu & CU_NURB_CYCLIC) prev= bezt+(a-1); - else prev= NULL; - next= bezt+1; + a = nu->pntsu; + bezt = nu->bezt; + if (nu->flagu & CU_NURB_CYCLIC) prev = bezt + (a - 1); + else prev = NULL; + next = bezt + 1; while (a--) { calchandleNurb_intern(bezt, prev, next, 0, skip_align); - prev= bezt; - if (a==1) { - if (nu->flagu & CU_NURB_CYCLIC) next= nu->bezt; - else next= NULL; + prev = bezt; + if (a == 1) { + if (nu->flagu & CU_NURB_CYCLIC) next = nu->bezt; + else next = NULL; } else next++; @@ -2745,27 +2745,27 @@ void BKE_nurb_handles_test(Nurb *nu) if (nu->type != CU_BEZIER) return; - bezt= nu->bezt; - a= nu->pntsu; + bezt = nu->bezt; + a = nu->pntsu; while (a--) { - flag= 0; + flag = 0; if (bezt->f1 & SELECT) flag++; if (bezt->f2 & SELECT) flag += 2; if (bezt->f3 & SELECT) flag += 4; - if ( !(flag==0 || flag==7) ) { + if (!(flag == 0 || flag == 7) ) { if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM)) { /* auto */ - bezt->h1= HD_ALIGN; + bezt->h1 = HD_ALIGN; } if (ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) { /* auto */ - bezt->h2= HD_ALIGN; + bezt->h2 = HD_ALIGN; } - if (bezt->h1==HD_VECT) { /* vector */ - if (flag < 4) bezt->h1= 0; + if (bezt->h1 == HD_VECT) { /* vector */ + if (flag < 4) bezt->h1 = 0; } - if (bezt->h2==HD_VECT) { /* vector */ - if ( flag > 3) bezt->h2= 0; + if (bezt->h2 == HD_VECT) { /* vector */ + if (flag > 3) bezt->h2 = 0; } } bezt++; @@ -2781,64 +2781,64 @@ void BKE_nurb_handles_autocalc(Nurb *nu, int flag) BezTriple *bezt2, *bezt1, *bezt0; int i, align, leftsmall, rightsmall; - if (nu==NULL || nu->bezt==NULL) return; + if (nu == NULL || nu->bezt == NULL) return; bezt2 = nu->bezt; - bezt1 = bezt2 + (nu->pntsu-1); + bezt1 = bezt2 + (nu->pntsu - 1); bezt0 = bezt1 - 1; i = nu->pntsu; while (i--) { - align= leftsmall= rightsmall= 0; + align = leftsmall = rightsmall = 0; /* left handle: */ - if (flag==0 || (bezt1->f1 & flag) ) { - bezt1->h1= 0; + if (flag == 0 || (bezt1->f1 & flag) ) { + bezt1->h1 = 0; /* distance too short: vectorhandle */ if (len_v3v3(bezt1->vec[1], bezt0->vec[1]) < 0.0001f) { - bezt1->h1= HD_VECT; - leftsmall= 1; + bezt1->h1 = HD_VECT; + leftsmall = 1; } else { /* aligned handle? */ if (dist_to_line_v2(bezt1->vec[1], bezt1->vec[0], bezt1->vec[2]) < 0.0001f) { - align= 1; - bezt1->h1= HD_ALIGN; + align = 1; + bezt1->h1 = HD_ALIGN; } /* or vector handle? */ if (dist_to_line_v2(bezt1->vec[0], bezt1->vec[1], bezt0->vec[1]) < 0.0001f) - bezt1->h1= HD_VECT; + bezt1->h1 = HD_VECT; } } /* right handle: */ - if (flag==0 || (bezt1->f3 & flag) ) { - bezt1->h2= 0; + if (flag == 0 || (bezt1->f3 & flag) ) { + bezt1->h2 = 0; /* distance too short: vectorhandle */ if (len_v3v3(bezt1->vec[1], bezt2->vec[1]) < 0.0001f) { - bezt1->h2= HD_VECT; - rightsmall= 1; + bezt1->h2 = HD_VECT; + rightsmall = 1; } else { /* aligned handle? */ - if (align) bezt1->h2= HD_ALIGN; + if (align) bezt1->h2 = HD_ALIGN; /* or vector handle? */ if (dist_to_line_v2(bezt1->vec[2], bezt1->vec[1], bezt2->vec[1]) < 0.0001f) - bezt1->h2= HD_VECT; + bezt1->h2 = HD_VECT; } } - if (leftsmall && bezt1->h2==HD_ALIGN) bezt1->h2= 0; - if (rightsmall && bezt1->h1==HD_ALIGN) bezt1->h1= 0; + if (leftsmall && bezt1->h2 == HD_ALIGN) bezt1->h2 = 0; + if (rightsmall && bezt1->h1 == HD_ALIGN) bezt1->h1 = 0; /* undesired combination: */ - if (bezt1->h1==HD_ALIGN && bezt1->h2==HD_VECT) bezt1->h1= 0; - if (bezt1->h2==HD_ALIGN && bezt1->h1==HD_VECT) bezt1->h2= 0; + if (bezt1->h1 == HD_ALIGN && bezt1->h2 == HD_VECT) bezt1->h1 = 0; + if (bezt1->h2 == HD_ALIGN && bezt1->h1 == HD_VECT) bezt1->h2 = 0; - bezt0= bezt1; - bezt1= bezt2; + bezt0 = bezt1; + bezt1 = bezt2; bezt2++; } @@ -2849,10 +2849,10 @@ void BKE_nurbList_handles_autocalc(ListBase *editnurb, int flag) { Nurb *nu; - nu= editnurb->first; + nu = editnurb->first; while (nu) { BKE_nurb_handles_autocalc(nu, flag); - nu= nu->next; + nu = nu->next; } } @@ -2866,19 +2866,19 @@ void BKE_nurbList_handles_set(ListBase *editnurb, short code) /* code==6: Clear align, like 3 but no toggle */ Nurb *nu; BezTriple *bezt; - short a, ok=0; + short a, ok = 0; - if (code==1 || code==2) { - nu= editnurb->first; + if (code == 1 || code == 2) { + nu = editnurb->first; while (nu) { if (nu->type == CU_BEZIER) { - bezt= nu->bezt; - a= nu->pntsu; + bezt = nu->bezt; + a = nu->pntsu; while (a--) { if ((bezt->f1 & SELECT) || (bezt->f3 & SELECT)) { - if (bezt->f1 & SELECT) bezt->h1= code; - if (bezt->f3 & SELECT) bezt->h2= code; - if (bezt->h1!=bezt->h2) { + if (bezt->f1 & SELECT) bezt->h1 = code; + if (bezt->f3 & SELECT) bezt->h2 = code; + if (bezt->h1 != bezt->h2) { if (ELEM(bezt->h1, HD_ALIGN, HD_AUTO)) bezt->h1 = HD_FREE; if (ELEM(bezt->h2, HD_ALIGN, HD_AUTO)) bezt->h2 = HD_FREE; } @@ -2887,13 +2887,13 @@ void BKE_nurbList_handles_set(ListBase *editnurb, short code) } BKE_nurb_handles_calc(nu); } - nu= nu->next; + nu = nu->next; } } else { /* there is 1 handle not FREE: FREE it all, else make ALIGNED */ - nu= editnurb->first; + nu = editnurb->first; if (code == 5) { ok = HD_ALIGN; } @@ -2904,34 +2904,34 @@ void BKE_nurbList_handles_set(ListBase *editnurb, short code) /* Toggle */ while (nu) { if (nu->type == CU_BEZIER) { - bezt= nu->bezt; - a= nu->pntsu; + bezt = nu->bezt; + a = nu->pntsu; while (a--) { - if ((bezt->f1 & SELECT) && bezt->h1) ok= 1; - if ((bezt->f3 & SELECT) && bezt->h2) ok= 1; + if ((bezt->f1 & SELECT) && bezt->h1) ok = 1; + if ((bezt->f3 & SELECT) && bezt->h2) ok = 1; if (ok) break; bezt++; } } - nu= nu->next; + nu = nu->next; } - if (ok) ok= HD_FREE; - else ok= HD_ALIGN; + if (ok) ok = HD_FREE; + else ok = HD_ALIGN; } - nu= editnurb->first; + nu = editnurb->first; while (nu) { if (nu->type == CU_BEZIER) { - bezt= nu->bezt; - a= nu->pntsu; + bezt = nu->bezt; + a = nu->pntsu; while (a--) { - if (bezt->f1 & SELECT) bezt->h1= ok; - if (bezt->f3 & SELECT) bezt->h2= ok; + if (bezt->f1 & SELECT) bezt->h1 = ok; + if (bezt->f3 & SELECT) bezt->h2 = ok; bezt++; } BKE_nurb_handles_calc(nu); } - nu= nu->next; + nu = nu->next; } } } @@ -2939,9 +2939,9 @@ void BKE_nurbList_handles_set(ListBase *editnurb, short code) static void swapdata(void *adr1, void *adr2, int len) { - if (len<=0) return; + if (len <= 0) return; - if (len<65) { + if (len < 65) { char adr[64]; memcpy(adr, adr1, len); @@ -2951,7 +2951,7 @@ static void swapdata(void *adr1, void *adr2, int len) else { char *adr; - adr= (char *)MEM_mallocN(len, "curve swap"); + adr = (char *)MEM_mallocN(len, "curve swap"); memcpy(adr, adr1, len); memcpy(adr1, adr2, len); memcpy(adr2, adr, len); @@ -2966,44 +2966,44 @@ void BKE_nurb_direction_switch(Nurb *nu) float *fp1, *fp2, *tempf; int a, b; - if (nu->pntsu==1 && nu->pntsv==1) return; + if (nu->pntsu == 1 && nu->pntsv == 1) return; if (nu->type == CU_BEZIER) { - a= nu->pntsu; - bezt1= nu->bezt; - bezt2= bezt1+(a-1); - if (a & 1) a+= 1; /* if odd, also swap middle content */ - a/= 2; - while (a>0) { - if (bezt1!=bezt2) SWAP(BezTriple, *bezt1, *bezt2); + a = nu->pntsu; + bezt1 = nu->bezt; + bezt2 = bezt1 + (a - 1); + if (a & 1) a += 1; /* if odd, also swap middle content */ + a /= 2; + while (a > 0) { + if (bezt1 != bezt2) SWAP(BezTriple, *bezt1, *bezt2); swapdata(bezt1->vec[0], bezt1->vec[2], 12); - if (bezt1!=bezt2) swapdata(bezt2->vec[0], bezt2->vec[2], 12); + if (bezt1 != bezt2) swapdata(bezt2->vec[0], bezt2->vec[2], 12); SWAP(char, bezt1->h1, bezt1->h2); SWAP(short, bezt1->f1, bezt1->f3); - if (bezt1!=bezt2) { + if (bezt1 != bezt2) { SWAP(char, bezt2->h1, bezt2->h2); SWAP(short, bezt2->f1, bezt2->f3); - bezt1->alfa= -bezt1->alfa; - bezt2->alfa= -bezt2->alfa; + bezt1->alfa = -bezt1->alfa; + bezt2->alfa = -bezt2->alfa; } a--; bezt1++; bezt2--; } } - else if (nu->pntsv==1) { - a= nu->pntsu; - bp1= nu->bp; - bp2= bp1+(a-1); - a/= 2; - while (bp1!=bp2 && a>0) { + else if (nu->pntsv == 1) { + a = nu->pntsu; + bp1 = nu->bp; + bp2 = bp1 + (a - 1); + a /= 2; + while (bp1 != bp2 && a > 0) { SWAP(BPoint, *bp1, *bp2); a--; - bp1->alfa= -bp1->alfa; - bp2->alfa= -bp2->alfa; + bp1->alfa = -bp1->alfa; + bp2->alfa = -bp2->alfa; bp1++; bp2--; } @@ -3011,33 +3011,33 @@ void BKE_nurb_direction_switch(Nurb *nu) /* no knots for too short paths */ if (nu->knotsu) { /* inverse knots */ - a= KNOTSU(nu); - fp1= nu->knotsu; - fp2= fp1+(a-1); - a/= 2; - while (fp1!=fp2 && a>0) { + a = KNOTSU(nu); + fp1 = nu->knotsu; + fp2 = fp1 + (a - 1); + a /= 2; + while (fp1 != fp2 && a > 0) { SWAP(float, *fp1, *fp2); a--; fp1++; fp2--; } /* and make in increasing order again */ - a= KNOTSU(nu); - fp1= nu->knotsu; - fp2=tempf= MEM_mallocN(sizeof(float)*a, "switchdirect"); + a = KNOTSU(nu); + fp1 = nu->knotsu; + fp2 = tempf = MEM_mallocN(sizeof(float) * a, "switchdirect"); while (a--) { - fp2[0]= fabs(fp1[1]-fp1[0]); + fp2[0] = fabs(fp1[1] - fp1[0]); fp1++; fp2++; } - a= KNOTSU(nu)-1; - fp1= nu->knotsu; - fp2= tempf; - fp1[0]= 0.0; + a = KNOTSU(nu) - 1; + fp1 = nu->knotsu; + fp2 = tempf; + fp1[0] = 0.0; fp1++; while (a--) { - fp1[0]= fp1[-1]+fp2[0]; + fp1[0] = fp1[-1] + fp2[0]; fp1++; fp2++; } @@ -3047,14 +3047,14 @@ void BKE_nurb_direction_switch(Nurb *nu) } else { - for (b=0; b<nu->pntsv; b++) { + for (b = 0; b < nu->pntsv; b++) { - bp1= nu->bp+b*nu->pntsu; - a= nu->pntsu; - bp2= bp1+(a-1); - a/= 2; + bp1 = nu->bp + b * nu->pntsu; + a = nu->pntsu; + bp2 = bp1 + (a - 1); + a /= 2; - while (bp1!=bp2 && a>0) { + while (bp1 != bp2 && a > 0) { SWAP(BPoint, *bp1, *bp2); a--; bp1++; @@ -3065,28 +3065,28 @@ void BKE_nurb_direction_switch(Nurb *nu) } -float (*BKE_curve_vertexCos_get(Curve *UNUSED(cu), ListBase *lb, int *numVerts_r))[3] +float (*BKE_curve_vertexCos_get(Curve * UNUSED(cu), ListBase * lb, int *numVerts_r))[3] { int i, numVerts = *numVerts_r = BKE_nurbList_verts_count(lb); - float *co, (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "cu_vcos"); + float *co, (*cos)[3] = MEM_mallocN(sizeof(*cos) * numVerts, "cu_vcos"); Nurb *nu; co = cos[0]; - for (nu=lb->first; nu; nu=nu->next) { + for (nu = lb->first; nu; nu = nu->next) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; - for (i=0; i<nu->pntsu; i++, bezt++) { - 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; + for (i = 0; i < nu->pntsu; i++, bezt++) { + 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++) { - copy_v3_v3(co, bp->vec); co+=3; + for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { + copy_v3_v3(co, bp->vec); co += 3; } } } @@ -3100,21 +3100,21 @@ void BK_curve_vertexCos_apply(Curve *UNUSED(cu), ListBase *lb, float (*vertexCos Nurb *nu; int i; - for (nu=lb->first; nu; nu=nu->next) { + for (nu = lb->first; nu; nu = nu->next) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; - for (i=0; i<nu->pntsu; i++, bezt++) { - 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; + for (i = 0; i < nu->pntsu; i++, bezt++) { + 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++) { - copy_v3_v3(bp->vec, co); co+=3; + for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { + copy_v3_v3(bp->vec, co); co += 3; } } @@ -3122,29 +3122,29 @@ void BK_curve_vertexCos_apply(Curve *UNUSED(cu), ListBase *lb, float (*vertexCos } } -float (*BKE_curve_keyVertexCos_get(Curve *UNUSED(cu), ListBase *lb, float *key))[3] +float (*BKE_curve_keyVertexCos_get(Curve * UNUSED(cu), ListBase * lb, float *key))[3] { int i, numVerts = BKE_nurbList_verts_count(lb); - float *co, (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "cu_vcos"); + float *co, (*cos)[3] = MEM_mallocN(sizeof(*cos) * numVerts, "cu_vcos"); Nurb *nu; co = cos[0]; - for (nu=lb->first; nu; nu=nu->next) { + for (nu = lb->first; nu; nu = nu->next) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; - for (i=0; i<nu->pntsu; i++, bezt++) { - 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 */ + for (i = 0; i < nu->pntsu; i++, bezt++) { + 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 */ } } else { BPoint *bp = nu->bp; - for (i=0; i<nu->pntsu*nu->pntsv; i++, bp++) { - copy_v3_v3(co, key); co+=3; key+=3; + for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { + copy_v3_v3(co, key); co += 3; key += 3; key++; /* skip tilt */ } } @@ -3158,22 +3158,22 @@ void BKE_curve_keyVertexTilts_apply(Curve *UNUSED(cu), ListBase *lb, float *key) Nurb *nu; int i; - for (nu=lb->first; nu; nu=nu->next) { + for (nu = lb->first; nu; nu = nu->next) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; - for (i=0; i<nu->pntsu; i++, bezt++) { - key+=3*3; - bezt->alfa= *key; - key+=3; + for (i = 0; i < nu->pntsu; i++, bezt++) { + key += 3 * 3; + bezt->alfa = *key; + key += 3; } } else { BPoint *bp = nu->bp; - for (i=0; i<nu->pntsu*nu->pntsv; i++, bp++) { - key+=3; - bp->alfa= *key; + for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { + key += 3; + bp->alfa = *key; key++; } } @@ -3182,31 +3182,31 @@ void BKE_curve_keyVertexTilts_apply(Curve *UNUSED(cu), ListBase *lb, float *key) int BKE_nurb_check_valid_u(struct Nurb *nu) { - if (nu==NULL) return 0; - if (nu->pntsu <= 1) return 0; - if (nu->type != CU_NURBS) return 1; /* not a nurb, lets assume its valid */ - - if (nu->pntsu < nu->orderu) return 0; - if (((nu->flag & CU_NURB_CYCLIC)==0) && (nu->flagu & CU_NURB_BEZIER)) { /* Bezier U Endpoints */ - if (nu->orderu==4) { - if (nu->pntsu < 5) return 0; /* bezier with 4 orderu needs 5 points */ + if (nu == NULL) return 0; + if (nu->pntsu <= 1) return 0; + if (nu->type != CU_NURBS) return 1; /* not a nurb, lets assume its valid */ + + if (nu->pntsu < nu->orderu) return 0; + if (((nu->flag & CU_NURB_CYCLIC) == 0) && (nu->flagu & CU_NURB_BEZIER)) { /* Bezier U Endpoints */ + if (nu->orderu == 4) { + if (nu->pntsu < 5) return 0; /* bezier with 4 orderu needs 5 points */ } - else if (nu->orderu != 3) return 0; /* order must be 3 or 4 */ + else if (nu->orderu != 3) return 0; /* order must be 3 or 4 */ } return 1; } int BKE_nurb_check_valid_v(struct Nurb *nu) { - if (nu==NULL) return 0; - if (nu->pntsv <= 1) return 0; - if (nu->type != CU_NURBS) return 1; /* not a nurb, lets assume its valid */ - - if (nu->pntsv < nu->orderv) return 0; - if (((nu->flag & CU_NURB_CYCLIC)==0) && (nu->flagv & CU_NURB_BEZIER)) { /* Bezier V Endpoints */ - if (nu->orderv==4) { - if (nu->pntsv < 5) return 0; /* bezier with 4 orderu needs 5 points */ + if (nu == NULL) return 0; + if (nu->pntsv <= 1) return 0; + if (nu->type != CU_NURBS) return 1; /* not a nurb, lets assume its valid */ + + if (nu->pntsv < nu->orderv) return 0; + if (((nu->flag & CU_NURB_CYCLIC) == 0) && (nu->flagv & CU_NURB_BEZIER)) { /* Bezier V Endpoints */ + if (nu->orderv == 4) { + if (nu->pntsv < 5) return 0; /* bezier with 4 orderu needs 5 points */ } - else if (nu->orderv != 3) return 0; /* order must be 3 or 4 */ + else if (nu->orderv != 3) return 0; /* order must be 3 or 4 */ } return 1; } @@ -3214,13 +3214,13 @@ int BKE_nurb_check_valid_v(struct Nurb *nu) int BKE_nurb_order_clamp_u(struct Nurb *nu) { int change = 0; - if (nu->pntsu<nu->orderu) { - nu->orderu= nu->pntsu; - change= 1; + if (nu->pntsu < nu->orderu) { + nu->orderu = nu->pntsu; + change = 1; } - if (((nu->flagu & CU_NURB_CYCLIC)==0) && (nu->flagu & CU_NURB_BEZIER)) { + if (((nu->flagu & CU_NURB_CYCLIC) == 0) && (nu->flagu & CU_NURB_BEZIER)) { CLAMP(nu->orderu, 3, 4); - change= 1; + change = 1; } return change; } @@ -3228,13 +3228,13 @@ int BKE_nurb_order_clamp_u(struct Nurb *nu) int BKE_nurb_order_clamp_v(struct Nurb *nu) { int change = 0; - if (nu->pntsv<nu->orderv) { - nu->orderv= nu->pntsv; - change= 1; + if (nu->pntsv < nu->orderv) { + nu->orderv = nu->pntsv; + change = 1; } - if (((nu->flagv & CU_NURB_CYCLIC)==0) && (nu->flagv & CU_NURB_BEZIER)) { + if (((nu->flagv & CU_NURB_CYCLIC) == 0) && (nu->flagv & CU_NURB_BEZIER)) { CLAMP(nu->orderv, 3, 4); - change= 1; + change = 1; } return change; } @@ -3253,10 +3253,10 @@ ListBase *BKE_curve_nurbs_get(Curve *cu) /* basic vertex data functions */ int BKE_curve_minmax(Curve *cu, float min[3], float max[3]) { - ListBase *nurb_lb= BKE_curve_nurbs_get(cu); + ListBase *nurb_lb = BKE_curve_nurbs_get(cu); Nurb *nu; - for (nu= nurb_lb->first; nu; nu= nu->next) + for (nu = nurb_lb->first; nu; nu = nu->next) BKE_nurb_minmax(nu, min, max); return (nurb_lb->first != NULL); @@ -3264,20 +3264,20 @@ int BKE_curve_minmax(Curve *cu, float min[3], float max[3]) int BKE_curve_center_median(Curve *cu, float cent[3]) { - ListBase *nurb_lb= BKE_curve_nurbs_get(cu); + ListBase *nurb_lb = BKE_curve_nurbs_get(cu); Nurb *nu; - int total= 0; + int total = 0; zero_v3(cent); - for (nu= nurb_lb->first; nu; nu= nu->next) { + for (nu = nurb_lb->first; nu; nu = nu->next) { int i; if (nu->type == CU_BEZIER) { BezTriple *bezt; - i= nu->pntsu; + i = nu->pntsu; total += i * 3; - for (bezt= nu->bezt; i--; bezt++) { + for (bezt = nu->bezt; i--; bezt++) { add_v3_v3(cent, bezt->vec[0]); add_v3_v3(cent, bezt->vec[1]); add_v3_v3(cent, bezt->vec[2]); @@ -3285,15 +3285,15 @@ int BKE_curve_center_median(Curve *cu, float cent[3]) } else { BPoint *bp; - i= nu->pntsu*nu->pntsv; + i = nu->pntsu * nu->pntsv; total += i; - for (bp= nu->bp; i--; bp++) { + for (bp = nu->bp; i--; bp++) { add_v3_v3(cent, bp->vec); } } } - mul_v3_fl(cent, 1.0f/(float)total); + mul_v3_fl(cent, 1.0f / (float)total); return (total != 0); } @@ -3312,25 +3312,25 @@ int BKE_curve_center_bounds(Curve *cu, float cent[3]) void BKE_curve_translate(Curve *cu, float offset[3], int do_keys) { - ListBase *nurb_lb= BKE_curve_nurbs_get(cu); + ListBase *nurb_lb = BKE_curve_nurbs_get(cu); Nurb *nu; int i; - for (nu= nurb_lb->first; nu; nu= nu->next) { + for (nu = nurb_lb->first; nu; nu = nu->next) { BezTriple *bezt; BPoint *bp; if (nu->type == CU_BEZIER) { - i= nu->pntsu; - for (bezt= nu->bezt; i--; bezt++) { + i = nu->pntsu; + for (bezt = nu->bezt; i--; bezt++) { add_v3_v3(bezt->vec[0], offset); add_v3_v3(bezt->vec[1], offset); add_v3_v3(bezt->vec[2], offset); } } else { - i= nu->pntsu*nu->pntsv; - for (bp= nu->bp; i--; bp++) { + i = nu->pntsu * nu->pntsv; + for (bp = nu->bp; i--; bp++) { add_v3_v3(bp->vec, offset); } } @@ -3338,9 +3338,9 @@ void BKE_curve_translate(Curve *cu, float offset[3], int do_keys) if (do_keys && cu->key) { KeyBlock *kb; - for (kb=cu->key->block.first; kb; kb=kb->next) { - float *fp= kb->data; - for (i= kb->totelem; i--; fp+=3) { + for (kb = cu->key->block.first; kb; kb = kb->next) { + float *fp = kb->data; + for (i = kb->totelem; i--; fp += 3) { add_v3_v3(fp, offset); } } @@ -3349,13 +3349,13 @@ void BKE_curve_translate(Curve *cu, float offset[3], int do_keys) void BKE_curve_delete_material_index(Curve *cu, int index) { - const int curvetype= BKE_curve_type_get(cu); + const int curvetype = BKE_curve_type_get(cu); if (curvetype == OB_FONT) { - struct CharInfo *info= cu->strinfo; + struct CharInfo *info = cu->strinfo; int i; - for (i= cu->len-1; i >= 0; i--, info++) { - if (info->mat_nr && info->mat_nr>=index) { + for (i = cu->len - 1; i >= 0; i--, info++) { + if (info->mat_nr && info->mat_nr >= index) { info->mat_nr--; } } @@ -3363,8 +3363,8 @@ void BKE_curve_delete_material_index(Curve *cu, int index) else { Nurb *nu; - for (nu= cu->nurb.first; nu; nu= nu->next) { - if (nu->mat_nr && nu->mat_nr>=index) { + for (nu = cu->nurb.first; nu; nu = nu->next) { + if (nu->mat_nr && nu->mat_nr >= index) { nu->mat_nr--; if (curvetype == OB_CURVE) nu->charidx--; } diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index fa57cc7ce44..0ec0c16073b 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -60,7 +60,7 @@ #include "BKE_curve.h" #include "BKE_displist.h" -static ListBase ttfdata= {NULL, NULL}; +static ListBase ttfdata = {NULL, NULL}; /* The vfont code */ void BKE_vfont_free(struct VFont *vf) @@ -90,13 +90,13 @@ void BKE_vfont_free(struct VFont *vf) } } -static void *builtin_font_data= NULL; -static int builtin_font_size= 0; +static void *builtin_font_data = NULL; +static int builtin_font_size = 0; void BKE_vfont_builtin_register(void *mem, int size) { - builtin_font_data= mem; - builtin_font_size= size; + builtin_font_data = mem; + builtin_font_size = size; } static PackedFile *get_builtin_packedfile(void) @@ -107,7 +107,7 @@ static PackedFile *get_builtin_packedfile(void) return NULL; } else { - void *mem= MEM_mallocN(builtin_font_size, "vfd_builtin"); + void *mem = MEM_mallocN(builtin_font_size, "vfd_builtin"); memcpy(mem, builtin_font_data, builtin_font_size); @@ -119,10 +119,10 @@ void BKE_vfont_free_global_ttf(void) { struct TmpFont *tf; - for (tf= ttfdata.first; tf; tf= tf->next) { - if (tf->pf) freePackedFile(tf->pf); /* NULL when the font file can't be found on disk */ - tf->pf= NULL; - tf->vfont= NULL; + for (tf = ttfdata.first; tf; tf = tf->next) { + if (tf->pf) freePackedFile(tf->pf); /* NULL when the font file can't be found on disk */ + tf->pf = NULL; + tf->vfont = NULL; } BLI_freelistN(&ttfdata); } @@ -131,7 +131,7 @@ struct TmpFont *BKE_vfont_find_tmpfont(VFont *vfont) { struct TmpFont *tmpfnt = NULL; - if (vfont==NULL) return NULL; + if (vfont == NULL) return NULL; // Try finding the font from font list tmpfnt = ttfdata.first; @@ -148,7 +148,7 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont) struct TmpFont *tmpfnt = NULL; PackedFile *tpf; - if (vfont==NULL) return NULL; + if (vfont == NULL) return NULL; // Try finding the font from font list tmpfnt = BKE_vfont_find_tmpfont(vfont); @@ -157,37 +157,37 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont) if (!vfont->data) { PackedFile *pf; - if (strcmp(vfont->name, FO_BUILTIN_NAME)==0) { - pf= get_builtin_packedfile(); + if (strcmp(vfont->name, FO_BUILTIN_NAME) == 0) { + pf = get_builtin_packedfile(); } else { if (vfont->packedfile) { - pf= vfont->packedfile; + pf = vfont->packedfile; // We need to copy a tmp font to memory unless it is already there if (!tmpfnt) { - tpf= MEM_callocN(sizeof(*tpf), "PackedFile"); - tpf->data= MEM_mallocN(pf->size, "packFile"); - tpf->size= pf->size; + tpf = MEM_callocN(sizeof(*tpf), "PackedFile"); + tpf->data = MEM_mallocN(pf->size, "packFile"); + tpf->size = pf->size; memcpy(tpf->data, pf->data, pf->size); // Add temporary packed file to globals - tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font"); - tmpfnt->pf= tpf; - tmpfnt->vfont= vfont; + tmpfnt = (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font"); + tmpfnt->pf = tpf; + tmpfnt->vfont = vfont; BLI_addtail(&ttfdata, tmpfnt); } } else { - pf= newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id)); + pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id)); if (!tmpfnt) { - tpf= newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id)); + tpf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id)); // Add temporary packed file to globals - tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font"); - tmpfnt->pf= tpf; - tmpfnt->vfont= vfont; + tmpfnt = (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font"); + tmpfnt->pf = tpf; + tmpfnt->vfont = vfont; BLI_addtail(&ttfdata, tmpfnt); } } @@ -195,12 +195,12 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont) printf("Font file doesn't exist: %s\n", vfont->name); strcpy(vfont->name, FO_BUILTIN_NAME); - pf= get_builtin_packedfile(); + pf = get_builtin_packedfile(); } } if (pf) { - vfont->data= BLI_vfontdata_from_freetypefont(pf); + vfont->data = BLI_vfontdata_from_freetypefont(pf); if (pf != vfont->packedfile) { freePackedFile(pf); } @@ -213,17 +213,17 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont) VFont *BKE_vfont_load(Main *bmain, const char *name) { char filename[FILE_MAXFILE]; - VFont *vfont= NULL; + VFont *vfont = NULL; PackedFile *pf; PackedFile *tpf = NULL; int is_builtin; struct TmpFont *tmpfnt; - if (strcmp(name, FO_BUILTIN_NAME)==0) { + if (strcmp(name, FO_BUILTIN_NAME) == 0) { BLI_strncpy(filename, name, sizeof(filename)); - pf= get_builtin_packedfile(); - is_builtin= 1; + pf = get_builtin_packedfile(); + is_builtin = 1; } else { char dir[FILE_MAXDIR]; @@ -231,23 +231,23 @@ VFont *BKE_vfont_load(Main *bmain, const char *name) BLI_strncpy(dir, name, sizeof(dir)); BLI_splitdirstring(dir, filename); - pf= newPackedFile(NULL, name, bmain->name); - tpf= newPackedFile(NULL, name, bmain->name); + pf = newPackedFile(NULL, name, bmain->name); + tpf = newPackedFile(NULL, name, bmain->name); - is_builtin= 0; + is_builtin = 0; } if (pf) { VFontData *vfd; - vfd= BLI_vfontdata_from_freetypefont(pf); + vfd = BLI_vfontdata_from_freetypefont(pf); if (vfd) { vfont = BKE_libblock_alloc(&bmain->vfont, ID_VF, filename); vfont->data = vfd; /* if there's a font name, use it for the ID name */ if (vfd->name[0] != '\0') { - BLI_strncpy(vfont->id.name+2, vfd->name, sizeof(vfont->id.name)-2); + BLI_strncpy(vfont->id.name + 2, vfd->name, sizeof(vfont->id.name) - 2); } BLI_strncpy(vfont->name, name, sizeof(vfont->name)); @@ -258,9 +258,9 @@ VFont *BKE_vfont_load(Main *bmain, const char *name) // Do not add FO_BUILTIN_NAME to temporary listbase if (strcmp(filename, FO_BUILTIN_NAME)) { - tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font"); - tmpfnt->pf= tpf; - tmpfnt->vfont= vfont; + tmpfnt = (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font"); + tmpfnt->pf = tpf; + tmpfnt->vfont = vfont; BLI_addtail(&ttfdata, tmpfnt); } } @@ -278,12 +278,12 @@ VFont *BKE_vfont_load(Main *bmain, const char *name) static VFont *which_vfont(Curve *cu, CharInfo *info) { - switch (info->flag & (CU_CHINFO_BOLD|CU_CHINFO_ITALIC)) { + switch (info->flag & (CU_CHINFO_BOLD | CU_CHINFO_ITALIC)) { case CU_CHINFO_BOLD: if (cu->vfontb) return(cu->vfontb); else return(cu->vfont); case CU_CHINFO_ITALIC: if (cu->vfonti) return(cu->vfonti); else return(cu->vfont); - case (CU_CHINFO_BOLD|CU_CHINFO_ITALIC): + case (CU_CHINFO_BOLD | CU_CHINFO_ITALIC): if (cu->vfontbi) return(cu->vfontbi); else return(cu->vfont); default: return(cu->vfont); @@ -294,8 +294,8 @@ VFont *BKE_vfont_builtin_get(void) { VFont *vf; - for (vf= G.main->vfont.first; vf; vf= vf->id.next) - if (strcmp(vf->name, FO_BUILTIN_NAME)==0) + for (vf = G.main->vfont.first; vf; vf = vf->id.next) + if (strcmp(vf->name, FO_BUILTIN_NAME) == 0) return vf; return BKE_vfont_load(G.main, FO_BUILTIN_NAME); @@ -303,7 +303,7 @@ VFont *BKE_vfont_builtin_get(void) static VChar *find_vfont_char(VFontData *vfd, intptr_t character) { - VChar *che= NULL; + VChar *che = NULL; for (che = vfd->characters.first; che; che = che->next) { if (che->index == character) @@ -317,21 +317,21 @@ static void build_underline(Curve *cu, float x1, float y1, float x2, float y2, i Nurb *nu2; BPoint *bp; - nu2 =(Nurb*) MEM_callocN(sizeof(Nurb), "underline_nurb"); + nu2 = (Nurb *) MEM_callocN(sizeof(Nurb), "underline_nurb"); if (nu2 == NULL) return; - nu2->resolu= cu->resolu; + nu2->resolu = cu->resolu; nu2->bezt = NULL; nu2->knotsu = nu2->knotsv = NULL; - nu2->flag= CU_2D; - nu2->charidx = charidx+1000; - if (mat_nr > 0) nu2->mat_nr= mat_nr-1; + nu2->flag = CU_2D; + nu2->charidx = charidx + 1000; + if (mat_nr > 0) nu2->mat_nr = mat_nr - 1; nu2->pntsu = 4; nu2->pntsv = 1; nu2->orderu = 4; nu2->orderv = 1; nu2->flagu = CU_NURB_CYCLIC; - bp = (BPoint*)MEM_callocN(4 * sizeof(BPoint), "underline_bp"); + bp = (BPoint *)MEM_callocN(4 * sizeof(BPoint), "underline_bp"); if (bp == NULL) { MEM_freeN(nu2); return; @@ -368,27 +368,27 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo VChar *che = NULL; int i; - vfd= vfont_get_data(bmain, which_vfont(cu, info)); + vfd = vfont_get_data(bmain, which_vfont(cu, info)); if (!vfd) return; #if 0 if (cu->selend < cu->selstart) { - if ((charidx >= (cu->selend)) && (charidx <= (cu->selstart-2))) - sel= 1; + if ((charidx >= (cu->selend)) && (charidx <= (cu->selstart - 2))) + sel = 1; } else { - if ((charidx >= (cu->selstart-1)) && (charidx <= (cu->selend-1))) - sel= 1; + if ((charidx >= (cu->selstart - 1)) && (charidx <= (cu->selend - 1))) + sel = 1; } #endif /* make a copy at distance ofsx, ofsy with shear*/ - fsize= cu->fsize; - shear= cu->shear; - si= (float)sin(rot); - co= (float)cos(rot); + fsize = cu->fsize; + shear = cu->shear; + si = (float)sin(rot); + co = (float)cos(rot); - che= find_vfont_char(vfd, character); + che = find_vfont_char(vfd, character); // Select the glyph data if (che) @@ -398,25 +398,25 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo while (nu1) { bezt1 = nu1->bezt; if (bezt1) { - nu2 =(Nurb*) MEM_mallocN(sizeof(Nurb), "duplichar_nurb"); + nu2 = (Nurb *) MEM_mallocN(sizeof(Nurb), "duplichar_nurb"); if (nu2 == NULL) break; memcpy(nu2, nu1, sizeof(struct Nurb)); - nu2->resolu= cu->resolu; + nu2->resolu = cu->resolu; nu2->bp = NULL; nu2->knotsu = nu2->knotsv = NULL; - nu2->flag= CU_SMOOTH; + nu2->flag = CU_SMOOTH; nu2->charidx = charidx; if (info->mat_nr > 0) { - nu2->mat_nr= info->mat_nr-1; + nu2->mat_nr = info->mat_nr - 1; } else { - nu2->mat_nr= 0; + nu2->mat_nr = 0; } /* nu2->trim.first = 0; */ /* nu2->trim.last = 0; */ i = nu2->pntsu; - bezt2 = (BezTriple*)MEM_mallocN(i * sizeof(BezTriple), "duplichar_bezt2"); + bezt2 = (BezTriple *)MEM_mallocN(i * sizeof(BezTriple), "duplichar_bezt2"); if (bezt2 == NULL) { MEM_freeN(nu2); break; @@ -427,7 +427,7 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo if (shear != 0.0f) { bezt2 = nu2->bezt; - for (i= nu2->pntsu; i > 0; i--) { + for (i = nu2->pntsu; i > 0; i--) { bezt2->vec[0][0] += shear * bezt2->vec[0][1]; bezt2->vec[1][0] += shear * bezt2->vec[1][1]; bezt2->vec[2][0] += shear * bezt2->vec[2][1]; @@ -435,19 +435,19 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo } } if (rot != 0.0f) { - bezt2= nu2->bezt; - for (i=nu2->pntsu; i > 0; i--) { - fp= bezt2->vec[0]; - - x= fp[0]; - fp[0]= co*x + si*fp[1]; - fp[1]= -si*x + co*fp[1]; - x= fp[3]; - fp[3]= co*x + si*fp[4]; - fp[4]= -si*x + co*fp[4]; - x= fp[6]; - fp[6]= co*x + si*fp[7]; - fp[7]= -si*x + co*fp[7]; + bezt2 = nu2->bezt; + for (i = nu2->pntsu; i > 0; i--) { + fp = bezt2->vec[0]; + + x = fp[0]; + fp[0] = co * x + si * fp[1]; + fp[1] = -si * x + co * fp[1]; + x = fp[3]; + fp[3] = co * x + si * fp[4]; + fp[4] = -si * x + co * fp[4]; + x = fp[6]; + fp[6] = co * x + si * fp[7]; + fp[7] = -si * x + co * fp[7]; bezt2++; } @@ -455,9 +455,9 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo bezt2 = nu2->bezt; if (info->flag & CU_CHINFO_SMALLCAPS_CHECK) { - const float sca= cu->smallcaps_scale; - for (i= nu2->pntsu; i > 0; i--) { - fp= bezt2->vec[0]; + const float sca = cu->smallcaps_scale; + for (i = nu2->pntsu; i > 0; i--) { + fp = bezt2->vec[0]; fp[0] *= sca; fp[1] *= sca; fp[3] *= sca; @@ -469,14 +469,14 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo } bezt2 = nu2->bezt; - for (i= nu2->pntsu; i > 0; i--) { - fp= bezt2->vec[0]; - fp[0]= (fp[0]+ofsx)*fsize; - fp[1]= (fp[1]+ofsy)*fsize; - fp[3]= (fp[3]+ofsx)*fsize; - fp[4]= (fp[4]+ofsy)*fsize; - fp[6]= (fp[6]+ofsx)*fsize; - fp[7]= (fp[7]+ofsy)*fsize; + for (i = nu2->pntsu; i > 0; i--) { + fp = bezt2->vec[0]; + fp[0] = (fp[0] + ofsx) * fsize; + fp[1] = (fp[1] + ofsy) * fsize; + fp[3] = (fp[3] + ofsx) * fsize; + fp[4] = (fp[4] + ofsy) * fsize; + fp[6] = (fp[6] + ofsx) * fsize; + fp[7] = (fp[7] + ofsy) * fsize; bezt2++; } @@ -489,19 +489,19 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo int BKE_vfont_select_get(Object *ob, int *start, int *end) { - Curve *cu= ob->data; + Curve *cu = ob->data; - if (cu->editfont==NULL || ob->type != OB_FONT) return 0; + if (cu->editfont == NULL || ob->type != OB_FONT) return 0; if (cu->selstart == 0) return 0; if (cu->selstart <= cu->selend) { - *start = cu->selstart-1; - *end = cu->selend-1; + *start = cu->selstart - 1; + *end = cu->selend - 1; return 1; } else { *start = cu->selend; - *end = cu->selstart-2; + *end = cu->selstart - 2; return -1; } } @@ -520,32 +520,31 @@ static float char_width(Curve *cu, VChar *che, CharInfo *info) } } -struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int mode) -{ +struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int mode){ VFont *vfont, *oldvfont; - VFontData *vfd= NULL; + VFontData *vfd = NULL; Curve *cu; CharInfo *info = NULL, *custrinfo; TextBox *tb; VChar *che; - struct chartrans *chartransdata=NULL, *ct; + struct chartrans *chartransdata = NULL, *ct; float *f, xof, yof, xtrax, linedist, *linedata, *linedata2, *linedata3, *linedata4; - float twidth, maxlen= 0; + float twidth, maxlen = 0; int i, slen, j; int curbox; int selstart, selend; int utf8len; - short cnr=0, lnr=0, wsnr= 0; + short cnr = 0, lnr = 0, wsnr = 0; wchar_t *mem, *tmp, ascii; /* renark: do calculations including the trailing '\0' of a string * because the cursor can be at that location */ - if (ob->type!=OB_FONT) return NULL; + if (ob->type != OB_FONT) return NULL; // Set font data - cu= (Curve *) ob->data; - vfont= cu->vfont; + cu = (Curve *) ob->data; + vfont = cu->vfont; if (cu->str == NULL) return NULL; if (vfont == NULL) return NULL; @@ -562,17 +561,17 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int if (cu->ulheight == 0.0f) cu->ulheight = 0.05f; - if (cu->strinfo==NULL) /* old file */ - cu->strinfo = MEM_callocN((slen+4) * sizeof(CharInfo), "strinfo compat"); + if (cu->strinfo == NULL) /* old file */ + cu->strinfo = MEM_callocN((slen + 4) * sizeof(CharInfo), "strinfo compat"); - custrinfo= cu->strinfo; + custrinfo = cu->strinfo; if (cu->editfont) - custrinfo= cu->editfont->textbufinfo; + custrinfo = cu->editfont->textbufinfo; - if (cu->tb==NULL) - cu->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "TextBox compat"); + if (cu->tb == NULL) + cu->tb = MEM_callocN(MAXTEXTBOX * sizeof(TextBox), "TextBox compat"); - vfd= vfont_get_data(bmain, vfont); + vfd = vfont_get_data(bmain, vfont); /* The VFont Data can not be found */ if (!vfd) { @@ -583,7 +582,7 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int /* calc offset and rotation of each char */ ct = chartransdata = - (struct chartrans*)MEM_callocN((slen+1)* sizeof(struct chartrans), "buildtext"); + (struct chartrans *)MEM_callocN((slen + 1) * sizeof(struct chartrans), "buildtext"); /* We assume the worst case: 1 character per line (is freed at end anyway) */ @@ -592,57 +591,57 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int linedata3 = MEM_callocN(sizeof(float) * (slen * 2 + 1), "buildtext4"); linedata4 = MEM_callocN(sizeof(float) * (slen * 2 + 1), "buildtext5"); - linedist= cu->linedist; + linedist = cu->linedist; - xof= cu->xof + (cu->tb[0].x/cu->fsize); - yof= cu->yof + (cu->tb[0].y/cu->fsize); + xof = cu->xof + (cu->tb[0].x / cu->fsize); + yof = cu->yof + (cu->tb[0].y / cu->fsize); - xtrax= 0.5f*cu->spacing-0.5f; + xtrax = 0.5f * cu->spacing - 0.5f; oldvfont = NULL; - for (i=0; i<slen; i++) custrinfo[i].flag &= ~(CU_CHINFO_WRAP|CU_CHINFO_SMALLCAPS_CHECK); + for (i = 0; i < slen; i++) custrinfo[i].flag &= ~(CU_CHINFO_WRAP | CU_CHINFO_SMALLCAPS_CHECK); if (cu->selboxes) MEM_freeN(cu->selboxes); cu->selboxes = NULL; if (BKE_vfont_select_get(ob, &selstart, &selend)) - cu->selboxes = MEM_callocN((selend-selstart+1)*sizeof(SelBox), "font selboxes"); + cu->selboxes = MEM_callocN((selend - selstart + 1) * sizeof(SelBox), "font selboxes"); tb = &(cu->tb[0]); - curbox= 0; - for (i = 0 ; i<=slen ; i++) { - makebreak: + curbox = 0; + for (i = 0; i <= slen; i++) { +makebreak: // Characters in the list info = &(custrinfo[i]); ascii = mem[i]; if (info->flag & CU_CHINFO_SMALLCAPS) { ascii = towupper(ascii); if (mem[i] != ascii) { - mem[i]= ascii; + mem[i] = ascii; info->flag |= CU_CHINFO_SMALLCAPS_CHECK; } } vfont = which_vfont(cu, info); - if (vfont==NULL) break; + if (vfont == NULL) break; - che= find_vfont_char(vfd, ascii); + che = find_vfont_char(vfd, ascii); /* * The character wasn't in the current curve base so load it * But if the font is FO_BUILTIN_NAME then do not try loading since * whole font is in the memory already */ - if (che == NULL && strcmp(vfont->name, FO_BUILTIN_NAME)) { + if (che == NULL && strcmp(vfont->name, FO_BUILTIN_NAME)) { BLI_vfontchar_from_freetypefont(vfont, ascii); } /* Try getting the character again from the list */ - che= find_vfont_char(vfd, ascii); + che = find_vfont_char(vfd, ascii); /* No VFont found */ - if (vfont==NULL) { + if (vfont == NULL) { if (mem) MEM_freeN(mem); MEM_freeN(chartransdata); @@ -650,7 +649,7 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int } if (vfont != oldvfont) { - vfd= vfont_get_data(bmain, vfont); + vfd = vfont_get_data(bmain, vfont); oldvfont = vfont; } @@ -665,24 +664,24 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int twidth = char_width(cu, che, info); // Calculate positions - if ((tb->w != 0.0f) && (ct->dobreak==0) && ((xof-(tb->x/cu->fsize)+twidth)*cu->fsize) > tb->w + cu->xof*cu->fsize) { - // fprintf(stderr, "linewidth exceeded: %c%c%c...\n", mem[i], mem[i+1], mem[i+2]); - for (j=i; j && (mem[j] != '\n') && (mem[j] != '\r') && (chartransdata[j].dobreak==0); j--) { - if (mem[j]==' ' || mem[j]=='-') { - ct -= (i-(j-1)); - cnr -= (i-(j-1)); + if ((tb->w != 0.0f) && (ct->dobreak == 0) && ((xof - (tb->x / cu->fsize) + twidth) * cu->fsize) > tb->w + cu->xof * cu->fsize) { + // fprintf(stderr, "linewidth exceeded: %c%c%c...\n", mem[i], mem[i+1], mem[i+2]); + for (j = i; j && (mem[j] != '\n') && (mem[j] != '\r') && (chartransdata[j].dobreak == 0); j--) { + if (mem[j] == ' ' || mem[j] == '-') { + ct -= (i - (j - 1)); + cnr -= (i - (j - 1)); if (mem[j] == ' ') wsnr--; if (mem[j] == '-') wsnr++; - i = j-1; + i = j - 1; xof = ct->xof; ct[1].dobreak = 1; - custrinfo[i+1].flag |= CU_CHINFO_WRAP; + custrinfo[i + 1].flag |= CU_CHINFO_WRAP; goto makebreak; } if (chartransdata[j].dobreak) { - // fprintf(stderr, "word too long: %c%c%c...\n", mem[j], mem[j+1], mem[j+2]); - ct->dobreak= 1; - custrinfo[i+1].flag |= CU_CHINFO_WRAP; + // fprintf(stderr, "word too long: %c%c%c...\n", mem[j], mem[j+1], mem[j+2]); + ct->dobreak = 1; + custrinfo[i + 1].flag |= CU_CHINFO_WRAP; ct -= 1; cnr -= 1; i--; @@ -691,27 +690,27 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int } } } - if (ascii== '\n' || ascii== '\r' || ascii==0 || ct->dobreak) { - ct->xof= xof; - ct->yof= yof; - ct->linenr= lnr; - ct->charnr= cnr; - - yof-= linedist; - - maxlen= MAX2(maxlen, (xof-tb->x/cu->fsize)); - linedata[lnr]= xof-tb->x/cu->fsize; - linedata2[lnr]= cnr; - linedata3[lnr]= tb->w/cu->fsize; - linedata4[lnr]= wsnr; + if (ascii == '\n' || ascii == '\r' || ascii == 0 || ct->dobreak) { + ct->xof = xof; + ct->yof = yof; + ct->linenr = lnr; + ct->charnr = cnr; + + yof -= linedist; + + maxlen = MAX2(maxlen, (xof - tb->x / cu->fsize)); + linedata[lnr] = xof - tb->x / cu->fsize; + linedata2[lnr] = cnr; + linedata3[lnr] = tb->w / cu->fsize; + linedata4[lnr] = wsnr; if ( (tb->h != 0.0f) && - ((-(yof-(tb->y/cu->fsize))) > ((tb->h/cu->fsize)-(linedist*cu->fsize)) - cu->yof) && - (cu->totbox > (curbox+1)) ) { - maxlen= 0; + ((-(yof - (tb->y / cu->fsize))) > ((tb->h / cu->fsize) - (linedist * cu->fsize)) - cu->yof) && + (cu->totbox > (curbox + 1)) ) { + maxlen = 0; tb++; curbox++; - yof= cu->yof + tb->y/cu->fsize; + yof = cu->yof + tb->y / cu->fsize; } /* XXX, has been unused for years, need to check if this is useful, r4613 r5282 - campbell */ @@ -719,43 +718,43 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int if (ascii == '\n' || ascii == '\r') xof = cu->xof; else - xof= cu->xof + (tb->x/cu->fsize); + xof = cu->xof + (tb->x / cu->fsize); #else - xof= cu->xof + (tb->x/cu->fsize); + xof = cu->xof + (tb->x / cu->fsize); #endif lnr++; - cnr= 0; - wsnr= 0; + cnr = 0; + wsnr = 0; } - else if (ascii==9) { /* TAB */ + else if (ascii == 9) { /* TAB */ float tabfac; - ct->xof= xof; - ct->yof= yof; - ct->linenr= lnr; - ct->charnr= cnr++; - - tabfac= (xof-cu->xof+0.01f); - tabfac= 2.0f*ceilf(tabfac/2.0f); - xof= cu->xof+tabfac; + ct->xof = xof; + ct->yof = yof; + ct->linenr = lnr; + ct->charnr = cnr++; + + tabfac = (xof - cu->xof + 0.01f); + tabfac = 2.0f * ceilf(tabfac / 2.0f); + xof = cu->xof + tabfac; } else { - SelBox *sb= NULL; + SelBox *sb = NULL; float wsfac; - ct->xof= xof; - ct->yof= yof; - ct->linenr= lnr; - ct->charnr= cnr++; + ct->xof = xof; + ct->yof = yof; + ct->linenr = lnr; + ct->charnr = cnr++; - if (cu->selboxes && (i>=selstart) && (i<=selend)) { - sb = &(cu->selboxes[i-selstart]); - sb->y = yof*cu->fsize-linedist*cu->fsize*0.1f; - sb->h = linedist*cu->fsize; - sb->w = xof*cu->fsize; + if (cu->selboxes && (i >= selstart) && (i <= selend)) { + sb = &(cu->selboxes[i - selstart]); + sb->y = yof * cu->fsize - linedist * cu->fsize * 0.1f; + sb->h = linedist * cu->fsize; + sb->w = xof * cu->fsize; } - if (ascii==32) { + if (ascii == 32) { wsfac = cu->wordspace; wsnr++; } @@ -764,20 +763,20 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int // Set the width of the character twidth = char_width(cu, che, info); - xof += (twidth*wsfac*(1.0f+(info->kern/40.0f)) ) + xtrax; + xof += (twidth * wsfac * (1.0f + (info->kern / 40.0f)) ) + xtrax; if (sb) - sb->w = (xof*cu->fsize) - sb->w; + sb->w = (xof * cu->fsize) - sb->w; } ct++; } - cu->lines= 1; - ct= chartransdata; + cu->lines = 1; + ct = chartransdata; tmp = mem; - for (i= 0; i<=slen; i++, tmp++, ct++) { + for (i = 0; i <= slen; i++, tmp++, ct++) { ascii = *tmp; - if (ascii== '\n' || ascii== '\r' || ct->dobreak) cu->lines++; + if (ascii == '\n' || ascii == '\r' || ct->dobreak) cu->lines++; } // linedata is now: width of line @@ -785,55 +784,55 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int // linedata3 is now: maxlen of that line // linedata4 is now: number of whitespaces of line - if (cu->spacemode!=CU_LEFT) { - ct= chartransdata; + if (cu->spacemode != CU_LEFT) { + ct = chartransdata; - if (cu->spacemode==CU_RIGHT) { - for (i=0;i<lnr;i++) linedata[i]= linedata3[i]-linedata[i]; - for (i=0; i<=slen; i++) { - ct->xof+= linedata[ct->linenr]; + if (cu->spacemode == CU_RIGHT) { + for (i = 0; i < lnr; i++) linedata[i] = linedata3[i] - linedata[i]; + for (i = 0; i <= slen; i++) { + ct->xof += linedata[ct->linenr]; ct++; } } - else if (cu->spacemode==CU_MIDDLE) { - for (i=0;i<lnr;i++) linedata[i]= (linedata3[i]-linedata[i])/2; - for (i=0; i<=slen; i++) { - ct->xof+= linedata[ct->linenr]; + else if (cu->spacemode == CU_MIDDLE) { + for (i = 0; i < lnr; i++) linedata[i] = (linedata3[i] - linedata[i]) / 2; + for (i = 0; i <= slen; i++) { + ct->xof += linedata[ct->linenr]; ct++; } } - else if ((cu->spacemode==CU_FLUSH) && - (cu->tb[0].w != 0.0f)) { - for (i=0;i<lnr;i++) - if (linedata2[i]>1) - linedata[i]= (linedata3[i]-linedata[i])/(linedata2[i]-1); - for (i=0; i<=slen; i++) { - for (j=i; (!ELEM3(mem[j], '\0', '\n', '\r')) && (chartransdata[j].dobreak == 0) && (j < slen); j++) { + else if ((cu->spacemode == CU_FLUSH) && + (cu->tb[0].w != 0.0f)) { + for (i = 0; i < lnr; i++) + if (linedata2[i] > 1) + linedata[i] = (linedata3[i] - linedata[i]) / (linedata2[i] - 1); + for (i = 0; i <= slen; i++) { + for (j = i; (!ELEM3(mem[j], '\0', '\n', '\r')) && (chartransdata[j].dobreak == 0) && (j < slen); j++) { /* do nothing */ } // if ((mem[j]!='\r') && (mem[j]!='\n') && (mem[j])) { - ct->xof+= ct->charnr*linedata[ct->linenr]; + ct->xof += ct->charnr * linedata[ct->linenr]; // } ct++; } } - else if ((cu->spacemode==CU_JUSTIFY) && (cu->tb[0].w != 0.0f)) { + else if ((cu->spacemode == CU_JUSTIFY) && (cu->tb[0].w != 0.0f)) { float curofs = 0.0f; for (i = 0; i <= slen; i++) { - for (j=i; (mem[j]) && (mem[j]!='\n') && - (mem[j] != '\r') && (chartransdata[j].dobreak == 0) && (j < slen); + for (j = i; (mem[j]) && (mem[j] != '\n') && + (mem[j] != '\r') && (chartransdata[j].dobreak == 0) && (j < slen); j++) { /* pass */ } - if ((mem[j]!='\r') && (mem[j]!='\n') && - ((chartransdata[j].dobreak!=0))) { - if (mem[i]==' ') curofs += (linedata3[ct->linenr]-linedata[ct->linenr])/linedata4[ct->linenr]; - ct->xof+= curofs; + if ((mem[j] != '\r') && (mem[j] != '\n') && + ((chartransdata[j].dobreak != 0))) { + if (mem[i] == ' ') curofs += (linedata3[ct->linenr] - linedata[ct->linenr]) / linedata4[ct->linenr]; + ct->xof += curofs; } - if (mem[i]=='\n' || mem[i]=='\r' || chartransdata[i].dobreak) curofs= 0; + if (mem[i] == '\n' || mem[i] == '\r' || chartransdata[i].dobreak) curofs = 0; ct++; } } @@ -841,13 +840,13 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int /* TEXT ON CURVE */ /* Note: Only OB_CURVE objects could have a path */ - if (cu->textoncurve && cu->textoncurve->type==OB_CURVE) { - Curve *cucu= cu->textoncurve->data; - int oldflag= cucu->flag; + if (cu->textoncurve && cu->textoncurve->type == OB_CURVE) { + Curve *cucu = cu->textoncurve->data; + int oldflag = cucu->flag; - cucu->flag |= (CU_PATH+CU_FOLLOW); + cucu->flag |= (CU_PATH + CU_FOLLOW); - if (cucu->path==NULL) makeDispListCurveTypes(scene, cu->textoncurve, 0); + if (cucu->path == NULL) makeDispListCurveTypes(scene, cu->textoncurve, 0); if (cucu->path) { float distfac, imat[4][4], imat3[3][3], cmat[3][3]; float minx, maxx, miny, maxy; @@ -858,116 +857,116 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int copy_m3_m4(cmat, cu->textoncurve->obmat); mul_m3_m3m3(cmat, cmat, imat3); - sizefac= normalize_v3(cmat[0])/cu->fsize; + sizefac = normalize_v3(cmat[0]) / cu->fsize; - minx=miny= 1.0e20f; - maxx=maxy= -1.0e20f; - ct= chartransdata; - for (i=0; i<=slen; i++, ct++) { - if (minx>ct->xof) minx= ct->xof; - if (maxx<ct->xof) maxx= ct->xof; - if (miny>ct->yof) miny= ct->yof; - if (maxy<ct->yof) maxy= ct->yof; + minx = miny = 1.0e20f; + maxx = maxy = -1.0e20f; + ct = chartransdata; + for (i = 0; i <= slen; i++, ct++) { + if (minx > ct->xof) minx = ct->xof; + if (maxx < ct->xof) maxx = ct->xof; + if (miny > ct->yof) miny = ct->yof; + if (maxy < ct->yof) maxy = ct->yof; } /* we put the x-coordinaat exact at the curve, the y is rotated */ /* length correction */ - distfac= sizefac*cucu->path->totdist/(maxx-minx); - timeofs= 0.0f; + distfac = sizefac * cucu->path->totdist / (maxx - minx); + timeofs = 0.0f; if (distfac > 1.0f) { /* path longer than text: spacemode involves */ - distfac= 1.0f/distfac; + distfac = 1.0f / distfac; - if (cu->spacemode==CU_RIGHT) { - timeofs= 1.0f-distfac; + if (cu->spacemode == CU_RIGHT) { + timeofs = 1.0f - distfac; } - else if (cu->spacemode==CU_MIDDLE) { - timeofs= (1.0f-distfac)/2.0f; + else if (cu->spacemode == CU_MIDDLE) { + timeofs = (1.0f - distfac) / 2.0f; } - else if (cu->spacemode==CU_FLUSH) distfac= 1.0f; + else if (cu->spacemode == CU_FLUSH) distfac = 1.0f; } - else distfac= 1.0; + else distfac = 1.0; - distfac/= (maxx-minx); + distfac /= (maxx - minx); - timeofs+= distfac*cu->xof; /* not cyclic */ + timeofs += distfac * cu->xof; /* not cyclic */ - ct= chartransdata; - for (i=0; i<=slen; i++, ct++) { + ct = chartransdata; + for (i = 0; i <= slen; i++, ct++) { float ctime, dtime, vec[4], tvec[4], rotvec[3]; float si, co; /* rotate around center character */ ascii = mem[i]; - che= find_vfont_char(vfd, ascii); + che = find_vfont_char(vfd, ascii); twidth = char_width(cu, che, info); - dtime= distfac*0.5f*twidth; + dtime = distfac * 0.5f * twidth; - ctime= timeofs + distfac*( ct->xof - minx); + ctime = timeofs + distfac * (ct->xof - minx); CLAMP(ctime, 0.0f, 1.0f); /* calc the right loc AND the right rot separately */ /* vec, tvec need 4 items */ where_on_path(cu->textoncurve, ctime, vec, tvec, NULL, NULL, NULL); - where_on_path(cu->textoncurve, ctime+dtime, tvec, rotvec, NULL, NULL, NULL); + where_on_path(cu->textoncurve, ctime + dtime, tvec, rotvec, NULL, NULL, NULL); mul_v3_fl(vec, sizefac); - ct->rot= (float)(M_PI-atan2(rotvec[1], rotvec[0])); + ct->rot = (float)(M_PI - atan2(rotvec[1], rotvec[0])); - si= (float)sin(ct->rot); - co= (float)cos(ct->rot); + si = (float)sin(ct->rot); + co = (float)cos(ct->rot); - yof= ct->yof; + yof = ct->yof; - ct->xof= vec[0] + si*yof; - ct->yof= vec[1] + co*yof; + ct->xof = vec[0] + si * yof; + ct->yof = vec[1] + co * yof; } - cucu->flag= oldflag; + cucu->flag = oldflag; } } if (cu->selboxes) { - ct= chartransdata; - for (i=0; i<=selend; i++, ct++) { - if (i>=selstart) { - cu->selboxes[i-selstart].x = ct->xof*cu->fsize; - cu->selboxes[i-selstart].y = ct->yof*cu->fsize; + ct = chartransdata; + for (i = 0; i <= selend; i++, ct++) { + if (i >= selstart) { + cu->selboxes[i - selstart].x = ct->xof * cu->fsize; + cu->selboxes[i - selstart].y = ct->yof * cu->fsize; } } } - if (mode==FO_CURSUP || mode==FO_CURSDOWN || mode==FO_PAGEUP || mode==FO_PAGEDOWN) { + if (mode == FO_CURSUP || mode == FO_CURSDOWN || mode == FO_PAGEUP || mode == FO_PAGEDOWN) { /* 2: curs up * 3: curs down */ - ct= chartransdata+cu->pos; + ct = chartransdata + cu->pos; - if ((mode==FO_CURSUP || mode==FO_PAGEUP) && ct->linenr==0); - else if ((mode==FO_CURSDOWN || mode==FO_PAGEDOWN) && ct->linenr==lnr); + if ((mode == FO_CURSUP || mode == FO_PAGEUP) && ct->linenr == 0) ; + else if ((mode == FO_CURSDOWN || mode == FO_PAGEDOWN) && ct->linenr == lnr) ; else { switch (mode) { - case FO_CURSUP: lnr= ct->linenr-1; break; - case FO_CURSDOWN: lnr= ct->linenr+1; break; - case FO_PAGEUP: lnr= ct->linenr-10; break; - case FO_PAGEDOWN: lnr= ct->linenr+10; break; + case FO_CURSUP: lnr = ct->linenr - 1; break; + case FO_CURSDOWN: lnr = ct->linenr + 1; break; + case FO_PAGEUP: lnr = ct->linenr - 10; break; + case FO_PAGEDOWN: lnr = ct->linenr + 10; break; } - cnr= ct->charnr; + cnr = ct->charnr; /* seek for char with lnr en cnr */ - cu->pos= 0; - ct= chartransdata; - for (i= 0; i<slen; i++) { - if (ct->linenr==lnr) { - if (ct->charnr==cnr) break; - if ( (ct+1)->charnr==0) break; + cu->pos = 0; + ct = chartransdata; + for (i = 0; i < slen; i++) { + if (ct->linenr == lnr) { + if (ct->charnr == cnr) break; + if ( (ct + 1)->charnr == 0) break; } - else if (ct->linenr>lnr) break; + else if (ct->linenr > lnr) break; cu->pos++; ct++; } @@ -978,23 +977,23 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int if (cu->editfont) { float si, co; - ct= chartransdata+cu->pos; - si= (float)sin(ct->rot); - co= (float)cos(ct->rot); + ct = chartransdata + cu->pos; + si = (float)sin(ct->rot); + co = (float)cos(ct->rot); - f= cu->editfont->textcurs[0]; + f = cu->editfont->textcurs[0]; - f[0]= cu->fsize*(-0.1f*co + ct->xof); - f[1]= cu->fsize*(0.1f*si + ct->yof); + f[0] = cu->fsize * (-0.1f * co + ct->xof); + f[1] = cu->fsize * (0.1f * si + ct->yof); - f[2]= cu->fsize*(0.1f*co + ct->xof); - f[3]= cu->fsize*(-0.1f*si + ct->yof); + f[2] = cu->fsize * (0.1f * co + ct->xof); + f[3] = cu->fsize * (-0.1f * si + ct->yof); - f[4]= cu->fsize*( 0.1f*co + 0.8f*si + ct->xof); - f[5]= cu->fsize*(-0.1f*si + 0.8f*co + ct->yof); + f[4] = cu->fsize * (0.1f * co + 0.8f * si + ct->xof); + f[5] = cu->fsize * (-0.1f * si + 0.8f * co + ct->yof); - f[6]= cu->fsize*(-0.1f*co + 0.8f*si + ct->xof); - f[7]= cu->fsize*( 0.1f*si + 0.8f*co + ct->yof); + f[6] = cu->fsize * (-0.1f * co + 0.8f * si + ct->xof); + f[7] = cu->fsize * (0.1f * si + 0.8f * co + ct->yof); } @@ -1013,9 +1012,9 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int /* make nurbdata */ BKE_nurbList_free(&cu->nurb); - ct= chartransdata; - if (cu->sepchar==0) { - for (i= 0; i<slen; i++) { + ct = chartransdata; + if (cu->sepchar == 0) { + for (i = 0; i < slen; i++) { unsigned long cha = (uintptr_t) mem[i]; info = &(custrinfo[i]); if (info->mat_nr > (ob->totcol)) { @@ -1027,42 +1026,42 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int buildchar(bmain, cu, cha, info, ct->xof, ct->yof, ct->rot, i); if ((info->flag & CU_CHINFO_UNDERLINE) && (cu->textoncurve == NULL) && (cha != '\n') && (cha != '\r')) { - float ulwidth, uloverlap= 0.0f; + float ulwidth, uloverlap = 0.0f; - if ( (i<(slen-1)) && (mem[i+1] != '\n') && (mem[i+1] != '\r') && - ((mem[i+1] != ' ') || (custrinfo[i+1].flag & CU_CHINFO_UNDERLINE)) && ((custrinfo[i+1].flag & CU_CHINFO_WRAP)==0) - ) { + if ( (i < (slen - 1)) && (mem[i + 1] != '\n') && (mem[i + 1] != '\r') && + ((mem[i + 1] != ' ') || (custrinfo[i + 1].flag & CU_CHINFO_UNDERLINE)) && ((custrinfo[i + 1].flag & CU_CHINFO_WRAP) == 0) + ) { uloverlap = xtrax + 0.1f; } // Find the character, the characters has to be in the memory already // since character checking has been done earlier already. - che= find_vfont_char(vfd, cha); + che = find_vfont_char(vfd, cha); twidth = char_width(cu, che, info); - ulwidth = cu->fsize * ((twidth* (1.0f+(info->kern/40.0f)))+uloverlap); - build_underline(cu, ct->xof*cu->fsize, ct->yof*cu->fsize + (cu->ulpos-0.05f)*cu->fsize, - ct->xof*cu->fsize + ulwidth, - ct->yof*cu->fsize + (cu->ulpos-0.05f)*cu->fsize - cu->ulheight*cu->fsize, - i, info->mat_nr); + ulwidth = cu->fsize * ((twidth * (1.0f + (info->kern / 40.0f))) + uloverlap); + build_underline(cu, ct->xof * cu->fsize, ct->yof * cu->fsize + (cu->ulpos - 0.05f) * cu->fsize, + ct->xof * cu->fsize + ulwidth, + ct->yof * cu->fsize + (cu->ulpos - 0.05f) * cu->fsize - cu->ulheight * cu->fsize, + i, info->mat_nr); } ct++; } } else { int outta = 0; - for (i= 0; (i<slen) && (outta==0); i++) { + for (i = 0; (i < slen) && (outta == 0); i++) { ascii = mem[i]; info = &(custrinfo[i]); - if (cu->sepchar == (i+1)) { + if (cu->sepchar == (i + 1)) { float vecyo[3]; - vecyo[0]= ct->xof; - vecyo[1]= ct->yof; - vecyo[2]= 0.0f; + vecyo[0] = ct->xof; + vecyo[1] = ct->yof; + vecyo[2] = 0.0f; mem[0] = ascii; mem[1] = 0; - custrinfo[0]= *info; + custrinfo[0] = *info; cu->pos = 1; cu->len = 1; mul_v3_m4v3(ob->loc, ob->obmat, vecyo); @@ -1074,7 +1073,7 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int } } - if (mode==FO_DUPLI) { + if (mode == FO_DUPLI) { MEM_freeN(mem); return chartransdata; } diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index da3acce9228..6ec19018ab5 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -62,8 +62,8 @@ void free_gpencil_strokes(bGPDframe *gpf) if (gpf == NULL) return; /* free strokes */ - for (gps= gpf->strokes.first; gps; gps= gpsn) { - gpsn= gps->next; + for (gps = gpf->strokes.first; gps; gps = gpsn) { + gpsn = gps->next; /* free stroke memory arrays, then stroke itself */ if (gps->points) MEM_freeN(gps->points); @@ -80,8 +80,8 @@ void free_gpencil_frames(bGPDlayer *gpl) if (gpl == NULL) return; /* free frames */ - for (gpf= gpl->frames.first; gpf; gpf= gpfn) { - gpfn= gpf->next; + for (gpf = gpl->frames.first; gpf; gpf = gpfn) { + gpfn = gpf->next; /* free strokes and their associated memory */ free_gpencil_strokes(gpf); @@ -98,8 +98,8 @@ void free_gpencil_layers(ListBase *list) if (list == NULL) return; /* delete layers*/ - for (gpl= list->first; gpl; gpl= gpln) { - gpln= gpl->next; + for (gpl = list->first; gpl; gpl = gpln) { + gpln = gpl->next; /* free layers and their data */ free_gpencil_frames(gpl); @@ -117,32 +117,32 @@ void BKE_gpencil_free(bGPdata *gpd) /* -------- Container Creation ---------- */ /* add a new gp-frame to the given layer */ -bGPDframe *gpencil_frame_addnew (bGPDlayer *gpl, int cframe) +bGPDframe *gpencil_frame_addnew(bGPDlayer *gpl, int cframe) { bGPDframe *gpf, *gf; - short state=0; + short state = 0; /* error checking */ if ((gpl == NULL) || (cframe <= 0)) return NULL; /* allocate memory for this frame */ - gpf= MEM_callocN(sizeof(bGPDframe), "bGPDframe"); - gpf->framenum= cframe; + gpf = MEM_callocN(sizeof(bGPDframe), "bGPDframe"); + gpf->framenum = cframe; /* find appropriate place to add frame */ if (gpl->frames.first) { - for (gf= gpl->frames.first; gf; gf= gf->next) { + for (gf = gpl->frames.first; gf; gf = gf->next) { /* check if frame matches one that is supposed to be added */ if (gf->framenum == cframe) { - state= -1; + state = -1; break; } /* if current frame has already exceeded the frame to add, add before */ if (gf->framenum > cframe) { BLI_insertlinkbefore(&gpl->frames, gf, gpf); - state= 1; + state = 1; break; } } @@ -163,7 +163,7 @@ bGPDframe *gpencil_frame_addnew (bGPDlayer *gpl, int cframe) } /* add a new gp-layer and make it the active layer */ -bGPDlayer *gpencil_layer_addnew (bGPdata *gpd) +bGPDlayer *gpencil_layer_addnew(bGPdata *gpd) { bGPDlayer *gpl; @@ -172,13 +172,13 @@ bGPDlayer *gpencil_layer_addnew (bGPdata *gpd) return NULL; /* allocate memory for frame and add to end of list */ - gpl= MEM_callocN(sizeof(bGPDlayer), "bGPDlayer"); + gpl = MEM_callocN(sizeof(bGPDlayer), "bGPDlayer"); /* add to datablock */ BLI_addtail(&gpd->layers, gpl); /* set basic settings */ - gpl->color[3]= 0.9f; + gpl->color[3] = 0.9f; gpl->thickness = 3; /* auto-name */ @@ -193,15 +193,15 @@ bGPDlayer *gpencil_layer_addnew (bGPdata *gpd) } /* add a new gp-datablock */ -bGPdata *gpencil_data_addnew (const char name[]) +bGPdata *gpencil_data_addnew(const char name[]) { bGPdata *gpd; /* allocate memory for a new block */ - gpd= BKE_libblock_alloc(&G.main->gpencil, ID_GD, name); + gpd = BKE_libblock_alloc(&G.main->gpencil, ID_GD, name); /* initial settings */ - gpd->flag = (GP_DATA_DISPINFO|GP_DATA_EXPAND); + gpd->flag = (GP_DATA_DISPINFO | GP_DATA_EXPAND); /* for now, stick to view is also enabled by default * since this is more useful... @@ -214,7 +214,7 @@ bGPdata *gpencil_data_addnew (const char name[]) /* -------- Data Duplication ---------- */ /* make a copy of a given gpencil frame */ -bGPDframe *gpencil_frame_duplicate (bGPDframe *src) +bGPDframe *gpencil_frame_duplicate(bGPDframe *src) { bGPDstroke *gps, *gpsd; bGPDframe *dst; @@ -224,15 +224,15 @@ bGPDframe *gpencil_frame_duplicate (bGPDframe *src) return NULL; /* make a copy of the source frame */ - dst= MEM_dupallocN(src); - dst->prev= dst->next= NULL; + dst = MEM_dupallocN(src); + dst->prev = dst->next = NULL; /* copy strokes */ - dst->strokes.first = dst->strokes.last= NULL; - for (gps= src->strokes.first; gps; gps= gps->next) { + dst->strokes.first = dst->strokes.last = NULL; + for (gps = src->strokes.first; gps; gps = gps->next) { /* make copy of source stroke, then adjust pointer to points too */ - gpsd= MEM_dupallocN(gps); - gpsd->points= MEM_dupallocN(gps->points); + gpsd = MEM_dupallocN(gps); + gpsd->points = MEM_dupallocN(gps->points); BLI_addtail(&dst->strokes, gpsd); } @@ -242,7 +242,7 @@ bGPDframe *gpencil_frame_duplicate (bGPDframe *src) } /* make a copy of a given gpencil layer */ -bGPDlayer *gpencil_layer_duplicate (bGPDlayer *src) +bGPDlayer *gpencil_layer_duplicate(bGPDlayer *src) { bGPDframe *gpf, *gpfd; bGPDlayer *dst; @@ -252,19 +252,19 @@ bGPDlayer *gpencil_layer_duplicate (bGPDlayer *src) return NULL; /* make a copy of source layer */ - dst= MEM_dupallocN(src); - dst->prev= dst->next= NULL; + dst = MEM_dupallocN(src); + dst->prev = dst->next = NULL; /* copy frames */ - dst->frames.first= dst->frames.last= NULL; - for (gpf= src->frames.first; gpf; gpf= gpf->next) { + dst->frames.first = dst->frames.last = NULL; + for (gpf = src->frames.first; gpf; gpf = gpf->next) { /* make a copy of source frame */ - gpfd= gpencil_frame_duplicate(gpf); + gpfd = gpencil_frame_duplicate(gpf); BLI_addtail(&dst->frames, gpfd); /* if source frame was the current layer's 'active' frame, reassign that too */ if (gpf == dst->actframe) - dst->actframe= gpfd; + dst->actframe = gpfd; } /* return new layer */ @@ -272,7 +272,7 @@ bGPDlayer *gpencil_layer_duplicate (bGPDlayer *src) } /* make a copy of a given gpencil datablock */ -bGPdata *gpencil_data_duplicate (bGPdata *src) +bGPdata *gpencil_data_duplicate(bGPdata *src) { bGPDlayer *gpl, *gpld; bGPdata *dst; @@ -282,13 +282,13 @@ bGPdata *gpencil_data_duplicate (bGPdata *src) return NULL; /* make a copy of the base-data */ - dst= MEM_dupallocN(src); + dst = MEM_dupallocN(src); /* copy layers */ - dst->layers.first= dst->layers.last= NULL; - for (gpl= src->layers.first; gpl; gpl= gpl->next) { + dst->layers.first = dst->layers.last = NULL; + for (gpl = src->layers.first; gpl; gpl = gpl->next) { /* make a copy of source layer and its data */ - gpld= gpencil_layer_duplicate(gpl); + gpld = gpencil_layer_duplicate(gpl); BLI_addtail(&dst->layers, gpld); } @@ -301,7 +301,7 @@ bGPdata *gpencil_data_duplicate (bGPdata *src) /* delete the last stroke of the given frame */ void gpencil_frame_delete_laststroke(bGPDlayer *gpl, bGPDframe *gpf) { - bGPDstroke *gps= (gpf) ? gpf->strokes.last : NULL; + bGPDstroke *gps = (gpf) ? gpf->strokes.last : NULL; int cfra = (gpf) ? gpf->framenum : 0; /* assume that the current frame was not locked */ /* error checking */ @@ -325,7 +325,7 @@ void gpencil_frame_delete_laststroke(bGPDlayer *gpl, bGPDframe *gpf) * - this sets the layer's actframe var (if allowed to) * - extension beyond range (if first gp-frame is after all frame in interest and cannot add) */ -bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) +bGPDframe *gpencil_layer_getframe(bGPDlayer *gpl, int cframe, short addnew) { bGPDframe *gpf = NULL; short found = 0; @@ -336,12 +336,12 @@ bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) /* check if there is already an active frame */ if (gpl->actframe) { - gpf= gpl->actframe; + gpf = gpl->actframe; /* do not allow any changes to layer's active frame if layer is locked from changes * or if the layer has been set to stay on the current frame */ - if (gpl->flag & (GP_LAYER_LOCKED|GP_LAYER_FRAMELOCK)) + if (gpl->flag & (GP_LAYER_LOCKED | GP_LAYER_FRAMELOCK)) return gpf; /* do not allow any changes to actframe if frame has painting tag attached to it */ if (gpf->flag & GP_FRAME_PAINT) @@ -349,13 +349,13 @@ bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) /* try to find matching frame */ if (gpf->framenum < cframe) { - for (; gpf; gpf= gpf->next) { + for (; gpf; gpf = gpf->next) { if (gpf->framenum == cframe) { - found= 1; + found = 1; break; } else if ((gpf->next) && (gpf->next->framenum > cframe)) { - found= 1; + found = 1; break; } } @@ -363,19 +363,19 @@ bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) /* set the appropriate frame */ if (addnew) { if ((found) && (gpf->framenum == cframe)) - gpl->actframe= gpf; + gpl->actframe = gpf; else - gpl->actframe= gpencil_frame_addnew(gpl, cframe); + gpl->actframe = gpencil_frame_addnew(gpl, cframe); } else if (found) - gpl->actframe= gpf; + gpl->actframe = gpf; else - gpl->actframe= gpl->frames.last; + gpl->actframe = gpl->frames.last; } else { - for (; gpf; gpf= gpf->prev) { + for (; gpf; gpf = gpf->prev) { if (gpf->framenum <= cframe) { - found= 1; + found = 1; break; } } @@ -383,35 +383,35 @@ bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) /* set the appropriate frame */ if (addnew) { if ((found) && (gpf->framenum == cframe)) - gpl->actframe= gpf; + gpl->actframe = gpf; else - gpl->actframe= gpencil_frame_addnew(gpl, cframe); + gpl->actframe = gpencil_frame_addnew(gpl, cframe); } else if (found) - gpl->actframe= gpf; + gpl->actframe = gpf; else - gpl->actframe= gpl->frames.first; + gpl->actframe = gpl->frames.first; } } else if (gpl->frames.first) { /* check which of the ends to start checking from */ - const int first= ((bGPDframe *)(gpl->frames.first))->framenum; - const int last= ((bGPDframe *)(gpl->frames.last))->framenum; + const int first = ((bGPDframe *)(gpl->frames.first))->framenum; + const int last = ((bGPDframe *)(gpl->frames.last))->framenum; - if (abs(cframe-first) > abs(cframe-last)) { + if (abs(cframe - first) > abs(cframe - last)) { /* find gp-frame which is less than or equal to cframe */ - for (gpf= gpl->frames.last; gpf; gpf= gpf->prev) { + for (gpf = gpl->frames.last; gpf; gpf = gpf->prev) { if (gpf->framenum <= cframe) { - found= 1; + found = 1; break; } } } else { /* find gp-frame which is less than or equal to cframe */ - for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { if (gpf->framenum <= cframe) { - found= 1; + found = 1; break; } } @@ -420,12 +420,12 @@ bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) /* set the appropriate frame */ if (addnew) { if ((found) && (gpf->framenum == cframe)) - gpl->actframe= gpf; + gpl->actframe = gpf; else - gpl->actframe= gpencil_frame_addnew(gpl, cframe); + gpl->actframe = gpencil_frame_addnew(gpl, cframe); } else if (found) - gpl->actframe= gpf; + gpl->actframe = gpf; else { /* unresolved errogenous situation! */ printf("Error: cannot find appropriate gp-frame\n"); @@ -435,7 +435,7 @@ bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) else { /* currently no frames (add if allowed to) */ if (addnew) - gpl->actframe= gpencil_frame_addnew(gpl, cframe); + gpl->actframe = gpencil_frame_addnew(gpl, cframe); else { /* don't do anything... this may be when no frames yet! */ /* gpl->actframe should still be NULL */ @@ -460,7 +460,7 @@ void gpencil_layer_delframe(bGPDlayer *gpl, bGPDframe *gpf) } /* get the active gp-layer for editing */ -bGPDlayer *gpencil_layer_getactive (bGPdata *gpd) +bGPDlayer *gpencil_layer_getactive(bGPdata *gpd) { bGPDlayer *gpl; @@ -469,7 +469,7 @@ bGPDlayer *gpencil_layer_getactive (bGPdata *gpd) return NULL; /* loop over layers until found (assume only one active) */ - for (gpl=gpd->layers.first; gpl; gpl=gpl->next) { + for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { if (gpl->flag & GP_LAYER_ACTIVE) return gpl; } @@ -488,7 +488,7 @@ void gpencil_layer_setactive(bGPdata *gpd, bGPDlayer *active) return; /* loop over layers deactivating all */ - for (gpl=gpd->layers.first; gpl; gpl=gpl->next) + for (gpl = gpd->layers.first; gpl; gpl = gpl->next) gpl->flag &= ~GP_LAYER_ACTIVE; /* set as active one */ @@ -498,7 +498,7 @@ void gpencil_layer_setactive(bGPdata *gpd, bGPDlayer *active) /* delete the active gp-layer */ void gpencil_layer_delactive(bGPdata *gpd) { - bGPDlayer *gpl= gpencil_layer_getactive(gpd); + bGPDlayer *gpl = gpencil_layer_getactive(gpd); /* error checking */ if (ELEM(NULL, gpd, gpl)) diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index c722522250c..2fc436ab4de 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -66,7 +66,7 @@ void BKE_group_free(Group *group) GroupObject *go; while (group->gobject.first) { - go= group->gobject.first; + go = group->gobject.first; BLI_remlink(&group->gobject, go); free_group_object(go); } @@ -74,67 +74,67 @@ void BKE_group_free(Group *group) void BKE_group_unlink(Group *group) { - Main *bmain= G.main; + Main *bmain = G.main; Material *ma; Object *ob; Scene *sce; SceneRenderLayer *srl; ParticleSystem *psys; - for (ma= bmain->mat.first; ma; ma= ma->id.next) { - if (ma->group==group) - ma->group= NULL; + for (ma = bmain->mat.first; ma; ma = ma->id.next) { + if (ma->group == group) + ma->group = NULL; } - for (ma= bmain->mat.first; ma; ma= ma->id.next) { - if (ma->group==group) - ma->group= NULL; + for (ma = bmain->mat.first; ma; ma = ma->id.next) { + if (ma->group == group) + ma->group = NULL; } - for (sce= bmain->scene.first; sce; sce= sce->id.next) { - Base *base= sce->base.first; + for (sce = bmain->scene.first; sce; sce = sce->id.next) { + Base *base = sce->base.first; /* ensure objects are not in this group */ - for (; base; base= base->next) { - if (rem_from_group(group, base->object, sce, base) && find_group(base->object, NULL)==NULL) { + for (; base; base = base->next) { + if (rem_from_group(group, base->object, sce, base) && find_group(base->object, NULL) == NULL) { base->object->flag &= ~OB_FROMGROUP; base->flag &= ~OB_FROMGROUP; } } - for (srl= sce->r.layers.first; srl; srl= srl->next) { - if (srl->light_override==group) - srl->light_override= NULL; + for (srl = sce->r.layers.first; srl; srl = srl->next) { + if (srl->light_override == group) + srl->light_override = NULL; } } - for (ob= bmain->object.first; ob; ob= ob->id.next) { + for (ob = bmain->object.first; ob; ob = ob->id.next) { - if (ob->dup_group==group) { - ob->dup_group= NULL; -#if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */ + if (ob->dup_group == group) { + ob->dup_group = NULL; +#if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */ { bActionStrip *strip; /* duplicator strips use a group object, we remove it */ - for (strip= ob->nlastrips.first; strip; strip= strip->next) { + for (strip = ob->nlastrips.first; strip; strip = strip->next) { if (strip->object) - strip->object= NULL; + strip->object = NULL; } } #endif } - for (psys=ob->particlesystem.first; psys; psys=psys->next) { - if (psys->part->dup_group==group) - psys->part->dup_group= NULL; -#if 0 /* not used anymore, only keps for readfile.c, no need to account for this */ - if (psys->part->eff_group==group) - psys->part->eff_group= NULL; + for (psys = ob->particlesystem.first; psys; psys = psys->next) { + if (psys->part->dup_group == group) + psys->part->dup_group = NULL; +#if 0 /* not used anymore, only keps for readfile.c, no need to account for this */ + if (psys->part->eff_group == group) + psys->part->eff_group = NULL; #endif } } /* group stays in library, but no members */ BKE_group_free(group); - group->id.us= 0; + group->id.us = 0; } Group *add_group(const char *name) @@ -142,7 +142,7 @@ Group *add_group(const char *name) Group *group; group = BKE_libblock_alloc(&G.main->group, ID_GR, name); - group->layer= (1<<20)-1; + group->layer = (1 << 20) - 1; return group; } @@ -150,7 +150,7 @@ Group *BKE_group_copy(Group *group) { Group *groupn; - groupn= MEM_dupallocN(group); + groupn = MEM_dupallocN(group); BLI_duplicatelist(&groupn->gobject, &group->gobject); return groupn; @@ -161,17 +161,17 @@ static int add_to_group_internal(Group *group, Object *ob) { GroupObject *go; - if (group==NULL || ob==NULL) return 0; + if (group == NULL || ob == NULL) return 0; /* check if the object has been added already */ - for (go= group->gobject.first; go; go= go->next) { - if (go->ob==ob) return 0; + for (go = group->gobject.first; go; go = go->next) { + if (go->ob == ob) return 0; } - go= MEM_callocN(sizeof(GroupObject), "groupobject"); + go = MEM_callocN(sizeof(GroupObject), "groupobject"); BLI_addtail(&group->gobject, go); - go->ob= ob; + go->ob = ob; return 1; } @@ -179,10 +179,10 @@ static int add_to_group_internal(Group *group, Object *ob) int add_to_group(Group *group, Object *object, Scene *scene, Base *base) { if (add_to_group_internal(group, object)) { - if ((object->flag & OB_FROMGROUP)==0) { + if ((object->flag & OB_FROMGROUP) == 0) { - if (scene && base==NULL) - base= BKE_scene_base_find(scene, object); + if (scene && base == NULL) + base = BKE_scene_base_find(scene, object); object->flag |= OB_FROMGROUP; @@ -201,18 +201,18 @@ static int rem_from_group_internal(Group *group, Object *ob) { GroupObject *go, *gon; int removed = 0; - if (group==NULL) return 0; + if (group == NULL) return 0; - go= group->gobject.first; + go = group->gobject.first; while (go) { - gon= go->next; - if (go->ob==ob) { + gon = go->next; + if (go->ob == ob) { BLI_remlink(&group->gobject, go); free_group_object(go); removed = 1; /* should break here since an object being in a group twice cant happen? */ } - go= gon; + go = gon; } return removed; } @@ -222,8 +222,8 @@ int rem_from_group(Group *group, Object *object, Scene *scene, Base *base) if (rem_from_group_internal(group, object)) { /* object can be NULL */ if (object && find_group(object, NULL) == NULL) { - if (scene && base==NULL) - base= BKE_scene_base_find(scene, object); + if (scene && base == NULL) + base = BKE_scene_base_find(scene, object); object->flag &= ~OB_FROMGROUP; @@ -241,10 +241,10 @@ int object_in_group(Object *ob, Group *group) { GroupObject *go; - if (group==NULL || ob==NULL) return 0; + if (group == NULL || ob == NULL) return 0; - for (go= group->gobject.first; go; go= go->next) { - if (go->ob==ob) + for (go = group->gobject.first; go; go = go->next) { + if (go->ob == ob) return 1; } return 0; @@ -253,14 +253,14 @@ int object_in_group(Object *ob, Group *group) Group *find_group(Object *ob, Group *group) { if (group) - group= group->id.next; + group = group->id.next; else - group= G.main->group.first; + group = G.main->group.first; while (group) { if (object_in_group(ob, group)) return group; - group= group->id.next; + group = group->id.next; } return NULL; } @@ -269,11 +269,11 @@ void group_tag_recalc(Group *group) { GroupObject *go; - if (group==NULL) return; + if (group == NULL) return; - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { if (go->ob) - go->ob->recalc= go->recalc; + go->ob->recalc = go->recalc; } } @@ -286,7 +286,7 @@ int group_is_animated(Object *UNUSED(parent), Group *group) return 1; #endif - for (go= group->gobject.first; go; go= go->next) + for (go = group->gobject.first; go; go = go->next) if (go->ob && go->ob->proxy) return 1; @@ -298,38 +298,38 @@ int group_is_animated(Object *UNUSED(parent), Group *group) /* keep checking nla.c though, in case internal structure of strip changes */ static void group_replaces_nla(Object *parent, Object *target, char mode) { - static ListBase nlastrips={NULL, NULL}; - static bAction *action= NULL; - static int done= 0; + static ListBase nlastrips = {NULL, NULL}; + static bAction *action = NULL; + static int done = 0; bActionStrip *strip, *nstrip; - if (mode=='s') { + if (mode == 's') { - for (strip= parent->nlastrips.first; strip; strip= strip->next) { - if (strip->object==target) { - if (done==0) { + for (strip = parent->nlastrips.first; strip; strip = strip->next) { + if (strip->object == target) { + if (done == 0) { /* clear nla & action from object */ - nlastrips= target->nlastrips; - target->nlastrips.first= target->nlastrips.last= NULL; - action= target->action; - target->action= NULL; + nlastrips = target->nlastrips; + target->nlastrips.first = target->nlastrips.last = NULL; + action = target->action; + target->action = NULL; target->nlaflag |= OB_NLA_OVERRIDE; - done= 1; + done = 1; } - nstrip= MEM_dupallocN(strip); + nstrip = MEM_dupallocN(strip); BLI_addtail(&target->nlastrips, nstrip); } } } - else if (mode=='e') { + else if (mode == 'e') { if (done) { BLI_freelistN(&target->nlastrips); - target->nlastrips= nlastrips; - target->action= action; + target->nlastrips = nlastrips; + target->action = action; - nlastrips.first= nlastrips.last= NULL; /* not needed, but yah... :) */ - action= NULL; - done= 0; + nlastrips.first = nlastrips.last = NULL; /* not needed, but yah... :) */ + action = NULL; + done = 0; } } } @@ -353,30 +353,30 @@ void group_handle_recalc_and_update(Scene *scene, Object *UNUSED(parent), Group int cfrao; /* switch to local time */ - cfrao= scene->r.cfra; + cfrao = scene->r.cfra; /* we need a DAG per group... */ - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { if (go->ob && go->recalc) { - go->ob->recalc= go->recalc; + go->ob->recalc = go->recalc; group_replaces_nla(parent, go->ob, 's'); BKE_object_handle_update(scene, go->ob); group_replaces_nla(parent, go->ob, 'e'); /* leave recalc tags in case group members are in normal scene */ - go->ob->recalc= go->recalc; + go->ob->recalc = go->recalc; } } /* restore */ - scene->r.cfra= cfrao; + scene->r.cfra = cfrao; } else #endif { /* only do existing tags, as set by regular depsgraph */ - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { if (go->ob) { if (go->ob->recalc) { BKE_object_handle_update(scene, go->ob); @@ -391,17 +391,17 @@ Object *group_get_member_with_action(Group *group, bAction *act) { GroupObject *go; - if (group==NULL || act==NULL) return NULL; + if (group == NULL || act == NULL) return NULL; - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { if (go->ob) { - if (go->ob->action==act) + if (go->ob->action == act) return go->ob; if (go->ob->nlastrips.first) { bActionStrip *strip; - for (strip= go->ob->nlastrips.first; strip; strip= strip->next) { - if (strip->act==act) + for (strip = go->ob->nlastrips.first; strip; strip = strip->next) { + if (strip->act == act) return go->ob; } } @@ -418,21 +418,21 @@ void group_relink_nla_objects(Object *ob) GroupObject *go; bActionStrip *strip; - if (ob==NULL || ob->dup_group==NULL) return; - group= ob->dup_group; + if (ob == NULL || ob->dup_group == NULL) return; + group = ob->dup_group; - for (strip= ob->nlastrips.first; strip; strip= strip->next) { + for (strip = ob->nlastrips.first; strip; strip = strip->next) { if (strip->object) { - for (go= group->gobject.first; go; go= go->next) { + for (go = group->gobject.first; go; go = go->next) { if (go->ob) { - if (strcmp(go->ob->id.name, strip->object->id.name)==0) + if (strcmp(go->ob->id.name, strip->object->id.name) == 0) break; } } if (go) - strip->object= go->ob; + strip->object = go->ob; else - strip->object= NULL; + strip->object = NULL; } } diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 88cfa63e3e7..aff1e65224b 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -92,18 +92,18 @@ #include "BLO_sys_types.h" // for intptr_t support /* max int, to indicate we don't store sequences in ibuf */ -#define IMA_NO_INDEX 0x7FEFEFEF +#define IMA_NO_INDEX 0x7FEFEFEF /* quick lookup: supports 1 million frames, thousand passes */ -#define IMA_MAKE_INDEX(frame, index) ((frame)<<10)+index -#define IMA_INDEX_FRAME(index) (index>>10) -#define IMA_INDEX_PASS(index) (index & ~1023) +#define IMA_MAKE_INDEX(frame, index) ((frame) << 10) + index +#define IMA_INDEX_FRAME(index) (index >> 10) +#define IMA_INDEX_PASS(index) (index & ~1023) /* ******** IMAGE PROCESSING ************* */ -static void de_interlace_ng(struct ImBuf *ibuf) /* neogeo fields */ +static void de_interlace_ng(struct ImBuf *ibuf) /* neogeo fields */ { - struct ImBuf * tbuf1, * tbuf2; + struct ImBuf *tbuf1, *tbuf2; if (ibuf == NULL) return; if (ibuf->flags & IB_fields) return; @@ -129,9 +129,9 @@ static void de_interlace_ng(struct ImBuf *ibuf) /* neogeo fields */ ibuf->y /= 2; } -static void de_interlace_st(struct ImBuf *ibuf) /* standard fields */ +static void de_interlace_st(struct ImBuf *ibuf) /* standard fields */ { - struct ImBuf * tbuf1, * tbuf2; + struct ImBuf *tbuf1, *tbuf2; if (ibuf == NULL) return; if (ibuf->flags & IB_fields) return; @@ -159,7 +159,7 @@ static void de_interlace_st(struct ImBuf *ibuf) /* standard fields */ void BKE_image_de_interlace(Image *ima, int odd) { - ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL); + ImBuf *ibuf = BKE_image_get_ibuf(ima, NULL); if (ibuf) { if (odd) de_interlace_st(ibuf); @@ -185,16 +185,16 @@ static void image_free_buffers(Image *ima) } if (ima->anim) IMB_free_anim(ima->anim); - ima->anim= NULL; + ima->anim = NULL; if (ima->rr) { RE_FreeRenderResult(ima->rr); - ima->rr= NULL; + ima->rr = NULL; } GPU_free_image(ima); - ima->ok= IMA_OK; + ima->ok = IMA_OK; } /* called by library too, do not free ima itself */ @@ -212,10 +212,10 @@ void BKE_image_free(Image *ima) BKE_previewimg_free(&ima->preview); - for (a=0; a<IMA_MAX_RENDER_SLOT; a++) { + for (a = 0; a < IMA_MAX_RENDER_SLOT; a++) { if (ima->renders[a]) { RE_FreeRenderResult(ima->renders[a]); - ima->renders[a]= NULL; + ima->renders[a] = NULL; } } } @@ -225,17 +225,17 @@ static Image *image_alloc(const char *name, short source, short type) { Image *ima; - ima= BKE_libblock_alloc(&G.main->image, ID_IM, name); + ima = BKE_libblock_alloc(&G.main->image, ID_IM, name); if (ima) { - ima->ok= IMA_OK; + ima->ok = IMA_OK; - ima->xrep= ima->yrep= 1; - ima->aspx= ima->aspy= 1.0; - ima->gen_x= 1024; ima->gen_y= 1024; - ima->gen_type= 1; /* no defines yet? */ + ima->xrep = ima->yrep = 1; + ima->aspx = ima->aspy = 1.0; + ima->gen_x = 1024; ima->gen_y = 1024; + ima->gen_type = 1; /* no defines yet? */ - ima->source= source; - ima->type= type; + ima->source = source; + ima->type = type; } return ima; } @@ -246,14 +246,14 @@ static ImBuf *image_get_ibuf(Image *ima, int index, int frame) /* this function is intended to be thread safe. with IMA_NO_INDEX this * should be OK, but when iterating over the list this is more tricky * */ - if (index==IMA_NO_INDEX) + if (index == IMA_NO_INDEX) return ima->ibufs.first; else { ImBuf *ibuf; - index= IMA_MAKE_INDEX(frame, index); - for (ibuf= ima->ibufs.first; ibuf; ibuf= ibuf->next) - if (ibuf->index==index) + index = IMA_MAKE_INDEX(frame, index); + for (ibuf = ima->ibufs.first; ibuf; ibuf = ibuf->next) + if (ibuf->index == index) return ibuf; return NULL; @@ -276,15 +276,15 @@ static void image_assign_ibuf(Image *ima, ImBuf *ibuf, int index, int frame) if (ibuf) { ImBuf *link; - if (index!=IMA_NO_INDEX) - index= IMA_MAKE_INDEX(frame, index); + if (index != IMA_NO_INDEX) + index = IMA_MAKE_INDEX(frame, index); /* insert based on index */ - for (link= ima->ibufs.first; link; link= link->next) - if (link->index>=index) + for (link = ima->ibufs.first; link; link = link->next) + if (link->index >= index) break; - ibuf->index= index; + ibuf->index = index; if (ima->flag & IMA_CM_PREDIVIDE) ibuf->flags |= IB_cm_predivide; else @@ -294,7 +294,7 @@ static void image_assign_ibuf(Image *ima, ImBuf *ibuf, int index, int frame) BLI_insertlinkbefore(&ima->ibufs, link, ibuf); /* now we don't want copies? */ - if (link && ibuf->index==link->index) + if (link && ibuf->index == link->index) image_remove_ibuf(ima, link); } } @@ -302,21 +302,21 @@ static void image_assign_ibuf(Image *ima, ImBuf *ibuf, int index, int frame) /* empty image block, of similar type and filename */ Image *BKE_image_copy(Image *ima) { - Image *nima= image_alloc(ima->id.name+2, ima->source, ima->type); + Image *nima = image_alloc(ima->id.name + 2, ima->source, ima->type); BLI_strncpy(nima->name, ima->name, sizeof(ima->name)); - nima->flag= ima->flag; - nima->tpageflag= ima->tpageflag; + nima->flag = ima->flag; + nima->tpageflag = ima->tpageflag; - nima->gen_x= ima->gen_x; - nima->gen_y= ima->gen_y; - nima->gen_type= ima->gen_type; + nima->gen_x = ima->gen_x; + nima->gen_y = ima->gen_y; + nima->gen_type = ima->gen_type; - nima->animspeed= ima->animspeed; + nima->animspeed = ima->animspeed; - nima->aspx= ima->aspx; - nima->aspy= ima->aspy; + nima->aspx = ima->aspx; + nima->aspy = ima->aspy; return nima; } @@ -329,54 +329,54 @@ static void extern_local_image(Image *UNUSED(ima)) void BKE_image_make_local(struct Image *ima) { - Main *bmain= G.main; + Main *bmain = G.main; Tex *tex; Brush *brush; Mesh *me; - int is_local= FALSE, is_lib= FALSE; + 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; + 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) { + 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) { + 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; + if (tex->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - for (brush= bmain->brush.first; brush; brush= brush->id.next) { + 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; + if (brush->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - for (me= bmain->mesh.first; me; me= me->id.next) { + 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++) { + for (i = 0; i < me->fdata.totlayer; i++) { if (me->fdata.layers[i].type == CD_MTFACE) { - tface= (MTFace*)me->fdata.layers[i].data; + tface = (MTFace *)me->fdata.layers[i].data; - for (a=0; a<me->totface; a++, tface++) { + for (a = 0; a < me->totface; a++, tface++) { if (tface->tpage == ima) { - if (me->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (me->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } @@ -387,14 +387,14 @@ void BKE_image_make_local(struct Image *ima) MTexPoly *mtpoly; int a, i; - for (i=0; i<me->pdata.totlayer; i++) { + for (i = 0; i < me->pdata.totlayer; i++) { if (me->pdata.layers[i].type == CD_MTEXPOLY) { - mtpoly= (MTexPoly*)me->pdata.layers[i].data; + mtpoly = (MTexPoly *)me->pdata.layers[i].data; - for (a=0; a<me->totpoly; a++, mtpoly++) { + for (a = 0; a < me->totpoly; a++, mtpoly++) { if (mtpoly->tpage == ima) { - if (me->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (me->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } @@ -408,55 +408,55 @@ void BKE_image_make_local(struct Image *ima) extern_local_image(ima); } else if (is_local && is_lib) { - Image *ima_new= BKE_image_copy(ima); + Image *ima_new = BKE_image_copy(ima); - ima_new->id.us= 0; + ima_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, ima->id.lib, &ima_new->id); - tex= bmain->tex.first; + tex = bmain->tex.first; while (tex) { - if (tex->id.lib==NULL) { - if (tex->ima==ima) { + if (tex->id.lib == NULL) { + if (tex->ima == ima) { tex->ima = ima_new; ima_new->id.us++; ima->id.us--; } } - tex= tex->id.next; + tex = tex->id.next; } - brush= bmain->brush.first; + brush = bmain->brush.first; while (brush) { - if (brush->id.lib==NULL) { - if (brush->clone.image==ima) { + if (brush->id.lib == NULL) { + if (brush->clone.image == ima) { brush->clone.image = ima_new; ima_new->id.us++; ima->id.us--; } } - brush= brush->id.next; + 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; + me = bmain->mesh.first; while (me) { if (me->mtface) { MTFace *tface; int a, i; - for (i=0; i<me->fdata.totlayer; i++) { + for (i = 0; i < me->fdata.totlayer; i++) { if (me->fdata.layers[i].type == CD_MTFACE) { - tface= (MTFace*)me->fdata.layers[i].data; + tface = (MTFace *)me->fdata.layers[i].data; - for (a=0; a<me->totface; a++, tface++) { + for (a = 0; a < me->totface; a++, tface++) { if (tface->tpage == ima) { tface->tpage = ima_new; if (ima_new->id.us == 0) { - tface->tpage->id.us= 1; + tface->tpage->id.us = 1; } - id_lib_extern((ID*)ima_new); + id_lib_extern((ID *)ima_new); } } } @@ -467,24 +467,24 @@ void BKE_image_make_local(struct Image *ima) MTexPoly *mtpoly; int a, i; - for (i=0; i<me->pdata.totlayer; i++) { + for (i = 0; i < me->pdata.totlayer; i++) { if (me->pdata.layers[i].type == CD_MTEXPOLY) { - mtpoly= (MTexPoly*)me->pdata.layers[i].data; + mtpoly = (MTexPoly *)me->pdata.layers[i].data; - for (a=0; a<me->totpoly; a++, mtpoly++) { + for (a = 0; a < me->totpoly; a++, mtpoly++) { if (mtpoly->tpage == ima) { mtpoly->tpage = ima_new; if (ima_new->id.us == 0) { - mtpoly->tpage->id.us= 1; + mtpoly->tpage->id.us = 1; } - id_lib_extern((ID*)ima_new); + id_lib_extern((ID *)ima_new); } } } } } - me= me->id.next; + me = me->id.next; } } } @@ -494,9 +494,9 @@ void BKE_image_merge(Image *dest, Image *source) ImBuf *ibuf; /* sanity check */ - if (dest && source && dest!=source) { + if (dest && source && dest != source) { - while ((ibuf= source->ibufs.first)) { + while ((ibuf = source->ibufs.first)) { BLI_remlink(&source->ibufs, ibuf); image_assign_ibuf(dest, ibuf, IMA_INDEX_PASS(ibuf->index), IMA_INDEX_FRAME(ibuf->index)); } @@ -516,21 +516,21 @@ Image *BKE_image_load(const char *filepath) BLI_path_abs(str, G.main->name); /* exists? */ - file= BLI_open(str, O_BINARY|O_RDONLY, 0); - if (file== -1) return NULL; + file = BLI_open(str, O_BINARY | O_RDONLY, 0); + if (file == -1) return NULL; close(file); /* create a short library name */ - len= strlen(filepath); + len = strlen(filepath); while (len > 0 && filepath[len - 1] != '/' && filepath[len - 1] != '\\') len--; - libname= filepath+len; + libname = filepath + len; - ima= image_alloc(libname, IMA_SRC_FILE, IMA_TYPE_IMAGE); + ima = image_alloc(libname, IMA_SRC_FILE, IMA_TYPE_IMAGE); BLI_strncpy(ima->name, filepath, sizeof(ima->name)); if (BLI_testextensie_array(filepath, imb_ext_movie)) - ima->source= IMA_SRC_MOVIE; + ima->source = IMA_SRC_MOVIE; return ima; } @@ -548,17 +548,17 @@ Image *BKE_image_load_exists(const char *filepath) BLI_path_abs(str, G.main->name); /* first search an identical image */ - for (ima= G.main->image.first; ima; ima= ima->id.next) { - if (ima->source!=IMA_SRC_VIEWER && ima->source!=IMA_SRC_GENERATED) { + for (ima = G.main->image.first; ima; ima = ima->id.next) { + if (ima->source != IMA_SRC_VIEWER && ima->source != IMA_SRC_GENERATED) { BLI_strncpy(strtest, ima->name, sizeof(ima->name)); BLI_path_abs(strtest, G.main->name); - if (BLI_path_cmp(strtest, str)==0) { - if (ima->anim==NULL || ima->id.us==0) { - BLI_strncpy(ima->name, filepath, sizeof(ima->name)); /* for stringcode */ - ima->id.us++; /* officially should not, it doesn't link here! */ - if (ima->ok==0) - ima->ok= IMA_OK; + if (BLI_path_cmp(strtest, str) == 0) { + if (ima->anim == NULL || ima->id.us == 0) { + BLI_strncpy(ima->name, filepath, sizeof(ima->name)); /* for stringcode */ + ima->id.us++; /* officially should not, it doesn't link here! */ + if (ima->ok == 0) + ima->ok = IMA_OK; /* RETURN! */ return ima; } @@ -572,30 +572,30 @@ Image *BKE_image_load_exists(const char *filepath) static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short uvtestgrid, float color[4]) { ImBuf *ibuf; - unsigned char *rect= NULL; - float *rect_float= NULL; + unsigned char *rect = NULL; + float *rect_float = NULL; if (floatbuf) { - ibuf= IMB_allocImBuf(width, height, depth, IB_rectfloat); - rect_float= (float*)ibuf->rect_float; + ibuf = IMB_allocImBuf(width, height, depth, IB_rectfloat); + rect_float = (float *)ibuf->rect_float; } else { - ibuf= IMB_allocImBuf(width, height, depth, IB_rect); - rect= (unsigned char*)ibuf->rect; + ibuf = IMB_allocImBuf(width, height, depth, IB_rect); + rect = (unsigned char *)ibuf->rect; } BLI_strncpy(ibuf->name, name, sizeof(ibuf->name)); ibuf->userflags |= IB_BITMAPDIRTY; switch (uvtestgrid) { - case 1: - BKE_image_buf_fill_checker(rect, rect_float, width, height); - break; - case 2: - BKE_image_buf_fill_checker_color(rect, rect_float, width, height); - break; - default: - BKE_image_buf_fill_color(rect, rect_float, width, height, color); + case 1: + BKE_image_buf_fill_checker(rect, rect_float, width, height); + break; + case 2: + BKE_image_buf_fill_checker_color(rect, rect_float, width, height); + break; + default: + BKE_image_buf_fill_color(rect, rect_float, width, height, color); } return ibuf; @@ -605,21 +605,21 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char Image *BKE_image_add_generated(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short uvtestgrid, float color[4]) { /* on save, type is changed to FILE in editsima.c */ - Image *ima= image_alloc(name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST); + Image *ima = image_alloc(name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST); if (ima) { ImBuf *ibuf; /* BLI_strncpy(ima->name, name, FILE_MAX); */ /* don't do this, this writes in ain invalid filepath! */ - ima->gen_x= width; - ima->gen_y= height; - ima->gen_type= uvtestgrid; + ima->gen_x = width; + ima->gen_y = height; + ima->gen_type = uvtestgrid; ima->gen_flag |= (floatbuf ? IMA_GEN_FLOAT : 0); - ibuf= add_ibuf_size(width, height, ima->name, depth, floatbuf, uvtestgrid, color); + ibuf = add_ibuf_size(width, height, ima->name, depth, floatbuf, uvtestgrid, color); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); - ima->ok= IMA_OK_LOADED; + ima->ok = IMA_OK_LOADED; } return ima; @@ -631,12 +631,12 @@ Image *BKE_image_add_from_imbuf(ImBuf *ibuf) /* on save, type is changed to FILE in editsima.c */ Image *ima; - ima= image_alloc(BLI_path_basename(ibuf->name), IMA_SRC_FILE, IMA_TYPE_IMAGE); + ima = image_alloc(BLI_path_basename(ibuf->name), IMA_SRC_FILE, IMA_TYPE_IMAGE); if (ima) { BLI_strncpy(ima->name, ibuf->name, FILE_MAX); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); - ima->ok= IMA_OK_LOADED; + ima->ok = IMA_OK_LOADED; } return ima; @@ -645,20 +645,20 @@ Image *BKE_image_add_from_imbuf(ImBuf *ibuf) /* packs rect from memory as PNG */ void BKE_image_memorypack(Image *ima) { - ImBuf *ibuf= image_get_ibuf(ima, IMA_NO_INDEX, 0); + ImBuf *ibuf = image_get_ibuf(ima, IMA_NO_INDEX, 0); - if (ibuf==NULL) + if (ibuf == NULL) return; if (ima->packedfile) { freePackedFile(ima->packedfile); ima->packedfile = NULL; } - ibuf->ftype= PNG; - ibuf->planes= R_IMF_PLANES_RGBA; + ibuf->ftype = PNG; + ibuf->planes = R_IMF_PLANES_RGBA; IMB_saveiff(ibuf, ibuf->name, IB_rect | IB_mem); - if (ibuf->encodedbuffer==NULL) { + if (ibuf->encodedbuffer == NULL) { printf("memory save for pack error\n"); } else { @@ -666,14 +666,14 @@ void BKE_image_memorypack(Image *ima) pf->data = ibuf->encodedbuffer; pf->size = ibuf->encodedsize; - ima->packedfile= pf; - ibuf->encodedbuffer= NULL; - ibuf->encodedsize= 0; + ima->packedfile = pf; + ibuf->encodedbuffer = NULL; + ibuf->encodedsize = 0; ibuf->userflags &= ~IB_BITMAPDIRTY; - if (ima->source==IMA_SRC_GENERATED) { - ima->source= IMA_SRC_FILE; - ima->type= IMA_TYPE_IMAGE; + if (ima->source == IMA_SRC_GENERATED) { + ima->source = IMA_SRC_FILE; + ima->type = IMA_TYPE_IMAGE; } } } @@ -690,7 +690,7 @@ static void tag_all_images_time() Image *ima; int ctime = (int)PIL_check_seconds_timer(); - ima= G.main->image.first; + ima = G.main->image.first; while (ima) { if (ima->bindcode || ima->repbind || ima->ibufs.first) { ima->lastused = ctime; @@ -718,9 +718,9 @@ void free_old_images(void) lasttime = ctime; - ima= G.main->image.first; + ima = G.main->image.first; while (ima) { - if ((ima->flag & IMA_NOCOLLECT)==0 && ctime - ima->lastused > U.textimeout) { + if ((ima->flag & IMA_NOCOLLECT) == 0 && ctime - ima->lastused > U.textimeout) { /* If it's in GL memory, deallocate and set time tag to current time * This gives textures a "second chance" to be used before dying. */ if (ima->bindcode || ima->repbind) { @@ -742,18 +742,18 @@ static uintptr_t image_mem_size(Image *ima) int level; uintptr_t size = 0; - size= 0; + size = 0; /* viewers have memory depending on other rules, has no valid rect pointer */ - if (ima->source==IMA_SRC_VIEWER) + if (ima->source == IMA_SRC_VIEWER) return 0; - for (ibuf= ima->ibufs.first; ibuf; ibuf= ibuf->next) { + for (ibuf = ima->ibufs.first; ibuf; ibuf = ibuf->next) { if (ibuf->rect) size += MEM_allocN_len(ibuf->rect); else if (ibuf->rect_float) size += MEM_allocN_len(ibuf->rect_float); - for (level=0; level<IB_MIPMAP_LEVELS; level++) { - ibufm= ibuf->mipmap[level]; + for (level = 0; level < IB_MIPMAP_LEVELS; level++) { + ibufm = ibuf->mipmap[level]; if (ibufm) { if (ibufm->rect) size += MEM_allocN_len(ibufm->rect); else if (ibufm->rect_float) size += MEM_allocN_len(ibufm->rect_float); @@ -767,18 +767,18 @@ static uintptr_t image_mem_size(Image *ima) void BKE_image_print_memlist(void) { Image *ima; - uintptr_t size, totsize= 0; + uintptr_t size, totsize = 0; - for (ima= G.main->image.first; ima; ima= ima->id.next) + for (ima = G.main->image.first; ima; ima = ima->id.next) totsize += image_mem_size(ima); - printf("\ntotal image memory len: %.3f MB\n", (double)totsize/(double)(1024*1024)); + printf("\ntotal image memory len: %.3f MB\n", (double)totsize / (double)(1024 * 1024)); - for (ima= G.main->image.first; ima; ima= ima->id.next) { - size= image_mem_size(ima); + for (ima = G.main->image.first; ima; ima = ima->id.next) { + size = image_mem_size(ima); if (size) - printf("%s len: %.3f MB\n", ima->id.name+2, (double)size/(double)(1024*1024)); + printf("%s len: %.3f MB\n", ima->id.name + 2, (double)size / (double)(1024 * 1024)); } } @@ -788,30 +788,30 @@ void BKE_image_free_all_textures(void) Image *ima; /* unsigned int totsize= 0; */ - for (ima= G.main->image.first; ima; ima= ima->id.next) + for (ima = G.main->image.first; ima; ima = ima->id.next) ima->id.flag &= ~LIB_DOIT; - for (tex= G.main->tex.first; tex; tex= tex->id.next) + for (tex = G.main->tex.first; tex; tex = tex->id.next) if (tex->ima) tex->ima->id.flag |= LIB_DOIT; - for (ima= G.main->image.first; ima; ima= ima->id.next) { + for (ima = G.main->image.first; ima; ima = ima->id.next) { if (ima->ibufs.first && (ima->id.flag & LIB_DOIT)) { ImBuf *ibuf; - for (ibuf= ima->ibufs.first; ibuf; ibuf= ibuf->next) { + for (ibuf = ima->ibufs.first; ibuf; ibuf = ibuf->next) { /* escape when image is painted on */ if (ibuf->userflags & IB_BITMAPDIRTY) break; #if 0 if (ibuf->mipmap[0]) - totsize+= 1.33*ibuf->x*ibuf->y*4; + totsize += 1.33 * ibuf->x * ibuf->y * 4; else - totsize+= ibuf->x*ibuf->y*4; + totsize += ibuf->x * ibuf->y * 4; #endif } - if (ibuf==NULL) + if (ibuf == NULL) image_free_buffers(ima); } } @@ -823,13 +823,13 @@ void BKE_image_free_anim_ibufs(Image *ima, int except_frame) { ImBuf *ibuf, *nbuf; - for (ibuf= ima->ibufs.first; ibuf; ibuf= nbuf) { - nbuf= ibuf->next; + for (ibuf = ima->ibufs.first; ibuf; ibuf = nbuf) { + nbuf = ibuf->next; if (ibuf->userflags & IB_BITMAPDIRTY) continue; - if (ibuf->index==IMA_NO_INDEX) + if (ibuf->index == IMA_NO_INDEX) continue; - if (except_frame!=IMA_INDEX_FRAME(ibuf->index)) { + if (except_frame != IMA_INDEX_FRAME(ibuf->index)) { BLI_remlink(&ima->ibufs, ibuf); if (ibuf->userdata) { @@ -845,7 +845,7 @@ void BKE_image_all_free_anim_ibufs(int cfra) { Image *ima; - for (ima= G.main->image.first; ima; ima= ima->id.next) + for (ima = G.main->image.first; ima; ima = ima->id.next) if (ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) BKE_image_free_anim_ibufs(ima, cfra); } @@ -855,47 +855,47 @@ void BKE_image_all_free_anim_ibufs(int cfra) int BKE_imtype_to_ftype(const char imtype) { - if (imtype==R_IMF_IMTYPE_TARGA) + if (imtype == R_IMF_IMTYPE_TARGA) return TGA; - else if (imtype==R_IMF_IMTYPE_RAWTGA) + else if (imtype == R_IMF_IMTYPE_RAWTGA) return RAWTGA; - else if (imtype== R_IMF_IMTYPE_IRIS) + else if (imtype == R_IMF_IMTYPE_IRIS) return IMAGIC; #ifdef WITH_HDR - else if (imtype==R_IMF_IMTYPE_RADHDR) + else if (imtype == R_IMF_IMTYPE_RADHDR) return RADHDR; #endif - else if (imtype==R_IMF_IMTYPE_PNG) + else if (imtype == R_IMF_IMTYPE_PNG) return PNG; #ifdef WITH_DDS - else if (imtype==R_IMF_IMTYPE_DDS) + else if (imtype == R_IMF_IMTYPE_DDS) return DDS; #endif - else if (imtype==R_IMF_IMTYPE_BMP) + else if (imtype == R_IMF_IMTYPE_BMP) return BMP; #ifdef WITH_TIFF - else if (imtype==R_IMF_IMTYPE_TIFF) + else if (imtype == R_IMF_IMTYPE_TIFF) return TIF; #endif - else if (imtype==R_IMF_IMTYPE_OPENEXR || imtype==R_IMF_IMTYPE_MULTILAYER) + else if (imtype == R_IMF_IMTYPE_OPENEXR || imtype == R_IMF_IMTYPE_MULTILAYER) return OPENEXR; #ifdef WITH_CINEON - else if (imtype==R_IMF_IMTYPE_CINEON) + else if (imtype == R_IMF_IMTYPE_CINEON) return CINEON; - else if (imtype==R_IMF_IMTYPE_DPX) + else if (imtype == R_IMF_IMTYPE_DPX) return DPX; #endif #ifdef WITH_OPENJPEG - else if (imtype==R_IMF_IMTYPE_JP2) + else if (imtype == R_IMF_IMTYPE_JP2) return JP2; #endif else - return JPG|90; + return JPG | 90; } char BKE_ftype_to_imtype(const int ftype) { - if (ftype==0) + if (ftype == 0) return R_IMF_IMTYPE_TARGA; else if (ftype == IMAGIC) return R_IMF_IMTYPE_IRIS; @@ -939,15 +939,15 @@ char BKE_ftype_to_imtype(const int ftype) int BKE_imtype_is_movie(const char imtype) { switch (imtype) { - case R_IMF_IMTYPE_AVIRAW: - case R_IMF_IMTYPE_AVIJPEG: - case R_IMF_IMTYPE_AVICODEC: - case R_IMF_IMTYPE_QUICKTIME: - case R_IMF_IMTYPE_FFMPEG: - case R_IMF_IMTYPE_H264: - case R_IMF_IMTYPE_THEORA: - case R_IMF_IMTYPE_XVID: - case R_IMF_IMTYPE_FRAMESERVER: + case R_IMF_IMTYPE_AVIRAW: + case R_IMF_IMTYPE_AVIJPEG: + case R_IMF_IMTYPE_AVICODEC: + case R_IMF_IMTYPE_QUICKTIME: + case R_IMF_IMTYPE_FFMPEG: + case R_IMF_IMTYPE_H264: + case R_IMF_IMTYPE_THEORA: + case R_IMF_IMTYPE_XVID: + case R_IMF_IMTYPE_FRAMESERVER: return 1; } return 0; @@ -956,8 +956,8 @@ int BKE_imtype_is_movie(const char imtype) int BKE_imtype_supports_zbuf(const char imtype) { switch (imtype) { - case R_IMF_IMTYPE_IRIZ: - case R_IMF_IMTYPE_OPENEXR: /* but not R_IMF_IMTYPE_MULTILAYER */ + case R_IMF_IMTYPE_IRIZ: + case R_IMF_IMTYPE_OPENEXR: /* but not R_IMF_IMTYPE_MULTILAYER */ return 1; } return 0; @@ -966,7 +966,7 @@ int BKE_imtype_supports_zbuf(const char imtype) int BKE_imtype_supports_compress(const char imtype) { switch (imtype) { - case R_IMF_IMTYPE_PNG: + case R_IMF_IMTYPE_PNG: return 1; } return 0; @@ -975,9 +975,9 @@ int BKE_imtype_supports_compress(const char imtype) int BKE_imtype_supports_quality(const char imtype) { switch (imtype) { - case R_IMF_IMTYPE_JPEG90: - case R_IMF_IMTYPE_JP2: - case R_IMF_IMTYPE_AVIJPEG: + case R_IMF_IMTYPE_JPEG90: + case R_IMF_IMTYPE_JP2: + case R_IMF_IMTYPE_AVIJPEG: return 1; } return 0; @@ -985,32 +985,32 @@ int BKE_imtype_supports_quality(const char imtype) char BKE_imtype_valid_channels(const char imtype) { - char chan_flag= IMA_CHAN_FLAG_RGB; /* assume all support rgb */ + char chan_flag = IMA_CHAN_FLAG_RGB; /* assume all support rgb */ /* alpha */ switch (imtype) { - case R_IMF_IMTYPE_TARGA: - case R_IMF_IMTYPE_IRIS: - case R_IMF_IMTYPE_PNG: - /* case R_IMF_IMTYPE_BMP: */ /* read but not write */ - case R_IMF_IMTYPE_RADHDR: - case R_IMF_IMTYPE_TIFF: - case R_IMF_IMTYPE_OPENEXR: - case R_IMF_IMTYPE_MULTILAYER: - case R_IMF_IMTYPE_DDS: - case R_IMF_IMTYPE_JP2: - case R_IMF_IMTYPE_QUICKTIME: + case R_IMF_IMTYPE_TARGA: + case R_IMF_IMTYPE_IRIS: + case R_IMF_IMTYPE_PNG: + /* case R_IMF_IMTYPE_BMP: */ /* read but not write */ + case R_IMF_IMTYPE_RADHDR: + case R_IMF_IMTYPE_TIFF: + case R_IMF_IMTYPE_OPENEXR: + case R_IMF_IMTYPE_MULTILAYER: + case R_IMF_IMTYPE_DDS: + case R_IMF_IMTYPE_JP2: + case R_IMF_IMTYPE_QUICKTIME: chan_flag |= IMA_CHAN_FLAG_ALPHA; } /* bw */ switch (imtype) { - case R_IMF_IMTYPE_PNG: - case R_IMF_IMTYPE_JPEG90: - case R_IMF_IMTYPE_TARGA: - case R_IMF_IMTYPE_RAWTGA: - case R_IMF_IMTYPE_TIFF: - case R_IMF_IMTYPE_IRIS: + case R_IMF_IMTYPE_PNG: + case R_IMF_IMTYPE_JPEG90: + case R_IMF_IMTYPE_TARGA: + case R_IMF_IMTYPE_RAWTGA: + case R_IMF_IMTYPE_TIFF: + case R_IMF_IMTYPE_IRIS: chan_flag |= IMA_CHAN_FLAG_BW; } @@ -1020,23 +1020,23 @@ char BKE_imtype_valid_channels(const char imtype) char BKE_imtype_valid_depths(const char imtype) { switch (imtype) { - case R_IMF_IMTYPE_RADHDR: - return R_IMF_CHAN_DEPTH_32; - case R_IMF_IMTYPE_TIFF: - return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_16; - case R_IMF_IMTYPE_OPENEXR: - return R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_32; - case R_IMF_IMTYPE_MULTILAYER: - return R_IMF_CHAN_DEPTH_32; - /* eeh, cineone does some strange 10bits per channel */ - case R_IMF_IMTYPE_DPX: - case R_IMF_IMTYPE_CINEON: - return R_IMF_CHAN_DEPTH_12; - case R_IMF_IMTYPE_JP2: - return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16; - /* most formats are 8bit only */ - default: - return R_IMF_CHAN_DEPTH_8; + case R_IMF_IMTYPE_RADHDR: + return R_IMF_CHAN_DEPTH_32; + case R_IMF_IMTYPE_TIFF: + return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_16; + case R_IMF_IMTYPE_OPENEXR: + return R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_32; + case R_IMF_IMTYPE_MULTILAYER: + return R_IMF_CHAN_DEPTH_32; + /* eeh, cineone does some strange 10bits per channel */ + case R_IMF_IMTYPE_DPX: + case R_IMF_IMTYPE_CINEON: + return R_IMF_CHAN_DEPTH_12; + case R_IMF_IMTYPE_JP2: + return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16; + /* most formats are 8bit only */ + default: + return R_IMF_CHAN_DEPTH_8; } } @@ -1083,78 +1083,78 @@ char BKE_imtype_from_arg(const char *imtype_arg) int BKE_add_image_extension(char *string, const char imtype) { - const char *extension= NULL; + const char *extension = NULL; - if (imtype== R_IMF_IMTYPE_IRIS) { + if (imtype == R_IMF_IMTYPE_IRIS) { if (!BLI_testextensie(string, ".rgb")) - extension= ".rgb"; + extension = ".rgb"; } - else if (imtype==R_IMF_IMTYPE_IRIZ) { + else if (imtype == R_IMF_IMTYPE_IRIZ) { if (!BLI_testextensie(string, ".rgb")) - extension= ".rgb"; + extension = ".rgb"; } #ifdef WITH_HDR - else if (imtype==R_IMF_IMTYPE_RADHDR) { + else if (imtype == R_IMF_IMTYPE_RADHDR) { if (!BLI_testextensie(string, ".hdr")) - extension= ".hdr"; + extension = ".hdr"; } #endif else if (ELEM5(imtype, R_IMF_IMTYPE_PNG, R_IMF_IMTYPE_FFMPEG, R_IMF_IMTYPE_H264, R_IMF_IMTYPE_THEORA, R_IMF_IMTYPE_XVID)) { if (!BLI_testextensie(string, ".png")) - extension= ".png"; + extension = ".png"; } #ifdef WITH_DDS - else if (imtype==R_IMF_IMTYPE_DDS) { + else if (imtype == R_IMF_IMTYPE_DDS) { if (!BLI_testextensie(string, ".dds")) - extension= ".dds"; + extension = ".dds"; } #endif - else if (imtype==R_IMF_IMTYPE_RAWTGA) { + else if (imtype == R_IMF_IMTYPE_RAWTGA) { if (!BLI_testextensie(string, ".tga")) - extension= ".tga"; + extension = ".tga"; } - else if (imtype==R_IMF_IMTYPE_BMP) { + else if (imtype == R_IMF_IMTYPE_BMP) { if (!BLI_testextensie(string, ".bmp")) - extension= ".bmp"; + extension = ".bmp"; } #ifdef WITH_TIFF - else if (imtype==R_IMF_IMTYPE_TIFF) { + else if (imtype == R_IMF_IMTYPE_TIFF) { if (!BLI_testextensie(string, ".tif") && !BLI_testextensie(string, ".tiff")) { - extension= ".tif"; + extension = ".tif"; } } #endif #ifdef WITH_OPENEXR else if (ELEM(imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) { if (!BLI_testextensie(string, ".exr")) - extension= ".exr"; + extension = ".exr"; } #endif #ifdef WITH_CINEON - else if (imtype==R_IMF_IMTYPE_CINEON) { + else if (imtype == R_IMF_IMTYPE_CINEON) { if (!BLI_testextensie(string, ".cin")) - extension= ".cin"; + extension = ".cin"; } - else if (imtype==R_IMF_IMTYPE_DPX) { + else if (imtype == R_IMF_IMTYPE_DPX) { if (!BLI_testextensie(string, ".dpx")) - extension= ".dpx"; + extension = ".dpx"; } #endif - else if (imtype==R_IMF_IMTYPE_TARGA) { + else if (imtype == R_IMF_IMTYPE_TARGA) { if (!BLI_testextensie(string, ".tga")) - extension= ".tga"; + extension = ".tga"; } #ifdef WITH_OPENJPEG - else if (imtype==R_IMF_IMTYPE_JP2) { + else if (imtype == R_IMF_IMTYPE_JP2) { if (!BLI_testextensie(string, ".jp2")) - extension= ".jp2"; + extension = ".jp2"; } #endif else { // R_IMF_IMTYPE_AVICODEC, R_IMF_IMTYPE_AVIRAW, R_IMF_IMTYPE_AVIJPEG, R_IMF_IMTYPE_JPEG90, R_IMF_IMTYPE_QUICKTIME etc if (!(BLI_testextensie(string, ".jpg") || BLI_testextensie(string, ".jpeg"))) - extension= ".jpg"; + extension = ".jpg"; } if (extension) { @@ -1186,17 +1186,17 @@ void BKE_imformat_defaults(ImageFormatData *im_format) /* could allow access externally - 512 is for long names, 64 is for id names */ typedef struct StampData { - char file[512]; - char note[512]; - char date[512]; - char marker[512]; - char time[512]; - char frame[512]; - char camera[64]; - char cameralens[64]; - char scene[64]; - char strip[64]; - char rendertime[64]; + char file[512]; + char note[512]; + char date[512]; + char marker[512]; + char time[512]; + char frame[512]; + char camera[64]; + char cameralens[64]; + char scene[64]; + char strip[64]; + char rendertime[64]; } StampData; static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int do_prefix) @@ -1206,7 +1206,7 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d time_t t; if (scene->r.stamp & R_STAMP_FILENAME) { - BLI_snprintf(stamp_data->file, sizeof(stamp_data->file), do_prefix ? "File %s":"%s", G.relbase_valid ? G.main->name:"<untitled>"); + BLI_snprintf(stamp_data->file, sizeof(stamp_data->file), do_prefix ? "File %s" : "%s", G.relbase_valid ? G.main->name : "<untitled>"); } else { stamp_data->file[0] = '\0'; @@ -1223,8 +1223,8 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (scene->r.stamp & R_STAMP_DATE) { t = time(NULL); tl = localtime(&t); - BLI_snprintf(text, sizeof(text), "%04d/%02d/%02d %02d:%02d:%02d", tl->tm_year+1900, tl->tm_mon+1, tl->tm_mday, tl->tm_hour, tl->tm_min, tl->tm_sec); - BLI_snprintf(stamp_data->date, sizeof(stamp_data->date), do_prefix ? "Date %s":"%s", text); + BLI_snprintf(text, sizeof(text), "%04d/%02d/%02d %02d:%02d:%02d", tl->tm_year + 1900, tl->tm_mon + 1, tl->tm_mday, tl->tm_hour, tl->tm_min, tl->tm_sec); + BLI_snprintf(stamp_data->date, sizeof(stamp_data->date), do_prefix ? "Date %s" : "%s", text); } else { stamp_data->date[0] = '\0'; @@ -1233,10 +1233,10 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (scene->r.stamp & R_STAMP_MARKER) { char *name = BKE_scene_find_last_marker_name(scene, CFRA); - if (name) BLI_strncpy(text, name, sizeof(text)); - else BLI_strncpy(text, "<none>", sizeof(text)); + if (name) BLI_strncpy(text, name, sizeof(text)); + else BLI_strncpy(text, "<none>", sizeof(text)); - BLI_snprintf(stamp_data->marker, sizeof(stamp_data->marker), do_prefix ? "Marker %s":"%s", text); + BLI_snprintf(stamp_data->marker, sizeof(stamp_data->marker), do_prefix ? "Marker %s" : "%s", text); } else { stamp_data->marker[0] = '\0'; @@ -1245,8 +1245,8 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (scene->r.stamp & R_STAMP_TIME) { int f = (int)(scene->r.cfra % scene->r.frs_sec); int s = (int)(scene->r.cfra / scene->r.frs_sec); - int h= 0; - int m= 0; + int h = 0; + int m = 0; if (s) { m = (int)(s / 60); @@ -1263,7 +1263,7 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d else BLI_snprintf(text, sizeof(text), "%02d:%02d:%02d.%03d", h, m, s, f); - BLI_snprintf(stamp_data->time, sizeof(stamp_data->time), do_prefix ? "Time %s":"%s", text); + BLI_snprintf(stamp_data->time, sizeof(stamp_data->time), do_prefix ? "Time %s" : "%s", text); } else { stamp_data->time[0] = '\0'; @@ -1271,20 +1271,20 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (scene->r.stamp & R_STAMP_FRAME) { char fmtstr[32]; - int digits= 1; + int digits = 1; - if (scene->r.efra>9) - digits= 1 + (int) log10(scene->r.efra); + if (scene->r.efra > 9) + digits = 1 + (int) log10(scene->r.efra); - BLI_snprintf(fmtstr, sizeof(fmtstr), do_prefix ? "Frame %%0%di":"%%0%di", digits); - BLI_snprintf (stamp_data->frame, sizeof(stamp_data->frame), fmtstr, scene->r.cfra); + BLI_snprintf(fmtstr, sizeof(fmtstr), do_prefix ? "Frame %%0%di" : "%%0%di", digits); + BLI_snprintf(stamp_data->frame, sizeof(stamp_data->frame), fmtstr, scene->r.cfra); } else { stamp_data->frame[0] = '\0'; } if (scene->r.stamp & R_STAMP_CAMERA) { - BLI_snprintf(stamp_data->camera, sizeof(stamp_data->camera), do_prefix ? "Camera %s":"%s", camera ? camera->id.name+2 : "<none>"); + BLI_snprintf(stamp_data->camera, sizeof(stamp_data->camera), do_prefix ? "Camera %s" : "%s", camera ? camera->id.name + 2 : "<none>"); } else { stamp_data->camera[0] = '\0'; @@ -1294,41 +1294,41 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (camera && camera->type == OB_CAMERA) { BLI_snprintf(text, sizeof(text), "%.2f", ((Camera *)camera->data)->lens); } - else BLI_strncpy(text, "<none>", sizeof(text)); + else BLI_strncpy(text, "<none>", sizeof(text)); - BLI_snprintf(stamp_data->cameralens, sizeof(stamp_data->cameralens), do_prefix ? "Lens %s":"%s", text); + BLI_snprintf(stamp_data->cameralens, sizeof(stamp_data->cameralens), do_prefix ? "Lens %s" : "%s", text); } else { stamp_data->cameralens[0] = '\0'; } if (scene->r.stamp & R_STAMP_SCENE) { - BLI_snprintf(stamp_data->scene, sizeof(stamp_data->scene), do_prefix ? "Scene %s":"%s", scene->id.name+2); + BLI_snprintf(stamp_data->scene, sizeof(stamp_data->scene), do_prefix ? "Scene %s" : "%s", scene->id.name + 2); } else { stamp_data->scene[0] = '\0'; } if (scene->r.stamp & R_STAMP_SEQSTRIP) { - Sequence *seq= seq_foreground_frame_get(scene, scene->r.cfra); + Sequence *seq = seq_foreground_frame_get(scene, scene->r.cfra); - if (seq) BLI_strncpy(text, seq->name+2, sizeof(text)); - else BLI_strncpy(text, "<none>", sizeof(text)); + if (seq) BLI_strncpy(text, seq->name + 2, sizeof(text)); + else BLI_strncpy(text, "<none>", sizeof(text)); - BLI_snprintf(stamp_data->strip, sizeof(stamp_data->strip), do_prefix ? "Strip %s":"%s", text); + BLI_snprintf(stamp_data->strip, sizeof(stamp_data->strip), do_prefix ? "Strip %s" : "%s", text); } else { stamp_data->strip[0] = '\0'; } { - Render *re= RE_GetRender(scene->id.name); - RenderStats *stats= re ? RE_GetStats(re):NULL; + Render *re = RE_GetRender(scene->id.name); + RenderStats *stats = re ? RE_GetStats(re) : NULL; if (stats && (scene->r.stamp & R_STAMP_RENDERTIME)) { BLI_timestr(stats->lastframetime, text); - BLI_snprintf(stamp_data->rendertime, sizeof(stamp_data->rendertime), do_prefix ? "RenderTime %s":"%s", text); + BLI_snprintf(stamp_data->rendertime, sizeof(stamp_data->rendertime), do_prefix ? "RenderTime %s" : "%s", text); } else { stamp_data->rendertime[0] = '\0'; @@ -1342,7 +1342,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec float w, h, pad; int x, y, y_ofs; float h_fixed; - const int mono= blf_mono_font_render; // XXX + const int mono = blf_mono_font_render; // XXX #define BUFF_MARGIN_X 2 #define BUFF_MARGIN_Y 1 @@ -1354,29 +1354,29 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* TODO, do_versions */ if (scene->r.stamp_font_id < 8) - scene->r.stamp_font_id= 12; + scene->r.stamp_font_id = 12; /* set before return */ BLF_size(mono, scene->r.stamp_font_id, 72); BLF_buffer(mono, rectf, rect, width, height, channels); BLF_buffer_col(mono, scene->r.fg_stamp[0], scene->r.fg_stamp[1], scene->r.fg_stamp[2], 1.0); - pad= BLF_width_max(mono); + pad = BLF_width_max(mono); /* use 'h_fixed' rather than 'h', aligns better */ - h_fixed= BLF_height_max(mono); + h_fixed = BLF_height_max(mono); y_ofs = -BLF_descender(mono); - x= 0; - y= height; + x = 0; + y = height; if (stamp_data.file[0]) { /* Top left corner */ - BLF_width_and_height(mono, stamp_data.file, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.file, &w, &h); h = h_fixed; y -= h; /* also a little of space to the background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); /* and draw the text. */ BLF_position(mono, x, y + y_ofs, 0.0); @@ -1388,11 +1388,11 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* Top left corner, below File */ if (stamp_data.note[0]) { - BLF_width_and_height(mono, stamp_data.note, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.note, &w, &h); h = h_fixed; y -= h; /* and space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.note); @@ -1403,11 +1403,11 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* Top left corner, below File (or Note) */ if (stamp_data.date[0]) { - BLF_width_and_height(mono, stamp_data.date, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.date, &w, &h); h = h_fixed; y -= h; /* and space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.date); @@ -1418,25 +1418,25 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* Top left corner, below File, Date or Note */ if (stamp_data.rendertime[0]) { - BLF_width_and_height(mono, stamp_data.rendertime, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.rendertime, &w, &h); h = h_fixed; y -= h; /* and space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.rendertime); } - x= 0; - y= 0; + x = 0; + y = 0; /* Bottom left corner, leaving space for timing */ if (stamp_data.marker[0]) { - BLF_width_and_height(mono, stamp_data.marker, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.marker, &w, &h); h = h_fixed; /* extra space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); @@ -1448,10 +1448,10 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* Left bottom corner */ if (stamp_data.time[0]) { - BLF_width_and_height(mono, stamp_data.time, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.time, &w, &h); h = h_fixed; /* extra space for background */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); @@ -1462,10 +1462,10 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } if (stamp_data.frame[0]) { - BLF_width_and_height(mono, stamp_data.frame, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.frame, &w, &h); h = h_fixed; /* extra space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); @@ -1476,10 +1476,10 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } if (stamp_data.camera[0]) { - BLF_width_and_height(mono, stamp_data.camera, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.camera, &w, &h); h = h_fixed; /* extra space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.camera); @@ -1488,37 +1488,37 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } if (stamp_data.cameralens[0]) { - BLF_width_and_height(mono, stamp_data.cameralens, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.cameralens, &w, &h); h = h_fixed; /* extra space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.cameralens); } if (stamp_data.scene[0]) { - BLF_width_and_height(mono, stamp_data.scene, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.scene, &w, &h); h = h_fixed; /* Bottom right corner, with an extra space because blenfont is too strict! */ - x= width - w - 2; + x = width - w - 2; /* extra space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); /* and pad the text. */ - BLF_position(mono, x, y+y_ofs, 0.0); + BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.scene); } if (stamp_data.strip[0]) { - BLF_width_and_height(mono, stamp_data.strip, &w, &h); h= h_fixed; + BLF_width_and_height(mono, stamp_data.strip, &w, &h); h = h_fixed; /* Top right corner, with an extra space because blenfont is too strict! */ - x= width - w - pad; - y= height - h; + x = width - w - pad; + y = height - h; /* extra space for background. */ - buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x-BUFF_MARGIN_X, y-BUFF_MARGIN_Y, x+w+BUFF_MARGIN_X, y+h+BUFF_MARGIN_Y); + buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); BLF_draw_buffer(mono, stamp_data.strip); @@ -1535,38 +1535,38 @@ void BKE_imbuf_stamp_info(Scene *scene, Object *camera, struct ImBuf *ibuf) { struct StampData stamp_data; - if (!ibuf) return; + if (!ibuf) return; /* fill all the data values, no prefix */ stampdata(scene, camera, &stamp_data, 0); - if (stamp_data.file[0]) IMB_metadata_change_field (ibuf, "File", stamp_data.file); - if (stamp_data.note[0]) IMB_metadata_change_field (ibuf, "Note", stamp_data.note); - if (stamp_data.date[0]) IMB_metadata_change_field (ibuf, "Date", stamp_data.date); - if (stamp_data.marker[0]) IMB_metadata_change_field (ibuf, "Marker", stamp_data.marker); - if (stamp_data.time[0]) IMB_metadata_change_field (ibuf, "Time", stamp_data.time); - if (stamp_data.frame[0]) IMB_metadata_change_field (ibuf, "Frame", stamp_data.frame); - if (stamp_data.camera[0]) IMB_metadata_change_field (ibuf, "Camera", stamp_data.camera); - if (stamp_data.cameralens[0]) IMB_metadata_change_field (ibuf, "Lens", stamp_data.cameralens); - if (stamp_data.scene[0]) IMB_metadata_change_field (ibuf, "Scene", stamp_data.scene); - if (stamp_data.strip[0]) IMB_metadata_change_field (ibuf, "Strip", stamp_data.strip); - if (stamp_data.rendertime[0]) IMB_metadata_change_field (ibuf, "RenderTime", stamp_data.rendertime); + if (stamp_data.file[0]) IMB_metadata_change_field(ibuf, "File", stamp_data.file); + if (stamp_data.note[0]) IMB_metadata_change_field(ibuf, "Note", stamp_data.note); + if (stamp_data.date[0]) IMB_metadata_change_field(ibuf, "Date", stamp_data.date); + if (stamp_data.marker[0]) IMB_metadata_change_field(ibuf, "Marker", stamp_data.marker); + if (stamp_data.time[0]) IMB_metadata_change_field(ibuf, "Time", stamp_data.time); + if (stamp_data.frame[0]) IMB_metadata_change_field(ibuf, "Frame", stamp_data.frame); + if (stamp_data.camera[0]) IMB_metadata_change_field(ibuf, "Camera", stamp_data.camera); + if (stamp_data.cameralens[0]) IMB_metadata_change_field(ibuf, "Lens", stamp_data.cameralens); + if (stamp_data.scene[0]) IMB_metadata_change_field(ibuf, "Scene", stamp_data.scene); + if (stamp_data.strip[0]) IMB_metadata_change_field(ibuf, "Strip", stamp_data.strip); + if (stamp_data.rendertime[0]) IMB_metadata_change_field(ibuf, "RenderTime", stamp_data.rendertime); } int BKE_imbuf_alpha_test(ImBuf *ibuf) { int tot; if (ibuf->rect_float) { - float *buf= ibuf->rect_float; - for (tot= ibuf->x * ibuf->y; tot--; buf+=4) { + float *buf = ibuf->rect_float; + for (tot = ibuf->x * ibuf->y; tot--; buf += 4) { if (buf[3] < 1.0f) { return TRUE; } } } else if (ibuf->rect) { - unsigned char *buf= (unsigned char *)ibuf->rect; - for (tot= ibuf->x * ibuf->y; tot--; buf+=4) { + unsigned char *buf = (unsigned char *)ibuf->rect; + for (tot = ibuf->x * ibuf->y; tot--; buf += 4) { if (buf[3] != 255) { return TRUE; } @@ -1580,73 +1580,73 @@ int BKE_imbuf_alpha_test(ImBuf *ibuf) * are already set */ int BKE_imbuf_write(ImBuf *ibuf, const char *name, ImageFormatData *imf) { - char imtype= imf->imtype; - char compress= imf->compress; - char quality= imf->quality; + char imtype = imf->imtype; + char compress = imf->compress; + char quality = imf->quality; int ok; - if (imtype== R_IMF_IMTYPE_IRIS) { - ibuf->ftype= IMAGIC; + if (imtype == R_IMF_IMTYPE_IRIS) { + ibuf->ftype = IMAGIC; } #ifdef WITH_HDR - else if (imtype==R_IMF_IMTYPE_RADHDR) { - ibuf->ftype= RADHDR; + else if (imtype == R_IMF_IMTYPE_RADHDR) { + ibuf->ftype = RADHDR; } #endif else if (ELEM5(imtype, R_IMF_IMTYPE_PNG, R_IMF_IMTYPE_FFMPEG, R_IMF_IMTYPE_H264, R_IMF_IMTYPE_THEORA, R_IMF_IMTYPE_XVID)) { - ibuf->ftype= PNG; + ibuf->ftype = PNG; - if (imtype==R_IMF_IMTYPE_PNG) + if (imtype == R_IMF_IMTYPE_PNG) ibuf->ftype |= compress; } #ifdef WITH_DDS - else if (imtype==R_IMF_IMTYPE_DDS) { - ibuf->ftype= DDS; + else if (imtype == R_IMF_IMTYPE_DDS) { + ibuf->ftype = DDS; } #endif - else if (imtype==R_IMF_IMTYPE_BMP) { - ibuf->ftype= BMP; + else if (imtype == R_IMF_IMTYPE_BMP) { + ibuf->ftype = BMP; } #ifdef WITH_TIFF - else if (imtype==R_IMF_IMTYPE_TIFF) { - ibuf->ftype= TIF; + else if (imtype == R_IMF_IMTYPE_TIFF) { + ibuf->ftype = TIF; if (imf->depth == R_IMF_CHAN_DEPTH_16) ibuf->ftype |= TIF_16BIT; } #endif #ifdef WITH_OPENEXR - else if (imtype==R_IMF_IMTYPE_OPENEXR || imtype==R_IMF_IMTYPE_MULTILAYER) { - ibuf->ftype= OPENEXR; + else if (imtype == R_IMF_IMTYPE_OPENEXR || imtype == R_IMF_IMTYPE_MULTILAYER) { + ibuf->ftype = OPENEXR; if (imf->depth == R_IMF_CHAN_DEPTH_16) ibuf->ftype |= OPENEXR_HALF; ibuf->ftype |= (imf->exr_codec & OPENEXR_COMPRESS); if (!(imf->flag & R_IMF_FLAG_ZBUF)) - ibuf->zbuf_float = NULL; /* signal for exr saving */ + ibuf->zbuf_float = NULL; /* signal for exr saving */ } #endif #ifdef WITH_CINEON - else if (imtype==R_IMF_IMTYPE_CINEON) { + else if (imtype == R_IMF_IMTYPE_CINEON) { ibuf->ftype = CINEON; } - else if (imtype==R_IMF_IMTYPE_DPX) { + else if (imtype == R_IMF_IMTYPE_DPX) { ibuf->ftype = DPX; } #endif - else if (imtype==R_IMF_IMTYPE_TARGA) { - ibuf->ftype= TGA; + else if (imtype == R_IMF_IMTYPE_TARGA) { + ibuf->ftype = TGA; } - else if (imtype==R_IMF_IMTYPE_RAWTGA) { - ibuf->ftype= RAWTGA; + else if (imtype == R_IMF_IMTYPE_RAWTGA) { + ibuf->ftype = RAWTGA; } #ifdef WITH_OPENJPEG - else if (imtype==R_IMF_IMTYPE_JP2) { - if (quality < 10) quality= 90; - ibuf->ftype= JP2|quality; + else if (imtype == R_IMF_IMTYPE_JP2) { + if (quality < 10) quality = 90; + ibuf->ftype = JP2 | quality; if (imf->depth == R_IMF_CHAN_DEPTH_16) { ibuf->ftype |= JP2_16BIT; @@ -1668,8 +1668,8 @@ int BKE_imbuf_write(ImBuf *ibuf, const char *name, ImageFormatData *imf) #endif else { /* R_IMF_IMTYPE_JPEG90, etc. default we save jpegs */ - if (quality < 10) quality= 90; - ibuf->ftype= JPG|quality; + if (quality < 10) quality = 90; + ibuf->ftype = JPG | quality; } BLI_make_existing_file(name); @@ -1685,21 +1685,21 @@ int BKE_imbuf_write(ImBuf *ibuf, const char *name, ImageFormatData *imf) /* same as BKE_imbuf_write() but crappy workaround not to perminantly modify * _some_, values in the imbuf */ int BKE_imbuf_write_as(ImBuf *ibuf, const char *name, ImageFormatData *imf, - const short save_copy) + const short save_copy) { - ImBuf ibuf_back= *ibuf; + ImBuf ibuf_back = *ibuf; int ok; /* all data is rgba anyway, * this just controls how to save for some formats */ - ibuf->planes= imf->planes; + ibuf->planes = imf->planes; - ok= BKE_imbuf_write(ibuf, name, imf); + ok = BKE_imbuf_write(ibuf, name, imf); if (save_copy) { /* note that we are not restoring _all_ settings */ - ibuf->planes= ibuf_back.planes; - ibuf->ftype= ibuf_back.ftype; + ibuf->planes = ibuf_back.planes; + ibuf->ftype = ibuf_back.ftype; } return ok; @@ -1716,8 +1716,8 @@ int BKE_imbuf_write_stamp(Scene *scene, struct Object *camera, ImBuf *ibuf, cons void BKE_makepicstring(char *string, const char *base, const char *relbase, int frame, const char imtype, const short use_ext, const short use_frames) { - if (string==NULL) return; - BLI_strncpy(string, base, FILE_MAX - 10); /* weak assumption */ + if (string == NULL) return; + BLI_strncpy(string, base, FILE_MAX - 10); /* weak assumption */ BLI_path_abs(string, relbase); if (use_frames) @@ -1729,8 +1729,7 @@ void BKE_makepicstring(char *string, const char *base, const char *relbase, int } /* used by sequencer too */ -struct anim *openanim(const char *name, int flags, int streamindex) -{ +struct anim *openanim(const char *name, int flags, int streamindex){ struct anim *anim; struct ImBuf *ibuf; @@ -1778,16 +1777,16 @@ Image *BKE_image_verify_viewer(int type, const char *name) { Image *ima; - for (ima=G.main->image.first; ima; ima= ima->id.next) - if (ima->source==IMA_SRC_VIEWER) - if (ima->type==type) + for (ima = G.main->image.first; ima; ima = ima->id.next) + if (ima->source == IMA_SRC_VIEWER) + if (ima->type == type) break; - if (ima==NULL) - ima= image_alloc(name, IMA_SRC_VIEWER, type); + if (ima == NULL) + ima = image_alloc(name, IMA_SRC_VIEWER, type); /* happens on reload, imagewindow cannot be image user when hidden*/ - if (ima->id.us==0) + if (ima->id.us == 0) id_us_plus(&ima->id); return ima; @@ -1800,78 +1799,78 @@ void BKE_image_assign_ibuf(Image *ima, ImBuf *ibuf) void BKE_image_signal(Image *ima, ImageUser *iuser, int signal) { - if (ima==NULL) + if (ima == NULL) return; switch (signal) { - case IMA_SIGNAL_FREE: - image_free_buffers(ima); - if (iuser) - iuser->ok= 1; - break; - case IMA_SIGNAL_SRC_CHANGE: - if (ima->type == IMA_TYPE_UV_TEST) - if (ima->source != IMA_SRC_GENERATED) - ima->type= IMA_TYPE_IMAGE; - - if (ima->source==IMA_SRC_GENERATED) { - if (ima->gen_x==0 || ima->gen_y==0) { - ImBuf *ibuf= image_get_ibuf(ima, IMA_NO_INDEX, 0); - if (ibuf) { - ima->gen_x= ibuf->x; - ima->gen_y= ibuf->y; + case IMA_SIGNAL_FREE: + image_free_buffers(ima); + if (iuser) + iuser->ok = 1; + break; + case IMA_SIGNAL_SRC_CHANGE: + if (ima->type == IMA_TYPE_UV_TEST) + if (ima->source != IMA_SRC_GENERATED) + ima->type = IMA_TYPE_IMAGE; + + if (ima->source == IMA_SRC_GENERATED) { + if (ima->gen_x == 0 || ima->gen_y == 0) { + ImBuf *ibuf = image_get_ibuf(ima, IMA_NO_INDEX, 0); + if (ibuf) { + ima->gen_x = ibuf->x; + ima->gen_y = ibuf->y; + } } } - } - - /* force reload on first use, but not for multilayer, that makes nodes and buttons in ui drawing fail */ - if (ima->type!=IMA_TYPE_MULTILAYER) - image_free_buffers(ima); - ima->ok= 1; - if (iuser) - iuser->ok= 1; - break; - - case IMA_SIGNAL_RELOAD: - /* try to repack file */ - if (ima->packedfile) { - PackedFile *pf; - pf = newPackedFile(NULL, ima->name, ID_BLEND_PATH(G.main, &ima->id)); - if (pf) { - freePackedFile(ima->packedfile); - ima->packedfile = pf; + /* force reload on first use, but not for multilayer, that makes nodes and buttons in ui drawing fail */ + if (ima->type != IMA_TYPE_MULTILAYER) image_free_buffers(ima); + + ima->ok = 1; + if (iuser) + iuser->ok = 1; + break; + + case IMA_SIGNAL_RELOAD: + /* try to repack file */ + if (ima->packedfile) { + PackedFile *pf; + pf = newPackedFile(NULL, ima->name, ID_BLEND_PATH(G.main, &ima->id)); + if (pf) { + freePackedFile(ima->packedfile); + ima->packedfile = pf; + image_free_buffers(ima); + } + else { + printf("ERROR: Image not available. Keeping packed image\n"); + } } - else { - printf("ERROR: Image not available. Keeping packed image\n"); - } - } - else - image_free_buffers(ima); + else + image_free_buffers(ima); - if (iuser) - iuser->ok= 1; + if (iuser) + iuser->ok = 1; - break; - case IMA_SIGNAL_USER_NEW_IMAGE: - if (iuser) { - iuser->ok= 1; - if (ima->source==IMA_SRC_FILE || ima->source==IMA_SRC_SEQUENCE) { - if (ima->type==IMA_TYPE_MULTILAYER) { - iuser->multi_index= 0; - iuser->layer= iuser->pass= 0; + break; + case IMA_SIGNAL_USER_NEW_IMAGE: + if (iuser) { + iuser->ok = 1; + if (ima->source == IMA_SRC_FILE || ima->source == IMA_SRC_SEQUENCE) { + if (ima->type == IMA_TYPE_MULTILAYER) { + iuser->multi_index = 0; + iuser->layer = iuser->pass = 0; + } } } - } - break; + break; } /* don't use notifiers because they are not 100% sure to succeeded * this also makes sure all scenes are accounted for. */ { Scene *scene; - for (scene= G.main->scene.first; scene; scene= scene->id.next) { + for (scene = G.main->scene.first; scene; scene = scene->id.next) { if (scene->nodetree) { nodeUpdateID(scene->nodetree, &ima->id); } @@ -1885,32 +1884,32 @@ void BKE_image_signal(Image *ima, ImageUser *iuser, int signal) RenderPass *BKE_image_multilayer_index(RenderResult *rr, ImageUser *iuser) { RenderLayer *rl; - RenderPass *rpass= NULL; + RenderPass *rpass = NULL; - if (rr==NULL) + if (rr == NULL) return NULL; if (iuser) { - short index= 0, rl_index= 0, rp_index; + short index = 0, rl_index = 0, rp_index; - for (rl= rr->layers.first; rl; rl= rl->next, rl_index++) { - rp_index= 0; - for (rpass= rl->passes.first; rpass; rpass= rpass->next, index++, rp_index++) - if (iuser->layer==rl_index && iuser->pass==rp_index) + for (rl = rr->layers.first; rl; rl = rl->next, rl_index++) { + rp_index = 0; + for (rpass = rl->passes.first; rpass; rpass = rpass->next, index++, rp_index++) + if (iuser->layer == rl_index && iuser->pass == rp_index) break; if (rpass) break; } if (rpass) - iuser->multi_index= index; + iuser->multi_index = index; else - iuser->multi_index= 0; + iuser->multi_index = 0; } - if (rpass==NULL) { - rl= rr->layers.first; + if (rpass == NULL) { + rl = rr->layers.first; if (rl) - rpass= rl->passes.first; + rpass = rl->passes.first; } return rpass; @@ -1921,7 +1920,7 @@ RenderResult *BKE_image_acquire_renderresult(Scene *scene, Image *ima) if (ima->rr) { return ima->rr; } - else if (ima->type==IMA_TYPE_R_RESULT) { + else if (ima->type == IMA_TYPE_R_RESULT) { if (ima->render_slot == ima->last_render_slot) return RE_AcquireResultRead(RE_GetRender(scene->id.name)); else @@ -1933,8 +1932,8 @@ RenderResult *BKE_image_acquire_renderresult(Scene *scene, Image *ima) void BKE_image_release_renderresult(Scene *scene, Image *ima) { - if (ima->rr); - else if (ima->type==IMA_TYPE_R_RESULT) { + if (ima->rr) ; + else if (ima->type == IMA_TYPE_R_RESULT) { if (ima->render_slot == ima->last_render_slot) RE_ReleaseResult(RE_GetRender(scene->id.name)); } @@ -1944,20 +1943,20 @@ void BKE_image_backup_render(Scene *scene, Image *ima) { /* called right before rendering, ima->renders contains render * result pointers for everything but the current render */ - Render *re= RE_GetRender(scene->id.name); - int slot= ima->render_slot, last= ima->last_render_slot; + Render *re = RE_GetRender(scene->id.name); + int slot = ima->render_slot, last = ima->last_render_slot; if (slot != last) { if (ima->renders[slot]) { RE_FreeRenderResult(ima->renders[slot]); - ima->renders[slot]= NULL; + ima->renders[slot] = NULL; } - ima->renders[last]= NULL; + ima->renders[last] = NULL; RE_SwapResult(re, &ima->renders[last]); } - ima->last_render_slot= slot; + ima->last_render_slot = slot; } /* after imbuf load, openexr type can return with a exrhandle open */ @@ -1965,22 +1964,22 @@ void BKE_image_backup_render(Scene *scene, Image *ima) static void image_create_multilayer(Image *ima, ImBuf *ibuf, int framenr) { - ima->rr= RE_MultilayerConvert(ibuf->userdata, ibuf->x, ibuf->y); + ima->rr = RE_MultilayerConvert(ibuf->userdata, ibuf->x, ibuf->y); #ifdef WITH_OPENEXR IMB_exr_close(ibuf->userdata); #endif - ibuf->userdata= NULL; + ibuf->userdata = NULL; if (ima->rr) - ima->rr->framenr= framenr; + ima->rr->framenr = framenr; } /* common stuff to do with images after loading */ static void image_initialize_after_load(Image *ima, ImBuf *ibuf) { /* preview is NULL when it has never been used as an icon before */ - if (G.background==0 && ima->preview==NULL) + if (G.background == 0 && ima->preview == NULL) BKE_icon_changed(BKE_icon_getid(&ima->id)); /* fields */ @@ -1991,7 +1990,7 @@ static void image_initialize_after_load(Image *ima, ImBuf *ibuf) /* timer */ ima->lastused = clock() / CLOCKS_PER_SEC; - ima->ok= IMA_OK_LOADED; + ima->ok = IMA_OK_LOADED; } @@ -2006,14 +2005,14 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame) if (ima->lastframe != frame) ima->tpageflag |= IMA_TPAGE_REFRESH; - ima->lastframe= frame; + ima->lastframe = frame; BLI_strncpy(name, ima->name, sizeof(name)); BLI_stringdec(name, head, tail, &numlen); BLI_stringenc(name, head, tail, numlen, frame); BLI_path_abs(name, ID_BLEND_PATH(G.main, &ima->id)); - flag= IB_rect|IB_multilayer; + flag = IB_rect | IB_multilayer; if (ima->flag & IMA_DO_PREMUL) flag |= IB_premul; @@ -2022,21 +2021,21 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame) #if 0 if (ibuf) { - printf(AT" loaded %s\n", name); + printf(AT " loaded %s\n", name); } else { - printf(AT" missed %s\n", name); + printf(AT " missed %s\n", name); } #endif if (ibuf) { #ifdef WITH_OPENEXR /* handle multilayer case, don't assign ibuf. will be handled in BKE_image_get_ibuf */ - if (ibuf->ftype==OPENEXR && ibuf->userdata) { + if (ibuf->ftype == OPENEXR && ibuf->userdata) { image_create_multilayer(ima, ibuf, frame); - ima->type= IMA_TYPE_MULTILAYER; + ima->type = IMA_TYPE_MULTILAYER; IMB_freeImBuf(ibuf); - ibuf= NULL; + ibuf = NULL; } else { image_initialize_after_load(ima, ibuf); @@ -2048,30 +2047,30 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame) #endif } else - ima->ok= 0; + ima->ok = 0; if (iuser) - iuser->ok= ima->ok; + iuser->ok = ima->ok; return ibuf; } static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int frame) { - struct ImBuf *ibuf= NULL; + struct ImBuf *ibuf = NULL; /* either we load from RenderResult, or we have to load a new one */ /* check for new RenderResult */ - if (ima->rr==NULL || frame!=ima->rr->framenr) { + if (ima->rr == NULL || frame != ima->rr->framenr) { /* copy to survive not found multilayer image */ - RenderResult *oldrr= ima->rr; + RenderResult *oldrr = ima->rr; - ima->rr= NULL; + ima->rr = NULL; ibuf = image_load_sequence_file(ima, iuser, frame); if (ibuf) { /* actually an error */ - ima->type= IMA_TYPE_IMAGE; + ima->type = IMA_TYPE_IMAGE; printf("error, multi is normal image\n"); } // printf("loaded new result %p\n", ima->rr); @@ -2081,34 +2080,34 @@ static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int f if (oldrr) RE_FreeRenderResult(oldrr); } else { - ima->rr= oldrr; + ima->rr = oldrr; } } if (ima->rr) { - RenderPass *rpass= BKE_image_multilayer_index(ima->rr, iuser); + RenderPass *rpass = BKE_image_multilayer_index(ima->rr, iuser); if (rpass) { // printf("load from pass %s\n", rpass->name); /* since we free render results, we copy the rect */ - ibuf= IMB_allocImBuf(ima->rr->rectx, ima->rr->recty, 32, 0); - ibuf->rect_float= MEM_dupallocN(rpass->rect); + ibuf = IMB_allocImBuf(ima->rr->rectx, ima->rr->recty, 32, 0); + ibuf->rect_float = MEM_dupallocN(rpass->rect); ibuf->flags |= IB_rectfloat; - ibuf->mall= IB_rectfloat; - ibuf->channels= rpass->channels; + ibuf->mall = IB_rectfloat; + ibuf->channels = rpass->channels; ibuf->profile = IB_PROFILE_LINEAR_RGB; image_initialize_after_load(ima, ibuf); - image_assign_ibuf(ima, ibuf, iuser?iuser->multi_index:0, frame); + image_assign_ibuf(ima, ibuf, iuser ? iuser->multi_index : 0, frame); } // else printf("pass not found\n"); } else - ima->ok= 0; + ima->ok = 0; if (iuser) - iuser->ok= ima->ok; + iuser->ok = ima->ok; return ibuf; } @@ -2116,11 +2115,11 @@ static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int f static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) { - struct ImBuf *ibuf= NULL; + struct ImBuf *ibuf = NULL; - ima->lastframe= frame; + ima->lastframe = frame; - if (ima->anim==NULL) { + if (ima->anim == NULL) { char str[FILE_MAX]; BLI_strncpy(str, ima->name, FILE_MAX); @@ -2130,35 +2129,35 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) ima->anim = openanim(str, IB_rect, 0); /* let's initialize this user */ - if (ima->anim && iuser && iuser->frames==0) - iuser->frames= IMB_anim_get_duration(ima->anim, - IMB_TC_RECORD_RUN); + if (ima->anim && iuser && iuser->frames == 0) + iuser->frames = IMB_anim_get_duration(ima->anim, + IMB_TC_RECORD_RUN); } if (ima->anim) { int dur = IMB_anim_get_duration(ima->anim, - IMB_TC_RECORD_RUN); - int fra= frame-1; + IMB_TC_RECORD_RUN); + int fra = frame - 1; - if (fra<0) fra = 0; - if (fra>(dur-1)) fra= dur-1; + if (fra < 0) fra = 0; + if (fra > (dur - 1)) fra = dur - 1; ibuf = IMB_makeSingleUser( - IMB_anim_absolute(ima->anim, fra, - IMB_TC_RECORD_RUN, - IMB_PROXY_NONE)); + IMB_anim_absolute(ima->anim, fra, + IMB_TC_RECORD_RUN, + IMB_PROXY_NONE)); if (ibuf) { image_initialize_after_load(ima, ibuf); image_assign_ibuf(ima, ibuf, 0, frame); } else - ima->ok= 0; + ima->ok = 0; } else - ima->ok= 0; + ima->ok = 0; if (iuser) - iuser->ok= ima->ok; + iuser->ok = ima->ok; return ibuf; } @@ -2175,13 +2174,13 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) /* is there a PackedFile with this image ? */ if (ima->packedfile) { - flag = IB_rect|IB_multilayer; + 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, "<packed data>"); + ibuf = IMB_ibImageFromMemory((unsigned char *)ima->packedfile->data, ima->packedfile->size, flag, "<packed data>"); } else { - flag= IB_rect|IB_multilayer|IB_metadata; + flag = IB_rect | IB_multilayer | IB_metadata; if (ima->flag & IMA_DO_PREMUL) flag |= IB_premul; @@ -2195,15 +2194,15 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) if (ibuf) { /* handle multilayer case, don't assign ibuf. will be handled in BKE_image_get_ibuf */ - if (ibuf->ftype==OPENEXR && ibuf->userdata) { + if (ibuf->ftype == OPENEXR && ibuf->userdata) { image_create_multilayer(ima, ibuf, cfra); - ima->type= IMA_TYPE_MULTILAYER; + ima->type = IMA_TYPE_MULTILAYER; IMB_freeImBuf(ibuf); - ibuf= NULL; + ibuf = NULL; } else { image_initialize_after_load(ima, ibuf); - assign= 1; + assign = 1; /* check if the image is a font image... */ detectBitmapFont(ibuf); @@ -2214,49 +2213,49 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) } } else - ima->ok= 0; + ima->ok = 0; if (assign) image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); if (iuser) - iuser->ok= ima->ok; + iuser->ok = ima->ok; return ibuf; } static ImBuf *image_get_ibuf_multilayer(Image *ima, ImageUser *iuser) { - ImBuf *ibuf= NULL; + ImBuf *ibuf = NULL; - if (ima->rr==NULL) { + if (ima->rr == NULL) { ibuf = image_load_image_file(ima, iuser, 0); if (ibuf) { /* actually an error */ - ima->type= IMA_TYPE_IMAGE; + ima->type = IMA_TYPE_IMAGE; return ibuf; } } if (ima->rr) { - RenderPass *rpass= BKE_image_multilayer_index(ima->rr, iuser); + RenderPass *rpass = BKE_image_multilayer_index(ima->rr, iuser); if (rpass) { - ibuf= IMB_allocImBuf(ima->rr->rectx, ima->rr->recty, 32, 0); + ibuf = IMB_allocImBuf(ima->rr->rectx, ima->rr->recty, 32, 0); image_initialize_after_load(ima, ibuf); - ibuf->rect_float= rpass->rect; + ibuf->rect_float = rpass->rect; ibuf->flags |= IB_rectfloat; - ibuf->channels= rpass->channels; + ibuf->channels = rpass->channels; ibuf->profile = IB_PROFILE_LINEAR_RGB; - image_assign_ibuf(ima, ibuf, iuser?iuser->multi_index:IMA_NO_INDEX, 0); + image_assign_ibuf(ima, ibuf, iuser ? iuser->multi_index : IMA_NO_INDEX, 0); } } - if (ibuf==NULL) - ima->ok= 0; + if (ibuf == NULL) + ima->ok = 0; if (iuser) - iuser->ok= ima->ok; + iuser->ok = ima->ok; return ibuf; } @@ -2274,7 +2273,7 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_ float dither; int channels, layer, pass; ImBuf *ibuf; - int from_render= (ima->render_slot == ima->last_render_slot); + int from_render = (ima->render_slot == ima->last_render_slot); if (!(iuser && iuser->scene)) return NULL; @@ -2283,18 +2282,18 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_ if (!lock_r) return NULL; - re= RE_GetRender(iuser->scene->id.name); + re = RE_GetRender(iuser->scene->id.name); - channels= 4; - layer= (iuser)? iuser->layer: 0; - pass= (iuser)? iuser->pass: 0; + channels = 4; + layer = (iuser) ? iuser->layer : 0; + pass = (iuser) ? iuser->pass : 0; if (from_render) { RE_AcquireResultImage(re, &rres); } else if (ima->renders[ima->render_slot]) { - rres= *(ima->renders[ima->render_slot]); - rres.have_combined= rres.rectf != NULL; + rres = *(ima->renders[ima->render_slot]); + rres.have_combined = rres.rectf != NULL; } else memset(&rres, 0, sizeof(RenderResult)); @@ -2308,83 +2307,83 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_ /* release is done in BKE_image_release_ibuf using lock_r */ if (from_render) { BLI_lock_thread(LOCK_VIEWER); - *lock_r= re; + *lock_r = re; } /* this gives active layer, composite or seqence result */ - rect= (unsigned int *)rres.rect32; - rectf= rres.rectf; - rectz= rres.rectz; - dither= iuser->scene->r.dither_intensity; + rect = (unsigned int *)rres.rect32; + rectf = rres.rectf; + rectz = rres.rectz; + dither = iuser->scene->r.dither_intensity; /* combined layer gets added as first layer */ - if (rres.have_combined && layer==0); + if (rres.have_combined && layer == 0) ; else if (rres.layers.first) { - RenderLayer *rl= BLI_findlink(&rres.layers, layer-(rres.have_combined?1:0)); + RenderLayer *rl = BLI_findlink(&rres.layers, layer - (rres.have_combined ? 1 : 0)); if (rl) { RenderPass *rpass; /* there's no combined pass, is in renderlayer itself */ - if (pass==0) { - rectf= rl->rectf; + if (pass == 0) { + rectf = rl->rectf; } else { - rpass= BLI_findlink(&rl->passes, pass-1); + rpass = BLI_findlink(&rl->passes, pass - 1); if (rpass) { - channels= rpass->channels; - rectf= rpass->rect; - dither= 0.0f; /* don't dither passes */ + channels = rpass->channels; + rectf = rpass->rect; + dither = 0.0f; /* don't dither passes */ } } - for (rpass= rl->passes.first; rpass; rpass= rpass->next) + for (rpass = rl->passes.first; rpass; rpass = rpass->next) if (rpass->passtype == SCE_PASS_Z) - rectz= rpass->rect; + rectz = rpass->rect; } } - ibuf= image_get_ibuf(ima, IMA_NO_INDEX, 0); + ibuf = image_get_ibuf(ima, IMA_NO_INDEX, 0); /* make ibuf if needed, and initialize it */ - if (ibuf==NULL) { - ibuf= IMB_allocImBuf(rres.rectx, rres.recty, 32, 0); + if (ibuf == NULL) { + ibuf = IMB_allocImBuf(rres.rectx, rres.recty, 32, 0); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); } - ibuf->x= rres.rectx; - ibuf->y= rres.recty; + ibuf->x = rres.rectx; + ibuf->y = rres.recty; /* free rect buffer if float buffer changes, so it can be recreated with * the updated result, and also in case we got byte buffer from sequencer, * so we don't keep reference to freed buffer */ - if (ibuf->rect_float!=rectf || rect || !rectf) + if (ibuf->rect_float != rectf || rect || !rectf) imb_freerectImBuf(ibuf); if (rect) - ibuf->rect= rect; + ibuf->rect = rect; if (rectf) { - ibuf->rect_float= rectf; + ibuf->rect_float = rectf; ibuf->flags |= IB_rectfloat; - ibuf->channels= channels; + ibuf->channels = channels; } else { - ibuf->rect_float= NULL; + ibuf->rect_float = NULL; ibuf->flags &= ~IB_rectfloat; } if (rectz) { - ibuf->zbuf_float= rectz; + ibuf->zbuf_float = rectz; ibuf->flags |= IB_zbuffloat; } else { - ibuf->zbuf_float= NULL; + ibuf->zbuf_float = NULL; ibuf->flags &= ~IB_zbuffloat; } /* since its possible to access the buffer from the image directly, set the profile [#25073] */ - ibuf->profile= (iuser->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_NONE; - ibuf->dither= dither; + ibuf->profile = (iuser->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_NONE; + ibuf->dither = dither; if (iuser->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE) { ibuf->flags |= IB_cm_predivide; @@ -2395,7 +2394,7 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_ ima->flag &= ~IMA_CM_PREDIVIDE; } - ima->ok= IMA_OK_LOADED; + ima->ok = IMA_OK_LOADED; return ibuf; } @@ -2406,18 +2405,18 @@ static ImBuf *image_get_ibuf_threadsafe(Image *ima, ImageUser *iuser, int *frame int frame = 0, index = 0; /* see if we already have an appropriate ibuf, with image source and type */ - if (ima->source==IMA_SRC_MOVIE) { - frame= iuser?iuser->framenr:ima->lastframe; - ibuf= image_get_ibuf(ima, 0, frame); + if (ima->source == IMA_SRC_MOVIE) { + frame = iuser ? iuser->framenr : ima->lastframe; + ibuf = image_get_ibuf(ima, 0, frame); /* XXX temp stuff? */ if (ima->lastframe != frame) ima->tpageflag |= IMA_TPAGE_REFRESH; ima->lastframe = frame; } - else if (ima->source==IMA_SRC_SEQUENCE) { - if (ima->type==IMA_TYPE_IMAGE) { - frame= iuser?iuser->framenr:ima->lastframe; - ibuf= image_get_ibuf(ima, 0, frame); + else if (ima->source == IMA_SRC_SEQUENCE) { + if (ima->type == IMA_TYPE_IMAGE) { + frame = iuser ? iuser->framenr : ima->lastframe; + ibuf = image_get_ibuf(ima, 0, frame); /* XXX temp stuff? */ if (ima->lastframe != frame) { @@ -2425,20 +2424,20 @@ static ImBuf *image_get_ibuf_threadsafe(Image *ima, ImageUser *iuser, int *frame } ima->lastframe = frame; } - else if (ima->type==IMA_TYPE_MULTILAYER) { - frame= iuser?iuser->framenr:ima->lastframe; - index= iuser?iuser->multi_index:IMA_NO_INDEX; - ibuf= image_get_ibuf(ima, index, frame); + else if (ima->type == IMA_TYPE_MULTILAYER) { + frame = iuser ? iuser->framenr : ima->lastframe; + index = iuser ? iuser->multi_index : IMA_NO_INDEX; + ibuf = image_get_ibuf(ima, index, frame); } } - else if (ima->source==IMA_SRC_FILE) { - if (ima->type==IMA_TYPE_IMAGE) - ibuf= image_get_ibuf(ima, IMA_NO_INDEX, 0); - else if (ima->type==IMA_TYPE_MULTILAYER) - ibuf= image_get_ibuf(ima, iuser?iuser->multi_index:IMA_NO_INDEX, 0); + else if (ima->source == IMA_SRC_FILE) { + if (ima->type == IMA_TYPE_IMAGE) + ibuf = image_get_ibuf(ima, IMA_NO_INDEX, 0); + else if (ima->type == IMA_TYPE_MULTILAYER) + ibuf = image_get_ibuf(ima, iuser ? iuser->multi_index : IMA_NO_INDEX, 0); } else if (ima->source == IMA_SRC_GENERATED) { - ibuf= image_get_ibuf(ima, IMA_NO_INDEX, 0); + ibuf = image_get_ibuf(ima, IMA_NO_INDEX, 0); } else if (ima->source == IMA_SRC_VIEWER) { /* always verify entirely, not that this shouldn't happen @@ -2457,9 +2456,9 @@ static ImBuf *image_get_ibuf_threadsafe(Image *ima, ImageUser *iuser, int *frame * if not, use BKE_image_get_ibuf which doesn't require a release */ ImBuf *BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r) { - ImBuf *ibuf= NULL; + ImBuf *ibuf = NULL; float color[] = {0, 0, 0, 1}; - int frame= 0, index= 0; + int frame = 0, index = 0; /* This function is intended to be thread-safe. It postpones the mutex lock * until it needs to load the image, if the image is already there it @@ -2473,20 +2472,20 @@ ImBuf *BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r) * 2) set ima/iuser->ok to 0 to IMA_OK_LOADED */ if (lock_r) - *lock_r= NULL; + *lock_r = NULL; /* quick reject tests */ - if (ima==NULL) + if (ima == NULL) return NULL; if (iuser) { - if (iuser->ok==0) + if (iuser->ok == 0) return NULL; } - else if (ima->ok==0) + else if (ima->ok == 0) return NULL; /* try to get the ibuf without locking */ - ibuf= image_get_ibuf_threadsafe(ima, iuser, &frame, &index); + ibuf = image_get_ibuf_threadsafe(ima, iuser, &frame, &index); if (ibuf == NULL) { /* couldn't get ibuf and image is not ok, so let's lock and try to @@ -2496,75 +2495,75 @@ ImBuf *BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r) /* need to check ok flag and loading ibuf again, because the situation * might have changed in the meantime */ if (iuser) { - if (iuser->ok==0) { + if (iuser->ok == 0) { BLI_unlock_thread(LOCK_IMAGE); return NULL; } } - else if (ima->ok==0) { + else if (ima->ok == 0) { BLI_unlock_thread(LOCK_IMAGE); return NULL; } - ibuf= image_get_ibuf_threadsafe(ima, iuser, &frame, &index); + ibuf = image_get_ibuf_threadsafe(ima, iuser, &frame, &index); if (ibuf == NULL) { /* we are sure we have to load the ibuf, using source and type */ - if (ima->source==IMA_SRC_MOVIE) { + if (ima->source == IMA_SRC_MOVIE) { /* source is from single file, use flipbook to store ibuf */ - ibuf= image_load_movie_file(ima, iuser, frame); + ibuf = image_load_movie_file(ima, iuser, frame); } - else if (ima->source==IMA_SRC_SEQUENCE) { - if (ima->type==IMA_TYPE_IMAGE) { + else if (ima->source == IMA_SRC_SEQUENCE) { + if (ima->type == IMA_TYPE_IMAGE) { /* regular files, ibufs in flipbook, allows saving */ - ibuf= image_load_sequence_file(ima, iuser, frame); + ibuf = image_load_sequence_file(ima, iuser, frame); } /* no else; on load the ima type can change */ - if (ima->type==IMA_TYPE_MULTILAYER) { + if (ima->type == IMA_TYPE_MULTILAYER) { /* only 1 layer/pass stored in imbufs, no exrhandle anim storage, no saving */ - ibuf= image_load_sequence_multilayer(ima, iuser, frame); + ibuf = image_load_sequence_multilayer(ima, iuser, frame); } } - else if (ima->source==IMA_SRC_FILE) { + else if (ima->source == IMA_SRC_FILE) { - if (ima->type==IMA_TYPE_IMAGE) - ibuf= image_load_image_file(ima, iuser, frame); /* cfra only for '#', this global is OK */ + if (ima->type == IMA_TYPE_IMAGE) + ibuf = image_load_image_file(ima, iuser, frame); /* cfra only for '#', this global is OK */ /* no else; on load the ima type can change */ - if (ima->type==IMA_TYPE_MULTILAYER) + if (ima->type == IMA_TYPE_MULTILAYER) /* keeps render result, stores ibufs in listbase, allows saving */ - ibuf= image_get_ibuf_multilayer(ima, iuser); + ibuf = image_get_ibuf_multilayer(ima, iuser); } else if (ima->source == IMA_SRC_GENERATED) { /* generated is: ibuf is allocated dynamically */ /* UV testgrid or black or solid etc */ - if (ima->gen_x==0) ima->gen_x= 1024; - if (ima->gen_y==0) ima->gen_y= 1024; - ibuf= add_ibuf_size(ima->gen_x, ima->gen_y, ima->name, 24, (ima->gen_flag & IMA_GEN_FLOAT) != 0, ima->gen_type, color); + if (ima->gen_x == 0) ima->gen_x = 1024; + if (ima->gen_y == 0) ima->gen_y = 1024; + ibuf = add_ibuf_size(ima->gen_x, ima->gen_y, ima->name, 24, (ima->gen_flag & IMA_GEN_FLOAT) != 0, ima->gen_type, color); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); - ima->ok= IMA_OK_LOADED; + ima->ok = IMA_OK_LOADED; } else if (ima->source == IMA_SRC_VIEWER) { - if (ima->type==IMA_TYPE_R_RESULT) { + if (ima->type == IMA_TYPE_R_RESULT) { /* always verify entirely, and potentially * returns pointer to release later */ - ibuf= image_get_render_result(ima, iuser, lock_r); + ibuf = image_get_render_result(ima, iuser, lock_r); } - else if (ima->type==IMA_TYPE_COMPOSITE) { + else if (ima->type == IMA_TYPE_COMPOSITE) { /* requires lock/unlock, otherwise don't return image */ if (lock_r) { /* unlock in BKE_image_release_ibuf */ BLI_lock_thread(LOCK_VIEWER); - *lock_r= ima; + *lock_r = ima; /* XXX anim play for viewer nodes not yet supported */ - frame= 0; // XXX iuser?iuser->framenr:0; - ibuf= image_get_ibuf(ima, 0, frame); + frame = 0; // XXX iuser?iuser->framenr:0; + ibuf = image_get_ibuf(ima, 0, frame); if (!ibuf) { /* Composite Viewer, all handled in compositor */ /* fake ibuf, will be filled in compositor */ - ibuf= IMB_allocImBuf(256, 256, 32, IB_rect); + ibuf = IMB_allocImBuf(256, 256, 32, IB_rect); image_assign_ibuf(ima, ibuf, 0, frame); } } @@ -2601,38 +2600,38 @@ ImBuf *BKE_image_get_ibuf(Image *ima, ImageUser *iuser) int BKE_image_user_frame_get(const ImageUser *iuser, int cfra, int fieldnr) { - const int len= (iuser->fie_ima*iuser->frames)/2; + const int len = (iuser->fie_ima * iuser->frames) / 2; - if (len==0) { + if (len == 0) { return 0; } else { int framenr; - cfra= cfra - iuser->sfra+1; + cfra = cfra - iuser->sfra + 1; /* cyclic */ if (iuser->cycl) { - cfra= ((cfra) % len); - if (cfra < 0) cfra+= len; - if (cfra==0) cfra= len; + cfra = ((cfra) % len); + if (cfra < 0) cfra += len; + if (cfra == 0) cfra = len; } - if (cfra<0) cfra= 0; - else if (cfra>len) cfra= len; + if (cfra < 0) cfra = 0; + else if (cfra > len) cfra = len; /* convert current frame to current field */ - cfra= 2*(cfra); + cfra = 2 * (cfra); if (fieldnr) cfra++; /* transform to images space */ - framenr= (cfra+iuser->fie_ima-2)/iuser->fie_ima; - if (framenr>iuser->frames) framenr= iuser->frames; - framenr+= iuser->offset; + framenr = (cfra + iuser->fie_ima - 2) / iuser->fie_ima; + if (framenr > iuser->frames) framenr = iuser->frames; + framenr += iuser->offset; if (iuser->cycl) { - framenr= ((framenr) % len); - while (framenr < 0) framenr+= len; - if (framenr==0) framenr= len; + framenr = ((framenr) % len); + while (framenr < 0) framenr += len; + if (framenr == 0) framenr = len; } return framenr; @@ -2641,15 +2640,15 @@ int BKE_image_user_frame_get(const ImageUser *iuser, int cfra, int fieldnr) void BKE_image_user_frame_calc(ImageUser *iuser, int cfra, int fieldnr) { - const int framenr= BKE_image_user_frame_get(iuser, cfra, fieldnr); + const int framenr = BKE_image_user_frame_get(iuser, cfra, fieldnr); /* allows image users to handle redraws */ if (iuser->flag & IMA_ANIM_ALWAYS) - if (framenr!=iuser->framenr) + if (framenr != iuser->framenr) iuser->flag |= IMA_ANIM_REFRESHED; - iuser->framenr= framenr; - if (iuser->ok==0) iuser->ok= 1; + iuser->framenr = framenr; + if (iuser->ok == 0) iuser->ok = 1; } int BKE_image_has_alpha(struct Image *image) @@ -2658,8 +2657,8 @@ int BKE_image_has_alpha(struct Image *image) void *lock; int planes; - ibuf= BKE_image_acquire_ibuf(image, NULL, &lock); - planes = (ibuf?ibuf->planes:0); + ibuf = BKE_image_acquire_ibuf(image, NULL, &lock); + planes = (ibuf ? ibuf->planes : 0); BKE_image_release_ibuf(image, lock); if (planes == 32) diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index c2cb45d9f9d..1077b5ad7c3 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -84,10 +84,10 @@ void BKE_ipo_free(Ipo *ipo) { IpoCurve *icu, *icn; - int n= 0; + int n = 0; - for (icu= ipo->curve.first; icu; icu= icn) { - icn= icu->next; + for (icu = ipo->curve.first; icu; icu = icn) { + icn = icu->next; n++; if (icu->bezt) MEM_freeN(icu->bezt); @@ -98,7 +98,7 @@ void BKE_ipo_free(Ipo *ipo) } if (G.debug & G_DEBUG) - printf("Freed %d (Unconverted) Ipo-Curves from IPO '%s'\n", n, ipo->id.name+2); + printf("Freed %d (Unconverted) Ipo-Curves from IPO '%s'\n", n, ipo->id.name + 2); } /* *************************************************** */ @@ -115,35 +115,35 @@ typedef struct AdrBit2Path { /* Mapping Tables to use bits <-> RNA paths */ /* Object layers */ -static AdrBit2Path ob_layer_bits[]= { - {(1<<0), "layers", 0}, - {(1<<1), "layers", 1}, - {(1<<2), "layers", 2}, - {(1<<3), "layers", 3}, - {(1<<4), "layers", 4}, - {(1<<5), "layers", 5}, - {(1<<6), "layers", 6}, - {(1<<7), "layers", 7}, - {(1<<8), "layers", 8}, - {(1<<9), "layers", 9}, - {(1<<10), "layers", 10}, - {(1<<11), "layers", 11}, - {(1<<12), "layers", 12}, - {(1<<13), "layers", 13}, - {(1<<14), "layers", 14}, - {(1<<15), "layers", 15}, - {(1<<16), "layers", 16}, - {(1<<17), "layers", 17}, - {(1<<18), "layers", 18}, - {(1<<19), "layers", 19} +static AdrBit2Path ob_layer_bits[] = { + {(1 << 0), "layers", 0}, + {(1 << 1), "layers", 1}, + {(1 << 2), "layers", 2}, + {(1 << 3), "layers", 3}, + {(1 << 4), "layers", 4}, + {(1 << 5), "layers", 5}, + {(1 << 6), "layers", 6}, + {(1 << 7), "layers", 7}, + {(1 << 8), "layers", 8}, + {(1 << 9), "layers", 9}, + {(1 << 10), "layers", 10}, + {(1 << 11), "layers", 11}, + {(1 << 12), "layers", 12}, + {(1 << 13), "layers", 13}, + {(1 << 14), "layers", 14}, + {(1 << 15), "layers", 15}, + {(1 << 16), "layers", 16}, + {(1 << 17), "layers", 17}, + {(1 << 18), "layers", 18}, + {(1 << 19), "layers", 19} }; /* Material mode */ -static AdrBit2Path ma_mode_bits[]= { +static AdrBit2Path ma_mode_bits[] = { // {MA_TRACEBLE, "traceable", 0}, -// {MA_SHADOW, "shadow", 0}, +// {MA_SHADOW, "shadow", 0}, // {MA_SHLESS, "shadeless", 0}, -// ... +// ... {MA_RAYTRANSP, "transparency", 0}, {MA_RAYMIRROR, "raytrace_mirror.enabled", 0}, // {MA_HALO, "type", MA_TYPE_HALO} @@ -154,99 +154,99 @@ static AdrBit2Path ma_mode_bits[]= { /* quick macro for returning the appropriate array for adrcode_bitmaps_to_paths() */ #define RET_ABP(items) \ { \ - *tot= sizeof(items)/sizeof(AdrBit2Path); \ + *tot = sizeof(items) / sizeof(AdrBit2Path); \ return items; \ } /* This function checks if a Blocktype+Adrcode combo, returning a mapping table */ -static AdrBit2Path *adrcode_bitmaps_to_paths (int blocktype, int adrcode, int *tot) +static AdrBit2Path *adrcode_bitmaps_to_paths(int blocktype, int adrcode, int *tot) { /* Object layers */ if ((blocktype == ID_OB) && (adrcode == OB_LAY)) RET_ABP(ob_layer_bits) - else if ((blocktype == ID_MA) && (adrcode == MA_MODE)) - RET_ABP(ma_mode_bits) - // XXX TODO: add other types... + else if ((blocktype == ID_MA) && (adrcode == MA_MODE)) + RET_ABP(ma_mode_bits) + // XXX TODO: add other types... - /* Normal curve */ - return NULL; + /* Normal curve */ + return NULL; } /* *************************************************** */ /* ADRCODE to RNA-Path Conversion Code - Standard */ /* Object types */ -static const char *ob_adrcodes_to_paths (int adrcode, int *array_index) +static const char *ob_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { case OB_LOC_X: - *array_index= 0; return "location"; + *array_index = 0; return "location"; case OB_LOC_Y: - *array_index= 1; return "location"; + *array_index = 1; return "location"; case OB_LOC_Z: - *array_index= 2; return "location"; + *array_index = 2; return "location"; case OB_DLOC_X: - *array_index= 0; return "delta_location"; + *array_index = 0; return "delta_location"; case OB_DLOC_Y: - *array_index= 1; return "delta_location"; + *array_index = 1; return "delta_location"; case OB_DLOC_Z: - *array_index= 2; return "delta_location"; + *array_index = 2; return "delta_location"; case OB_ROT_X: - *array_index= 0; return "rotation_euler"; + *array_index = 0; return "rotation_euler"; case OB_ROT_Y: - *array_index= 1; return "rotation_euler"; + *array_index = 1; return "rotation_euler"; case OB_ROT_Z: - *array_index= 2; return "rotation_euler"; + *array_index = 2; return "rotation_euler"; case OB_DROT_X: - *array_index= 0; return "delta_rotation_euler"; + *array_index = 0; return "delta_rotation_euler"; case OB_DROT_Y: - *array_index= 1; return "delta_rotation_euler"; + *array_index = 1; return "delta_rotation_euler"; case OB_DROT_Z: - *array_index= 2; return "delta_rotation_euler"; + *array_index = 2; return "delta_rotation_euler"; case OB_SIZE_X: - *array_index= 0; return "scale"; + *array_index = 0; return "scale"; case OB_SIZE_Y: - *array_index= 1; return "scale"; + *array_index = 1; return "scale"; case OB_SIZE_Z: - *array_index= 2; return "scale"; + *array_index = 2; return "scale"; case OB_DSIZE_X: - *array_index= 0; return "delta_scale"; + *array_index = 0; return "delta_scale"; case OB_DSIZE_Y: - *array_index= 1; return "delta_scale"; + *array_index = 1; return "delta_scale"; case OB_DSIZE_Z: - *array_index= 2; return "delta_scale"; + *array_index = 2; return "delta_scale"; case OB_COL_R: - *array_index= 0; return "color"; + *array_index = 0; return "color"; case OB_COL_G: - *array_index= 1; return "color"; + *array_index = 1; return "color"; case OB_COL_B: - *array_index= 2; return "color"; + *array_index = 2; return "color"; case OB_COL_A: - *array_index= 3; return "color"; + *array_index = 3; return "color"; #if 0 case OB_PD_FSTR: - if (ob->pd) poin= &(ob->pd->f_strength); + if (ob->pd) poin = &(ob->pd->f_strength); break; case OB_PD_FFALL: - if (ob->pd) poin= &(ob->pd->f_power); + if (ob->pd) poin = &(ob->pd->f_power); break; case OB_PD_SDAMP: - if (ob->pd) poin= &(ob->pd->pdef_damp); + if (ob->pd) poin = &(ob->pd->pdef_damp); break; case OB_PD_RDAMP: - if (ob->pd) poin= &(ob->pd->pdef_rdamp); + if (ob->pd) poin = &(ob->pd->pdef_rdamp); break; case OB_PD_PERM: - if (ob->pd) poin= &(ob->pd->pdef_perm); + if (ob->pd) poin = &(ob->pd->pdef_perm); break; case OB_PD_FMAXD: - if (ob->pd) poin= &(ob->pd->maxdist); + if (ob->pd) poin = &(ob->pd->maxdist); break; #endif } @@ -257,42 +257,42 @@ static const char *ob_adrcodes_to_paths (int adrcode, int *array_index) /* PoseChannel types * NOTE: pchan name comes from 'actname' added earlier... */ -static const char *pchan_adrcodes_to_paths (int adrcode, int *array_index) +static const char *pchan_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { case AC_QUAT_W: - *array_index= 0; return "rotation_quaternion"; + *array_index = 0; return "rotation_quaternion"; case AC_QUAT_X: - *array_index= 1; return "rotation_quaternion"; + *array_index = 1; return "rotation_quaternion"; case AC_QUAT_Y: - *array_index= 2; return "rotation_quaternion"; + *array_index = 2; return "rotation_quaternion"; case AC_QUAT_Z: - *array_index= 3; return "rotation_quaternion"; + *array_index = 3; return "rotation_quaternion"; case AC_EUL_X: - *array_index= 0; return "rotation_euler"; + *array_index = 0; return "rotation_euler"; case AC_EUL_Y: - *array_index= 1; return "rotation_euler"; + *array_index = 1; return "rotation_euler"; case AC_EUL_Z: - *array_index= 2; return "rotation_euler"; + *array_index = 2; return "rotation_euler"; case AC_LOC_X: - *array_index= 0; return "location"; + *array_index = 0; return "location"; case AC_LOC_Y: - *array_index= 1; return "location"; + *array_index = 1; return "location"; case AC_LOC_Z: - *array_index= 2; return "location"; + *array_index = 2; return "location"; case AC_SIZE_X: - *array_index= 0; return "scale"; + *array_index = 0; return "scale"; case AC_SIZE_Y: - *array_index= 1; return "scale"; + *array_index = 1; return "scale"; case AC_SIZE_Z: - *array_index= 2; return "scale"; + *array_index = 2; return "scale"; } /* for debugging only */ @@ -301,16 +301,16 @@ static const char *pchan_adrcodes_to_paths (int adrcode, int *array_index) } /* Constraint types */ -static const char *constraint_adrcodes_to_paths (int adrcode, int *array_index) +static const char *constraint_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { case CO_ENFORCE: return "influence"; - case CO_HEADTAIL: // XXX this needs to be wrapped in RNA.. probably then this path will be invalid + case CO_HEADTAIL: // XXX this needs to be wrapped in RNA.. probably then this path will be invalid return "data.head_tail"; } @@ -321,7 +321,7 @@ static const char *constraint_adrcodes_to_paths (int adrcode, int *array_index) * NOTE: as we don't have access to the keyblock where the data comes from (for now), * we'll just use numerical indices for now... */ -static char *shapekey_adrcodes_to_paths (int adrcode, int *UNUSED(array_index)) +static char *shapekey_adrcodes_to_paths(int adrcode, int *UNUSED(array_index)) { static char buf[128]; @@ -338,64 +338,64 @@ static char *shapekey_adrcodes_to_paths (int adrcode, int *UNUSED(array_index)) } /* MTex (Texture Slot) types */ -static const char *mtex_adrcodes_to_paths (int adrcode, int *UNUSED(array_index)) +static const char *mtex_adrcodes_to_paths(int adrcode, int *UNUSED(array_index)) { - const char *base=NULL, *prop=NULL; + const char *base = NULL, *prop = NULL; static char buf[128]; /* base part of path */ - if (adrcode & MA_MAP1) base= "textures[0]"; - else if (adrcode & MA_MAP2) base= "textures[1]"; - else if (adrcode & MA_MAP3) base= "textures[2]"; - else if (adrcode & MA_MAP4) base= "textures[3]"; - else if (adrcode & MA_MAP5) base= "textures[4]"; - else if (adrcode & MA_MAP6) base= "textures[5]"; - else if (adrcode & MA_MAP7) base= "textures[6]"; - else if (adrcode & MA_MAP8) base= "textures[7]"; - else if (adrcode & MA_MAP9) base= "textures[8]"; - else if (adrcode & MA_MAP10) base= "textures[9]"; - else if (adrcode & MA_MAP11) base= "textures[10]"; - else if (adrcode & MA_MAP12) base= "textures[11]"; - else if (adrcode & MA_MAP13) base= "textures[12]"; - else if (adrcode & MA_MAP14) base= "textures[13]"; - else if (adrcode & MA_MAP15) base= "textures[14]"; - else if (adrcode & MA_MAP16) base= "textures[15]"; - else if (adrcode & MA_MAP17) base= "textures[16]"; - else if (adrcode & MA_MAP18) base= "textures[17]"; + if (adrcode & MA_MAP1) base = "textures[0]"; + else if (adrcode & MA_MAP2) base = "textures[1]"; + else if (adrcode & MA_MAP3) base = "textures[2]"; + else if (adrcode & MA_MAP4) base = "textures[3]"; + else if (adrcode & MA_MAP5) base = "textures[4]"; + else if (adrcode & MA_MAP6) base = "textures[5]"; + else if (adrcode & MA_MAP7) base = "textures[6]"; + else if (adrcode & MA_MAP8) base = "textures[7]"; + else if (adrcode & MA_MAP9) base = "textures[8]"; + else if (adrcode & MA_MAP10) base = "textures[9]"; + else if (adrcode & MA_MAP11) base = "textures[10]"; + else if (adrcode & MA_MAP12) base = "textures[11]"; + else if (adrcode & MA_MAP13) base = "textures[12]"; + else if (adrcode & MA_MAP14) base = "textures[13]"; + else if (adrcode & MA_MAP15) base = "textures[14]"; + else if (adrcode & MA_MAP16) base = "textures[15]"; + else if (adrcode & MA_MAP17) base = "textures[16]"; + else if (adrcode & MA_MAP18) base = "textures[17]"; /* property identifier for path */ - adrcode= (adrcode & (MA_MAP1-1)); + adrcode = (adrcode & (MA_MAP1 - 1)); switch (adrcode) { #if 0 // XXX these are not wrapped in RNA yet! case MAP_OFS_X: - poin= &(mtex->ofs[0]); break; + poin = &(mtex->ofs[0]); break; case MAP_OFS_Y: - poin= &(mtex->ofs[1]); break; + poin = &(mtex->ofs[1]); break; case MAP_OFS_Z: - poin= &(mtex->ofs[2]); break; + poin = &(mtex->ofs[2]); break; case MAP_SIZE_X: - poin= &(mtex->size[0]); break; + poin = &(mtex->size[0]); break; case MAP_SIZE_Y: - poin= &(mtex->size[1]); break; + poin = &(mtex->size[1]); break; case MAP_SIZE_Z: - poin= &(mtex->size[2]); break; + poin = &(mtex->size[2]); break; case MAP_R: - poin= &(mtex->r); break; + poin = &(mtex->r); break; case MAP_G: - poin= &(mtex->g); break; + poin = &(mtex->g); break; case MAP_B: - poin= &(mtex->b); break; + poin = &(mtex->b); break; case MAP_DVAR: - poin= &(mtex->def_var); break; + poin = &(mtex->def_var); break; case MAP_COLF: - poin= &(mtex->colfac); break; + poin = &(mtex->colfac); break; case MAP_NORF: - poin= &(mtex->norfac); break; + poin = &(mtex->norfac); break; case MAP_VARF: - poin= &(mtex->varfac); break; + poin = &(mtex->varfac); break; #endif case MAP_DISP: - prop= "warp_factor"; break; + prop = "warp_factor"; break; } /* only build and return path if there's a property */ @@ -408,10 +408,10 @@ static const char *mtex_adrcodes_to_paths (int adrcode, int *UNUSED(array_index) } /* Texture types */ -static const char *texture_adrcodes_to_paths (int adrcode, int *array_index) +static const char *texture_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { @@ -420,7 +420,7 @@ static const char *texture_adrcodes_to_paths (int adrcode, int *array_index) case TE_TURB: return "turbulence"; - case TE_NDEPTH: // XXX texture RNA undefined + case TE_NDEPTH: // XXX texture RNA undefined //poin= &(tex->noisedepth); *type= IPO_SHORT; break; break; case TE_NTYPE: // XXX texture RNA undefined @@ -432,15 +432,15 @@ static const char *texture_adrcodes_to_paths (int adrcode, int *array_index) case TE_N_BAS2: return "noise_basis"; // XXX this is not yet defined in RNA... - /* voronoi */ + /* voronoi */ case TE_VNW1: - *array_index= 0; return "feature_weights"; + *array_index = 0; return "feature_weights"; case TE_VNW2: - *array_index= 1; return "feature_weights"; + *array_index = 1; return "feature_weights"; case TE_VNW3: - *array_index= 2; return "feature_weights"; + *array_index = 2; return "feature_weights"; case TE_VNW4: - *array_index= 3; return "feature_weights"; + *array_index = 3; return "feature_weights"; case TE_VNMEXP: return "minkovsky_exponent"; case TE_VN_DISTM: @@ -448,17 +448,17 @@ static const char *texture_adrcodes_to_paths (int adrcode, int *array_index) case TE_VN_COLT: return "color_type"; - /* distorted noise / voronoi */ + /* distorted noise / voronoi */ case TE_ISCA: return "noise_intensity"; - /* distorted noise */ + /* distorted noise */ case TE_DISTA: return "distortion_amount"; - /* musgrave */ + /* musgrave */ case TE_MG_TYP: // XXX texture RNA undefined - // poin= &(tex->stype); *type= IPO_SHORT; break; + // poin= &(tex->stype); *type= IPO_SHORT; break; break; case TE_MGH: return "highest_dimension"; @@ -472,11 +472,11 @@ static const char *texture_adrcodes_to_paths (int adrcode, int *array_index) return "gain"; case TE_COL_R: - *array_index= 0; return "rgb_factor"; + *array_index = 0; return "rgb_factor"; case TE_COL_G: - *array_index= 1; return "rgb_factor"; + *array_index = 1; return "rgb_factor"; case TE_COL_B: - *array_index= 2; return "rgb_factor"; + *array_index = 2; return "rgb_factor"; case TE_BRIGHT: return "brightness"; @@ -488,33 +488,33 @@ static const char *texture_adrcodes_to_paths (int adrcode, int *array_index) } /* Material Types */ -static const char *material_adrcodes_to_paths (int adrcode, int *array_index) +static const char *material_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { case MA_COL_R: - *array_index= 0; return "diffuse_color"; + *array_index = 0; return "diffuse_color"; case MA_COL_G: - *array_index= 1; return "diffuse_color"; + *array_index = 1; return "diffuse_color"; case MA_COL_B: - *array_index= 2; return "diffuse_color"; + *array_index = 2; return "diffuse_color"; case MA_SPEC_R: - *array_index= 0; return "specular_color"; + *array_index = 0; return "specular_color"; case MA_SPEC_G: - *array_index= 1; return "specular_color"; + *array_index = 1; return "specular_color"; case MA_SPEC_B: - *array_index= 2; return "specular_color"; + *array_index = 2; return "specular_color"; case MA_MIR_R: - *array_index= 0; return "mirror_color"; + *array_index = 0; return "mirror_color"; case MA_MIR_G: - *array_index= 1; return "mirror_color"; + *array_index = 1; return "mirror_color"; case MA_MIR_B: - *array_index= 2; return "mirror_color"; + *array_index = 2; return "mirror_color"; case MA_ALPHA: return "alpha"; @@ -572,10 +572,10 @@ static const char *material_adrcodes_to_paths (int adrcode, int *array_index) } /* Camera Types */ -static const char *camera_adrcodes_to_paths (int adrcode, int *array_index) +static const char *camera_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { @@ -596,9 +596,9 @@ static const char *camera_adrcodes_to_paths (int adrcode, int *array_index) #if 0 // XXX these are not defined in RNA case CAM_YF_APERT: - poin= &(ca->YF_aperture); break; + poin = &(ca->YF_aperture); break; case CAM_YF_FDIST: - poin= &(ca->YF_dofdist); break; + poin = &(ca->YF_dofdist); break; #endif // XXX these are not defined in RNA case CAM_SHIFT_X: @@ -612,10 +612,10 @@ static const char *camera_adrcodes_to_paths (int adrcode, int *array_index) } /* Lamp Types */ -static const char *lamp_adrcodes_to_paths (int adrcode, int *array_index) +static const char *lamp_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { @@ -623,11 +623,11 @@ static const char *lamp_adrcodes_to_paths (int adrcode, int *array_index) return "energy"; case LA_COL_R: - *array_index= 0; return "color"; + *array_index = 0; return "color"; case LA_COL_G: - *array_index= 1; return "color"; + *array_index = 1; return "color"; case LA_COL_B: - *array_index= 2; return "color"; + *array_index = 2; return "color"; case LA_DIST: return "distance"; @@ -654,10 +654,10 @@ static const char *lamp_adrcodes_to_paths (int adrcode, int *array_index) } /* Sound Types */ -static const char *sound_adrcodes_to_paths (int adrcode, int *array_index) +static const char *sound_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { @@ -665,7 +665,7 @@ static const char *sound_adrcodes_to_paths (int adrcode, int *array_index) return "volume"; case SND_PITCH: return "pitch"; - /* XXX Joshua -- I had wrapped panning in rna, but someone commented out, calling it "unused" */ + /* XXX Joshua -- I had wrapped panning in rna, but someone commented out, calling it "unused" */ #if 0 case SND_PANNING: return "panning"; @@ -679,25 +679,25 @@ static const char *sound_adrcodes_to_paths (int adrcode, int *array_index) } /* World Types */ -static const char *world_adrcodes_to_paths (int adrcode, int *array_index) +static const char *world_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { case WO_HOR_R: - *array_index= 0; return "horizon_color"; + *array_index = 0; return "horizon_color"; case WO_HOR_G: - *array_index= 1; return "horizon_color"; + *array_index = 1; return "horizon_color"; case WO_HOR_B: - *array_index= 2; return "horizon_color"; + *array_index = 2; return "horizon_color"; case WO_ZEN_R: - *array_index= 0; return "zenith_color"; + *array_index = 0; return "zenith_color"; case WO_ZEN_G: - *array_index= 1; return "zenith_color"; + *array_index = 1; return "zenith_color"; case WO_ZEN_B: - *array_index= 2; return "zenith_color"; + *array_index = 2; return "zenith_color"; case WO_EXPOS: return "exposure"; @@ -724,16 +724,16 @@ static const char *world_adrcodes_to_paths (int adrcode, int *array_index) default: /* for now, we assume that the others were MTex channels */ return mtex_adrcodes_to_paths(adrcode, array_index); - } + } return NULL; } /* Particle Types */ -static const char *particle_adrcodes_to_paths (int adrcode, int *array_index) +static const char *particle_adrcodes_to_paths(int adrcode, int *array_index) { /* set array index like this in-case nothing sets it correctly */ - *array_index= 0; + *array_index = 0; /* result depends on adrcode */ switch (adrcode) { @@ -752,11 +752,11 @@ static const char *particle_adrcodes_to_paths (int adrcode, int *array_index) case PART_LENGTH: return "settings.length"; case PART_GRAV_X: - *array_index= 0; return "settings.acceleration"; + *array_index = 0; return "settings.acceleration"; case PART_GRAV_Y: - *array_index= 1; return "settings.acceleration"; + *array_index = 1; return "settings.acceleration"; case PART_GRAV_Z: - *array_index= 2; return "settings.acceleration"; + *array_index = 2; return "settings.acceleration"; case PART_KINK_AMP: return "settings.kink_amplitude"; case PART_KINK_FREQ: @@ -773,22 +773,22 @@ static const char *particle_adrcodes_to_paths (int adrcode, int *array_index) * as the similar object forces */ #if 0 case PART_PD_FSTR: - if (part->pd) poin= &(part->pd->f_strength); + if (part->pd) poin = &(part->pd->f_strength); break; case PART_PD_FFALL: - if (part->pd) poin= &(part->pd->f_power); + if (part->pd) poin = &(part->pd->f_power); break; case PART_PD_FMAXD: - if (part->pd) poin= &(part->pd->maxdist); + if (part->pd) poin = &(part->pd->maxdist); break; case PART_PD2_FSTR: - if (part->pd2) poin= &(part->pd2->f_strength); + if (part->pd2) poin = &(part->pd2->f_strength); break; case PART_PD2_FFALL: - if (part->pd2) poin= &(part->pd2->f_power); + if (part->pd2) poin = &(part->pd2->f_power); break; case PART_PD2_FMAXD: - if (part->pd2) poin= &(part->pd2->maxdist); + if (part->pd2) poin = &(part->pd2->maxdist); break; #endif @@ -807,84 +807,84 @@ static const char *particle_adrcodes_to_paths (int adrcode, int *array_index) * - array_index - index in property's array (if applicable) to use * - return - the allocated path... */ -static char *get_rna_access (int blocktype, int adrcode, char actname[], char constname[], Sequence *seq, int *array_index) +static char *get_rna_access(int blocktype, int adrcode, char actname[], char constname[], Sequence *seq, int *array_index) { - DynStr *path= BLI_dynstr_new(); - const char *propname=NULL; - char *rpath=NULL; + DynStr *path = BLI_dynstr_new(); + const char *propname = NULL; + char *rpath = NULL; char buf[512]; - int dummy_index= 0; + int dummy_index = 0; /* hack: if constname is set, we can only be dealing with an Constraint curve */ if (constname) - blocktype= ID_CO; + blocktype = ID_CO; /* get property name based on blocktype */ switch (blocktype) { case ID_OB: /* object */ - propname= ob_adrcodes_to_paths(adrcode, &dummy_index); + propname = ob_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_PO: /* pose channel */ - propname= pchan_adrcodes_to_paths(adrcode, &dummy_index); + propname = pchan_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_KE: /* shapekeys */ - propname= shapekey_adrcodes_to_paths(adrcode, &dummy_index); + propname = shapekey_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_CO: /* constraint */ - propname= constraint_adrcodes_to_paths(adrcode, &dummy_index); + propname = constraint_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_TE: /* texture */ - propname= texture_adrcodes_to_paths(adrcode, &dummy_index); + propname = texture_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_MA: /* material */ - propname= material_adrcodes_to_paths(adrcode, &dummy_index); + propname = material_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_CA: /* camera */ - propname= camera_adrcodes_to_paths(adrcode, &dummy_index); + propname = camera_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_LA: /* lamp */ - propname= lamp_adrcodes_to_paths(adrcode, &dummy_index); + propname = lamp_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_SO: /* sound */ - propname= sound_adrcodes_to_paths(adrcode, &dummy_index); + propname = sound_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_WO: /* world */ - propname= world_adrcodes_to_paths(adrcode, &dummy_index); + propname = world_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_PA: /* particle */ - propname= particle_adrcodes_to_paths(adrcode, &dummy_index); + propname = particle_adrcodes_to_paths(adrcode, &dummy_index); break; case ID_CU: /* curve */ /* this used to be a 'dummy' curve which got evaluated on the fly... * now we've got real var for this! */ - propname= "eval_time"; + propname = "eval_time"; break; /* XXX problematic blocktypes */ case ID_SEQ: /* sequencer strip */ //SEQ_FAC1: switch (adrcode) { - case SEQ_FAC1: - propname= "effect_fader"; - break; - case SEQ_FAC_SPEED: - propname= "speed_fader"; - break; - case SEQ_FAC_OPACITY: - propname= "blend_opacity"; - break; + case SEQ_FAC1: + propname = "effect_fader"; + break; + case SEQ_FAC_SPEED: + propname = "speed_fader"; + break; + case SEQ_FAC_OPACITY: + propname = "blend_opacity"; + break; } // poin= &(seq->facf0); // XXX this doesn't seem to be included anywhere in sequencer RNA... break; @@ -906,7 +906,7 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co if ((propname == NULL) && (blocktype > 0)) { /* nothing was found, so exit */ if (array_index) - *array_index= 0; + *array_index = 0; BLI_dynstr_free(path); @@ -914,7 +914,7 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co } else { if (array_index) - *array_index= dummy_index; + *array_index = dummy_index; } /* 'buf' _must_ be initialized in this block */ @@ -925,11 +925,11 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co BLI_snprintf(buf, sizeof(buf), "pose.bones[\"%s\"].constraints[\"%s\"]", actname, constname); } else if (actname && actname[0]) { - if ((blocktype == ID_OB) && strcmp(actname, "Object")==0) { + if ((blocktype == ID_OB) && strcmp(actname, "Object") == 0) { /* Actionified "Object" IPO's... no extra path stuff needed */ - buf[0]= '\0'; /* empty string */ + buf[0] = '\0'; /* empty string */ } - else if ((blocktype == ID_KE) && strcmp(actname, "Shape")==0) { + else if ((blocktype == ID_KE) && strcmp(actname, "Shape") == 0) { /* Actionified "Shape" IPO's - these are forced onto object level via the action container there... */ strcpy(buf, "data.shape_keys"); } @@ -944,10 +944,10 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co } else if (seq) { /* Sequence names in Scene */ - BLI_snprintf(buf, sizeof(buf), "sequence_editor.sequences_all[\"%s\"]", seq->name+2); + BLI_snprintf(buf, sizeof(buf), "sequence_editor.sequences_all[\"%s\"]", seq->name + 2); } else { - buf[0]= '\0'; /* empty string */ + buf[0] = '\0'; /* empty string */ } BLI_dynstr_append(path, buf); @@ -966,7 +966,7 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co } /* convert to normal MEM_malloc'd string */ - rpath= BLI_dynstr_get_cstring(path); + rpath = BLI_dynstr_get_cstring(path); BLI_dynstr_free(path); /* return path... */ @@ -977,7 +977,7 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co /* Conversion Utilities */ /* Convert adrcodes to driver target transform channel types */ -static short adrcode_to_dtar_transchan (short adrcode) +static short adrcode_to_dtar_transchan(short adrcode) { switch (adrcode) { case OB_LOC_X: @@ -1007,12 +1007,12 @@ static short adrcode_to_dtar_transchan (short adrcode) } /* Convert IpoDriver to ChannelDriver - will free the old data (i.e. the old driver) */ -static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver) +static ChannelDriver *idriver_to_cdriver(IpoDriver *idriver) { ChannelDriver *cdriver; /* allocate memory for new driver */ - cdriver= MEM_callocN(sizeof(ChannelDriver), "ChannelDriver"); + cdriver = MEM_callocN(sizeof(ChannelDriver), "ChannelDriver"); /* if 'pydriver', just copy data across */ if (idriver->type == IPO_DRIVER_TYPE_PYTHON) { @@ -1027,54 +1027,54 @@ static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver) DriverTarget *dtar = NULL; /* this should be ok for all types here... */ - cdriver->type= DRIVER_TYPE_AVERAGE; + cdriver->type = DRIVER_TYPE_AVERAGE; /* what to store depends on the 'blocktype' - object or posechannel */ if (idriver->blocktype == ID_AR) { /* PoseChannel */ if (idriver->adrcode == OB_ROT_DIFF) { /* Rotational Difference requires a special type of variable */ - dvar= driver_add_new_variable(cdriver); + dvar = driver_add_new_variable(cdriver); driver_change_variable_type(dvar, DVAR_TYPE_ROT_DIFF); - /* first bone target */ - dtar= &dvar->targets[0]; - dtar->id= (ID *)idriver->ob; - dtar->idtype= ID_OB; + /* first bone target */ + dtar = &dvar->targets[0]; + dtar->id = (ID *)idriver->ob; + dtar->idtype = ID_OB; if (idriver->name[0]) BLI_strncpy(dtar->pchan_name, idriver->name, sizeof(dtar->pchan_name)); - /* second bone target (name was stored in same var as the first one) */ - dtar= &dvar->targets[1]; - dtar->id= (ID *)idriver->ob; - dtar->idtype= ID_OB; + /* second bone target (name was stored in same var as the first one) */ + dtar = &dvar->targets[1]; + dtar->id = (ID *)idriver->ob; + dtar->idtype = ID_OB; if (idriver->name[0]) // xxx... for safety - BLI_strncpy(dtar->pchan_name, idriver->name+DRIVER_NAME_OFFS, sizeof(dtar->pchan_name)); + BLI_strncpy(dtar->pchan_name, idriver->name + DRIVER_NAME_OFFS, sizeof(dtar->pchan_name)); } else { /* only a single variable, of type 'transform channel' */ - dvar= driver_add_new_variable(cdriver); + dvar = driver_add_new_variable(cdriver); driver_change_variable_type(dvar, DVAR_TYPE_TRANSFORM_CHAN); /* only requires a single target */ - dtar= &dvar->targets[0]; - dtar->id= (ID *)idriver->ob; - dtar->idtype= ID_OB; + dtar = &dvar->targets[0]; + dtar->id = (ID *)idriver->ob; + dtar->idtype = ID_OB; if (idriver->name[0]) BLI_strncpy(dtar->pchan_name, idriver->name, sizeof(dtar->pchan_name)); - dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode); + dtar->transChan = adrcode_to_dtar_transchan(idriver->adrcode); dtar->flag |= DTAR_FLAG_LOCALSPACE; /* old drivers took local space */ } } else { /* Object */ - /* only a single variable, of type 'transform channel' */ - dvar= driver_add_new_variable(cdriver); + /* only a single variable, of type 'transform channel' */ + dvar = driver_add_new_variable(cdriver); driver_change_variable_type(dvar, DVAR_TYPE_TRANSFORM_CHAN); - /* only requires single target */ - dtar= &dvar->targets[0]; - dtar->id= (ID *)idriver->ob; - dtar->idtype= ID_OB; - dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode); + /* only requires single target */ + dtar = &dvar->targets[0]; + dtar->id = (ID *)idriver->ob; + dtar->idtype = ID_OB; + dtar->transChan = adrcode_to_dtar_transchan(idriver->adrcode); } } @@ -1085,7 +1085,7 @@ static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver) /* Add F-Curve to the correct list * - grpname is needed to be used as group name where relevant, and is usually derived from actname */ -static void fcurve_add_to_list (ListBase *groups, ListBase *list, FCurve *fcu, char *grpname, int muteipo) +static void fcurve_add_to_list(ListBase *groups, ListBase *list, FCurve *fcu, char *grpname, int muteipo) { /* If we're adding to an action, we will have groups to write to... */ if (groups && grpname) { @@ -1093,22 +1093,22 @@ static void fcurve_add_to_list (ListBase *groups, ListBase *list, FCurve *fcu, c * and extract the resultant lists... */ bAction tmp_act; - bActionGroup *agrp= NULL; + bActionGroup *agrp = NULL; /* init the temp action */ memset(&tmp_act, 0, sizeof(bAction)); // XXX only enable this line if we get errors - tmp_act.groups.first= groups->first; - tmp_act.groups.last= groups->last; - tmp_act.curves.first= list->first; - tmp_act.curves.last= list->last; + tmp_act.groups.first = groups->first; + tmp_act.groups.last = groups->last; + tmp_act.curves.first = list->first; + tmp_act.curves.last = list->last; /* ... xxx, the other vars don't need to be filled in */ /* get the group to use */ - agrp= BKE_action_group_find_name(&tmp_act, grpname); + agrp = BKE_action_group_find_name(&tmp_act, grpname); /* no matching group, so add one */ if (agrp == NULL) { /* Add a new group, and make it active */ - agrp= MEM_callocN(sizeof(bActionGroup), "bActionGroup"); + agrp = MEM_callocN(sizeof(bActionGroup), "bActionGroup"); agrp->flag = AGRP_SELECTED; if (muteipo) agrp->flag |= AGRP_MUTED; @@ -1127,10 +1127,10 @@ static void fcurve_add_to_list (ListBase *groups, ListBase *list, FCurve *fcu, c fcu->flag |= FCURVE_MUTED; /* set the output lists based on the ones in the temp action */ - groups->first= tmp_act.groups.first; - groups->last= tmp_act.groups.last; - list->first= tmp_act.curves.first; - list->last= tmp_act.curves.last; + groups->first = tmp_act.groups.first; + groups->last = tmp_act.groups.last; + list->first = tmp_act.curves.first; + list->last = tmp_act.curves.last; } else { /* simply add the F-Curve to the end of the given list */ @@ -1144,18 +1144,18 @@ static void fcurve_add_to_list (ListBase *groups, ListBase *list, FCurve *fcu, c * constname: name of Constraint-Channel (if applicable) that IPO-Curve's IPO-block belonged to * seq: sequencer-strip (if applicable) that IPO-Curve's IPO-block belonged to */ -static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve *icu, char *actname, char *constname, Sequence * seq, int muteipo) +static void icu_to_fcurves(ID *id, ListBase *groups, ListBase *list, IpoCurve *icu, char *actname, char *constname, Sequence *seq, int muteipo) { AdrBit2Path *abp; FCurve *fcu; int totbits; /* allocate memory for a new F-Curve */ - fcu= MEM_callocN(sizeof(FCurve), "FCurve"); + fcu = MEM_callocN(sizeof(FCurve), "FCurve"); /* convert driver */ if (icu->driver) - fcu->driver= idriver_to_cdriver(icu->driver); + fcu->driver = idriver_to_cdriver(icu->driver); /* copy flags */ if (icu->flag & IPO_VISIBLE) fcu->flag |= FCURVE_VISIBLE; @@ -1170,9 +1170,9 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * case IPO_DIR: /* linear extrapolation */ { /* just copy, as the new defines match the old ones... */ - fcu->extend= icu->extrap; + fcu->extend = icu->extrap; } - break; + break; case IPO_CYCL: /* cyclic extrapolation */ case IPO_CYCLX: /* cyclic extrapolation + offset */ @@ -1180,22 +1180,22 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * /* Add a new FModifier (Cyclic) instead of setting extend value * as that's the new equivalent of that option. */ - FModifier *fcm= add_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_CYCLES); - FMod_Cycles *data= (FMod_Cycles *)fcm->data; + FModifier *fcm = add_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_CYCLES); + FMod_Cycles *data = (FMod_Cycles *)fcm->data; /* if 'offset' one is in use, set appropriate settings */ if (icu->extrap == IPO_CYCLX) - data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC_OFFSET; + data->before_mode = data->after_mode = FCM_EXTRAPOLATE_CYCLIC_OFFSET; else - data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC; + data->before_mode = data->after_mode = FCM_EXTRAPOLATE_CYCLIC; } - break; + break; } /* -------- */ /* get adrcode <-> bitflags mapping to handle nasty bitflag curves? */ - abp= adrcode_bitmaps_to_paths(icu->blocktype, icu->adrcode, &totbits); + abp = adrcode_bitmaps_to_paths(icu->blocktype, icu->adrcode, &totbits); if (abp && totbits) { FCurve *fcurve; int b; @@ -1203,49 +1203,49 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * if (G.debug & G_DEBUG) printf("\tconvert bitflag ipocurve, totbits = %d\n", totbits); /* add the 'only int values' flag */ - fcu->flag |= (FCURVE_INT_VALUES|FCURVE_DISCRETE_VALUES); + fcu->flag |= (FCURVE_INT_VALUES | FCURVE_DISCRETE_VALUES); /* for each bit we have to remap + check for: * 1) we need to make copy the existing F-Curve data (fcu -> fcurve), - * except for the last one which will use the original + * except for the last one which will use the original * 2) copy the relevant path info across * 3) filter the keyframes for the flag of interest */ - for (b=0; b < totbits; b++, abp++) { - unsigned int i=0; + for (b = 0; b < totbits; b++, abp++) { + unsigned int i = 0; /* make a copy of existing base-data if not the last curve */ - if (b < (totbits-1)) - fcurve= copy_fcurve(fcu); + if (b < (totbits - 1)) + fcurve = copy_fcurve(fcu); else - fcurve= fcu; + fcurve = fcu; /* set path */ - fcurve->rna_path= BLI_strdup(abp->path); - fcurve->array_index= abp->array_index; + fcurve->rna_path = BLI_strdup(abp->path); + fcurve->array_index = abp->array_index; /* convert keyframes * - beztriples and bpoints are mutually exclusive, so we won't have both at the same time * - beztriples are more likely to be encountered as they are keyframes (the other type wasn't used yet) */ - fcurve->totvert= icu->totvert; + fcurve->totvert = icu->totvert; if (icu->bezt) { BezTriple *dst, *src; /* allocate new array for keyframes/beztriples */ - fcurve->bezt= MEM_callocN(sizeof(BezTriple)*fcurve->totvert, "BezTriples"); + fcurve->bezt = MEM_callocN(sizeof(BezTriple) * fcurve->totvert, "BezTriples"); /* loop through copying all BezTriples individually, as we need to modify a few things */ - for (dst=fcurve->bezt, src=icu->bezt, i=0; i < fcurve->totvert; i++, dst++, src++) { + for (dst = fcurve->bezt, src = icu->bezt, i = 0; i < fcurve->totvert; i++, dst++, src++) { /* firstly, copy BezTriple data */ - *dst= *src; + *dst = *src; /* interpolation can only be constant... */ - dst->ipo= BEZT_IPO_CONST; + dst->ipo = BEZT_IPO_CONST; /* 'hide' flag is now used for keytype - only 'keyframes' existed before */ - dst->hide= BEZT_KEYTYPE_KEYFRAME; + dst->hide = BEZT_KEYTYPE_KEYFRAME; /* auto-handles - per curve to per handle */ if (icu->flag & IPO_AUTO_HORIZ) { @@ -1255,9 +1255,9 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * /* correct values, by checking if the flag of interest is set */ if ( ((int)(dst->vec[1][1])) & (abp->bit) ) - dst->vec[0][1]= dst->vec[1][1]= dst->vec[2][1] = 1.0f; + dst->vec[0][1] = dst->vec[1][1] = dst->vec[2][1] = 1.0f; else - dst->vec[0][1]= dst->vec[1][1]= dst->vec[2][1] = 0.0f; + dst->vec[0][1] = dst->vec[1][1] = dst->vec[2][1] = 0.0f; } } else if (icu->bp) { @@ -1271,12 +1271,12 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * } } else { - unsigned int i=0; + unsigned int i = 0; /* get rna-path * - we will need to set the 'disabled' flag if no path is able to be made (for now) */ - fcu->rna_path= get_rna_access(icu->blocktype, icu->adrcode, actname, constname, seq, &fcu->array_index); + fcu->rna_path = get_rna_access(icu->blocktype, icu->adrcode, actname, constname, seq, &fcu->array_index); if (fcu->rna_path == NULL) fcu->flag |= FCURVE_DISABLED; @@ -1284,25 +1284,25 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * * - beztriples and bpoints are mutually exclusive, so we won't have both at the same time * - beztriples are more likely to be encountered as they are keyframes (the other type wasn't used yet) */ - fcu->totvert= icu->totvert; + fcu->totvert = icu->totvert; if (icu->bezt) { BezTriple *dst, *src; /* allocate new array for keyframes/beztriples */ - fcu->bezt= MEM_callocN(sizeof(BezTriple)*fcu->totvert, "BezTriples"); + fcu->bezt = MEM_callocN(sizeof(BezTriple) * fcu->totvert, "BezTriples"); /* loop through copying all BezTriples individually, as we need to modify a few things */ - for (dst=fcu->bezt, src=icu->bezt, i=0; i < fcu->totvert; i++, dst++, src++) { + for (dst = fcu->bezt, src = icu->bezt, i = 0; i < fcu->totvert; i++, dst++, src++) { /* firstly, copy BezTriple data */ - *dst= *src; + *dst = *src; /* now copy interpolation from curve (if not already set) */ if (icu->ipo != IPO_MIXED) - dst->ipo= icu->ipo; + dst->ipo = icu->ipo; /* 'hide' flag is now used for keytype - only 'keyframes' existed before */ - dst->hide= BEZT_KEYTYPE_KEYFRAME; + dst->hide = BEZT_KEYTYPE_KEYFRAME; /* auto-handles - per curve to per handle */ if (icu->flag & IPO_AUTO_HORIZ) { @@ -1315,9 +1315,9 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * * - we need radians for RNA to do the right thing */ if ( ((icu->blocktype == ID_OB) && ELEM3(icu->adrcode, OB_ROT_X, OB_ROT_Y, OB_ROT_Z)) || - ((icu->blocktype == ID_PO) && ELEM3(icu->adrcode, AC_EUL_X, AC_EUL_Y, AC_EUL_Z)) ) + ((icu->blocktype == ID_PO) && ELEM3(icu->adrcode, AC_EUL_X, AC_EUL_Y, AC_EUL_Z)) ) { - const float fac= (float)M_PI / 18.0f; //10.0f * M_PI/180.0f; + const float fac = (float)M_PI / 18.0f; //10.0f * M_PI/180.0f; dst->vec[0][1] *= fac; dst->vec[1][1] *= fac; @@ -1329,7 +1329,7 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * * - we now need as 'frames' */ if ( (id) && (icu->blocktype == GS(id->name)) && - (fcu->rna_path && strcmp(fcu->rna_path, "eval_time")==0) ) + (fcu->rna_path && strcmp(fcu->rna_path, "eval_time") == 0) ) { Curve *cu = (Curve *)id; @@ -1340,15 +1340,15 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * /* correct times for rotation drivers * - need to go from degrees to radians... - * - there's only really 1 target to worry about + * - there's only really 1 target to worry about * - were also degrees/10 */ if (fcu->driver && fcu->driver->variables.first) { - DriverVar *dvar= fcu->driver->variables.first; - DriverTarget *dtar= &dvar->targets[0]; + DriverVar *dvar = fcu->driver->variables.first; + DriverTarget *dtar = &dvar->targets[0]; if (ELEM3(dtar->transChan, DTAR_TRANSCHAN_ROTX, DTAR_TRANSCHAN_ROTY, DTAR_TRANSCHAN_ROTZ)) { - const float fac= (float)M_PI / 18.0f; + const float fac = (float)M_PI / 18.0f; dst->vec[0][0] *= fac; dst->vec[1][0] *= fac; @@ -1358,8 +1358,8 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * /* correct values for sequencer curves, that were not locked to frame */ if (seq && (seq->flag & SEQ_IPO_FRAME_LOCKED) == 0) { - double mul= (seq->enddisp-seq->startdisp)/100.0f; - double offset= seq->startdisp; + double mul = (seq->enddisp - seq->startdisp) / 100.0f; + double offset = seq->startdisp; dst->vec[0][0] *= mul; dst->vec[0][0] += offset; @@ -1389,7 +1389,7 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve * * This does not assume that any ID or AnimData uses it, but does assume that * it is given two lists, which it will perform driver/animation-data separation. */ -static void ipo_to_animato (ID *id, Ipo *ipo, char actname[], char constname[], Sequence *seq, ListBase *animgroups, ListBase *anim, ListBase *drivers) +static void ipo_to_animato(ID *id, Ipo *ipo, char actname[], char constname[], Sequence *seq, ListBase *animgroups, ListBase *anim, ListBase *drivers) { IpoCurve *icu; @@ -1407,13 +1407,13 @@ static void ipo_to_animato (ID *id, Ipo *ipo, char actname[], char constname[], */ if (actname) { if ((ipo->blocktype == ID_OB) && (strcmp(actname, "Object") == 0)) - actname= NULL; + actname = NULL; else if ((ipo->blocktype == ID_OB) && (strcmp(actname, "Shape") == 0)) - actname= NULL; + actname = NULL; } /* loop over IPO-Curves, freeing as we progress */ - for (icu= ipo->curve.first; icu; icu= icu->next) { + for (icu = ipo->curve.first; icu; icu = icu->next) { /* Since an IPO-Curve may end up being made into many F-Curves (i.e. bitflag curves), * we figure out the best place to put the channel, then tell the curve-converter to just dump there */ @@ -1424,7 +1424,7 @@ static void ipo_to_animato (ID *id, Ipo *ipo, char actname[], char constname[], } else { MEM_freeN(icu->driver); - icu->driver= NULL; + icu->driver = NULL; } } else @@ -1436,8 +1436,8 @@ static void ipo_to_animato (ID *id, Ipo *ipo, char actname[], char constname[], if (ID_REAL_USERS(ipo) <= 0) { IpoCurve *icn; - for (icu= ipo->curve.first; icu; icu= icn) { - icn= icu->next; + for (icu = ipo->curve.first; icu; icu = icn) { + icn = icu->next; /* free driver */ if (icu->driver) @@ -1458,7 +1458,7 @@ static void ipo_to_animato (ID *id, Ipo *ipo, char actname[], char constname[], * to Objects, where ob->ipo and ob->action need to be combined). * NOTE: we need to be careful here, as same data-structs are used for new system too! */ -static void action_to_animato (ID *id, bAction *act, ListBase *groups, ListBase *curves, ListBase *drivers) +static void action_to_animato(ID *id, bAction *act, ListBase *groups, ListBase *curves, ListBase *drivers) { bActionChannel *achan, *achann; bConstraintChannel *conchan, *conchann; @@ -1473,27 +1473,27 @@ static void action_to_animato (ID *id, bAction *act, ListBase *groups, ListBase BLI_freelistN(&act->groups); /* loop through Action-Channels, converting data, freeing as we go */ - for (achan= act->chanbase.first; achan; achan= achann) { + for (achan = act->chanbase.first; achan; achan = achann) { /* get pointer to next Action Channel */ - achann= achan->next; + achann = achan->next; /* convert Action Channel's IPO data */ if (achan->ipo) { ipo_to_animato(id, achan->ipo, achan->name, NULL, NULL, groups, curves, drivers); achan->ipo->id.us--; - achan->ipo= NULL; + achan->ipo = NULL; } /* convert constraint channel IPO-data */ - for (conchan= achan->constraintChannels.first; conchan; conchan= conchann) { + for (conchan = achan->constraintChannels.first; conchan; conchan = conchann) { /* get pointer to next Constraint Channel */ - conchann= conchan->next; + conchann = conchan->next; /* convert Constraint Channel's IPO data */ if (conchan->ipo) { ipo_to_animato(id, conchan->ipo, achan->name, conchan->name, NULL, groups, curves, drivers); conchan->ipo->id.us--; - conchan->ipo= NULL; + conchan->ipo = NULL; } /* free Constraint Channel */ @@ -1512,9 +1512,9 @@ static void action_to_animato (ID *id, bAction *act, ListBase *groups, ListBase * This assumes that AnimData has been added already. Separation of drivers * from animation data is accomplished here too... */ -static void ipo_to_animdata (ID *id, Ipo *ipo, char actname[], char constname[], Sequence *seq) +static void ipo_to_animdata(ID *id, Ipo *ipo, char actname[], char constname[], Sequence *seq) { - AnimData *adt= BKE_animdata_from_id(id); + AnimData *adt = BKE_animdata_from_id(id); ListBase anim = {NULL, NULL}; ListBase drivers = {NULL, NULL}; @@ -1528,8 +1528,8 @@ static void ipo_to_animdata (ID *id, Ipo *ipo, char actname[], char constname[], if (G.debug & G_DEBUG) { printf("ipo to animdata - ID:%s, IPO:%s, actname:%s constname:%s seqname:%s curves:%d\n", - id->name+2, ipo->id.name+2, (actname)?actname:"<None>", (constname)?constname:"<None>", (seq)?(seq->name+2):"<None>", - BLI_countlist(&ipo->curve)); + id->name + 2, ipo->id.name + 2, (actname) ? actname : "<None>", (constname) ? constname : "<None>", (seq) ? (seq->name + 2) : "<None>", + BLI_countlist(&ipo->curve)); } /* Convert curves to animato system (separated into separate lists of F-Curves for animation and drivers), @@ -1545,9 +1545,9 @@ static void ipo_to_animdata (ID *id, Ipo *ipo, char actname[], char constname[], if (adt->action == NULL) { char nameBuf[MAX_ID_NAME]; - BLI_snprintf(nameBuf, sizeof(nameBuf), "CDA:%s", ipo->id.name+2); + BLI_snprintf(nameBuf, sizeof(nameBuf), "CDA:%s", ipo->id.name + 2); - adt->action= add_empty_action(nameBuf); + adt->action = add_empty_action(nameBuf); if (G.debug & G_DEBUG) printf("\t\tadded new action - '%s'\n", nameBuf); } @@ -1566,9 +1566,9 @@ static void ipo_to_animdata (ID *id, Ipo *ipo, char actname[], char constname[], /* Convert Action-block to new system * NOTE: we need to be careful here, as same data-structs are used for new system too! */ -static void action_to_animdata (ID *id, bAction *act) +static void action_to_animdata(ID *id, bAction *act) { - AnimData *adt= BKE_animdata_from_id(id); + AnimData *adt = BKE_animdata_from_id(id); /* only continue if there are Action Channels (indicating unconverted data) */ if (ELEM(NULL, adt, act->chanbase.first)) @@ -1578,7 +1578,7 @@ static void action_to_animdata (ID *id, bAction *act) if (adt->action == NULL) { /* set this Action as AnimData's Action */ if (G.debug & G_DEBUG) printf("act_to_adt - set adt action to act\n"); - adt->action= act; + adt->action = act; } /* convert Action data */ @@ -1592,16 +1592,16 @@ static void action_to_animdata (ID *id, bAction *act) // - NLA curve/stride modifiers... /* Convert NLA-Strip to new system */ -static void nlastrips_to_animdata (ID *id, ListBase *strips) +static void nlastrips_to_animdata(ID *id, ListBase *strips) { - AnimData *adt= BKE_animdata_from_id(id); + AnimData *adt = BKE_animdata_from_id(id); NlaTrack *nlt = NULL; NlaStrip *strip; bActionStrip *as, *asn; /* for each one of the original strips, convert to a new strip and free the old... */ - for (as= strips->first; as; as= asn) { - asn= as->next; + for (as = strips->first; as; as = asn) { + asn = as->next; /* this old strip is only worth something if it had an action... */ if (as->act) { @@ -1614,36 +1614,36 @@ static void nlastrips_to_animdata (ID *id, ListBase *strips) * - no need to muck around with the user-counts, since this is just * passing over the ref to the new owner, not creating an additional ref */ - strip= MEM_callocN(sizeof(NlaStrip), "NlaStrip"); - strip->act= as->act; - - /* endpoints */ - strip->start= as->start; - strip->end= as->end; - strip->actstart= as->actstart; - strip->actend= as->actend; - - /* action reuse */ - strip->repeat= as->repeat; - strip->scale= as->scale; - if (as->flag & ACTSTRIP_LOCK_ACTION) strip->flag |= NLASTRIP_FLAG_SYNC_LENGTH; + strip = MEM_callocN(sizeof(NlaStrip), "NlaStrip"); + strip->act = as->act; - /* blending */ - strip->blendin= as->blendin; - strip->blendout= as->blendout; - strip->blendmode= (as->mode==ACTSTRIPMODE_ADD) ? NLASTRIP_MODE_ADD : NLASTRIP_MODE_REPLACE; - if (as->flag & ACTSTRIP_AUTO_BLENDS) strip->flag |= NLASTRIP_FLAG_AUTO_BLENDS; - - /* assorted setting flags */ - if (as->flag & ACTSTRIP_SELECT) strip->flag |= NLASTRIP_FLAG_SELECT; - if (as->flag & ACTSTRIP_ACTIVE) strip->flag |= NLASTRIP_FLAG_ACTIVE; - - if (as->flag & ACTSTRIP_MUTE) strip->flag |= NLASTRIP_FLAG_MUTED; - if (as->flag & ACTSTRIP_REVERSE) strip->flag |= NLASTRIP_FLAG_REVERSE; - - /* by default, we now always extrapolate, while in the past this was optional */ - if ((as->flag & ACTSTRIP_HOLDLASTFRAME)==0) - strip->extendmode= NLASTRIP_EXTEND_NOTHING; + /* endpoints */ + strip->start = as->start; + strip->end = as->end; + strip->actstart = as->actstart; + strip->actend = as->actend; + + /* action reuse */ + strip->repeat = as->repeat; + strip->scale = as->scale; + if (as->flag & ACTSTRIP_LOCK_ACTION) strip->flag |= NLASTRIP_FLAG_SYNC_LENGTH; + + /* blending */ + strip->blendin = as->blendin; + strip->blendout = as->blendout; + strip->blendmode = (as->mode == ACTSTRIPMODE_ADD) ? NLASTRIP_MODE_ADD : NLASTRIP_MODE_REPLACE; + if (as->flag & ACTSTRIP_AUTO_BLENDS) strip->flag |= NLASTRIP_FLAG_AUTO_BLENDS; + + /* assorted setting flags */ + if (as->flag & ACTSTRIP_SELECT) strip->flag |= NLASTRIP_FLAG_SELECT; + if (as->flag & ACTSTRIP_ACTIVE) strip->flag |= NLASTRIP_FLAG_ACTIVE; + + if (as->flag & ACTSTRIP_MUTE) strip->flag |= NLASTRIP_FLAG_MUTED; + if (as->flag & ACTSTRIP_REVERSE) strip->flag |= NLASTRIP_FLAG_REVERSE; + + /* by default, we now always extrapolate, while in the past this was optional */ + if ((as->flag & ACTSTRIP_HOLDLASTFRAME) == 0) + strip->extendmode = NLASTRIP_EXTEND_NOTHING; } /* try to add this strip to the current NLA-Track (i.e. the 'last' one on the stack atm) */ @@ -1651,7 +1651,7 @@ static void nlastrips_to_animdata (ID *id, ListBase *strips) /* trying to add to the current failed (no space), * so add a new track to the stack, and add to that... */ - nlt= add_nlatrack(adt, NULL); + nlt = add_nlatrack(adt, NULL); BKE_nlatrack_add_strip(nlt, strip); } } @@ -1701,13 +1701,13 @@ void do_versions_ipos_to_animato(Main *main) /* ----------- Animation Attached to Data -------------- */ /* objects */ - for (id= main->object.first; id; id= id->next) { - Object *ob= (Object *)id; + for (id = main->object.first; id; id = id->next) { + Object *ob = (Object *)id; bPoseChannel *pchan; bConstraint *con; bConstraintChannel *conchan, *conchann; - if (G.debug & G_DEBUG) printf("\tconverting ob %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting ob %s\n", id->name + 2); /* check if object has any animation data */ if (ob->nlastrips.first) { @@ -1719,7 +1719,7 @@ void do_versions_ipos_to_animato(Main *main) ipo_to_animdata(id, ob->ipo, NULL, NULL, NULL); ob->ipo->id.us--; - ob->ipo= NULL; + ob->ipo = NULL; } /* Action is skipped since it'll be used by some strip in the NLA anyway, @@ -1727,7 +1727,7 @@ void do_versions_ipos_to_animato(Main *main) */ if (ob->action) { ob->action->id.us--; - ob->action= NULL; + ob->action = NULL; } /* finally NLA */ @@ -1735,7 +1735,7 @@ void do_versions_ipos_to_animato(Main *main) } else if ((ob->ipo) || (ob->action)) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Action first - so that Action name get conserved */ if (ob->action) { @@ -1744,7 +1744,7 @@ void do_versions_ipos_to_animato(Main *main) /* only decrease usercount if this Action isn't now being used by AnimData */ if (ob->action != adt->action) { ob->action->id.us--; - ob->action= NULL; + ob->action = NULL; } } @@ -1752,7 +1752,7 @@ void do_versions_ipos_to_animato(Main *main) if (ob->ipo) { ipo_to_animdata(id, ob->ipo, NULL, NULL, NULL); ob->ipo->id.us--; - ob->ipo= NULL; + ob->ipo = NULL; } } @@ -1761,8 +1761,8 @@ void do_versions_ipos_to_animato(Main *main) /* Verify if there's AnimData block */ BKE_id_add_animdata(id); - for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - for (con= pchan->constraints.first; con; con= con->next) { + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + for (con = pchan->constraints.first; con; con = con->next) { /* if constraint has own IPO, convert add these to Object * (NOTE: they're most likely to be drivers too) */ @@ -1772,14 +1772,14 @@ void do_versions_ipos_to_animato(Main *main) */ ipo_to_animdata(id, con->ipo, pchan->name, con->name, NULL); con->ipo->id.us--; - con->ipo= NULL; + con->ipo = NULL; } } } } /* check constraints for local IPO's */ - for (con= ob->constraints.first; con; con= con->next) { + for (con = ob->constraints.first; con; con = con->next) { /* if constraint has own IPO, convert add these to Object * (NOTE: they're most likely to be drivers too) */ @@ -1792,7 +1792,7 @@ void do_versions_ipos_to_animato(Main *main) */ ipo_to_animdata(id, con->ipo, NULL, con->name, NULL); con->ipo->id.us--; - con->ipo= NULL; + con->ipo = NULL; } /* check for Action Constraint */ @@ -1804,15 +1804,15 @@ void do_versions_ipos_to_animato(Main *main) /* Verify if there's AnimData block */ BKE_id_add_animdata(id); - for (conchan= ob->constraintChannels.first; conchan; conchan= conchann) { + for (conchan = ob->constraintChannels.first; conchan; conchan = conchann) { /* get pointer to next Constraint Channel */ - conchann= conchan->next; + conchann = conchan->next; /* convert Constraint Channel's IPO data */ if (conchan->ipo) { ipo_to_animdata(id, conchan->ipo, NULL, conchan->name, NULL); conchan->ipo->id.us--; - conchan->ipo= NULL; + conchan->ipo = NULL; } /* free Constraint Channel */ @@ -1822,17 +1822,17 @@ void do_versions_ipos_to_animato(Main *main) /* object's action will always be object-rooted */ { - AnimData *adt= BKE_animdata_from_id(id); + AnimData *adt = BKE_animdata_from_id(id); if (adt && adt->action) adt->action->idroot = ID_OB; } } /* shapekeys */ - for (id= main->key.first; id; id= id->next) { - Key *key= (Key *)id; + for (id = main->key.first; id; id = id->next) { + Key *key = (Key *)id; - if (G.debug & G_DEBUG) printf("\tconverting key %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting key %s\n", id->name + 2); /* we're only interested in the IPO * NOTE: for later, it might be good to port these over to Object instead, as many of these @@ -1840,7 +1840,7 @@ void do_versions_ipos_to_animato(Main *main) */ if (key->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert Shapekey data... */ ipo_to_animdata(id, key->ipo, NULL, NULL, NULL); @@ -1849,20 +1849,20 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = key->ipo->blocktype; key->ipo->id.us--; - key->ipo= NULL; + key->ipo = NULL; } } /* materials */ - for (id= main->mat.first; id; id= id->next) { - Material *ma= (Material *)id; + for (id = main->mat.first; id; id = id->next) { + Material *ma = (Material *)id; - if (G.debug & G_DEBUG) printf("\tconverting material %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting material %s\n", id->name + 2); /* we're only interested in the IPO */ if (ma->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert Material data... */ ipo_to_animdata(id, ma->ipo, NULL, NULL, NULL); @@ -1871,20 +1871,20 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = ma->ipo->blocktype; ma->ipo->id.us--; - ma->ipo= NULL; + ma->ipo = NULL; } } /* worlds */ - for (id= main->world.first; id; id= id->next) { - World *wo= (World *)id; + for (id = main->world.first; id; id = id->next) { + World *wo = (World *)id; - if (G.debug & G_DEBUG) printf("\tconverting world %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting world %s\n", id->name + 2); /* we're only interested in the IPO */ if (wo->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert World data... */ ipo_to_animdata(id, wo->ipo, NULL, NULL, NULL); @@ -1893,26 +1893,26 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = wo->ipo->blocktype; wo->ipo->id.us--; - wo->ipo= NULL; + wo->ipo = NULL; } } /* sequence strips */ - for (id= main->scene.first; id; id= id->next) { + for (id = main->scene.first; id; id = id->next) { Scene *scene = (Scene *)id; - Editing * ed = scene->ed; + Editing *ed = scene->ed; if (ed && ed->seqbasep) { - Sequence * seq; + Sequence *seq; - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); - SEQ_BEGIN (ed, seq) + SEQ_BEGIN(ed, seq) { IpoCurve *icu = (seq->ipo) ? seq->ipo->curve.first : NULL; short adrcode = SEQ_FAC1; if (G.debug & G_DEBUG) - printf("\tconverting sequence strip %s\n", seq->name+2); + printf("\tconverting sequence strip %s\n", seq->name + 2); if (ELEM(NULL, seq->ipo, icu)) { seq->flag |= SEQ_USE_EFFECT_DEFAULT_FADE; @@ -1941,7 +1941,7 @@ void do_versions_ipos_to_animato(Main *main) ipo_to_animdata((ID *)scene, seq->ipo, NULL, NULL, seq); if (adt->action) - adt->action->idroot = ID_SCE; /* scene-rooted */ + adt->action->idroot = ID_SCE; /* scene-rooted */ seq->ipo->id.us--; seq->ipo = NULL; @@ -1952,15 +1952,15 @@ void do_versions_ipos_to_animato(Main *main) /* textures */ - for (id= main->tex.first; id; id= id->next) { - Tex *te= (Tex *)id; + for (id = main->tex.first; id; id = id->next) { + Tex *te = (Tex *)id; - if (G.debug & G_DEBUG) printf("\tconverting texture %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting texture %s\n", id->name + 2); /* we're only interested in the IPO */ if (te->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert Texture data... */ ipo_to_animdata(id, te->ipo, NULL, NULL, NULL); @@ -1969,20 +1969,20 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = te->ipo->blocktype; te->ipo->id.us--; - te->ipo= NULL; + te->ipo = NULL; } } /* cameras */ - for (id= main->camera.first; id; id= id->next) { - Camera *ca= (Camera *)id; + for (id = main->camera.first; id; id = id->next) { + Camera *ca = (Camera *)id; - if (G.debug & G_DEBUG) printf("\tconverting camera %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting camera %s\n", id->name + 2); /* we're only interested in the IPO */ if (ca->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert Camera data... */ ipo_to_animdata(id, ca->ipo, NULL, NULL, NULL); @@ -1991,20 +1991,20 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = ca->ipo->blocktype; ca->ipo->id.us--; - ca->ipo= NULL; + ca->ipo = NULL; } } /* lamps */ - for (id= main->lamp.first; id; id= id->next) { - Lamp *la= (Lamp *)id; + for (id = main->lamp.first; id; id = id->next) { + Lamp *la = (Lamp *)id; - if (G.debug & G_DEBUG) printf("\tconverting lamp %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting lamp %s\n", id->name + 2); /* we're only interested in the IPO */ if (la->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert Lamp data... */ ipo_to_animdata(id, la->ipo, NULL, NULL, NULL); @@ -2013,20 +2013,20 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = la->ipo->blocktype; la->ipo->id.us--; - la->ipo= NULL; + la->ipo = NULL; } } /* curves */ - for (id= main->curve.first; id; id= id->next) { - Curve *cu= (Curve *)id; + for (id = main->curve.first; id; id = id->next) { + Curve *cu = (Curve *)id; - if (G.debug & G_DEBUG) printf("\tconverting curve %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting curve %s\n", id->name + 2); /* we're only interested in the IPO */ if (cu->ipo) { /* Add AnimData block */ - AnimData *adt= BKE_id_add_animdata(id); + AnimData *adt = BKE_id_add_animdata(id); /* Convert Curve data... */ ipo_to_animdata(id, cu->ipo, NULL, NULL, NULL); @@ -2035,7 +2035,7 @@ void do_versions_ipos_to_animato(Main *main) adt->action->idroot = cu->ipo->blocktype; cu->ipo->id.us--; - cu->ipo= NULL; + cu->ipo = NULL; } } @@ -2051,10 +2051,10 @@ void do_versions_ipos_to_animato(Main *main) */ /* actions */ - for (id= main->action.first; id; id= id->next) { - bAction *act= (bAction *)id; + for (id = main->action.first; id; id = id->next) { + bAction *act = (bAction *)id; - if (G.debug & G_DEBUG) printf("\tconverting action %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting action %s\n", id->name + 2); /* if old action, it will be object-only... */ if (act->chanbase.first) @@ -2065,23 +2065,23 @@ void do_versions_ipos_to_animato(Main *main) } /* ipo's */ - for (id= main->ipo.first; id; id= id->next) { - Ipo *ipo= (Ipo *)id; + for (id = main->ipo.first; id; id = id->next) { + Ipo *ipo = (Ipo *)id; - if (G.debug & G_DEBUG) printf("\tconverting ipo %s\n", id->name+2); + if (G.debug & G_DEBUG) printf("\tconverting ipo %s\n", id->name + 2); /* most likely this IPO has already been processed, so check if any curves left to convert */ if (ipo->curve.first) { bAction *new_act; /* add a new action for this, and convert all data into that action */ - new_act= add_empty_action("ConvIPO_Action"); // XXX need a better name... + new_act = add_empty_action("ConvIPO_Action"); // XXX need a better name... ipo_to_animato(NULL, ipo, NULL, NULL, NULL, NULL, &new_act->curves, &drivers); new_act->idroot = ipo->blocktype; } /* clear fake-users, and set user-count to zero to make sure it is cleared on file-save */ - ipo->id.us= 0; + ipo->id.us = 0; ipo->id.flag &= ~LIB_FAKEUSER; } diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c index e7206af3a0f..20e3edc7044 100644 --- a/source/blender/blenkernel/intern/lamp.c +++ b/source/blender/blenkernel/intern/lamp.c @@ -55,30 +55,30 @@ void *BKE_lamp_add(const char *name) { Lamp *la; - la= BKE_libblock_alloc(&G.main->lamp, ID_LA, name); - - la->r= la->g= la->b= la->k= 1.0f; - la->haint= la->energy= 1.0f; - la->dist= 25.0f; - la->spotsize= 45.0f; - la->spotblend= 0.15f; - la->att2= 1.0f; - la->mode= LA_SHAD_BUF; - la->bufsize= 512; - la->clipsta= 0.5f; - la->clipend= 40.0f; - la->shadspotsize= 45.0f; - la->samp= 3; - la->bias= 1.0f; - la->soft= 3.0f; - la->compressthresh= 0.05f; - la->ray_samp= la->ray_sampy= la->ray_sampz= 1; - la->area_size=la->area_sizey=la->area_sizez= 1.0f; - la->buffers= 1; - la->buftype= LA_SHADBUF_HALFWAY; + la = BKE_libblock_alloc(&G.main->lamp, ID_LA, name); + + la->r = la->g = la->b = la->k = 1.0f; + la->haint = la->energy = 1.0f; + la->dist = 25.0f; + la->spotsize = 45.0f; + la->spotblend = 0.15f; + la->att2 = 1.0f; + la->mode = LA_SHAD_BUF; + la->bufsize = 512; + la->clipsta = 0.5f; + la->clipend = 40.0f; + la->shadspotsize = 45.0f; + la->samp = 3; + la->bias = 1.0f; + la->soft = 3.0f; + la->compressthresh = 0.05f; + la->ray_samp = la->ray_sampy = la->ray_sampz = 1; + la->area_size = la->area_sizey = la->area_sizez = 1.0f; + la->buffers = 1; + la->buftype = LA_SHADBUF_HALFWAY; la->ray_samp_method = LA_SAMP_HALTON; la->adapt_thresh = 0.001f; - la->preview=NULL; + la->preview = NULL; la->falloff_type = LA_FALLOFF_INVSQUARE; la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f); la->sun_effect_type = 0; @@ -92,11 +92,11 @@ void *BKE_lamp_add(const char *name) la->atm_extinction_factor = 1.0f; la->atm_distance_factor = 1.0f; la->sun_intensity = 1.0f; - la->skyblendtype= MA_RAMP_ADD; - la->skyblendfac= 1.0f; - la->sky_colorspace= BLI_XYZ_CIE; - la->sky_exposure= 1.0f; - la->shadow_frustum_size= 10.0f; + la->skyblendtype = MA_RAMP_ADD; + la->skyblendfac = 1.0f; + la->sky_colorspace = BLI_XYZ_CIE; + la->sky_exposure = 1.0f; + la->shadow_frustum_size = 10.0f; curvemapping_initialize(la->curfalloff); return la; @@ -107,11 +107,11 @@ Lamp *BKE_lamp_copy(Lamp *la) Lamp *lan; int a; - lan= BKE_libblock_copy(&la->id); + lan = BKE_libblock_copy(&la->id); - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (lan->mtex[a]) { - lan->mtex[a]= MEM_mallocN(sizeof(MTex), "copylamptex"); + lan->mtex[a] = MEM_mallocN(sizeof(MTex), "copylamptex"); memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex)); id_us_plus((ID *)lan->mtex[a]->tex); } @@ -120,7 +120,7 @@ Lamp *BKE_lamp_copy(Lamp *la) lan->curfalloff = curvemapping_copy(la->curfalloff); if (la->nodetree) - lan->nodetree= ntreeCopyTree(la->nodetree); + lan->nodetree = ntreeCopyTree(la->nodetree); if (la->preview) lan->preview = BKE_previewimg_copy(la->preview); @@ -133,12 +133,12 @@ Lamp *localize_lamp(Lamp *la) Lamp *lan; int a; - lan= BKE_libblock_copy(&la->id); + lan = BKE_libblock_copy(&la->id); BLI_remlink(&G.main->lamp, lan); - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (lan->mtex[a]) { - lan->mtex[a]= MEM_mallocN(sizeof(MTex), "localize_lamp"); + lan->mtex[a] = MEM_mallocN(sizeof(MTex), "localize_lamp"); memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex)); /* free lamp decrements */ id_us_plus((ID *)lan->mtex[a]->tex); @@ -148,60 +148,60 @@ Lamp *localize_lamp(Lamp *la) lan->curfalloff = curvemapping_copy(la->curfalloff); if (la->nodetree) - lan->nodetree= ntreeLocalize(la->nodetree); + lan->nodetree = ntreeLocalize(la->nodetree); - lan->preview= NULL; + lan->preview = NULL; return lan; } void BKE_lamp_make_local(Lamp *la) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (la->id.lib==NULL) return; - if (la->id.us==1) { + if (la->id.lib == NULL) return; + if (la->id.us == 1) { id_clear_lib_data(bmain, &la->id); return; } - ob= bmain->object.first; + ob = bmain->object.first; while (ob) { - if (ob->data==la) { - if (ob->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (ob->data == la) { + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } - ob= ob->id.next; + ob = ob->id.next; } if (is_local && is_lib == FALSE) { id_clear_lib_data(bmain, &la->id); } else if (is_local && is_lib) { - Lamp *la_new= BKE_lamp_copy(la); - la_new->id.us= 0; + Lamp *la_new = BKE_lamp_copy(la); + la_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, la->id.lib, &la_new->id); - ob= bmain->object.first; + ob = bmain->object.first; while (ob) { - if (ob->data==la) { + if (ob->data == la) { - if (ob->id.lib==NULL) { - ob->data= la_new; + if (ob->id.lib == NULL) { + ob->data = la_new; la_new->id.us++; la->id.us--; } } - ob= ob->id.next; + ob = ob->id.next; } } } @@ -211,8 +211,8 @@ void BKE_lamp_free(Lamp *la) MTex *mtex; int a; - for (a=0; a<MAX_MTEX; a++) { - mtex= la->mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = la->mtex[a]; if (mtex && mtex->tex) mtex->tex->id.us--; if (mtex) MEM_freeN(mtex); } diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 12496e78037..4076031fa18 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -69,17 +69,17 @@ void calc_lat_fudu(int flag, int res, float *fu, float *du) { - if (res==1) { - *fu= 0.0; - *du= 0.0; + if (res == 1) { + *fu = 0.0; + *du = 0.0; } else if (flag & LT_GRID) { - *fu= -0.5f*(res-1); - *du= 1.0f; + *fu = -0.5f * (res - 1); + *du = 1.0f; } else { - *fu= -1.0f; - *du= 2.0f/(res-1); + *fu = -1.0f; + *du = 2.0f / (res - 1); } } @@ -87,53 +87,53 @@ void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb) { BPoint *bp; int i, u, v, w; - float fu, fv, fw, uc, vc, wc, du=0.0, dv=0.0, dw=0.0; + float fu, fv, fw, uc, vc, wc, du = 0.0, dv = 0.0, dw = 0.0; float *co, (*vertexCos)[3] = NULL; /* vertex weight groups are just freed all for now */ if (lt->dvert) { - free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw); - lt->dvert= NULL; + free_dverts(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw); + lt->dvert = NULL; } - while (uNew*vNew*wNew > 32000) { - if ( uNew>=vNew && uNew>=wNew) uNew--; - else if ( vNew>=uNew && vNew>=wNew) vNew--; + while (uNew * vNew * wNew > 32000) { + if (uNew >= vNew && uNew >= wNew) uNew--; + else if (vNew >= uNew && vNew >= wNew) vNew--; else wNew--; } - vertexCos = MEM_mallocN(sizeof(*vertexCos)*uNew*vNew*wNew, "tmp_vcos"); + vertexCos = MEM_mallocN(sizeof(*vertexCos) * uNew * vNew * wNew, "tmp_vcos"); calc_lat_fudu(lt->flag, uNew, &fu, &du); calc_lat_fudu(lt->flag, vNew, &fv, &dv); calc_lat_fudu(lt->flag, wNew, &fw, &dw); - /* If old size is different then resolution changed in interface, - * try to do clever reinit of points. Pretty simply idea, we just - * deform new verts by old lattice, but scaling them to match old - * size first. - */ + /* If old size is different then resolution changed in interface, + * try to do clever reinit of points. Pretty simply idea, we just + * deform new verts by old lattice, but scaling them to match old + * size first. + */ if (ltOb) { - if (uNew!=1 && lt->pntsu!=1) { + if (uNew != 1 && lt->pntsu != 1) { fu = lt->fu; - du = (lt->pntsu-1)*lt->du/(uNew-1); + du = (lt->pntsu - 1) * lt->du / (uNew - 1); } - if (vNew!=1 && lt->pntsv!=1) { + if (vNew != 1 && lt->pntsv != 1) { fv = lt->fv; - dv = (lt->pntsv-1)*lt->dv/(vNew-1); + dv = (lt->pntsv - 1) * lt->dv / (vNew - 1); } - if (wNew!=1 && lt->pntsw!=1) { + if (wNew != 1 && lt->pntsw != 1) { fw = lt->fw; - dw = (lt->pntsw-1)*lt->dw/(wNew-1); + dw = (lt->pntsw - 1) * lt->dw / (wNew - 1); } } co = vertexCos[0]; - for (w=0, wc=fw; w<wNew; w++, wc+=dw) { - for (v=0, vc=fv; v<vNew; v++, vc+=dv) { - for (u=0, uc=fu; u<uNew; u++, co+=3, uc+=du) { + for (w = 0, wc = fw; w < wNew; w++, wc += dw) { + for (v = 0, vc = fv; v < vNew; v++, vc += dv) { + for (u = 0, uc = fu; u < uNew; u++, co += 3, uc += du) { co[0] = uc; co[1] = vc; co[2] = wc; @@ -145,15 +145,15 @@ void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb) float mat[4][4]; int typeu = lt->typeu, typev = lt->typev, typew = lt->typew; - /* works best if we force to linear type (endpoints match) */ + /* works best if we force to linear type (endpoints match) */ lt->typeu = lt->typev = lt->typew = KEY_LINEAR; - /* prevent using deformed locations */ + /* prevent using deformed locations */ freedisplist(<Ob->disp); copy_m4_m4(mat, ltOb->obmat); unit_m4(ltOb->obmat); - lattice_deform_verts(ltOb, NULL, NULL, vertexCos, uNew*vNew*wNew, NULL, 1.0f); + lattice_deform_verts(ltOb, NULL, NULL, vertexCos, uNew * vNew * wNew, NULL, 1.0f); copy_m4_m4(ltOb->obmat, mat); lt->typeu = typeu; @@ -173,11 +173,11 @@ void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb) lt->pntsw = wNew; MEM_freeN(lt->def); - lt->def= MEM_callocN(lt->pntsu*lt->pntsv*lt->pntsw*sizeof(BPoint), "lattice bp"); + lt->def = MEM_callocN(lt->pntsu * lt->pntsv * lt->pntsw * sizeof(BPoint), "lattice bp"); - bp= lt->def; + bp = lt->def; - for (i=0; i<lt->pntsu*lt->pntsv*lt->pntsw; i++, bp++) { + for (i = 0; i < lt->pntsu * lt->pntsv * lt->pntsw; i++, bp++) { copy_v3_v3(bp->vec, vertexCos[i]); } @@ -188,14 +188,14 @@ Lattice *BKE_lattice_add(const char *name) { Lattice *lt; - lt= BKE_libblock_alloc(&G.main->latt, ID_LT, name); + lt = BKE_libblock_alloc(&G.main->latt, ID_LT, name); - lt->flag= LT_GRID; + lt->flag = LT_GRID; - lt->typeu= lt->typev= lt->typew= KEY_BSPLINE; + lt->typeu = lt->typev = lt->typew = KEY_BSPLINE; - lt->def= MEM_callocN(sizeof(BPoint), "lattvert"); /* temporary */ - BKE_lattice_resize(lt, 2, 2, 2, NULL); /* creates a uniform lattice */ + lt->def = MEM_callocN(sizeof(BPoint), "lattvert"); /* temporary */ + BKE_lattice_resize(lt, 2, 2, 2, NULL); /* creates a uniform lattice */ return lt; } @@ -204,19 +204,19 @@ Lattice *BKE_lattice_copy(Lattice *lt) { Lattice *ltn; - ltn= BKE_libblock_copy(<->id); - ltn->def= MEM_dupallocN(lt->def); + ltn = BKE_libblock_copy(<->id); + ltn->def = MEM_dupallocN(lt->def); - ltn->key= BKE_key_copy(ltn->key); - if (ltn->key) ltn->key->from= (ID *)ltn; + ltn->key = BKE_key_copy(ltn->key); + if (ltn->key) ltn->key->from = (ID *)ltn; if (lt->dvert) { - int tot= lt->pntsu*lt->pntsv*lt->pntsw; - ltn->dvert = MEM_mallocN (sizeof (MDeformVert)*tot, "Lattice MDeformVert"); + int tot = lt->pntsu * lt->pntsv * lt->pntsw; + ltn->dvert = MEM_mallocN(sizeof (MDeformVert) * tot, "Lattice MDeformVert"); copy_dverts(ltn->dvert, lt->dvert, tot); } - ltn->editlatt= NULL; + ltn->editlatt = NULL; return ltn; } @@ -224,12 +224,12 @@ Lattice *BKE_lattice_copy(Lattice *lt) void BKE_lattice_free(Lattice *lt) { if (lt->def) MEM_freeN(lt->def); - if (lt->dvert) free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw); + if (lt->dvert) free_dverts(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw); if (lt->editlatt) { - Lattice *editlt= lt->editlatt->latt; + Lattice *editlt = lt->editlatt->latt; if (editlt->def) MEM_freeN(editlt->def); - if (editlt->dvert) free_dverts(editlt->dvert, lt->pntsu*lt->pntsv*lt->pntsw); + if (editlt->dvert) free_dverts(editlt->dvert, lt->pntsu * lt->pntsv * lt->pntsw); MEM_freeN(editlt); MEM_freeN(lt->editlatt); @@ -238,49 +238,49 @@ void BKE_lattice_free(Lattice *lt) /* free animation data */ if (lt->adt) { BKE_free_animdata(<->id); - lt->adt= NULL; + lt->adt = NULL; } } void BKE_lattice_make_local(Lattice *lt) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (lt->id.lib==NULL) return; - if (lt->id.us==1) { + if (lt->id.lib == NULL) return; + if (lt->id.us == 1) { id_clear_lib_data(bmain, <->id); return; } - for (ob= bmain->object.first; ob && ELEM(FALSE, is_lib, is_local); ob= ob->id.next) { - if (ob->data==lt) { - if (ob->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (ob = bmain->object.first; ob && ELEM(FALSE, is_lib, is_local); ob = ob->id.next) { + if (ob->data == lt) { + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - if (is_local && is_lib==FALSE) { + if (is_local && is_lib == FALSE) { id_clear_lib_data(bmain, <->id); } else if (is_local && is_lib) { - Lattice *lt_new= BKE_lattice_copy(lt); - lt_new->id.us= 0; + Lattice *lt_new = BKE_lattice_copy(lt); + lt_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, lt->id.lib, <_new->id); - for (ob= bmain->object.first; ob; ob= ob->id.next) { - if (ob->data==lt) { - if (ob->id.lib==NULL) { - ob->data= lt_new; + for (ob = bmain->object.first; ob; ob = ob->id.next) { + if (ob->data == lt) { + if (ob->id.lib == NULL) { + ob->data = lt_new; lt_new->id.us++; lt->id.us--; } @@ -291,22 +291,22 @@ void BKE_lattice_make_local(Lattice *lt) void init_latt_deform(Object *oblatt, Object *ob) { - /* we make an array with all differences */ - Lattice *lt= oblatt->data; + /* we make an array with all differences */ + Lattice *lt = oblatt->data; BPoint *bp; DispList *dl = find_displist(&oblatt->disp, DL_VERTS); - float *co = dl?dl->verts:NULL; + float *co = dl ? dl->verts : NULL; float *fp, imat[4][4]; float fu, fv, fw; int u, v, w; - if (lt->editlatt) lt= lt->editlatt->latt; + if (lt->editlatt) lt = lt->editlatt->latt; bp = lt->def; - fp= lt->latticedata= MEM_mallocN(sizeof(float)*3*lt->pntsu*lt->pntsv*lt->pntsw, "latticedata"); + fp = lt->latticedata = MEM_mallocN(sizeof(float) * 3 * lt->pntsu * lt->pntsv * lt->pntsw, "latticedata"); - /* for example with a particle system: ob==0 */ - if (ob==NULL) { + /* for example with a particle system: ob==0 */ + if (ob == NULL) { /* in deformspace, calc matrix */ invert_m4_m4(lt->latmat, oblatt->obmat); @@ -322,9 +322,9 @@ void init_latt_deform(Object *oblatt, Object *ob) invert_m4_m4(imat, lt->latmat); } - for (w=0, fw=lt->fw; w<lt->pntsw; w++, fw+=lt->dw) { - for (v=0, fv=lt->fv; v<lt->pntsv; v++, fv+=lt->dv) { - for (u=0, fu=lt->fu; u<lt->pntsu; u++, bp++, co+=3, fp+=3, fu+=lt->du) { + for (w = 0, fw = lt->fw; w < lt->pntsw; w++, fw += lt->dw) { + for (v = 0, fv = lt->fv; v < lt->pntsv; v++, fv += lt->dv) { + for (u = 0, fu = lt->fu; u < lt->pntsu; u++, bp++, co += 3, fp += 3, fu += lt->du) { if (dl) { fp[0] = co[0] - fu; fp[1] = co[1] - fv; @@ -344,23 +344,23 @@ void init_latt_deform(Object *oblatt, Object *ob) void calc_latt_deform(Object *ob, float co[3], float weight) { - Lattice *lt= ob->data; + Lattice *lt = ob->data; float u, v, w, tu[4], tv[4], tw[4]; float vec[3]; int idx_w, idx_v, idx_u; int ui, vi, wi, uu, vv, ww; /* vgroup influence */ - int defgroup_nr= -1; - float co_prev[3], weight_blend= 0.0f; - MDeformVert *dvert= BKE_lattice_deform_verts_get(ob); + int defgroup_nr = -1; + float co_prev[3], weight_blend = 0.0f; + MDeformVert *dvert = BKE_lattice_deform_verts_get(ob); - if (lt->editlatt) lt= lt->editlatt->latt; - if (lt->latticedata==NULL) return; + if (lt->editlatt) lt = lt->editlatt->latt; + if (lt->latticedata == NULL) return; if (lt->vgroup[0] && dvert) { - defgroup_nr= defgroup_name_index(ob, lt->vgroup); + defgroup_nr = defgroup_name_index(ob, lt->vgroup); copy_v3_v3(co_prev, co); } @@ -369,68 +369,68 @@ void calc_latt_deform(Object *ob, float co[3], float weight) /* u v w coords */ - if (lt->pntsu>1) { - u= (vec[0]-lt->fu)/lt->du; - ui= (int)floor(u); + if (lt->pntsu > 1) { + u = (vec[0] - lt->fu) / lt->du; + ui = (int)floor(u); u -= ui; key_curve_position_weights(u, tu, lt->typeu); } else { - tu[0]= tu[2]= tu[3]= 0.0; tu[1]= 1.0; - ui= 0; + tu[0] = tu[2] = tu[3] = 0.0; tu[1] = 1.0; + ui = 0; } - if (lt->pntsv>1) { - v= (vec[1]-lt->fv)/lt->dv; - vi= (int)floor(v); + if (lt->pntsv > 1) { + v = (vec[1] - lt->fv) / lt->dv; + vi = (int)floor(v); v -= vi; key_curve_position_weights(v, tv, lt->typev); } else { - tv[0]= tv[2]= tv[3]= 0.0; tv[1]= 1.0; - vi= 0; + tv[0] = tv[2] = tv[3] = 0.0; tv[1] = 1.0; + vi = 0; } - if (lt->pntsw>1) { - w= (vec[2]-lt->fw)/lt->dw; - wi= (int)floor(w); + if (lt->pntsw > 1) { + w = (vec[2] - lt->fw) / lt->dw; + wi = (int)floor(w); w -= wi; key_curve_position_weights(w, tw, lt->typew); } else { - tw[0]= tw[2]= tw[3]= 0.0; tw[1]= 1.0; - wi= 0; + tw[0] = tw[2] = tw[3] = 0.0; tw[1] = 1.0; + wi = 0; } - for (ww= wi-1; ww<=wi+2; ww++) { - w= tw[ww-wi+1]; + for (ww = wi - 1; ww <= wi + 2; ww++) { + w = tw[ww - wi + 1]; if (w != 0.0f) { - if (ww>0) { - if (ww<lt->pntsw) idx_w= ww*lt->pntsu*lt->pntsv; - else idx_w= (lt->pntsw-1)*lt->pntsu*lt->pntsv; + if (ww > 0) { + if (ww < lt->pntsw) idx_w = ww * lt->pntsu * lt->pntsv; + else idx_w = (lt->pntsw - 1) * lt->pntsu * lt->pntsv; } - else idx_w= 0; + else idx_w = 0; - for (vv= vi-1; vv<=vi+2; vv++) { - v= w*tv[vv-vi+1]; + for (vv = vi - 1; vv <= vi + 2; vv++) { + v = w * tv[vv - vi + 1]; if (v != 0.0f) { - if (vv>0) { - if (vv<lt->pntsv) idx_v= idx_w + vv*lt->pntsu; - else idx_v= idx_w + (lt->pntsv-1)*lt->pntsu; + if (vv > 0) { + if (vv < lt->pntsv) idx_v = idx_w + vv * lt->pntsu; + else idx_v = idx_w + (lt->pntsv - 1) * lt->pntsu; } - else idx_v= idx_w; + else idx_v = idx_w; - for (uu= ui-1; uu<=ui+2; uu++) { - u= weight*v*tu[uu-ui+1]; + for (uu = ui - 1; uu <= ui + 2; uu++) { + u = weight * v * tu[uu - ui + 1]; if (u != 0.0f) { - if (uu>0) { - if (uu<lt->pntsu) idx_u= idx_v + uu; - else idx_u= idx_v + (lt->pntsu-1); + if (uu > 0) { + if (uu < lt->pntsu) idx_u = idx_v + uu; + else idx_u = idx_v + (lt->pntsu - 1); } - else idx_u= idx_v; + else idx_u = idx_v; madd_v3_v3fl(co, <->latticedata[idx_u * 3], u); @@ -450,18 +450,18 @@ void calc_latt_deform(Object *ob, float co[3], float weight) void end_latt_deform(Object *ob) { - Lattice *lt= ob->data; + Lattice *lt = ob->data; - if (lt->editlatt) lt= lt->editlatt->latt; + if (lt->editlatt) lt = lt->editlatt->latt; if (lt->latticedata) MEM_freeN(lt->latticedata); - lt->latticedata= NULL; + lt->latticedata = NULL; } - /* calculations is in local space of deformed object - * so we store in latmat transform from path coord inside object - */ +/* calculations is in local space of deformed object + * so we store in latmat transform from path coord inside object + */ typedef struct { float dmin[3], dmax[3]; float curvespace[4][4], objectspace[4][4], objectspace3[3][3]; @@ -474,7 +474,7 @@ static void init_curve_deform(Object *par, Object *ob, CurveDeform *cd) mult_m4_m4m4(cd->objectspace, ob->imat, par->obmat); invert_m4_m4(cd->curvespace, cd->objectspace); copy_m3_m4(cd->objectspace3, cd->objectspace); - cd->no_rot_axis= 0; + cd->no_rot_axis = 0; } /* this makes sure we can extend for non-cyclic. @@ -483,41 +483,41 @@ static void init_curve_deform(Object *par, Object *ob, CurveDeform *cd) */ static int where_on_path_deform(Object *ob, float ctime, float vec[4], float dir[3], float quat[4], float *radius) { - Curve *cu= ob->data; + Curve *cu = ob->data; BevList *bl; float ctime1; - int cycl=0; + int cycl = 0; /* test for cyclic */ - bl= cu->bev.first; + bl = cu->bev.first; if (!bl->nr) return 0; - if (bl && bl->poly> -1) cycl= 1; + if (bl && bl->poly > -1) cycl = 1; - if (cycl==0) { - ctime1= CLAMPIS(ctime, 0.0f, 1.0f); + if (cycl == 0) { + ctime1 = CLAMPIS(ctime, 0.0f, 1.0f); } - else ctime1= ctime; + else ctime1 = ctime; /* vec needs 4 items */ if (where_on_path(ob, ctime1, vec, dir, quat, radius, NULL)) { - if (cycl==0) { - Path *path= cu->path; + if (cycl == 0) { + Path *path = cu->path; float dvec[3]; if (ctime < 0.0f) { sub_v3_v3v3(dvec, path->data[1].vec, path->data[0].vec); - mul_v3_fl(dvec, ctime*(float)path->len); + mul_v3_fl(dvec, ctime * (float)path->len); add_v3_v3(vec, dvec); if (quat) copy_qt_qt(quat, path->data[0].quat); - if (radius) *radius= path->data[0].radius; + if (radius) *radius = path->data[0].radius; } else if (ctime > 1.0f) { - sub_v3_v3v3(dvec, path->data[path->len-1].vec, path->data[path->len-2].vec); - mul_v3_fl(dvec, (ctime-1.0f)*(float)path->len); + sub_v3_v3v3(dvec, path->data[path->len - 1].vec, path->data[path->len - 2].vec); + mul_v3_fl(dvec, (ctime - 1.0f) * (float)path->len); add_v3_v3(vec, dvec); - if (quat) copy_qt_qt(quat, path->data[path->len-1].quat); - if (radius) *radius= path->data[path->len-1].radius; + if (quat) copy_qt_qt(quat, path->data[path->len - 1].quat); + if (radius) *radius = path->data[path->len - 1].radius; /* weight - not used but could be added */ } } @@ -534,43 +534,43 @@ static int where_on_path_deform(Object *ob, float ctime, float vec[4], float dir static int calc_curve_deform(Scene *scene, Object *par, float co[3], const short axis, CurveDeform *cd, float quat_r[4]) { - Curve *cu= par->data; + Curve *cu = par->data; float fac, loc[4], dir[3], new_quat[4], radius; short index; const int is_neg_axis = (axis > 2); /* to be sure, mostly after file load */ - if (cu->path==NULL) { + if (cu->path == NULL) { makeDispListCurveTypes(scene, par, 0); - if (cu->path==NULL) return 0; // happens on append... + if (cu->path == NULL) return 0; // happens on append... } /* options */ if (is_neg_axis) { index = axis - 3; if (cu->flag & CU_STRETCH) - fac= (-co[index]-cd->dmax[index])/(cd->dmax[index] - cd->dmin[index]); + fac = (-co[index] - cd->dmax[index]) / (cd->dmax[index] - cd->dmin[index]); else - fac= - (co[index]-cd->dmax[index])/(cu->path->totdist); + fac = -(co[index] - cd->dmax[index]) / (cu->path->totdist); } else { index = axis; if (cu->flag & CU_STRETCH) - fac= (co[index]-cd->dmin[index])/(cd->dmax[index] - cd->dmin[index]); + fac = (co[index] - cd->dmin[index]) / (cd->dmax[index] - cd->dmin[index]); else - fac= + (co[index]-cd->dmin[index])/(cu->path->totdist); + fac = +(co[index] - cd->dmin[index]) / (cu->path->totdist); } - if ( where_on_path_deform(par, fac, loc, dir, new_quat, &radius)) { /* returns OK */ + if (where_on_path_deform(par, fac, loc, dir, new_quat, &radius)) { /* returns OK */ float quat[4], cent[3]; - if (cd->no_rot_axis) { /* set by caller */ + if (cd->no_rot_axis) { /* set by caller */ /* this is not exactly the same as 2.4x, since the axis is having rotation removed rather than * changing the axis before calculating the tilt but serves much the same purpose */ - float dir_flat[3]={0, 0, 0}, q[4]; + float dir_flat[3] = {0, 0, 0}, q[4]; copy_v3_v3(dir_flat, dir); - dir_flat[cd->no_rot_axis-1]= 0.0f; + dir_flat[cd->no_rot_axis - 1] = 0.0f; normalize_v3(dir); normalize_v3(dir_flat); @@ -598,9 +598,9 @@ static int calc_curve_deform(Scene *scene, Object *par, float co[3], /* zero the axis which is not used, * the big block of text above now applies to these 3 lines */ - quat_apply_track(quat, axis, (axis == 0 || axis == 2) ? 1:0); /* up flag is a dummy, set so no rotation is done */ + quat_apply_track(quat, axis, (axis == 0 || axis == 2) ? 1 : 0); /* up flag is a dummy, set so no rotation is done */ vec_apply_track(cent, axis); - cent[index]= 0.0f; + cent[index] = 0.0f; /* scale if enabled */ @@ -637,26 +637,26 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, cu = cuOb->data; flag = cu->flag; - cu->flag |= (CU_PATH|CU_FOLLOW); // needed for path & bevlist + cu->flag |= (CU_PATH | CU_FOLLOW); // needed for path & bevlist init_curve_deform(cuOb, target, &cd); /* dummy bounds, keep if CU_DEFORM_BOUNDS_OFF is set */ if (is_neg_axis == FALSE) { - cd.dmin[0]= cd.dmin[1]= cd.dmin[2]= 0.0f; - cd.dmax[0]= cd.dmax[1]= cd.dmax[2]= 1.0f; + cd.dmin[0] = cd.dmin[1] = cd.dmin[2] = 0.0f; + cd.dmax[0] = cd.dmax[1] = cd.dmax[2] = 1.0f; } else { /* negative, these bounds give a good rest position */ - cd.dmin[0]= cd.dmin[1]= cd.dmin[2]= -1.0f; - cd.dmax[0]= cd.dmax[1]= cd.dmax[2]= 0.0f; + cd.dmin[0] = cd.dmin[1] = cd.dmin[2] = -1.0f; + cd.dmax[0] = cd.dmax[1] = cd.dmax[2] = 0.0f; } /* check whether to use vertex groups (only possible if target is a Mesh) * we want either a Mesh with no derived data, or derived data with * deformverts */ - if (target && target->type==OB_MESH) { + if (target && target->type == OB_MESH) { /* if there's derived data without deformverts, don't use vgroups */ if (dm && !dm->getVertData(dm, 0, CD_MDEFORMVERT)) use_vgroups = 0; @@ -668,8 +668,8 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, } if (vgroup && vgroup[0] && use_vgroups) { - Mesh *me= target->data; - int index= defgroup_name_index(target, vgroup); + Mesh *me = target->data; + int index = defgroup_name_index(target, vgroup); if (index != -1 && (me->dvert || dm)) { MDeformVert *dvert = me->dvert; @@ -681,7 +681,7 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, dvert = me->dvert; for (a = 0; a < numVerts; a++, dvert++) { if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT); - weight= defvert_find_weight(dvert, index); + weight = defvert_find_weight(dvert, index); if (weight > 0.0f) { mul_m4_v3(cd.curvespace, vertexCos[a]); @@ -709,7 +709,7 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, for (a = 0; a < numVerts; a++, dvert++) { if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT); - weight= defvert_find_weight(dvert, index); + weight = defvert_find_weight(dvert, index); if (weight > 0.0f) { /* already in 'cd.curvespace', prev for loop */ @@ -764,7 +764,7 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target, } init_curve_deform(cuOb, target, &cd); - cd.no_rot_axis= no_rot_axis; /* option to only rotate for XY, for example */ + cd.no_rot_axis = no_rot_axis; /* option to only rotate for XY, for example */ copy_v3_v3(cd.dmin, orco); copy_v3_v3(cd.dmax, orco); @@ -799,7 +799,7 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm, * we want either a Mesh with no derived data, or derived data with * deformverts */ - if (target && target->type==OB_MESH) { + if (target && target->type == OB_MESH) { /* if there's derived data without deformverts, don't use vgroups */ if (dm && !dm->getVertData(dm, 0, CD_MDEFORMVERT)) use_vgroups = 0; @@ -821,7 +821,7 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm, for (a = 0; a < numVerts; a++, dvert++) { if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT); - weight= defvert_find_weight(dvert, index); + weight = defvert_find_weight(dvert, index); if (weight > 0.0f) calc_latt_deform(laOb, vertexCos[a], weight * fac); @@ -838,12 +838,12 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm, int object_deform_mball(Object *ob, ListBase *dispbase) { - if (ob->parent && ob->parent->type==OB_LATTICE && ob->partype==PARSKEL) { + if (ob->parent && ob->parent->type == OB_LATTICE && ob->partype == PARSKEL) { DispList *dl; - for (dl=dispbase->first; dl; dl=dl->next) { + for (dl = dispbase->first; dl; dl = dl->next) { lattice_deform_verts(ob->parent, ob, NULL, - (float(*)[3]) dl->verts, dl->nr, NULL, 1.0f); + (float(*)[3])dl->verts, dl->nr, NULL, 1.0f); } return 1; @@ -862,52 +862,52 @@ void outside_lattice(Lattice *lt) { BPoint *bp, *bp1, *bp2; int u, v, w; - float fac1, du=0.0, dv=0.0, dw=0.0; + float fac1, du = 0.0, dv = 0.0, dw = 0.0; if (lt->flag & LT_OUTSIDE) { - bp= lt->def; + bp = lt->def; - if (lt->pntsu>1) du= 1.0f/((float)lt->pntsu-1); - if (lt->pntsv>1) dv= 1.0f/((float)lt->pntsv-1); - if (lt->pntsw>1) dw= 1.0f/((float)lt->pntsw-1); + if (lt->pntsu > 1) du = 1.0f / ((float)lt->pntsu - 1); + if (lt->pntsv > 1) dv = 1.0f / ((float)lt->pntsv - 1); + if (lt->pntsw > 1) dw = 1.0f / ((float)lt->pntsw - 1); - for (w=0; w<lt->pntsw; w++) { + for (w = 0; w < lt->pntsw; w++) { - for (v=0; v<lt->pntsv; v++) { + for (v = 0; v < lt->pntsv; v++) { - for (u=0; u<lt->pntsu; u++, bp++) { - if (u==0 || v==0 || w==0 || u==lt->pntsu-1 || v==lt->pntsv-1 || w==lt->pntsw-1); + for (u = 0; u < lt->pntsu; u++, bp++) { + if (u == 0 || v == 0 || w == 0 || u == lt->pntsu - 1 || v == lt->pntsv - 1 || w == lt->pntsw - 1) ; else { - bp->hide= 1; + bp->hide = 1; bp->f1 &= ~SELECT; /* u extrema */ - bp1= latt_bp(lt, 0, v, w); - bp2= latt_bp(lt, lt->pntsu-1, v, w); + bp1 = latt_bp(lt, 0, v, w); + bp2 = latt_bp(lt, lt->pntsu - 1, v, w); - fac1= du*u; - bp->vec[0]= (1.0f-fac1)*bp1->vec[0] + fac1*bp2->vec[0]; - bp->vec[1]= (1.0f-fac1)*bp1->vec[1] + fac1*bp2->vec[1]; - bp->vec[2]= (1.0f-fac1)*bp1->vec[2] + fac1*bp2->vec[2]; + fac1 = du * u; + bp->vec[0] = (1.0f - fac1) * bp1->vec[0] + fac1 * bp2->vec[0]; + bp->vec[1] = (1.0f - fac1) * bp1->vec[1] + fac1 * bp2->vec[1]; + bp->vec[2] = (1.0f - fac1) * bp1->vec[2] + fac1 * bp2->vec[2]; /* v extrema */ - bp1= latt_bp(lt, u, 0, w); - bp2= latt_bp(lt, u, lt->pntsv-1, w); + bp1 = latt_bp(lt, u, 0, w); + bp2 = latt_bp(lt, u, lt->pntsv - 1, w); - fac1= dv*v; - bp->vec[0]+= (1.0f-fac1)*bp1->vec[0] + fac1*bp2->vec[0]; - bp->vec[1]+= (1.0f-fac1)*bp1->vec[1] + fac1*bp2->vec[1]; - bp->vec[2]+= (1.0f-fac1)*bp1->vec[2] + fac1*bp2->vec[2]; + fac1 = dv * v; + bp->vec[0] += (1.0f - fac1) * bp1->vec[0] + fac1 * bp2->vec[0]; + bp->vec[1] += (1.0f - fac1) * bp1->vec[1] + fac1 * bp2->vec[1]; + bp->vec[2] += (1.0f - fac1) * bp1->vec[2] + fac1 * bp2->vec[2]; /* w extrema */ - bp1= latt_bp(lt, u, v, 0); - bp2= latt_bp(lt, u, v, lt->pntsw-1); + bp1 = latt_bp(lt, u, v, 0); + bp2 = latt_bp(lt, u, v, lt->pntsw - 1); - fac1= dw*w; - bp->vec[0]+= (1.0f-fac1)*bp1->vec[0] + fac1*bp2->vec[0]; - bp->vec[1]+= (1.0f-fac1)*bp1->vec[1] + fac1*bp2->vec[1]; - bp->vec[2]+= (1.0f-fac1)*bp1->vec[2] + fac1*bp2->vec[2]; + fac1 = dw * w; + bp->vec[0] += (1.0f - fac1) * bp1->vec[0] + fac1 * bp2->vec[0]; + bp->vec[1] += (1.0f - fac1) * bp1->vec[1] + fac1 * bp2->vec[1]; + bp->vec[2] += (1.0f - fac1) * bp1->vec[2] + fac1 * bp2->vec[2]; mul_v3_fl(bp->vec, 0.3333333f); @@ -919,12 +919,12 @@ void outside_lattice(Lattice *lt) } } else { - bp= lt->def; + bp = lt->def; - for (w=0; w<lt->pntsw; w++) - for (v=0; v<lt->pntsv; v++) - for (u=0; u<lt->pntsu; u++, bp++) - bp->hide= 0; + for (w = 0; w < lt->pntsw; w++) + for (v = 0; v < lt->pntsv; v++) + for (u = 0; u < lt->pntsu; u++, bp++) + bp->hide = 0; } } @@ -934,12 +934,12 @@ float (*BKE_lattice_vertexcos_get(struct Object *ob, int *numVerts_r))[3] int i, numVerts; float (*vertexCos)[3]; - if (lt->editlatt) lt= lt->editlatt->latt; - numVerts = *numVerts_r = lt->pntsu*lt->pntsv*lt->pntsw; + if (lt->editlatt) lt = lt->editlatt->latt; + numVerts = *numVerts_r = lt->pntsu * lt->pntsv * lt->pntsw; - vertexCos = MEM_mallocN(sizeof(*vertexCos)*numVerts, "lt_vcos"); + vertexCos = MEM_mallocN(sizeof(*vertexCos) * numVerts, "lt_vcos"); - for (i=0; i<numVerts; i++) { + for (i = 0; i < numVerts; i++) { copy_v3_v3(vertexCos[i], lt->def[i].vec); } @@ -949,31 +949,31 @@ float (*BKE_lattice_vertexcos_get(struct Object *ob, int *numVerts_r))[3] void BKE_lattice_vertexcos_apply(struct Object *ob, float (*vertexCos)[3]) { Lattice *lt = ob->data; - int i, numVerts = lt->pntsu*lt->pntsv*lt->pntsw; + int i, numVerts = lt->pntsu * lt->pntsv * lt->pntsw; - for (i=0; i<numVerts; i++) { + for (i = 0; i < numVerts; i++) { copy_v3_v3(lt->def[i].vec, vertexCos[i]); } } void BKE_lattice_modifiers_calc(Scene *scene, Object *ob) { - Lattice *lt= ob->data; + Lattice *lt = ob->data; ModifierData *md = modifiers_getVirtualModifierList(ob); float (*vertexCos)[3] = NULL; - int numVerts, editmode = (lt->editlatt!=NULL); + int numVerts, editmode = (lt->editlatt != NULL); freedisplist(&ob->disp); - for (; md; md=md->next) { + for (; md; md = md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene= scene; + md->scene = scene; - if (!(md->mode&eModifierMode_Realtime)) continue; - if (editmode && !(md->mode&eModifierMode_Editmode)) continue; + if (!(md->mode & eModifierMode_Realtime)) continue; + if (editmode && !(md->mode & eModifierMode_Editmode)) continue; if (mti->isDisabled && mti->isDisabled(md, 0)) continue; - if (mti->type!=eModifierTypeType_OnlyDeform) continue; + if (mti->type != eModifierTypeType_OnlyDeform) continue; if (!vertexCos) vertexCos = BKE_lattice_vertexcos_get(ob, &numVerts); mti->deformVerts(md, ob, NULL, vertexCos, numVerts, 0, 0); @@ -987,16 +987,16 @@ void BKE_lattice_modifiers_calc(Scene *scene, Object *ob) dl->type = DL_VERTS; dl->parts = 1; dl->nr = numVerts; - dl->verts = (float*) vertexCos; + dl->verts = (float *) vertexCos; BLI_addtail(&ob->disp, dl); } } -struct MDeformVert* BKE_lattice_deform_verts_get(struct Object *oblatt) +struct MDeformVert *BKE_lattice_deform_verts_get(struct Object *oblatt) { - Lattice *lt = (Lattice*)oblatt->data; + Lattice *lt = (Lattice *)oblatt->data; BLI_assert(oblatt->type == OB_LATTICE); - if (lt->editlatt) lt= lt->editlatt->latt; + if (lt->editlatt) lt = lt->editlatt->latt; return lt->dvert; } diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 13cfb40a0eb..7507442a4d5 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -82,8 +82,8 @@ void BKE_material_free(Material *ma) MTex *mtex; int a; - for (a=0; a<MAX_MTEX; a++) { - mtex= ma->mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = ma->mtex[a]; if (mtex && mtex->tex) mtex->tex->id.us--; if (mtex) MEM_freeN(mtex); } @@ -95,7 +95,7 @@ void BKE_material_free(Material *ma) if (ma->preview) BKE_previewimg_free(&ma->preview); - BKE_icon_delete((struct ID*)ma); + BKE_icon_delete((struct ID *)ma); ma->id.icon_id = 0; /* is no lib link block, but material extension */ @@ -110,67 +110,67 @@ void BKE_material_free(Material *ma) void init_material(Material *ma) { - ma->r= ma->g= ma->b= ma->ref= 0.8; - ma->specr= ma->specg= ma->specb= 1.0; - ma->mirr= ma->mirg= ma->mirb= 1.0; - ma->spectra= 1.0; - ma->amb= 1.0; - ma->alpha= 1.0; - ma->spec= ma->hasize= 0.5; - ma->har= 50; - ma->starc= ma->ringc= 4; - ma->linec= 12; - ma->flarec= 1; - ma->flaresize= ma->subsize= 1.0; - ma->flareboost= 1; - ma->seed2= 6; - ma->friction= 0.5; - ma->refrac= 4.0; - ma->roughness= 0.5; - ma->param[0]= 0.5; - ma->param[1]= 0.1; - ma->param[2]= 0.5; - ma->param[3]= 0.1; - ma->rms= 0.1; - ma->darkness= 1.0; - - ma->strand_sta= ma->strand_end= 1.0f; - - ma->ang= 1.0; - ma->ray_depth= 2; - ma->ray_depth_tra= 2; - ma->fresnel_mir= 0.0; - ma->fresnel_tra= 0.0; - ma->fresnel_tra_i= 1.25; - ma->fresnel_mir_i= 1.25; - ma->tx_limit= 0.0; - ma->tx_falloff= 1.0; - ma->shad_alpha= 1.0f; - - ma->gloss_mir = ma->gloss_tra= 1.0; - ma->samp_gloss_mir = ma->samp_gloss_tra= 18; + ma->r = ma->g = ma->b = ma->ref = 0.8; + ma->specr = ma->specg = ma->specb = 1.0; + ma->mirr = ma->mirg = ma->mirb = 1.0; + ma->spectra = 1.0; + ma->amb = 1.0; + ma->alpha = 1.0; + ma->spec = ma->hasize = 0.5; + ma->har = 50; + ma->starc = ma->ringc = 4; + ma->linec = 12; + ma->flarec = 1; + ma->flaresize = ma->subsize = 1.0; + ma->flareboost = 1; + ma->seed2 = 6; + ma->friction = 0.5; + ma->refrac = 4.0; + ma->roughness = 0.5; + ma->param[0] = 0.5; + ma->param[1] = 0.1; + ma->param[2] = 0.5; + ma->param[3] = 0.1; + ma->rms = 0.1; + ma->darkness = 1.0; + + ma->strand_sta = ma->strand_end = 1.0f; + + ma->ang = 1.0; + ma->ray_depth = 2; + ma->ray_depth_tra = 2; + ma->fresnel_mir = 0.0; + ma->fresnel_tra = 0.0; + ma->fresnel_tra_i = 1.25; + ma->fresnel_mir_i = 1.25; + ma->tx_limit = 0.0; + ma->tx_falloff = 1.0; + ma->shad_alpha = 1.0f; + + ma->gloss_mir = ma->gloss_tra = 1.0; + ma->samp_gloss_mir = ma->samp_gloss_tra = 18; ma->adapt_thresh_mir = ma->adapt_thresh_tra = 0.005; ma->dist_mir = 0.0; ma->fadeto_mir = MA_RAYMIR_FADETOSKY; - ma->rampfac_col= 1.0; - ma->rampfac_spec= 1.0; - ma->pr_lamp= 3; /* two lamps, is bits */ - ma->pr_type= MA_SPHERE; - - ma->sss_radius[0]= 1.0f; - ma->sss_radius[1]= 1.0f; - ma->sss_radius[2]= 1.0f; - ma->sss_col[0]= 1.0f; - ma->sss_col[1]= 1.0f; - ma->sss_col[2]= 1.0f; - ma->sss_error= 0.05f; - ma->sss_scale= 0.1f; - ma->sss_ior= 1.3f; - ma->sss_colfac= 1.0f; - ma->sss_texfac= 0.0f; - ma->sss_front= 1.0f; - ma->sss_back= 1.0f; + ma->rampfac_col = 1.0; + ma->rampfac_spec = 1.0; + ma->pr_lamp = 3; /* two lamps, is bits */ + ma->pr_type = MA_SPHERE; + + ma->sss_radius[0] = 1.0f; + ma->sss_radius[1] = 1.0f; + ma->sss_radius[2] = 1.0f; + ma->sss_col[0] = 1.0f; + ma->sss_col[1] = 1.0f; + ma->sss_col[2] = 1.0f; + ma->sss_error = 0.05f; + ma->sss_scale = 0.1f; + ma->sss_ior = 1.3f; + ma->sss_colfac = 1.0f; + ma->sss_texfac = 0.0f; + ma->sss_front = 1.0f; + ma->sss_back = 1.0f; ma->vol.density = 1.0f; ma->vol.emission = 0.0f; @@ -191,11 +191,11 @@ void init_material(Material *ma) ma->vol.ms_intensity = 1.f; ma->game.flag = GEMAT_BACKCULL; - ma->game.alpha_blend=0; - ma->game.face_orientation=0; + ma->game.alpha_blend = 0; + ma->game.face_orientation = 0; - ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RAYBIAS|MA_TANGENT_STR|MA_ZTRANSP; - ma->shade_flag= MA_APPROX_OCCLUSION; + ma->mode = MA_TRACEBLE | MA_SHADBUF | MA_SHADOW | MA_RAYBIAS | MA_TANGENT_STR | MA_ZTRANSP; + ma->shade_flag = MA_APPROX_OCCLUSION; ma->preview = NULL; } @@ -203,7 +203,7 @@ Material *BKE_material_add(const char *name) { Material *ma; - ma= BKE_libblock_alloc(&G.main->mat, ID_MA, name); + ma = BKE_libblock_alloc(&G.main->mat, ID_MA, name); init_material(ma); @@ -216,28 +216,28 @@ Material *BKE_material_copy(Material *ma) Material *man; int a; - man= BKE_libblock_copy(&ma->id); + man = BKE_libblock_copy(&ma->id); id_lib_extern((ID *)man->group); - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (ma->mtex[a]) { - man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial"); + man->mtex[a] = MEM_mallocN(sizeof(MTex), "copymaterial"); memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex)); id_us_plus((ID *)man->mtex[a]->tex); } } - if (ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col); - if (ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec); + if (ma->ramp_col) man->ramp_col = MEM_dupallocN(ma->ramp_col); + if (ma->ramp_spec) man->ramp_spec = MEM_dupallocN(ma->ramp_spec); if (ma->preview) man->preview = BKE_previewimg_copy(ma->preview); if (ma->nodetree) { - man->nodetree= ntreeCopyTree(ma->nodetree); /* 0 == full new tree */ + man->nodetree = ntreeCopyTree(ma->nodetree); /* 0 == full new tree */ } - man->gpumaterial.first= man->gpumaterial.last= NULL; + man->gpumaterial.first = man->gpumaterial.last = NULL; return man; } @@ -248,26 +248,26 @@ Material *localize_material(Material *ma) Material *man; int a; - man= BKE_libblock_copy(&ma->id); + man = BKE_libblock_copy(&ma->id); BLI_remlink(&G.main->mat, man); /* no increment for texture ID users, in previewrender.c it prevents decrement */ - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (ma->mtex[a]) { - man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial"); + man->mtex[a] = MEM_mallocN(sizeof(MTex), "copymaterial"); memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex)); } } - if (ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col); - if (ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec); + if (ma->ramp_col) man->ramp_col = MEM_dupallocN(ma->ramp_col); + if (ma->ramp_spec) man->ramp_spec = MEM_dupallocN(ma->ramp_spec); man->preview = NULL; if (ma->nodetree) - man->nodetree= ntreeLocalize(ma->nodetree); + man->nodetree = ntreeLocalize(ma->nodetree); - man->gpumaterial.first= man->gpumaterial.last= NULL; + man->gpumaterial.first = man->gpumaterial.last = NULL; return man; } @@ -275,29 +275,29 @@ Material *localize_material(Material *ma) static void extern_local_material(Material *ma) { int i; - for (i=0; i < MAX_MTEX; i++) { + for (i = 0; i < MAX_MTEX; i++) { if (ma->mtex[i]) id_lib_extern((ID *)ma->mtex[i]->tex); } } void BKE_material_make_local(Material *ma) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; Mesh *me; Curve *cu; MetaBall *mb; - int a, is_local= FALSE, is_lib= FALSE; + int a, is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (ma->id.lib==NULL) return; + if (ma->id.lib == NULL) return; /* One local user; set flag and return. */ - if (ma->id.us==1) { + if (ma->id.us == 1) { id_clear_lib_data(bmain, &ma->id); extern_local_material(ma); return; @@ -306,56 +306,56 @@ void BKE_material_make_local(Material *ma) /* Check which other IDs reference this one to determine if it's used by * lib or local */ /* test objects */ - ob= bmain->object.first; + 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) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < ob->totcol; a++) { + if (ob->mat[a] == ma) { + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } - ob= ob->id.next; + ob = ob->id.next; } /* test meshes */ - me= bmain->mesh.first; + me = bmain->mesh.first; while (me) { if (me->mat) { - for (a=0; a<me->totcol; a++) { - if (me->mat[a]==ma) { - if (me->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < me->totcol; a++) { + if (me->mat[a] == ma) { + if (me->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } - me= me->id.next; + me = me->id.next; } /* test curves */ - cu= bmain->curve.first; + cu = bmain->curve.first; while (cu) { if (cu->mat) { - for (a=0; a<cu->totcol; a++) { - if (cu->mat[a]==ma) { - if (cu->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < cu->totcol; a++) { + if (cu->mat[a] == ma) { + if (cu->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } - cu= cu->id.next; + cu = cu->id.next; } /* test mballs */ - mb= bmain->mball.first; + mb = bmain->mball.first; while (mb) { if (mb->mat) { - for (a=0; a<mb->totcol; a++) { - if (mb->mat[a]==ma) { - if (mb->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < mb->totcol; a++) { + if (mb->mat[a] == ma) { + if (mb->id.lib) is_lib = TRUE; + else is_local = TRUE; } } } - mb= mb->id.next; + mb = mb->id.next; } /* Only local users. */ @@ -365,76 +365,76 @@ void BKE_material_make_local(Material *ma) } /* Both user and local, so copy. */ else if (is_local && is_lib) { - Material *ma_new= BKE_material_copy(ma); + Material *ma_new = BKE_material_copy(ma); - ma_new->id.us= 0; + ma_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, ma->id.lib, &ma_new->id); /* do objects */ - ob= bmain->object.first; + 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==NULL) { - ob->mat[a]= ma_new; + for (a = 0; a < ob->totcol; a++) { + if (ob->mat[a] == ma) { + if (ob->id.lib == NULL) { + ob->mat[a] = ma_new; ma_new->id.us++; ma->id.us--; } } } } - ob= ob->id.next; + ob = ob->id.next; } /* do meshes */ - me= bmain->mesh.first; + me = bmain->mesh.first; while (me) { if (me->mat) { - for (a=0; a<me->totcol; a++) { - if (me->mat[a]==ma) { - if (me->id.lib==NULL) { - me->mat[a]= ma_new; + for (a = 0; a < me->totcol; a++) { + if (me->mat[a] == ma) { + if (me->id.lib == NULL) { + me->mat[a] = ma_new; ma_new->id.us++; ma->id.us--; } } } } - me= me->id.next; + me = me->id.next; } /* do curves */ - cu= bmain->curve.first; + cu = bmain->curve.first; while (cu) { if (cu->mat) { - for (a=0; a<cu->totcol; a++) { - if (cu->mat[a]==ma) { - if (cu->id.lib==NULL) { - cu->mat[a]= ma_new; + for (a = 0; a < cu->totcol; a++) { + if (cu->mat[a] == ma) { + if (cu->id.lib == NULL) { + cu->mat[a] = ma_new; ma_new->id.us++; ma->id.us--; } } } } - cu= cu->id.next; + cu = cu->id.next; } /* do mballs */ - mb= bmain->mball.first; + mb = bmain->mball.first; while (mb) { if (mb->mat) { - for (a=0; a<mb->totcol; a++) { - if (mb->mat[a]==ma) { - if (mb->id.lib==NULL) { - mb->mat[a]= ma_new; + for (a = 0; a < mb->totcol; a++) { + if (mb->mat[a] == ma) { + if (mb->id.lib == NULL) { + mb->mat[a] = ma_new; ma_new->id.us++; ma->id.us--; } } } } - mb= mb->id.next; + mb = mb->id.next; } } } @@ -443,7 +443,7 @@ void BKE_material_make_local(Material *ma) void extern_local_matarar(struct Material **matar, short totcol) { short i; - for (i= 0; i < totcol; i++) { + for (i = 0; i < totcol; i++) { id_lib_extern((ID *)matar[i]); } } @@ -454,16 +454,16 @@ Material ***give_matarar(Object *ob) Curve *cu; MetaBall *mb; - if (ob->type==OB_MESH) { - me= ob->data; + if (ob->type == OB_MESH) { + me = ob->data; return &(me->mat); } else if (ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF)) { - cu= ob->data; + cu = ob->data; return &(cu->mat); } - else if (ob->type==OB_MBALL) { - mb= ob->data; + else if (ob->type == OB_MBALL) { + mb = ob->data; return &(mb->mat); } return NULL; @@ -475,16 +475,16 @@ short *give_totcolp(Object *ob) Curve *cu; MetaBall *mb; - if (ob->type==OB_MESH) { - me= ob->data; + if (ob->type == OB_MESH) { + me = ob->data; return &(me->totcol); } else if (ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF)) { - cu= ob->data; + cu = ob->data; return &(cu->totcol); } - else if (ob->type==OB_MBALL) { - mb= ob->data; + else if (ob->type == OB_MBALL) { + mb = ob->data; return &(mb->totcol); } return NULL; @@ -494,15 +494,15 @@ short *give_totcolp(Object *ob) Material ***give_matarar_id(ID *id) { switch (GS(id->name)) { - case ID_ME: - return &(((Mesh *)id)->mat); - break; - case ID_CU: - return &(((Curve *)id)->mat); - break; - case ID_MB: - return &(((MetaBall *)id)->mat); - break; + case ID_ME: + return &(((Mesh *)id)->mat); + break; + case ID_CU: + return &(((Curve *)id)->mat); + break; + case ID_MB: + return &(((MetaBall *)id)->mat); + break; } return NULL; } @@ -510,15 +510,15 @@ Material ***give_matarar_id(ID *id) short *give_totcolp_id(ID *id) { switch (GS(id->name)) { - case ID_ME: - return &(((Mesh *)id)->totcol); - break; - case ID_CU: - return &(((Curve *)id)->totcol); - break; - case ID_MB: - return &(((MetaBall *)id)->totcol); - break; + case ID_ME: + return &(((Mesh *)id)->totcol); + break; + case ID_CU: + return &(((Curve *)id)->totcol); + break; + case ID_MB: + return &(((MetaBall *)id)->totcol); + break; } return NULL; } @@ -526,29 +526,29 @@ short *give_totcolp_id(ID *id) static void data_delete_material_index_id(ID *id, short index) { switch (GS(id->name)) { - case ID_ME: - BKE_mesh_delete_material_index((Mesh *)id, index); - break; - case ID_CU: - BKE_curve_delete_material_index((Curve *)id, index); - break; - case ID_MB: - /* meta-elems don't have materials atm */ - break; + case ID_ME: + BKE_mesh_delete_material_index((Mesh *)id, index); + break; + case ID_CU: + BKE_curve_delete_material_index((Curve *)id, index); + break; + case ID_MB: + /* meta-elems don't have materials atm */ + break; } } void material_append_id(ID *id, Material *ma) { Material ***matar; - if ((matar= give_matarar_id(id))) { - short *totcol= give_totcolp_id(id); - Material **mat= MEM_callocN(sizeof(void *) * ((*totcol) + 1), "newmatar"); + if ((matar = give_matarar_id(id))) { + short *totcol = give_totcolp_id(id); + Material **mat = MEM_callocN(sizeof(void *) * ((*totcol) + 1), "newmatar"); if (*totcol) memcpy(mat, *matar, sizeof(void *) * (*totcol)); if (*matar) MEM_freeN(*matar); - *matar= mat; - (*matar)[(*totcol)++]= ma; + *matar = mat; + (*matar)[(*totcol)++] = ma; id_us_plus((ID *)ma); test_object_materials(id); @@ -557,33 +557,33 @@ void material_append_id(ID *id, Material *ma) Material *material_pop_id(ID *id, int index_i, int remove_material_slot) { - short index= (short)index_i; - Material *ret= NULL; + short index = (short)index_i; + Material *ret = NULL; Material ***matar; - if ((matar= give_matarar_id(id))) { - short *totcol= give_totcolp_id(id); + if ((matar = give_matarar_id(id))) { + short *totcol = give_totcolp_id(id); if (index >= 0 && index < (*totcol)) { - ret= (*matar)[index]; + ret = (*matar)[index]; id_us_min((ID *)ret); if (remove_material_slot) { if (*totcol <= 1) { - *totcol= 0; + *totcol = 0; MEM_freeN(*matar); - *matar= NULL; + *matar = NULL; } else { Material **mat; if (index + 1 != (*totcol)) - memmove((*matar)+index, (*matar)+(index+1), sizeof(void *) * ((*totcol) - (index + 1))); + memmove((*matar) + index, (*matar) + (index + 1), sizeof(void *) * ((*totcol) - (index + 1))); (*totcol)--; - mat= MEM_callocN(sizeof(void *) * (*totcol), "newmatar"); + mat = MEM_callocN(sizeof(void *) * (*totcol), "newmatar"); memcpy(mat, *matar, sizeof(void *) * (*totcol)); MEM_freeN(*matar); - *matar= mat; + *matar = mat; test_object_materials(id); } @@ -593,7 +593,7 @@ Material *material_pop_id(ID *id, int index_i, int remove_material_slot) /* don't remove material slot, only clear it*/ else - (*matar)[index]= NULL; + (*matar)[index] = NULL; } } @@ -605,33 +605,33 @@ Material *give_current_material(Object *ob, short act) Material ***matarar, *ma; short *totcolp; - if (ob==NULL) return NULL; + if (ob == NULL) return NULL; /* if object cannot have material, totcolp==NULL */ - totcolp= give_totcolp(ob); - if (totcolp==NULL || ob->totcol==0) return NULL; + totcolp = give_totcolp(ob); + if (totcolp == NULL || ob->totcol == 0) return NULL; - if (act<0) { + if (act < 0) { printf("no!\n"); } - if (act>ob->totcol) act= ob->totcol; - else if (act<=0) act= 1; + if (act > ob->totcol) act = ob->totcol; + else if (act <= 0) act = 1; - if (ob->matbits && ob->matbits[act-1]) { /* in object */ - ma= ob->mat[act-1]; + if (ob->matbits && ob->matbits[act - 1]) { /* in object */ + ma = ob->mat[act - 1]; } - else { /* in data */ + else { /* in data */ /* check for inconsistency */ if (*totcolp < ob->totcol) - ob->totcol= *totcolp; - if (act>ob->totcol) act= ob->totcol; + ob->totcol = *totcolp; + if (act > ob->totcol) act = ob->totcol; - matarar= give_matarar(ob); + matarar = give_matarar(ob); - if (matarar && *matarar) ma= (*matarar)[act-1]; - else ma= NULL; + if (matarar && *matarar) ma = (*matarar)[act - 1]; + else ma = NULL; } @@ -641,19 +641,19 @@ Material *give_current_material(Object *ob, short act) ID *material_from(Object *ob, short act) { - if (ob==NULL) return NULL; + if (ob == NULL) return NULL; - if (ob->totcol==0) return ob->data; - if (act==0) act= 1; + if (ob->totcol == 0) return ob->data; + if (act == 0) act = 1; - if (ob->matbits[act-1]) return (ID *)ob; + if (ob->matbits[act - 1]) return (ID *)ob; else return ob->data; } Material *give_node_material(Material *ma) { if (ma && ma->use_nodes && ma->nodetree) { - bNode *node= nodeGetActiveID(ma->nodetree, ID_MA); + bNode *node = nodeGetActiveID(ma->nodetree, ID_MA); if (node) return (Material *)node->id; @@ -670,7 +670,7 @@ Material *give_node_material(Material *ma) * well. I expect we'll sort it out soon... */ /* from blendef: */ -#define GS(a) (*((short *)(a))) +#define GS(a) (*((short *)(a))) /* from misc_util: flip the bytes from x */ /* #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */ @@ -680,29 +680,29 @@ void resize_object_material(Object *ob, const short totcol) Material **newmatar; char *newmatbits; - if (totcol==0) { + if (totcol == 0) { if (ob->totcol) { MEM_freeN(ob->mat); MEM_freeN(ob->matbits); - ob->mat= NULL; - ob->matbits= NULL; + ob->mat = NULL; + ob->matbits = NULL; } } - else if (ob->totcol<totcol) { - newmatar= MEM_callocN(sizeof(void *)*totcol, "newmatar"); - newmatbits= MEM_callocN(sizeof(char)*totcol, "newmatbits"); + else if (ob->totcol < totcol) { + newmatar = MEM_callocN(sizeof(void *) * totcol, "newmatar"); + newmatbits = MEM_callocN(sizeof(char) * totcol, "newmatbits"); if (ob->totcol) { - memcpy(newmatar, ob->mat, sizeof(void *)*ob->totcol); - memcpy(newmatbits, ob->matbits, sizeof(char)*ob->totcol); + memcpy(newmatar, ob->mat, sizeof(void *) * ob->totcol); + memcpy(newmatbits, ob->matbits, sizeof(char) * ob->totcol); MEM_freeN(ob->mat); MEM_freeN(ob->matbits); } - ob->mat= newmatar; - ob->matbits= newmatbits; + ob->mat = newmatar; + ob->matbits = newmatbits; } - ob->totcol= totcol; - if (ob->totcol && ob->actcol==0) ob->actcol= 1; - if (ob->actcol>ob->totcol) ob->actcol= ob->totcol; + ob->totcol = totcol; + if (ob->totcol && ob->actcol == 0) ob->actcol = 1; + if (ob->actcol > ob->totcol) ob->actcol = ob->totcol; } void test_object_materials(ID *id) @@ -711,12 +711,12 @@ void test_object_materials(ID *id) Object *ob; short *totcol; - if (id==NULL || (totcol=give_totcolp_id(id))==NULL) { + if (id == NULL || (totcol = give_totcolp_id(id)) == NULL) { return; } - for (ob= G.main->object.first; ob; ob= ob->id.next) { - if (ob->data==id) { + for (ob = G.main->object.first; ob; ob = ob->id.next) { + if (ob->data == id) { resize_object_material(ob, *totcol); } } @@ -727,8 +727,8 @@ void assign_material_id(ID *id, Material *ma, short act) Material *mao, **matar, ***matarar; short *totcolp; - if (act>MAXMAT) return; - if (act<1) act= 1; + if (act > MAXMAT) return; + if (act < 1) act = 1; /* prevent crashing when using accidentally */ BLI_assert(id->lib == NULL); @@ -736,27 +736,27 @@ void assign_material_id(ID *id, Material *ma, short act) /* test arraylens */ - totcolp= give_totcolp_id(id); - matarar= give_matarar_id(id); + totcolp = give_totcolp_id(id); + matarar = give_matarar_id(id); - if (totcolp==NULL || matarar==NULL) return; + if (totcolp == NULL || matarar == NULL) return; if (act > *totcolp) { - matar= MEM_callocN(sizeof(void *)*act, "matarray1"); + matar = MEM_callocN(sizeof(void *) * act, "matarray1"); if (*totcolp) { - memcpy(matar, *matarar, sizeof(void *)*(*totcolp)); + memcpy(matar, *matarar, sizeof(void *) * (*totcolp)); MEM_freeN(*matarar); } - *matarar= matar; - *totcolp= act; + *matarar = matar; + *totcolp = act; } /* in data */ - mao= (*matarar)[act-1]; + mao = (*matarar)[act - 1]; if (mao) mao->id.us--; - (*matarar)[act-1]= ma; + (*matarar)[act - 1] = ma; if (ma) id_us_plus((ID *)ma); @@ -770,8 +770,8 @@ void assign_material(Object *ob, Material *ma, short act) char *matbits; short *totcolp; - if (act>MAXMAT) return; - if (act<1) act= 1; + if (act > MAXMAT) return; + if (act < 1) act = 1; /* prevent crashing when using accidentally */ BLI_assert(ob->id.lib == NULL); @@ -779,54 +779,54 @@ void assign_material(Object *ob, Material *ma, short act) /* test arraylens */ - totcolp= give_totcolp(ob); - matarar= give_matarar(ob); + totcolp = give_totcolp(ob); + matarar = give_matarar(ob); - if (totcolp==NULL || matarar==NULL) return; + if (totcolp == NULL || matarar == NULL) return; if (act > *totcolp) { - matar= MEM_callocN(sizeof(void *)*act, "matarray1"); + matar = MEM_callocN(sizeof(void *) * act, "matarray1"); if (*totcolp) { - memcpy(matar, *matarar, sizeof(void *)*(*totcolp)); + memcpy(matar, *matarar, sizeof(void *) * (*totcolp)); MEM_freeN(*matarar); } - *matarar= matar; - *totcolp= act; + *matarar = matar; + *totcolp = act; } if (act > ob->totcol) { - matar= MEM_callocN(sizeof(void *)*act, "matarray2"); - matbits= MEM_callocN(sizeof(char)*act, "matbits1"); - if ( ob->totcol) { + matar = MEM_callocN(sizeof(void *) * act, "matarray2"); + matbits = MEM_callocN(sizeof(char) * act, "matbits1"); + if (ob->totcol) { memcpy(matar, ob->mat, sizeof(void *) * ob->totcol); - memcpy(matbits, ob->matbits, sizeof(char)*(*totcolp)); + memcpy(matbits, ob->matbits, sizeof(char) * (*totcolp)); MEM_freeN(ob->mat); MEM_freeN(ob->matbits); } - ob->mat= matar; - ob->matbits= matbits; - ob->totcol= act; + ob->mat = matar; + ob->matbits = matbits; + ob->totcol = act; /* copy object/mesh linking, or assign based on userpref */ if (ob->actcol) - ob->matbits[act-1]= ob->matbits[ob->actcol-1]; + ob->matbits[act - 1] = ob->matbits[ob->actcol - 1]; else - ob->matbits[act-1]= (U.flag & USER_MAT_ON_OB)? 1: 0; + ob->matbits[act - 1] = (U.flag & USER_MAT_ON_OB) ? 1 : 0; } /* do it */ - if (ob->matbits[act-1]) { /* in object */ - mao= ob->mat[act-1]; + if (ob->matbits[act - 1]) { /* in object */ + mao = ob->mat[act - 1]; if (mao) mao->id.us--; - ob->mat[act-1]= ma; + ob->mat[act - 1] = ma; } - else { /* in data */ - mao= (*matarar)[act-1]; + else { /* in data */ + mao = (*matarar)[act - 1]; if (mao) mao->id.us--; - (*matarar)[act-1]= ma; + (*matarar)[act - 1] = ma; } if (ma) @@ -837,19 +837,19 @@ void assign_material(Object *ob, Material *ma, short act) /* XXX - this calls many more update calls per object then are needed, could be optimized */ void assign_matarar(struct Object *ob, struct Material ***matar, short totcol) { - int actcol_orig= ob->actcol; + int actcol_orig = ob->actcol; short i; while (object_remove_material_slot(ob)) {}; /* now we have the right number of slots */ - for (i=0; i<totcol; i++) - assign_material(ob, (*matar)[i], i+1); + for (i = 0; i < totcol; i++) + assign_material(ob, (*matar)[i], i + 1); if (actcol_orig > ob->totcol) - actcol_orig= ob->totcol; + actcol_orig = ob->totcol; - ob->actcol= actcol_orig; + ob->actcol = actcol_orig; } @@ -858,45 +858,45 @@ short find_material_index(Object *ob, Material *ma) Material ***matarar; short a, *totcolp; - if (ma==NULL) return 0; + if (ma == NULL) return 0; - totcolp= give_totcolp(ob); - matarar= give_matarar(ob); + totcolp = give_totcolp(ob); + matarar = give_matarar(ob); - if (totcolp==NULL || matarar==NULL) return 0; + if (totcolp == NULL || matarar == NULL) return 0; - for (a=0; a<*totcolp; a++) - if ((*matarar)[a]==ma) - break; - if (a<*totcolp) - return a+1; + for (a = 0; a < *totcolp; a++) + if ((*matarar)[a] == ma) + break; + if (a < *totcolp) + return a + 1; return 0; } int object_add_material_slot(Object *ob) { - if (ob==NULL) return FALSE; - if (ob->totcol>=MAXMAT) return FALSE; + if (ob == NULL) return FALSE; + if (ob->totcol >= MAXMAT) return FALSE; - assign_material(ob, NULL, ob->totcol+1); - ob->actcol= ob->totcol; + assign_material(ob, NULL, ob->totcol + 1); + ob->actcol = ob->totcol; return TRUE; } static void do_init_render_material(Material *ma, int r_mode, float *amb) { MTex *mtex; - int a, needuv=0, needtang=0; + int a, needuv = 0, needtang = 0; - if (ma->flarec==0) ma->flarec= 1; + if (ma->flarec == 0) ma->flarec = 1; /* add all texcoflags from mtex, texco and mapto were cleared in advance */ - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { /* separate tex switching */ - if (ma->septex & (1<<a)) continue; + if (ma->septex & (1 << a)) continue; - mtex= ma->mtex[a]; + mtex = ma->mtex[a]; if (mtex && mtex->tex && (mtex->tex->type | (mtex->tex->use_nodes && mtex->tex->nodetree) )) { ma->texco |= mtex->texco; @@ -904,41 +904,41 @@ static void do_init_render_material(Material *ma, int r_mode, float *amb) /* always get derivatives for these textures */ if (ELEM3(mtex->tex->type, TEX_IMAGE, TEX_PLUGIN, TEX_ENVMAP)) ma->texco |= TEXCO_OSA; - else if (mtex->texflag & (MTEX_COMPAT_BUMP|MTEX_3TAP_BUMP|MTEX_5TAP_BUMP|MTEX_BICUBIC_BUMP)) ma->texco |= TEXCO_OSA; + else if (mtex->texflag & (MTEX_COMPAT_BUMP | MTEX_3TAP_BUMP | MTEX_5TAP_BUMP | MTEX_BICUBIC_BUMP)) ma->texco |= TEXCO_OSA; - if (ma->texco & (TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM|TEXCO_STRAND|TEXCO_STRESS)) needuv= 1; - else if (ma->texco & (TEXCO_GLOB|TEXCO_UV|TEXCO_OBJECT|TEXCO_SPEED)) needuv= 1; - else if (ma->texco & (TEXCO_LAVECTOR|TEXCO_VIEW|TEXCO_STICKY)) needuv= 1; + if (ma->texco & (TEXCO_ORCO | TEXCO_REFL | TEXCO_NORM | TEXCO_STRAND | TEXCO_STRESS)) needuv = 1; + else if (ma->texco & (TEXCO_GLOB | TEXCO_UV | TEXCO_OBJECT | TEXCO_SPEED)) needuv = 1; + else if (ma->texco & (TEXCO_LAVECTOR | TEXCO_VIEW | TEXCO_STICKY)) needuv = 1; if ((ma->mapto & MAP_NORM) && (mtex->normapspace == MTEX_NSPACE_TANGENT)) - needtang= 1; + needtang = 1; } } if (needtang) ma->mode |= MA_NORMAP_TANG; else ma->mode &= ~MA_NORMAP_TANG; - if (ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) { - needuv= 1; - if (r_mode & R_OSA) ma->texco |= TEXCO_OSA; /* for texfaces */ + if (ma->mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) { + needuv = 1; + if (r_mode & R_OSA) ma->texco |= TEXCO_OSA; /* for texfaces */ } if (needuv) ma->texco |= NEED_UV; /* since the raytracer doesnt recalc O structs for each ray, we have to preset them all */ if (r_mode & R_RAYTRACE) { - if ((ma->mode & (MA_RAYMIRROR|MA_SHADOW_TRA)) || ((ma->mode & MA_TRANSP) && (ma->mode & MA_RAYTRANSP))) { - ma->texco |= NEED_UV|TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM; + if ((ma->mode & (MA_RAYMIRROR | MA_SHADOW_TRA)) || ((ma->mode & MA_TRANSP) && (ma->mode & MA_RAYTRANSP))) { + ma->texco |= NEED_UV | TEXCO_ORCO | TEXCO_REFL | TEXCO_NORM; if (r_mode & R_OSA) ma->texco |= TEXCO_OSA; } } if (amb) { - ma->ambr= ma->amb*amb[0]; - ma->ambg= ma->amb*amb[1]; - ma->ambb= ma->amb*amb[2]; + ma->ambr = ma->amb * amb[0]; + ma->ambg = ma->amb * amb[1]; + ma->ambb = ma->amb * amb[2]; } /* will become or-ed result of all node modes */ - ma->mode_l= ma->mode; + ma->mode_l = ma->mode; ma->mode_l &= ~MA_SHLESS; if (ma->strand_surfnor > 0.0f) @@ -953,17 +953,17 @@ static void init_render_nodetree(bNodeTree *ntree, Material *basemat, int r_mode { bNode *node; - for (node=ntree->nodes.first; node; node= node->next) { + for (node = ntree->nodes.first; node; node = node->next) { if (node->id) { - if (GS(node->id->name)==ID_MA) { - Material *ma= (Material *)node->id; - if (ma!=basemat) { + if (GS(node->id->name) == ID_MA) { + Material *ma = (Material *)node->id; + if (ma != basemat) { do_init_render_material(ma, r_mode, amb); basemat->texco |= ma->texco; - basemat->mode_l |= ma->mode_l & ~(MA_TRANSP|MA_ZTRANSP|MA_RAYTRANSP); + basemat->mode_l |= ma->mode_l & ~(MA_TRANSP | MA_ZTRANSP | MA_RAYTRANSP); } } - else if (node->type==NODE_GROUP) + else if (node->type == NODE_GROUP) init_render_nodetree((bNodeTree *)node->id, basemat, r_mode, amb); } } @@ -989,15 +989,15 @@ void init_render_materials(Main *bmain, int r_mode, float *amb) /* clear these flags before going over materials, to make sure they * are cleared only once, otherwise node materials contained in other * node materials can go wrong */ - for (ma= bmain->mat.first; ma; ma= ma->id.next) { + for (ma = bmain->mat.first; ma; ma = ma->id.next) { if (ma->id.us) { - ma->texco= 0; - ma->mapto= 0; + ma->texco = 0; + ma->mapto = 0; } } /* two steps, first initialize, then or the flags for layers */ - for (ma= bmain->mat.first; ma; ma= ma->id.next) { + for (ma = bmain->mat.first; ma; ma = ma->id.next) { /* is_used flag comes back in convertblender.c */ ma->flag &= ~MA_IS_USED; if (ma->id.us) @@ -1019,7 +1019,7 @@ void end_render_material(Material *mat) void end_render_materials(Main *bmain) { Material *ma; - for (ma= bmain->mat.first; ma; ma= ma->id.next) + for (ma = bmain->mat.first; ma; ma = ma->id.next) if (ma->id.us) end_render_material(ma); } @@ -1028,13 +1028,13 @@ static int material_in_nodetree(bNodeTree *ntree, Material *mat) { bNode *node; - for (node=ntree->nodes.first; node; node= node->next) { - if (node->id && GS(node->id->name)==ID_MA) { - if (node->id==(ID*)mat) + for (node = ntree->nodes.first; node; node = node->next) { + if (node->id && GS(node->id->name) == ID_MA) { + if (node->id == (ID *)mat) return 1; } - else if (node->type==NODE_GROUP) - if (material_in_nodetree((bNodeTree*)node->id, mat)) + else if (node->type == NODE_GROUP) + if (material_in_nodetree((bNodeTree *)node->id, mat)) return 1; } @@ -1043,7 +1043,7 @@ static int material_in_nodetree(bNodeTree *ntree, Material *mat) int material_in_material(Material *parmat, Material *mat) { - if (parmat==mat) + if (parmat == mat) return 1; else if (parmat->nodetree && parmat->use_nodes) return material_in_nodetree(parmat->nodetree, mat); @@ -1086,15 +1086,15 @@ void automatname(Material *ma) int nr, r, g, b; float ref; - if (ma==NULL) return; - if (ma->mode & MA_SHLESS) ref= 1.0; - else ref= ma->ref; - - r= (int)(4.99f*(ref*ma->r)); - g= (int)(4.99f*(ref*ma->g)); - b= (int)(4.99f*(ref*ma->b)); - nr= r + 5*g + 25*b; - if (nr>124) nr= 124; + if (ma == NULL) return; + if (ma->mode & MA_SHLESS) ref = 1.0; + else ref = ma->ref; + + r = (int)(4.99f * (ref * ma->r)); + g = (int)(4.99f * (ref * ma->g)); + b = (int)(4.99f * (ref * ma->b)); + nr = r + 5 * g + 25 * b; + if (nr > 124) nr = 124; new_id(&G.main->mat, (ID *)ma, colname_array[nr]); } @@ -1107,7 +1107,7 @@ int object_remove_material_slot(Object *ob) short *totcolp; short a, actcol; - if (ob==NULL || ob->totcol==0) { + if (ob == NULL || ob->totcol == 0) { return FALSE; } @@ -1124,54 +1124,54 @@ int object_remove_material_slot(Object *ob) * after that check indices in mesh/curve/mball!!! */ - totcolp= give_totcolp(ob); - matarar= give_matarar(ob); + totcolp = give_totcolp(ob); + matarar = give_matarar(ob); - if (*matarar==NULL) return FALSE; + if (*matarar == NULL) return FALSE; /* we delete the actcol */ - mao= (*matarar)[ob->actcol-1]; + mao = (*matarar)[ob->actcol - 1]; if (mao) mao->id.us--; - for (a=ob->actcol; a<ob->totcol; a++) - (*matarar)[a-1]= (*matarar)[a]; + for (a = ob->actcol; a < ob->totcol; a++) + (*matarar)[a - 1] = (*matarar)[a]; (*totcolp)--; - if (*totcolp==0) { + if (*totcolp == 0) { MEM_freeN(*matarar); - *matarar= NULL; + *matarar = NULL; } - actcol= ob->actcol; - obt= G.main->object.first; + actcol = ob->actcol; + obt = G.main->object.first; while (obt) { - if (obt->data==ob->data) { + if (obt->data == ob->data) { /* WATCH IT: do not use actcol from ob or from obt (can become zero) */ - mao= obt->mat[actcol-1]; + mao = obt->mat[actcol - 1]; if (mao) mao->id.us--; - for (a=actcol; a<obt->totcol; a++) { - obt->mat[a-1]= obt->mat[a]; - obt->matbits[a-1]= obt->matbits[a]; + for (a = actcol; a < obt->totcol; a++) { + obt->mat[a - 1] = obt->mat[a]; + obt->matbits[a - 1] = obt->matbits[a]; } obt->totcol--; - if (obt->actcol > obt->totcol) obt->actcol= obt->totcol; + if (obt->actcol > obt->totcol) obt->actcol = obt->totcol; - if (obt->totcol==0) { + if (obt->totcol == 0) { MEM_freeN(obt->mat); MEM_freeN(obt->matbits); - obt->mat= NULL; - obt->matbits= NULL; + obt->mat = NULL; + obt->matbits = NULL; } } - obt= obt->id.next; + obt = obt->id.next; } /* check indices from mesh */ if (ELEM4(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) { - data_delete_material_index_id((ID *)ob->data, actcol-1); + data_delete_material_index_id((ID *)ob->data, actcol - 1); freedisplist(&ob->disp); } @@ -1182,253 +1182,253 @@ int object_remove_material_slot(Object *ob) /* r_col = current value, col = new value, fac==0 is no change */ void ramp_blend(int type, float r_col[3], const float fac, const float col[3]) { - float tmp, facm= 1.0f-fac; + float tmp, facm = 1.0f - fac; switch (type) { case MA_RAMP_BLEND: - r_col[0] = facm*(r_col[0]) + fac*col[0]; - r_col[1] = facm*(r_col[1]) + fac*col[1]; - r_col[2] = facm*(r_col[2]) + fac*col[2]; + r_col[0] = facm * (r_col[0]) + fac * col[0]; + r_col[1] = facm * (r_col[1]) + fac * col[1]; + r_col[2] = facm * (r_col[2]) + fac * col[2]; break; case MA_RAMP_ADD: - r_col[0] += fac*col[0]; - r_col[1] += fac*col[1]; - r_col[2] += fac*col[2]; + r_col[0] += fac * col[0]; + r_col[1] += fac * col[1]; + r_col[2] += fac * col[2]; break; case MA_RAMP_MULT: - r_col[0] *= (facm + fac*col[0]); - r_col[1] *= (facm + fac*col[1]); - r_col[2] *= (facm + fac*col[2]); + r_col[0] *= (facm + fac * col[0]); + r_col[1] *= (facm + fac * col[1]); + r_col[2] *= (facm + fac * col[2]); break; case MA_RAMP_SCREEN: - r_col[0] = 1.0f - (facm + fac*(1.0f - col[0])) * (1.0f - r_col[0]); - r_col[1] = 1.0f - (facm + fac*(1.0f - col[1])) * (1.0f - r_col[1]); - r_col[2] = 1.0f - (facm + fac*(1.0f - col[2])) * (1.0f - r_col[2]); + r_col[0] = 1.0f - (facm + fac * (1.0f - col[0])) * (1.0f - r_col[0]); + r_col[1] = 1.0f - (facm + fac * (1.0f - col[1])) * (1.0f - r_col[1]); + r_col[2] = 1.0f - (facm + fac * (1.0f - col[2])) * (1.0f - r_col[2]); break; case MA_RAMP_OVERLAY: if (r_col[0] < 0.5f) - r_col[0] *= (facm + 2.0f*fac*col[0]); + r_col[0] *= (facm + 2.0f * fac * col[0]); else - r_col[0] = 1.0f - (facm + 2.0f*fac*(1.0f - col[0])) * (1.0f - r_col[0]); + r_col[0] = 1.0f - (facm + 2.0f * fac * (1.0f - col[0])) * (1.0f - r_col[0]); if (r_col[1] < 0.5f) - r_col[1] *= (facm + 2.0f*fac*col[1]); + r_col[1] *= (facm + 2.0f * fac * col[1]); else - r_col[1] = 1.0f - (facm + 2.0f*fac*(1.0f - col[1])) * (1.0f - r_col[1]); + r_col[1] = 1.0f - (facm + 2.0f * fac * (1.0f - col[1])) * (1.0f - r_col[1]); if (r_col[2] < 0.5f) - r_col[2] *= (facm + 2.0f*fac*col[2]); + r_col[2] *= (facm + 2.0f * fac * col[2]); else - r_col[2] = 1.0f - (facm + 2.0f*fac*(1.0f - col[2])) * (1.0f - r_col[2]); + r_col[2] = 1.0f - (facm + 2.0f * fac * (1.0f - col[2])) * (1.0f - r_col[2]); break; case MA_RAMP_SUB: - r_col[0] -= fac*col[0]; - r_col[1] -= fac*col[1]; - r_col[2] -= fac*col[2]; + r_col[0] -= fac * col[0]; + r_col[1] -= fac * col[1]; + r_col[2] -= fac * col[2]; break; case MA_RAMP_DIV: - if (col[0]!=0.0f) - r_col[0] = facm*(r_col[0]) + fac*(r_col[0])/col[0]; - if (col[1]!=0.0f) - r_col[1] = facm*(r_col[1]) + fac*(r_col[1])/col[1]; - if (col[2]!=0.0f) - r_col[2] = facm*(r_col[2]) + fac*(r_col[2])/col[2]; + if (col[0] != 0.0f) + r_col[0] = facm * (r_col[0]) + fac * (r_col[0]) / col[0]; + if (col[1] != 0.0f) + r_col[1] = facm * (r_col[1]) + fac * (r_col[1]) / col[1]; + if (col[2] != 0.0f) + r_col[2] = facm * (r_col[2]) + fac * (r_col[2]) / col[2]; break; case MA_RAMP_DIFF: - r_col[0] = facm*(r_col[0]) + fac*fabsf(r_col[0]-col[0]); - r_col[1] = facm*(r_col[1]) + fac*fabsf(r_col[1]-col[1]); - r_col[2] = facm*(r_col[2]) + fac*fabsf(r_col[2]-col[2]); + r_col[0] = facm * (r_col[0]) + fac *fabsf(r_col[0] - col[0]); + r_col[1] = facm * (r_col[1]) + fac *fabsf(r_col[1] - col[1]); + r_col[2] = facm * (r_col[2]) + fac *fabsf(r_col[2] - col[2]); break; case MA_RAMP_DARK: - tmp=col[0]+((1-col[0])*facm); - if (tmp < r_col[0]) r_col[0]= tmp; - tmp=col[1]+((1-col[1])*facm); - if (tmp < r_col[1]) r_col[1]= tmp; - tmp=col[2]+((1-col[2])*facm); - if (tmp < r_col[2]) r_col[2]= tmp; + tmp = col[0] + ((1 - col[0]) * facm); + if (tmp < r_col[0]) r_col[0] = tmp; + tmp = col[1] + ((1 - col[1]) * facm); + if (tmp < r_col[1]) r_col[1] = tmp; + tmp = col[2] + ((1 - col[2]) * facm); + if (tmp < r_col[2]) r_col[2] = tmp; break; case MA_RAMP_LIGHT: - tmp= fac*col[0]; - if (tmp > r_col[0]) r_col[0]= tmp; - tmp= fac*col[1]; - if (tmp > r_col[1]) r_col[1]= tmp; - tmp= fac*col[2]; - if (tmp > r_col[2]) r_col[2]= tmp; - break; + tmp = fac * col[0]; + if (tmp > r_col[0]) r_col[0] = tmp; + tmp = fac * col[1]; + if (tmp > r_col[1]) r_col[1] = tmp; + tmp = fac * col[2]; + if (tmp > r_col[2]) r_col[2] = tmp; + break; case MA_RAMP_DODGE: if (r_col[0] != 0.0f) { - tmp = 1.0f - fac*col[0]; + tmp = 1.0f - fac * col[0]; if (tmp <= 0.0f) r_col[0] = 1.0f; - else if ((tmp = (r_col[0]) / tmp)> 1.0f) + else if ((tmp = (r_col[0]) / tmp) > 1.0f) r_col[0] = 1.0f; else r_col[0] = tmp; } if (r_col[1] != 0.0f) { - tmp = 1.0f - fac*col[1]; - if (tmp <= 0.0f ) + tmp = 1.0f - fac * col[1]; + if (tmp <= 0.0f) r_col[1] = 1.0f; - else if ((tmp = (r_col[1]) / tmp) > 1.0f ) + else if ((tmp = (r_col[1]) / tmp) > 1.0f) r_col[1] = 1.0f; else r_col[1] = tmp; } if (r_col[2] != 0.0f) { - tmp = 1.0f - fac*col[2]; + tmp = 1.0f - fac * col[2]; if (tmp <= 0.0f) r_col[2] = 1.0f; - else if ((tmp = (r_col[2]) / tmp) > 1.0f ) + else if ((tmp = (r_col[2]) / tmp) > 1.0f) r_col[2] = 1.0f; else r_col[2] = tmp; } break; case MA_RAMP_BURN: - tmp = facm + fac*col[0]; + tmp = facm + fac * col[0]; if (tmp <= 0.0f) r_col[0] = 0.0f; - else if (( tmp = (1.0f - (1.0f - (r_col[0])) / tmp )) < 0.0f) - r_col[0] = 0.0f; + else if ((tmp = (1.0f - (1.0f - (r_col[0])) / tmp)) < 0.0f) + r_col[0] = 0.0f; else if (tmp > 1.0f) - r_col[0]=1.0f; + r_col[0] = 1.0f; else r_col[0] = tmp; - tmp = facm + fac*col[1]; + tmp = facm + fac * col[1]; if (tmp <= 0.0f) r_col[1] = 0.0f; - else if (( tmp = (1.0f - (1.0f - (r_col[1])) / tmp )) < 0.0f ) - r_col[1] = 0.0f; - else if (tmp >1.0f) - r_col[1]=1.0f; + else if ((tmp = (1.0f - (1.0f - (r_col[1])) / tmp)) < 0.0f) + r_col[1] = 0.0f; + else if (tmp > 1.0f) + r_col[1] = 1.0f; else r_col[1] = tmp; - tmp = facm + fac*col[2]; - if (tmp <= 0.0f) + tmp = facm + fac * col[2]; + if (tmp <= 0.0f) + r_col[2] = 0.0f; + else if ((tmp = (1.0f - (1.0f - (r_col[2])) / tmp)) < 0.0f) r_col[2] = 0.0f; - else if (( tmp = (1.0f - (1.0f - (r_col[2])) / tmp )) < 0.0f ) - r_col[2] = 0.0f; - else if (tmp >1.0f) - r_col[2]= 1.0f; + else if (tmp > 1.0f) + r_col[2] = 1.0f; else r_col[2] = tmp; break; case MA_RAMP_HUE: - { - float rH, rS, rV; - float colH, colS, colV; - float tmpr, tmpg, tmpb; - rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); - if (colS != 0) { - rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); - hsv_to_rgb(colH, rS, rV, &tmpr, &tmpg, &tmpb); - r_col[0] = facm*(r_col[0]) + fac*tmpr; - r_col[1] = facm*(r_col[1]) + fac*tmpg; - r_col[2] = facm*(r_col[2]) + fac*tmpb; - } - } - break; - case MA_RAMP_SAT: - { - float rH, rS, rV; - float colH, colS, colV; + { + float rH, rS, rV; + float colH, colS, colV; + float tmpr, tmpg, tmpb; + rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); + if (colS != 0) { rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); - if (rS != 0) { - rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); - hsv_to_rgb(rH, (facm*rS +fac*colS), rV, r_col+0, r_col+1, r_col+2); - } + hsv_to_rgb(colH, rS, rV, &tmpr, &tmpg, &tmpb); + r_col[0] = facm * (r_col[0]) + fac * tmpr; + r_col[1] = facm * (r_col[1]) + fac * tmpg; + r_col[2] = facm * (r_col[2]) + fac * tmpb; } - break; - case MA_RAMP_VAL: - { - float rH, rS, rV; - float colH, colS, colV; - rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); + } + break; + case MA_RAMP_SAT: + { + float rH, rS, rV; + float colH, colS, colV; + rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); + if (rS != 0) { rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); - hsv_to_rgb(rH, rS, (facm*rV +fac*colV), r_col+0, r_col+1, r_col+2); + hsv_to_rgb(rH, (facm * rS + fac * colS), rV, r_col + 0, r_col + 1, r_col + 2); } - break; + } + break; + case MA_RAMP_VAL: + { + float rH, rS, rV; + float colH, colS, colV; + rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); + rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); + hsv_to_rgb(rH, rS, (facm * rV + fac * colV), r_col + 0, r_col + 1, r_col + 2); + } + break; case MA_RAMP_COLOR: - { - float rH, rS, rV; - float colH, colS, colV; - float tmpr, tmpg, tmpb; - rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); - if (colS != 0) { - rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); - hsv_to_rgb(colH, colS, rV, &tmpr, &tmpg, &tmpb); - r_col[0] = facm*(r_col[0]) + fac*tmpr; - r_col[1] = facm*(r_col[1]) + fac*tmpg; - r_col[2] = facm*(r_col[2]) + fac*tmpb; - } + { + float rH, rS, rV; + float colH, colS, colV; + float tmpr, tmpg, tmpb; + rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV); + if (colS != 0) { + rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV); + hsv_to_rgb(colH, colS, rV, &tmpr, &tmpg, &tmpb); + r_col[0] = facm * (r_col[0]) + fac * tmpr; + r_col[1] = facm * (r_col[1]) + fac * tmpg; + r_col[2] = facm * (r_col[2]) + fac * tmpb; } - break; + } + break; case MA_RAMP_SOFT: - { - float scr, scg, scb; + { + float scr, scg, scb; - /* first calculate non-fac based Screen mix */ - scr = 1.0f - (1.0f - col[0]) * (1.0f - r_col[0]); - scg = 1.0f - (1.0f - col[1]) * (1.0f - r_col[1]); - scb = 1.0f - (1.0f - col[2]) * (1.0f - r_col[2]); + /* first calculate non-fac based Screen mix */ + scr = 1.0f - (1.0f - col[0]) * (1.0f - r_col[0]); + scg = 1.0f - (1.0f - col[1]) * (1.0f - r_col[1]); + scb = 1.0f - (1.0f - col[2]) * (1.0f - r_col[2]); - r_col[0] = facm*(r_col[0]) + fac*(((1.0f - r_col[0]) * col[0] * (r_col[0])) + (r_col[0] * scr)); - r_col[1] = facm*(r_col[1]) + fac*(((1.0f - r_col[1]) * col[1] * (r_col[1])) + (r_col[1] * scg)); - r_col[2] = facm*(r_col[2]) + fac*(((1.0f - r_col[2]) * col[2] * (r_col[2])) + (r_col[2] * scb)); - } - break; + r_col[0] = facm * (r_col[0]) + fac * (((1.0f - r_col[0]) * col[0] * (r_col[0])) + (r_col[0] * scr)); + r_col[1] = facm * (r_col[1]) + fac * (((1.0f - r_col[1]) * col[1] * (r_col[1])) + (r_col[1] * scg)); + r_col[2] = facm * (r_col[2]) + fac * (((1.0f - r_col[2]) * col[2] * (r_col[2])) + (r_col[2] * scb)); + } + break; case MA_RAMP_LINEAR: if (col[0] > 0.5f) - r_col[0] = r_col[0] + fac*(2.0f*(col[0]-0.5f)); + r_col[0] = r_col[0] + fac * (2.0f * (col[0] - 0.5f)); else - r_col[0] = r_col[0] + fac*(2.0f*(col[0]) - 1.0f); + r_col[0] = r_col[0] + fac * (2.0f * (col[0]) - 1.0f); if (col[1] > 0.5f) - r_col[1] = r_col[1] + fac*(2.0f*(col[1]-0.5f)); + r_col[1] = r_col[1] + fac * (2.0f * (col[1] - 0.5f)); else - r_col[1] = r_col[1] + fac*(2.0f*(col[1]) -1.0f); + r_col[1] = r_col[1] + fac * (2.0f * (col[1]) - 1.0f); if (col[2] > 0.5f) - r_col[2] = r_col[2] + fac*(2.0f*(col[2]-0.5f)); + r_col[2] = r_col[2] + fac * (2.0f * (col[2] - 0.5f)); else - r_col[2] = r_col[2] + fac*(2.0f*(col[2]) - 1.0f); + r_col[2] = r_col[2] + fac * (2.0f * (col[2]) - 1.0f); break; } } /* copy/paste buffer, if we had a propper py api that would be better */ static Material matcopybuf; -static short matcopied= 0; +static short matcopied = 0; void clear_matcopybuf(void) { memset(&matcopybuf, 0, sizeof(Material)); - matcopied= 0; + matcopied = 0; } void free_matcopybuf(void) { int a; - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (matcopybuf.mtex[a]) { MEM_freeN(matcopybuf.mtex[a]); - matcopybuf.mtex[a]= NULL; + matcopybuf.mtex[a] = NULL; } } if (matcopybuf.ramp_col) MEM_freeN(matcopybuf.ramp_col); if (matcopybuf.ramp_spec) MEM_freeN(matcopybuf.ramp_spec); - matcopybuf.ramp_col= NULL; - matcopybuf.ramp_spec= NULL; + matcopybuf.ramp_col = NULL; + matcopybuf.ramp_spec = NULL; if (matcopybuf.nodetree) { ntreeFreeTree(matcopybuf.nodetree); MEM_freeN(matcopybuf.nodetree); - matcopybuf.nodetree= NULL; + matcopybuf.nodetree = NULL; } - matcopied= 0; + matcopied = 0; } void copy_matcopybuf(Material *ma) @@ -1440,19 +1440,19 @@ void copy_matcopybuf(Material *ma) free_matcopybuf(); memcpy(&matcopybuf, ma, sizeof(Material)); - if (matcopybuf.ramp_col) matcopybuf.ramp_col= MEM_dupallocN(matcopybuf.ramp_col); - if (matcopybuf.ramp_spec) matcopybuf.ramp_spec= MEM_dupallocN(matcopybuf.ramp_spec); + if (matcopybuf.ramp_col) matcopybuf.ramp_col = MEM_dupallocN(matcopybuf.ramp_col); + if (matcopybuf.ramp_spec) matcopybuf.ramp_spec = MEM_dupallocN(matcopybuf.ramp_spec); - for (a=0; a<MAX_MTEX; a++) { - mtex= matcopybuf.mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = matcopybuf.mtex[a]; if (mtex) { - matcopybuf.mtex[a]= MEM_dupallocN(mtex); + matcopybuf.mtex[a] = MEM_dupallocN(mtex); } } - matcopybuf.nodetree= ntreeCopyTree(ma->nodetree); - matcopybuf.preview= NULL; - matcopybuf.gpumaterial.first= matcopybuf.gpumaterial.last= NULL; - matcopied= 1; + matcopybuf.nodetree = ntreeCopyTree(ma->nodetree); + matcopybuf.preview = NULL; + matcopybuf.gpumaterial.first = matcopybuf.gpumaterial.last = NULL; + matcopied = 1; } void paste_matcopybuf(Material *ma) @@ -1461,13 +1461,13 @@ void paste_matcopybuf(Material *ma) MTex *mtex; ID id; - if (matcopied==0) + if (matcopied == 0) return; /* free current mat */ if (ma->ramp_col) MEM_freeN(ma->ramp_col); if (ma->ramp_spec) MEM_freeN(ma->ramp_spec); - for (a=0; a<MAX_MTEX; a++) { - mtex= ma->mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = ma->mtex[a]; if (mtex && mtex->tex) mtex->tex->id.us--; if (mtex) MEM_freeN(mtex); } @@ -1479,22 +1479,22 @@ void paste_matcopybuf(Material *ma) GPU_material_free(ma); - id= (ma->id); + id = (ma->id); memcpy(ma, &matcopybuf, sizeof(Material)); - (ma->id)= id; + (ma->id) = id; - if (matcopybuf.ramp_col) ma->ramp_col= MEM_dupallocN(matcopybuf.ramp_col); - if (matcopybuf.ramp_spec) ma->ramp_spec= MEM_dupallocN(matcopybuf.ramp_spec); + if (matcopybuf.ramp_col) ma->ramp_col = MEM_dupallocN(matcopybuf.ramp_col); + if (matcopybuf.ramp_spec) ma->ramp_spec = MEM_dupallocN(matcopybuf.ramp_spec); - for (a=0; a<MAX_MTEX; a++) { - mtex= ma->mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = ma->mtex[a]; if (mtex) { - ma->mtex[a]= MEM_dupallocN(mtex); + ma->mtex[a] = MEM_dupallocN(mtex); if (mtex->tex) id_us_plus((ID *)mtex->tex); } } - ma->nodetree= ntreeCopyTree(matcopybuf.nodetree); + ma->nodetree = ntreeCopyTree(matcopybuf.nodetree); } @@ -1530,7 +1530,7 @@ static int encode_tfaceflag(MTFace *tf, int convertall) static void decode_tfaceflag(Material *ma, int flag, int convertall) { int alphablend; - GameSettings *game= &ma->game; + GameSettings *game = &ma->game; /* flag is shifted in 1 to make 0 != no flag yet (see encode_tfaceflag) */ flag -= 1; @@ -1539,7 +1539,7 @@ static void decode_tfaceflag(Material *ma, int flag, int convertall) (*game).flag = 0; /* General Material Options */ - if ((flag & TF_DYNAMIC)==0) (*game).flag |= GEMAT_NOPHYSICS; + if ((flag & TF_DYNAMIC) == 0) (*game).flag |= GEMAT_NOPHYSICS; /* Material Offline Rendering Properties */ if (convertall) { @@ -1547,8 +1547,8 @@ static void decode_tfaceflag(Material *ma, int flag, int convertall) } /* Special Face Properties */ - if ((flag & TF_TWOSIDE)==0) (*game).flag |= GEMAT_BACKCULL; - if (flag & TF_INVISIBLE)(*game).flag |= GEMAT_INVISIBLE; + if ((flag & TF_TWOSIDE) == 0) (*game).flag |= GEMAT_BACKCULL; + if (flag & TF_INVISIBLE) (*game).flag |= GEMAT_INVISIBLE; if (flag & TF_BMFONT) (*game).flag |= GEMAT_TEXT; /* Face Orientation */ @@ -1570,7 +1570,7 @@ static int check_tfaceneedmaterial(int flag) // also if only flags are visible and collision see if all objects using this mesh have this option in physics /* flag is shifted in 1 to make 0 != no flag yet (see encode_tfaceflag) */ - flag -=1; + flag -= 1; // deprecated flags flag &= ~TF_OBCOL; @@ -1597,11 +1597,11 @@ static int check_tfaceneedmaterial(int flag) // XXX to be optmized or replaced by an equivalent blender internal function static int integer_getdigits(int number) { - int i=0; + int i = 0; if (number == 0) return 1; while (number != 0) { - number = (int)(number/10); + number = (int)(number / 10); i++; } return i; @@ -1615,7 +1615,7 @@ static void calculate_tface_materialname(char *matname, char *newname, int flag) int digits = integer_getdigits(flag); /* clamp the old name, remove the MA prefix and add the .TF.flag suffix * e.g. matname = "MALoooooooooooooongName"; newname = "Loooooooooooooon.TF.2" */ - BLI_snprintf(newname, MAX_ID_NAME, "%.*s.TF.%0*d", MAX_ID_NAME-(digits+5), matname, digits, flag); + BLI_snprintf(newname, MAX_ID_NAME, "%.*s.TF.%0*d", MAX_ID_NAME - (digits + 5), matname, digits, flag); } /* returns -1 if no match */ @@ -1623,7 +1623,7 @@ static short mesh_getmaterialnumber(Mesh *me, Material *ma) { short a; - for (a=0; a<me->totcol; a++) { + for (a = 0; a < me->totcol; a++) { if (me->mat[a] == ma) { return a; } @@ -1636,11 +1636,11 @@ static short mesh_getmaterialnumber(Mesh *me, Material *ma) static short mesh_addmaterial(Mesh *me, Material *ma) { material_append_id(&me->id, NULL); - me->mat[me->totcol-1]= ma; + me->mat[me->totcol - 1] = ma; id_us_plus(&ma->id); - return me->totcol-1; + return me->totcol - 1; } static void set_facetexture_flags(Material *ma, Image *image) @@ -1659,26 +1659,26 @@ static short convert_tfacenomaterial(Main *main, Mesh *me, MTFace *tf, int flag) { Material *ma; char idname[MAX_ID_NAME]; - short mat_nr= -1; + short mat_nr = -1; /* new material, the name uses the flag*/ BLI_snprintf(idname, sizeof(idname), "MAMaterial.TF.%0*d", integer_getdigits(flag), flag); - if ((ma= BLI_findstring(&main->mat, idname+2, offsetof(ID, name)+2))) { - mat_nr= mesh_getmaterialnumber(me, ma); + if ((ma = BLI_findstring(&main->mat, idname + 2, offsetof(ID, name) + 2))) { + mat_nr = mesh_getmaterialnumber(me, ma); /* assign the material to the mesh */ - if (mat_nr == -1) mat_nr= mesh_addmaterial(me, ma); + if (mat_nr == -1) mat_nr = mesh_addmaterial(me, ma); /* if needed set "Face Textures [Alpha]" Material options */ set_facetexture_flags(ma, tf->tpage); } /* create a new material */ else { - ma= BKE_material_add(idname+2); + ma = BKE_material_add(idname + 2); if (ma) { - printf("TexFace Convert: Material \"%s\" created.\n", idname+2); - mat_nr= mesh_addmaterial(me, ma); + printf("TexFace Convert: Material \"%s\" created.\n", idname + 2); + mat_nr = mesh_addmaterial(me, ma); /* if needed set "Face Textures [Alpha]" Material options */ set_facetexture_flags(ma, tf->tpage); @@ -1690,7 +1690,7 @@ static short convert_tfacenomaterial(Main *main, Mesh *me, MTFace *tf, int flag) ma->game.flag = -flag; id_us_min((ID *)ma); } - else printf("Error: Unable to create Material \"%s\" for Mesh \"%s\".", idname+2, me->id.name+2); + else printf("Error: Unable to create Material \"%s\" for Mesh \"%s\".", idname + 2, me->id.name + 2); } /* set as converted, no need to go bad to this face */ @@ -1711,49 +1711,49 @@ static void convert_tfacematerial(Main *main, Material *ma) CustomDataLayer *cdl; char idname[MAX_ID_NAME]; - for (me=main->mesh.first; me; me=me->id.next) { + for (me = main->mesh.first; me; me = me->id.next) { /* check if this mesh uses this material */ - for (a=0;a<me->totcol;a++) + for (a = 0; a < me->totcol; a++) if (me->mat[a] == ma) break; /* no material found */ if (a == me->totcol) continue; /* get the active tface layer */ - index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); - cdl= (index == -1)? NULL: &me->fdata.layers[index]; + index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); + cdl = (index == -1) ? NULL : &me->fdata.layers[index]; if (!cdl) continue; /* loop over all the faces and stop at the ones that use the material*/ - for (a=0, mf=me->mface; a<me->totface; a++, mf++) { + for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { if (me->mat[mf->mat_nr] != ma) continue; /* texface data for this face */ - tf = ((MTFace*)cdl->data) + a; + tf = ((MTFace *)cdl->data) + a; flag = encode_tfaceflag(tf, 1); /* the name of the new material */ calculate_tface_materialname(ma->id.name, (char *)&idname, flag); - if ((mat_new= BLI_findstring(&main->mat, idname+2, offsetof(ID, name)+2))) { + if ((mat_new = BLI_findstring(&main->mat, idname + 2, offsetof(ID, name) + 2))) { /* material already existent, see if the mesh has it */ mat_nr = mesh_getmaterialnumber(me, mat_new); /* material is not in the mesh, add it */ - if (mat_nr == -1) mat_nr= mesh_addmaterial(me, mat_new); + if (mat_nr == -1) mat_nr = mesh_addmaterial(me, mat_new); } /* create a new material */ else { - mat_new=BKE_material_copy(ma); + mat_new = BKE_material_copy(ma); if (mat_new) { /* rename the material*/ strcpy(mat_new->id.name, idname); id_us_min((ID *)mat_new); - mat_nr= mesh_addmaterial(me, mat_new); + mat_nr = mesh_addmaterial(me, mat_new); decode_tfaceflag(mat_new, flag, 1); } else { - printf("Error: Unable to create Material \"%s\" for Mesh \"%s.", idname+2, me->id.name+2); + printf("Error: Unable to create Material \"%s\" for Mesh \"%s.", idname + 2, me->id.name + 2); mat_nr = mf->mat_nr; continue; } @@ -1770,8 +1770,8 @@ static void convert_tfacematerial(Main *main, Material *ma) mf->mat_nr = mat_nr; } /* remove material from mesh */ - for (a=0;a<me->totcol;) - if (me->mat[a] == ma) material_pop_id(&me->id, a, 1);else a++; + for (a = 0; a < me->totcol; ) + if (me->mat[a] == ma) material_pop_id(&me->id, a, 1); else a++; } } @@ -1805,20 +1805,20 @@ int do_version_tface(Main *main, int fileload) */ /* 1st part: marking mesh materials to update */ - for (me=main->mesh.first; me; me=me->id.next) { + for (me = main->mesh.first; me; me = me->id.next) { if (me->id.lib) continue; /* get the active tface layer */ - index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); - cdl= (index == -1)? NULL: &me->fdata.layers[index]; + index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); + cdl = (index == -1) ? NULL : &me->fdata.layers[index]; if (!cdl) continue; - nomaterialslots = (me->totcol==0?1:0); + nomaterialslots = (me->totcol == 0 ? 1 : 0); /* loop over all the faces*/ - for (a=0, mf=me->mface; a<me->totface; a++, mf++) { + for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { /* texface data for this face */ - tf = ((MTFace*)cdl->data) + a; + tf = ((MTFace *)cdl->data) + a; /* conversion should happen only once */ if (fileload) @@ -1834,7 +1834,7 @@ int do_version_tface(Main *main, int fileload) /* create/find a new material and assign to the face */ if (check_tfaceneedmaterial(flag)) { - mf->mat_nr= convert_tfacenomaterial(main, me, tf, flag); + mf->mat_nr = convert_tfacenomaterial(main, me, tf, flag); } /* else mark them as no-material to be reverted to 0 later */ else { @@ -1842,7 +1842,7 @@ int do_version_tface(Main *main, int fileload) } } else if (mf->mat_nr < me->totcol) { - ma= me->mat[mf->mat_nr]; + ma = me->mat[mf->mat_nr]; /* no material create one if necessary */ if (!ma) { @@ -1851,7 +1851,7 @@ int do_version_tface(Main *main, int fileload) /* create/find a new material and assign to the face */ if (check_tfaceneedmaterial(flag)) - mf->mat_nr= convert_tfacenomaterial(main, me, tf, flag); + mf->mat_nr = convert_tfacenomaterial(main, me, tf, flag); continue; } @@ -1869,11 +1869,11 @@ int do_version_tface(Main *main, int fileload) /* found a material */ else { - flag = encode_tfaceflag(tf, ((fileload)?0:1)); + flag = encode_tfaceflag(tf, ((fileload) ? 0 : 1)); /* first time changing this material */ if (ma->game.flag == 0) - ma->game.flag= -flag; + ma->game.flag = -flag; /* mark material as disputed */ else if (ma->game.flag != -flag) { @@ -1902,18 +1902,18 @@ int do_version_tface(Main *main, int fileload) /* if we didn't have material slot and now we do, we need to * make sure the materials are correct */ if (nomaterialslots) { - if (me->totcol>0) { - for (a=0, mf=me->mface; a<me->totface; a++, mf++) { + if (me->totcol > 0) { + for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { if (mf->mat_nr == -1) { /* texface data for this face */ - tf = ((MTFace*)cdl->data) + a; - mf->mat_nr= convert_tfacenomaterial(main, me, tf, encode_tfaceflag(tf, 1)); + tf = ((MTFace *)cdl->data) + a; + mf->mat_nr = convert_tfacenomaterial(main, me, tf, encode_tfaceflag(tf, 1)); } } } else { - for (a=0, mf=me->mface; a<me->totface; a++, mf++) { - mf->mat_nr=0; + for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { + mf->mat_nr = 0; } } } @@ -1924,14 +1924,14 @@ int do_version_tface(Main *main, int fileload) /* skip library files */ /* we shouldn't loop through the materials created in the loop. make the loop stop at its original length) */ - for (ma= main->mat.first, a=0; ma; ma= ma->id.next, a++) { + for (ma = main->mat.first, a = 0; ma; ma = ma->id.next, a++) { if (ma->id.lib) continue; /* disputed material */ if (ma->game.flag == MAT_BGE_DISPUTED) { ma->game.flag = 0; if (fileload) { - printf("Warning: material \"%s\" skipped - to convert old game texface to material go to the Help menu.\n", ma->id.name+2); + printf("Warning: material \"%s\" skipped - to convert old game texface to material go to the Help menu.\n", ma->id.name + 2); nowarning = 0; } else @@ -1947,24 +1947,24 @@ int do_version_tface(Main *main, int fileload) /* material is good make sure all faces using * this material are set to converted */ if (fileload) { - for (me=main->mesh.first; me; me=me->id.next) { + for (me = main->mesh.first; me; me = me->id.next) { /* check if this mesh uses this material */ - for (a=0;a<me->totcol;a++) + for (a = 0; a < me->totcol; a++) if (me->mat[a] == ma) break; /* no material found */ if (a == me->totcol) continue; /* get the active tface layer */ - index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); - cdl= (index == -1)? NULL: &me->fdata.layers[index]; + index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); + cdl = (index == -1) ? NULL : &me->fdata.layers[index]; if (!cdl) continue; /* loop over all the faces and stop at the ones that use the material*/ - for (a=0, mf=me->mface; a<me->totface; a++, mf++) { + for (a = 0, mf = me->mface; a < me->totface; a++, mf++) { if (me->mat[mf->mat_nr] == ma) { /* texface data for this face */ - tf = ((MTFace*)cdl->data) + a; + tf = ((MTFace *)cdl->data) + a; tf->mode |= TF_CONVERTED; } } diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index be6459bac90..ba0efe5fbba 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -67,67 +67,67 @@ /* Data types */ -typedef struct point { /* a three-dimensional point */ - float x, y, z; /* its coordinates */ +typedef struct point { /* a three-dimensional point */ + float x, y, z; /* its coordinates */ } MB_POINT; -typedef struct vertex { /* surface vertex */ - MB_POINT position, normal; /* position and surface normal */ +typedef struct vertex { /* surface vertex */ + MB_POINT position, normal; /* position and surface normal */ } VERTEX; -typedef struct vertices { /* list of vertices in polygonization */ - int count, max; /* # vertices, max # allowed */ - VERTEX *ptr; /* dynamically allocated */ +typedef struct vertices { /* list of vertices in polygonization */ + int count, max; /* # vertices, max # allowed */ + VERTEX *ptr; /* dynamically allocated */ } VERTICES; -typedef struct corner { /* corner of a cube */ - int i, j, k; /* (i, j, k) is index within lattice */ - float x, y, z, value; /* location and function value */ +typedef struct corner { /* corner of a cube */ + int i, j, k; /* (i, j, k) is index within lattice */ + float x, y, z, value; /* location and function value */ struct corner *next; } CORNER; -typedef struct cube { /* partitioning cell (cube) */ - int i, j, k; /* lattice location of cube */ - CORNER *corners[8]; /* eight corners */ +typedef struct cube { /* partitioning cell (cube) */ + int i, j, k; /* lattice location of cube */ + CORNER *corners[8]; /* eight corners */ } CUBE; -typedef struct cubes { /* linked list of cubes acting as stack */ - CUBE cube; /* a single cube */ - struct cubes *next; /* remaining elements */ +typedef struct cubes { /* linked list of cubes acting as stack */ + CUBE cube; /* a single cube */ + struct cubes *next; /* remaining elements */ } CUBES; -typedef struct centerlist { /* list of cube locations */ - int i, j, k; /* cube location */ - struct centerlist *next; /* remaining elements */ +typedef struct centerlist { /* list of cube locations */ + int i, j, k; /* cube location */ + struct centerlist *next; /* remaining elements */ } CENTERLIST; -typedef struct edgelist { /* list of edges */ - int i1, j1, k1, i2, j2, k2; /* edge corner ids */ - int vid; /* vertex id */ - struct edgelist *next; /* remaining elements */ +typedef struct edgelist { /* list of edges */ + int i1, j1, k1, i2, j2, k2; /* edge corner ids */ + int vid; /* vertex id */ + struct edgelist *next; /* remaining elements */ } EDGELIST; -typedef struct intlist { /* list of integers */ - int i; /* an integer */ - struct intlist *next; /* remaining elements */ +typedef struct intlist { /* list of integers */ + int i; /* an integer */ + struct intlist *next; /* remaining elements */ } INTLIST; -typedef struct intlists { /* list of list of integers */ - INTLIST *list; /* a list of integers */ - struct intlists *next; /* remaining elements */ +typedef struct intlists { /* list of list of integers */ + INTLIST *list; /* a list of integers */ + struct intlists *next; /* remaining elements */ } INTLISTS; -typedef struct process { /* parameters, function, storage */ +typedef struct process { /* parameters, function, storage */ /* what happens here? floats, I think. */ /* float (*function)(void); */ /* implicit surface function */ float (*function)(float, float, float); - float size, delta; /* cube size, normal delta */ - int bounds; /* cube range within lattice */ - CUBES *cubes; /* active cubes */ - VERTICES vertices; /* surface vertices */ - CENTERLIST **centers; /* cube center hash table */ - CORNER **corners; /* corner value hash table */ - EDGELIST **edges; /* edge and vertex id hash table */ + float size, delta; /* cube size, normal delta */ + int bounds; /* cube range within lattice */ + CUBES *cubes; /* active cubes */ + VERTICES vertices; /* surface vertices */ + CENTERLIST **centers; /* cube center hash table */ + CORNER **corners; /* corner value hash table */ + EDGELIST **edges; /* edge and vertex id hash table */ } PROCESS; /* dividing scene using octal tree makes polygonisation faster */ @@ -137,20 +137,20 @@ typedef struct ml_pointer { } ml_pointer; typedef struct octal_node { - struct octal_node *nodes[8]; /* children of current node */ - struct octal_node *parent; /* parent of current node */ - struct ListBase elems; /* ListBase of MetaElem pointers (ml_pointer) */ - float x_min, y_min, z_min; /* 1st border point */ - float x_max, y_max, z_max; /* 7th border point */ - float x, y, z; /* center of node */ - int pos, neg; /* number of positive and negative MetaElements in the node */ - int count; /* number of MetaElems, which belongs to the node */ + struct octal_node *nodes[8];/* children of current node */ + struct octal_node *parent; /* parent of current node */ + struct ListBase elems; /* ListBase of MetaElem pointers (ml_pointer) */ + float x_min, y_min, z_min; /* 1st border point */ + float x_max, y_max, z_max; /* 7th border point */ + float x, y, z; /* center of node */ + int pos, neg; /* number of positive and negative MetaElements in the node */ + int count; /* number of MetaElems, which belongs to the node */ } octal_node; typedef struct octal_tree { - struct octal_node *first; /* first node */ - int pos, neg; /* number of positive and negative MetaElements in the scene */ - short depth; /* number of scene subdivision */ + struct octal_node *first; /* first node */ + int pos, neg; /* number of positive and negative MetaElements in the scene */ + short depth; /* number of scene subdivision */ } octal_tree; struct pgn_elements { @@ -161,14 +161,14 @@ struct pgn_elements { /* Forward declarations */ static int vertid(CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb); static int setcenter(CENTERLIST *table[], int i, int j, int k); -static CORNER *setcorner(PROCESS* p, int i, int j, int k); -static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, - float (*function)(float, float, float), MB_POINT *p, MetaBall *mb, int f); +static CORNER *setcorner(PROCESS *p, int i, int j, int k); +static void converge(MB_POINT *p1, MB_POINT *p2, float v1, float v2, + float (*function)(float, float, float), MB_POINT *p, MetaBall *mb, int f); /* Global variables */ -static float thresh= 0.6f; -static int totelem=0; +static float thresh = 0.6f; +static int totelem = 0; static MetaElem **mainb; static octal_tree *metaball_tree = NULL; /* Functions */ @@ -177,9 +177,9 @@ void BKE_metaball_unlink(MetaBall *mb) { int a; - for (a=0; a<mb->totcol; a++) { + for (a = 0; a < mb->totcol; a++) { if (mb->mat[a]) mb->mat[a]->id.us--; - mb->mat[a]= NULL; + mb->mat[a] = NULL; } } @@ -203,14 +203,14 @@ MetaBall *BKE_metaball_add(const char *name) { MetaBall *mb; - mb= BKE_libblock_alloc(&G.main->mball, ID_MB, name); + mb = BKE_libblock_alloc(&G.main->mball, ID_MB, name); - mb->size[0]= mb->size[1]= mb->size[2]= 1.0; - mb->texflag= MB_AUTOSPACE; + mb->size[0] = mb->size[1] = mb->size[2] = 1.0; + mb->texflag = MB_AUTOSPACE; - mb->wiresize= 0.4f; - mb->rendersize= 0.2f; - mb->thresh= 0.6f; + mb->wiresize = 0.4f; + mb->rendersize = 0.2f; + mb->thresh = 0.6f; return mb; } @@ -220,18 +220,18 @@ MetaBall *BKE_metaball_copy(MetaBall *mb) MetaBall *mbn; int a; - mbn= BKE_libblock_copy(&mb->id); + mbn = BKE_libblock_copy(&mb->id); BLI_duplicatelist(&mbn->elems, &mb->elems); - mbn->mat= MEM_dupallocN(mb->mat); - for (a=0; a<mbn->totcol; a++) { + mbn->mat = MEM_dupallocN(mb->mat); + for (a = 0; a < mbn->totcol; a++) { id_us_plus((ID *)mbn->mat[a]); } - mbn->bb= MEM_dupallocN(mb->bb); + mbn->bb = MEM_dupallocN(mb->bb); - mbn->editelems= NULL; - mbn->lastelem= NULL; + mbn->editelems = NULL; + mbn->lastelem = NULL; return mbn; } @@ -245,27 +245,27 @@ static void extern_local_mball(MetaBall *mb) void BKE_metaball_make_local(MetaBall *mb) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (mb->id.lib==NULL) return; - if (mb->id.us==1) { + if (mb->id.lib == NULL) return; + if (mb->id.us == 1) { id_clear_lib_data(bmain, &mb->id); extern_local_mball(mb); return; } - for (ob= G.main->object.first; ob && ELEM(0, is_lib, is_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) is_lib= TRUE; - else is_local= TRUE; + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } @@ -274,16 +274,16 @@ void BKE_metaball_make_local(MetaBall *mb) extern_local_mball(mb); } else if (is_local && is_lib) { - MetaBall *mb_new= BKE_metaball_copy(mb); - mb_new->id.us= 0; + MetaBall *mb_new = BKE_metaball_copy(mb); + mb_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, mb->id.lib, &mb_new->id); - for (ob= G.main->object.first; ob; ob= ob->id.next) { + for (ob = G.main->object.first; ob; ob = ob->id.next) { if (ob->data == mb) { - if (ob->id.lib==NULL) { - ob->data= mb_new; + if (ob->id.lib == NULL) { + ob->data = mb_new; mb_new->id.us++; mb->id.us--; } @@ -296,44 +296,44 @@ void BKE_metaball_make_local(MetaBall *mb) * don't do context manipulation here (rna uses) */ MetaElem *BKE_metaball_element_add(MetaBall *mb, const int type) { - MetaElem *ml= MEM_callocN(sizeof(MetaElem), "metaelem"); + MetaElem *ml = MEM_callocN(sizeof(MetaElem), "metaelem"); unit_qt(ml->quat); - ml->rad= 2.0; - ml->s= 2.0; - ml->flag= MB_SCALE_RAD; + ml->rad = 2.0; + ml->s = 2.0; + ml->flag = MB_SCALE_RAD; switch (type) { - case MB_BALL: - ml->type = MB_BALL; - ml->expx= ml->expy= ml->expz= 1.0; - - break; - case MB_TUBE: - ml->type = MB_TUBE; - ml->expx= ml->expy= ml->expz= 1.0; - - break; - case MB_PLANE: - ml->type = MB_PLANE; - ml->expx= ml->expy= ml->expz= 1.0; - - break; - case MB_ELIPSOID: - ml->type = MB_ELIPSOID; - ml->expx= 1.2f; - ml->expy= 0.8f; - ml->expz= 1.0; - - break; - case MB_CUBE: - ml->type = MB_CUBE; - ml->expx= ml->expy= ml->expz= 1.0; + case MB_BALL: + ml->type = MB_BALL; + ml->expx = ml->expy = ml->expz = 1.0; + + break; + case MB_TUBE: + ml->type = MB_TUBE; + ml->expx = ml->expy = ml->expz = 1.0; + + break; + case MB_PLANE: + ml->type = MB_PLANE; + ml->expx = ml->expy = ml->expz = 1.0; + + break; + case MB_ELIPSOID: + ml->type = MB_ELIPSOID; + ml->expx = 1.2f; + ml->expy = 0.8f; + ml->expz = 1.0; + + break; + case MB_CUBE: + ml->type = MB_CUBE; + ml->expx = ml->expy = ml->expz = 1.0; - break; - default: - break; + break; + default: + break; } BLI_addtail(&mb->elems, ml); @@ -351,27 +351,27 @@ void BKE_metaball_texspace_calc(Object *ob) DispList *dl; BoundBox *bb; float *data, min[3], max[3] /*, loc[3], size[3] */; - int tot, doit=0; + int tot, doit = 0; - if (ob->bb==NULL) ob->bb= MEM_callocN(sizeof(BoundBox), "mb boundbox"); - bb= ob->bb; + if (ob->bb == NULL) ob->bb = MEM_callocN(sizeof(BoundBox), "mb boundbox"); + bb = ob->bb; /* Weird one, this. */ -/* INIT_MINMAX(min, max); */ - (min)[0]= (min)[1]= (min)[2]= 1.0e30f; - (max)[0]= (max)[1]= (max)[2]= -1.0e30f; +/* INIT_MINMAX(min, max); */ + (min)[0] = (min)[1] = (min)[2] = 1.0e30f; + (max)[0] = (max)[1] = (max)[2] = -1.0e30f; - dl= ob->disp.first; + dl = ob->disp.first; while (dl) { - tot= dl->nr; - if (tot) doit= 1; - data= dl->verts; + tot = dl->nr; + if (tot) doit = 1; + data = dl->verts; while (tot--) { /* Also weird... but longer. From utildefines. */ DO_MINMAX(data, min, max); - data+= 3; + data += 3; } - dl= dl->next; + dl = dl->next; } if (!doit) { @@ -379,13 +379,13 @@ void BKE_metaball_texspace_calc(Object *ob) max[0] = max[1] = max[2] = 1.0f; } #if 0 - loc[0]= (min[0]+max[0])/2.0f; - loc[1]= (min[1]+max[1])/2.0f; - loc[2]= (min[2]+max[2])/2.0f; - - size[0]= (max[0]-min[0])/2.0f; - size[1]= (max[1]-min[1])/2.0f; - size[2]= (max[2]-min[2])/2.0f; + loc[0] = (min[0] + max[0]) / 2.0f; + loc[1] = (min[1] + max[1]) / 2.0f; + loc[2] = (min[2] + max[2]) / 2.0f; + + size[0] = (max[0] - min[0]) / 2.0f; + size[1] = (max[1] - min[1]) / 2.0f; + size[2] = (max[2] - min[2]) / 2.0f; #endif BKE_boundbox_init_from_minmax(bb, min, max); } @@ -399,27 +399,27 @@ float *BKE_metaball_make_orco(Object *ob, ListBase *dispbase) int a; /* restore size and loc */ - bb= ob->bb; - loc[0]= (bb->vec[0][0]+bb->vec[4][0])/2.0f; - size[0]= bb->vec[4][0]-loc[0]; - loc[1]= (bb->vec[0][1]+bb->vec[2][1])/2.0f; - size[1]= bb->vec[2][1]-loc[1]; - loc[2]= (bb->vec[0][2]+bb->vec[1][2])/2.0f; - size[2]= bb->vec[1][2]-loc[2]; - - dl= dispbase->first; - orcodata= MEM_mallocN(sizeof(float)*3*dl->nr, "MballOrco"); - - data= dl->verts; - orco= orcodata; - a= dl->nr; + bb = ob->bb; + loc[0] = (bb->vec[0][0] + bb->vec[4][0]) / 2.0f; + size[0] = bb->vec[4][0] - loc[0]; + loc[1] = (bb->vec[0][1] + bb->vec[2][1]) / 2.0f; + size[1] = bb->vec[2][1] - loc[1]; + loc[2] = (bb->vec[0][2] + bb->vec[1][2]) / 2.0f; + size[2] = bb->vec[1][2] - loc[2]; + + dl = dispbase->first; + orcodata = MEM_mallocN(sizeof(float) * 3 * dl->nr, "MballOrco"); + + data = dl->verts; + orco = orcodata; + a = dl->nr; while (a--) { - orco[0]= (data[0]-loc[0])/size[0]; - orco[1]= (data[1]-loc[1])/size[1]; - orco[2]= (data[2]-loc[2])/size[2]; + orco[0] = (data[0] - loc[0]) / size[0]; + orco[1] = (data[1] - loc[1]) / size[1]; + orco[2] = (data[2] - loc[2]) / size[2]; - data+= 3; - orco+= 3; + data += 3; + orco += 3; } return orcodata; @@ -447,8 +447,8 @@ int BKE_metaball_is_basis(Object *ob) int len; /* just a quick test */ - len= strlen(ob->id.name); - if ( isdigit(ob->id.name[len-1]) ) return 0; + len = strlen(ob->id.name); + if (isdigit(ob->id.name[len - 1]) ) return 0; return 1; } @@ -458,8 +458,8 @@ int BKE_metaball_is_basis_for(Object *ob1, Object *ob2) int basis1nr, basis2nr; char basis1name[MAX_ID_NAME], basis2name[MAX_ID_NAME]; - BLI_split_name_num(basis1name, &basis1nr, ob1->id.name+2, '.'); - BLI_split_name_num(basis2name, &basis2nr, ob2->id.name+2, '.'); + BLI_split_name_num(basis1name, &basis1nr, ob1->id.name + 2, '.'); + BLI_split_name_num(basis2name, &basis2nr, ob2->id.name + 2, '.'); if (!strcmp(basis1name, basis2name)) return BKE_metaball_is_basis(ob1); else return 0; @@ -473,34 +473,34 @@ int BKE_metaball_is_basis_for(Object *ob1, Object *ob2) * because this metaball influence polygonisation of metaballs. */ void BKE_metaball_properties_copy(Scene *scene, Object *active_object) { - Scene *sce_iter= scene; + Scene *sce_iter = scene; Base *base; Object *ob; - MetaBall *active_mball = (MetaBall*)active_object->data; + MetaBall *active_mball = (MetaBall *)active_object->data; int basisnr, obnr; char basisname[MAX_ID_NAME], obname[MAX_ID_NAME]; - BLI_split_name_num(basisname, &basisnr, active_object->id.name+2, '.'); + BLI_split_name_num(basisname, &basisnr, active_object->id.name + 2, '.'); /* XXX recursion check, see scene.c, just too simple code this BKE_scene_base_iter_next() */ - if (F_ERROR==BKE_scene_base_iter_next(&sce_iter, 0, NULL, NULL)) + if (F_ERROR == BKE_scene_base_iter_next(&sce_iter, 0, NULL, NULL)) return; while (BKE_scene_base_iter_next(&sce_iter, 1, &base, &ob)) { - if (ob->type==OB_MBALL) { + if (ob->type == OB_MBALL) { if (ob != active_object) { - BLI_split_name_num(obname, &obnr, ob->id.name+2, '.'); + BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.'); /* Object ob has to be in same "group" ... it means, that it has to have * same base of its name */ - if (strcmp(obname, basisname)==0) { - MetaBall *mb= ob->data; + if (strcmp(obname, basisname) == 0) { + MetaBall *mb = ob->data; /* Copy properties from selected/edited metaball */ - mb->wiresize= active_mball->wiresize; - mb->rendersize= active_mball->rendersize; - mb->thresh= active_mball->thresh; - mb->flag= active_mball->flag; + mb->wiresize = active_mball->wiresize; + mb->rendersize = active_mball->rendersize; + mb->thresh = active_mball->thresh; + mb->flag = active_mball->flag; } } } @@ -518,50 +518,50 @@ void BKE_metaball_properties_copy(Scene *scene, Object *active_object) */ Object *BKE_metaball_basis_find(Scene *scene, Object *basis) { - Scene *sce_iter= scene; + Scene *sce_iter = scene; Base *base; - Object *ob, *bob= basis; - MetaElem *ml=NULL; + Object *ob, *bob = basis; + MetaElem *ml = NULL; int basisnr, obnr; char basisname[MAX_ID_NAME], obname[MAX_ID_NAME]; - BLI_split_name_num(basisname, &basisnr, basis->id.name+2, '.'); - totelem= 0; + BLI_split_name_num(basisname, &basisnr, basis->id.name + 2, '.'); + totelem = 0; /* XXX recursion check, see scene.c, just too simple code this BKE_scene_base_iter_next() */ - if (F_ERROR==BKE_scene_base_iter_next(&sce_iter, 0, NULL, NULL)) + if (F_ERROR == BKE_scene_base_iter_next(&sce_iter, 0, NULL, NULL)) return NULL; while (BKE_scene_base_iter_next(&sce_iter, 1, &base, &ob)) { - if (ob->type==OB_MBALL) { - if (ob==bob) { - MetaBall *mb= ob->data; + if (ob->type == OB_MBALL) { + if (ob == bob) { + MetaBall *mb = ob->data; /* if bob object is in edit mode, then dynamic list of all MetaElems * is stored in editelems */ - if (mb->editelems) ml= mb->editelems->first; + if (mb->editelems) ml = mb->editelems->first; /* if bob object is in object mode */ - else ml= mb->elems.first; + else ml = mb->elems.first; } else { - BLI_split_name_num(obname, &obnr, ob->id.name+2, '.'); + BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.'); /* object ob has to be in same "group" ... it means, that it has to have * same base of its name */ - if (strcmp(obname, basisname)==0) { - MetaBall *mb= ob->data; + if (strcmp(obname, basisname) == 0) { + MetaBall *mb = ob->data; /* if object is in edit mode, then dynamic list of all MetaElems * is stored in editelems */ - if (mb->editelems) ml= mb->editelems->first; + if (mb->editelems) ml = mb->editelems->first; /* if bob object is in object mode */ - else ml= mb->elems.first; + else ml = mb->elems.first; if (obnr < basisnr) { if (!(ob->flag & OB_FROMDUPLI)) { - basis= ob; - basisnr= obnr; + basis = ob; + basisnr = obnr; } } } @@ -569,7 +569,7 @@ Object *BKE_metaball_basis_find(Scene *scene, Object *basis) while (ml) { if (!(ml->flag & MB_HIDE)) totelem++; - ml= ml->next; + ml = ml->next; } } } @@ -591,33 +591,33 @@ Object *BKE_metaball_basis_find(Scene *scene, Object *basis) * Permission is granted to reproduce, use and distribute this code for * any and all purposes, provided that this notice appears in all copies. */ -#define RES 12 /* # converge iterations */ - -#define L 0 /* left direction: -x, -i */ -#define R 1 /* right direction: +x, +i */ -#define B 2 /* bottom direction: -y, -j */ -#define T 3 /* top direction: +y, +j */ -#define N 4 /* near direction: -z, -k */ -#define F 5 /* far direction: +z, +k */ -#define LBN 0 /* left bottom near corner */ -#define LBF 1 /* left bottom far corner */ -#define LTN 2 /* left top near corner */ -#define LTF 3 /* left top far corner */ -#define RBN 4 /* right bottom near corner */ -#define RBF 5 /* right bottom far corner */ -#define RTN 6 /* right top near corner */ -#define RTF 7 /* right top far corner */ +#define RES 12 /* # converge iterations */ + +#define L 0 /* left direction: -x, -i */ +#define R 1 /* right direction: +x, +i */ +#define B 2 /* bottom direction: -y, -j */ +#define T 3 /* top direction: +y, +j */ +#define N 4 /* near direction: -z, -k */ +#define F 5 /* far direction: +z, +k */ +#define LBN 0 /* left bottom near corner */ +#define LBF 1 /* left bottom far corner */ +#define LTN 2 /* left top near corner */ +#define LTF 3 /* left top far corner */ +#define RBN 4 /* right bottom near corner */ +#define RBF 5 /* right bottom far corner */ +#define RTN 6 /* right top near corner */ +#define RTF 7 /* right top far corner */ /* the LBN corner of cube (i, j, k), corresponds with location * (i-0.5)*size, (j-0.5)*size, (k-0.5)*size) */ -#define HASHBIT (5) -#define HASHSIZE (size_t)(1<<(3*HASHBIT)) /*! < hash table size (32768) */ +#define HASHBIT (5) +#define HASHSIZE (size_t)(1 << (3 * HASHBIT)) /*! < hash table size (32768) */ -#define HASH(i, j, k) ((((( (i) & 31)<<5) | ( (j) & 31))<<5 ) | ( (k) & 31) ) +#define HASH(i, j, k) ((((( (i) & 31) << 5) | ( (j) & 31)) << 5) | ( (k) & 31) ) -#define MB_BIT(i, bit) (((i)>>(bit))&1) -#define FLIP(i, bit) ((i)^1<<(bit)) /* flip the given bit of i */ +#define MB_BIT(i, bit) (((i) >> (bit)) & 1) +#define FLIP(i, bit) ((i) ^ 1 << (bit)) /* flip the given bit of i */ /* **************** POLYGONIZATION ************************ */ @@ -634,78 +634,78 @@ static float densfunc(MetaElem *ball, float x, float y, float z) float dist2 = 0.0, dx, dy, dz; float vec[3]; - vec[0]= x; - vec[1]= y; - vec[2]= z; + vec[0] = x; + vec[1] = y; + vec[2] = z; mul_m4_v3((float (*)[4])ball->imat, vec); - dx= vec[0]; - dy= vec[1]; - dz= vec[2]; - - if (ball->type==MB_BALL) { - } - else if (ball->type==MB_TUBEX) { - if ( dx > ball->len) dx-= ball->len; - else if (dx< -ball->len) dx+= ball->len; - else dx= 0.0; - } - else if (ball->type==MB_TUBEY) { - if ( dy > ball->len) dy-= ball->len; - else if (dy< -ball->len) dy+= ball->len; - else dy= 0.0; - } - else if (ball->type==MB_TUBEZ) { - if ( dz > ball->len) dz-= ball->len; - else if (dz< -ball->len) dz+= ball->len; - else dz= 0.0; - } - else if (ball->type==MB_TUBE) { - if ( dx > ball->expx) dx-= ball->expx; - else if (dx< -ball->expx) dx+= ball->expx; - else dx= 0.0; - } - else if (ball->type==MB_PLANE) { - if ( dx > ball->expx) dx-= ball->expx; - else if (dx< -ball->expx) dx+= ball->expx; - else dx= 0.0; - if ( dy > ball->expy) dy-= ball->expy; - else if (dy< -ball->expy) dy+= ball->expy; - else dy= 0.0; - } - else if (ball->type==MB_ELIPSOID) { - dx *= 1/ball->expx; - dy *= 1/ball->expy; - dz *= 1/ball->expz; - } - else if (ball->type==MB_CUBE) { - if ( dx > ball->expx) dx-= ball->expx; - else if (dx< -ball->expx) dx+= ball->expx; - else dx= 0.0; - if ( dy > ball->expy) dy-= ball->expy; - else if (dy< -ball->expy) dy+= ball->expy; - else dy= 0.0; - if ( dz > ball->expz) dz-= ball->expz; - else if (dz< -ball->expz) dz+= ball->expz; - else dz= 0.0; - } - - dist2= (dx*dx + dy*dy + dz*dz); + dx = vec[0]; + dy = vec[1]; + dz = vec[2]; + + if (ball->type == MB_BALL) { + } + else if (ball->type == MB_TUBEX) { + if (dx > ball->len) dx -= ball->len; + else if (dx < -ball->len) dx += ball->len; + else dx = 0.0; + } + else if (ball->type == MB_TUBEY) { + if (dy > ball->len) dy -= ball->len; + else if (dy < -ball->len) dy += ball->len; + else dy = 0.0; + } + else if (ball->type == MB_TUBEZ) { + if (dz > ball->len) dz -= ball->len; + else if (dz < -ball->len) dz += ball->len; + else dz = 0.0; + } + else if (ball->type == MB_TUBE) { + if (dx > ball->expx) dx -= ball->expx; + else if (dx < -ball->expx) dx += ball->expx; + else dx = 0.0; + } + else if (ball->type == MB_PLANE) { + if (dx > ball->expx) dx -= ball->expx; + else if (dx < -ball->expx) dx += ball->expx; + else dx = 0.0; + if (dy > ball->expy) dy -= ball->expy; + else if (dy < -ball->expy) dy += ball->expy; + else dy = 0.0; + } + else if (ball->type == MB_ELIPSOID) { + dx *= 1 / ball->expx; + dy *= 1 / ball->expy; + dz *= 1 / ball->expz; + } + else if (ball->type == MB_CUBE) { + if (dx > ball->expx) dx -= ball->expx; + else if (dx < -ball->expx) dx += ball->expx; + else dx = 0.0; + if (dy > ball->expy) dy -= ball->expy; + else if (dy < -ball->expy) dy += ball->expy; + else dy = 0.0; + if (dz > ball->expz) dz -= ball->expz; + else if (dz < -ball->expz) dz += ball->expz; + else dz = 0.0; + } + + dist2 = (dx * dx + dy * dy + dz * dz); if (ball->flag & MB_NEGATIVE) { - dist2= 1.0f-(dist2/ball->rad2); + dist2 = 1.0f - (dist2 / ball->rad2); if (dist2 < 0.0f) return 0.5f; - return 0.5f-ball->s*dist2*dist2*dist2; + return 0.5f - ball->s * dist2 * dist2 * dist2; } else { - dist2= 1.0f-(dist2/ball->rad2); + dist2 = 1.0f - (dist2 / ball->rad2); if (dist2 < 0.0f) return -0.5f; - return ball->s*dist2*dist2*dist2 -0.5f; + return ball->s * dist2 * dist2 * dist2 - 0.5f; } } -static octal_node* find_metaball_octal_node(octal_node *node, float x, float y, float z, short depth) +static octal_node *find_metaball_octal_node(octal_node *node, float x, float y, float z, short depth) { if (!depth) return node; @@ -778,24 +778,24 @@ static float metaball(float x, float y, float z) { struct octal_node *node; struct ml_pointer *ml_p; - float dens=0; + float dens = 0; int a; if (totelem > 1) { - node= find_metaball_octal_node(metaball_tree->first, x, y, z, metaball_tree->depth); + node = find_metaball_octal_node(metaball_tree->first, x, y, z, metaball_tree->depth); if (node) { - ml_p= node->elems.first; + ml_p = node->elems.first; while (ml_p) { - dens+=densfunc(ml_p->ml, x, y, z); - ml_p= ml_p->next; + dens += densfunc(ml_p->ml, x, y, z); + ml_p = ml_p->next; } - dens+= -0.5f*(metaball_tree->pos - node->pos); - dens+= 0.5f*(metaball_tree->neg - node->neg); + dens += -0.5f * (metaball_tree->pos - node->pos); + dens += 0.5f * (metaball_tree->neg - node->neg); } else { - for (a=0; a<totelem; a++) { + for (a = 0; a < totelem; a++) { dens += densfunc(mainb[a], x, y, z); } } @@ -809,7 +809,7 @@ static float metaball(float x, float y, float z) /* ******************************************** */ -static int *indices=NULL; +static int *indices = NULL; static int totindex, curindex; @@ -818,28 +818,28 @@ static void accum_mballfaces(int i1, int i2, int i3, int i4) int *newi, *cur; /* static int i=0; I would like to delete altogether, but I don't dare to, yet */ - if (totindex==curindex) { - totindex+= 256; - newi= MEM_mallocN(4*sizeof(int)*totindex, "vertindex"); + if (totindex == curindex) { + totindex += 256; + newi = MEM_mallocN(4 * sizeof(int) * totindex, "vertindex"); if (indices) { - memcpy(newi, indices, 4*sizeof(int)*(totindex-256)); + memcpy(newi, indices, 4 * sizeof(int) * (totindex - 256)); MEM_freeN(indices); } - indices= newi; + indices = newi; } - cur= indices+4*curindex; + cur = indices + 4 * curindex; /* displists now support array drawing, we treat tri's as fake quad */ - cur[0]= i1; - cur[1]= i2; - cur[2]= i3; - if (i4==0) - cur[3]= i3; + cur[0] = i1; + cur[1] = i2; + cur[2] = i3; + if (i4 == 0) + cur[3] = i3; else - cur[3]= i4; + cur[3] = i4; curindex++; @@ -851,41 +851,41 @@ static void *new_pgn_element(int size) /* during polygonize 1000s of elements are allocated * and never freed in between. Freeing only done at the end. */ - int blocksize= 16384; - static int offs= 0; /* the current free address */ - static struct pgn_elements *cur= NULL; - static ListBase lb= {NULL, NULL}; + int blocksize = 16384; + static int offs = 0; /* the current free address */ + static struct pgn_elements *cur = NULL; + static ListBase lb = {NULL, NULL}; void *adr; - if (size>10000 || size==0) { + if (size > 10000 || size == 0) { printf("incorrect use of new_pgn_element\n"); } - else if (size== -1) { - cur= lb.first; + else if (size == -1) { + cur = lb.first; while (cur) { MEM_freeN(cur->data); - cur= cur->next; + cur = cur->next; } BLI_freelistN(&lb); return NULL; } - size= 4*( (size+3)/4 ); + size = 4 * ( (size + 3) / 4); if (cur) { - if (size+offs < blocksize) { - adr= (void *) (cur->data+offs); - offs+= size; + if (size + offs < blocksize) { + adr = (void *) (cur->data + offs); + offs += size; return adr; } } - cur= MEM_callocN(sizeof(struct pgn_elements), "newpgn"); - cur->data= MEM_callocN(blocksize, "newpgn"); + cur = MEM_callocN(sizeof(struct pgn_elements), "newpgn"); + cur->data = MEM_callocN(blocksize, "newpgn"); BLI_addtail(&lb, cur); - offs= size; + offs = size; return cur->data; } @@ -902,31 +902,35 @@ static void freepolygonize(PROCESS *p) /**** Cubical Polygonization (optional) ****/ -#define LB 0 /* left bottom edge */ -#define LT 1 /* left top edge */ -#define LN 2 /* left near edge */ -#define LF 3 /* left far edge */ -#define RB 4 /* right bottom edge */ -#define RT 5 /* right top edge */ -#define RN 6 /* right near edge */ -#define RF 7 /* right far edge */ -#define BN 8 /* bottom near edge */ -#define BF 9 /* bottom far edge */ -#define TN 10 /* top near edge */ -#define TF 11 /* top far edge */ +#define LB 0 /* left bottom edge */ +#define LT 1 /* left top edge */ +#define LN 2 /* left near edge */ +#define LF 3 /* left far edge */ +#define RB 4 /* right bottom edge */ +#define RT 5 /* right top edge */ +#define RN 6 /* right near edge */ +#define RF 7 /* right far edge */ +#define BN 8 /* bottom near edge */ +#define BF 9 /* bottom far edge */ +#define TN 10 /* top near edge */ +#define TF 11 /* top far edge */ static INTLISTS *cubetable[256]; /* edge: LB, LT, LN, LF, RB, RT, RN, RF, BN, BF, TN, TF */ -static int corner1[12] = { - LBN, LTN, LBN, LBF, RBN, RTN, RBN, RBF, LBN, LBF, LTN, LTF}; -static int corner2[12] = { - LBF, LTF, LTN, LTF, RBF, RTF, RTN, RTF, RBN, RBF, RTN, RTF}; -static int leftface[12] = { - B, L, L, F, R, T, N, R, N, B, T, F}; +static int corner1[12] = { + LBN, LTN, LBN, LBF, RBN, RTN, RBN, RBF, LBN, LBF, LTN, LTF +}; +static int corner2[12] = { + LBF, LTF, LTN, LTF, RBF, RTF, RTN, RTF, RBN, RBF, RTN, RTF +}; +static int leftface[12] = { + B, L, L, F, R, T, N, R, N, B, T, F +}; /* face on left when going corner1 to corner2 */ -static int rightface[12] = { - L, T, N, L, B, R, R, F, B, F, N, T}; +static int rightface[12] = { + L, T, N, L, B, R, R, F, B, F, N, T +}; /* face on right when going corner1 to corner2 */ @@ -938,7 +942,7 @@ static void docube(CUBE *cube, PROCESS *p, MetaBall *mb) CORNER *c1, *c2; int i, index = 0, count, indexar[8]; - for (i = 0; i < 8; i++) if (cube->corners[i]->value > 0.0f) index += (1<<i); + for (i = 0; i < 8; i++) if (cube->corners[i]->value > 0.0f) index += (1 << i); for (polys = cubetable[index]; polys; polys = polys->next) { INTLIST *edges; @@ -952,44 +956,44 @@ static void docube(CUBE *cube, PROCESS *p, MetaBall *mb) indexar[count] = vertid(c1, c2, p, mb); count++; } - if (count>2) { + if (count > 2) { switch (count) { - case 3: - accum_mballfaces(indexar[2], indexar[1], indexar[0], 0); - break; - case 4: - if (indexar[0]==0) accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); - else accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); - break; - case 5: - if (indexar[0]==0) accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); - else accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); - - accum_mballfaces(indexar[4], indexar[3], indexar[0], 0); - break; - case 6: - if (indexar[0]==0) { - accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); - accum_mballfaces(indexar[0], indexar[5], indexar[4], indexar[3]); - } - else { - accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); - accum_mballfaces(indexar[5], indexar[4], indexar[3], indexar[0]); - } - break; - case 7: - if (indexar[0]==0) { - accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); - accum_mballfaces(indexar[0], indexar[5], indexar[4], indexar[3]); - } - else { - accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); - accum_mballfaces(indexar[5], indexar[4], indexar[3], indexar[0]); - } + case 3: + accum_mballfaces(indexar[2], indexar[1], indexar[0], 0); + break; + case 4: + if (indexar[0] == 0) accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); + else accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); + break; + case 5: + if (indexar[0] == 0) accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); + else accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); - accum_mballfaces(indexar[6], indexar[5], indexar[0], 0); + accum_mballfaces(indexar[4], indexar[3], indexar[0], 0); + break; + case 6: + if (indexar[0] == 0) { + accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); + accum_mballfaces(indexar[0], indexar[5], indexar[4], indexar[3]); + } + else { + accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); + accum_mballfaces(indexar[5], indexar[4], indexar[3], indexar[0]); + } + break; + case 7: + if (indexar[0] == 0) { + accum_mballfaces(indexar[0], indexar[3], indexar[2], indexar[1]); + accum_mballfaces(indexar[0], indexar[5], indexar[4], indexar[3]); + } + else { + accum_mballfaces(indexar[3], indexar[2], indexar[1], indexar[0]); + accum_mballfaces(indexar[5], indexar[4], indexar[3], indexar[0]); + } - break; + accum_mballfaces(indexar[6], indexar[5], indexar[0], 0); + + break; } } } @@ -1000,17 +1004,17 @@ static void docube(CUBE *cube, PROCESS *p, MetaBall *mb) * if surface crosses face, compute other four corners of adjacent cube * and add new cube to cube stack */ -static void testface(int i, int j, int k, CUBE* old, int bit, int c1, int c2, int c3, int c4, PROCESS *p) +static void testface(int i, int j, int k, CUBE *old, int bit, int c1, int c2, int c3, int c4, PROCESS *p) { CUBE newc; CUBES *oldcubes = p->cubes; CORNER *corn1, *corn2, *corn3, *corn4; int n, pos; - corn1= old->corners[c1]; - corn2= old->corners[c2]; - corn3= old->corners[c3]; - corn4= old->corners[c4]; + corn1 = old->corners[c1]; + corn2 = old->corners[c2]; + corn3 = old->corners[c3]; + corn4 = old->corners[c4]; pos = corn1->value > 0.0f ? 1 : 0; @@ -1036,22 +1040,22 @@ static void testface(int i, int j, int k, CUBE* old, int bit, int c1, int c2, in newc.corners[FLIP(c3, bit)] = corn3; newc.corners[FLIP(c4, bit)] = corn4; - if (newc.corners[0]==NULL) newc.corners[0] = setcorner(p, i, j, k); - if (newc.corners[1]==NULL) newc.corners[1] = setcorner(p, i, j, k+1); - if (newc.corners[2]==NULL) newc.corners[2] = setcorner(p, i, j+1, k); - if (newc.corners[3]==NULL) newc.corners[3] = setcorner(p, i, j+1, k+1); - if (newc.corners[4]==NULL) newc.corners[4] = setcorner(p, i+1, j, k); - if (newc.corners[5]==NULL) newc.corners[5] = setcorner(p, i+1, j, k+1); - if (newc.corners[6]==NULL) newc.corners[6] = setcorner(p, i+1, j+1, k); - if (newc.corners[7]==NULL) newc.corners[7] = setcorner(p, i+1, j+1, k+1); + if (newc.corners[0] == NULL) newc.corners[0] = setcorner(p, i, j, k); + if (newc.corners[1] == NULL) newc.corners[1] = setcorner(p, i, j, k + 1); + if (newc.corners[2] == NULL) newc.corners[2] = setcorner(p, i, j + 1, k); + if (newc.corners[3] == NULL) newc.corners[3] = setcorner(p, i, j + 1, k + 1); + if (newc.corners[4] == NULL) newc.corners[4] = setcorner(p, i + 1, j, k); + if (newc.corners[5] == NULL) newc.corners[5] = setcorner(p, i + 1, j, k + 1); + if (newc.corners[6] == NULL) newc.corners[6] = setcorner(p, i + 1, j + 1, k); + if (newc.corners[7] == NULL) newc.corners[7] = setcorner(p, i + 1, j + 1, k + 1); - p->cubes->cube= newc; + p->cubes->cube = newc; } /* setcorner: return corner with the given lattice location * set (and cache) its function value */ -static CORNER *setcorner (PROCESS* p, int i, int j, int k) +static CORNER *setcorner(PROCESS *p, int i, int j, int k) { /* for speed, do corner value caching here */ CORNER *c; @@ -1070,11 +1074,11 @@ static CORNER *setcorner (PROCESS* p, int i, int j, int k) c = (CORNER *) new_pgn_element(sizeof(CORNER)); c->i = i; - c->x = ((float)i-0.5f)*p->size; + c->x = ((float)i - 0.5f) * p->size; c->j = j; - c->y = ((float)j-0.5f)*p->size; + c->y = ((float)j - 0.5f) * p->size; c->k = k; - c->z = ((float)k-0.5f)*p->size; + c->z = ((float)k - 0.5f) * p->size; c->value = p->function(c->x, c->y, c->z); c->next = p->corners[index]; @@ -1086,33 +1090,33 @@ static CORNER *setcorner (PROCESS* p, int i, int j, int k) /* nextcwedge: return next clockwise edge from given edge around given face */ -static int nextcwedge (int edge, int face) +static int nextcwedge(int edge, int face) { switch (edge) { - case LB: - return (face == L)? LF : BN; - case LT: - return (face == L)? LN : TF; - case LN: - return (face == L)? LB : TN; - case LF: - return (face == L)? LT : BF; - case RB: - return (face == R)? RN : BF; - case RT: - return (face == R)? RF : TN; - case RN: - return (face == R)? RT : BN; - case RF: - return (face == R)? RB : TF; - case BN: - return (face == B)? RB : LN; - case BF: - return (face == B)? LB : RF; - case TN: - return (face == T)? LT : RN; - case TF: - return (face == T)? RT : LF; + case LB: + return (face == L) ? LF : BN; + case LT: + return (face == L) ? LN : TF; + case LN: + return (face == L) ? LB : TN; + case LF: + return (face == L) ? LT : BF; + case RB: + return (face == R) ? RN : BF; + case RT: + return (face == R) ? RF : TN; + case RN: + return (face == R) ? RT : BN; + case RF: + return (face == R) ? RB : TF; + case BN: + return (face == B) ? RB : LN; + case BF: + return (face == B) ? LB : RF; + case TN: + return (face == T) ? LT : RN; + case TF: + return (face == T) ? RT : LF; } return 0; } @@ -1120,22 +1124,22 @@ static int nextcwedge (int edge, int face) /* otherface: return face adjoining edge that is not the given face */ -static int otherface (int edge, int face) +static int otherface(int edge, int face) { int other = leftface[edge]; - return face == other? rightface[edge] : other; + return face == other ? rightface[edge] : other; } /* makecubetable: create the 256 entry table for cubical polygonization */ -static void makecubetable (void) +static void makecubetable(void) { - static int isdone= 0; + static int isdone = 0; int i, e, c, done[12], pos[8]; if (isdone) return; - isdone= 1; + isdone = 1; for (i = 0; i < 256; i++) { for (e = 0; e < 12; e++) done[e] = 0; @@ -1147,7 +1151,7 @@ static void makecubetable (void) int start = e, edge = e; /* get face that is to right of edge from pos to neg corner: */ - int face = pos[corner1[e]]? rightface[e] : leftface[e]; + int face = pos[corner1[e]] ? rightface[e] : leftface[e]; while (1) { edge = nextcwedge(edge, face); @@ -1177,21 +1181,21 @@ void BKE_metaball_cubeTable_free(void) INTLIST *ints, *nints; for (i = 0; i < 256; i++) { - lists= cubetable[i]; + lists = cubetable[i]; while (lists) { - nlists= lists->next; + nlists = lists->next; - ints= lists->list; + ints = lists->list; while (ints) { - nints= ints->next; + nints = ints->next; MEM_freeN(ints); - ints= nints; + ints = nints; } MEM_freeN(lists); - lists= nlists; + lists = nlists; } - cubetable[i]= NULL; + cubetable[i] = NULL; } } @@ -1205,8 +1209,8 @@ static int setcenter(CENTERLIST *table[], int i, int j, int k) int index; CENTERLIST *newc, *l, *q; - index= HASH(i, j, k); - q= table[index]; + index = HASH(i, j, k); + q = table[index]; for (l = q; l != NULL; l = l->next) { if (l->i == i && l->j == j && l->k == k) return 1; @@ -1225,25 +1229,25 @@ static int setcenter(CENTERLIST *table[], int i, int j, int k) /* setedge: set vertex id for edge */ -static void setedge (EDGELIST *table[], - int i1, int j1, - int k1, int i2, - int j2, int k2, - int vid) +static void setedge(EDGELIST *table[], + int i1, int j1, + int k1, int i2, + int j2, int k2, + int vid) { unsigned int index; EDGELIST *newe; - if (i1>i2 || (i1==i2 && (j1>j2 || (j1==j2 && k1>k2)))) { - int t=i1; - i1=i2; - i2=t; - t=j1; - j1=j2; - j2=t; - t=k1; - k1=k2; - k2=t; + if (i1 > i2 || (i1 == i2 && (j1 > j2 || (j1 == j2 && k1 > k2)))) { + int t = i1; + i1 = i2; + i2 = t; + t = j1; + j1 = j2; + j2 = t; + t = k1; + k1 = k2; + k2 = t; } index = HASH(i1, j1, k1) + HASH(i2, j2, k2); newe = (EDGELIST *) new_pgn_element(sizeof(EDGELIST)); @@ -1261,27 +1265,27 @@ static void setedge (EDGELIST *table[], /* getedge: return vertex id for edge; return -1 if not set */ -static int getedge (EDGELIST *table[], - int i1, int j1, int k1, - int i2, int j2, int k2) +static int getedge(EDGELIST *table[], + int i1, int j1, int k1, + int i2, int j2, int k2) { EDGELIST *q; - if (i1>i2 || (i1==i2 && (j1>j2 || (j1==j2 && k1>k2)))) { - int t=i1; - i1=i2; - i2=t; - t=j1; - j1=j2; - j2=t; - t=k1; - k1=k2; - k2=t; - } - q = table[HASH(i1, j1, k1)+HASH(i2, j2, k2)]; + if (i1 > i2 || (i1 == i2 && (j1 > j2 || (j1 == j2 && k1 > k2)))) { + int t = i1; + i1 = i2; + i2 = t; + t = j1; + j1 = j2; + j2 = t; + t = k1; + k1 = k2; + k2 = t; + } + q = table[HASH(i1, j1, k1) + HASH(i2, j2, k2)]; for (; q != NULL; q = q->next) { if (q->i1 == i1 && q->j1 == j1 && q->k1 == k1 && - q->i2 == i2 && q->j2 == j2 && q->k2 == k2) + q->i2 == i2 && q->j2 == j2 && q->k2 == k2) { return q->vid; } @@ -1302,12 +1306,12 @@ static int getedge (EDGELIST *table[], /* addtovertices: add v to sequence of vertices */ -static void addtovertices (VERTICES *vertices, VERTEX v) +static void addtovertices(VERTICES *vertices, VERTEX v) { if (vertices->count == vertices->max) { int i; VERTEX *newv; - vertices->max = vertices->count == 0 ? 10 : 2*vertices->count; + vertices->max = vertices->count == 0 ? 10 : 2 * vertices->count; newv = (VERTEX *) MEM_callocN(vertices->max * sizeof(VERTEX), "addtovertices"); for (i = 0; i < vertices->count; i++) newv[i] = vertices->ptr[i]; @@ -1320,15 +1324,15 @@ static void addtovertices (VERTICES *vertices, VERTEX v) /* vnormal: compute unit length surface normal at point */ -static void vnormal (MB_POINT *point, PROCESS *p, MB_POINT *v) +static void vnormal(MB_POINT *point, PROCESS *p, MB_POINT *v) { - float delta= 0.2f*p->delta; + float delta = 0.2f * p->delta; float f = p->function(point->x, point->y, point->z); - v->x = p->function(point->x+delta, point->y, point->z)-f; - v->y = p->function(point->x, point->y+delta, point->z)-f; - v->z = p->function(point->x, point->y, point->z+delta)-f; - f = sqrtf(v->x*v->x + v->y*v->y + v->z*v->z); + v->x = p->function(point->x + delta, point->y, point->z) - f; + v->y = p->function(point->x, point->y + delta, point->z) - f; + v->z = p->function(point->x, point->y, point->z + delta) - f; + f = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z); if (f != 0.0f) { v->x /= f; @@ -1343,21 +1347,21 @@ static void vnormal (MB_POINT *point, PROCESS *p, MB_POINT *v) f = p->function(point->x, point->y, point->z); - temp.x = p->function(point->x+delta, point->y, point->z)-f; - temp.y = p->function(point->x, point->y+delta, point->z)-f; - temp.z = p->function(point->x, point->y, point->z+delta)-f; - f = sqrtf(temp.x*temp.x + temp.y*temp.y + temp.z*temp.z); + temp.x = p->function(point->x + delta, point->y, point->z) - f; + temp.y = p->function(point->x, point->y + delta, point->z) - f; + temp.z = p->function(point->x, point->y, point->z + delta) - f; + f = sqrtf(temp.x * temp.x + temp.y * temp.y + temp.z * temp.z); if (f != 0.0f) { temp.x /= f; temp.y /= f; temp.z /= f; - v->x+= temp.x; - v->y+= temp.y; - v->z+= temp.z; + v->x += temp.x; + v->y += temp.y; + v->z += temp.z; - f = sqrtf(v->x*v->x + v->y*v->y + v->z*v->z); + f = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z); if (f != 0.0f) { v->x /= f; @@ -1370,13 +1374,13 @@ static void vnormal (MB_POINT *point, PROCESS *p, MB_POINT *v) } -static int vertid (CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb) +static int vertid(CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb) { VERTEX v; MB_POINT a, b; int vid = getedge(p->edges, c1->i, c1->j, c1->k, c2->i, c2->j, c2->k); - if (vid != -1) return vid; /* previously computed */ + if (vid != -1) return vid; /* previously computed */ a.x = c1->x; a.y = c1->y; a.z = c1->z; @@ -1387,8 +1391,8 @@ static int vertid (CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb) converge(&a, &b, c1->value, c2->value, p->function, &v.position, mb, 1); /* position */ vnormal(&v.position, p, &v.normal); - addtovertices(&p->vertices, v); /* save vertex */ - vid = p->vertices.count-1; + addtovertices(&p->vertices, v); /* save vertex */ + vid = p->vertices.count - 1; setedge(p->edges, c1->i, c1->j, c1->k, c2->i, c2->j, c2->k, vid); return vid; @@ -1399,8 +1403,8 @@ static int vertid (CORNER *c1, CORNER *c2, PROCESS *p, MetaBall *mb) /* converge: from two points of differing sign, converge to zero crossing */ /* watch it: p1 and p2 are used to calculate */ -static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, - float (*function)(float, float, float), MB_POINT *p, MetaBall *mb, int f) +static void converge(MB_POINT *p1, MB_POINT *p2, float v1, float v2, + float (*function)(float, float, float), MB_POINT *p, MetaBall *mb, int f) { int i = 0; MB_POINT pos, neg; @@ -1408,14 +1412,14 @@ static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, float dx = 0.0f, dy = 0.0f, dz = 0.0f; if (v1 < 0) { - pos= *p2; - neg= *p1; + pos = *p2; + neg = *p1; positive = v2; negative = v1; } else { - pos= *p1; - neg= *p2; + pos = *p1; + neg = *p2; positive = v1; negative = v2; } @@ -1426,25 +1430,25 @@ static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, /* Approximation by linear interpolation is faster then binary subdivision, * but it results sometimes (mb->thresh < 0.2) into the strange results */ - if ((mb->thresh > 0.2f) && (f==1)) { - if ((dy == 0.0f) && (dz == 0.0f)) { - p->x = neg.x - negative*dx/(positive-negative); - p->y = neg.y; - p->z = neg.z; - return; - } - if ((dx == 0.0f) && (dz == 0.0f)) { - p->x = neg.x; - p->y = neg.y - negative*dy/(positive-negative); - p->z = neg.z; - return; - } - if ((dx == 0.0f) && (dy == 0.0f)) { - p->x = neg.x; - p->y = neg.y; - p->z = neg.z - negative*dz/(positive-negative); - return; - } + if ((mb->thresh > 0.2f) && (f == 1)) { + if ((dy == 0.0f) && (dz == 0.0f)) { + p->x = neg.x - negative * dx / (positive - negative); + p->y = neg.y; + p->z = neg.z; + return; + } + if ((dx == 0.0f) && (dz == 0.0f)) { + p->x = neg.x; + p->y = neg.y - negative * dy / (positive - negative); + p->z = neg.z; + return; + } + if ((dx == 0.0f) && (dy == 0.0f)) { + p->x = neg.x; + p->y = neg.y; + p->z = neg.z - negative * dz / (positive - negative); + return; + } } if ((dy == 0.0f) && (dz == 0.0f)) { @@ -1452,8 +1456,8 @@ static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, p->z = neg.z; while (1) { if (i++ == RES) return; - p->x = 0.5f*(pos.x + neg.x); - if ((function(p->x, p->y, p->z)) > 0.0f) pos.x = p->x; else neg.x = p->x; + p->x = 0.5f * (pos.x + neg.x); + if ((function(p->x, p->y, p->z)) > 0.0f) pos.x = p->x; else neg.x = p->x; } } @@ -1462,26 +1466,26 @@ static void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, p->z = neg.z; while (1) { if (i++ == RES) return; - p->y = 0.5f*(pos.y + neg.y); - if ((function(p->x, p->y, p->z)) > 0.0f) pos.y = p->y; else neg.y = p->y; + p->y = 0.5f * (pos.y + neg.y); + if ((function(p->x, p->y, p->z)) > 0.0f) pos.y = p->y; else neg.y = p->y; } - } + } if ((dx == 0.0f) && (dy == 0.0f)) { p->x = neg.x; p->y = neg.y; while (1) { if (i++ == RES) return; - p->z = 0.5f*(pos.z + neg.z); - if ((function(p->x, p->y, p->z)) > 0.0f) pos.z = p->z; else neg.z = p->z; + p->z = 0.5f * (pos.z + neg.z); + if ((function(p->x, p->y, p->z)) > 0.0f) pos.z = p->z; else neg.z = p->z; } } /* This is necessary to find start point */ while (1) { - p->x = 0.5f*(pos.x + neg.x); - p->y = 0.5f*(pos.y + neg.y); - p->z = 0.5f*(pos.z + neg.z); + p->x = 0.5f * (pos.x + neg.x); + p->y = 0.5f * (pos.y + neg.y); + p->z = 0.5f * (pos.z + neg.z); if (i++ == RES) return; @@ -1507,23 +1511,23 @@ static void add_cube(PROCESS *mbproc, int i, int j, int k, int count) /* hmmm, not only one, but eight cube will be added on the stack * ... */ - for (a=i-1; a<i+count; a++) - for (b=j-1; b<j+count; b++) - for (c=k-1; c<k+count; c++) { + for (a = i - 1; a < i + count; a++) + for (b = j - 1; b < j + count; b++) + for (c = k - 1; c < k + count; c++) { /* test if cube has been found before */ - if ( setcenter(mbproc->centers, a, b, c)==0 ) { + if (setcenter(mbproc->centers, a, b, c) == 0) { /* push cube on stack: */ - ncube= (CUBES *) new_pgn_element(sizeof(CUBES)); - ncube->next= mbproc->cubes; - mbproc->cubes= ncube; + ncube = (CUBES *) new_pgn_element(sizeof(CUBES)); + ncube->next = mbproc->cubes; + mbproc->cubes = ncube; - ncube->cube.i= a; - ncube->cube.j= b; - ncube->cube.k= c; + ncube->cube.i = a; + ncube->cube.j = b; + ncube->cube.k = c; /* set corners of initial cube: */ for (n = 0; n < 8; n++) - ncube->cube.corners[n] = setcorner(mbproc, a+MB_BIT(n, 2), b+MB_BIT(n, 1), c+MB_BIT(n, 0)); + ncube->cube.corners[n] = setcorner(mbproc, a + MB_BIT(n, 2), b + MB_BIT(n, 1), c + MB_BIT(n, 0)); } } } @@ -1534,64 +1538,64 @@ static void find_first_points(PROCESS *mbproc, MetaBall *mb, int a) MB_POINT IN, in, OUT, out; /*point;*/ MetaElem *ml; int i, j, k, c_i, c_j, c_k; - int index[3]={1, 0, -1}; - float f =0.0f; + int index[3] = {1, 0, -1}; + float f = 0.0f; float in_v /*, out_v*/; MB_POINT workp; float tmp_v, workp_v, max_len, len, dx, dy, dz, nx, ny, nz, MAXN; ml = mainb[a]; - f = 1-(mb->thresh/ml->s); + f = 1 - (mb->thresh / ml->s); /* Skip, when Stiffness of MetaElement is too small ... MetaElement can't be * visible alone ... but still can influence others MetaElements :-) */ if (f > 0.0f) { - OUT.x = IN.x = in.x= 0.0; - OUT.y = IN.y = in.y= 0.0; - OUT.z = IN.z = in.z= 0.0; + OUT.x = IN.x = in.x = 0.0; + OUT.y = IN.y = in.y = 0.0; + OUT.z = IN.z = in.z = 0.0; calc_mballco(ml, (float *)&in); in_v = mbproc->function(in.x, in.y, in.z); - for (i=0;i<3;i++) { + for (i = 0; i < 3; i++) { switch (ml->type) { case MB_BALL: - OUT.x = out.x= IN.x + index[i]*ml->rad; + OUT.x = out.x = IN.x + index[i] * ml->rad; break; case MB_TUBE: case MB_PLANE: case MB_ELIPSOID: case MB_CUBE: - OUT.x = out.x= IN.x + index[i]*(ml->expx + ml->rad); + OUT.x = out.x = IN.x + index[i] * (ml->expx + ml->rad); break; } - for (j=0;j<3;j++) { + for (j = 0; j < 3; j++) { switch (ml->type) { case MB_BALL: - OUT.y = out.y= IN.y + index[j]*ml->rad; + OUT.y = out.y = IN.y + index[j] * ml->rad; break; case MB_TUBE: case MB_PLANE: case MB_ELIPSOID: case MB_CUBE: - OUT.y = out.y= IN.y + index[j]*(ml->expy + ml->rad); + OUT.y = out.y = IN.y + index[j] * (ml->expy + ml->rad); break; } - for (k=0;k<3;k++) { + for (k = 0; k < 3; k++) { out.x = OUT.x; out.y = OUT.y; switch (ml->type) { case MB_BALL: case MB_TUBE: case MB_PLANE: - out.z= IN.z + index[k]*ml->rad; + out.z = IN.z + index[k] * ml->rad; break; case MB_ELIPSOID: case MB_CUBE: - out.z= IN.z + index[k]*(ml->expz + ml->rad); + out.z = IN.z + index[k] * (ml->expz + ml->rad); break; } @@ -1604,32 +1608,32 @@ static void find_first_points(PROCESS *mbproc, MetaBall *mb, int a) workp.y = in.y; workp.z = in.z; workp_v = in_v; - max_len = sqrtf((out.x-in.x)*(out.x-in.x) + (out.y-in.y)*(out.y-in.y) + (out.z-in.z)*(out.z-in.z)); + max_len = sqrtf((out.x - in.x) * (out.x - in.x) + (out.y - in.y) * (out.y - in.y) + (out.z - in.z) * (out.z - in.z)); - nx = abs((out.x - in.x)/mbproc->size); - ny = abs((out.y - in.y)/mbproc->size); - nz = abs((out.z - in.z)/mbproc->size); + nx = abs((out.x - in.x) / mbproc->size); + ny = abs((out.y - in.y) / mbproc->size); + nz = abs((out.z - in.z) / mbproc->size); MAXN = MAX3(nx, ny, nz); - if (MAXN!=0.0f) { - dx = (out.x - in.x)/MAXN; - dy = (out.y - in.y)/MAXN; - dz = (out.z - in.z)/MAXN; + if (MAXN != 0.0f) { + dx = (out.x - in.x) / MAXN; + dy = (out.y - in.y) / MAXN; + dz = (out.z - in.z) / MAXN; len = 0.0; - while (len<=max_len) { + while (len <= max_len) { workp.x += dx; workp.y += dy; workp.z += dz; /* compute value of implicite function */ tmp_v = mbproc->function(workp.x, workp.y, workp.z); /* add cube to the stack, when value of implicite function crosses zero value */ - if ((tmp_v<0.0f && workp_v>=0.0f)||(tmp_v>0.0f && workp_v<=0.0f)) { + if ((tmp_v < 0.0f && workp_v >= 0.0f) || (tmp_v > 0.0f && workp_v <= 0.0f)) { /* indexes of CUBE, which includes "first point" */ - c_i= (int)floor(workp.x/mbproc->size); - c_j= (int)floor(workp.y/mbproc->size); - c_k= (int)floor(workp.z/mbproc->size); + c_i = (int)floor(workp.x / mbproc->size); + c_j = (int)floor(workp.y / mbproc->size); + c_k = (int)floor(workp.z / mbproc->size); /* add CUBE (with indexes c_i, c_j, c_k) to the stack, * this cube includes found point of Implicit Surface */ @@ -1638,7 +1642,7 @@ static void find_first_points(PROCESS *mbproc, MetaBall *mb, int a) else add_cube(mbproc, c_i, c_j, c_k, 1); } - len = sqrtf((workp.x-in.x)*(workp.x-in.x) + (workp.y-in.y)*(workp.y-in.y) + (workp.z-in.z)*(workp.z-in.z)); + len = sqrtf((workp.x - in.x) * (workp.x - in.x) + (workp.y - in.y) * (workp.y - in.y) + (workp.z - in.z) * (workp.z - in.z)); workp_v = tmp_v; } @@ -1660,10 +1664,10 @@ static void polygonize(PROCESS *mbproc, MetaBall *mb) /* allocate hash tables and build cube polygon table: */ mbproc->centers = MEM_callocN(HASHSIZE * sizeof(CENTERLIST *), "mbproc->centers"); mbproc->corners = MEM_callocN(HASHSIZE * sizeof(CORNER *), "mbproc->corners"); - mbproc->edges = MEM_callocN(2*HASHSIZE * sizeof(EDGELIST *), "mbproc->edges"); + mbproc->edges = MEM_callocN(2 * HASHSIZE * sizeof(EDGELIST *), "mbproc->edges"); makecubetable(); - for (a=0; a<totelem; a++) { + for (a = 0; a < totelem; a++) { /* try to find 8 points on the surface for each MetaElem */ find_first_points(mbproc, mb, a); @@ -1680,232 +1684,232 @@ static void polygonize(PROCESS *mbproc, MetaBall *mb) mbproc->cubes = mbproc->cubes->next; /* test six face directions, maybe add to stack: */ - testface(c.i-1, c.j, c.k, &c, 2, LBN, LBF, LTN, LTF, mbproc); - testface(c.i+1, c.j, c.k, &c, 2, RBN, RBF, RTN, RTF, mbproc); - testface(c.i, c.j-1, c.k, &c, 1, LBN, LBF, RBN, RBF, mbproc); - testface(c.i, c.j+1, c.k, &c, 1, LTN, LTF, RTN, RTF, mbproc); - testface(c.i, c.j, c.k-1, &c, 0, LBN, LTN, RBN, RTN, mbproc); - testface(c.i, c.j, c.k+1, &c, 0, LBF, LTF, RBF, RTF, mbproc); + testface(c.i - 1, c.j, c.k, &c, 2, LBN, LBF, LTN, LTF, mbproc); + testface(c.i + 1, c.j, c.k, &c, 2, RBN, RBF, RTN, RTF, mbproc); + testface(c.i, c.j - 1, c.k, &c, 1, LBN, LBF, RBN, RBF, mbproc); + testface(c.i, c.j + 1, c.k, &c, 1, LTN, LTF, RTN, RTF, mbproc); + testface(c.i, c.j, c.k - 1, &c, 0, LBN, LTN, RBN, RTN, mbproc); + testface(c.i, c.j, c.k + 1, &c, 0, LBF, LTF, RBF, RTF, mbproc); } } -static float init_meta(Scene *scene, Object *ob) /* return totsize */ +static float init_meta(Scene *scene, Object *ob) /* return totsize */ { - Scene *sce_iter= scene; + Scene *sce_iter = scene; Base *base; Object *bob; MetaBall *mb; MetaElem *ml; float size, totsize, obinv[4][4], obmat[4][4], vec[3]; //float max=0.0; - int a, obnr, zero_size=0; + int a, obnr, zero_size = 0; char obname[MAX_ID_NAME]; - copy_m4_m4(obmat, ob->obmat); /* to cope with duplicators from BKE_scene_base_iter_next */ + copy_m4_m4(obmat, ob->obmat); /* to cope with duplicators from BKE_scene_base_iter_next */ invert_m4_m4(obinv, ob->obmat); - a= 0; + a = 0; - BLI_split_name_num(obname, &obnr, ob->id.name+2, '.'); + BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.'); /* make main array */ BKE_scene_base_iter_next(&sce_iter, 0, NULL, NULL); while (BKE_scene_base_iter_next(&sce_iter, 1, &base, &bob)) { - if (bob->type==OB_MBALL) { - zero_size= 0; - ml= NULL; + if (bob->type == OB_MBALL) { + zero_size = 0; + ml = NULL; - if (bob==ob && (base->flag & OB_FROMDUPLI)==0) { - mb= ob->data; + if (bob == ob && (base->flag & OB_FROMDUPLI) == 0) { + mb = ob->data; - if (mb->editelems) ml= mb->editelems->first; - else ml= mb->elems.first; + if (mb->editelems) ml = mb->editelems->first; + else ml = mb->elems.first; } else { char name[MAX_ID_NAME]; int nr; - BLI_split_name_num(name, &nr, bob->id.name+2, '.'); - if ( strcmp(obname, name)==0 ) { - mb= bob->data; + BLI_split_name_num(name, &nr, bob->id.name + 2, '.'); + if (strcmp(obname, name) == 0) { + mb = bob->data; - if (mb->editelems) ml= mb->editelems->first; - else ml= mb->elems.first; + if (mb->editelems) ml = mb->editelems->first; + else ml = mb->elems.first; } } /* when metaball object has zero scale, then MetaElem to this MetaBall * will not be put to mainb array */ - if (bob->size[0]==0.0f || bob->size[1]==0.0f || bob->size[2]==0.0f) { - zero_size= 1; + if (bob->size[0] == 0.0f || bob->size[1] == 0.0f || bob->size[2] == 0.0f) { + zero_size = 1; } else if (bob->parent) { - struct Object *pob=bob->parent; + struct Object *pob = bob->parent; while (pob) { - if (pob->size[0]==0.0f || pob->size[1]==0.0f || pob->size[2]==0.0f) { - zero_size= 1; + if (pob->size[0] == 0.0f || pob->size[1] == 0.0f || pob->size[2] == 0.0f) { + zero_size = 1; break; } - pob= pob->parent; + pob = pob->parent; } } if (zero_size) { - unsigned int ml_count=0; + unsigned int ml_count = 0; while (ml) { ml_count++; - ml= ml->next; + ml = ml->next; } totelem -= ml_count; } else { - while (ml) { - if (!(ml->flag & MB_HIDE)) { - int i; - float temp1[4][4], temp2[4][4], temp3[4][4]; - float (*mat)[4] = NULL, (*imat)[4] = NULL; - float max_x, max_y, max_z, min_x, min_y, min_z; - - max_x = max_y = max_z = -3.4e38; - min_x = min_y = min_z = 3.4e38; - - /* too big stiffness seems only ugly due to linear interpolation - * no need to have possibility for too big stiffness */ - if (ml->s > 10.0f) ml->s = 10.0f; + while (ml) { + if (!(ml->flag & MB_HIDE)) { + int i; + float temp1[4][4], temp2[4][4], temp3[4][4]; + float (*mat)[4] = NULL, (*imat)[4] = NULL; + float max_x, max_y, max_z, min_x, min_y, min_z; + + max_x = max_y = max_z = -3.4e38; + min_x = min_y = min_z = 3.4e38; + + /* too big stiffness seems only ugly due to linear interpolation + * no need to have possibility for too big stiffness */ + if (ml->s > 10.0f) ml->s = 10.0f; + + /* Rotation of MetaElem is stored in quat */ + quat_to_mat4(temp3, ml->quat); + + /* Translation of MetaElem */ + unit_m4(temp2); + temp2[3][0] = ml->x; + temp2[3][1] = ml->y; + temp2[3][2] = ml->z; + + mult_m4_m4m4(temp1, temp2, temp3); + + /* make a copy because of duplicates */ + mainb[a] = new_pgn_element(sizeof(MetaElem)); + *(mainb[a]) = *ml; + mainb[a]->bb = new_pgn_element(sizeof(BoundBox)); + + mat = new_pgn_element(4 * 4 * sizeof(float)); + imat = new_pgn_element(4 * 4 * sizeof(float)); + + /* mat is the matrix to transform from mball into the basis-mball */ + invert_m4_m4(obinv, obmat); + mult_m4_m4m4(temp2, obinv, bob->obmat); + /* MetaBall transformation */ + mult_m4_m4m4(mat, temp2, temp1); + + invert_m4_m4(imat, mat); + + mainb[a]->rad2 = ml->rad * ml->rad; + + mainb[a]->mat = (float *) mat; + mainb[a]->imat = (float *) imat; + + /* untransformed Bounding Box of MetaElem */ + /* 0 */ + mainb[a]->bb->vec[0][0] = -ml->expx; + mainb[a]->bb->vec[0][1] = -ml->expy; + mainb[a]->bb->vec[0][2] = -ml->expz; + /* 1 */ + mainb[a]->bb->vec[1][0] = ml->expx; + mainb[a]->bb->vec[1][1] = -ml->expy; + mainb[a]->bb->vec[1][2] = -ml->expz; + /* 2 */ + mainb[a]->bb->vec[2][0] = ml->expx; + mainb[a]->bb->vec[2][1] = ml->expy; + mainb[a]->bb->vec[2][2] = -ml->expz; + /* 3 */ + mainb[a]->bb->vec[3][0] = -ml->expx; + mainb[a]->bb->vec[3][1] = ml->expy; + mainb[a]->bb->vec[3][2] = -ml->expz; + /* 4 */ + mainb[a]->bb->vec[4][0] = -ml->expx; + mainb[a]->bb->vec[4][1] = -ml->expy; + mainb[a]->bb->vec[4][2] = ml->expz; + /* 5 */ + mainb[a]->bb->vec[5][0] = ml->expx; + mainb[a]->bb->vec[5][1] = -ml->expy; + mainb[a]->bb->vec[5][2] = ml->expz; + /* 6 */ + mainb[a]->bb->vec[6][0] = ml->expx; + mainb[a]->bb->vec[6][1] = ml->expy; + mainb[a]->bb->vec[6][2] = ml->expz; + /* 7 */ + mainb[a]->bb->vec[7][0] = -ml->expx; + mainb[a]->bb->vec[7][1] = ml->expy; + mainb[a]->bb->vec[7][2] = ml->expz; + + /* transformation of Metalem bb */ + for (i = 0; i < 8; i++) + mul_m4_v3((float (*)[4])mat, mainb[a]->bb->vec[i]); + + /* find max and min of transformed bb */ + for (i = 0; i < 8; i++) { + /* find maximums */ + if (mainb[a]->bb->vec[i][0] > max_x) max_x = mainb[a]->bb->vec[i][0]; + if (mainb[a]->bb->vec[i][1] > max_y) max_y = mainb[a]->bb->vec[i][1]; + if (mainb[a]->bb->vec[i][2] > max_z) max_z = mainb[a]->bb->vec[i][2]; + /* find minimums */ + if (mainb[a]->bb->vec[i][0] < min_x) min_x = mainb[a]->bb->vec[i][0]; + if (mainb[a]->bb->vec[i][1] < min_y) min_y = mainb[a]->bb->vec[i][1]; + if (mainb[a]->bb->vec[i][2] < min_z) min_z = mainb[a]->bb->vec[i][2]; + } - /* Rotation of MetaElem is stored in quat */ - quat_to_mat4(temp3, ml->quat); + /* create "new" bb, only point 0 and 6, which are + * necessary for octal tree filling */ + mainb[a]->bb->vec[0][0] = min_x - ml->rad; + mainb[a]->bb->vec[0][1] = min_y - ml->rad; + mainb[a]->bb->vec[0][2] = min_z - ml->rad; - /* Translation of MetaElem */ - unit_m4(temp2); - temp2[3][0]= ml->x; - temp2[3][1]= ml->y; - temp2[3][2]= ml->z; + mainb[a]->bb->vec[6][0] = max_x + ml->rad; + mainb[a]->bb->vec[6][1] = max_y + ml->rad; + mainb[a]->bb->vec[6][2] = max_z + ml->rad; - mult_m4_m4m4(temp1, temp2, temp3); - - /* make a copy because of duplicates */ - mainb[a]= new_pgn_element(sizeof(MetaElem)); - *(mainb[a])= *ml; - mainb[a]->bb = new_pgn_element(sizeof(BoundBox)); - - mat= new_pgn_element(4*4*sizeof(float)); - imat= new_pgn_element(4*4*sizeof(float)); - - /* mat is the matrix to transform from mball into the basis-mball */ - invert_m4_m4(obinv, obmat); - mult_m4_m4m4(temp2, obinv, bob->obmat); - /* MetaBall transformation */ - mult_m4_m4m4(mat, temp2, temp1); - - invert_m4_m4(imat, mat); - - mainb[a]->rad2= ml->rad*ml->rad; - - mainb[a]->mat= (float*) mat; - mainb[a]->imat= (float*) imat; - - /* untransformed Bounding Box of MetaElem */ - /* 0 */ - mainb[a]->bb->vec[0][0]= -ml->expx; - mainb[a]->bb->vec[0][1]= -ml->expy; - mainb[a]->bb->vec[0][2]= -ml->expz; - /* 1 */ - mainb[a]->bb->vec[1][0]= ml->expx; - mainb[a]->bb->vec[1][1]= -ml->expy; - mainb[a]->bb->vec[1][2]= -ml->expz; - /* 2 */ - mainb[a]->bb->vec[2][0]= ml->expx; - mainb[a]->bb->vec[2][1]= ml->expy; - mainb[a]->bb->vec[2][2]= -ml->expz; - /* 3 */ - mainb[a]->bb->vec[3][0]= -ml->expx; - mainb[a]->bb->vec[3][1]= ml->expy; - mainb[a]->bb->vec[3][2]= -ml->expz; - /* 4 */ - mainb[a]->bb->vec[4][0]= -ml->expx; - mainb[a]->bb->vec[4][1]= -ml->expy; - mainb[a]->bb->vec[4][2]= ml->expz; - /* 5 */ - mainb[a]->bb->vec[5][0]= ml->expx; - mainb[a]->bb->vec[5][1]= -ml->expy; - mainb[a]->bb->vec[5][2]= ml->expz; - /* 6 */ - mainb[a]->bb->vec[6][0]= ml->expx; - mainb[a]->bb->vec[6][1]= ml->expy; - mainb[a]->bb->vec[6][2]= ml->expz; - /* 7 */ - mainb[a]->bb->vec[7][0]= -ml->expx; - mainb[a]->bb->vec[7][1]= ml->expy; - mainb[a]->bb->vec[7][2]= ml->expz; - - /* transformation of Metalem bb */ - for (i=0; i<8; i++) - mul_m4_v3((float (*)[4])mat, mainb[a]->bb->vec[i]); - - /* find max and min of transformed bb */ - for (i=0; i<8; i++) { - /* find maximums */ - if (mainb[a]->bb->vec[i][0] > max_x) max_x = mainb[a]->bb->vec[i][0]; - if (mainb[a]->bb->vec[i][1] > max_y) max_y = mainb[a]->bb->vec[i][1]; - if (mainb[a]->bb->vec[i][2] > max_z) max_z = mainb[a]->bb->vec[i][2]; - /* find minimums */ - if (mainb[a]->bb->vec[i][0] < min_x) min_x = mainb[a]->bb->vec[i][0]; - if (mainb[a]->bb->vec[i][1] < min_y) min_y = mainb[a]->bb->vec[i][1]; - if (mainb[a]->bb->vec[i][2] < min_z) min_z = mainb[a]->bb->vec[i][2]; + a++; } - - /* create "new" bb, only point 0 and 6, which are - * necessary for octal tree filling */ - mainb[a]->bb->vec[0][0] = min_x - ml->rad; - mainb[a]->bb->vec[0][1] = min_y - ml->rad; - mainb[a]->bb->vec[0][2] = min_z - ml->rad; - - mainb[a]->bb->vec[6][0] = max_x + ml->rad; - mainb[a]->bb->vec[6][1] = max_y + ml->rad; - mainb[a]->bb->vec[6][2] = max_z + ml->rad; - - a++; + ml = ml->next; } - ml= ml->next; - } } } } /* totsize (= 'manhattan' radius) */ - totsize= 0.0; - for (a=0; a<totelem; a++) { + totsize = 0.0; + for (a = 0; a < totelem; a++) { - vec[0]= mainb[a]->x + mainb[a]->rad + mainb[a]->expx; - vec[1]= mainb[a]->y + mainb[a]->rad + mainb[a]->expy; - vec[2]= mainb[a]->z + mainb[a]->rad + mainb[a]->expz; + vec[0] = mainb[a]->x + mainb[a]->rad + mainb[a]->expx; + vec[1] = mainb[a]->y + mainb[a]->rad + mainb[a]->expy; + vec[2] = mainb[a]->z + mainb[a]->rad + mainb[a]->expz; calc_mballco(mainb[a], vec); - size= fabsf(vec[0]); - if ( size > totsize ) totsize= size; - size= fabsf(vec[1]); - if ( size > totsize ) totsize= size; - size= fabsf(vec[2]); - if ( size > totsize ) totsize= size; + size = fabsf(vec[0]); + if (size > totsize) totsize = size; + size = fabsf(vec[1]); + if (size > totsize) totsize = size; + size = fabsf(vec[2]); + if (size > totsize) totsize = size; - vec[0]= mainb[a]->x - mainb[a]->rad; - vec[1]= mainb[a]->y - mainb[a]->rad; - vec[2]= mainb[a]->z - mainb[a]->rad; + vec[0] = mainb[a]->x - mainb[a]->rad; + vec[1] = mainb[a]->y - mainb[a]->rad; + vec[2] = mainb[a]->z - mainb[a]->rad; calc_mballco(mainb[a], vec); - size= fabsf(vec[0]); - if ( size > totsize ) totsize= size; - size= fabsf(vec[1]); - if ( size > totsize ) totsize= size; - size= fabsf(vec[2]); - if ( size > totsize ) totsize= size; + size = fabsf(vec[0]); + if (size > totsize) totsize = size; + size = fabsf(vec[1]); + if (size > totsize) totsize = size; + size = fabsf(vec[2]); + if (size > totsize) totsize = size; } - for (a=0; a<totelem; a++) { + for (a = 0; a < totelem; a++) { thresh += densfunc(mainb[a], 2.0f * totsize, 2.0f * totsize, 2.0f * totsize); } @@ -1919,8 +1923,8 @@ static void fill_metaball_octal_node(octal_node *node, MetaElem *ml, short i) { ml_pointer *ml_p; - ml_p= MEM_mallocN(sizeof(ml_pointer), "ml_pointer"); - ml_p->ml= ml; + ml_p = MEM_mallocN(sizeof(ml_pointer), "ml_pointer"); + ml_p->ml = ml; BLI_addtail(&(node->nodes[i]->elems), ml_p); node->count++; @@ -1955,16 +1959,16 @@ static void subdivide_metaball_octal_node(octal_node *node, float size_x, float int a, i; /* create new nodes */ - for (a=0;a<8;a++) { - node->nodes[a]= MEM_mallocN(sizeof(octal_node), "octal_node"); - for (i=0;i<8;i++) - node->nodes[a]->nodes[i]= NULL; - node->nodes[a]->parent= node; - node->nodes[a]->elems.first= NULL; - node->nodes[a]->elems.last= NULL; - node->nodes[a]->count= 0; - node->nodes[a]->neg= 0; - node->nodes[a]->pos= 0; + for (a = 0; a < 8; a++) { + node->nodes[a] = MEM_mallocN(sizeof(octal_node), "octal_node"); + for (i = 0; i < 8; i++) + node->nodes[a]->nodes[i] = NULL; + node->nodes[a]->parent = node; + node->nodes[a]->elems.first = NULL; + node->nodes[a]->elems.last = NULL; + node->nodes[a]->count = 0; + node->nodes[a]->neg = 0; + node->nodes[a]->pos = 0; } size_x /= 2; @@ -1980,64 +1984,64 @@ static void subdivide_metaball_octal_node(octal_node *node, float size_x, float node->nodes[0]->x_min = node->x_min; node->nodes[0]->y_min = node->y_min; node->nodes[0]->z_min = node->z_min; - node->nodes[0]->x = node->nodes[0]->x_min + size_x/2; - node->nodes[0]->y = node->nodes[0]->y_min + size_y/2; - node->nodes[0]->z = node->nodes[0]->z_min + size_z/2; + node->nodes[0]->x = node->nodes[0]->x_min + size_x / 2; + node->nodes[0]->y = node->nodes[0]->y_min + size_y / 2; + node->nodes[0]->z = node->nodes[0]->z_min + size_z / 2; node->nodes[1]->x_min = x; node->nodes[1]->y_min = node->y_min; node->nodes[1]->z_min = node->z_min; - node->nodes[1]->x = node->nodes[1]->x_min + size_x/2; - node->nodes[1]->y = node->nodes[1]->y_min + size_y/2; - node->nodes[1]->z = node->nodes[1]->z_min + size_z/2; + node->nodes[1]->x = node->nodes[1]->x_min + size_x / 2; + node->nodes[1]->y = node->nodes[1]->y_min + size_y / 2; + node->nodes[1]->z = node->nodes[1]->z_min + size_z / 2; node->nodes[2]->x_min = x; node->nodes[2]->y_min = y; node->nodes[2]->z_min = node->z_min; - node->nodes[2]->x = node->nodes[2]->x_min + size_x/2; - node->nodes[2]->y = node->nodes[2]->y_min + size_y/2; - node->nodes[2]->z = node->nodes[2]->z_min + size_z/2; + node->nodes[2]->x = node->nodes[2]->x_min + size_x / 2; + node->nodes[2]->y = node->nodes[2]->y_min + size_y / 2; + node->nodes[2]->z = node->nodes[2]->z_min + size_z / 2; node->nodes[3]->x_min = node->x_min; node->nodes[3]->y_min = y; node->nodes[3]->z_min = node->z_min; - node->nodes[3]->x = node->nodes[3]->x_min + size_x/2; - node->nodes[3]->y = node->nodes[3]->y_min + size_y/2; - node->nodes[3]->z = node->nodes[3]->z_min + size_z/2; + node->nodes[3]->x = node->nodes[3]->x_min + size_x / 2; + node->nodes[3]->y = node->nodes[3]->y_min + size_y / 2; + node->nodes[3]->z = node->nodes[3]->z_min + size_z / 2; node->nodes[4]->x_min = node->x_min; node->nodes[4]->y_min = node->y_min; node->nodes[4]->z_min = z; - node->nodes[4]->x = node->nodes[4]->x_min + size_x/2; - node->nodes[4]->y = node->nodes[4]->y_min + size_y/2; - node->nodes[4]->z = node->nodes[4]->z_min + size_z/2; + node->nodes[4]->x = node->nodes[4]->x_min + size_x / 2; + node->nodes[4]->y = node->nodes[4]->y_min + size_y / 2; + node->nodes[4]->z = node->nodes[4]->z_min + size_z / 2; node->nodes[5]->x_min = x; node->nodes[5]->y_min = node->y_min; node->nodes[5]->z_min = z; - node->nodes[5]->x = node->nodes[5]->x_min + size_x/2; - node->nodes[5]->y = node->nodes[5]->y_min + size_y/2; - node->nodes[5]->z = node->nodes[5]->z_min + size_z/2; + node->nodes[5]->x = node->nodes[5]->x_min + size_x / 2; + node->nodes[5]->y = node->nodes[5]->y_min + size_y / 2; + node->nodes[5]->z = node->nodes[5]->z_min + size_z / 2; node->nodes[6]->x_min = x; node->nodes[6]->y_min = y; node->nodes[6]->z_min = z; - node->nodes[6]->x = node->nodes[6]->x_min + size_x/2; - node->nodes[6]->y = node->nodes[6]->y_min + size_y/2; - node->nodes[6]->z = node->nodes[6]->z_min + size_z/2; + node->nodes[6]->x = node->nodes[6]->x_min + size_x / 2; + node->nodes[6]->y = node->nodes[6]->y_min + size_y / 2; + node->nodes[6]->z = node->nodes[6]->z_min + size_z / 2; node->nodes[7]->x_min = node->x_min; node->nodes[7]->y_min = y; node->nodes[7]->z_min = z; - node->nodes[7]->x = node->nodes[7]->x_min + size_x/2; - node->nodes[7]->y = node->nodes[7]->y_min + size_y/2; - node->nodes[7]->z = node->nodes[7]->z_min + size_z/2; + node->nodes[7]->x = node->nodes[7]->x_min + size_x / 2; + node->nodes[7]->y = node->nodes[7]->y_min + size_y / 2; + node->nodes[7]->z = node->nodes[7]->z_min + size_z / 2; - ml_p= node->elems.first; + ml_p = node->elems.first; /* setting up references of MetaElems for new nodes */ while (ml_p) { - ml= ml_p->ml; + ml = ml_p->ml; if (ml->bb->vec[0][2] < z) { if (ml->bb->vec[0][1] < y) { /* vec[0][0] lies in first octant */ @@ -2187,7 +2191,7 @@ static void subdivide_metaball_octal_node(octal_node *node, float size_x, float fill_metaball_octal_node(node, ml, 6); } } - ml_p= ml_p->next; + ml_p = ml_p->next; } /* free references of MetaElems for curent node (it is not needed anymore) */ @@ -2195,8 +2199,8 @@ static void subdivide_metaball_octal_node(octal_node *node, float size_x, float depth--; - if (depth>0) { - for (a=0;a<8;a++) { + if (depth > 0) { + for (a = 0; a < 8; a++) { if (node->nodes[a]->count > 0) /* if node is not empty, then it is subdivided */ subdivide_metaball_octal_node(node->nodes[a], size_x, size_y, size_z, depth); } @@ -2207,8 +2211,8 @@ static void subdivide_metaball_octal_node(octal_node *node, float size_x, float static void free_metaball_octal_node(octal_node *node) { int a; - for (a=0;a<8;a++) { - if (node->nodes[a]!=NULL) free_metaball_octal_node(node->nodes[a]); + for (a = 0; a < 8; a++) { + if (node->nodes[a] != NULL) free_metaball_octal_node(node->nodes[a]); } BLI_freelistN(&node->elems); MEM_freeN(node); @@ -2222,36 +2226,36 @@ static void init_metaball_octal_tree(int depth) float size[3]; int a; - metaball_tree= MEM_mallocN(sizeof(octal_tree), "metaball_octal_tree"); - metaball_tree->first= node= MEM_mallocN(sizeof(octal_node), "metaball_octal_node"); + metaball_tree = MEM_mallocN(sizeof(octal_tree), "metaball_octal_tree"); + metaball_tree->first = node = MEM_mallocN(sizeof(octal_node), "metaball_octal_node"); /* maximal depth of octree */ - metaball_tree->depth= depth; + metaball_tree->depth = depth; - metaball_tree->neg= node->neg=0; - metaball_tree->pos= node->pos=0; + metaball_tree->neg = node->neg = 0; + metaball_tree->pos = node->pos = 0; - node->elems.first= NULL; - node->elems.last= NULL; - node->count=0; + node->elems.first = NULL; + node->elems.last = NULL; + node->count = 0; - for (a=0;a<8;a++) - node->nodes[a]=NULL; + for (a = 0; a < 8; a++) + node->nodes[a] = NULL; - node->x_min= node->y_min= node->z_min= FLT_MAX; - node->x_max= node->y_max= node->z_max= -FLT_MAX; + node->x_min = node->y_min = node->z_min = FLT_MAX; + node->x_max = node->y_max = node->z_max = -FLT_MAX; /* size of octal tree scene */ - for (a=0;a<totelem;a++) { - if (mainb[a]->bb->vec[0][0] < node->x_min) node->x_min= mainb[a]->bb->vec[0][0]; - if (mainb[a]->bb->vec[0][1] < node->y_min) node->y_min= mainb[a]->bb->vec[0][1]; - if (mainb[a]->bb->vec[0][2] < node->z_min) node->z_min= mainb[a]->bb->vec[0][2]; - - if (mainb[a]->bb->vec[6][0] > node->x_max) node->x_max= mainb[a]->bb->vec[6][0]; - if (mainb[a]->bb->vec[6][1] > node->y_max) node->y_max= mainb[a]->bb->vec[6][1]; - if (mainb[a]->bb->vec[6][2] > node->z_max) node->z_max= mainb[a]->bb->vec[6][2]; + for (a = 0; a < totelem; a++) { + if (mainb[a]->bb->vec[0][0] < node->x_min) node->x_min = mainb[a]->bb->vec[0][0]; + if (mainb[a]->bb->vec[0][1] < node->y_min) node->y_min = mainb[a]->bb->vec[0][1]; + if (mainb[a]->bb->vec[0][2] < node->z_min) node->z_min = mainb[a]->bb->vec[0][2]; + + if (mainb[a]->bb->vec[6][0] > node->x_max) node->x_max = mainb[a]->bb->vec[6][0]; + if (mainb[a]->bb->vec[6][1] > node->y_max) node->y_max = mainb[a]->bb->vec[6][1]; + if (mainb[a]->bb->vec[6][2] > node->z_max) node->z_max = mainb[a]->bb->vec[6][2]; - ml_p= MEM_mallocN(sizeof(ml_pointer), "ml_pointer"); - ml_p->ml= mainb[a]; + ml_p = MEM_mallocN(sizeof(ml_pointer), "ml_pointer"); + ml_p->ml = mainb[a]; BLI_addtail(&node->elems, ml_p); if (mainb[a]->flag & MB_NEGATIVE) { @@ -2265,9 +2269,9 @@ static void init_metaball_octal_tree(int depth) } /* size of first node */ - size[0]= node->x_max - node->x_min; - size[1]= node->y_max - node->y_min; - size[2]= node->z_max - node->z_min; + size[0] = node->x_max - node->x_min; + size[1] = node->y_max - node->y_min; + size[2] = node->z_max - node->z_min; /* first node is subdivided recursively */ subdivide_metaball_octal_node(node, size[0], size[1], size[2], metaball_tree->depth); @@ -2281,41 +2285,41 @@ void BKE_metaball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) int a, nr_cubes; float *ve, *no, totsize, width; - mb= ob->data; + mb = ob->data; - if (totelem==0) return; - if (!(G.rendering) && (mb->flag==MB_UPDATE_NEVER)) return; - if (G.moving && mb->flag==MB_UPDATE_FAST) return; + if (totelem == 0) return; + if (!(G.rendering) && (mb->flag == MB_UPDATE_NEVER)) return; + if (G.moving && mb->flag == MB_UPDATE_FAST) return; - curindex= totindex= 0; - indices= NULL; - thresh= mb->thresh; + curindex = totindex = 0; + indices = NULL; + thresh = mb->thresh; /* total number of MetaElems (totelem) is precomputed in find_basis_mball() function */ - mainb= MEM_mallocN(sizeof(void *)*totelem, "mainb"); + mainb = MEM_mallocN(sizeof(void *) * totelem, "mainb"); /* initialize all mainb (MetaElems) */ - totsize= init_meta(scene, ob); + totsize = init_meta(scene, ob); if (metaball_tree) { free_metaball_octal_node(metaball_tree->first); MEM_freeN(metaball_tree); - metaball_tree= NULL; + metaball_tree = NULL; } /* if scene includes more then one MetaElem, then octal tree optimalisation is used */ if ((totelem > 1) && (totelem <= 64)) init_metaball_octal_tree(1); if ((totelem > 64) && (totelem <= 128)) init_metaball_octal_tree(2); - if ((totelem > 128) && (totelem <= 512)) init_metaball_octal_tree(3); + if ((totelem > 128) && (totelem <= 512)) init_metaball_octal_tree(3); if ((totelem > 512) && (totelem <= 1024)) init_metaball_octal_tree(4); if (totelem > 1024) init_metaball_octal_tree(5); /* don't polygonize metaballs with too high resolution (base mball to small) * note: Eps was 0.0001f but this was giving problems for blood animation for durian, using 0.00001f */ if (metaball_tree) { - if ( ob->size[0] <= 0.00001f * (metaball_tree->first->x_max - metaball_tree->first->x_min) || - ob->size[1] <= 0.00001f * (metaball_tree->first->y_max - metaball_tree->first->y_min) || - ob->size[2] <= 0.00001f * (metaball_tree->first->z_max - metaball_tree->first->z_min)) + if (ob->size[0] <= 0.00001f * (metaball_tree->first->x_max - metaball_tree->first->x_min) || + ob->size[1] <= 0.00001f * (metaball_tree->first->y_max - metaball_tree->first->y_min) || + ob->size[2] <= 0.00001f * (metaball_tree->first->z_max - metaball_tree->first->z_min)) { new_pgn_element(-1); /* free values created by init_meta */ @@ -2324,27 +2328,27 @@ void BKE_metaball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) /* free tree */ free_metaball_octal_node(metaball_tree->first); MEM_freeN(metaball_tree); - metaball_tree= NULL; + metaball_tree = NULL; return; } } /* width is size per polygonize cube */ - if (G.rendering) width= mb->rendersize; + if (G.rendering) width = mb->rendersize; else { - width= mb->wiresize; - if (G.moving && mb->flag==MB_UPDATE_HALFRES) width*= 2; + width = mb->wiresize; + if (G.moving && mb->flag == MB_UPDATE_HALFRES) width *= 2; } /* nr_cubes is just for safety, minimum is totsize */ - nr_cubes= (int)(0.5f+totsize/width); + nr_cubes = (int)(0.5f + totsize / width); /* init process */ mbproc.function = metaball; mbproc.size = width; mbproc.bounds = nr_cubes; - mbproc.cubes= NULL; - mbproc.delta = width/(float)(RES*RES); + mbproc.cubes = NULL; + mbproc.delta = width / (float)(RES * RES); polygonize(&mbproc, mb); @@ -2354,31 +2358,31 @@ void BKE_metaball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) if (totelem > 1) { free_metaball_octal_node(metaball_tree->first); MEM_freeN(metaball_tree); - metaball_tree= NULL; + metaball_tree = NULL; } if (curindex) { - dl= MEM_callocN(sizeof(DispList), "mbaldisp"); + dl = MEM_callocN(sizeof(DispList), "mbaldisp"); BLI_addtail(dispbase, dl); - dl->type= DL_INDEX4; - dl->nr= mbproc.vertices.count; - dl->parts= curindex; + dl->type = DL_INDEX4; + dl->nr = mbproc.vertices.count; + dl->parts = curindex; - dl->index= indices; - indices= NULL; - - a= mbproc.vertices.count; - dl->verts= ve= MEM_mallocN(sizeof(float)*3*a, "mballverts"); - dl->nors= no= MEM_mallocN(sizeof(float)*3*a, "mballnors"); - - for (a=0; a<mbproc.vertices.count; a++, no+=3, ve+=3) { - ve[0]= mbproc.vertices.ptr[a].position.x; - ve[1]= mbproc.vertices.ptr[a].position.y; - ve[2]= mbproc.vertices.ptr[a].position.z; - - no[0]= mbproc.vertices.ptr[a].normal.x; - no[1]= mbproc.vertices.ptr[a].normal.y; - no[2]= mbproc.vertices.ptr[a].normal.z; + dl->index = indices; + indices = NULL; + + a = mbproc.vertices.count; + dl->verts = ve = MEM_mallocN(sizeof(float) * 3 * a, "mballverts"); + dl->nors = no = MEM_mallocN(sizeof(float) * 3 * a, "mballnors"); + + for (a = 0; a < mbproc.vertices.count; a++, no += 3, ve += 3) { + ve[0] = mbproc.vertices.ptr[a].position.x; + ve[1] = mbproc.vertices.ptr[a].position.y; + ve[2] = mbproc.vertices.ptr[a].position.z; + + no[0] = mbproc.vertices.ptr[a].normal.x; + no[1] = mbproc.vertices.ptr[a].normal.y; + no[2] = mbproc.vertices.ptr[a].normal.z; } } @@ -2402,7 +2406,7 @@ int BKE_metaball_minmax(MetaBall *mb, float min[3], float max[3]) int BKE_metaball_center_median(MetaBall *mb, float cent[3]) { MetaElem *ml; - int total= 0; + int total = 0; zero_v3(cent); @@ -2411,7 +2415,7 @@ int BKE_metaball_center_median(MetaBall *mb, float cent[3]) } if (total) - mul_v3_fl(cent, 1.0f/(float)total); + mul_v3_fl(cent, 1.0f / (float)total); return (total != 0); } diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index ffc33e3b86a..ecf6fd8e5de 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -97,28 +97,28 @@ static const char *cmpcode_to_str(int code) case MESHCMP_DVERT_WEIGHTMISMATCH: return "Vertex Weight Mismatch"; case MESHCMP_DVERT_GROUPMISMATCH: - return "Vertex Group Mismatch"; + return "Vertex Group Mismatch"; case MESHCMP_DVERT_TOTGROUPMISMATCH: - return "Vertex Doesn't Belong To Same Number Of Groups"; + return "Vertex Doesn't Belong To Same Number Of Groups"; case MESHCMP_LOOPCOLMISMATCH: - return "Vertex Color Mismatch"; + return "Vertex Color Mismatch"; case MESHCMP_LOOPUVMISMATCH: - return "UV Mismatch"; + return "UV Mismatch"; case MESHCMP_LOOPMISMATCH: - return "Loop Mismatch"; + return "Loop Mismatch"; case MESHCMP_POLYVERTMISMATCH: - return "Loop Vert Mismatch In Poly Test"; + return "Loop Vert Mismatch In Poly Test"; case MESHCMP_POLYMISMATCH: - return "Loop Vert Mismatch"; + return "Loop Vert Mismatch"; case MESHCMP_EDGEUNKNOWN: - return "Edge Mismatch"; + return "Edge Mismatch"; case MESHCMP_VERTCOMISMATCH: - return "Vertex Coordinate Mismatch"; + return "Vertex Coordinate Mismatch"; case MESHCMP_CDLAYERS_MISMATCH: - return "CustomData Layer Count Mismatch"; + return "CustomData Layer Count Mismatch"; default: - return "Mesh Comparison Code Unknown"; - } + return "Mesh Comparison Code Unknown"; + } } /* thresh is threshold for comparing vertices, uvs, vertex colors, @@ -126,7 +126,7 @@ static const char *cmpcode_to_str(int code) static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2, float thresh) { CustomDataLayer *l1, *l2; - int i, i1=0, i2=0, tot, j; + int i, i1 = 0, i2 = 0, tot, j; for (i = 0; i < c1->totlayer; i++) { if (ELEM7(c1->layers[i].type, CD_MVERT, CD_MEDGE, CD_MPOLY, @@ -150,7 +150,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 l1 = c1->layers; l2 = c2->layers; tot = i1; i1 = 0; i2 = 0; - for (i=0; i < tot; i++) { + for (i = 0; i < tot; i++) { while (i1 < c1->totlayer && !ELEM7(l1->type, CD_MVERT, CD_MEDGE, CD_MPOLY, CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT)) { @@ -168,7 +168,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 MVert *v2 = l2->data; int vtot = m1->totvert; - for (j=0; j<vtot; j++, v1++, v2++) { + for (j = 0; j < vtot; j++, v1++, v2++) { if (len_v3v3(v1->co, v2->co) > thresh) return MESHCMP_VERTCOMISMATCH; /*I don't care about normals, let's just do coodinates*/ @@ -182,11 +182,11 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 EdgeHash *eh = BLI_edgehash_new(); int etot = m1->totedge; - for (j=0; j<etot; j++, e1++) { + for (j = 0; j < etot; j++, e1++) { BLI_edgehash_insert(eh, e1->v1, e1->v2, e1); } - for (j=0; j<etot; j++, e2++) { + for (j = 0; j < etot; j++, e2++) { if (!BLI_edgehash_lookup(eh, e2->v1, e2->v2)) return MESHCMP_EDGEUNKNOWN; } @@ -198,7 +198,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 MPoly *p2 = l2->data; int ptot = m1->totpoly; - for (j=0; j<ptot; j++, p1++, p2++) { + for (j = 0; j < ptot; j++, p1++, p2++) { MLoop *lp1, *lp2; int k; @@ -208,7 +208,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 lp1 = m1->mloop + p1->loopstart; lp2 = m2->mloop + p2->loopstart; - for (k=0; k<p1->totloop; k++, lp1++, lp2++) { + for (k = 0; k < p1->totloop; k++, lp1++, lp2++) { if (lp1->v != lp2->v) return MESHCMP_POLYVERTMISMATCH; } @@ -219,7 +219,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 MLoop *lp2 = l2->data; int ltot = m1->totloop; - for (j=0; j<ltot; j++, lp1++, lp2++) { + for (j = 0; j < ltot; j++, lp1++, lp2++) { if (lp1->v != lp2->v) return MESHCMP_LOOPMISMATCH; } @@ -229,7 +229,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 MLoopUV *lp2 = l2->data; int ltot = m1->totloop; - for (j=0; j<ltot; j++, lp1++, lp2++) { + for (j = 0; j < ltot; j++, lp1++, lp2++) { if (len_v2v2(lp1->uv, lp2->uv) > thresh) return MESHCMP_LOOPUVMISMATCH; } @@ -240,7 +240,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 MLoopCol *lp2 = l2->data; int ltot = m1->totloop; - for (j=0; j<ltot; j++, lp1++, lp2++) { + for (j = 0; j < ltot; j++, lp1++, lp2++) { if (ABS(lp1->r - lp2->r) > thresh || ABS(lp1->g - lp2->g) > thresh || ABS(lp1->b - lp2->b) > thresh || @@ -256,14 +256,14 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 MDeformVert *dv2 = l2->data; int dvtot = m1->totvert; - for (j=0; j<dvtot; j++, dv1++, dv2++) { + for (j = 0; j < dvtot; j++, dv1++, dv2++) { int k; - MDeformWeight *dw1 = dv1->dw, *dw2=dv2->dw; + MDeformWeight *dw1 = dv1->dw, *dw2 = dv2->dw; if (dv1->totweight != dv2->totweight) return MESHCMP_DVERT_TOTGROUPMISMATCH; - for (k=0; k<dv1->totweight; k++, dw1++, dw2++) { + for (k = 0; k < dv1->totweight; k++, dw1++, dw2++) { if (dw1->def_nr != dw2->def_nr) return MESHCMP_DVERT_GROUPMISMATCH; if (ABS(dw1->weight - dw2->weight) > thresh) @@ -293,7 +293,7 @@ const char *BKE_mesh_cmp(Mesh *me1, Mesh *me2, float thresh) if (me1->totpoly != me2->totpoly) return "Number of faces don't match"; - if (me1->totloop !=me2->totloop) + if (me1->totloop != me2->totloop) return "Number of loops don't match"; if ((c = customdata_compare(&me1->vdata, &me2->vdata, me1, me2, thresh))) @@ -327,7 +327,7 @@ static void mesh_ensure_tessellation_customdata(Mesh *me) const int totcol_tessface = CustomData_number_of_layers(&me->fdata, CD_MCOL); if (tottex_tessface != tottex_original || - totcol_tessface != totcol_original ) + totcol_tessface != totcol_original) { BKE_mesh_tessface_clear(me); @@ -340,8 +340,8 @@ static void mesh_ensure_tessellation_customdata(Mesh *me) * and check if there was any data to begin with, for now just print the warning with * some info to help troubleshoot whats going on - campbell */ printf("%s: warning! Tessellation uvs or vcol data got out of sync, " - "had to reset!\n CD_MTFACE: %d != CD_MTEXPOLY: %d || CD_MCOL: %d != CD_MLOOPCOL: %d\n", - __func__, tottex_tessface, tottex_original, totcol_tessface, totcol_original); + "had to reset!\n CD_MTFACE: %d != CD_MTEXPOLY: %d || CD_MCOL: %d != CD_MLOOPCOL: %d\n", + __func__, tottex_tessface, tottex_original, totcol_tessface, totcol_original); } } } @@ -396,19 +396,19 @@ void BKE_mesh_unlink(Mesh *me) { int a; - if (me==NULL) return; + if (me == NULL) return; - for (a=0; a<me->totcol; a++) { + for (a = 0; a < me->totcol; a++) { if (me->mat[a]) me->mat[a]->id.us--; - me->mat[a]= NULL; + me->mat[a] = NULL; } if (me->key) { me->key->id.us--; } - me->key= NULL; + me->key = NULL; - if (me->texcomesh) me->texcomesh= NULL; + if (me->texcomesh) me->texcomesh = NULL; } /* do not free mesh itself */ @@ -425,7 +425,7 @@ void BKE_mesh_free(Mesh *me, int unlink) if (me->adt) { BKE_free_animdata(&me->id); - me->adt= NULL; + me->adt = NULL; } if (me->mat) MEM_freeN(me->mat); @@ -443,12 +443,12 @@ void copy_dverts(MDeformVert *dst, MDeformVert *src, int copycount) if (!src || !dst) return; - memcpy (dst, src, copycount * sizeof(MDeformVert)); + memcpy(dst, src, copycount * sizeof(MDeformVert)); - for (i=0; i<copycount; i++) { + for (i = 0; i < copycount; i++) { if (src[i].dw) { - dst[i].dw = MEM_callocN (sizeof(MDeformWeight)*src[i].totweight, "copy_deformWeight"); - memcpy (dst[i].dw, src[i].dw, sizeof (MDeformWeight)*src[i].totweight); + dst[i].dw = MEM_callocN(sizeof(MDeformWeight) * src[i].totweight, "copy_deformWeight"); + memcpy(dst[i].dw, src[i].dw, sizeof (MDeformWeight) * src[i].totweight); } } @@ -459,16 +459,16 @@ void free_dverts(MDeformVert *dvert, int totvert) /* Instead of freeing the verts directly, * call this function to delete any special * vert data */ - int i; + int i; if (!dvert) return; /* Free any special data from the verts */ - for (i=0; i<totvert; i++) { - if (dvert[i].dw) MEM_freeN (dvert[i].dw); + for (i = 0; i < totvert; i++) { + if (dvert[i].dw) MEM_freeN(dvert[i].dw); } - MEM_freeN (dvert); + MEM_freeN(dvert); } static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata) @@ -488,14 +488,14 @@ Mesh *BKE_mesh_add(const char *name) { Mesh *me; - me= BKE_libblock_alloc(&G.main->mesh, ID_ME, name); + me = BKE_libblock_alloc(&G.main->mesh, ID_ME, name); - me->size[0]= me->size[1]= me->size[2]= 1.0; - me->smoothresh= 30; - me->texflag= ME_AUTOSPACE; - me->flag= ME_TWOSIDED; - me->bb= BKE_boundbox_alloc_unit(); - me->drawflag= ME_DRAWEDGES|ME_DRAWFACES|ME_DRAWCREASES; + me->size[0] = me->size[1] = me->size[2] = 1.0; + me->smoothresh = 30; + me->texflag = ME_AUTOSPACE; + me->flag = ME_TWOSIDED; + me->bb = BKE_boundbox_alloc_unit(); + me->drawflag = ME_DRAWEDGES | ME_DRAWFACES | ME_DRAWCREASES; return me; } @@ -508,10 +508,10 @@ Mesh *BKE_mesh_copy(Mesh *me) int a, i; const int do_tessface = ((me->totface != 0) && (me->totpoly == 0)); /* only do tessface if we have no polys */ - men= BKE_libblock_copy(&me->id); + men = BKE_libblock_copy(&me->id); - men->mat= MEM_dupallocN(me->mat); - for (a=0; a<men->totcol; a++) { + men->mat = MEM_dupallocN(me->mat); + for (a = 0; a < men->totcol; a++) { id_us_plus((ID *)men->mat[a]); } id_us_plus((ID *)men->texcomesh); @@ -530,33 +530,33 @@ Mesh *BKE_mesh_copy(Mesh *me) mesh_update_customdata_pointers(men, do_tessface); /* ensure indirect linked data becomes lib-extern */ - for (i=0; i<me->fdata.totlayer; i++) { + for (i = 0; i < me->fdata.totlayer; i++) { if (me->fdata.layers[i].type == CD_MTFACE) { - tface= (MTFace*)me->fdata.layers[i].data; + tface = (MTFace *)me->fdata.layers[i].data; - for (a=0; a<me->totface; a++, tface++) + for (a = 0; a < me->totface; a++, tface++) if (tface->tpage) - id_lib_extern((ID*)tface->tpage); + id_lib_extern((ID *)tface->tpage); } } - for (i=0; i<me->pdata.totlayer; i++) { + for (i = 0; i < me->pdata.totlayer; i++) { if (me->pdata.layers[i].type == CD_MTEXPOLY) { - txface= (MTexPoly*)me->pdata.layers[i].data; + txface = (MTexPoly *)me->pdata.layers[i].data; - for (a=0; a<me->totpoly; a++, txface++) + for (a = 0; a < me->totpoly; a++, txface++) if (txface->tpage) - id_lib_extern((ID*)txface->tpage); + id_lib_extern((ID *)txface->tpage); } } - men->mselect= NULL; - men->edit_btmesh= NULL; + men->mselect = NULL; + men->edit_btmesh = NULL; - men->bb= MEM_dupallocN(men->bb); + men->bb = MEM_dupallocN(men->bb); - men->key= BKE_key_copy(me->key); - if (men->key) men->key->from= (ID *)men; + men->key = BKE_key_copy(me->key); + if (men->key) men->key->from = (ID *)men; return men; } @@ -579,11 +579,11 @@ static void expand_local_mesh(Mesh *me) if (me->mtface || me->mtpoly) { int a, i; - for (i=0; i<me->pdata.totlayer; i++) { + for (i = 0; i < me->pdata.totlayer; i++) { if (me->pdata.layers[i].type == CD_MTEXPOLY) { - MTexPoly *txface= (MTexPoly*)me->fdata.layers[i].data; + MTexPoly *txface = (MTexPoly *)me->fdata.layers[i].data; - for (a=0; a<me->totpoly; a++, txface++) { + for (a = 0; a < me->totpoly; a++, txface++) { /* special case: ima always local immediately */ if (txface->tpage) { id_lib_extern((ID *)txface->tpage); @@ -592,11 +592,11 @@ static void expand_local_mesh(Mesh *me) } } - for (i=0; i<me->fdata.totlayer; i++) { + for (i = 0; i < me->fdata.totlayer; i++) { if (me->fdata.layers[i].type == CD_MTFACE) { - MTFace *tface= (MTFace*)me->fdata.layers[i].data; + MTFace *tface = (MTFace *)me->fdata.layers[i].data; - for (a=0; a<me->totface; a++, tface++) { + for (a = 0; a < me->totface; a++, tface++) { /* special case: ima always local immediately */ if (tface->tpage) { id_lib_extern((ID *)tface->tpage); @@ -613,26 +613,26 @@ static void expand_local_mesh(Mesh *me) void BKE_mesh_make_local(Mesh *me) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (me->id.lib==NULL) return; - if (me->id.us==1) { + if (me->id.lib == NULL) return; + if (me->id.us == 1) { id_clear_lib_data(bmain, &me->id); expand_local_mesh(me); return; } - for (ob= bmain->object.first; ob && ELEM(0, is_lib, is_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) is_lib= TRUE; - else is_local= TRUE; + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } } @@ -641,16 +641,16 @@ void BKE_mesh_make_local(Mesh *me) expand_local_mesh(me); } else if (is_local && is_lib) { - Mesh *me_new= BKE_mesh_copy(me); - me_new->id.us= 0; + Mesh *me_new = BKE_mesh_copy(me); + me_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, me->id.lib, &me_new->id); - for (ob= bmain->object.first; ob; ob= ob->id.next) { + for (ob = bmain->object.first; ob; ob = ob->id.next) { if (me == ob->data) { - if (ob->id.lib==NULL) { + if (ob->id.lib == NULL) { set_mesh(ob, me_new); } } @@ -664,11 +664,11 @@ void BKE_mesh_boundbox_calc(Mesh *me, float r_loc[3], float r_size[3]) float min[3], max[3]; float mloc[3], msize[3]; - if (me->bb==NULL) me->bb= MEM_callocN(sizeof(BoundBox), "boundbox"); - bb= me->bb; + if (me->bb == NULL) me->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); + bb = me->bb; - if (!r_loc) r_loc= mloc; - if (!r_size) r_size= msize; + if (!r_loc) r_loc = mloc; + if (!r_size) r_size = msize; INIT_MINMAX(min, max); if (!BKE_mesh_minmax(me, min, max)) { @@ -678,9 +678,9 @@ void BKE_mesh_boundbox_calc(Mesh *me, float r_loc[3], float r_size[3]) mid_v3_v3v3(r_loc, min, max); - r_size[0]= (max[0]-min[0])/2.0f; - r_size[1]= (max[1]-min[1])/2.0f; - r_size[2]= (max[2]-min[2])/2.0f; + r_size[0] = (max[0] - min[0]) / 2.0f; + r_size[1] = (max[1] - min[1]) / 2.0f; + r_size[2] = (max[2] - min[2]) / 2.0f; BKE_boundbox_init_from_minmax(bb, min, max); } @@ -693,10 +693,10 @@ void BKE_mesh_texspace_calc(Mesh *me) BKE_mesh_boundbox_calc(me, loc, size); if (me->texflag & ME_AUTOSPACE) { - for (a=0; a<3; a++) { - if (size[a]==0.0f) size[a]= 1.0f; - else if (size[a]>0.0f && size[a]<0.00001f) size[a]= 0.00001f; - else if (size[a]<0.0f && size[a]> -0.00001f) size[a]= -0.00001f; + for (a = 0; a < 3; a++) { + if (size[a] == 0.0f) size[a] = 1.0f; + else if (size[a] > 0.0f && size[a] < 0.00001f) size[a] = 0.00001f; + else if (size[a] < 0.0f && size[a] > -0.00001f) size[a] = -0.00001f; } copy_v3_v3(me->loc, loc); @@ -707,7 +707,7 @@ void BKE_mesh_texspace_calc(Mesh *me) BoundBox *BKE_mesh_boundbox_get(Object *ob) { - Mesh *me= ob->data; + Mesh *me = ob->data; if (ob->bb) return ob->bb; @@ -724,8 +724,8 @@ void BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_rot[3], float r_siz BKE_mesh_texspace_calc(me); } - if (r_loc) copy_v3_v3(r_loc, me->loc); - if (r_rot) copy_v3_v3(r_rot, me->rot); + if (r_loc) copy_v3_v3(r_loc, me->loc); + if (r_rot) copy_v3_v3(r_rot, me->rot); if (r_size) copy_v3_v3(r_size, me->size); } @@ -733,20 +733,20 @@ float *BKE_mesh_orco_verts_get(Object *ob) { Mesh *me = ob->data; MVert *mvert = NULL; - Mesh *tme = me->texcomesh?me->texcomesh:me; + Mesh *tme = me->texcomesh ? me->texcomesh : me; int a, totvert; float (*vcos)[3] = NULL; /* Get appropriate vertex coordinates */ - vcos = MEM_callocN(sizeof(*vcos)*me->totvert, "orco mesh"); + vcos = MEM_callocN(sizeof(*vcos) * me->totvert, "orco mesh"); mvert = tme->mvert; totvert = MIN2(tme->totvert, me->totvert); - for (a=0; a<totvert; a++, mvert++) { + for (a = 0; a < totvert; a++, mvert++) { copy_v3_v3(vcos[a], mvert->co); } - return (float*)vcos; + return (float *)vcos; } void BKE_mesh_orco_verts_transform(Mesh *me, float (*orco)[3], int totvert, int invert) @@ -757,17 +757,17 @@ void BKE_mesh_orco_verts_transform(Mesh *me, float (*orco)[3], int totvert, int BKE_mesh_texspace_get(me->texcomesh ? me->texcomesh : me, loc, NULL, size); if (invert) { - for (a=0; a<totvert; a++) { + for (a = 0; a < totvert; a++) { float *co = orco[a]; madd_v3_v3v3v3(co, loc, co, size); } } else { - for (a=0; a<totvert; a++) { + for (a = 0; a < totvert; a++) { float *co = orco[a]; - co[0] = (co[0]-loc[0])/size[0]; - co[1] = (co[1]-loc[1])/size[1]; - co[2] = (co[2]-loc[2])/size[2]; + co[0] = (co[0] - loc[0]) / size[0]; + co[1] = (co[1] - loc[1]) / size[1]; + co[2] = (co[2] - loc[2]) / size[2]; } } } @@ -777,51 +777,51 @@ void BKE_mesh_orco_verts_transform(Mesh *me, float (*orco)[3], int totvert, int int test_index_face(MFace *mface, CustomData *fdata, int mfindex, int nr) { /* first test if the face is legal */ - if ((mface->v3 || nr==4) && mface->v3==mface->v4) { - mface->v4= 0; + if ((mface->v3 || nr == 4) && mface->v3 == mface->v4) { + mface->v4 = 0; nr--; } - if ((mface->v2 || mface->v4) && mface->v2==mface->v3) { - mface->v3= mface->v4; - mface->v4= 0; + if ((mface->v2 || mface->v4) && mface->v2 == mface->v3) { + mface->v3 = mface->v4; + mface->v4 = 0; nr--; } - if (mface->v1==mface->v2) { - mface->v2= mface->v3; - mface->v3= mface->v4; - mface->v4= 0; + if (mface->v1 == mface->v2) { + mface->v2 = mface->v3; + mface->v3 = mface->v4; + mface->v4 = 0; nr--; } /* check corrupt cases, bowtie geometry, cant handle these because edge data wont exist so just return 0 */ - if (nr==3) { + if (nr == 3) { if ( - /* real edges */ - mface->v1==mface->v2 || - mface->v2==mface->v3 || - mface->v3==mface->v1 - ) { + /* real edges */ + mface->v1 == mface->v2 || + mface->v2 == mface->v3 || + mface->v3 == mface->v1) + { return 0; } } - else if (nr==4) { + else if (nr == 4) { if ( - /* real edges */ - mface->v1==mface->v2 || - mface->v2==mface->v3 || - mface->v3==mface->v4 || - mface->v4==mface->v1 || - /* across the face */ - mface->v1==mface->v3 || - mface->v2==mface->v4 - ) { + /* real edges */ + mface->v1 == mface->v2 || + mface->v2 == mface->v3 || + mface->v3 == mface->v4 || + mface->v4 == mface->v1 || + /* across the face */ + mface->v1 == mface->v3 || + mface->v2 == mface->v4 + ) { return 0; } } /* prevent a zero at wrong index location */ - if (nr==3) { - if (mface->v3==0) { + if (nr == 3) { + if (mface->v3 == 0) { static int corner_indices[4] = {1, 2, 0, 3}; SWAP(unsigned int, mface->v1, mface->v2); @@ -831,8 +831,8 @@ int test_index_face(MFace *mface, CustomData *fdata, int mfindex, int nr) CustomData_swap(fdata, mfindex, corner_indices); } } - else if (nr==4) { - if (mface->v3==0 || mface->v4==0) { + else if (nr == 4) { + if (mface->v3 == 0 || mface->v4 == 0) { static int corner_indices[4] = {2, 3, 0, 1}; SWAP(unsigned int, mface->v1, mface->v3); @@ -849,24 +849,24 @@ int test_index_face(MFace *mface, CustomData *fdata, int mfindex, int nr) Mesh *BKE_mesh_from_object(Object *ob) { - if (ob==NULL) return NULL; - if (ob->type==OB_MESH) return ob->data; + if (ob == NULL) return NULL; + if (ob->type == OB_MESH) return ob->data; else return NULL; } void set_mesh(Object *ob, Mesh *me) { - Mesh *old=NULL; + Mesh *old = NULL; multires_force_update(ob); - if (ob==NULL) return; + if (ob == NULL) return; - if (ob->type==OB_MESH) { - old= ob->data; + if (ob->type == OB_MESH) { + old = ob->data; if (old) old->id.us--; - ob->data= me; + ob->data = me; id_us_plus((ID *)me); } @@ -887,24 +887,24 @@ static void to_edgesort(struct edgesort *ed, unsigned int v1, unsigned int v2, short is_loose, short is_draw) { - if (v1<v2) { - ed->v1= v1; ed->v2= v2; + if (v1 < v2) { + ed->v1 = v1; ed->v2 = v2; } else { - ed->v1= v2; ed->v2= v1; + ed->v1 = v2; ed->v2 = v1; } - ed->is_loose= is_loose; - ed->is_draw= is_draw; + ed->is_loose = is_loose; + ed->is_draw = is_draw; } static int vergedgesort(const void *v1, const void *v2) { - const struct edgesort *x1=v1, *x2=v2; + const struct edgesort *x1 = v1, *x2 = v2; - if ( x1->v1 > x2->v1) return 1; - else if ( x1->v1 < x2->v1) return -1; - else if ( x1->v2 > x2->v2) return 1; - else if ( x1->v2 < x2->v2) return -1; + if (x1->v1 > x2->v1) return 1; + else if (x1->v1 < x2->v1) return -1; + else if (x1->v2 > x2->v2) return 1; + else if (x1->v2 < x2->v2) return -1; return 0; } @@ -912,8 +912,8 @@ static int vergedgesort(const void *v1, const void *v2) /* Create edges based on known verts and faces */ static void make_edges_mdata(MVert *UNUSED(allvert), MFace *allface, MLoop *allloop, - MPoly *allpoly, int UNUSED(totvert), int totface, int UNUSED(totloop), int totpoly, - int old, MEdge **alledge, int *_totedge) + MPoly *allpoly, int UNUSED(totvert), int totface, int UNUSED(totloop), int totpoly, + int old, MEdge **alledge, int *_totedge) { MPoly *mpoly; MLoop *mloop; @@ -921,26 +921,26 @@ static void make_edges_mdata(MVert *UNUSED(allvert), MFace *allface, MLoop *alll MEdge *medge; EdgeHash *hash = BLI_edgehash_new(); struct edgesort *edsort, *ed; - int a, b, totedge=0, final=0; + int a, b, totedge = 0, final = 0; /* we put all edges in array, sort them, and detect doubles that way */ - for (a= totface, mface= allface; a>0; a--, mface++) { - if (mface->v4) totedge+=4; - else if (mface->v3) totedge+=3; - else totedge+=1; + for (a = totface, mface = allface; a > 0; a--, mface++) { + if (mface->v4) totedge += 4; + else if (mface->v3) totedge += 3; + else totedge += 1; } - if (totedge==0) { + if (totedge == 0) { /* flag that mesh has edges */ - (*alledge)= MEM_callocN(0, "make mesh edges"); + (*alledge) = MEM_callocN(0, "make mesh edges"); (*_totedge) = 0; return; } - ed= edsort= MEM_mallocN(totedge*sizeof(struct edgesort), "edgesort"); + ed = edsort = MEM_mallocN(totedge * sizeof(struct edgesort), "edgesort"); - for (a= totface, mface= allface; a>0; a--, mface++) { + for (a = totface, mface = allface; a > 0; a--, mface++) { to_edgesort(ed++, mface->v1, mface->v2, !mface->v3, mface->edcode & ME_V1V2); if (mface->v4) { to_edgesort(ed++, mface->v2, mface->v3, 0, mface->edcode & ME_V2V3); @@ -956,54 +956,54 @@ static void make_edges_mdata(MVert *UNUSED(allvert), MFace *allface, MLoop *alll qsort(edsort, totedge, sizeof(struct edgesort), vergedgesort); /* count final amount */ - for (a=totedge, ed=edsort; a>1; a--, ed++) { + for (a = totedge, ed = edsort; a > 1; a--, ed++) { /* edge is unique when it differs from next edge, or is last */ - if (ed->v1 != (ed+1)->v1 || ed->v2 != (ed+1)->v2) final++; + if (ed->v1 != (ed + 1)->v1 || ed->v2 != (ed + 1)->v2) final++; } final++; - (*alledge)= medge= MEM_callocN(sizeof (MEdge) * final, "BKE_mesh_make_edges mdge"); - (*_totedge)= final; + (*alledge) = medge = MEM_callocN(sizeof (MEdge) * final, "BKE_mesh_make_edges mdge"); + (*_totedge) = final; - for (a=totedge, ed=edsort; a>1; a--, ed++) { + for (a = totedge, ed = edsort; a > 1; a--, ed++) { /* edge is unique when it differs from next edge, or is last */ - if (ed->v1 != (ed+1)->v1 || ed->v2 != (ed+1)->v2) { - medge->v1= ed->v1; - medge->v2= ed->v2; - if (old==0 || ed->is_draw) medge->flag= ME_EDGEDRAW|ME_EDGERENDER; - if (ed->is_loose) medge->flag|= ME_LOOSEEDGE; + if (ed->v1 != (ed + 1)->v1 || ed->v2 != (ed + 1)->v2) { + medge->v1 = ed->v1; + medge->v2 = ed->v2; + if (old == 0 || ed->is_draw) medge->flag = ME_EDGEDRAW | ME_EDGERENDER; + if (ed->is_loose) medge->flag |= ME_LOOSEEDGE; /* order is swapped so extruding this edge as a surface wont flip face normals * with cyclic curves */ - if (ed->v1+1 != ed->v2) { + if (ed->v1 + 1 != ed->v2) { SWAP(unsigned int, medge->v1, medge->v2); } medge++; } else { /* equal edge, we merge the drawflag */ - (ed+1)->is_draw |= ed->is_draw; + (ed + 1)->is_draw |= ed->is_draw; } } /* last edge */ - medge->v1= ed->v1; - medge->v2= ed->v2; - medge->flag= ME_EDGEDRAW; - if (ed->is_loose) medge->flag|= ME_LOOSEEDGE; + medge->v1 = ed->v1; + medge->v2 = ed->v2; + medge->flag = ME_EDGEDRAW; + if (ed->is_loose) medge->flag |= ME_LOOSEEDGE; medge->flag |= ME_EDGERENDER; MEM_freeN(edsort); /*set edge members of mloops*/ - medge= *alledge; - for (a=0; a<*_totedge; a++, medge++) { + medge = *alledge; + for (a = 0; a < *_totedge; a++, medge++) { BLI_edgehash_insert(hash, medge->v1, medge->v2, SET_INT_IN_POINTER(a)); } mpoly = allpoly; - for (a=0; a<totpoly; a++, mpoly++) { + for (a = 0; a < totpoly; a++, mpoly++) { mloop = allloop + mpoly->loopstart; - for (b=0; b<mpoly->totloop; b++) { + for (b = 0; b < mpoly->totloop; b++) { int v1, v2; v1 = mloop[b].v; @@ -1018,19 +1018,19 @@ static void make_edges_mdata(MVert *UNUSED(allvert), MFace *allface, MLoop *alll void BKE_mesh_make_edges(Mesh *me, int old) { MEdge *medge; - int totedge=0; + int totedge = 0; make_edges_mdata(me->mvert, me->mface, me->mloop, me->mpoly, me->totvert, me->totface, me->totloop, me->totpoly, old, &medge, &totedge); - if (totedge==0) { + if (totedge == 0) { /* flag that mesh has edges */ me->medge = medge; me->totedge = 0; return; } - medge= CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, totedge); - me->medge= medge; - me->totedge= totedge; + medge = CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, totedge); + me->medge = medge; + me->totedge = totedge; BKE_mesh_strip_loose_faces(me); } @@ -1175,50 +1175,50 @@ void BKE_mesh_from_metaball(ListBase *lb, Mesh *me) float *nors, *verts; int a, *index; - dl= lb->first; - if (dl==NULL) return; - - if (dl->type==DL_INDEX4) { - mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, dl->nr); - allloop= mloop= CustomData_add_layer(&me->ldata, CD_MLOOP, CD_CALLOC, NULL, dl->parts * 4); - mpoly= CustomData_add_layer(&me->pdata, CD_MPOLY, CD_CALLOC, NULL, dl->parts); - me->mvert= mvert; - me->mloop= mloop; - me->mpoly= mpoly; - me->totvert= dl->nr; - me->totpoly= dl->parts; - - a= dl->nr; - nors= dl->nors; - verts= dl->verts; + dl = lb->first; + if (dl == NULL) return; + + if (dl->type == DL_INDEX4) { + mvert = CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, dl->nr); + allloop = mloop = CustomData_add_layer(&me->ldata, CD_MLOOP, CD_CALLOC, NULL, dl->parts * 4); + mpoly = CustomData_add_layer(&me->pdata, CD_MPOLY, CD_CALLOC, NULL, dl->parts); + me->mvert = mvert; + me->mloop = mloop; + me->mpoly = mpoly; + me->totvert = dl->nr; + me->totpoly = dl->parts; + + a = dl->nr; + nors = dl->nors; + verts = dl->verts; while (a--) { copy_v3_v3(mvert->co, verts); normal_float_to_short_v3(mvert->no, nors); mvert++; - nors+= 3; - verts+= 3; + nors += 3; + verts += 3; } - a= dl->parts; - index= dl->index; + a = dl->parts; + index = dl->index; while (a--) { - int count= index[2] != index[3] ? 4 : 3; + int count = index[2] != index[3] ? 4 : 3; - mloop[0].v= index[0]; - mloop[1].v= index[1]; - mloop[2].v= index[2]; + mloop[0].v = index[0]; + mloop[1].v = index[1]; + mloop[2].v = index[2]; if (count == 4) - mloop[3].v= index[3]; + mloop[3].v = index[3]; - mpoly->totloop= count; - mpoly->loopstart= (int)(mloop - allloop); - mpoly->flag= ME_SMOOTH; + mpoly->totloop = count; + mpoly->loopstart = (int)(mloop - allloop); + mpoly->flag = ME_SMOOTH; mpoly++; - mloop+= count; - me->totloop+= count; - index+= 4; + mloop += count; + me->totloop += count; + index += 4; } mesh_update_customdata_pointers(me, TRUE); @@ -1260,46 +1260,46 @@ int BKE_mesh_nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, MLoop *mloop; MEdge *medge; float *data; - int a, b, ofs, vertcount, startvert, totvert=0, totedge=0, totloop=0, totvlak=0; + int a, b, ofs, vertcount, startvert, totvert = 0, totedge = 0, totloop = 0, totvlak = 0; int p1, p2, p3, p4, *index; - int conv_polys= 0; + int conv_polys = 0; - cu= ob->data; + cu = ob->data; - conv_polys|= cu->flag & CU_3D; /* 2d polys are filled with DL_INDEX3 displists */ - conv_polys|= ob->type == OB_SURF; /* surf polys are never filled */ + conv_polys |= cu->flag & CU_3D; /* 2d polys are filled with DL_INDEX3 displists */ + conv_polys |= ob->type == OB_SURF; /* surf polys are never filled */ /* count */ - dl= dispbase->first; + dl = dispbase->first; while (dl) { - if (dl->type==DL_SEGM) { - totvert+= dl->parts*dl->nr; - totedge+= dl->parts*(dl->nr-1); + if (dl->type == DL_SEGM) { + totvert += dl->parts * dl->nr; + totedge += dl->parts * (dl->nr - 1); } - else if (dl->type==DL_POLY) { + else if (dl->type == DL_POLY) { if (conv_polys) { - totvert+= dl->parts*dl->nr; - totedge+= dl->parts*dl->nr; + totvert += dl->parts * dl->nr; + totedge += dl->parts * dl->nr; } } - else if (dl->type==DL_SURF) { + else if (dl->type == DL_SURF) { int tot; - totvert+= dl->parts*dl->nr; - tot = (dl->parts-1+((dl->flag & DL_CYCL_V)==2))*(dl->nr-1+(dl->flag & DL_CYCL_U)); + totvert += dl->parts * dl->nr; + tot = (dl->parts - 1 + ((dl->flag & DL_CYCL_V) == 2)) * (dl->nr - 1 + (dl->flag & DL_CYCL_U)); totvlak += tot; totloop += tot * 4; } - else if (dl->type==DL_INDEX3) { + else if (dl->type == DL_INDEX3) { int tot; - totvert+= dl->nr; + totvert += dl->nr; tot = dl->parts; - totvlak+= tot; + totvlak += tot; totloop += tot * 3; } - dl= dl->next; + dl = dl->next; } - if (totvert==0) { + if (totvert == 0) { /* error("can't convert"); */ /* Make Sure you check ob->data is a curve */ return -1; @@ -1311,28 +1311,28 @@ int BKE_mesh_nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, *allpoly = mpoly = MEM_callocN(sizeof(MPoly) * totvlak, "nurbs_init mloop"); /* verts and faces */ - vertcount= 0; + vertcount = 0; - dl= dispbase->first; + dl = dispbase->first; while (dl) { - int smooth= dl->rt & CU_SMOOTH ? 1 : 0; + int smooth = dl->rt & CU_SMOOTH ? 1 : 0; - if (dl->type==DL_SEGM) { - startvert= vertcount; - a= dl->parts*dl->nr; - data= dl->verts; + if (dl->type == DL_SEGM) { + startvert = vertcount; + a = dl->parts * dl->nr; + data = dl->verts; while (a--) { copy_v3_v3(mvert->co, data); - data+=3; + data += 3; vertcount++; mvert++; } - for (a=0; a<dl->parts; a++) { - ofs= a*dl->nr; - for (b=1; b<dl->nr; b++) { - medge->v1= startvert+ofs+b-1; - medge->v2= startvert+ofs+b; + for (a = 0; a < dl->parts; a++) { + ofs = a * dl->nr; + for (b = 1; b < dl->nr; b++) { + medge->v1 = startvert + ofs + b - 1; + medge->v2 = startvert + ofs + b; medge->flag = ME_LOOSEEDGE | ME_EDGERENDER | ME_EDGEDRAW; medge++; @@ -1340,122 +1340,122 @@ int BKE_mesh_nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, } } - else if (dl->type==DL_POLY) { + else if (dl->type == DL_POLY) { if (conv_polys) { - startvert= vertcount; - a= dl->parts*dl->nr; - data= dl->verts; + startvert = vertcount; + a = dl->parts * dl->nr; + data = dl->verts; while (a--) { copy_v3_v3(mvert->co, data); - data+=3; + data += 3; vertcount++; mvert++; } - for (a=0; a<dl->parts; a++) { - ofs= a*dl->nr; - for (b=0; b<dl->nr; b++) { - medge->v1= startvert+ofs+b; - if (b==dl->nr-1) medge->v2= startvert+ofs; - else medge->v2= startvert+ofs+b+1; + for (a = 0; a < dl->parts; a++) { + ofs = a * dl->nr; + for (b = 0; b < dl->nr; b++) { + medge->v1 = startvert + ofs + b; + if (b == dl->nr - 1) medge->v2 = startvert + ofs; + else medge->v2 = startvert + ofs + b + 1; medge->flag = ME_LOOSEEDGE | ME_EDGERENDER | ME_EDGEDRAW; medge++; } } } } - else if (dl->type==DL_INDEX3) { - startvert= vertcount; - a= dl->nr; - data= dl->verts; + else if (dl->type == DL_INDEX3) { + startvert = vertcount; + a = dl->nr; + data = dl->verts; while (a--) { copy_v3_v3(mvert->co, data); - data+=3; + data += 3; vertcount++; mvert++; } - a= dl->parts; - index= dl->index; + a = dl->parts; + index = dl->index; while (a--) { - mloop[0].v = startvert+index[0]; - mloop[1].v = startvert+index[2]; - mloop[2].v = startvert+index[1]; + mloop[0].v = startvert + index[0]; + mloop[1].v = startvert + index[2]; + mloop[2].v = startvert + index[1]; mpoly->loopstart = (int)(mloop - (*allloop)); mpoly->totloop = 3; mpoly->mat_nr = dl->col; if (smooth) mpoly->flag |= ME_SMOOTH; mpoly++; - mloop+= 3; - index+= 3; + mloop += 3; + index += 3; } } - else if (dl->type==DL_SURF) { - startvert= vertcount; - a= dl->parts*dl->nr; - data= dl->verts; + else if (dl->type == DL_SURF) { + startvert = vertcount; + a = dl->parts * dl->nr; + data = dl->verts; while (a--) { copy_v3_v3(mvert->co, data); - data+=3; + data += 3; vertcount++; mvert++; } - for (a=0; a<dl->parts; a++) { + for (a = 0; a < dl->parts; a++) { - if ( (dl->flag & DL_CYCL_V)==0 && a==dl->parts-1) break; + if ( (dl->flag & DL_CYCL_V) == 0 && a == dl->parts - 1) break; - if (dl->flag & DL_CYCL_U) { /* p2 -> p1 -> */ - p1= startvert+ dl->nr*a; /* p4 -> p3 -> */ - p2= p1+ dl->nr-1; /* -----> next row */ - p3= p1+ dl->nr; - p4= p2+ dl->nr; - b= 0; + if (dl->flag & DL_CYCL_U) { /* p2 -> p1 -> */ + p1 = startvert + dl->nr * a; /* p4 -> p3 -> */ + p2 = p1 + dl->nr - 1; /* -----> next row */ + p3 = p1 + dl->nr; + p4 = p2 + dl->nr; + b = 0; } else { - p2= startvert+ dl->nr*a; - p1= p2+1; - p4= p2+ dl->nr; - p3= p1+ dl->nr; - b= 1; + p2 = startvert + dl->nr * a; + p1 = p2 + 1; + p4 = p2 + dl->nr; + p3 = p1 + dl->nr; + b = 1; } - if ( (dl->flag & DL_CYCL_V) && a==dl->parts-1) { - p3-= dl->parts*dl->nr; - p4-= dl->parts*dl->nr; + if ( (dl->flag & DL_CYCL_V) && a == dl->parts - 1) { + p3 -= dl->parts * dl->nr; + p4 -= dl->parts * dl->nr; } - for (; b<dl->nr; b++) { - mloop[0].v= p1; - mloop[1].v= p3; - mloop[2].v= p4; - mloop[3].v= p2; + for (; b < dl->nr; b++) { + mloop[0].v = p1; + mloop[1].v = p3; + mloop[2].v = p4; + mloop[3].v = p2; mpoly->loopstart = (int)(mloop - (*allloop)); mpoly->totloop = 4; mpoly->mat_nr = dl->col; if (smooth) mpoly->flag |= ME_SMOOTH; mpoly++; - mloop+= 4; + mloop += 4; - p4= p3; + p4 = p3; p3++; - p2= p1; + p2 = p1; p1++; } } } - dl= dl->next; + dl = dl->next; } - *_totpoly= totvlak; - *_totloop= totloop; - *_totedge= totedge; - *_totvert= totvert; + *_totpoly = totvlak; + *_totloop = totloop; + *_totedge = totedge; + *_totvert = totvert; /* not uded for bmesh */ #if 0 @@ -1469,18 +1469,18 @@ int BKE_mesh_nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, /* this may fail replacing ob->data, be sure to check ob->type */ void BKE_mesh_from_nurbs(Object *ob) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob1; - DerivedMesh *dm= ob->derivedFinal; + DerivedMesh *dm = ob->derivedFinal; Mesh *me; Curve *cu; - MVert *allvert= NULL; - MEdge *alledge= NULL; + MVert *allvert = NULL; + MEdge *alledge = NULL; MLoop *allloop = NULL; MPoly *allpoly = NULL; int totvert, totedge, totloop, totpoly; - cu= ob->data; + cu = ob->data; if (dm == NULL) { if (BKE_mesh_nurbs_to_mdata(ob, &allvert, &totvert, @@ -1492,50 +1492,50 @@ void BKE_mesh_from_nurbs(Object *ob) } /* make mesh */ - me= BKE_mesh_add("Mesh"); - me->totvert= totvert; - me->totedge= totedge; + me = BKE_mesh_add("Mesh"); + me->totvert = totvert; + me->totedge = totedge; me->totloop = totloop; me->totpoly = totpoly; - me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, allvert, me->totvert); - me->medge= CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, alledge, me->totedge); - me->mloop= CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, allloop, me->totloop); - me->mpoly= CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, allpoly, me->totpoly); + me->mvert = CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, allvert, me->totvert); + me->medge = CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, alledge, me->totedge); + me->mloop = CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, allloop, me->totloop); + me->mpoly = CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, allpoly, me->totpoly); BKE_mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL); BKE_mesh_calc_edges(me, TRUE); } else { - me= BKE_mesh_add("Mesh"); + me = BKE_mesh_add("Mesh"); DM_to_mesh(dm, me, ob); } - me->totcol= cu->totcol; - me->mat= cu->mat; + me->totcol = cu->totcol; + me->mat = cu->mat; BKE_mesh_texspace_calc(me); - cu->mat= NULL; - cu->totcol= 0; + cu->mat = NULL; + cu->totcol = 0; if (ob->data) { BKE_libblock_free(&bmain->curve, ob->data); } - ob->data= me; - ob->type= OB_MESH; + ob->data = me; + ob->type = OB_MESH; /* other users */ - ob1= bmain->object.first; + ob1 = bmain->object.first; while (ob1) { - if (ob1->data==cu) { - ob1->type= OB_MESH; + if (ob1->data == cu) { + ob1->type = OB_MESH; - ob1->data= ob->data; + ob1->data = ob->data; id_us_plus((ID *)ob->data); } - ob1= ob1->id.next; + ob1 = ob1->id.next; } } @@ -1551,14 +1551,14 @@ typedef struct VertLink { static void prependPolyLineVert(ListBase *lb, unsigned int index) { - VertLink *vl= MEM_callocN(sizeof(VertLink), "VertLink"); + VertLink *vl = MEM_callocN(sizeof(VertLink), "VertLink"); vl->index = index; BLI_addhead(lb, vl); } static void appendPolyLineVert(ListBase *lb, unsigned int index) { - VertLink *vl= MEM_callocN(sizeof(VertLink), "VertLink"); + VertLink *vl = MEM_callocN(sizeof(VertLink), "VertLink"); vl->index = index; BLI_addtail(lb, vl); } @@ -1566,11 +1566,11 @@ static void appendPolyLineVert(ListBase *lb, unsigned int index) void BKE_mesh_from_curve(Scene *scene, Object *ob) { /* make new mesh data from the original copy */ - DerivedMesh *dm= mesh_get_derived_final(scene, ob, CD_MASK_MESH); + DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_MESH); - MVert *mverts= dm->getVertArray(dm); - MEdge *med, *medge= dm->getEdgeArray(dm); - MFace *mf, *mface= dm->getTessFaceArray(dm); + MVert *mverts = dm->getVertArray(dm); + MEdge *med, *medge = dm->getEdgeArray(dm); + MFace *mf, *mface = dm->getTessFaceArray(dm); int totedge = dm->getNumEdges(dm); int totface = dm->getNumTessFaces(dm); @@ -1585,7 +1585,7 @@ void BKE_mesh_from_curve(Scene *scene, Object *ob) ListBase edges = {NULL, NULL}; /* create edges from all faces (so as to find edges not in any faces) */ - mf= mface; + mf = mface; for (i = 0; i < totface; i++, mf++) { if (!BLI_edgehash_haskey(eh, mf->v1, mf->v2)) BLI_edgehash_insert(eh, mf->v1, mf->v2, NULL); @@ -1604,22 +1604,22 @@ void BKE_mesh_from_curve(Scene *scene, Object *ob) } } - med= medge; - for (i=0; i<totedge; i++, med++) { + med = medge; + for (i = 0; i < totedge; i++, med++) { if (!BLI_edgehash_haskey(eh, med->v1, med->v2)) { - EdgeLink *edl= MEM_callocN(sizeof(EdgeLink), "EdgeLink"); + EdgeLink *edl = MEM_callocN(sizeof(EdgeLink), "EdgeLink"); BLI_edgehash_insert(eh_edge, med->v1, med->v2, NULL); - edl->edge= med; + edl->edge = med; - BLI_addtail(&edges, edl); totedges++; + BLI_addtail(&edges, edl); totedges++; } } BLI_edgehash_free(eh_edge, NULL); BLI_edgehash_free(eh, NULL); if (edges.first) { - Curve *cu = BKE_curve_add(ob->id.name+2, OB_CURVE); + Curve *cu = BKE_curve_add(ob->id.name + 2, OB_CURVE); cu->flag |= CU_3D; while (edges.first) { @@ -1627,55 +1627,55 @@ void BKE_mesh_from_curve(Scene *scene, Object *ob) ListBase polyline = {NULL, NULL}; /* store a list of VertLink's */ int closed = FALSE; - int totpoly= 0; - MEdge *med_current= ((EdgeLink *)edges.last)->edge; - unsigned int startVert= med_current->v1; - unsigned int endVert= med_current->v2; - int ok= TRUE; + int totpoly = 0; + MEdge *med_current = ((EdgeLink *)edges.last)->edge; + unsigned int startVert = med_current->v1; + unsigned int endVert = med_current->v2; + int ok = TRUE; - appendPolyLineVert(&polyline, startVert); totpoly++; - appendPolyLineVert(&polyline, endVert); totpoly++; - BLI_freelinkN(&edges, edges.last); totedges--; + appendPolyLineVert(&polyline, startVert); totpoly++; + appendPolyLineVert(&polyline, endVert); totpoly++; + BLI_freelinkN(&edges, edges.last); totedges--; while (ok) { /* while connected edges are found... */ ok = FALSE; - i= totedges; + i = totedges; while (i) { EdgeLink *edl; - i-=1; - edl= BLI_findlink(&edges, i); - med= edl->edge; + i -= 1; + edl = BLI_findlink(&edges, i); + med = edl->edge; - if (med->v1==endVert) { + if (med->v1 == endVert) { endVert = med->v2; - appendPolyLineVert(&polyline, med->v2); totpoly++; - BLI_freelinkN(&edges, edl); totedges--; - ok= TRUE; + appendPolyLineVert(&polyline, med->v2); totpoly++; + BLI_freelinkN(&edges, edl); totedges--; + ok = TRUE; } - else if (med->v2==endVert) { + else if (med->v2 == endVert) { endVert = med->v1; - appendPolyLineVert(&polyline, endVert); totpoly++; - BLI_freelinkN(&edges, edl); totedges--; - ok= TRUE; + appendPolyLineVert(&polyline, endVert); totpoly++; + BLI_freelinkN(&edges, edl); totedges--; + ok = TRUE; } - else if (med->v1==startVert) { + else if (med->v1 == startVert) { startVert = med->v2; - prependPolyLineVert(&polyline, startVert); totpoly++; - BLI_freelinkN(&edges, edl); totedges--; - ok= TRUE; + prependPolyLineVert(&polyline, startVert); totpoly++; + BLI_freelinkN(&edges, edl); totedges--; + ok = TRUE; } - else if (med->v2==startVert) { + else if (med->v2 == startVert) { startVert = med->v1; - prependPolyLineVert(&polyline, startVert); totpoly++; - BLI_freelinkN(&edges, edl); totedges--; - ok= TRUE; + prependPolyLineVert(&polyline, startVert); totpoly++; + BLI_freelinkN(&edges, edl); totedges--; + ok = TRUE; } } } /* Now we have a polyline, make into a curve */ - if (startVert==endVert) { + if (startVert == endVert) { BLI_freelinkN(&polyline, polyline.last); totpoly--; closed = TRUE; @@ -1690,19 +1690,19 @@ void BKE_mesh_from_curve(Scene *scene, Object *ob) /* create new 'nurb' within the curve */ nu = (Nurb *)MEM_callocN(sizeof(Nurb), "MeshNurb"); - nu->pntsu= totpoly; - nu->pntsv= 1; - nu->orderu= 4; - nu->flagu= CU_NURB_ENDPOINT | (closed ? CU_NURB_CYCLIC:0); /* endpoint */ - nu->resolu= 12; + nu->pntsu = totpoly; + nu->pntsv = 1; + nu->orderu = 4; + nu->flagu = CU_NURB_ENDPOINT | (closed ? CU_NURB_CYCLIC : 0); /* endpoint */ + nu->resolu = 12; - nu->bp= (BPoint *)MEM_callocN(sizeof(BPoint)*totpoly, "bpoints"); + nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * totpoly, "bpoints"); /* add points */ - vl= polyline.first; - for (i=0, bp=nu->bp; i < totpoly; i++, bp++, vl=(VertLink *)vl->next) { + vl = polyline.first; + for (i = 0, bp = nu->bp; i < totpoly; i++, bp++, vl = (VertLink *)vl->next) { copy_v3_v3(bp->vec, mverts[vl->index].co); - bp->f1= SELECT; + bp->f1 = SELECT; bp->radius = bp->weight = 1.0; } BLI_freelistN(&polyline); @@ -1714,11 +1714,11 @@ void BKE_mesh_from_curve(Scene *scene, Object *ob) } ((Mesh *)ob->data)->id.us--; - ob->data= cu; - ob->type= OB_CURVE; + ob->data = cu; + ob->type = OB_CURVE; /* curve objects can't contain DM in usual cases, we could free memory */ - needsFree= 1; + needsFree = 1; } dm->needsFree = needsFree; @@ -1730,7 +1730,7 @@ void BKE_mesh_from_curve(Scene *scene, Object *ob) /* curve object could have got bounding box only in special cases */ if (ob->bb) { MEM_freeN(ob->bb); - ob->bb= NULL; + ob->bb = NULL; } } } @@ -1739,15 +1739,15 @@ void BKE_mesh_delete_material_index(Mesh *me, short index) { int i; - for (i=0; i<me->totpoly; i++) { - MPoly *mp = &((MPoly*) me->mpoly)[i]; - if (mp->mat_nr && mp->mat_nr>=index) + for (i = 0; i < me->totpoly; i++) { + MPoly *mp = &((MPoly *) me->mpoly)[i]; + if (mp->mat_nr && mp->mat_nr >= index) mp->mat_nr--; } - for (i=0; i<me->totface; i++) { - MFace *mf = &((MFace*) me->mface)[i]; - if (mf->mat_nr && mf->mat_nr>=index) + for (i = 0; i < me->totface; i++) { + MFace *mf = &((MFace *) me->mface)[i]; + if (mf->mat_nr && mf->mat_nr >= index) mf->mat_nr--; } } @@ -1757,8 +1757,8 @@ void BKE_mesh_smooth_flag_set(Object *meshOb, int enableSmooth) Mesh *me = meshOb->data; int i; - for (i=0; i<me->totpoly; i++) { - MPoly *mp = &((MPoly*) me->mpoly)[i]; + for (i = 0; i < me->totpoly; i++) { + MPoly *mp = &((MPoly *) me->mpoly)[i]; if (enableSmooth) { mp->flag |= ME_SMOOTH; @@ -1768,8 +1768,8 @@ void BKE_mesh_smooth_flag_set(Object *meshOb, int enableSmooth) } } - for (i=0; i<me->totface; i++) { - MFace *mf = &((MFace*) me->mface)[i]; + for (i = 0; i < me->totface; i++) { + MFace *mf = &((MFace *) me->mface)[i]; if (enableSmooth) { mf->flag |= ME_SMOOTH; @@ -1781,8 +1781,8 @@ void BKE_mesh_smooth_flag_set(Object *meshOb, int enableSmooth) } void BKE_mesh_calc_normals_mapping(MVert *mverts, int numVerts, - MLoop *mloop, MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3], - MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3]) + MLoop *mloop, MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3], + MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3]) { BKE_mesh_calc_normals_mapping_ex(mverts, numVerts, mloop, mpolys, numLoops, numPolys, polyNors_r, mfaces, numFaces, @@ -1790,10 +1790,10 @@ void BKE_mesh_calc_normals_mapping(MVert *mverts, int numVerts, } void BKE_mesh_calc_normals_mapping_ex(MVert *mverts, int numVerts, - MLoop *mloop, MPoly *mpolys, - int numLoops, int numPolys, float (*polyNors_r)[3], - MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3], - const short only_face_normals) + MLoop *mloop, MPoly *mpolys, + int numLoops, int numPolys, float (*polyNors_r)[3], + MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3], + const short only_face_normals) { float (*pnors)[3] = polyNors_r, (*fnors)[3] = faceNors_r; int i; @@ -1822,18 +1822,18 @@ void BKE_mesh_calc_normals_mapping_ex(MVert *mverts, int numVerts, else { /* only calc poly normals */ mp = mpolys; - for (i=0; i<numPolys; i++, mp++) { - mesh_calc_poly_normal(mp, mloop+mp->loopstart, mverts, pnors[i]); + for (i = 0; i < numPolys; i++, mp++) { + mesh_calc_poly_normal(mp, mloop + mp->loopstart, mverts, pnors[i]); } } - if ( origIndexFace && - /* fnors==faceNors_r */ /* NO NEED TO ALLOC YET */ - fnors != NULL && - numFaces) + if (origIndexFace && + /* fnors==faceNors_r */ /* NO NEED TO ALLOC YET */ + fnors != NULL && + numFaces) { mf = mfaces; - for (i=0; i<numFaces; i++, mf++, origIndexFace++) { + for (i = 0; i < numFaces; i++, mf++, origIndexFace++) { if (*origIndexFace < numPolys) { copy_v3_v3(fnors[i], pnors[*origIndexFace]); } @@ -1856,7 +1856,7 @@ void BKE_mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpo { float (*pnors)[3] = polyNors_r; - float (*tnorms)[3], (*edgevecbuf)[3]= NULL; + float (*tnorms)[3], (*edgevecbuf)[3] = NULL; float **vertcos = NULL, **vertnos = NULL; BLI_array_declare(vertcos); BLI_array_declare(vertnos); @@ -1869,11 +1869,11 @@ void BKE_mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpo if (!pnors) pnors = MEM_callocN(sizeof(float) * 3 * numPolys, "poly_nors mesh.c"); /*first go through and calculate normals for all the polys*/ - tnorms = MEM_callocN(sizeof(float)*3*numVerts, "tnorms mesh.c"); + tnorms = MEM_callocN(sizeof(float) * 3 * numVerts, "tnorms mesh.c"); mp = mpolys; - for (i=0; i<numPolys; i++, mp++) { - mesh_calc_poly_normal(mp, mloop+mp->loopstart, mverts, pnors[i]); + for (i = 0; i < numPolys; i++, mp++) { + mesh_calc_poly_normal(mp, mloop + mp->loopstart, mverts, pnors[i]); ml = mloop + mp->loopstart; BLI_array_empty(vertcos); @@ -1881,7 +1881,7 @@ void BKE_mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpo BLI_array_grow_items(vertcos, mp->totloop); BLI_array_grow_items(vertnos, mp->totloop); - for (j=0; j < mp->totloop; j++) { + for (j = 0; j < mp->totloop; j++) { int vindex = ml[j].v; vertcos[j] = mverts[vindex].co; vertnos[j] = tnorms[vindex]; @@ -1898,9 +1898,9 @@ void BKE_mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpo BLI_array_free(edgevecbuf); /* following Mesh convention; we use vertex coordinate itself for normal in this case */ - for (i=0; i<numVerts; i++) { - MVert *mv= &mverts[i]; - float *no= tnorms[i]; + for (i = 0; i < numVerts; i++) { + MVert *mv = &mverts[i]; + float *no = tnorms[i]; if (normalize_v3(no) == 0.0f) normalize_v3_v3(no, mv->co); @@ -1915,15 +1915,15 @@ void BKE_mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpo void BKE_mesh_calc_normals_tessface(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*faceNors_r)[3]) { - float (*tnorms)[3]= MEM_callocN(numVerts*sizeof(*tnorms), "tnorms"); - float (*fnors)[3]= (faceNors_r)? faceNors_r: MEM_callocN(sizeof(*fnors)*numFaces, "meshnormals"); + float (*tnorms)[3] = MEM_callocN(numVerts * sizeof(*tnorms), "tnorms"); + float (*fnors)[3] = (faceNors_r) ? faceNors_r : MEM_callocN(sizeof(*fnors) * numFaces, "meshnormals"); int i; - for (i=0; i<numFaces; i++) { - MFace *mf= &mfaces[i]; - float *f_no= fnors[i]; - float *n4 = (mf->v4)? tnorms[mf->v4]: NULL; - float *c4 = (mf->v4)? mverts[mf->v4].co: NULL; + for (i = 0; i < numFaces; i++) { + MFace *mf = &mfaces[i]; + float *f_no = fnors[i]; + float *n4 = (mf->v4) ? tnorms[mf->v4] : NULL; + float *c4 = (mf->v4) ? mverts[mf->v4].co : NULL; if (mf->v4) normal_quad_v3(f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, mverts[mf->v4].co); @@ -1931,13 +1931,13 @@ void BKE_mesh_calc_normals_tessface(MVert *mverts, int numVerts, MFace *mfaces, normal_tri_v3(f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co); accumulate_vertex_normals(tnorms[mf->v1], tnorms[mf->v2], tnorms[mf->v3], n4, - f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, c4); + f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, c4); } /* following Mesh convention; we use vertex coordinate itself for normal in this case */ - for (i=0; i<numVerts; i++) { - MVert *mv= &mverts[i]; - float *no= tnorms[i]; + for (i = 0; i < numVerts; i++) { + MVert *mv = &mverts[i]; + float *no = tnorms[i]; if (normalize_v3(no) == 0.0f) normalize_v3_v3(no, mv->co); @@ -1964,7 +1964,7 @@ static void bm_corners_to_loops(Mesh *me, int findex, int loopstart, int numTex, mf = me->mface + findex; - for (i=0; i < numTex; i++) { + for (i = 0; i < numTex; i++) { texface = CustomData_get_n(&me->fdata, CD_MTFACE, findex, i); texpoly = CustomData_get_n(&me->pdata, CD_MTEXPOLY, findex, i); @@ -1980,7 +1980,7 @@ static void bm_corners_to_loops(Mesh *me, int findex, int loopstart, int numTex, } } - for (i=0; i < numCol; i++) { + for (i = 0; i < numCol; i++) { mloopcol = CustomData_get_n(&me->ldata, CD_MLOOPCOL, loopstart, i); mcol = CustomData_get_n(&me->fdata, CD_MCOL, findex, i); @@ -2001,7 +2001,7 @@ static void bm_corners_to_loops(Mesh *me, int findex, int loopstart, int numTex, if (CustomData_external_test(&me->fdata, CD_MDISPS)) { CustomData_external_add(&me->ldata, &me->id, CD_MDISPS, - me->totloop, me->fdata.external->filename); + me->totloop, me->fdata.external->filename); } corners = multires_mdisp_corners(fd); @@ -2015,16 +2015,16 @@ static void bm_corners_to_loops(Mesh *me, int findex, int loopstart, int numTex, else { side = sqrt(fd->totdisp / corners); - for (i=0; i<tot; i++, disps += side*side, ld++) { - ld->totdisp = side*side; + for (i = 0; i < tot; i++, disps += side * side, ld++) { + ld->totdisp = side * side; ld->level = (int)(logf(side - 1.0f) / (float)M_LN2) + 1; if (ld->disps) MEM_freeN(ld->disps); - ld->disps = MEM_callocN(sizeof(float)*3*side*side, "converted loop mdisps"); + ld->disps = MEM_callocN(sizeof(float) * 3 * side * side, "converted loop mdisps"); if (fd->disps) { - memcpy(ld->disps, disps, sizeof(float)*3*side*side); + memcpy(ld->disps, disps, sizeof(float) * 3 * side * side); } } } @@ -2048,7 +2048,7 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) memset(&mesh->pdata, 0, sizeof(mesh->pdata)); mesh->totpoly = mesh->totface; - mesh->mpoly = MEM_callocN(sizeof(MPoly)*mesh->totpoly, "mpoly converted"); + mesh->mpoly = MEM_callocN(sizeof(MPoly) * mesh->totpoly, "mpoly converted"); CustomData_add_layer(&mesh->pdata, CD_MPOLY, CD_ASSIGN, mesh->mpoly, mesh->totpoly); numTex = CustomData_number_of_layers(&mesh->fdata, CD_MTFACE); @@ -2056,16 +2056,16 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) totloop = 0; mf = mesh->mface; - for (i=0; i<mesh->totface; i++, mf++) { + for (i = 0; i < mesh->totface; i++, mf++) { totloop += mf->v4 ? 4 : 3; } mesh->totloop = totloop; - mesh->mloop = MEM_callocN(sizeof(MLoop)*mesh->totloop, "mloop converted"); + mesh->mloop = MEM_callocN(sizeof(MLoop) * mesh->totloop, "mloop converted"); CustomData_add_layer(&mesh->ldata, CD_MLOOP, CD_ASSIGN, mesh->mloop, totloop); CustomData_to_bmeshpoly(&mesh->fdata, &mesh->pdata, &mesh->ldata, - mesh->totloop, mesh->totpoly); + mesh->totloop, mesh->totpoly); /* ensure external data is transferred */ CustomData_external_read(&mesh->fdata, &mesh->id, CD_MASK_MDISPS, mesh->totface); @@ -2085,7 +2085,7 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) ml = mesh->mloop; mf = mesh->mface; mp = mesh->mpoly; - for (i=0; i<mesh->totface; i++, mf++, mp++) { + for (i = 0; i < mesh->totface; i++, mf++, mp++) { mp->loopstart = j; mp->totloop = mf->v4 ? 4 : 3; @@ -2093,7 +2093,8 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) mp->mat_nr = mf->mat_nr; mp->flag = mf->flag; -# define ML(v1, v2) {ml->v = mf->v1; ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v1, mf->v2)); ml++; j++;} +# define ML(v1, v2) {ml->v = mf->v1; ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v1, mf->v2)); ml++; j++; \ +} ML(v1, v2); ML(v2, v3); @@ -2105,7 +2106,7 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) ML(v3, v1); } -# undef ML +# undef ML bm_corners_to_loops(mesh, i, mp->loopstart, numTex, numCol); } @@ -2118,13 +2119,13 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) BLI_edgehash_free(eh, NULL); } -float (*mesh_getVertexCos(Mesh *me, int *numVerts_r))[3] +float (*mesh_getVertexCos(Mesh * me, int *numVerts_r))[3] { int i, numVerts = me->totvert; - float (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "vertexcos1"); + float (*cos)[3] = MEM_mallocN(sizeof(*cos) * numVerts, "vertexcos1"); if (numVerts_r) *numVerts_r = numVerts; - for (i=0; i<numVerts; i++) + for (i = 0; i < numVerts; i++) copy_v3_v3(cos[i], me->mvert[i].co); return cos; @@ -2141,86 +2142,86 @@ UvVertMap *BKE_mesh_uv_vert_map_make(struct MPoly *mpoly, struct MLoop *mloop, s UvMapVert *buf; MPoly *mp; unsigned int a; - int i, totuv, nverts; + int i, totuv, nverts; totuv = 0; /* generate UvMapVert array */ - mp= mpoly; - for (a=0; a<totpoly; a++, mp++) + mp = mpoly; + for (a = 0; a < totpoly; a++, mp++) if (!selected || (!(mp->flag & ME_HIDE) && (mp->flag & ME_FACE_SEL))) totuv += mp->totloop; - if (totuv==0) + if (totuv == 0) return NULL; - vmap= (UvVertMap*)MEM_callocN(sizeof(*vmap), "UvVertMap"); + vmap = (UvVertMap *)MEM_callocN(sizeof(*vmap), "UvVertMap"); if (!vmap) return NULL; - vmap->vert= (UvMapVert**)MEM_callocN(sizeof(*vmap->vert)*totvert, "UvMapVert*"); - buf= vmap->buf= (UvMapVert*)MEM_callocN(sizeof(*vmap->buf)*totuv, "UvMapVert"); + vmap->vert = (UvMapVert **)MEM_callocN(sizeof(*vmap->vert) * totvert, "UvMapVert*"); + buf = vmap->buf = (UvMapVert *)MEM_callocN(sizeof(*vmap->buf) * totuv, "UvMapVert"); if (!vmap->vert || !vmap->buf) { BKE_mesh_uv_vert_map_free(vmap); return NULL; } - mp= mpoly; - for (a=0; a<totpoly; a++, mp++) { + mp = mpoly; + for (a = 0; a < totpoly; a++, mp++) { if (!selected || (!(mp->flag & ME_HIDE) && (mp->flag & ME_FACE_SEL))) { - nverts= mp->totloop; + nverts = mp->totloop; - for (i=0; i<nverts; i++) { - buf->tfindex= i; - buf->f= a; + for (i = 0; i < nverts; i++) { + buf->tfindex = i; + buf->f = a; buf->separate = 0; - buf->next= vmap->vert[mloop[mp->loopstart + i].v]; - vmap->vert[mloop[mp->loopstart + i].v]= buf; + buf->next = vmap->vert[mloop[mp->loopstart + i].v]; + vmap->vert[mloop[mp->loopstart + i].v] = buf; buf++; } } } /* sort individual uvs for each vert */ - for (a=0; a<totvert; a++) { - UvMapVert *newvlist= NULL, *vlist=vmap->vert[a]; + for (a = 0; a < totvert; a++) { + UvMapVert *newvlist = NULL, *vlist = vmap->vert[a]; UvMapVert *iterv, *v, *lastv, *next; float *uv, *uv2, uvdiff[2]; while (vlist) { - v= vlist; - vlist= vlist->next; - v->next= newvlist; - newvlist= v; + v = vlist; + vlist = vlist->next; + v->next = newvlist; + newvlist = v; - uv= mloopuv[mpoly[v->f].loopstart + v->tfindex].uv; - lastv= NULL; - iterv= vlist; + uv = mloopuv[mpoly[v->f].loopstart + v->tfindex].uv; + lastv = NULL; + iterv = vlist; while (iterv) { - next= iterv->next; + next = iterv->next; - uv2= mloopuv[mpoly[iterv->f].loopstart + iterv->tfindex].uv; + uv2 = mloopuv[mpoly[iterv->f].loopstart + iterv->tfindex].uv; sub_v2_v2v2(uvdiff, uv2, uv); - if (fabsf(uv[0]-uv2[0]) < limit[0] && fabsf(uv[1]-uv2[1]) < limit[1]) { - if (lastv) lastv->next= next; - else vlist= next; - iterv->next= newvlist; - newvlist= iterv; + if (fabsf(uv[0] - uv2[0]) < limit[0] && fabsf(uv[1] - uv2[1]) < limit[1]) { + if (lastv) lastv->next = next; + else vlist = next; + iterv->next = newvlist; + newvlist = iterv; } else - lastv=iterv; + lastv = iterv; - iterv= next; + iterv = next; } newvlist->separate = 1; } - vmap->vert[a]= newvlist; + vmap->vert[a] = newvlist; } return vmap; @@ -2300,7 +2301,7 @@ void create_vert_edge_map(ListBase **map, IndexNode **mem, const MEdge *medge, c for (i = 0; i < totedge; ++i) { for (j = 0; j < 2; ++j, ++node) { node->index = i; - BLI_addtail(&(*map)[((unsigned int*)(&medge[i].v1))[j]], node); + BLI_addtail(&(*map)[((unsigned int *)(&medge[i].v1))[j]], node); } } } @@ -2324,22 +2325,22 @@ void BKE_mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata, MLoopUV *mloopuv; int i, j; - for (i=0; i < numTex; i++) { + for (i = 0; i < numTex; i++) { texface = CustomData_get_n(fdata, CD_MTFACE, findex, i); texpoly = CustomData_get_n(pdata, CD_MTEXPOLY, polyindex, i); ME_MTEXFACE_CPY(texface, texpoly); - for (j=0; j < mf_len; j++) { + for (j = 0; j < mf_len; j++) { mloopuv = CustomData_get_n(ldata, CD_MLOOPUV, lindex[j], i); copy_v2_v2(texface->uv[j], mloopuv->uv); } } - for (i=0; i < numCol; i++) { + for (i = 0; i < numCol; i++) { mcol = CustomData_get_n(fdata, CD_MCOL, findex, i); - for (j=0; j < mf_len; j++) { + for (j = 0; j < mf_len; j++) { mloopcol = CustomData_get_n(ldata, CD_MLOOPCOL, lindex[j], i); MESH_MLOOPCOL_TO_MCOL(mloopcol, &mcol[j]); } @@ -2348,7 +2349,7 @@ void BKE_mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata, if (hasPCol) { mcol = CustomData_get(fdata, findex, CD_PREVIEW_MCOL); - for (j=0; j < mf_len; j++) { + for (j = 0; j < mf_len; j++) { mloopcol = CustomData_get(ldata, lindex[j], CD_PREVIEW_MLOOPCOL); MESH_MLOOPCOL_TO_MCOL(mloopcol, &mcol[j]); } @@ -2358,7 +2359,7 @@ void BKE_mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata, OrigSpaceFace *of = CustomData_get(fdata, findex, CD_ORIGSPACE); OrigSpaceLoop *lof; - for (j=0; j < mf_len; j++) { + for (j = 0; j < mf_len; j++) { lof = CustomData_get(ldata, lindex[j], CD_ORIGSPACE_MLOOP); copy_v2_v2(of->uv[j], lof->uv); } @@ -2370,12 +2371,12 @@ void BKE_mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata, * returns number of tessellation faces. */ int BKE_mesh_recalc_tessellation(CustomData *fdata, - CustomData *ldata, CustomData *pdata, - MVert *mvert, int totface, int UNUSED(totloop), - int totpoly, - /* when tessellating to recalculate normals after - * we can skip copying here */ - const int do_face_nor_cpy) + CustomData *ldata, CustomData *pdata, + MVert *mvert, int totface, int UNUSED(totloop), + int totpoly, + /* when tessellating to recalculate normals after + * we can skip copying here */ + const int do_face_nor_cpy) { /* use this to avoid locking pthread for _every_ polygon * and calling the fill function */ @@ -2383,8 +2384,8 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata, #define USE_TESSFACE_SPEEDUP #define USE_TESSFACE_QUADS // NEEDS FURTHER TESTING -#define TESSFACE_SCANFILL (1<<0) -#define TESSFACE_IS_QUAD (1<<1) +#define TESSFACE_SCANFILL (1 << 0) +#define TESSFACE_IS_QUAD (1 << 1) MPoly *mp, *mpoly; MLoop *ml, *mloop; @@ -2428,7 +2429,7 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata, BLI_array_grow_one(mface_to_poly_map); \ BLI_array_grow_one(mface); \ mface_to_poly_map[mface_index] = poly_index; \ - mf= &mface[mface_index]; \ + mf = &mface[mface_index]; \ /* set loop indices, transformed to vert indices later */ \ mf->v1 = mp->loopstart + i1; \ mf->v2 = mp->loopstart + i2; \ @@ -2447,7 +2448,7 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata, BLI_array_grow_one(mface_to_poly_map); \ BLI_array_grow_one(mface); \ mface_to_poly_map[mface_index] = poly_index; \ - mf= &mface[mface_index]; \ + mf = &mface[mface_index]; \ /* set loop indices, transformed to vert indices later */ \ mf->v1 = mp->loopstart + 0; /* EXCEPTION */ \ mf->v2 = mp->loopstart + 1; /* EXCEPTION */ \ @@ -2487,7 +2488,7 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata, BLI_scanfill_begin(&sf_ctx); firstv = NULL; lastv = NULL; - for (j=0; j<mp->totloop; j++, ml++) { + for (j = 0; j < mp->totloop; j++, ml++) { v = BLI_scanfill_vert_add(&sf_ctx, mvert[ml->v].co); v->keyindex = mp->loopstart + j; @@ -2511,7 +2512,7 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata, for (f = sf_ctx.fillfacebase.first; f; f = f->next, mf++) { mface_to_poly_map[mface_index] = poly_index; - mf= &mface[mface_index]; + mf = &mface[mface_index]; /* set loop indices, transformed to vert indices later */ mf->v1 = f->v1->keyindex; @@ -2579,7 +2580,7 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata, } mf = mface; - for (mface_index=0; mface_index < totface; mface_index++, mf++) { + for (mface_index = 0; mface_index < totface; mface_index++, mf++) { #ifdef USE_TESSFACE_QUADS const int mf_len = mf->edcode & TESSFACE_IS_QUAD ? 4 : 3; @@ -2651,7 +2652,7 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata, * returns number of tessellation faces. */ int BKE_mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, - struct CustomData *pdata, int totface, int UNUSED(totloop), int totpoly) + struct CustomData *pdata, int totface, int UNUSED(totloop), int totpoly) { MLoop *mloop; @@ -2673,7 +2674,7 @@ int BKE_mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, mp = mpoly; k = 0; - for (i = 0; i<totpoly; i++, mp++) { + for (i = 0; i < totpoly; i++, mp++) { if (ELEM(mp->totloop, 3, 4)) { BLI_array_grow_one(mface); mf = &mface[k]; @@ -2696,7 +2697,7 @@ int BKE_mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, CustomData_free(fdata, totface); memset(fdata, 0, sizeof(CustomData)); - totface= k; + totface = k; CustomData_add_layer(fdata, CD_MFACE, CD_ASSIGN, mface, totface); @@ -2704,7 +2705,7 @@ int BKE_mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, mp = mpoly; k = 0; - for (i = 0; i<totpoly; i++, mp++) { + for (i = 0; i < totpoly; i++, mp++) { if (ELEM(mp->totloop, 3, 4)) { mf = &mface[k]; @@ -2748,7 +2749,7 @@ int BKE_mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata, test_index_face(mf, fdata, k, 4); } - mf->edcode= 0; + mf->edcode = 0; k++; } @@ -2833,7 +2834,7 @@ static void mesh_calc_ngon_normal_coords(MPoly *mpoly, MLoop *loopstart, } void BKE_mesh_calc_poly_normal_coords(MPoly *mpoly, MLoop *loopstart, - const float (*vertex_coords)[3], float no[3]) + const float (*vertex_coords)[3], float no[3]) { if (mpoly->totloop > 4) { mesh_calc_ngon_normal_coords(mpoly, loopstart, vertex_coords, no); @@ -2863,7 +2864,7 @@ void BKE_mesh_calc_poly_normal_coords(MPoly *mpoly, MLoop *loopstart, static void mesh_calc_ngon_center(MPoly *mpoly, MLoop *loopstart, MVert *mvert, float cent[3]) { - const float w= 1.0f / (float)mpoly->totloop; + const float w = 1.0f / (float)mpoly->totloop; int i; zero_v3(cent); @@ -2874,7 +2875,7 @@ static void mesh_calc_ngon_center(MPoly *mpoly, MLoop *loopstart, } void BKE_mesh_calc_poly_center(MPoly *mpoly, MLoop *loopstart, - MVert *mvarray, float cent[3]) + MVert *mvarray, float cent[3]) { if (mpoly->totloop == 3) { cent_tri_v3(cent, @@ -2898,7 +2899,7 @@ void BKE_mesh_calc_poly_center(MPoly *mpoly, MLoop *loopstart, /* note, passing polynormal is only a speedup so we can skip calculating it */ float BKE_mesh_calc_poly_area(MPoly *mpoly, MLoop *loopstart, - MVert *mvarray, float polynormal[3]) + MVert *mvarray, float polynormal[3]) { if (mpoly->totloop == 3) { return area_tri_v3(mvarray[loopstart[0].v].co, @@ -2917,7 +2918,7 @@ float BKE_mesh_calc_poly_area(MPoly *mpoly, MLoop *loopstart, int i; MLoop *l_iter = loopstart; float area, polynorm_local[3], (*vertexcos)[3]; - float *no= polynormal ? polynormal : polynorm_local; + float *no = polynormal ? polynormal : polynorm_local; BLI_array_fixedstack_declare(vertexcos, BM_NGON_STACK_SIZE, mpoly->totloop, __func__); /* pack vertex cos into an array for area_poly_v3 */ @@ -2942,7 +2943,7 @@ float BKE_mesh_calc_poly_area(MPoly *mpoly, MLoop *loopstart, /* Find the index of the loop in 'poly' which references vertex, * returns -1 if not found */ int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart, - unsigned vert) + unsigned vert) { int j; for (j = 0; j < poly->totloop; j++, loopstart++) { @@ -2957,11 +2958,11 @@ int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart, * vertex. Returns the index of the loop matching vertex, or -1 if the * vertex is not in 'poly' */ int poly_get_adj_loops_from_vert(unsigned adj_r[3], const MPoly *poly, - const MLoop *mloop, unsigned vert) + const MLoop *mloop, unsigned vert) { int corner = poly_find_loop_from_vert(poly, - &mloop[poly->loopstart], - vert); + &mloop[poly->loopstart], + vert); if (corner != -1) { const MLoop *ml = &mloop[poly->loopstart + corner]; @@ -2978,9 +2979,9 @@ int poly_get_adj_loops_from_vert(unsigned adj_r[3], const MPoly *poly, /* update the hide flag for edges and faces from the corresponding * flag in verts */ void BKE_mesh_flush_hidden_from_verts(const MVert *mvert, - const MLoop *mloop, - MEdge *medge, int totedge, - MPoly *mpoly, int totpoly) + const MLoop *mloop, + MEdge *medge, int totedge, + MPoly *mpoly, int totpoly) { int i, j; @@ -3019,15 +3020,15 @@ int BKE_mesh_minmax(Mesh *me, float r_min[3], float r_max[3]) int BKE_mesh_center_median(Mesh *me, float cent[3]) { - int i= me->totvert; + int i = me->totvert; MVert *mvert; zero_v3(cent); - for (mvert= me->mvert; i--; mvert++) { + for (mvert = me->mvert; i--; mvert++) { add_v3_v3(cent, mvert->co); } /* otherwise we get NAN for 0 verts */ if (me->totvert) { - mul_v3_fl(cent, 1.0f/(float)me->totvert); + mul_v3_fl(cent, 1.0f / (float)me->totvert); } return (me->totvert != 0); @@ -3047,17 +3048,17 @@ int BKE_mesh_center_bounds(Mesh *me, float cent[3]) void BKE_mesh_translate(Mesh *me, float offset[3], int do_keys) { - int i= me->totvert; + int i = me->totvert; MVert *mvert; - for (mvert= me->mvert; i--; mvert++) { + for (mvert = me->mvert; i--; mvert++) { add_v3_v3(mvert->co, offset); } if (do_keys && me->key) { KeyBlock *kb; - for (kb=me->key->block.first; kb; kb=kb->next) { - float *fp= kb->data; - for (i= kb->totelem; i--; fp+=3) { + for (kb = me->key->block.first; kb; kb = kb->next) { + float *fp = kb->data; + for (i = kb->totelem; i--; fp += 3) { add_v3_v3(fp, offset); } } @@ -3072,9 +3073,9 @@ void BKE_mesh_ensure_navmesh(Mesh *me) int numFaces = me->totpoly; int *recastData; CustomData_add_layer_named(&me->pdata, CD_RECAST, CD_CALLOC, NULL, numFaces, "recastData"); - recastData = (int*)CustomData_get_layer(&me->pdata, CD_RECAST); - for (i=0; i<numFaces; i++) { - recastData[i] = i+1; + recastData = (int *)CustomData_get_layer(&me->pdata, CD_RECAST); + for (i = 0; i < numFaces; i++) { + recastData[i] = i + 1; } CustomData_add_layer_named(&me->pdata, CD_RECAST, CD_REFERENCE, recastData, numFaces, "recastData"); } @@ -3083,10 +3084,10 @@ void BKE_mesh_ensure_navmesh(Mesh *me) void BKE_mesh_tessface_calc(Mesh *mesh) { mesh->totface = BKE_mesh_recalc_tessellation(&mesh->fdata, &mesh->ldata, &mesh->pdata, - mesh->mvert, - mesh->totface, mesh->totloop, mesh->totpoly, - /* calc normals right after, don't copy from polys here */ - FALSE); + mesh->mvert, + mesh->totface, mesh->totloop, mesh->totpoly, + /* calc normals right after, don't copy from polys here */ + FALSE); mesh_update_customdata_pointers(mesh, TRUE); } diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 849dbd83366..31741718a09 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -71,7 +71,7 @@ #include "BKE_main.h" #include "BKE_utildefines.h" #include "BKE_movieclip.h" -#include "BKE_image.h" /* openanim */ +#include "BKE_image.h" /* openanim */ #include "BKE_tracking.h" #include "IMB_imbuf_types.h" @@ -205,7 +205,7 @@ static ImBuf *movieclip_load_sequence_file(MovieClip *clip, MovieClipUser *user, else get_sequence_fname(clip, framenr, name); - loadflag = IB_rect|IB_multilayer; + loadflag = IB_rect | IB_multilayer; /* read ibuf */ ibuf = IMB_loadiffname(name, loadflag); @@ -250,7 +250,7 @@ static ImBuf *movieclip_load_movie_file(MovieClip *clip, MovieClipUser *user, in dur = IMB_anim_get_duration(clip->anim, tc); fra = framenr - 1; - if (fra<0) + if (fra < 0) fra = 0; if (fra > (dur - 1)) @@ -283,7 +283,7 @@ static void movieclip_calc_length(MovieClip *clip) clip->len = framenr + 1; } else { - for (;;) { + for (;; ) { get_sequence_fname(clip, framenr, name); if (!BLI_exists(name)) { @@ -338,7 +338,7 @@ typedef struct MovieClipImBufCacheKey { static void moviecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags) { - MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey*)userkey; + MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey *)userkey; *framenr = key->framenr; *proxy = key->proxy; @@ -347,7 +347,7 @@ static void moviecache_keydata(void *userkey, int *framenr, int *proxy, int *ren static unsigned int moviecache_hashhash(const void *keyv) { - MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey*)keyv; + MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey *)keyv; int rval = key->framenr; return rval; @@ -355,8 +355,8 @@ static unsigned int moviecache_hashhash(const void *keyv) static int moviecache_hashcmp(const void *av, const void *bv) { - const MovieClipImBufCacheKey *a = (MovieClipImBufCacheKey*)av; - const MovieClipImBufCacheKey *b = (MovieClipImBufCacheKey*)bv; + const MovieClipImBufCacheKey *a = (MovieClipImBufCacheKey *)av; + const MovieClipImBufCacheKey *b = (MovieClipImBufCacheKey *)bv; if (a->framenr < b->framenr) return -1; @@ -406,7 +406,7 @@ static void put_imbuf_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, i clip->cache = MEM_callocN(sizeof(MovieClipCache), "movieClipCache"); clip->cache->moviecache = IMB_moviecache_create(sizeof(MovieClipImBufCacheKey), moviecache_hashhash, - moviecache_hashcmp, moviecache_keydata); + moviecache_hashcmp, moviecache_keydata); } key.framenr = user->framenr; @@ -529,8 +529,8 @@ static void real_ibuf_size(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, in break; case MCLIP_PROXY_RENDER_SIZE_75: - *width = ((float)*width)*4.0f/3.0f; - *height = ((float)*height)*4.0f/3.0f; + *width = ((float)*width) * 4.0f / 3.0f; + *height = ((float)*height) * 4.0f / 3.0f; break; } } @@ -669,8 +669,8 @@ static ImBuf *put_postprocessed_frame_to_cache(MovieClip *clip, MovieClipUser *u if (postprocess_flag) { int disable_red = postprocess_flag & MOVIECLIP_DISABLE_RED, disable_green = postprocess_flag & MOVIECLIP_DISABLE_GREEN, - disable_blue = postprocess_flag & MOVIECLIP_DISABLE_BLUE, - grayscale = postprocess_flag & MOVIECLIP_PREVIEW_GRAYSCALE; + disable_blue = postprocess_flag & MOVIECLIP_DISABLE_BLUE, + grayscale = postprocess_flag & MOVIECLIP_PREVIEW_GRAYSCALE; if (!postproc_ibuf) postproc_ibuf = IMB_dupImBuf(ibuf); @@ -801,8 +801,8 @@ static ImBuf *get_stable_cached_frame(MovieClip *clip, MovieClipUser *user, int /* check for stabilization parameters */ if (tscale != cache->stabilized.scale || - tangle != cache->stabilized.angle || - !equals_v2v2(tloc, cache->stabilized.loc)) + tangle != cache->stabilized.angle || + !equals_v2v2(tloc, cache->stabilized.loc)) { return NULL; } @@ -1049,17 +1049,17 @@ void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClip BKE_movieclip_get_size(clip, user, &width, &height); undist_marker.pos[0] *= width; - undist_marker.pos[1] *= height*aspy; + undist_marker.pos[1] *= height * aspy; BKE_tracking_invert_intrinsics(&clip->tracking, undist_marker.pos, undist_marker.pos); undist_marker.pos[0] /= width; - undist_marker.pos[1] /= height*aspy; + undist_marker.pos[1] /= height * aspy; } /* NOTE: margin should be kept in sync with value from ui_draw_but_TRACKPREVIEW */ tmpibuf = BKE_tracking_get_pattern_imbuf(ibuf, track, &undist_marker, 3 /* margin */, - 1 /* anchor */, scopes->track_pos, NULL); + 1 /* anchor */, scopes->track_pos, NULL); if (tmpibuf->rect_float) IMB_rect_from_float(tmpibuf); @@ -1073,11 +1073,11 @@ void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClip IMB_freeImBuf(ibuf); } - if ((track->flag & TRACK_LOCKED)==0) { + if ((track->flag & TRACK_LOCKED) == 0) { scopes->marker = marker; scopes->track = track; - scopes->slide_scale[0] = track->pat_max[0]-track->pat_min[0]; - scopes->slide_scale[1] = track->pat_max[1]-track->pat_min[1]; + scopes->slide_scale[0] = track->pat_max[0] - track->pat_min[0]; + scopes->slide_scale[1] = track->pat_max[1] - track->pat_min[1]; } } } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 1057b027d1b..bf279040760 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -115,26 +115,26 @@ #include "GPU_material.h" /* Local function protos */ -static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul); +static void solve_parenting(Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul); -float originmat[3][3]; /* after BKE_object_where_is_calc(), can be used in other functions (bad!) */ +float originmat[3][3]; /* after BKE_object_where_is_calc(), can be used in other functions (bad!) */ void BKE_object_workob_clear(Object *workob) { memset(workob, 0, sizeof(Object)); - workob->size[0]= workob->size[1]= workob->size[2]= 1.0f; - workob->dscale[0]= workob->dscale[1]= workob->dscale[2]= 1.0f; - workob->rotmode= ROT_MODE_EUL; + workob->size[0] = workob->size[1] = workob->size[2] = 1.0f; + workob->dscale[0] = workob->dscale[1] = workob->dscale[2] = 1.0f; + workob->rotmode = ROT_MODE_EUL; } void BKE_object_update_base_layer(struct Scene *scene, Object *ob) { - Base *base= scene->base.first; + Base *base = scene->base.first; while (base) { - if (base->object == ob) base->lay= ob->lay; - base= base->next; + if (base->object == ob) base->lay = ob->lay; + base = base->next; } } @@ -153,7 +153,7 @@ void BKE_object_free_softbody(Object *ob) { if (ob->soft) { sbFree(ob->soft); - ob->soft= NULL; + ob->soft = NULL; } } @@ -161,7 +161,7 @@ void BKE_object_free_bulletsoftbody(Object *ob) { if (ob->bsoft) { bsbFree(ob->bsoft); - ob->bsoft= NULL; + ob->bsoft = NULL; } } @@ -189,9 +189,9 @@ int BKE_object_support_modifier_type_check(Object *ob, int modifier_type) mti = modifierType_getInfo(modifier_type); if (!((mti->flags & eModifierTypeFlag_AcceptsCVs) || - (ob->type==OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh)))) + (ob->type == OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh)))) { - return FALSE; + return FALSE; } return TRUE; @@ -208,7 +208,7 @@ void BKE_object_link_modifiers(struct Object *ob, struct Object *from) return; } - for (md=from->modifiers.first; md; md=md->next) { + for (md = from->modifiers.first; md; md = md->next) { ModifierData *nmd = NULL; if (ELEM4(md->type, eModifierType_Hook, eModifierType_Softbody, eModifierType_ParticleInstance, eModifierType_Collision)) continue; @@ -234,12 +234,12 @@ void BKE_object_free_display(Object *ob) if (ob->derivedDeform) { ob->derivedDeform->needsFree = 1; ob->derivedDeform->release(ob->derivedDeform); - ob->derivedDeform= NULL; + ob->derivedDeform = NULL; } if (ob->derivedFinal) { ob->derivedFinal->needsFree = 1; ob->derivedFinal->release(ob->derivedFinal); - ob->derivedFinal= NULL; + ob->derivedFinal = NULL; } freedisplist(&ob->disp); @@ -260,12 +260,12 @@ void free_sculptsession(Object *ob) { if (ob && ob->sculpt) { SculptSession *ss = ob->sculpt; - DerivedMesh *dm= ob->derivedFinal; + DerivedMesh *dm = ob->derivedFinal; if (ss->pbvh) BLI_pbvh_free(ss->pbvh); if (dm && dm->getPBVH) - dm->getPBVH(NULL, dm); /* signal to clear */ + dm->getPBVH(NULL, dm); /* signal to clear */ if (ss->texcache) MEM_freeN(ss->texcache); @@ -296,25 +296,25 @@ void BKE_object_free(Object *ob) /* disconnect specific data */ if (ob->data) { - ID *id= ob->data; + ID *id = ob->data; id->us--; - if (id->us==0) { - if (ob->type==OB_MESH) BKE_mesh_unlink(ob->data); - else if (ob->type==OB_CURVE) BKE_curve_unlink(ob->data); - else if (ob->type==OB_MBALL) BKE_metaball_unlink(ob->data); + if (id->us == 0) { + if (ob->type == OB_MESH) BKE_mesh_unlink(ob->data); + else if (ob->type == OB_CURVE) BKE_curve_unlink(ob->data); + else if (ob->type == OB_MBALL) BKE_metaball_unlink(ob->data); } - ob->data= NULL; + ob->data = NULL; } - for (a=0; a<ob->totcol; a++) { + for (a = 0; a < ob->totcol; a++) { if (ob->mat[a]) ob->mat[a]->id.us--; } if (ob->mat) MEM_freeN(ob->mat); if (ob->matbits) MEM_freeN(ob->matbits); - ob->mat= NULL; - ob->matbits= NULL; + ob->mat = NULL; + ob->matbits = NULL; if (ob->bb) MEM_freeN(ob->bb); - ob->bb= NULL; + ob->bb = NULL; if (ob->adt) BKE_free_animdata((ID *)ob); if (ob->poselib) ob->poselib->id.us--; if (ob->gpd) ((ID *)ob->gpd)->us--; @@ -348,15 +348,15 @@ static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Objec { Object *unlinkOb = userData; - if (*obpoin==unlinkOb) { + if (*obpoin == unlinkOb) { *obpoin = NULL; - ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; // XXX: should this just be OB_RECALC_DATA? + ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; // XXX: should this just be OB_RECALC_DATA? } } void BKE_object_unlink(Object *ob) { - Main *bmain= G.main; + Main *bmain = G.main; Object *obt; Material *mat; World *wrld; @@ -378,55 +378,55 @@ void BKE_object_unlink(Object *ob) /* check all objects: parents en bevels and fields, also from libraries */ // FIXME: need to check all animation blocks (drivers) - obt= bmain->object.first; + obt = bmain->object.first; while (obt) { - if (obt->proxy==ob) - obt->proxy= NULL; - if (obt->proxy_from==ob) { - obt->proxy_from= NULL; + if (obt->proxy == ob) + obt->proxy = NULL; + if (obt->proxy_from == ob) { + obt->proxy_from = NULL; obt->recalc |= OB_RECALC_OB; } - if (obt->proxy_group==ob) - obt->proxy_group= NULL; + if (obt->proxy_group == ob) + obt->proxy_group = NULL; - if (obt->parent==ob) { - obt->parent= NULL; - obt->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + if (obt->parent == ob) { + obt->parent = NULL; + obt->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; } modifiers_foreachObjectLink(obt, unlink_object__unlinkModifierLinks, ob); if (ELEM(obt->type, OB_CURVE, OB_FONT)) { - cu= obt->data; + cu = obt->data; - if (cu->bevobj==ob) { - cu->bevobj= NULL; - obt->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + if (cu->bevobj == ob) { + cu->bevobj = NULL; + obt->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; } - if (cu->taperobj==ob) { - cu->taperobj= NULL; - obt->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + if (cu->taperobj == ob) { + cu->taperobj = NULL; + obt->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; } - if (cu->textoncurve==ob) { - cu->textoncurve= NULL; - obt->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + if (cu->textoncurve == ob) { + cu->textoncurve = NULL; + obt->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; } } - else if (obt->type==OB_ARMATURE && obt->pose) { + else if (obt->type == OB_ARMATURE && obt->pose) { bPoseChannel *pchan; - for (pchan= obt->pose->chanbase.first; pchan; pchan= pchan->next) { - for (con = pchan->constraints.first; con; con=con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (pchan = obt->pose->chanbase.first; pchan; pchan = pchan->next) { + for (con = pchan->constraints.first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; if (cti && cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) { + for (ct = targets.first; ct; ct = ct->next) { if (ct->tar == ob) { ct->tar = NULL; - ct->subtarget[0]= '\0'; + ct->subtarget[0] = '\0'; obt->recalc |= OB_RECALC_DATA; } } @@ -435,29 +435,29 @@ void BKE_object_unlink(Object *ob) cti->flush_constraint_targets(con, &targets, 0); } } - if (pchan->custom==ob) - pchan->custom= NULL; + if (pchan->custom == ob) + pchan->custom = NULL; } } else if (ELEM(OB_MBALL, ob->type, obt->type)) { - if (BKE_metaball_is_basis_for (obt, ob)) - obt->recalc|= OB_RECALC_DATA; + if (BKE_metaball_is_basis_for(obt, ob)) + obt->recalc |= OB_RECALC_DATA; } sca_remove_ob_poin(obt, ob); - for (con = obt->constraints.first; con; con=con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (con = obt->constraints.first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; if (cti && cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) { + for (ct = targets.first; ct; ct = ct->next) { if (ct->tar == ob) { ct->tar = NULL; - ct->subtarget[0]= '\0'; + ct->subtarget[0] = '\0'; obt->recalc |= OB_RECALC_DATA; } } @@ -473,73 +473,73 @@ void BKE_object_unlink(Object *ob) obt->recalc |= OB_RECALC_DATA; /* cloth */ - for (md=obt->modifiers.first; md; md=md->next) + for (md = obt->modifiers.first; md; md = md->next) if (md->type == eModifierType_Cloth) obt->recalc |= OB_RECALC_DATA; } /* strips */ #if 0 // XXX old animation system - for (strip= obt->nlastrips.first; strip; strip= strip->next) { - if (strip->object==ob) - strip->object= NULL; + for (strip = obt->nlastrips.first; strip; strip = strip->next) { + if (strip->object == ob) + strip->object = NULL; if (strip->modifiers.first) { bActionModifier *amod; - for (amod= strip->modifiers.first; amod; amod= amod->next) - if (amod->ob==ob) - amod->ob= NULL; + for (amod = strip->modifiers.first; amod; amod = amod->next) + if (amod->ob == ob) + amod->ob = NULL; } } #endif // XXX old animation system /* particle systems */ if (obt->particlesystem.first) { - ParticleSystem *tpsys= obt->particlesystem.first; - for (; tpsys; tpsys=tpsys->next) { + ParticleSystem *tpsys = obt->particlesystem.first; + for (; tpsys; tpsys = tpsys->next) { BoidState *state = NULL; BoidRule *rule = NULL; ParticleTarget *pt = tpsys->targets.first; - for (; pt; pt=pt->next) { - if (pt->ob==ob) { + for (; pt; pt = pt->next) { + if (pt->ob == ob) { pt->ob = NULL; obt->recalc |= OB_RECALC_DATA; break; } } - if (tpsys->target_ob==ob) { - tpsys->target_ob= NULL; + if (tpsys->target_ob == ob) { + tpsys->target_ob = NULL; obt->recalc |= OB_RECALC_DATA; } - if (tpsys->part->dup_ob==ob) - tpsys->part->dup_ob= NULL; + if (tpsys->part->dup_ob == ob) + tpsys->part->dup_ob = NULL; - if (tpsys->part->phystype==PART_PHYS_BOIDS) { + if (tpsys->part->phystype == PART_PHYS_BOIDS) { ParticleData *pa; BoidParticle *bpa; int p; - for (p=0, pa=tpsys->particles; p<tpsys->totpart; p++, pa++) { + for (p = 0, pa = tpsys->particles; p < tpsys->totpart; p++, pa++) { bpa = pa->boid; if (bpa->ground == ob) bpa->ground = NULL; } } if (tpsys->part->boids) { - for (state = tpsys->part->boids->states.first; state; state=state->next) { - for (rule = state->rules.first; rule; rule=rule->next) { - if (rule->type==eBoidRuleType_Avoid) { - BoidRuleGoalAvoid *gabr = (BoidRuleGoalAvoid*)rule; - if (gabr->ob==ob) - gabr->ob= NULL; + for (state = tpsys->part->boids->states.first; state; state = state->next) { + for (rule = state->rules.first; rule; rule = rule->next) { + if (rule->type == eBoidRuleType_Avoid) { + BoidRuleGoalAvoid *gabr = (BoidRuleGoalAvoid *)rule; + if (gabr->ob == ob) + gabr->ob = NULL; } - else if (rule->type==eBoidRuleType_FollowLeader) { - BoidRuleFollowLeader *flbr = (BoidRuleFollowLeader*)rule; - if (flbr->ob==ob) - flbr->ob= NULL; + else if (rule->type == eBoidRuleType_FollowLeader) { + BoidRuleFollowLeader *flbr = (BoidRuleFollowLeader *)rule; + if (flbr->ob == ob) + flbr->ob = NULL; } } } @@ -549,64 +549,64 @@ void BKE_object_unlink(Object *ob) obt->recalc |= OB_RECALC_DATA; } - obt= obt->id.next; + obt = obt->id.next; } /* materials */ - mat= bmain->mat.first; + mat = bmain->mat.first; while (mat) { - for (a=0; a<MAX_MTEX; a++) { - if (mat->mtex[a] && ob==mat->mtex[a]->object) { + for (a = 0; a < MAX_MTEX; a++) { + if (mat->mtex[a] && ob == mat->mtex[a]->object) { /* actually, test for lib here... to do */ - mat->mtex[a]->object= NULL; + mat->mtex[a]->object = NULL; } } - mat= mat->id.next; + mat = mat->id.next; } /* textures */ - for (tex= bmain->tex.first; tex; tex= tex->id.next) { - if (tex->env && (ob==tex->env->object)) tex->env->object= NULL; - if (tex->pd && (ob==tex->pd->object)) tex->pd->object= NULL; - if (tex->vd && (ob==tex->vd->object)) tex->vd->object= NULL; + for (tex = bmain->tex.first; tex; tex = tex->id.next) { + if (tex->env && (ob == tex->env->object)) tex->env->object = NULL; + if (tex->pd && (ob == tex->pd->object)) tex->pd->object = NULL; + if (tex->vd && (ob == tex->vd->object)) tex->vd->object = NULL; } /* worlds */ - wrld= bmain->world.first; + wrld = bmain->world.first; while (wrld) { - if (wrld->id.lib==NULL) { - for (a=0; a<MAX_MTEX; a++) { - if (wrld->mtex[a] && ob==wrld->mtex[a]->object) - wrld->mtex[a]->object= NULL; + if (wrld->id.lib == NULL) { + for (a = 0; a < MAX_MTEX; a++) { + if (wrld->mtex[a] && ob == wrld->mtex[a]->object) + wrld->mtex[a]->object = NULL; } } - wrld= wrld->id.next; + wrld = wrld->id.next; } /* scenes */ - sce= bmain->scene.first; + sce = bmain->scene.first; while (sce) { - if (sce->id.lib==NULL) { - if (sce->camera==ob) sce->camera= NULL; - if (sce->toolsettings->skgen_template==ob) sce->toolsettings->skgen_template = NULL; - if (sce->toolsettings->particle.object==ob) sce->toolsettings->particle.object= NULL; + if (sce->id.lib == NULL) { + if (sce->camera == ob) sce->camera = NULL; + if (sce->toolsettings->skgen_template == ob) sce->toolsettings->skgen_template = NULL; + if (sce->toolsettings->particle.object == ob) sce->toolsettings->particle.object = NULL; #ifdef DURIAN_CAMERA_SWITCH { TimeMarker *m; - for (m= sce->markers.first; m; m= m->next) { - if (m->camera==ob) - m->camera= NULL; + for (m = sce->markers.first; m; m = m->next) { + if (m->camera == ob) + m->camera = NULL; } } #endif if (sce->ed) { Sequence *seq; - SEQ_BEGIN (sce->ed, seq) + SEQ_BEGIN(sce->ed, seq) { if (seq->scene_camera == ob) { seq->scene_camera = NULL; @@ -616,19 +616,19 @@ void BKE_object_unlink(Object *ob) } } - sce= sce->id.next; + sce = sce->id.next; } /* screens */ - sc= bmain->screen.first; + sc = bmain->screen.first; while (sc) { - ScrArea *sa= sc->areabase.first; + ScrArea *sa = sc->areabase.first; while (sa) { SpaceLink *sl; - for (sl= sa->spacedata.first; sl; sl= sl->next) { - if (sl->spacetype==SPACE_VIEW3D) { - View3D *v3d= (View3D*) sl; + for (sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *) sl; /* found doesn't need to be set here */ if (v3d->ob_centre == ob) { @@ -640,74 +640,74 @@ void BKE_object_unlink(Object *ob) v3d->localvd->ob_centre_bone[0] = '\0'; } - found= 0; - if (v3d->camera==ob) { - v3d->camera= NULL; - found= 1; + found = 0; + if (v3d->camera == ob) { + v3d->camera = NULL; + found = 1; } - if (v3d->localvd && v3d->localvd->camera==ob ) { - v3d->localvd->camera= NULL; + if (v3d->localvd && v3d->localvd->camera == ob) { + v3d->localvd->camera = NULL; found += 2; } if (found) { if (sa->spacetype == SPACE_VIEW3D) { - for (ar= sa->regionbase.first; ar; ar= ar->next) { - if (ar->regiontype==RGN_TYPE_WINDOW) { - rv3d= (RegionView3D *)ar->regiondata; + for (ar = sa->regionbase.first; ar; ar = ar->next) { + if (ar->regiontype == RGN_TYPE_WINDOW) { + rv3d = (RegionView3D *)ar->regiondata; if (found == 1 || found == 3) { if (rv3d->persp == RV3D_CAMOB) - rv3d->persp= RV3D_PERSP; + rv3d->persp = RV3D_PERSP; } if (found == 2 || found == 3) { if (rv3d->localvd && rv3d->localvd->persp == RV3D_CAMOB) - rv3d->localvd->persp= RV3D_PERSP; + rv3d->localvd->persp = RV3D_PERSP; } } } } } } - else if (sl->spacetype==SPACE_OUTLINER) { - SpaceOops *so= (SpaceOops *)sl; + else if (sl->spacetype == SPACE_OUTLINER) { + SpaceOops *so = (SpaceOops *)sl; if (so->treestore) { - TreeStoreElem *tselem= so->treestore->data; + TreeStoreElem *tselem = so->treestore->data; int a; - for (a=0; a<so->treestore->usedelem; a++, tselem++) { - if (tselem->id==(ID *)ob) tselem->id= NULL; + for (a = 0; a < so->treestore->usedelem; a++, tselem++) { + if (tselem->id == (ID *)ob) tselem->id = NULL; } } } - else if (sl->spacetype==SPACE_BUTS) { - SpaceButs *sbuts= (SpaceButs *)sl; + else if (sl->spacetype == SPACE_BUTS) { + SpaceButs *sbuts = (SpaceButs *)sl; - if (sbuts->pinid==(ID *)ob) { - sbuts->flag&= ~SB_PIN_CONTEXT; - sbuts->pinid= NULL; + if (sbuts->pinid == (ID *)ob) { + sbuts->flag &= ~SB_PIN_CONTEXT; + sbuts->pinid = NULL; } } } - sa= sa->next; + sa = sa->next; } - sc= sc->id.next; + sc = sc->id.next; } /* groups */ - group= bmain->group.first; + group = bmain->group.first; while (group) { rem_from_group(group, ob, NULL, NULL); - group= group->id.next; + group = group->id.next; } /* cameras */ - camera= bmain->camera.first; + camera = bmain->camera.first; while (camera) { - if (camera->dof_ob==ob) { + if (camera->dof_ob == ob) { camera->dof_ob = NULL; } - camera= camera->id.next; + camera = camera->id.next; } } @@ -715,12 +715,12 @@ int BKE_object_exists_check(Object *obtest) { Object *ob; - if (obtest==NULL) return 0; + if (obtest == NULL) return 0; - ob= G.main->object.first; + ob = G.main->object.first; while (ob) { - if (ob==obtest) return 1; - ob= ob->id.next; + if (ob == obtest) return 1; + ob = ob->id.next; } return 0; } @@ -730,40 +730,40 @@ int BKE_object_exists_check(Object *obtest) void *BKE_object_obdata_add_from_type(int type) { switch (type) { - case OB_MESH: return BKE_mesh_add("Mesh"); - case OB_CURVE: return BKE_curve_add("Curve", OB_CURVE); - case OB_SURF: return BKE_curve_add("Surf", OB_SURF); - case OB_FONT: return BKE_curve_add("Text", OB_FONT); - case OB_MBALL: return BKE_metaball_add("Meta"); - case OB_CAMERA: return BKE_camera_add("Camera"); - case OB_LAMP: return BKE_lamp_add("Lamp"); - case OB_LATTICE: return BKE_lattice_add("Lattice"); - case OB_ARMATURE: return BKE_armature_add("Armature"); - case OB_SPEAKER: return BKE_speaker_add("Speaker"); - case OB_EMPTY: return NULL; - default: - printf("BKE_object_obdata_add_from_type: Internal error, bad type: %d\n", type); - return NULL; + case OB_MESH: return BKE_mesh_add("Mesh"); + case OB_CURVE: return BKE_curve_add("Curve", OB_CURVE); + case OB_SURF: return BKE_curve_add("Surf", OB_SURF); + case OB_FONT: return BKE_curve_add("Text", OB_FONT); + case OB_MBALL: return BKE_metaball_add("Meta"); + case OB_CAMERA: return BKE_camera_add("Camera"); + case OB_LAMP: return BKE_lamp_add("Lamp"); + case OB_LATTICE: return BKE_lattice_add("Lattice"); + case OB_ARMATURE: return BKE_armature_add("Armature"); + case OB_SPEAKER: return BKE_speaker_add("Speaker"); + case OB_EMPTY: return NULL; + default: + printf("BKE_object_obdata_add_from_type: Internal error, bad type: %d\n", type); + return NULL; } } static const char *get_obdata_defname(int type) { switch (type) { - case OB_MESH: return "Mesh"; - case OB_CURVE: return "Curve"; - case OB_SURF: return "Surf"; - case OB_FONT: return "Text"; - case OB_MBALL: return "Mball"; - case OB_CAMERA: return "Camera"; - case OB_LAMP: return "Lamp"; - case OB_LATTICE: return "Lattice"; - case OB_ARMATURE: return "Armature"; - case OB_SPEAKER: return "Speaker"; - case OB_EMPTY: return "Empty"; - default: - printf("get_obdata_defname: Internal error, bad type: %d\n", type); - return "Empty"; + case OB_MESH: return "Mesh"; + case OB_CURVE: return "Curve"; + case OB_SURF: return "Surf"; + case OB_FONT: return "Text"; + case OB_MBALL: return "Mball"; + case OB_CAMERA: return "Camera"; + case OB_LAMP: return "Lamp"; + case OB_LATTICE: return "Lattice"; + case OB_ARMATURE: return "Armature"; + case OB_SPEAKER: return "Speaker"; + case OB_EMPTY: return "Empty"; + default: + printf("get_obdata_defname: Internal error, bad type: %d\n", type); + return "Empty"; } } @@ -772,24 +772,24 @@ Object *BKE_object_add_only_object(int type, const char *name) { Object *ob; - if(!name) + if (!name) name = get_obdata_defname(type); - ob= BKE_libblock_alloc(&G.main->object, ID_OB, name); + ob = BKE_libblock_alloc(&G.main->object, ID_OB, name); /* default object vars */ - ob->type= type; + ob->type = type; - ob->col[0]= ob->col[1]= ob->col[2]= 1.0; - ob->col[3]= 1.0; + ob->col[0] = ob->col[1] = ob->col[2] = 1.0; + ob->col[3] = 1.0; - ob->size[0]= ob->size[1]= ob->size[2]= 1.0; - ob->dscale[0]= ob->dscale[1]= ob->dscale[2]= 1.0; + ob->size[0] = ob->size[1] = ob->size[2] = 1.0; + ob->dscale[0] = ob->dscale[1] = ob->dscale[2] = 1.0; /* objects should default to having Euler XYZ rotations, * but rotations default to quaternions */ - ob->rotmode= ROT_MODE_EUL; + ob->rotmode = ROT_MODE_EUL; unit_axis_angle(ob->rotAxis, &ob->rotAngle); unit_axis_angle(ob->drotAxis, &ob->drotAngle); @@ -803,35 +803,35 @@ Object *BKE_object_add_only_object(int type, const char *name) unit_m4(ob->constinv); unit_m4(ob->parentinv); unit_m4(ob->obmat); - ob->dt= OB_TEXTURE; - ob->empty_drawtype= OB_PLAINAXES; - ob->empty_drawsize= 1.0; + ob->dt = OB_TEXTURE; + ob->empty_drawtype = OB_PLAINAXES; + ob->empty_drawsize = 1.0; - if (type==OB_CAMERA || type==OB_LAMP || type==OB_SPEAKER) { - ob->trackflag= OB_NEGZ; - ob->upflag= OB_POSY; + if (type == OB_CAMERA || type == OB_LAMP || type == OB_SPEAKER) { + ob->trackflag = OB_NEGZ; + ob->upflag = OB_POSY; } else { - ob->trackflag= OB_POSY; - ob->upflag= OB_POSZ; + ob->trackflag = OB_POSY; + ob->upflag = OB_POSZ; } - ob->dupon= 1; ob->dupoff= 0; - ob->dupsta= 1; ob->dupend= 100; + ob->dupon = 1; ob->dupoff = 0; + ob->dupsta = 1; ob->dupend = 100; ob->dupfacesca = 1.0; /* Game engine defaults*/ - ob->mass= ob->inertia= 1.0f; - ob->formfactor= 0.4f; - ob->damping= 0.04f; - ob->rdamping= 0.1f; + ob->mass = ob->inertia = 1.0f; + ob->formfactor = 0.4f; + ob->damping = 0.04f; + ob->rdamping = 0.1f; ob->anisotropicFriction[0] = 1.0f; ob->anisotropicFriction[1] = 1.0f; ob->anisotropicFriction[2] = 1.0f; - ob->gameflag= OB_PROP|OB_COLLISION; + ob->gameflag = OB_PROP | OB_COLLISION; ob->margin = 0.0; - ob->init_state=1; - ob->state=1; + ob->init_state = 1; + ob->state = 1; /* ob->pad3 == Contact Processing Threshold */ ob->m_contactProcessingThreshold = 1.0f; ob->obstacleRad = 1.0f; @@ -858,14 +858,14 @@ Object *BKE_object_add(struct Scene *scene, int type) BLI_strncpy(name, get_obdata_defname(type), sizeof(name)); ob = BKE_object_add_only_object(type, name); - ob->data= BKE_object_obdata_add_from_type(type); + ob->data = BKE_object_obdata_add_from_type(type); - ob->lay= scene->lay; + ob->lay = scene->lay; - base= BKE_scene_base_add(scene, ob); + base = BKE_scene_base_add(scene, ob); BKE_scene_base_deselect_all(scene); BKE_scene_base_select(scene, base); - ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; return ob; } @@ -874,19 +874,19 @@ SoftBody *copy_softbody(SoftBody *sb) { SoftBody *sbn; - if (sb==NULL) return(NULL); + if (sb == NULL) return(NULL); - sbn= MEM_dupallocN(sb); - sbn->totspring= sbn->totpoint= 0; - sbn->bpoint= NULL; - sbn->bspring= NULL; + sbn = MEM_dupallocN(sb); + sbn->totspring = sbn->totpoint = 0; + sbn->bpoint = NULL; + sbn->bspring = NULL; - sbn->keys= NULL; - sbn->totkey= sbn->totpointkey= 0; + sbn->keys = NULL; + sbn->totkey = sbn->totpointkey = 0; - sbn->scratch= NULL; + sbn->scratch = NULL; - sbn->pointcache= BKE_ptcache_copy_list(&sbn->ptcaches, &sb->ptcaches); + sbn->pointcache = BKE_ptcache_copy_list(&sbn->ptcaches, &sb->ptcaches); if (sb->effector_weights) sbn->effector_weights = MEM_dupallocN(sb->effector_weights); @@ -911,12 +911,12 @@ static ParticleSystem *copy_particlesystem(ParticleSystem *psys) ParticleData *pa; int p; - psysn= MEM_dupallocN(psys); - psysn->particles= MEM_dupallocN(psys->particles); - psysn->child= MEM_dupallocN(psys->child); + psysn = MEM_dupallocN(psys); + psysn->particles = MEM_dupallocN(psys->particles); + psysn->child = MEM_dupallocN(psys->child); if (psys->part->type == PART_HAIR) { - for (p=0, pa=psysn->particles; p<psysn->totpart; p++, pa++) + for (p = 0, pa = psysn->particles; p < psysn->totpart; p++, pa++) pa->hair = MEM_dupallocN(pa->hair); } @@ -930,7 +930,7 @@ static ParticleSystem *copy_particlesystem(ParticleSystem *psys) if (boid) boid = MEM_dupallocN(boid); - for (p=0, pa=psysn->particles; p<psysn->totpart; p++, pa++) { + for (p = 0, pa = psysn->particles; p < psysn->totpart; p++, pa++) { if (boid) pa->boid = boid++; if (key) { @@ -942,29 +942,29 @@ static ParticleSystem *copy_particlesystem(ParticleSystem *psys) if (psys->clmd) { psysn->clmd = (ClothModifierData *)modifier_new(eModifierType_Cloth); - modifier_copyData((ModifierData*)psys->clmd, (ModifierData*)psysn->clmd); + modifier_copyData((ModifierData *)psys->clmd, (ModifierData *)psysn->clmd); psys->hair_in_dm = psys->hair_out_dm = NULL; } BLI_duplicatelist(&psysn->targets, &psys->targets); - psysn->pathcache= NULL; - psysn->childcache= NULL; - psysn->edit= NULL; - psysn->frand= NULL; - psysn->pdd= NULL; - psysn->effectors= NULL; + psysn->pathcache = NULL; + psysn->childcache = NULL; + psysn->edit = NULL; + psysn->frand = NULL; + psysn->pdd = NULL; + psysn->effectors = NULL; psysn->pathcachebufs.first = psysn->pathcachebufs.last = NULL; psysn->childcachebufs.first = psysn->childcachebufs.last = NULL; psysn->renderdata = NULL; - psysn->pointcache= BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches); + psysn->pointcache = BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches); /* XXX - from reading existing code this seems correct but intended usage of * pointcache should /w cloth should be added in 'ParticleSystem' - campbell */ if (psysn->clmd) { - psysn->clmd->point_cache= psysn->pointcache; + psysn->clmd->point_cache = psysn->pointcache; } id_us_plus((ID *)psysn->part); @@ -982,34 +982,34 @@ void BKE_object_copy_particlesystems(Object *obn, Object *ob) return; } - obn->particlesystem.first= obn->particlesystem.last= NULL; - for (psys=ob->particlesystem.first; psys; psys=psys->next) { - npsys= copy_particlesystem(psys); + obn->particlesystem.first = obn->particlesystem.last = NULL; + for (psys = ob->particlesystem.first; psys; psys = psys->next) { + npsys = copy_particlesystem(psys); BLI_addtail(&obn->particlesystem, npsys); /* need to update particle modifiers too */ - for (md=obn->modifiers.first; md; md=md->next) { - if (md->type==eModifierType_ParticleSystem) { - ParticleSystemModifierData *psmd= (ParticleSystemModifierData*)md; - if (psmd->psys==psys) - psmd->psys= npsys; + for (md = obn->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_ParticleSystem) { + ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md; + if (psmd->psys == psys) + psmd->psys = npsys; } - else if (md->type==eModifierType_DynamicPaint) { - DynamicPaintModifierData *pmd= (DynamicPaintModifierData*)md; + else if (md->type == eModifierType_DynamicPaint) { + DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md; if (pmd->brush) { - if (pmd->brush->psys==psys) { - pmd->brush->psys= npsys; + if (pmd->brush->psys == psys) { + pmd->brush->psys = npsys; } } } - else if (md->type==eModifierType_Smoke) { - SmokeModifierData *smd = (SmokeModifierData*) md; + else if (md->type == eModifierType_Smoke) { + SmokeModifierData *smd = (SmokeModifierData *) md; - if (smd->type==MOD_SMOKE_TYPE_FLOW) { + if (smd->type == MOD_SMOKE_TYPE_FLOW) { if (smd->flow) { if (smd->flow->psys == psys) - smd->flow->psys= npsys; + smd->flow->psys = npsys; } } } @@ -1020,7 +1020,7 @@ void BKE_object_copy_particlesystems(Object *obn, Object *ob) void BKE_object_copy_softbody(Object *obn, Object *ob) { if (ob->soft) - obn->soft= copy_softbody(ob->soft); + obn->soft = copy_softbody(ob->soft); } static void copy_object_pose(Object *obn, Object *ob) @@ -1028,23 +1028,23 @@ static void copy_object_pose(Object *obn, Object *ob) bPoseChannel *chan; /* note: need to clear obn->pose pointer first, so that BKE_pose_copy_data works (otherwise there's a crash) */ - obn->pose= NULL; - BKE_pose_copy_data(&obn->pose, ob->pose, 1); /* 1 = copy constraints */ + obn->pose = NULL; + BKE_pose_copy_data(&obn->pose, ob->pose, 1); /* 1 = copy constraints */ - for (chan = obn->pose->chanbase.first; chan; chan=chan->next) { + for (chan = obn->pose->chanbase.first; chan; chan = chan->next) { bConstraint *con; - chan->flag &= ~(POSE_LOC|POSE_ROT|POSE_SIZE); + chan->flag &= ~(POSE_LOC | POSE_ROT | POSE_SIZE); - for (con= chan->constraints.first; con; con= con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (con = chan->constraints.first; con; con = con->next) { + bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; if (cti && cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) { + for (ct = targets.first; ct; ct = ct->next) { if (ct->tar == ob) ct->tar = obn; } @@ -1058,11 +1058,11 @@ static void copy_object_pose(Object *obn, Object *ob) static int object_pose_context(Object *ob) { - if ( (ob) && - (ob->type == OB_ARMATURE) && - (ob->pose) && - (ob->mode & OB_MODE_POSE) - ) { + if ( (ob) && + (ob->type == OB_ARMATURE) && + (ob->pose) && + (ob->mode & OB_MODE_POSE)) + { return 1; } else { @@ -1072,13 +1072,13 @@ static int object_pose_context(Object *ob) Object *BKE_object_pose_armature_get(Object *ob) { - if (ob==NULL) + if (ob == NULL) return NULL; if (object_pose_context(ob)) return ob; - ob= modifiers_isDeformedByArmature(ob); + ob = modifiers_isDeformedByArmature(ob); if (object_pose_context(ob)) return ob; @@ -1092,8 +1092,8 @@ static void copy_object_transform(Object *ob_tar, Object *ob_src) copy_v3_v3(ob_tar->rot, ob_src->rot); copy_v3_v3(ob_tar->quat, ob_src->quat); copy_v3_v3(ob_tar->rotAxis, ob_src->rotAxis); - ob_tar->rotAngle= ob_src->rotAngle; - ob_tar->rotmode= ob_src->rotmode; + ob_tar->rotAngle = ob_src->rotAngle; + ob_tar->rotmode = ob_src->rotmode; copy_v3_v3(ob_tar->size, ob_src->size); } @@ -1103,20 +1103,20 @@ Object *BKE_object_copy(Object *ob) ModifierData *md; int a; - obn= BKE_libblock_copy(&ob->id); + obn = BKE_libblock_copy(&ob->id); if (ob->totcol) { - obn->mat= MEM_dupallocN(ob->mat); - obn->matbits= MEM_dupallocN(ob->matbits); - obn->totcol= ob->totcol; + obn->mat = MEM_dupallocN(ob->mat); + obn->matbits = MEM_dupallocN(ob->matbits); + obn->totcol = ob->totcol; } - if (ob->bb) obn->bb= MEM_dupallocN(ob->bb); + if (ob->bb) obn->bb = MEM_dupallocN(ob->bb); obn->flag &= ~OB_FROMGROUP; - obn->modifiers.first = obn->modifiers.last= NULL; + obn->modifiers.first = obn->modifiers.last = NULL; - for (md=ob->modifiers.first; md; md=md->next) { + for (md = ob->modifiers.first; md; md = md->next) { ModifierData *nmd = modifier_new(md->type); BLI_strncpy(nmd->name, md->name, sizeof(nmd->name)); modifier_copyData(md, nmd); @@ -1133,7 +1133,7 @@ Object *BKE_object_copy(Object *ob) if (ob->pose) { copy_object_pose(obn, ob); /* backwards compat... non-armatures can get poses in older files? */ - if (ob->type==OB_ARMATURE) + if (ob->type == OB_ARMATURE) BKE_pose_rebuild(obn, obn->data); } defgroup_copy_list(&obn->defbase, &ob->defbase); @@ -1147,18 +1147,18 @@ Object *BKE_object_copy(Object *ob) id_us_plus((ID *)obn->gpd); id_lib_extern((ID *)obn->dup_group); - for (a=0; a<obn->totcol; a++) id_us_plus((ID *)obn->mat[a]); + for (a = 0; a < obn->totcol; a++) id_us_plus((ID *)obn->mat[a]); - obn->disp.first= obn->disp.last= NULL; + obn->disp.first = obn->disp.last = NULL; if (ob->pd) { - obn->pd= MEM_dupallocN(ob->pd); + obn->pd = MEM_dupallocN(ob->pd); if (obn->pd->tex) id_us_plus(&(obn->pd->tex->id)); if (obn->pd->rng) obn->pd->rng = MEM_dupallocN(ob->pd->rng); } - obn->soft= copy_softbody(ob->soft); + obn->soft = copy_softbody(ob->soft); obn->bsoft = copy_bulletsoftbody(ob->bsoft); BKE_object_copy_particlesystems(obn, ob); @@ -1169,7 +1169,7 @@ Object *BKE_object_copy(Object *ob) obn->gpulamp.first = obn->gpulamp.last = NULL; obn->pc_ids.first = obn->pc_ids.last = NULL; - obn->mpath= NULL; + obn->mpath = NULL; return obn; } @@ -1185,35 +1185,35 @@ static void extern_local_object(Object *ob) extern_local_matarar(ob->mat, ob->totcol); - for (psys=ob->particlesystem.first; psys; psys=psys->next) + for (psys = ob->particlesystem.first; psys; psys = psys->next) id_lib_extern((ID *)psys->part); } void BKE_object_make_local(Object *ob) { - Main *bmain= G.main; + Main *bmain = G.main; Scene *sce; Base *base; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (ob->id.lib==NULL) return; + if (ob->id.lib == NULL) return; - ob->proxy= ob->proxy_from= NULL; + ob->proxy = ob->proxy_from = NULL; - if (ob->id.us==1) { + if (ob->id.us == 1) { id_clear_lib_data(bmain, &ob->id); extern_local_object(ob); } else { - for (sce= bmain->scene.first; sce && ELEM(0, is_lib, is_local); sce= sce->id.next) { + for (sce = bmain->scene.first; sce && ELEM(0, is_lib, is_local); sce = sce->id.next) { if (BKE_scene_base_find(sce, ob)) { - if (sce->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (sce->id.lib) is_lib = TRUE; + else is_local = TRUE; } } @@ -1222,27 +1222,27 @@ void BKE_object_make_local(Object *ob) extern_local_object(ob); } else if (is_local && is_lib) { - Object *ob_new= BKE_object_copy(ob); + Object *ob_new = BKE_object_copy(ob); - ob_new->id.us= 0; + ob_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, ob->id.lib, &ob_new->id); - sce= bmain->scene.first; + sce = bmain->scene.first; while (sce) { - if (sce->id.lib==NULL) { - base= sce->base.first; + if (sce->id.lib == NULL) { + base = sce->base.first; while (base) { - if (base->object==ob) { - base->object= ob_new; + if (base->object == ob) { + base->object = ob_new; ob_new->id.us++; ob->id.us--; } - base= base->next; + base = base->next; } } - sce= sce->id.next; + sce = sce->id.next; } } } @@ -1263,9 +1263,9 @@ int BKE_object_is_libdata(Object *ob) int BKE_object_obdata_is_libdata(Object *ob) { if (!ob) return 0; - if (ob->proxy && (ob->data==NULL || ((ID *)ob->data)->lib==NULL)) return 0; + if (ob->proxy && (ob->data == NULL || ((ID *)ob->data)->lib == NULL)) return 0; if (ob->id.lib) return 1; - if (ob->data==NULL) return 0; + if (ob->data == NULL) return 0; if (((ID *)ob->data)->lib) return 1; return 0; @@ -1276,11 +1276,11 @@ int BKE_object_obdata_is_libdata(Object *ob) /* when you make proxy, ensure the exposed layers are extern */ static void armature_set_id_extern(Object *ob) { - bArmature *arm= ob->data; + bArmature *arm = ob->data; bPoseChannel *pchan; - unsigned int lay= arm->layer_protected; + unsigned int lay = arm->layer_protected; - for (pchan = ob->pose->chanbase.first; pchan; pchan=pchan->next) { + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { if (!(pchan->bone->layer & lay)) id_lib_extern((ID *)pchan->custom); } @@ -1294,27 +1294,27 @@ void BKE_object_copy_proxy_drivers(Object *ob, Object *target) /* add new animdata block */ if (!ob->adt) - ob->adt= BKE_id_add_animdata(&ob->id); + ob->adt = BKE_id_add_animdata(&ob->id); /* make a copy of all the drivers (for now), then correct any links that need fixing */ free_fcurves(&ob->adt->drivers); copy_fcurves(&ob->adt->drivers, &target->adt->drivers); - for (fcu= ob->adt->drivers.first; fcu; fcu= fcu->next) { - ChannelDriver *driver= fcu->driver; + for (fcu = ob->adt->drivers.first; fcu; fcu = fcu->next) { + ChannelDriver *driver = fcu->driver; DriverVar *dvar; - for (dvar= driver->variables.first; dvar; dvar= dvar->next) { + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { /* all drivers */ DRIVER_TARGETS_LOOPER(dvar) { if (dtar->id) { if ((Object *)dtar->id == target) - dtar->id= (ID *)ob; + dtar->id = (ID *)ob; else { /* only on local objects because this causes indirect links a -> b -> c, blend to point directly to a.blend * when a.blend has a proxy thats linked into c.blend */ - if (ob->id.lib==NULL) + if (ob->id.lib == NULL) id_lib_extern((ID *)dtar->id); } } @@ -1332,16 +1332,16 @@ void BKE_object_copy_proxy_drivers(Object *ob, Object *target) void BKE_object_make_proxy(Object *ob, Object *target, Object *gob) { /* paranoia checks */ - if (ob->id.lib || target->id.lib==NULL) { + if (ob->id.lib || target->id.lib == NULL) { printf("cannot make proxy\n"); return; } - ob->proxy= target; - ob->proxy_group= gob; + ob->proxy = target; + ob->proxy_group = gob; id_lib_extern(&target->id); - ob->recalc= target->recalc= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; + ob->recalc = target->recalc = OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; /* copy transform * - gob means this proxy comes from a group, just apply the matrix @@ -1350,7 +1350,7 @@ void BKE_object_make_proxy(Object *ob, Object *target, Object *gob) * - no gob means this is being made from a linked object, * this is closer to making a copy of the object - in-place. */ if (gob) { - ob->rotmode= target->rotmode; + ob->rotmode = target->rotmode; mult_m4_m4m4(ob->obmat, gob->obmat, target->obmat); if (gob->dup_group) { /* should always be true */ float tvec[3]; @@ -1362,7 +1362,7 @@ void BKE_object_make_proxy(Object *ob, Object *target, Object *gob) } else { copy_object_transform(ob, target); - ob->parent= target->parent; /* libdata */ + ob->parent = target->parent; /* libdata */ copy_m4_m4(ob->parentinv, target->parentinv); } @@ -1373,25 +1373,25 @@ void BKE_object_make_proxy(Object *ob, Object *target, Object *gob) // FIXME: this is considered by many as a bug /* set object type and link to data */ - ob->type= target->type; - ob->data= target->data; - id_us_plus((ID *)ob->data); /* ensures lib data becomes LIB_EXTERN */ + ob->type = target->type; + ob->data = target->data; + id_us_plus((ID *)ob->data); /* ensures lib data becomes LIB_EXTERN */ /* copy material and index information */ - ob->actcol= ob->totcol= 0; + ob->actcol = ob->totcol = 0; if (ob->mat) MEM_freeN(ob->mat); if (ob->matbits) MEM_freeN(ob->matbits); ob->mat = NULL; - ob->matbits= NULL; + ob->matbits = NULL; if ((target->totcol) && (target->mat) && OB_TYPE_SUPPORT_MATERIAL(ob->type)) { int i; - ob->actcol= target->actcol; - ob->totcol= target->totcol; + ob->actcol = target->actcol; + ob->totcol = target->totcol; ob->mat = MEM_dupallocN(target->mat); ob->matbits = MEM_dupallocN(target->matbits); - for (i=0; i<target->totcol; i++) { + for (i = 0; i < target->totcol; i++) { /* don't need to run test_object_materials since we know this object is new and not used elsewhere */ id_us_plus((ID *)ob->mat[i]); } @@ -1399,9 +1399,9 @@ void BKE_object_make_proxy(Object *ob, Object *target, Object *gob) /* type conversions */ if (target->type == OB_ARMATURE) { - copy_object_pose(ob, target); /* data copy, object pointers in constraints */ - BKE_pose_rest(ob->pose); /* clear all transforms in channels */ - BKE_pose_rebuild(ob, ob->data); /* set all internal links */ + copy_object_pose(ob, target); /* data copy, object pointers in constraints */ + BKE_pose_rest(ob->pose); /* clear all transforms in channels */ + BKE_pose_rebuild(ob, ob->data); /* set all internal links */ armature_set_id_extern(ob); } @@ -1414,14 +1414,14 @@ void BKE_object_make_proxy(Object *ob, Object *target, Object *gob) if (ob->id.properties) { IDP_FreeProperty(ob->id.properties); MEM_freeN(ob->id.properties); - ob->id.properties= NULL; + ob->id.properties = NULL; } if (target->id.properties) { - ob->id.properties= IDP_CopyProperty(target->id.properties); + ob->id.properties = IDP_CopyProperty(target->id.properties); } /* copy drawtype info */ - ob->dt= target->dt; + ob->dt = target->dt; } @@ -1471,7 +1471,7 @@ void BKE_object_rot_to_mat3(Object *ob, float mat[][3]) void BKE_object_mat3_to_rot(Object *ob, float mat[][3], short use_compat) { switch (ob->rotmode) { - case ROT_MODE_QUAT: + case ROT_MODE_QUAT: { float dquat[4]; mat3_to_quat(ob->quat, mat); @@ -1480,12 +1480,12 @@ void BKE_object_mat3_to_rot(Object *ob, float mat[][3], short use_compat) mul_qt_qtqt(ob->quat, dquat, ob->quat); } break; - case ROT_MODE_AXISANGLE: - mat3_to_axis_angle(ob->rotAxis, &ob->rotAngle, mat); - sub_v3_v3(ob->rotAxis, ob->drotAxis); - ob->rotAngle -= ob->drotAngle; - break; - default: /* euler */ + case ROT_MODE_AXISANGLE: + mat3_to_axis_angle(ob->rotAxis, &ob->rotAngle, mat); + sub_v3_v3(ob->rotAxis, ob->drotAxis); + ob->rotAngle -= ob->drotAngle; + break; + default: /* euler */ { float quat[4]; float dquat[4]; @@ -1499,19 +1499,19 @@ void BKE_object_mat3_to_rot(Object *ob, float mat[][3], short use_compat) quat_to_mat3(tmat, quat); /* end drot correction */ - if (use_compat) mat3_to_compatible_eulO(ob->rot, ob->rot, ob->rotmode, tmat); - else mat3_to_eulO(ob->rot, ob->rotmode, tmat); + if (use_compat) mat3_to_compatible_eulO(ob->rot, ob->rot, ob->rotmode, tmat); + else mat3_to_eulO(ob->rot, ob->rotmode, tmat); } } } void BKE_object_tfm_protected_backup(const Object *ob, - ObjectTfmProtectedChannels *obtfm) + ObjectTfmProtectedChannels *obtfm) { -#define TFMCPY( _v) (obtfm->_v = ob->_v) -#define TFMCPY3D( _v) copy_v3_v3(obtfm->_v, ob->_v) -#define TFMCPY4D( _v) copy_v4_v4(obtfm->_v, ob->_v) +#define TFMCPY(_v) (obtfm->_v = ob->_v) +#define TFMCPY3D(_v) copy_v3_v3(obtfm->_v, ob->_v) +#define TFMCPY4D(_v) copy_v4_v4(obtfm->_v, ob->_v) TFMCPY3D(loc); TFMCPY3D(dloc); @@ -1533,40 +1533,40 @@ void BKE_object_tfm_protected_backup(const Object *ob, } void BKE_object_tfm_protected_restore(Object *ob, - const ObjectTfmProtectedChannels *obtfm, - const short protectflag) + const ObjectTfmProtectedChannels *obtfm, + const short protectflag) { unsigned int i; - for (i= 0; i < 3; i++) { - if (protectflag & (OB_LOCK_LOCX<<i)) { - ob->loc[i]= obtfm->loc[i]; - ob->dloc[i]= obtfm->dloc[i]; + for (i = 0; i < 3; i++) { + if (protectflag & (OB_LOCK_LOCX << i)) { + ob->loc[i] = obtfm->loc[i]; + ob->dloc[i] = obtfm->dloc[i]; } - if (protectflag & (OB_LOCK_SCALEX<<i)) { - ob->size[i]= obtfm->size[i]; - ob->dscale[i]= obtfm->dscale[i]; + if (protectflag & (OB_LOCK_SCALEX << i)) { + ob->size[i] = obtfm->size[i]; + ob->dscale[i] = obtfm->dscale[i]; } - if (protectflag & (OB_LOCK_ROTX<<i)) { - ob->rot[i]= obtfm->rot[i]; - ob->drot[i]= obtfm->drot[i]; + if (protectflag & (OB_LOCK_ROTX << i)) { + ob->rot[i] = obtfm->rot[i]; + ob->drot[i] = obtfm->drot[i]; - ob->quat[i + 1]= obtfm->quat[i + 1]; - ob->dquat[i + 1]= obtfm->dquat[i + 1]; + ob->quat[i + 1] = obtfm->quat[i + 1]; + ob->dquat[i + 1] = obtfm->dquat[i + 1]; - ob->rotAxis[i]= obtfm->rotAxis[i]; - ob->drotAxis[i]= obtfm->drotAxis[i]; + ob->rotAxis[i] = obtfm->rotAxis[i]; + ob->drotAxis[i] = obtfm->drotAxis[i]; } } if ((protectflag & OB_LOCK_ROT4D) && (protectflag & OB_LOCK_ROTW)) { - ob->quat[0]= obtfm->quat[0]; - ob->dquat[0]= obtfm->dquat[0]; + ob->quat[0] = obtfm->quat[0]; + ob->dquat[0] = obtfm->dquat[0]; - ob->rotAngle= obtfm->rotAngle; - ob->drotAngle= obtfm->drotAngle; + ob->rotAngle = obtfm->rotAngle; + ob->drotAngle = obtfm->drotAngle; } } @@ -1600,7 +1600,7 @@ void BKE_object_apply_mat4(Object *ob, float mat[][4], const short use_compat, c /* BKE_object_mat3_to_rot handles delta rotations */ } -void BKE_object_to_mat3(Object *ob, float mat[][3]) /* no parent */ +void BKE_object_to_mat3(Object *ob, float mat[][3]) /* no parent */ { float smat[3][3]; float rmat[3][3]; @@ -1626,7 +1626,7 @@ void BKE_object_to_mat4(Object *ob, float mat[][4]) } /* extern */ -int enable_cu_speed= 1; +int enable_cu_speed = 1; static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) { @@ -1636,14 +1636,14 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) unit_m4(mat); - cu= par->data; - if (cu->path==NULL || cu->path->data==NULL) /* only happens on reload file, but violates depsgraph still... fix! */ + cu = par->data; + if (cu->path == NULL || cu->path->data == NULL) /* only happens on reload file, but violates depsgraph still... fix! */ makeDispListCurveTypes(scene, par, 0); - if (cu->path==NULL) return; + if (cu->path == NULL) return; /* catch exceptions: feature for nla stride editing */ if (ob->ipoflag & OB_DISABLE_PATH) { - ctime= 0.0f; + ctime = 0.0f; } /* catch exceptions: curve paths used as a duplicator */ else if (enable_cu_speed) { @@ -1654,14 +1654,14 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) * factor, which then gets clamped to lie within 0.0 - 1.0 range */ if (IS_EQF(cu->pathlen, 0.0f) == 0) - ctime= cu->ctime / cu->pathlen; + ctime = cu->ctime / cu->pathlen; else - ctime= cu->ctime; + ctime = cu->ctime; CLAMP(ctime, 0.0f, 1.0f); } else { - ctime= scene->r.cfra; + ctime = scene->r.cfra; if (IS_EQF(cu->pathlen, 0.0f) == 0) ctime /= cu->pathlen; @@ -1670,7 +1670,7 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) /* time calculus is correct, now apply distance offset */ if (cu->flag & CU_OFFS_PATHDIST) { - ctime += timeoffs/cu->path->totdist; + ctime += timeoffs / cu->path->totdist; /* restore */ SWAP(float, sf_orig, ob->sf); @@ -1678,7 +1678,7 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) /* vec: 4 items! */ - if (where_on_path(par, ctime, vec, dir, cu->flag & CU_FOLLOW ? quat:NULL, &radius, NULL)) { + if (where_on_path(par, ctime, vec, dir, cu->flag & CU_FOLLOW ? quat : NULL, &radius, NULL)) { if (cu->flag & CU_FOLLOW) { #if 0 @@ -1687,11 +1687,11 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) /* the tilt */ normalize_v3(dir); - q[0]= (float)cos(0.5*vec[3]); - x1= (float)sin(0.5*vec[3]); - q[1]= -x1*dir[0]; - q[2]= -x1*dir[1]; - q[3]= -x1*dir[2]; + q[0] = (float)cos(0.5 * vec[3]); + x1 = (float)sin(0.5 * vec[3]); + q[1] = -x1 * dir[0]; + q[2] = -x1 * dir[1]; + q[3] = -x1 * dir[2]; mul_qt_qtqt(quat, q, quat); #else quat_apply_track(quat, ob->trackflag, ob->upflag); @@ -1717,15 +1717,15 @@ static void ob_parbone(Object *ob, Object *par, float mat[][4]) bPoseChannel *pchan; float vec[3]; - if (par->type!=OB_ARMATURE) { + if (par->type != OB_ARMATURE) { unit_m4(mat); return; } /* Make sure the bone is still valid */ - pchan= BKE_pose_channel_find_name(par->pose, ob->parsubstr); + pchan = BKE_pose_channel_find_name(par->pose, ob->parsubstr); if (!pchan) { - printf ("Object %s with Bone parent: bone %s doesn't exist\n", ob->id.name+2, ob->parsubstr); + printf("Object %s with Bone parent: bone %s doesn't exist\n", ob->id.name + 2, ob->parsubstr); unit_m4(mat); return; } @@ -1744,15 +1744,15 @@ static void give_parvert(Object *par, int nr, float vec[3]) BMEditMesh *em; int a, count; - vec[0]=vec[1]=vec[2]= 0.0f; + vec[0] = vec[1] = vec[2] = 0.0f; - if (par->type==OB_MESH) { - Mesh *me= par->data; + if (par->type == OB_MESH) { + Mesh *me = par->data; DerivedMesh *dm; em = me->edit_btmesh; -#if 0 /* this was bmesh only, better, evaluate why this was needed - campbell*/ +#if 0 /* this was bmesh only, better, evaluate why this was needed - campbell*/ if (em) { BMVert *eve; BMIter iter; @@ -1760,7 +1760,7 @@ static void give_parvert(Object *par, int nr, float vec[3]) BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { int *keyindex = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_SHAPE_KEYINDEX); - if (keyindex && *keyindex==nr) { + if (keyindex && *keyindex == nr) { copy_v3_v3(vec, eve->co); break; } @@ -1768,17 +1768,17 @@ static void give_parvert(Object *par, int nr, float vec[3]) } #endif - dm = (em)? em->derivedFinal: par->derivedFinal; + dm = (em) ? em->derivedFinal : par->derivedFinal; if (dm) { - MVert *mvert= dm->getVertArray(dm); + MVert *mvert = dm->getVertArray(dm); int *index = (int *)dm->getVertDataArray(dm, CD_ORIGINDEX); int i, vindex, numVerts = dm->getNumVerts(dm); /* get the average of all verts with (original index == nr) */ - count= 0; + count = 0; for (i = 0; i < numVerts; i++) { - vindex= (index)? index[i]: i; + vindex = (index) ? index[i] : i; if (vindex == nr) { add_v3_v3(vec, mvert[i].co); @@ -1786,7 +1786,7 @@ static void give_parvert(Object *par, int nr, float vec[3]) } } - if (count==0) { + if (count == 0) { /* keep as 0, 0, 0 */ } else if (count > 0) { @@ -1804,21 +1804,21 @@ static void give_parvert(Object *par, int nr, float vec[3]) Curve *cu; BPoint *bp; BezTriple *bezt; - int found= 0; + int found = 0; ListBase *nurbs; - cu= par->data; - nurbs= BKE_curve_nurbs_get(cu); - nu= nurbs->first; + cu = par->data; + nurbs = BKE_curve_nurbs_get(cu); + nu = nurbs->first; - count= 0; + count = 0; while (nu && !found) { if (nu->type == CU_BEZIER) { - bezt= nu->bezt; - a= nu->pntsu; + bezt = nu->bezt; + a = nu->pntsu; while (a--) { - if (count==nr) { - found= 1; + if (count == nr) { + found = 1; copy_v3_v3(vec, bezt->vec[1]); break; } @@ -1827,43 +1827,43 @@ static void give_parvert(Object *par, int nr, float vec[3]) } } else { - bp= nu->bp; - a= nu->pntsu*nu->pntsv; + bp = nu->bp; + a = nu->pntsu * nu->pntsv; while (a--) { - if (count==nr) { - found= 1; - memcpy(vec, bp->vec, sizeof(float)*3); + if (count == nr) { + found = 1; + memcpy(vec, bp->vec, sizeof(float) * 3); break; } count++; bp++; } } - nu= nu->next; + nu = nu->next; } } - else if (par->type==OB_LATTICE) { - Lattice *latt= par->data; + else if (par->type == OB_LATTICE) { + Lattice *latt = par->data; BPoint *bp; DispList *dl = find_displist(&par->disp, DL_VERTS); - float *co = dl?dl->verts:NULL; + float *co = dl ? dl->verts : NULL; - if (latt->editlatt) latt= latt->editlatt->latt; + if (latt->editlatt) latt = latt->editlatt->latt; - a= latt->pntsu*latt->pntsv*latt->pntsw; - count= 0; - bp= latt->def; + a = latt->pntsu * latt->pntsv * latt->pntsw; + count = 0; + bp = latt->def; while (a--) { - if (count==nr) { + if (count == nr) { if (co) - memcpy(vec, co, 3*sizeof(float)); + memcpy(vec, co, 3 * sizeof(float)); else - memcpy(vec, bp->vec, 3*sizeof(float)); + memcpy(vec, bp->vec, 3 * sizeof(float)); break; } count++; - if (co) co+= 3; + if (co) co += 3; else bp++; } } @@ -1886,7 +1886,7 @@ static void ob_parvert3(Object *ob, Object *par, float mat[][4]) quat_to_mat3(cmat, q); copy_m4_m3(mat, cmat); - if (ob->type==OB_CURVE) { + if (ob->type == OB_CURVE) { copy_v3_v3(mat[3], v1); } else { @@ -1904,14 +1904,14 @@ static int where_is_object_parslow(Object *ob, float obmat[4][4], float slowmat[ int a; // include framerate - fac1= (1.0f / (1.0f + fabsf(ob->sf)) ); + fac1 = (1.0f / (1.0f + fabsf(ob->sf)) ); if (fac1 >= 1.0f) return 0; - fac2= 1.0f-fac1; + fac2 = 1.0f - fac1; - fp1= obmat[0]; - fp2= slowmat[0]; - for (a=0; a<16; a++, fp1++, fp2++) { - fp1[0]= fac1*fp1[0] + fac2*fp2[0]; + fp1 = obmat[0]; + fp2 = slowmat[0]; + for (a = 0; a < 16; a++, fp1++, fp2++) { + fp1[0] = fac1 * fp1[0] + fac2 * fp2[0]; } return 1; @@ -1920,32 +1920,32 @@ static int where_is_object_parslow(Object *ob, float obmat[4][4], float slowmat[ void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime) { float slowmat[4][4] = MAT4_UNITY; - float stime=ctime; + float stime = ctime; /* new version: correct parent+vertexparent and track+parent */ /* this one only calculates direct attached parent and track */ /* is faster, but should keep track of timeoffs */ - if (ob==NULL) return; + if (ob == NULL) return; /* execute drivers only, as animation has already been done */ BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, ctime, ADT_RECALC_DRIVERS); if (ob->parent) { - Object *par= ob->parent; + Object *par = ob->parent; /* hurms, code below conflicts with depgraph... (ton) */ /* and even worse, it gives bad effects for NLA stride too (try ctime != par->ctime, with MBlur) */ if (stime != par->ctime) { // only for ipo systems? - Object tmp= *par; + Object tmp = *par; - if (par->proxy_from); // was a copied matrix, no where_is! bad... + if (par->proxy_from) ; // was a copied matrix, no where_is! bad... else BKE_object_where_is_calc_time(scene, par, ctime); solve_parenting(scene, ob, par, ob->obmat, slowmat, 0); - *par= tmp; + *par = tmp; } else solve_parenting(scene, ob, par, ob->obmat, slowmat, 0); @@ -1966,17 +1966,17 @@ void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime) if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) { bConstraintOb *cob; - cob= constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT); + cob = constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT); /* constraints need ctime, not stime. Some call BKE_object_where_is_calc_time and bsystem_time */ - solve_constraints (&ob->constraints, cob, ctime); + solve_constraints(&ob->constraints, cob, ctime); constraints_clear_evalob(cob); } /* set negative scale flag in object */ - if (is_negative_m4(ob->obmat)) ob->transflag |= OB_NEG_SCALE; - else ob->transflag &= ~OB_NEG_SCALE; + if (is_negative_m4(ob->obmat)) ob->transflag |= OB_NEG_SCALE; + else ob->transflag &= ~OB_NEG_SCALE; } /* get object transformation matrix without recalculating dependencies and @@ -1988,7 +1988,7 @@ void BKE_object_where_is_calc_mat4(Scene *scene, Object *ob, float obmat[4][4]) float slowmat[4][4] = MAT4_UNITY; if (ob->parent) { - Object *par= ob->parent; + Object *par = ob->parent; solve_parenting(scene, ob, par, obmat, slowmat, 1); @@ -2000,7 +2000,7 @@ void BKE_object_where_is_calc_mat4(Scene *scene, Object *ob, float obmat[4][4]) } } -static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul) +static void solve_parenting(Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul) { float totmat[4][4]; float tmat[4][4]; @@ -2013,53 +2013,53 @@ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[ if (ob->partype & PARSLOW) copy_m4_m4(slowmat, obmat); switch (ob->partype & PARTYPE) { - case PAROBJECT: - ok= 0; - if (par->type==OB_CURVE) { - if (((Curve *)par->data)->flag & CU_PATH ) { - ob_parcurve(scene, ob, par, tmat); - ok= 1; + case PAROBJECT: + ok = 0; + if (par->type == OB_CURVE) { + if (((Curve *)par->data)->flag & CU_PATH) { + ob_parcurve(scene, ob, par, tmat); + ok = 1; + } } - } - if (ok) mul_serie_m4(totmat, par->obmat, tmat, - NULL, NULL, NULL, NULL, NULL, NULL); - else copy_m4_m4(totmat, par->obmat); + if (ok) mul_serie_m4(totmat, par->obmat, tmat, + NULL, NULL, NULL, NULL, NULL, NULL); + else copy_m4_m4(totmat, par->obmat); - break; - case PARBONE: - ob_parbone(ob, par, tmat); - mul_serie_m4(totmat, par->obmat, tmat, - NULL, NULL, NULL, NULL, NULL, NULL); - break; + break; + case PARBONE: + ob_parbone(ob, par, tmat); + mul_serie_m4(totmat, par->obmat, tmat, + NULL, NULL, NULL, NULL, NULL, NULL); + break; - case PARVERT1: - unit_m4(totmat); - if (simul) { - copy_v3_v3(totmat[3], par->obmat[3]); - } - else { - give_parvert(par, ob->par1, vec); - mul_v3_m4v3(totmat[3], par->obmat, vec); - } - break; - case PARVERT3: - ob_parvert3(ob, par, tmat); + case PARVERT1: + unit_m4(totmat); + if (simul) { + copy_v3_v3(totmat[3], par->obmat[3]); + } + else { + give_parvert(par, ob->par1, vec); + mul_v3_m4v3(totmat[3], par->obmat, vec); + } + break; + case PARVERT3: + ob_parvert3(ob, par, tmat); - mul_serie_m4(totmat, par->obmat, tmat, - NULL, NULL, NULL, NULL, NULL, NULL); - break; + mul_serie_m4(totmat, par->obmat, tmat, + NULL, NULL, NULL, NULL, NULL, NULL); + break; - case PARSKEL: - copy_m4_m4(totmat, par->obmat); - break; + case PARSKEL: + copy_m4_m4(totmat, par->obmat); + break; } // total mul_serie_m4(tmat, totmat, ob->parentinv, - NULL, NULL, NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL, NULL); mul_serie_m4(obmat, tmat, locmat, - NULL, NULL, NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL, NULL); if (simul) { @@ -2069,7 +2069,7 @@ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[ copy_m3_m4(originmat, tmat); // origin, voor help line - if ((ob->partype & PARTYPE)==PARSKEL ) { + if ((ob->partype & PARTYPE) == PARSKEL) { copy_v3_v3(ob->orig, par->obmat[3]); } else { @@ -2098,17 +2098,17 @@ void BKE_object_where_is_calc_simul(Scene *scene, Object *ob) /* NO TIMEOFFS */ if (ob->parent) { - par= ob->parent; + par = ob->parent; solve_parenting(scene, ob, par, ob->obmat, slowmat, 1); if (ob->partype & PARSLOW) { - fac1= (float)(1.0/(1.0+ fabs(ob->sf))); - fac2= 1.0f-fac1; - fp1= ob->obmat[0]; - fp2= slowmat[0]; - for (a=0; a<16; a++, fp1++, fp2++) { - fp1[0]= fac1*fp1[0] + fac2*fp2[0]; + fac1 = (float)(1.0 / (1.0 + fabs(ob->sf))); + fac2 = 1.0f - fac1; + fp1 = ob->obmat[0]; + fp2 = slowmat[0]; + for (a = 0; a < 16; a++, fp1++, fp2++) { + fp1[0] = fac1 * fp1[0] + fac2 * fp2[0]; } } } @@ -2120,7 +2120,7 @@ void BKE_object_where_is_calc_simul(Scene *scene, Object *ob) if (ob->constraints.first) { bConstraintOb *cob; - cob= constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT); + cob = constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT); solve_constraints(&ob->constraints, cob, (float)scene->r.cfra); constraints_clear_evalob(cob); } @@ -2134,15 +2134,15 @@ void BKE_object_workob_calc_parent(Scene *scene, Object *ob, Object *workob) unit_m4(workob->obmat); unit_m4(workob->parentinv); unit_m4(workob->constinv); - workob->parent= ob->parent; + workob->parent = ob->parent; - workob->trackflag= ob->trackflag; - workob->upflag= ob->upflag; + workob->trackflag = ob->trackflag; + workob->upflag = ob->upflag; - workob->partype= ob->partype; - workob->par1= ob->par1; - workob->par2= ob->par2; - workob->par3= ob->par3; + workob->partype = ob->partype; + workob->par1 = ob->par1; + workob->par2 = ob->par2; + workob->par3 = ob->par3; workob->constraints.first = ob->constraints.first; workob->constraints.last = ob->constraints.last; @@ -2157,7 +2157,7 @@ BoundBox *BKE_boundbox_alloc_unit(void) BoundBox *bb; float min[3] = {-1.0f, -1.0f, -1.0f}, max[3] = {-1.0f, -1.0f, -1.0f}; - bb= MEM_callocN(sizeof(BoundBox), "OB-BoundBox"); + bb = MEM_callocN(sizeof(BoundBox), "OB-BoundBox"); BKE_boundbox_init_from_minmax(bb, min, max); return bb; @@ -2165,28 +2165,28 @@ BoundBox *BKE_boundbox_alloc_unit(void) void BKE_boundbox_init_from_minmax(BoundBox *bb, float min[3], float max[3]) { - bb->vec[0][0]=bb->vec[1][0]=bb->vec[2][0]=bb->vec[3][0]= min[0]; - bb->vec[4][0]=bb->vec[5][0]=bb->vec[6][0]=bb->vec[7][0]= max[0]; + bb->vec[0][0] = bb->vec[1][0] = bb->vec[2][0] = bb->vec[3][0] = min[0]; + bb->vec[4][0] = bb->vec[5][0] = bb->vec[6][0] = bb->vec[7][0] = max[0]; - bb->vec[0][1]=bb->vec[1][1]=bb->vec[4][1]=bb->vec[5][1]= min[1]; - bb->vec[2][1]=bb->vec[3][1]=bb->vec[6][1]=bb->vec[7][1]= max[1]; + bb->vec[0][1] = bb->vec[1][1] = bb->vec[4][1] = bb->vec[5][1] = min[1]; + bb->vec[2][1] = bb->vec[3][1] = bb->vec[6][1] = bb->vec[7][1] = max[1]; - bb->vec[0][2]=bb->vec[3][2]=bb->vec[4][2]=bb->vec[7][2]= min[2]; - bb->vec[1][2]=bb->vec[2][2]=bb->vec[5][2]=bb->vec[6][2]= max[2]; + bb->vec[0][2] = bb->vec[3][2] = bb->vec[4][2] = bb->vec[7][2] = min[2]; + bb->vec[1][2] = bb->vec[2][2] = bb->vec[5][2] = bb->vec[6][2] = max[2]; } BoundBox *BKE_object_boundbox_get(Object *ob) { - BoundBox *bb= NULL; + BoundBox *bb = NULL; - if (ob->type==OB_MESH) { + if (ob->type == OB_MESH) { bb = BKE_mesh_boundbox_get(ob); } else if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { - bb= ob->bb ? ob->bb : ((Curve *)ob->data )->bb; + bb = ob->bb ? ob->bb : ((Curve *)ob->data)->bb; } - else if (ob->type==OB_MBALL) { - bb= ob->bb; + else if (ob->type == OB_MBALL) { + bb = ob->bb; } return bb; } @@ -2194,7 +2194,7 @@ BoundBox *BKE_object_boundbox_get(Object *ob) /* used to temporally disable/enable boundbox */ void BKE_object_boundbox_flag(Object *ob, int flag, int set) { - BoundBox *bb= BKE_object_boundbox_get(ob); + BoundBox *bb = BKE_object_boundbox_get(ob); if (bb) { if (set) bb->flag |= flag; else bb->flag &= ~flag; @@ -2205,7 +2205,7 @@ void BKE_object_dimensions_get(Object *ob, float vec[3]) { BoundBox *bb = NULL; - bb= BKE_object_boundbox_get(ob); + bb = BKE_object_boundbox_get(ob); if (bb) { float scale[3]; @@ -2224,7 +2224,7 @@ void BKE_object_dimensions_set(Object *ob, const float *value) { BoundBox *bb = NULL; - bb= BKE_object_boundbox_get(ob); + bb = BKE_object_boundbox_get(ob); if (bb) { float scale[3], len[3]; @@ -2245,66 +2245,66 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3]) BoundBox bb; float vec[3]; int a; - short change= FALSE; + short change = FALSE; switch (ob->type) { - case OB_CURVE: - case OB_FONT: - case OB_SURF: + case OB_CURVE: + case OB_FONT: + case OB_SURF: { - Curve *cu= ob->data; + Curve *cu = ob->data; - if (cu->bb==NULL) BKE_curve_texspace_calc(cu); - bb= *(cu->bb); + if (cu->bb == NULL) BKE_curve_texspace_calc(cu); + bb = *(cu->bb); - for (a=0; a<8; a++) { + for (a = 0; a < 8; a++) { mul_m4_v3(ob->obmat, bb.vec[a]); DO_MINMAX(bb.vec[a], min_r, max_r); } - change= TRUE; + change = TRUE; } break; - case OB_LATTICE: + case OB_LATTICE: { - Lattice *lt= ob->data; - BPoint *bp= lt->def; + Lattice *lt = ob->data; + BPoint *bp = lt->def; int u, v, w; - for (w=0; w<lt->pntsw; w++) { - for (v=0; v<lt->pntsv; v++) { - for (u=0; u<lt->pntsu; u++, bp++) { + for (w = 0; w < lt->pntsw; w++) { + for (v = 0; v < lt->pntsv; v++) { + for (u = 0; u < lt->pntsu; u++, bp++) { mul_v3_m4v3(vec, ob->obmat, bp->vec); DO_MINMAX(vec, min_r, max_r); } } } - change= TRUE; + change = TRUE; } break; - case OB_ARMATURE: - if (ob->pose) { - bPoseChannel *pchan; - for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - mul_v3_m4v3(vec, ob->obmat, pchan->pose_head); - DO_MINMAX(vec, min_r, max_r); - mul_v3_m4v3(vec, ob->obmat, pchan->pose_tail); - DO_MINMAX(vec, min_r, max_r); + case OB_ARMATURE: + if (ob->pose) { + bPoseChannel *pchan; + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + mul_v3_m4v3(vec, ob->obmat, pchan->pose_head); + DO_MINMAX(vec, min_r, max_r); + mul_v3_m4v3(vec, ob->obmat, pchan->pose_tail); + DO_MINMAX(vec, min_r, max_r); + } + change = TRUE; } - change= TRUE; - } - break; - case OB_MESH: + break; + case OB_MESH: { - Mesh *me= BKE_mesh_from_object(ob); + Mesh *me = BKE_mesh_from_object(ob); if (me) { bb = *BKE_mesh_boundbox_get(ob); - for (a=0; a<8; a++) { + for (a = 0; a < 8; a++) { mul_m4_v3(ob->obmat, bb.vec[a]); DO_MINMAX(bb.vec[a], min_r, max_r); } - change= TRUE; + change = TRUE; } } break; @@ -2325,32 +2325,32 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3]) int BKE_object_minmax_dupli(Scene *scene, Object *ob, float r_min[3], float r_max[3]) { - int ok= 0; - if ((ob->transflag & OB_DUPLI)==0) { + int ok = 0; + if ((ob->transflag & OB_DUPLI) == 0) { return ok; } else { ListBase *lb; DupliObject *dob; - lb= object_duplilist(scene, ob); - for (dob= lb->first; dob; dob= dob->next) { + lb = object_duplilist(scene, ob); + for (dob = lb->first; dob; dob = dob->next) { if (dob->no_draw == 0) { - BoundBox *bb= BKE_object_boundbox_get(dob->ob); + BoundBox *bb = BKE_object_boundbox_get(dob->ob); if (bb) { int i; - for (i=0; i<8; i++) { + for (i = 0; i < 8; i++) { float vec[3]; mul_v3_m4v3(vec, dob->mat, bb->vec[i]); DO_MINMAX(vec, r_min, r_max); } - ok= 1; + ok = 1; } } } - free_object_duplilist(lb); /* does restore */ + free_object_duplilist(lb); /* does restore */ } return ok; @@ -2363,12 +2363,12 @@ void BKE_object_foreach_display_point( float co[3]; if (ob->derivedFinal) { - DerivedMesh *dm= ob->derivedFinal; - MVert *mv= dm->getVertArray(dm); - int totvert= dm->getNumVerts(dm); + DerivedMesh *dm = ob->derivedFinal; + MVert *mv = dm->getVertArray(dm); + int totvert = dm->getNumVerts(dm); int i; - for (i= 0; i < totvert; i++, mv++) { + for (i = 0; i < totvert; i++, mv++) { mul_v3_m4v3(co, obmat, mv->co); func_cb(co, user_data); } @@ -2376,12 +2376,12 @@ void BKE_object_foreach_display_point( else if (ob->disp.first) { DispList *dl; - for (dl=ob->disp.first; dl; dl=dl->next) { - float *v3= dl->verts; - int totvert= dl->nr; + for (dl = ob->disp.first; dl; dl = dl->next) { + float *v3 = dl->verts; + int totvert = dl->nr; int i; - for (i= 0; i < totvert; i++, v3+=3) { + for (i = 0; i < totvert; i++, v3 += 3) { mul_v3_m4v3(co, obmat, v3); func_cb(co, user_data); } @@ -2396,24 +2396,24 @@ void BKE_scene_foreach_display_point( Base *base; Object *ob; - for (base= FIRSTBASE; base; base = base->next) { + for (base = FIRSTBASE; base; base = base->next) { if (BASE_VISIBLE(v3d, base) && (base->flag & flag) == flag) { - ob= base->object; + ob = base->object; - if ((ob->transflag & OB_DUPLI)==0) { + if ((ob->transflag & OB_DUPLI) == 0) { BKE_object_foreach_display_point(ob, ob->obmat, func_cb, user_data); } else { ListBase *lb; DupliObject *dob; - lb= object_duplilist(scene, ob); - for (dob= lb->first; dob; dob= dob->next) { + lb = object_duplilist(scene, ob); + for (dob = lb->first; dob; dob = dob->next) { if (dob->no_draw == 0) { BKE_object_foreach_display_point(dob->ob, dob->mat, func_cb, user_data); } } - free_object_duplilist(lb); /* does restore */ + free_object_duplilist(lb); /* does restore */ } } } @@ -2422,20 +2422,20 @@ void BKE_scene_foreach_display_point( /* copied from DNA_object_types.h */ typedef struct ObTfmBack { float loc[3], dloc[3], orig[3]; - float size[3], dscale[3]; /* scale and delta scale */ - float rot[3], drot[3]; /* euler rotation */ - float quat[4], dquat[4]; /* quaternion rotation */ - float rotAxis[3], drotAxis[3]; /* axis angle rotation - axis part */ - float rotAngle, drotAngle; /* axis angle rotation - angle part */ - float obmat[4][4]; /* final worldspace matrix with constraints & animsys applied */ + float size[3], dscale[3]; /* scale and delta scale */ + float rot[3], drot[3]; /* euler rotation */ + float quat[4], dquat[4]; /* quaternion rotation */ + float rotAxis[3], drotAxis[3]; /* axis angle rotation - axis part */ + float rotAngle, drotAngle; /* axis angle rotation - angle part */ + float obmat[4][4]; /* final worldspace matrix with constraints & animsys applied */ float parentinv[4][4]; /* inverse result of parent, so that object doesn't 'stick' to parent */ float constinv[4][4]; /* inverse result of constraints. doesn't include effect of parent or object local transform */ - float imat[4][4]; /* inverse matrix of 'obmat' for during render, old game engine, temporally: ipokeys of transform */ + float imat[4][4]; /* inverse matrix of 'obmat' for during render, old game engine, temporally: ipokeys of transform */ } ObTfmBack; void *BKE_object_tfm_backup(Object *ob) { - ObTfmBack *obtfm= MEM_mallocN(sizeof(ObTfmBack), "ObTfmBack"); + ObTfmBack *obtfm = MEM_mallocN(sizeof(ObTfmBack), "ObTfmBack"); copy_v3_v3(obtfm->loc, ob->loc); copy_v3_v3(obtfm->dloc, ob->dloc); copy_v3_v3(obtfm->orig, ob->orig); @@ -2447,8 +2447,8 @@ void *BKE_object_tfm_backup(Object *ob) copy_qt_qt(obtfm->dquat, ob->dquat); copy_v3_v3(obtfm->rotAxis, ob->rotAxis); copy_v3_v3(obtfm->drotAxis, ob->drotAxis); - obtfm->rotAngle= ob->rotAngle; - obtfm->drotAngle= ob->drotAngle; + obtfm->rotAngle = ob->rotAngle; + obtfm->drotAngle = ob->drotAngle; copy_m4_m4(obtfm->obmat, ob->obmat); copy_m4_m4(obtfm->parentinv, ob->parentinv); copy_m4_m4(obtfm->constinv, ob->constinv); @@ -2459,7 +2459,7 @@ void *BKE_object_tfm_backup(Object *ob) void BKE_object_tfm_restore(Object *ob, void *obtfm_pt) { - ObTfmBack *obtfm= (ObTfmBack *)obtfm_pt; + ObTfmBack *obtfm = (ObTfmBack *)obtfm_pt; copy_v3_v3(ob->loc, obtfm->loc); copy_v3_v3(ob->dloc, obtfm->dloc); copy_v3_v3(ob->orig, obtfm->orig); @@ -2471,8 +2471,8 @@ void BKE_object_tfm_restore(Object *ob, void *obtfm_pt) copy_qt_qt(ob->dquat, obtfm->dquat); copy_v3_v3(ob->rotAxis, obtfm->rotAxis); copy_v3_v3(ob->drotAxis, obtfm->drotAxis); - ob->rotAngle= obtfm->rotAngle; - ob->drotAngle= obtfm->drotAngle; + ob->rotAngle = obtfm->rotAngle; + ob->drotAngle = obtfm->drotAngle; copy_m4_m4(ob->obmat, obtfm->obmat); copy_m4_m4(ob->parentinv, obtfm->parentinv); copy_m4_m4(ob->constinv, obtfm->constinv); @@ -2502,12 +2502,12 @@ void BKE_object_handle_update(Scene *scene, Object *ob) BKE_pose_channels_hash_make(ob->pose); if (ob->recalc & OB_RECALC_DATA) { - if (ob->type==OB_ARMATURE) { + if (ob->type == OB_ARMATURE) { /* this happens for reading old files and to match library armatures * with poses we do it ahead of BKE_object_where_is_calc to ensure animation * is evaluated on the rebuilt pose, otherwise we get incorrect poses * on file load */ - if (ob->pose==NULL || (ob->pose->flag & POSE_RECALC)) + if (ob->pose == NULL || (ob->pose->flag & POSE_RECALC)) BKE_pose_rebuild(ob, ob->data); } } @@ -2518,13 +2518,13 @@ void BKE_object_handle_update(Scene *scene, Object *ob) if (ob->recalc & OB_RECALC_ALL) { if (G.debug & G_DEBUG) - printf("recalcob %s\n", ob->id.name+2); + printf("recalcob %s\n", ob->id.name + 2); /* handle proxy copy for target */ if (ob->id.lib && ob->proxy_from) { // printf("ob proxy copy, lib ob %s proxy %s\n", ob->id.name, ob->proxy_from->id.name); - if (ob->proxy_from->proxy_group) {/* transform proxy into group space */ - Object *obg= ob->proxy_from->proxy_group; + if (ob->proxy_from->proxy_group) { /* transform proxy into group space */ + Object *obg = ob->proxy_from->proxy_group; invert_m4_m4(obg->imat, obg->obmat); mult_m4_m4m4(ob->obmat, obg->imat, ob->proxy_from->obmat); if (obg->dup_group) { /* should always be true */ @@ -2539,14 +2539,14 @@ void BKE_object_handle_update(Scene *scene, Object *ob) } if (ob->recalc & OB_RECALC_DATA) { - ID *data_id= (ID *)ob->data; - AnimData *adt= BKE_animdata_from_id(data_id); - float ctime= (float)scene->r.cfra; // XXX this is bad... + ID *data_id = (ID *)ob->data; + AnimData *adt = BKE_animdata_from_id(data_id); + float ctime = (float)scene->r.cfra; // XXX this is bad... ListBase pidlist; PTCacheID *pid; if (G.debug & G_DEBUG) - printf("recalcdata %s\n", ob->id.name+2); + printf("recalcdata %s\n", ob->id.name + 2); if (adt) { /* evaluate drivers */ @@ -2556,9 +2556,9 @@ void BKE_object_handle_update(Scene *scene, Object *ob) /* includes all keys and modifiers */ switch (ob->type) { - case OB_MESH: + case OB_MESH: { -#if 0 // XXX, comment for 2.56a release, background wont set 'scene->customdata_mask' +#if 0 // XXX, comment for 2.56a release, background wont set 'scene->customdata_mask' BMEditMesh *em = (ob == scene->obedit) ? BMEdit_FromObject(ob) : NULL; BLI_assert((scene->customdata_mask & CD_MASK_BAREMESH) == CD_MASK_BAREMESH); if (em) { @@ -2568,9 +2568,9 @@ void BKE_object_handle_update(Scene *scene, Object *ob) makeDerivedMesh(scene, ob, NULL, scene->customdata_mask, 0); } -#else /* ensure CD_MASK_BAREMESH for now */ +#else /* ensure CD_MASK_BAREMESH for now */ BMEditMesh *em = (ob == scene->obedit) ? BMEdit_FromObject(ob) : NULL; - uint64_t data_mask= scene->customdata_mask | ob->customdata_mask | CD_MASK_BAREMESH; + uint64_t data_mask = scene->customdata_mask | ob->customdata_mask | CD_MASK_BAREMESH; if (em) { makeDerivedMesh(scene, ob, em, data_mask, 0); /* was CD_MASK_BAREMESH */ } @@ -2582,29 +2582,29 @@ void BKE_object_handle_update(Scene *scene, Object *ob) } break; - case OB_ARMATURE: - if (ob->id.lib && ob->proxy_from) { - // printf("pose proxy copy, lib ob %s proxy %s\n", ob->id.name, ob->proxy_from->id.name); - BKE_pose_copy_result(ob->pose, ob->proxy_from->pose); - } - else { - BKE_pose_where_is(scene, ob); - } - break; + case OB_ARMATURE: + if (ob->id.lib && ob->proxy_from) { + // printf("pose proxy copy, lib ob %s proxy %s\n", ob->id.name, ob->proxy_from->id.name); + BKE_pose_copy_result(ob->pose, ob->proxy_from->pose); + } + else { + BKE_pose_where_is(scene, ob); + } + break; - case OB_MBALL: - makeDispListMBall(scene, ob); - break; + case OB_MBALL: + makeDispListMBall(scene, ob); + break; - case OB_CURVE: - case OB_SURF: - case OB_FONT: - makeDispListCurveTypes(scene, ob, 0); - break; + case OB_CURVE: + case OB_SURF: + case OB_FONT: + makeDispListCurveTypes(scene, ob, 0); + break; - case OB_LATTICE: - BKE_lattice_modifiers_calc(scene, ob); - break; + case OB_LATTICE: + BKE_lattice_modifiers_calc(scene, ob); + break; } @@ -2613,7 +2613,7 @@ void BKE_object_handle_update(Scene *scene, Object *ob) DerivedMesh *dm; ob->transflag &= ~OB_DUPLIPARTS; - psys= ob->particlesystem.first; + psys = ob->particlesystem.first; while (psys) { if (psys_check_enabled(ob, psys)) { /* check use of dupli objects here */ @@ -2625,26 +2625,26 @@ void BKE_object_handle_update(Scene *scene, Object *ob) } particle_system_update(scene, ob, psys); - psys= psys->next; + psys = psys->next; } else if (psys->flag & PSYS_DELETE) { - tpsys=psys->next; + tpsys = psys->next; BLI_remlink(&ob->particlesystem, psys); psys_free(ob, psys); - psys= tpsys; + psys = tpsys; } else - psys= psys->next; + psys = psys->next; } if (G.rendering && ob->transflag & OB_DUPLIPARTS) { /* this is to make sure we get render level duplis in groups: * the derivedmesh must be created before init_render_mesh, * since object_duplilist does dupliparticles before that */ - dm = mesh_create_derived_render(scene, ob, CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL); + dm = mesh_create_derived_render(scene, ob, CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL); dm->release(dm); - for (psys=ob->particlesystem.first; psys; psys=psys->next) + for (psys = ob->particlesystem.first; psys; psys = psys->next) psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated; } } @@ -2652,18 +2652,18 @@ void BKE_object_handle_update(Scene *scene, Object *ob) /* check if quick cache is needed */ BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR); - for (pid=pidlist.first; pid; pid=pid->next) { + for (pid = pidlist.first; pid; pid = pid->next) { if ((pid->cache->flag & PTCACHE_BAKED) || (pid->cache->flag & PTCACHE_QUICK_CACHE) == 0) { continue; } - if (pid->cache->flag & PTCACHE_OUTDATED || (pid->cache->flag & PTCACHE_SIMULATION_VALID)==0) { + if (pid->cache->flag & PTCACHE_OUTDATED || (pid->cache->flag & PTCACHE_SIMULATION_VALID) == 0) { scene->physics_settings.quick_cache_step = - scene->physics_settings.quick_cache_step ? - MIN2(scene->physics_settings.quick_cache_step, pid->cache->step) : - pid->cache->step; + scene->physics_settings.quick_cache_step ? + MIN2(scene->physics_settings.quick_cache_step, pid->cache->step) : + pid->cache->step; } } @@ -2671,9 +2671,9 @@ void BKE_object_handle_update(Scene *scene, Object *ob) } /* the no-group proxy case, we call update */ - if (ob->proxy && ob->proxy_group==NULL) { + if (ob->proxy && ob->proxy_group == NULL) { /* set pointer in library proxy target, for copying, but restore it */ - ob->proxy->proxy_from= ob; + ob->proxy->proxy_from = ob; // printf("call update, lib ob %s proxy %s\n", ob->proxy->id.name, ob->id.name); BKE_object_handle_update(scene, ob->proxy); } @@ -2683,22 +2683,22 @@ void BKE_object_handle_update(Scene *scene, Object *ob) /* the case when this is a group proxy, object_update is called in group.c */ if (ob->proxy) { - ob->proxy->proxy_from= ob; + ob->proxy->proxy_from = ob; // printf("set proxy pointer for later group stuff %s\n", ob->id.name); } } void BKE_object_sculpt_modifiers_changed(Object *ob) { - SculptSession *ss= ob->sculpt; + SculptSession *ss = ob->sculpt; if (!ss->cache) { /* we free pbvh on changes, except during sculpt since it can't deal with * changing PVBH node organization, we hope topology does not change in * the meantime .. weak */ if (ss->pbvh) { - BLI_pbvh_free(ss->pbvh); - ss->pbvh= NULL; + BLI_pbvh_free(ss->pbvh); + ss->pbvh = NULL; } free_sculptsession_deformMats(ob->sculpt); @@ -2719,39 +2719,39 @@ void BKE_object_sculpt_modifiers_changed(Object *ob) int BKE_object_obdata_texspace_get(Object *ob, short **r_texflag, float **r_loc, float **r_size, float **r_rot) { - if (ob->data==NULL) + if (ob->data == NULL) return 0; switch (GS(((ID *)ob->data)->name)) { - case ID_ME: - { - Mesh *me= ob->data; - if (r_texflag) *r_texflag = &me->texflag; - if (r_loc) *r_loc = me->loc; - if (r_size) *r_size = me->size; - if (r_rot) *r_rot = me->rot; - break; - } - case ID_CU: - { - Curve *cu= ob->data; - if (r_texflag) *r_texflag = &cu->texflag; - if (r_loc) *r_loc = cu->loc; - if (r_size) *r_size = cu->size; - if (r_rot) *r_rot = cu->rot; - break; - } - case ID_MB: - { - MetaBall *mb= ob->data; - if (r_texflag) *r_texflag = &mb->texflag; - if (r_loc) *r_loc = mb->loc; - if (r_size) *r_size = mb->size; - if (r_rot) *r_rot = mb->rot; - break; - } - default: - return 0; + case ID_ME: + { + Mesh *me = ob->data; + if (r_texflag) *r_texflag = &me->texflag; + if (r_loc) *r_loc = me->loc; + if (r_size) *r_size = me->size; + if (r_rot) *r_rot = me->rot; + break; + } + case ID_CU: + { + Curve *cu = ob->data; + if (r_texflag) *r_texflag = &cu->texflag; + if (r_loc) *r_loc = cu->loc; + if (r_size) *r_size = cu->size; + if (r_rot) *r_rot = cu->rot; + break; + } + case ID_MB: + { + MetaBall *mb = ob->data; + if (r_texflag) *r_texflag = &mb->texflag; + if (r_loc) *r_loc = mb->loc; + if (r_size) *r_size = mb->size; + if (r_rot) *r_rot = mb->rot; + break; + } + default: + return 0; } return 1; } @@ -2798,7 +2798,7 @@ int BKE_object_insert_ptcache(Object *ob) BLI_sortlist(&ob->pc_ids, pc_cmp); - for (link=ob->pc_ids.first, i = 0; link; link=link->next, i++) { + for (link = ob->pc_ids.first, i = 0; link; link = link->next, i++) { int index = GET_INT_FROM_POINTER(link->data); if (i < index) @@ -2815,18 +2815,18 @@ int BKE_object_insert_ptcache(Object *ob) #if 0 static int pc_findindex(ListBase *listbase, int index) { - LinkData *link= NULL; - int number= 0; + LinkData *link = NULL; + int number = 0; if (listbase == NULL) return -1; - link= listbase->first; + link = listbase->first; while (link) { if ((int)link->data == index) return number; number++; - link= link->next; + link = link->next; } return -1; @@ -2845,30 +2845,30 @@ void object_delete_ptcache(Object *ob, int index) /************************* Mesh ************************/ static KeyBlock *insert_meshkey(Scene *scene, Object *ob, const char *name, int from_mix) { - Mesh *me= ob->data; - Key *key= me->key; + Mesh *me = ob->data; + Key *key = me->key; KeyBlock *kb; - int newkey= 0; + int newkey = 0; if (key == NULL) { - key= me->key= add_key((ID *)me); - key->type= KEY_RELATIVE; - newkey= 1; + key = me->key = add_key((ID *)me); + key->type = KEY_RELATIVE; + newkey = 1; } - if (newkey || from_mix==FALSE) { + if (newkey || from_mix == FALSE) { /* create from mesh */ kb = add_keyblock_ctime(key, name, FALSE); mesh_to_key(me, kb); } else { /* copy from current values */ - float *data= do_ob_key(scene, ob); + float *data = do_ob_key(scene, ob); /* create new block with prepared data */ kb = add_keyblock_ctime(key, name, FALSE); - kb->data= data; - kb->totelem= me->totvert; + kb->data = data; + kb->totelem = me->totvert; } return kb; @@ -2876,23 +2876,23 @@ static KeyBlock *insert_meshkey(Scene *scene, Object *ob, const char *name, int /************************* Lattice ************************/ static KeyBlock *insert_lattkey(Scene *scene, Object *ob, const char *name, int from_mix) { - Lattice *lt= ob->data; - Key *key= lt->key; + Lattice *lt = ob->data; + Key *key = lt->key; KeyBlock *kb; - int newkey= 0; + int newkey = 0; - if (key==NULL) { - key= lt->key= add_key((ID *)lt); - key->type= KEY_RELATIVE; - newkey= 1; + if (key == NULL) { + key = lt->key = add_key((ID *)lt); + key->type = KEY_RELATIVE; + newkey = 1; } - if (newkey || from_mix==FALSE) { + if (newkey || from_mix == FALSE) { kb = add_keyblock_ctime(key, name, FALSE); if (!newkey) { - KeyBlock *basekb= (KeyBlock *)key->block.first; - kb->data= MEM_dupallocN(basekb->data); - kb->totelem= basekb->totelem; + KeyBlock *basekb = (KeyBlock *)key->block.first; + kb->data = MEM_dupallocN(basekb->data); + kb->totelem = basekb->totelem; } else { latt_to_key(lt, kb); @@ -2900,12 +2900,12 @@ static KeyBlock *insert_lattkey(Scene *scene, Object *ob, const char *name, int } else { /* copy from current values */ - float *data= do_ob_key(scene, ob); + float *data = do_ob_key(scene, ob); /* create new block with prepared data */ kb = add_keyblock_ctime(key, name, FALSE); - kb->totelem= lt->pntsu*lt->pntsv*lt->pntsw; - kb->data= data; + kb->totelem = lt->pntsu * lt->pntsv * lt->pntsw; + kb->data = data; } return kb; @@ -2913,25 +2913,25 @@ static KeyBlock *insert_lattkey(Scene *scene, Object *ob, const char *name, int /************************* Curve ************************/ static KeyBlock *insert_curvekey(Scene *scene, Object *ob, const char *name, int from_mix) { - Curve *cu= ob->data; - Key *key= cu->key; + Curve *cu = ob->data; + Key *key = cu->key; KeyBlock *kb; - ListBase *lb= BKE_curve_nurbs_get(cu); - int newkey= 0; + ListBase *lb = BKE_curve_nurbs_get(cu); + int newkey = 0; - if (key==NULL) { - key= cu->key= add_key((ID *)cu); + if (key == NULL) { + key = cu->key = add_key((ID *)cu); key->type = KEY_RELATIVE; - newkey= 1; + newkey = 1; } - if (newkey || from_mix==FALSE) { + if (newkey || from_mix == FALSE) { /* create from curve */ kb = add_keyblock_ctime(key, name, FALSE); if (!newkey) { - KeyBlock *basekb= (KeyBlock *)key->block.first; - kb->data= MEM_dupallocN(basekb->data); - kb->totelem= basekb->totelem; + KeyBlock *basekb = (KeyBlock *)key->block.first; + kb->data = MEM_dupallocN(basekb->data); + kb->totelem = basekb->totelem; } else { curve_to_key(cu, kb, lb); @@ -2939,12 +2939,12 @@ static KeyBlock *insert_curvekey(Scene *scene, Object *ob, const char *name, int } else { /* copy from current values */ - float *data= do_ob_key(scene, ob); + float *data = do_ob_key(scene, ob); /* create new block with prepared data */ kb = add_keyblock_ctime(key, name, FALSE); - kb->totelem= BKE_nurbList_verts_count(lb); - kb->data= data; + kb->totelem = BKE_nurbList_verts_count(lb); + kb->data = data; } return kb; @@ -2970,7 +2970,7 @@ KeyBlock *BKE_object_insert_shape_key(Scene *scene, Object *ob, const char *name * cases false positives are hard to avoid (shape keys for example) */ int BKE_object_is_modified(Scene *scene, Object *ob) { - int flag= 0; + int flag = 0; if (ob_get_key(ob)) { flag |= eModifierMode_Render; @@ -2978,9 +2978,9 @@ int BKE_object_is_modified(Scene *scene, Object *ob) else { ModifierData *md; /* cloth */ - for (md=modifiers_getVirtualModifierList(ob); + for (md = modifiers_getVirtualModifierList(ob); md && (flag != (eModifierMode_Render | eModifierMode_Realtime)); - md=md->next) + md = md->next) { if ((flag & eModifierMode_Render) == 0 && modifier_isEnabled(scene, md, eModifierMode_Render)) flag |= eModifierMode_Render; @@ -2999,12 +2999,12 @@ int BKE_object_is_modified(Scene *scene, Object *ob) int BKE_object_is_deform_modified(Scene *scene, Object *ob) { ModifierData *md; - int flag= 0; + int flag = 0; /* cloth */ - for (md=modifiers_getVirtualModifierList(ob); - md && (flag != (eModifierMode_Render | eModifierMode_Realtime)); - md=md->next) + for (md = modifiers_getVirtualModifierList(ob); + md && (flag != (eModifierMode_Render | eModifierMode_Realtime)); + md = md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); @@ -3034,7 +3034,7 @@ void BKE_object_relink(Object *ob) relink_constraints(&ob->constraints); if (ob->pose) { bPoseChannel *chan; - for (chan = ob->pose->chanbase.first; chan; chan=chan->next) { + for (chan = ob->pose->chanbase.first; chan; chan = chan->next) { relink_constraints(&chan->constraints); } } @@ -3051,24 +3051,24 @@ void BKE_object_relink(Object *ob) MovieClip *BKE_object_movieclip_get(Scene *scene, Object *ob, int use_default) { - MovieClip *clip= use_default ? scene->clip : NULL; - bConstraint *con= ob->constraints.first, *scon= NULL; + MovieClip *clip = use_default ? scene->clip : NULL; + bConstraint *con = ob->constraints.first, *scon = NULL; while (con) { - if (con->type==CONSTRAINT_TYPE_CAMERASOLVER) { - if (scon==NULL || (scon->flag&CONSTRAINT_OFF)) - scon= con; + if (con->type == CONSTRAINT_TYPE_CAMERASOLVER) { + if (scon == NULL || (scon->flag & CONSTRAINT_OFF)) + scon = con; } - con= con->next; + con = con->next; } if (scon) { - bCameraSolverConstraint *solver= scon->data; - if ((solver->flag&CAMERASOLVER_ACTIVECLIP)==0) - clip= solver->clip; + bCameraSolverConstraint *solver = scon->data; + if ((solver->flag & CAMERASOLVER_ACTIVECLIP) == 0) + clip = solver->clip; else - clip= scene->clip; + clip = scene->clip; } return clip; diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 2a8a4ebc34b..a254e892289 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -84,35 +84,35 @@ #include "RE_render_ext.h" static void get_child_modifier_parameters(ParticleSettings *part, ParticleThreadContext *ctx, - ChildParticle *cpa, short cpa_from, int cpa_num, float *cpa_fuv, float *orco, ParticleTexture *ptex); + ChildParticle *cpa, short cpa_from, int cpa_num, float *cpa_fuv, float *orco, ParticleTexture *ptex); static void do_child_modifiers(ParticleSimulationData *sim, - ParticleTexture *ptex, ParticleKey *par, float *par_rot, ChildParticle *cpa, - float *orco, float mat[4][4], ParticleKey *state, float t); + ParticleTexture *ptex, ParticleKey *par, float *par_rot, ChildParticle *cpa, + float *orco, float mat[4][4], ParticleKey *state, float t); /* few helpers for countall etc. */ int count_particles(ParticleSystem *psys) { - ParticleSettings *part=psys->part; + ParticleSettings *part = psys->part; PARTICLE_P; - int tot=0; + int tot = 0; LOOP_SHOWN_PARTICLES { - if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN)==0); - else if (pa->alive == PARS_DEAD && (part->flag & PART_DIED)==0); + if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN) == 0) ; + else if (pa->alive == PARS_DEAD && (part->flag & PART_DIED) == 0) ; else tot++; } return tot; } int count_particles_mod(ParticleSystem *psys, int totgr, int cur) { - ParticleSettings *part=psys->part; + ParticleSettings *part = psys->part; PARTICLE_P; - int tot=0; + int tot = 0; LOOP_SHOWN_PARTICLES { - if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN)==0); - else if (pa->alive == PARS_DEAD && (part->flag & PART_DIED)==0); - else if (p%totgr==cur) tot++; + if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN) == 0) ; + else if (pa->alive == PARS_DEAD && (part->flag & PART_DIED) == 0) ; + else if (p % totgr == cur) tot++; } return tot; } @@ -127,17 +127,17 @@ static ParticleCacheKey **psys_alloc_path_cache_buffers(ListBase *bufs, int tot, ParticleCacheKey **cache; int i, totkey, totbufkey; - tot= MAX2(tot, 1); + tot = MAX2(tot, 1); totkey = 0; - cache = MEM_callocN(tot*sizeof(void*), "PathCacheArray"); + cache = MEM_callocN(tot * sizeof(void *), "PathCacheArray"); while (totkey < tot) { - totbufkey= MIN2(tot-totkey, PATH_CACHE_BUF_SIZE); - buf= MEM_callocN(sizeof(LinkData), "PathCacheLinkData"); - buf->data= MEM_callocN(sizeof(ParticleCacheKey)*totbufkey*steps, "ParticleCacheKey"); + totbufkey = MIN2(tot - totkey, PATH_CACHE_BUF_SIZE); + buf = MEM_callocN(sizeof(LinkData), "PathCacheLinkData"); + buf->data = MEM_callocN(sizeof(ParticleCacheKey) * totbufkey * steps, "ParticleCacheKey"); - for (i=0; i<totbufkey; i++) - cache[totkey+i] = ((ParticleCacheKey*)buf->data) + i*steps; + for (i = 0; i < totbufkey; i++) + cache[totkey + i] = ((ParticleCacheKey *)buf->data) + i * steps; totkey += totbufkey; BLI_addtail(bufs, buf); @@ -153,7 +153,7 @@ static void psys_free_path_cache_buffers(ParticleCacheKey **cache, ListBase *buf if (cache) MEM_freeN(cache); - for (buf= bufs->first; buf; buf=buf->next) + for (buf = bufs->first; buf; buf = buf->next) MEM_freeN(buf->data); BLI_freelistN(bufs); } @@ -165,9 +165,9 @@ static void psys_free_path_cache_buffers(ParticleCacheKey **cache, ListBase *buf ParticleSystem *psys_get_current(Object *ob) { ParticleSystem *psys; - if (ob==NULL) return NULL; + if (ob == NULL) return NULL; - for (psys=ob->particlesystem.first; psys; psys=psys->next) { + for (psys = ob->particlesystem.first; psys; psys = psys->next) { if (psys->flag & PSYS_CURRENT) return psys; } @@ -179,9 +179,9 @@ short psys_get_current_num(Object *ob) ParticleSystem *psys; short i; - if (ob==NULL) return 0; + if (ob == NULL) return 0; - for (psys=ob->particlesystem.first, i=0; psys; psys=psys->next, i++) + for (psys = ob->particlesystem.first, i = 0; psys; psys = psys->next, i++) if (psys->flag & PSYS_CURRENT) return i; @@ -192,9 +192,9 @@ void psys_set_current_num(Object *ob, int index) ParticleSystem *psys; short i; - if (ob==NULL) return; + if (ob == NULL) return; - for (psys=ob->particlesystem.first, i=0; psys; psys=psys->next, i++) { + for (psys = ob->particlesystem.first, i = 0; psys; psys = psys->next, i++) { if (i == index) psys->flag |= PSYS_CURRENT; else @@ -209,7 +209,7 @@ Object *psys_find_object(Scene *scene, ParticleSystem *psys) ParticleSystem *tpsys; for (base = scene->base.first; base; base = base->next) { - for (tpsys = base->object->particlesystem.first; psys; psys=psys->next) { + for (tpsys = base->object->particlesystem.first; psys; psys = psys->next) { if (tpsys == psys) return base->object; } @@ -221,16 +221,16 @@ Object *psys_find_object(Scene *scene, ParticleSystem *psys) Object *psys_get_lattice(ParticleSimulationData *sim) { - Object *lattice=NULL; + Object *lattice = NULL; - if (psys_in_edit_mode(sim->scene, sim->psys)==0) { + if (psys_in_edit_mode(sim->scene, sim->psys) == 0) { - ModifierData *md = (ModifierData*)psys_get_modifier(sim->ob, sim->psys); + ModifierData *md = (ModifierData *)psys_get_modifier(sim->ob, sim->psys); - for (; md; md=md->next) { - if (md->type==eModifierType_Lattice) { + for (; md; md = md->next) { + if (md->type == eModifierType_Lattice) { LatticeModifierData *lmd = (LatticeModifierData *)md; - lattice=lmd->object; + lattice = lmd->object; break; } } @@ -242,21 +242,21 @@ Object *psys_get_lattice(ParticleSimulationData *sim) } void psys_disable_all(Object *ob) { - ParticleSystem *psys=ob->particlesystem.first; + ParticleSystem *psys = ob->particlesystem.first; - for (; psys; psys=psys->next) + for (; psys; psys = psys->next) psys->flag |= PSYS_DISABLED; } void psys_enable_all(Object *ob) { - ParticleSystem *psys=ob->particlesystem.first; + ParticleSystem *psys = ob->particlesystem.first; - for (; psys; psys=psys->next) + for (; psys; psys = psys->next) psys->flag &= ~PSYS_DISABLED; } int psys_in_edit_mode(Scene *scene, ParticleSystem *psys) { - return (scene->basact && (scene->basact->object->mode & OB_MODE_PARTICLE_EDIT) && psys==psys_get_current((scene->basact)->object) && (psys->edit || psys->pointcache->edit) && !psys->renderdata); + return (scene->basact && (scene->basact->object->mode & OB_MODE_PARTICLE_EDIT) && psys == psys_get_current((scene->basact)->object) && (psys->edit || psys->pointcache->edit) && !psys->renderdata); } static void psys_create_frand(ParticleSystem *psys) { @@ -265,7 +265,7 @@ static void psys_create_frand(ParticleSystem *psys) BLI_srandom(psys->seed); - for (i=0; i<1024; i++, rand++) + for (i = 0; i < 1024; i++, rand++) *rand = BLI_frand(); } int psys_check_enabled(Object *ob, ParticleSystem *psys) @@ -275,7 +275,7 @@ int psys_check_enabled(Object *ob, ParticleSystem *psys) if (psys->flag & PSYS_DISABLED || psys->flag & PSYS_DELETE || !psys->part) return 0; - psmd= psys_get_modifier(ob, psys); + psmd = psys_get_modifier(ob, psys); if (psys->renderdata || G.rendering) { if (!(psmd->modifier.mode & eModifierMode_Render)) return 0; @@ -296,7 +296,7 @@ int psys_check_enabled(Object *ob, ParticleSystem *psys) int psys_check_edited(ParticleSystem *psys) { - if (psys->part && psys->part->type==PART_HAIR) + if (psys->part && psys->part->type == PART_HAIR) return (psys->flag & PSYS_EDITED || (psys->edit && psys->edit->edited)); else return (psys->pointcache->edit && psys->pointcache->edit->edited); @@ -339,7 +339,7 @@ void psys_check_group_weights(ParticleSettings *part) } dw = part->dupliweights.first; - for (; dw; dw=dw->next) { + for (; dw; dw = dw->next) { if (dw->flag & PART_DUPLIW_CURRENT) { current = 1; break; @@ -385,8 +385,8 @@ void BKE_particlesettings_free(ParticleSettings *part) boid_free_settings(part->boids); fluid_free_settings(part->fluid); - for (a=0; a<MAX_MTEX; a++) { - mtex= part->mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = part->mtex[a]; if (mtex && mtex->tex) mtex->tex->id.us--; if (mtex) MEM_freeN(mtex); } @@ -411,7 +411,7 @@ void free_hair(Object *UNUSED(ob), ParticleSystem *psys, int dynamics) psys->clmd->point_cache = psys->pointcache = NULL; psys->clmd->ptcaches.first = psys->clmd->ptcaches.last = NULL; - modifier_free((ModifierData*)psys->clmd); + modifier_free((ModifierData *)psys->clmd); psys->clmd = NULL; psys->pointcache = BKE_ptcache_add(&psys->ptcaches); @@ -441,8 +441,8 @@ void free_keyed_keys(ParticleSystem *psys) LOOP_PARTICLES { if (pa->keys) { - pa->keys= NULL; - pa->totkey= 0; + pa->keys = NULL; + pa->totkey = 0; } } } @@ -457,13 +457,13 @@ void psys_free_path_cache(ParticleSystem *psys, PTCacheEdit *edit) { if (edit) { psys_free_path_cache_buffers(edit->pathcache, &edit->pathcachebufs); - edit->pathcache= NULL; - edit->totcached= 0; + edit->pathcache = NULL; + edit->totcached = 0; } if (psys) { psys_free_path_cache_buffers(psys->pathcache, &psys->pathcachebufs); - psys->pathcache= NULL; - psys->totcached= 0; + psys->pathcache = NULL; + psys->totcached = 0; free_child_path_cache(psys); } @@ -472,8 +472,8 @@ void psys_free_children(ParticleSystem *psys) { if (psys->child) { MEM_freeN(psys->child); - psys->child= NULL; - psys->totchild=0; + psys->child = NULL; + psys->totchild = 0; } free_child_path_cache(psys); @@ -483,7 +483,7 @@ void psys_free_particles(ParticleSystem *psys) PARTICLE_P; if (psys->particles) { - if (psys->part->type==PART_HAIR) { + if (psys->part->type == PART_HAIR) { LOOP_PARTICLES { if (pa->hair) MEM_freeN(pa->hair); @@ -497,8 +497,8 @@ void psys_free_particles(ParticleSystem *psys) MEM_freeN(psys->particles->boid); MEM_freeN(psys->particles); - psys->particles= NULL; - psys->totpart= 0; + psys->particles = NULL; + psys->totpart = 0; } } void psys_free_pdd(ParticleSystem *psys) @@ -525,11 +525,11 @@ void psys_free_pdd(ParticleSystem *psys) } } /* free everything */ -void psys_free(Object *ob, ParticleSystem * psys) +void psys_free(Object *ob, ParticleSystem *psys) { if (psys) { int nr = 0; - ParticleSystem * tpsys; + ParticleSystem *tpsys; psys_free_path_cache(psys, NULL); @@ -547,7 +547,7 @@ void psys_free(Object *ob, ParticleSystem * psys) } // check if we are last non-visible particle system - for (tpsys=ob->particlesystem.first; tpsys; tpsys=tpsys->next) { + for (tpsys = ob->particlesystem.first; tpsys; tpsys = tpsys->next) { if (tpsys->part) { if (ELEM(tpsys->part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) { nr++; @@ -561,7 +561,7 @@ void psys_free(Object *ob, ParticleSystem * psys) if (psys->part) { psys->part->id.us--; - psys->part=NULL; + psys->part = NULL; } BKE_ptcache_free_list(&psys->ptcaches); @@ -622,17 +622,17 @@ typedef struct ParticleRenderData { static float psys_render_viewport_falloff(double rate, float dist, float width) { - return pow(rate, dist/width); + return pow(rate, dist / width); } static float psys_render_projected_area(ParticleSystem *psys, const float center[3], float area, double vprate, float *viewport) { - ParticleRenderData *data= psys->renderdata; + ParticleRenderData *data = psys->renderdata; float co[4], view[3], ortho1[3], ortho2[3], w, dx, dy, radius; /* transform to view space */ copy_v3_v3(co, center); - co[3]= 1.0f; + co[3] = 1.0f; mul_m4_v4(data->viewmat, co); /* compute two vectors orthogonal to view vector */ @@ -640,87 +640,87 @@ static float psys_render_projected_area(ParticleSystem *psys, const float center ortho_basis_v3v3_v3(ortho1, ortho2, view); /* compute on screen minification */ - w= co[2]*data->winmat[2][3] + data->winmat[3][3]; - dx= data->winx*ortho2[0]*data->winmat[0][0]; - dy= data->winy*ortho2[1]*data->winmat[1][1]; - w= sqrtf(dx*dx + dy*dy)/w; + w = co[2] * data->winmat[2][3] + data->winmat[3][3]; + dx = data->winx * ortho2[0] * data->winmat[0][0]; + dy = data->winy * ortho2[1] * data->winmat[1][1]; + w = sqrtf(dx * dx + dy * dy) / w; /* w squared because we are working with area */ - area= area*w*w; + area = area * w * w; /* viewport of the screen test */ /* project point on screen */ mul_m4_v4(data->winmat, co); if (co[3] != 0.0f) { - co[0]= 0.5f*data->winx*(1.0f + co[0]/co[3]); - co[1]= 0.5f*data->winy*(1.0f + co[1]/co[3]); + co[0] = 0.5f * data->winx * (1.0f + co[0] / co[3]); + co[1] = 0.5f * data->winy * (1.0f + co[1] / co[3]); } /* screen space radius */ - radius= sqrt(area/(float)M_PI); + radius = sqrt(area / (float)M_PI); /* make smaller using fallof once over screen edge */ - *viewport= 1.0f; + *viewport = 1.0f; - if (co[0]+radius < 0.0f) - *viewport *= psys_render_viewport_falloff(vprate, -(co[0]+radius), data->winx); - else if (co[0]-radius > data->winx) - *viewport *= psys_render_viewport_falloff(vprate, (co[0]-radius) - data->winx, data->winx); + if (co[0] + radius < 0.0f) + *viewport *= psys_render_viewport_falloff(vprate, -(co[0] + radius), data->winx); + else if (co[0] - radius > data->winx) + *viewport *= psys_render_viewport_falloff(vprate, (co[0] - radius) - data->winx, data->winx); - if (co[1]+radius < 0.0f) - *viewport *= psys_render_viewport_falloff(vprate, -(co[1]+radius), data->winy); - else if (co[1]-radius > data->winy) - *viewport *= psys_render_viewport_falloff(vprate, (co[1]-radius) - data->winy, data->winy); + if (co[1] + radius < 0.0f) + *viewport *= psys_render_viewport_falloff(vprate, -(co[1] + radius), data->winy); + else if (co[1] - radius > data->winy) + *viewport *= psys_render_viewport_falloff(vprate, (co[1] - radius) - data->winy, data->winy); return area; } void psys_render_set(Object *ob, ParticleSystem *psys, float viewmat[][4], float winmat[][4], int winx, int winy, int timeoffset) { - ParticleRenderData*data; - ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys); + ParticleRenderData *data; + ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); if (!G.rendering) return; if (psys->renderdata) return; - data= MEM_callocN(sizeof(ParticleRenderData), "ParticleRenderData"); + data = MEM_callocN(sizeof(ParticleRenderData), "ParticleRenderData"); - data->child= psys->child; - data->totchild= psys->totchild; - data->pathcache= psys->pathcache; + data->child = psys->child; + data->totchild = psys->totchild; + data->pathcache = psys->pathcache; data->pathcachebufs.first = psys->pathcachebufs.first; data->pathcachebufs.last = psys->pathcachebufs.last; - data->totcached= psys->totcached; - data->childcache= psys->childcache; + data->totcached = psys->totcached; + data->childcache = psys->childcache; data->childcachebufs.first = psys->childcachebufs.first; data->childcachebufs.last = psys->childcachebufs.last; - data->totchildcache= psys->totchildcache; + data->totchildcache = psys->totchildcache; if (psmd->dm) - data->dm= CDDM_copy(psmd->dm); - data->totdmvert= psmd->totdmvert; - data->totdmedge= psmd->totdmedge; - data->totdmface= psmd->totdmface; - - psys->child= NULL; - psys->pathcache= NULL; - psys->childcache= NULL; - psys->totchild= psys->totcached= psys->totchildcache= 0; + data->dm = CDDM_copy(psmd->dm); + data->totdmvert = psmd->totdmvert; + data->totdmedge = psmd->totdmedge; + data->totdmface = psmd->totdmface; + + psys->child = NULL; + psys->pathcache = NULL; + psys->childcache = NULL; + psys->totchild = psys->totcached = psys->totchildcache = 0; psys->pathcachebufs.first = psys->pathcachebufs.last = NULL; psys->childcachebufs.first = psys->childcachebufs.last = NULL; copy_m4_m4(data->winmat, winmat); mult_m4_m4m4(data->viewmat, viewmat, ob->obmat); mult_m4_m4m4(data->mat, winmat, data->viewmat); - data->winx= winx; - data->winy= winy; + data->winx = winx; + data->winy = winy; - data->timeoffset= timeoffset; + data->timeoffset = timeoffset; - psys->renderdata= data; + psys->renderdata = data; /* Hair can and has to be recalculated if everything isn't displayed. */ if (psys->part->disp != 100 && psys->part->type == PART_HAIR) @@ -729,10 +729,10 @@ void psys_render_set(Object *ob, ParticleSystem *psys, float viewmat[][4], float void psys_render_restore(Object *ob, ParticleSystem *psys) { - ParticleRenderData*data; - ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys); + ParticleRenderData *data; + ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); - data= psys->renderdata; + data = psys->renderdata; if (!data) return; @@ -740,7 +740,7 @@ void psys_render_restore(Object *ob, ParticleSystem *psys) MEM_freeN(data->elems); if (psmd->dm) { - psmd->dm->needsFree= 1; + psmd->dm->needsFree = 1; psmd->dm->release(psmd->dm); } @@ -748,93 +748,93 @@ void psys_render_restore(Object *ob, ParticleSystem *psys) if (psys->child) { MEM_freeN(psys->child); - psys->child= 0; - psys->totchild= 0; + psys->child = 0; + psys->totchild = 0; } - psys->child= data->child; - psys->totchild= data->totchild; - psys->pathcache= data->pathcache; + psys->child = data->child; + psys->totchild = data->totchild; + psys->pathcache = data->pathcache; psys->pathcachebufs.first = data->pathcachebufs.first; psys->pathcachebufs.last = data->pathcachebufs.last; - psys->totcached= data->totcached; - psys->childcache= data->childcache; + psys->totcached = data->totcached; + psys->childcache = data->childcache; psys->childcachebufs.first = data->childcachebufs.first; psys->childcachebufs.last = data->childcachebufs.last; - psys->totchildcache= data->totchildcache; + psys->totchildcache = data->totchildcache; - psmd->dm= data->dm; - psmd->totdmvert= data->totdmvert; - psmd->totdmedge= data->totdmedge; - psmd->totdmface= data->totdmface; + psmd->dm = data->dm; + psmd->totdmvert = data->totdmvert; + psmd->totdmedge = data->totdmedge; + psmd->totdmface = data->totdmface; psmd->flag &= ~eParticleSystemFlag_psys_updated; if (psmd->dm) psys_calc_dmcache(ob, psmd->dm, psys); MEM_freeN(data); - psys->renderdata= NULL; + psys->renderdata = NULL; } /* BMESH_TODO, for orig face data, we need to use MPoly */ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) { - DerivedMesh *dm= ctx->dm; - Mesh *me= (Mesh*)(ctx->sim.ob->data); + DerivedMesh *dm = ctx->dm; + Mesh *me = (Mesh *)(ctx->sim.ob->data); MFace *mf, *mface; MVert *mvert; ParticleRenderData *data; ParticleRenderElem *elems, *elem; - ParticleSettings *part= ctx->sim.psys->part; + ParticleSettings *part = ctx->sim.psys->part; float *facearea, (*facecenter)[3], size[3], fac, powrate, scaleclamp; float co1[3], co2[3], co3[3], co4[3], lambda, arearatio, t, area, viewport; double vprate; int *origindex, *facetotvert; int a, b, totorigface, totface, newtot, skipped; - if (part->ren_as!=PART_DRAW_PATH || !(part->draw & PART_DRAW_REN_STRAND)) + if (part->ren_as != PART_DRAW_PATH || !(part->draw & PART_DRAW_REN_STRAND)) return tot; if (!ctx->sim.psys->renderdata) return tot; - data= ctx->sim.psys->renderdata; + data = ctx->sim.psys->renderdata; if (data->timeoffset) return 0; if (!(part->simplify_flag & PART_SIMPLIFY_ENABLE)) return tot; - mvert= dm->getVertArray(dm); - mface= dm->getTessFaceArray(dm); - origindex= dm->getTessFaceDataArray(dm, CD_ORIGINDEX); - totface= dm->getNumTessFaces(dm); - totorigface= me->totpoly; + mvert = dm->getVertArray(dm); + mface = dm->getTessFaceArray(dm); + origindex = dm->getTessFaceDataArray(dm, CD_ORIGINDEX); + totface = dm->getNumTessFaces(dm); + totorigface = me->totpoly; if (totface == 0 || totorigface == 0) return tot; - facearea= MEM_callocN(sizeof(float)*totorigface, "SimplifyFaceArea"); - facecenter= MEM_callocN(sizeof(float[3])*totorigface, "SimplifyFaceCenter"); - facetotvert= MEM_callocN(sizeof(int)*totorigface, "SimplifyFaceArea"); - elems= MEM_callocN(sizeof(ParticleRenderElem)*totorigface, "SimplifyFaceElem"); + facearea = MEM_callocN(sizeof(float) * totorigface, "SimplifyFaceArea"); + facecenter = MEM_callocN(sizeof(float[3]) * totorigface, "SimplifyFaceCenter"); + facetotvert = MEM_callocN(sizeof(int) * totorigface, "SimplifyFaceArea"); + elems = MEM_callocN(sizeof(ParticleRenderElem) * totorigface, "SimplifyFaceElem"); if (data->elems) MEM_freeN(data->elems); - data->dosimplify= 1; - data->elems= elems; - data->origindex= origindex; + data->dosimplify = 1; + data->elems = elems; + data->origindex = origindex; /* compute number of children per original face */ - for (a=0; a<tot; a++) { - b= (origindex)? origindex[ctx->index[a]]: ctx->index[a]; + for (a = 0; a < tot; a++) { + b = (origindex) ? origindex[ctx->index[a]] : ctx->index[a]; if (b != -1) elems[b].totchild++; } /* compute areas and centers of original faces */ - for (mf=mface, a=0; a<totface; a++, mf++) { - b= (origindex)? origindex[a]: a; + for (mf = mface, a = 0; a < totface; a++, mf++) { + b = (origindex) ? origindex[a] : a; if (b != -1) { copy_v3_v3(co1, mvert[mf->v1].co); @@ -858,67 +858,67 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) } } - for (a=0; a<totorigface; a++) + for (a = 0; a < totorigface; a++) if (facetotvert[a] > 0) - mul_v3_fl(facecenter[a], 1.0f/facetotvert[a]); + mul_v3_fl(facecenter[a], 1.0f / facetotvert[a]); /* for conversion from BU area / pixel area to reference screen size */ BKE_mesh_texspace_get(me, 0, 0, size); - fac= ((size[0] + size[1] + size[2])/3.0f)/part->simplify_refsize; - fac= fac*fac; + fac = ((size[0] + size[1] + size[2]) / 3.0f) / part->simplify_refsize; + fac = fac * fac; - powrate= log(0.5f)/log(part->simplify_rate*0.5f); + powrate = log(0.5f) / log(part->simplify_rate * 0.5f); if (part->simplify_flag & PART_SIMPLIFY_VIEWPORT) - vprate= pow(1.0f - part->simplify_viewport, 5.0); + vprate = pow(1.0f - part->simplify_viewport, 5.0); else - vprate= 1.0; + vprate = 1.0; /* set simplification parameters per original face */ - for (a=0, elem=elems; a<totorigface; a++, elem++) { + for (a = 0, elem = elems; a < totorigface; a++, elem++) { area = psys_render_projected_area(ctx->sim.psys, facecenter[a], facearea[a], vprate, &viewport); - arearatio= fac*area/facearea[a]; + arearatio = fac * area / facearea[a]; if ((arearatio < 1.0f || viewport < 1.0f) && elem->totchild) { /* lambda is percentage of elements to keep */ - lambda= (arearatio < 1.0f)? powf(arearatio, powrate): 1.0f; + lambda = (arearatio < 1.0f) ? powf(arearatio, powrate) : 1.0f; lambda *= viewport; - lambda= MAX2(lambda, 1.0f/elem->totchild); + lambda = MAX2(lambda, 1.0f / elem->totchild); /* compute transition region */ - t= part->simplify_transition; - elem->t= (lambda-t < 0.0f)? lambda: (lambda+t > 1.0f)? 1.0f-lambda: t; - elem->reduce= 1; + t = part->simplify_transition; + elem->t = (lambda - t < 0.0f) ? lambda : (lambda + t > 1.0f) ? 1.0f - lambda : t; + elem->reduce = 1; /* scale at end and beginning of the transition region */ - elem->scalemax= (lambda+t < 1.0f)? 1.0f/lambda: 1.0f/(1.0f - elem->t*elem->t/t); - elem->scalemin= (lambda+t < 1.0f)? 0.0f: elem->scalemax*(1.0f-elem->t/t); + elem->scalemax = (lambda + t < 1.0f) ? 1.0f / lambda : 1.0f / (1.0f - elem->t * elem->t / t); + elem->scalemin = (lambda + t < 1.0f) ? 0.0f : elem->scalemax * (1.0f - elem->t / t); - elem->scalemin= sqrt(elem->scalemin); - elem->scalemax= sqrt(elem->scalemax); + elem->scalemin = sqrt(elem->scalemin); + elem->scalemax = sqrt(elem->scalemax); /* clamp scaling */ - scaleclamp= MIN2(elem->totchild, 10.0f); - elem->scalemin= MIN2(scaleclamp, elem->scalemin); - elem->scalemax= MIN2(scaleclamp, elem->scalemax); + scaleclamp = MIN2(elem->totchild, 10.0f); + elem->scalemin = MIN2(scaleclamp, elem->scalemin); + elem->scalemax = MIN2(scaleclamp, elem->scalemax); /* extend lambda to include transition */ - lambda= lambda + elem->t; + lambda = lambda + elem->t; if (lambda > 1.0f) - lambda= 1.0f; + lambda = 1.0f; } else { - lambda= arearatio; + lambda = arearatio; - elem->scalemax= 1.0f; //sqrt(lambda); - elem->scalemin= 1.0f; //sqrt(lambda); - elem->reduce= 0; + elem->scalemax = 1.0f; //sqrt(lambda); + elem->scalemin = 1.0f; //sqrt(lambda); + elem->reduce = 0; } - elem->lambda= lambda; - elem->scalemin= sqrt(elem->scalemin); - elem->scalemax= sqrt(elem->scalemax); - elem->curchild= 0; + elem->lambda = lambda; + elem->scalemin = sqrt(elem->scalemin); + elem->scalemax = sqrt(elem->scalemax); + elem->curchild = 0; } MEM_freeN(facearea); @@ -926,16 +926,16 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) MEM_freeN(facetotvert); /* move indices and set random number skipping */ - ctx->skip= MEM_callocN(sizeof(int)*tot, "SimplificationSkip"); + ctx->skip = MEM_callocN(sizeof(int) * tot, "SimplificationSkip"); - skipped= 0; - for (a=0, newtot=0; a<tot; a++) { - b= (origindex)? origindex[ctx->index[a]]: ctx->index[a]; + skipped = 0; + for (a = 0, newtot = 0; a < tot; a++) { + b = (origindex) ? origindex[ctx->index[a]] : ctx->index[a]; if (b != -1) { - if (elems[b].curchild++ < ceil(elems[b].lambda*elems[b].totchild)) { - ctx->index[newtot]= ctx->index[a]; - ctx->skip[newtot]= skipped; - skipped= 0; + if (elems[b].curchild++ < ceil(elems[b].lambda * elems[b].totchild)) { + ctx->index[newtot] = ctx->index[a]; + ctx->skip[newtot] = skipped; + skipped = 0; newtot++; } else skipped++; @@ -943,8 +943,8 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) else skipped++; } - for (a=0, elem=elems; a<totorigface; a++, elem++) - elem->curchild= 0; + for (a = 0, elem = elems; a < totorigface; a++, elem++) + elem->curchild = 0; return newtot; } @@ -959,44 +959,44 @@ int psys_render_simplify_params(ParticleSystem *psys, ChildParticle *cpa, float if (!(psys->renderdata && (psys->part->simplify_flag & PART_SIMPLIFY_ENABLE))) return 0; - data= psys->renderdata; + data = psys->renderdata; if (!data->dosimplify) return 0; - b= (data->origindex)? data->origindex[cpa->num]: cpa->num; + b = (data->origindex) ? data->origindex[cpa->num] : cpa->num; if (b == -1) return 0; - elem= &data->elems[b]; + elem = &data->elems[b]; - lambda= elem->lambda; - t= elem->t; - scalemin= elem->scalemin; - scalemax= elem->scalemax; + lambda = elem->lambda; + t = elem->t; + scalemin = elem->scalemin; + scalemax = elem->scalemax; if (!elem->reduce) { - scale= scalemin; - alpha= 1.0f; + scale = scalemin; + alpha = 1.0f; } else { - x= (elem->curchild+0.5f)/elem->totchild; - if (x < lambda-t) { - scale= scalemax; - alpha= 1.0f; + x = (elem->curchild + 0.5f) / elem->totchild; + if (x < lambda - t) { + scale = scalemax; + alpha = 1.0f; } - else if (x >= lambda+t) { - scale= scalemin; - alpha= 0.0f; + else if (x >= lambda + t) { + scale = scalemin; + alpha = 0.0f; } else { - w= (lambda+t - x)/(2.0f*t); - scale= scalemin + (scalemax - scalemin)*w; - alpha= w; + w = (lambda + t - x) / (2.0f * t); + scale = scalemin + (scalemax - scalemin) * w; + alpha = w; } } - params[0]= scale; - params[1]= alpha; + params[0] = scale; + params[1] = alpha; elem->curchild++; @@ -1010,9 +1010,9 @@ static float interpolate_particle_value(float v1, float v2, float v3, float v4, { float value; - value= w[0]*v1 + w[1]*v2 + w[2]*v3; + value = w[0] * v1 + w[1] * v2 + w[2] * v3; if (four) - value += w[3]*v4; + value += w[3] * v4; CLAMP(value, 0.f, 1.f); @@ -1023,7 +1023,7 @@ void psys_interpolate_particle(short type, ParticleKey keys[4], float dt, Partic { float t[4]; - if (type<0) { + if (type < 0) { interp_cubic_v3(result->co, result->vel, keys[1].co, keys[1].vel, keys[2].co, keys[2].vel, dt); } else { @@ -1034,13 +1034,13 @@ void psys_interpolate_particle(short type, ParticleKey keys[4], float dt, Partic if (velocity) { float temp[3]; - if (dt>0.999f) { - key_curve_position_weights(dt-0.001f, t, type); + if (dt > 0.999f) { + key_curve_position_weights(dt - 0.001f, t, type); interp_v3_v3v3v3v3(temp, keys[0].co, keys[1].co, keys[2].co, keys[3].co, t); sub_v3_v3v3(result->vel, result->co, temp); } else { - key_curve_position_weights(dt+0.001f, t, type); + key_curve_position_weights(dt + 0.001f, t, type); interp_v3_v3v3v3v3(temp, keys[0].co, keys[1].co, keys[2].co, keys[3].co, t); sub_v3_v3v3(result->vel, temp, result->co); } @@ -1110,7 +1110,7 @@ static int get_pointcache_times_for_particle(PointCache *cache, int index, float PTCacheMem *pm; int ret = 0; - for (pm=cache->mem_cache.first; pm; pm=pm->next) { + for (pm = cache->mem_cache.first; pm; pm = pm->next) { if (BKE_ptcache_mem_index_find(pm, index) >= 0) { *start = pm->frame; ret++; @@ -1118,7 +1118,7 @@ static int get_pointcache_times_for_particle(PointCache *cache, int index, float } } - for (pm=cache->mem_cache.last; pm; pm=pm->prev) { + for (pm = cache->mem_cache.last; pm; pm = pm->prev) { if (BKE_ptcache_mem_index_find(pm, index) >= 0) { *end = pm->frame; ret++; @@ -1134,7 +1134,7 @@ float psys_get_dietime_from_cache(PointCache *cache, int index) PTCacheMem *pm; int dietime = 10000000; /* some max value so that we can default to pa->time+lifetime */ - for (pm=cache->mem_cache.last; pm; pm=pm->prev) { + for (pm = cache->mem_cache.last; pm; pm = pm->prev) { if (BKE_ptcache_mem_index_find(pm, index) >= 0) return (float)pm->frame; } @@ -1163,7 +1163,7 @@ static void init_particle_interpolation(Object *ob, ParticleSystem *psys, Partic pind->dietime = (key + pa->totkey - 1)->time; } else if (pind->cache) { - float start=0.0f, end=0.0f; + float start = 0.0f, end = 0.0f; get_pointcache_keys_for_time(ob, pind->cache, &pind->pm, -1, 0.0f, NULL, NULL); pind->birthtime = pa ? pa->time : pind->cache->startframe; pind->dietime = pa ? pa->dietime : pind->cache->endframe; @@ -1222,7 +1222,7 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData if (result->time < 0.0f) real_t = -result->time; else - real_t = *(pind->ekey[0]->time) + t * (*(pind->ekey[0][point->totkey-1].time) - *(pind->ekey[0]->time)); + real_t = *(pind->ekey[0]->time) + t * (*(pind->ekey[0][point->totkey - 1].time) - *(pind->ekey[0]->time)); while (*(pind->ekey[1]->time) < real_t) pind->ekey[1]++; @@ -1231,7 +1231,7 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData } else if (pind->keyed) { /* we have only one key, so let's use that */ - if (pind->kkey[1]==NULL) { + if (pind->kkey[1] == NULL) { copy_particle_key(result, pind->kkey[0], 1); return; } @@ -1239,24 +1239,24 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData if (result->time < 0.0f) real_t = -result->time; else - real_t = pind->kkey[0]->time + t * (pind->kkey[0][pa->totkey-1].time - pind->kkey[0]->time); + real_t = pind->kkey[0]->time + t * (pind->kkey[0][pa->totkey - 1].time - pind->kkey[0]->time); - if (psys->part->phystype==PART_PHYS_KEYED && psys->flag & PSYS_KEYED_TIMING) { + if (psys->part->phystype == PART_PHYS_KEYED && psys->flag & PSYS_KEYED_TIMING) { ParticleTarget *pt = psys->targets.first; - pt=pt->next; + pt = pt->next; while (pt && pa->time + pt->time < real_t) - pt= pt->next; + pt = pt->next; if (pt) { - pt=pt->prev; + pt = pt->prev; if (pa->time + pt->time + pt->duration > real_t) real_t = pa->time + pt->time; } else - real_t = pa->time + ((ParticleTarget*)psys->targets.last)->time; + real_t = pa->time + ((ParticleTarget *)psys->targets.last)->time; } CLAMP(real_t, pa->time, pa->dietime); @@ -1276,7 +1276,7 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData if (result->time < 0.0f) real_t = -result->time; else - real_t = pind->hkey[0]->time + t * (pind->hkey[0][pa->totkey-1].time - pind->hkey[0]->time); + real_t = pind->hkey[0]->time + t * (pind->hkey[0][pa->totkey - 1].time - pind->hkey[0]->time); while (pind->hkey[1]->time < real_t) { pind->hkey[1]++; @@ -1301,7 +1301,7 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData memcpy(keys + 2, pind->kkey[1], sizeof(ParticleKey)); } else if (pind->cache) { - get_pointcache_keys_for_time(NULL, pind->cache, &pind->pm, p, real_t, keys+1, keys+2); + get_pointcache_keys_for_time(NULL, pind->cache, &pind->pm, p, real_t, keys + 1, keys + 2); } else { hair_to_particle(keys + 1, pind->hkey[0]); @@ -1362,37 +1362,37 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData /* now we should have in chronologiacl order k1<=k2<=t<=k3<=k4 with keytime between [0, 1]->[k2, k3] (k1 & k4 used for cardinal & bspline interpolation)*/ psys_interpolate_particle((pind->keyed || pind->cache || point_vel) ? -1 /* signal for cubic interpolation */ - : (pind->bspline ? KEY_BSPLINE : KEY_CARDINAL), - keys, keytime, result, 1); + : (pind->bspline ? KEY_BSPLINE : KEY_CARDINAL), + keys, keytime, result, 1); /* the velocity needs to be converted back from cubic interpolation */ if (pind->keyed || pind->cache || point_vel) - mul_v3_fl(result->vel, 1.f/invdt); + mul_v3_fl(result->vel, 1.f / invdt); } static void interpolate_pathcache(ParticleCacheKey *first, float t, ParticleCacheKey *result) { - int i=0; + int i = 0; ParticleCacheKey *cur = first; /* scale the requested time to fit the entire path even if the path is cut early */ - t *= (first+first->steps)->time; + t *= (first + first->steps)->time; - while (i<first->steps && cur->time < t) + while (i < first->steps && cur->time < t) cur++; if (cur->time == t) *result = *cur; else { - float dt = (t-(cur-1)->time)/(cur->time-(cur-1)->time); - interp_v3_v3v3(result->co, (cur-1)->co, cur->co, dt); - interp_v3_v3v3(result->vel, (cur-1)->vel, cur->vel, dt); - interp_qt_qtqt(result->rot, (cur-1)->rot, cur->rot, dt); + float dt = (t - (cur - 1)->time) / (cur->time - (cur - 1)->time); + interp_v3_v3v3(result->co, (cur - 1)->co, cur->co, dt); + interp_v3_v3v3(result->vel, (cur - 1)->vel, cur->vel, dt); + interp_qt_qtqt(result->rot, (cur - 1)->rot, cur->rot, dt); result->time = t; } /* first is actual base rotation, others are incremental from first */ - if (cur==first || cur-1==first) + if (cur == first || cur - 1 == first) copy_qt_qt(result->rot, first->rot); else mul_qt_qtqt(result->rot, first->rot, result->rot); @@ -1405,23 +1405,23 @@ static void interpolate_pathcache(ParticleCacheKey *first, float t, ParticleCach void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*orcodata)[3], float *w, float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor) { - float *v1=0, *v2=0, *v3=0, *v4=0; + float *v1 = 0, *v2 = 0, *v3 = 0, *v4 = 0; float e1[3], e2[3], s1, s2, t1, t2; float *uv1, *uv2, *uv3, *uv4; float n1[3], n2[3], n3[3], n4[3]; float tuv[4][2]; float *o1, *o2, *o3, *o4; - v1= mvert[mface->v1].co; - v2= mvert[mface->v2].co; - v3= mvert[mface->v3].co; + v1 = mvert[mface->v1].co; + v2 = mvert[mface->v2].co; + v3 = mvert[mface->v3].co; normal_short_to_float_v3(n1, mvert[mface->v1].no); normal_short_to_float_v3(n2, mvert[mface->v2].no); normal_short_to_float_v3(n3, mvert[mface->v3].no); if (mface->v4) { - v4= mvert[mface->v4].co; + v4 = mvert[mface->v4].co; normal_short_to_float_v3(n4, mvert[mface->v4].no); interp_v3_v3v3v3v3(vec, v1, v2, v3, v4, w); @@ -1447,58 +1447,58 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or /* calculate tangent vectors */ if (utan && vtan) { if (tface) { - uv1= tface->uv[0]; - uv2= tface->uv[1]; - uv3= tface->uv[2]; - uv4= tface->uv[3]; + uv1 = tface->uv[0]; + uv2 = tface->uv[1]; + uv3 = tface->uv[2]; + uv4 = tface->uv[3]; } else { - uv1= tuv[0]; uv2= tuv[1]; uv3= tuv[2]; uv4= tuv[3]; - map_to_sphere(uv1, uv1+1, v1[0], v1[1], v1[2]); - map_to_sphere(uv2, uv2+1, v2[0], v2[1], v2[2]); - map_to_sphere(uv3, uv3+1, v3[0], v3[1], v3[2]); + uv1 = tuv[0]; uv2 = tuv[1]; uv3 = tuv[2]; uv4 = tuv[3]; + map_to_sphere(uv1, uv1 + 1, v1[0], v1[1], v1[2]); + map_to_sphere(uv2, uv2 + 1, v2[0], v2[1], v2[2]); + map_to_sphere(uv3, uv3 + 1, v3[0], v3[1], v3[2]); if (v4) - map_to_sphere(uv4, uv4+1, v4[0], v4[1], v4[2]); + map_to_sphere(uv4, uv4 + 1, v4[0], v4[1], v4[2]); } if (v4) { - s1= uv3[0] - uv1[0]; - s2= uv4[0] - uv1[0]; + s1 = uv3[0] - uv1[0]; + s2 = uv4[0] - uv1[0]; - t1= uv3[1] - uv1[1]; - t2= uv4[1] - uv1[1]; + t1 = uv3[1] - uv1[1]; + t2 = uv4[1] - uv1[1]; sub_v3_v3v3(e1, v3, v1); sub_v3_v3v3(e2, v4, v1); } else { - s1= uv2[0] - uv1[0]; - s2= uv3[0] - uv1[0]; + s1 = uv2[0] - uv1[0]; + s2 = uv3[0] - uv1[0]; - t1= uv2[1] - uv1[1]; - t2= uv3[1] - uv1[1]; + t1 = uv2[1] - uv1[1]; + t2 = uv3[1] - uv1[1]; sub_v3_v3v3(e1, v2, v1); sub_v3_v3v3(e2, v3, v1); } - vtan[0] = (s1*e2[0] - s2*e1[0]); - vtan[1] = (s1*e2[1] - s2*e1[1]); - vtan[2] = (s1*e2[2] - s2*e1[2]); + vtan[0] = (s1 * e2[0] - s2 * e1[0]); + vtan[1] = (s1 * e2[1] - s2 * e1[1]); + vtan[2] = (s1 * e2[2] - s2 * e1[2]); - utan[0] = (t1*e2[0] - t2*e1[0]); - utan[1] = (t1*e2[1] - t2*e1[1]); - utan[2] = (t1*e2[2] - t2*e1[2]); + utan[0] = (t1 * e2[0] - t2 * e1[0]); + utan[1] = (t1 * e2[1] - t2 * e1[1]); + utan[2] = (t1 * e2[2] - t2 * e1[2]); } if (orco) { if (orcodata) { - o1= orcodata[mface->v1]; - o2= orcodata[mface->v2]; - o3= orcodata[mface->v3]; + o1 = orcodata[mface->v1]; + o2 = orcodata[mface->v2]; + o3 = orcodata[mface->v3]; if (mface->v4) { - o4= orcodata[mface->v4]; + o4 = orcodata[mface->v4]; interp_v3_v3v3v3v3(orco, o1, o2, o3, o4, w); @@ -1521,24 +1521,24 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or } void psys_interpolate_uvs(const MTFace *tface, int quad, const float w[4], float uvco[2]) { - float v10= tface->uv[0][0]; - float v11= tface->uv[0][1]; - float v20= tface->uv[1][0]; - float v21= tface->uv[1][1]; - float v30= tface->uv[2][0]; - float v31= tface->uv[2][1]; + float v10 = tface->uv[0][0]; + float v11 = tface->uv[0][1]; + float v20 = tface->uv[1][0]; + float v21 = tface->uv[1][1]; + float v30 = tface->uv[2][0]; + float v31 = tface->uv[2][1]; float v40, v41; if (quad) { - v40= tface->uv[3][0]; - v41= tface->uv[3][1]; + v40 = tface->uv[3][0]; + v41 = tface->uv[3][1]; - uvco[0]= w[0]*v10 + w[1]*v20 + w[2]*v30 + w[3]*v40; - uvco[1]= w[0]*v11 + w[1]*v21 + w[2]*v31 + w[3]*v41; + uvco[0] = w[0] * v10 + w[1] * v20 + w[2] * v30 + w[3] * v40; + uvco[1] = w[0] * v11 + w[1] * v21 + w[2] * v31 + w[3] * v41; } else { - uvco[0]= w[0]*v10 + w[1]*v20 + w[2]*v30; - uvco[1]= w[0]*v11 + w[1]*v21 + w[2]*v31; + uvco[0] = w[0] * v10 + w[1] * v20 + w[2] * v30; + uvco[1] = w[0] * v11 + w[1] * v21 + w[2] * v31; } } @@ -1546,30 +1546,30 @@ void psys_interpolate_mcol(const MCol *mcol, int quad, const float w[4], MCol *m { char *cp, *cp1, *cp2, *cp3, *cp4; - cp= (char *)mc; - cp1= (char *)&mcol[0]; - cp2= (char *)&mcol[1]; - cp3= (char *)&mcol[2]; + cp = (char *)mc; + cp1 = (char *)&mcol[0]; + cp2 = (char *)&mcol[1]; + cp3 = (char *)&mcol[2]; if (quad) { - cp4= (char *)&mcol[3]; + cp4 = (char *)&mcol[3]; - cp[0]= (int)(w[0]*cp1[0] + w[1]*cp2[0] + w[2]*cp3[0] + w[3]*cp4[0]); - cp[1]= (int)(w[0]*cp1[1] + w[1]*cp2[1] + w[2]*cp3[1] + w[3]*cp4[1]); - cp[2]= (int)(w[0]*cp1[2] + w[1]*cp2[2] + w[2]*cp3[2] + w[3]*cp4[2]); - cp[3]= (int)(w[0]*cp1[3] + w[1]*cp2[3] + w[2]*cp3[3] + w[3]*cp4[3]); + cp[0] = (int)(w[0] * cp1[0] + w[1] * cp2[0] + w[2] * cp3[0] + w[3] * cp4[0]); + cp[1] = (int)(w[0] * cp1[1] + w[1] * cp2[1] + w[2] * cp3[1] + w[3] * cp4[1]); + cp[2] = (int)(w[0] * cp1[2] + w[1] * cp2[2] + w[2] * cp3[2] + w[3] * cp4[2]); + cp[3] = (int)(w[0] * cp1[3] + w[1] * cp2[3] + w[2] * cp3[3] + w[3] * cp4[3]); } else { - cp[0]= (int)(w[0]*cp1[0] + w[1]*cp2[0] + w[2]*cp3[0]); - cp[1]= (int)(w[0]*cp1[1] + w[1]*cp2[1] + w[2]*cp3[1]); - cp[2]= (int)(w[0]*cp1[2] + w[1]*cp2[2] + w[2]*cp3[2]); - cp[3]= (int)(w[0]*cp1[3] + w[1]*cp2[3] + w[2]*cp3[3]); + cp[0] = (int)(w[0] * cp1[0] + w[1] * cp2[0] + w[2] * cp3[0]); + cp[1] = (int)(w[0] * cp1[1] + w[1] * cp2[1] + w[2] * cp3[1]); + cp[2] = (int)(w[0] * cp1[2] + w[1] * cp2[2] + w[2] * cp3[2]); + cp[3] = (int)(w[0] * cp1[3] + w[1] * cp2[3] + w[2] * cp3[3]); } } static float psys_interpolate_value_from_verts(DerivedMesh *dm, short from, int index, const float fw[4], const float *values) { - if (values==0 || index==-1) + if (values == 0 || index == -1) return 0.0; switch (from) { @@ -1578,7 +1578,7 @@ static float psys_interpolate_value_from_verts(DerivedMesh *dm, short from, int case PART_FROM_FACE: case PART_FROM_VOLUME: { - MFace *mf=dm->getTessFaceData(dm, index, CD_MFACE); + MFace *mf = dm->getTessFaceData(dm, index, CD_MFACE); return interpolate_particle_value(values[mf->v1], values[mf->v2], values[mf->v3], values[mf->v4], fw, mf->v4); } @@ -1589,8 +1589,8 @@ static float psys_interpolate_value_from_verts(DerivedMesh *dm, short from, int /* conversion of pa->fw to origspace layer coordinates */ static void psys_w_to_origspace(const float w[4], float uv[2]) { - uv[0]= w[1] + w[2]; - uv[1]= w[2] + w[3]; + uv[0] = w[1] + w[2]; + uv[1] = w[2] + w[3]; } /* conversion of pa->fw to weights in face from origspace */ @@ -1598,20 +1598,20 @@ static void psys_origspace_to_w(OrigSpaceFace *osface, int quad, const float w[4 { float v[4][3], co[3]; - v[0][0]= osface->uv[0][0]; v[0][1]= osface->uv[0][1]; v[0][2]= 0.0f; - v[1][0]= osface->uv[1][0]; v[1][1]= osface->uv[1][1]; v[1][2]= 0.0f; - v[2][0]= osface->uv[2][0]; v[2][1]= osface->uv[2][1]; v[2][2]= 0.0f; + v[0][0] = osface->uv[0][0]; v[0][1] = osface->uv[0][1]; v[0][2] = 0.0f; + v[1][0] = osface->uv[1][0]; v[1][1] = osface->uv[1][1]; v[1][2] = 0.0f; + v[2][0] = osface->uv[2][0]; v[2][1] = osface->uv[2][1]; v[2][2] = 0.0f; psys_w_to_origspace(w, co); - co[2]= 0.0f; + co[2] = 0.0f; if (quad) { - v[3][0]= osface->uv[3][0]; v[3][1]= osface->uv[3][1]; v[3][2]= 0.0f; + v[3][0] = osface->uv[3][0]; v[3][1] = osface->uv[3][1]; v[3][2] = 0.0f; interp_weights_poly_v3(neww, v, 4, co); } else { interp_weights_poly_v3(neww, v, 3, co); - neww[3]= 0.0f; + neww[3] = 0.0f; } } @@ -1619,7 +1619,7 @@ static void psys_origspace_to_w(OrigSpaceFace *osface, int quad, const float w[4 * and can be optimized but only for many lookups. returns the face index. */ int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, const float fw[4], struct LinkNode *node) { - Mesh *me= (Mesh*)ob->data; + Mesh *me = (Mesh *)ob->data; MPoly *mpoly; OrigSpaceFace *osface; int *origindex; @@ -1632,9 +1632,9 @@ int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, const f totface = dm->getNumTessFaces(dm); - if (osface==NULL || origindex==NULL) { + if (osface == NULL || origindex == NULL) { /* Assume we don't need osface data */ - if (index <totface) { + if (index < totface) { //printf("\tNO CD_ORIGSPACE, assuming not needed\n"); return index; } @@ -1644,14 +1644,14 @@ int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, const f } } else if (index >= me->totpoly) - return DMCACHE_NOTFOUND; /* index not in the original mesh */ + return DMCACHE_NOTFOUND; /* index not in the original mesh */ psys_w_to_origspace(fw, uv); if (node) { /* we have a linked list of faces that we use, faster! */ - for (;node; node=node->next) { - findex= GET_INT_FROM_POINTER(node->link); - faceuv= osface[findex].uv; + for (; node; node = node->next) { + findex = GET_INT_FROM_POINTER(node->link); + faceuv = osface[findex].uv; quad = (mpoly[findex].totloop == 4); /* check that this intersects - Its possible this misses :/ - @@ -1665,9 +1665,9 @@ int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, const f } } else { /* if we have no node, try every face */ - for (findex=0; findex<totface; findex++) { + for (findex = 0; findex < totface; findex++) { if (origindex[findex] == index) { - faceuv= osface[findex].uv; + faceuv = osface[findex].uv; quad = (mpoly[findex].totloop == 4); /* check that this intersects - Its possible this misses :/ - @@ -1718,25 +1718,25 @@ static int psys_map_index_on_dm(DerivedMesh *dm, int from, int index, int index_ *mapindex = index_dmcache; } else { /* FROM_FACE/FROM_VOLUME */ - /* find a face on the derived mesh that uses this face */ + /* find a face on the derived mesh that uses this face */ MFace *mface; OrigSpaceFace *osface; int i; i = index_dmcache; - if (i== DMCACHE_NOTFOUND || i >= dm->getNumTessFaces(dm)) + if (i == DMCACHE_NOTFOUND || i >= dm->getNumTessFaces(dm)) return 0; *mapindex = i; /* modify the original weights to become * weights for the derived mesh face */ - osface= dm->getTessFaceDataArray(dm, CD_ORIGSPACE); - mface= dm->getTessFaceData(dm, i, CD_MFACE); + osface = dm->getTessFaceDataArray(dm, CD_ORIGSPACE); + mface = dm->getTessFaceData(dm, i, CD_MFACE); if (osface == NULL) - mapfw[0]= mapfw[1]= mapfw[2]= mapfw[3]= 0.0f; + mapfw[0] = mapfw[1] = mapfw[2] = mapfw[3] = 0.0f; else psys_origspace_to_w(&osface[i], mface->v4, fw, mapfw); } @@ -1753,17 +1753,17 @@ void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache int mapindex; if (!psys_map_index_on_dm(dm, from, index, index_dmcache, fw, foffset, &mapindex, mapfw)) { - if (vec) { vec[0]=vec[1]=vec[2]=0.0; } - if (nor) { nor[0]=nor[1]=0.0; nor[2]=1.0; } - if (orco) { orco[0]=orco[1]=orco[2]=0.0; } - if (ornor) { ornor[0]=ornor[1]=0.0; ornor[2]=1.0; } - if (utan) { utan[0]=utan[1]=utan[2]=0.0; } - if (vtan) { vtan[0]=vtan[1]=vtan[2]=0.0; } + if (vec) { vec[0] = vec[1] = vec[2] = 0.0; } + if (nor) { nor[0] = nor[1] = 0.0; nor[2] = 1.0; } + if (orco) { orco[0] = orco[1] = orco[2] = 0.0; } + if (ornor) { ornor[0] = ornor[1] = 0.0; ornor[2] = 1.0; } + if (utan) { utan[0] = utan[1] = utan[2] = 0.0; } + if (vtan) { vtan[0] = vtan[1] = vtan[2] = 0.0; } return; } - orcodata= dm->getVertDataArray(dm, CD_ORCO); + orcodata = dm->getVertDataArray(dm, CD_ORCO); if (from == PART_FROM_VERT) { dm->getVertCo(dm, mapindex, vec); @@ -1782,8 +1782,8 @@ void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache } if (utan && vtan) { - utan[0]= utan[1]= utan[2]= 0.0f; - vtan[0]= vtan[1]= vtan[2]= 0.0f; + utan[0] = utan[1] = utan[2] = 0.0f; + vtan[0] = vtan[1] = vtan[2] = 0.0f; } } else { /* PART_FROM_FACE / PART_FROM_VOLUME */ @@ -1791,14 +1791,14 @@ void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache MTFace *mtface; MVert *mvert; - mface=dm->getTessFaceData(dm, mapindex, CD_MFACE); - mvert=dm->getVertDataArray(dm, CD_MVERT); - mtface=CustomData_get_layer(&dm->faceData, CD_MTFACE); + mface = dm->getTessFaceData(dm, mapindex, CD_MFACE); + mvert = dm->getVertDataArray(dm, CD_MVERT); + mtface = CustomData_get_layer(&dm->faceData, CD_MTFACE); if (mtface) mtface += mapindex; - if (from==PART_FROM_VOLUME) { + if (from == PART_FROM_VOLUME) { psys_interpolate_face(mvert, mface, mtface, orcodata, mapfw, vec, tmpnor, utan, vtan, orco, ornor); if (nor) copy_v3_v3(nor, tmpnor); @@ -1828,10 +1828,10 @@ ParticleSystemModifierData *psys_get_modifier(Object *ob, ParticleSystem *psys) ModifierData *md; ParticleSystemModifierData *psmd; - for (md=ob->modifiers.first; md; md=md->next) { - if (md->type==eModifierType_ParticleSystem) { - psmd= (ParticleSystemModifierData*) md; - if (psmd->psys==psys) { + for (md = ob->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_ParticleSystem) { + psmd = (ParticleSystemModifierData *) md; + if (psmd->psys == psys) { return psmd; } } @@ -1845,7 +1845,7 @@ ParticleSystemModifierData *psys_get_modifier(Object *ob, ParticleSystem *psys) static void psys_particle_on_shape(int UNUSED(distr), int UNUSED(index), float *UNUSED(fuv), float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor) { /* TODO */ - float zerovec[3]={0.0f, 0.0f, 0.0f}; + float zerovec[3] = {0.0f, 0.0f, 0.0f}; if (vec) { copy_v3_v3(vec, zerovec); } @@ -1871,7 +1871,7 @@ static void psys_particle_on_shape(int UNUSED(distr), int UNUSED(index), float * void psys_particle_on_emitter(ParticleSystemModifierData *psmd, int from, int index, int index_dmcache, float *fuv, float foffset, float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor) { if (psmd) { - if (psmd->psys->part->distr==PART_DISTR_GRID && psmd->psys->part->from != PART_FROM_VERT) { + if (psmd->psys->part->distr == PART_DISTR_GRID && psmd->psys->part->from != PART_FROM_VERT) { if (vec) copy_v3_v3(vec, fuv); @@ -1892,34 +1892,34 @@ void psys_particle_on_emitter(ParticleSystemModifierData *psmd, int from, int in static void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float time, float freq, float shape, float amplitude, float flat, short type, short axis, float obmat[][4], int smooth_start) { - float kink[3]={1.f, 0.f, 0.f}, par_vec[3], q1[4]={1.f, 0.f, 0.f, 0.f}; - float t, dt=1.f, result[3]; + float kink[3] = {1.f, 0.f, 0.f}, par_vec[3], q1[4] = {1.f, 0.f, 0.f, 0.f}; + float t, dt = 1.f, result[3]; if (par == NULL || type == PART_KINK_NO) return; CLAMP(time, 0.f, 1.f); - if (shape!=0.0f && type!=PART_KINK_BRAID) { - if (shape<0.0f) - time= (float)pow(time, 1.f+shape); + if (shape != 0.0f && type != PART_KINK_BRAID) { + if (shape < 0.0f) + time = (float)pow(time, 1.f + shape); else - time= (float)pow(time, 1.f/(1.f-shape)); + time = (float)pow(time, 1.f / (1.f - shape)); } - t = time * freq *(float)M_PI; + t = time * freq * (float)M_PI; if (smooth_start) { dt = fabs(t); /* smooth the beginning of kink */ CLAMP(dt, 0.f, (float)M_PI); - dt = sin(dt/2.f); + dt = sin(dt / 2.f); } if (type != PART_KINK_RADIAL) { float temp[3]; - kink[axis]=1.f; + kink[axis] = 1.f; if (obmat) mul_mat3_m4_v3(obmat, kink); @@ -1937,124 +1937,124 @@ static void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float sub_v3_v3v3(par_vec, par->co, state->co); switch (type) { - case PART_KINK_CURL: - { - negate_v3(par_vec); + case PART_KINK_CURL: + { + negate_v3(par_vec); - if (flat > 0.f) { - float proj[3]; - project_v3_v3v3(proj, par_vec, par->vel); - madd_v3_v3fl(par_vec, proj, -flat); + if (flat > 0.f) { + float proj[3]; + project_v3_v3v3(proj, par_vec, par->vel); + madd_v3_v3fl(par_vec, proj, -flat); - project_v3_v3v3(proj, par_vec, kink); - madd_v3_v3fl(par_vec, proj, -flat); - } + project_v3_v3v3(proj, par_vec, kink); + madd_v3_v3fl(par_vec, proj, -flat); + } - axis_angle_to_quat(q1, kink, (float)M_PI/2.f); + axis_angle_to_quat(q1, kink, (float)M_PI / 2.f); - mul_qt_v3(q1, par_vec); + mul_qt_v3(q1, par_vec); - madd_v3_v3fl(par_vec, kink, amplitude); + madd_v3_v3fl(par_vec, kink, amplitude); - /* rotate kink vector around strand tangent */ - if (t!=0.f) { - axis_angle_to_quat(q1, par->vel, t); - mul_qt_v3(q1, par_vec); - } + /* rotate kink vector around strand tangent */ + if (t != 0.f) { + axis_angle_to_quat(q1, par->vel, t); + mul_qt_v3(q1, par_vec); + } - add_v3_v3v3(result, par->co, par_vec); - break; - } - case PART_KINK_RADIAL: - { - if (flat > 0.f) { - float proj[3]; - /* flatten along strand */ - project_v3_v3v3(proj, par_vec, par->vel); - madd_v3_v3fl(result, proj, flat); + add_v3_v3v3(result, par->co, par_vec); + break; } + case PART_KINK_RADIAL: + { + if (flat > 0.f) { + float proj[3]; + /* flatten along strand */ + project_v3_v3v3(proj, par_vec, par->vel); + madd_v3_v3fl(result, proj, flat); + } - madd_v3_v3fl(result, par_vec, -amplitude*(float)sin(t)); - break; - } - case PART_KINK_WAVE: - { - madd_v3_v3fl(result, kink, amplitude*(float)sin(t)); + madd_v3_v3fl(result, par_vec, -amplitude * (float)sin(t)); + break; + } + case PART_KINK_WAVE: + { + madd_v3_v3fl(result, kink, amplitude * (float)sin(t)); - if (flat > 0.f) { - float proj[3]; - /* flatten along wave */ - project_v3_v3v3(proj, par_vec, kink); - madd_v3_v3fl(result, proj, flat); + if (flat > 0.f) { + float proj[3]; + /* flatten along wave */ + project_v3_v3v3(proj, par_vec, kink); + madd_v3_v3fl(result, proj, flat); - /* flatten along strand */ - project_v3_v3v3(proj, par_vec, par->vel); - madd_v3_v3fl(result, proj, flat); - } - break; - } - case PART_KINK_BRAID: - { - float y_vec[3]={0.f, 1.f, 0.f}; - float z_vec[3]={0.f, 0.f, 1.f}; - float vec_one[3], state_co[3]; - float inp_y, inp_z, length; - - if (par_rot) { - mul_qt_v3(par_rot, y_vec); - mul_qt_v3(par_rot, z_vec); + /* flatten along strand */ + project_v3_v3v3(proj, par_vec, par->vel); + madd_v3_v3fl(result, proj, flat); + } + break; } + case PART_KINK_BRAID: + { + float y_vec[3] = {0.f, 1.f, 0.f}; + float z_vec[3] = {0.f, 0.f, 1.f}; + float vec_one[3], state_co[3]; + float inp_y, inp_z, length; - negate_v3(par_vec); - normalize_v3_v3(vec_one, par_vec); + if (par_rot) { + mul_qt_v3(par_rot, y_vec); + mul_qt_v3(par_rot, z_vec); + } - inp_y=dot_v3v3(y_vec, vec_one); - inp_z=dot_v3v3(z_vec, vec_one); + negate_v3(par_vec); + normalize_v3_v3(vec_one, par_vec); - if (inp_y > 0.5f) { - copy_v3_v3(state_co, y_vec); + inp_y = dot_v3v3(y_vec, vec_one); + inp_z = dot_v3v3(z_vec, vec_one); - mul_v3_fl(y_vec, amplitude*(float)cos(t)); - mul_v3_fl(z_vec, amplitude/2.f*(float)sin(2.f*t)); - } - else if (inp_z > 0.0f) { - mul_v3_v3fl(state_co, z_vec, (float)sin((float)M_PI/3.f)); - madd_v3_v3fl(state_co, y_vec, -0.5f); + if (inp_y > 0.5f) { + copy_v3_v3(state_co, y_vec); - mul_v3_fl(y_vec, -amplitude * (float)cos(t + (float)M_PI/3.f)); - mul_v3_fl(z_vec, amplitude/2.f * (float)cos(2.f*t + (float)M_PI/6.f)); - } - else { - mul_v3_v3fl(state_co, z_vec, -(float)sin((float)M_PI/3.f)); - madd_v3_v3fl(state_co, y_vec, -0.5f); + mul_v3_fl(y_vec, amplitude * (float)cos(t)); + mul_v3_fl(z_vec, amplitude / 2.f * (float)sin(2.f * t)); + } + else if (inp_z > 0.0f) { + mul_v3_v3fl(state_co, z_vec, (float)sin((float)M_PI / 3.f)); + madd_v3_v3fl(state_co, y_vec, -0.5f); - mul_v3_fl(y_vec, amplitude * (float)-sin(t + (float)M_PI/6.f)); - mul_v3_fl(z_vec, amplitude/2.f * (float)-sin(2.f*t + (float)M_PI/3.f)); - } + mul_v3_fl(y_vec, -amplitude * (float)cos(t + (float)M_PI / 3.f)); + mul_v3_fl(z_vec, amplitude / 2.f * (float)cos(2.f * t + (float)M_PI / 6.f)); + } + else { + mul_v3_v3fl(state_co, z_vec, -(float)sin((float)M_PI / 3.f)); + madd_v3_v3fl(state_co, y_vec, -0.5f); - mul_v3_fl(state_co, amplitude); - add_v3_v3(state_co, par->co); - sub_v3_v3v3(par_vec, state->co, state_co); + mul_v3_fl(y_vec, amplitude * (float)-sin(t + (float)M_PI / 6.f)); + mul_v3_fl(z_vec, amplitude / 2.f * (float)-sin(2.f * t + (float)M_PI / 3.f)); + } - length = normalize_v3(par_vec); - mul_v3_fl(par_vec, MIN2(length, amplitude/2.f)); + mul_v3_fl(state_co, amplitude); + add_v3_v3(state_co, par->co); + sub_v3_v3v3(par_vec, state->co, state_co); - add_v3_v3v3(state_co, par->co, y_vec); - add_v3_v3(state_co, z_vec); - add_v3_v3(state_co, par_vec); + length = normalize_v3(par_vec); + mul_v3_fl(par_vec, MIN2(length, amplitude / 2.f)); - shape = 2.f*(float)M_PI * (1.f+shape); + add_v3_v3v3(state_co, par->co, y_vec); + add_v3_v3(state_co, z_vec); + add_v3_v3(state_co, par_vec); - if (t<shape) { - shape = t/shape; - shape = (float)sqrt((double)shape); - interp_v3_v3v3(result, result, state_co, shape); - } - else { - copy_v3_v3(result, state_co); + shape = 2.f * (float)M_PI * (1.f + shape); + + if (t < shape) { + shape = t / shape; + shape = (float)sqrt((double)shape); + interp_v3_v3v3(result, result, state_co, shape); + } + else { + copy_v3_v3(result, state_co); + } + break; } - break; - } } /* blend the start of the kink */ @@ -2068,18 +2068,18 @@ static float do_clump(ParticleKey *state, ParticleKey *par, float time, float cl { float clump = 0.f; - if (par && clumpfac!=0.0f) { + if (par && clumpfac != 0.0f) { float cpow; if (clumppow < 0.0f) - cpow=1.0f+clumppow; + cpow = 1.0f + clumppow; else - cpow=1.0f+9.0f*clumppow; + cpow = 1.0f + 9.0f * clumppow; if (clumpfac < 0.0f) /* clump roots instead of tips */ - clump = -clumpfac*pa_clump*(float)pow(1.0-(double)time, (double)cpow); + clump = -clumpfac * pa_clump * (float)pow(1.0 - (double)time, (double)cpow); else - clump = clumpfac*pa_clump*(float)pow((double)time, (double)cpow); + clump = clumpfac * pa_clump * (float)pow((double)time, (double)cpow); interp_v3_v3v3(state->co, state->co, par->co, clump); } @@ -2108,12 +2108,12 @@ void precalc_guides(ParticleSimulationData *sim, ListBase *effectors) pd_point_from_particle(sim, pa, &state, &point); - for (eff = effectors->first; eff; eff=eff->next) { + for (eff = effectors->first; eff; eff = eff->next) { if (eff->pd->forcefield != PFIELD_GUIDE) continue; if (!eff->guide_data) - eff->guide_data = MEM_callocN(sizeof(GuideEffectorData)*psys->totpart, "GuideEffectorData"); + eff->guide_data = MEM_callocN(sizeof(GuideEffectorData) * psys->totpart, "GuideEffectorData"); data = eff->guide_data + p; @@ -2139,78 +2139,78 @@ int do_guides(ListBase *effectors, ParticleKey *state, int index, float time) float guidetime, radius, weight, angle, totstrength = 0.0f; float vec_to_point[3]; - if (effectors) for (eff = effectors->first; eff; eff=eff->next) { - pd = eff->pd; + if (effectors) for (eff = effectors->first; eff; eff = eff->next) { + pd = eff->pd; - if (pd->forcefield != PFIELD_GUIDE) - continue; + if (pd->forcefield != PFIELD_GUIDE) + continue; - data = eff->guide_data + index; + data = eff->guide_data + index; - if (data->strength <= 0.0f) - continue; + if (data->strength <= 0.0f) + continue; - guidetime = time / (1.0f - pd->free_end); + guidetime = time / (1.0f - pd->free_end); - if (guidetime>1.0f) - continue; + if (guidetime > 1.0f) + continue; - cu = (Curve*)eff->ob->data; + cu = (Curve *)eff->ob->data; - if (pd->flag & PFIELD_GUIDE_PATH_ADD) { - if (where_on_path(eff->ob, data->strength * guidetime, guidevec, guidedir, NULL, &radius, &weight)==0) - return 0; - } - else { - if (where_on_path(eff->ob, guidetime, guidevec, guidedir, NULL, &radius, &weight)==0) - return 0; - } + if (pd->flag & PFIELD_GUIDE_PATH_ADD) { + if (where_on_path(eff->ob, data->strength * guidetime, guidevec, guidedir, NULL, &radius, &weight) == 0) + return 0; + } + else { + if (where_on_path(eff->ob, guidetime, guidevec, guidedir, NULL, &radius, &weight) == 0) + return 0; + } - mul_m4_v3(eff->ob->obmat, guidevec); - mul_mat3_m4_v3(eff->ob->obmat, guidedir); + mul_m4_v3(eff->ob->obmat, guidevec); + mul_mat3_m4_v3(eff->ob->obmat, guidedir); - normalize_v3(guidedir); + normalize_v3(guidedir); - copy_v3_v3(vec_to_point, data->vec_to_point); + copy_v3_v3(vec_to_point, data->vec_to_point); - if (guidetime != 0.0f) { - /* curve direction */ - cross_v3_v3v3(temp, eff->guide_dir, guidedir); - angle = dot_v3v3(eff->guide_dir, guidedir)/(len_v3(eff->guide_dir)); - angle = saacos(angle); - axis_angle_to_quat(rot2, temp, angle); - mul_qt_v3(rot2, vec_to_point); + if (guidetime != 0.0f) { + /* curve direction */ + cross_v3_v3v3(temp, eff->guide_dir, guidedir); + angle = dot_v3v3(eff->guide_dir, guidedir) / (len_v3(eff->guide_dir)); + angle = saacos(angle); + axis_angle_to_quat(rot2, temp, angle); + mul_qt_v3(rot2, vec_to_point); - /* curve tilt */ - axis_angle_to_quat(rot2, guidedir, guidevec[3] - eff->guide_loc[3]); - mul_qt_v3(rot2, vec_to_point); - } + /* curve tilt */ + axis_angle_to_quat(rot2, guidedir, guidevec[3] - eff->guide_loc[3]); + mul_qt_v3(rot2, vec_to_point); + } - /* curve taper */ - if (cu->taperobj) - mul_v3_fl(vec_to_point, calc_taper(eff->scene, cu->taperobj, (int)(data->strength*guidetime*100.0f), 100)); + /* curve taper */ + if (cu->taperobj) + mul_v3_fl(vec_to_point, calc_taper(eff->scene, cu->taperobj, (int)(data->strength * guidetime * 100.0f), 100)); - else { /* curve size*/ - if (cu->flag & CU_PATH_RADIUS) { - mul_v3_fl(vec_to_point, radius); + else { /* curve size*/ + if (cu->flag & CU_PATH_RADIUS) { + mul_v3_fl(vec_to_point, radius); + } } - } - par.co[0] = par.co[1] = par.co[2] = 0.0f; - copy_v3_v3(key.co, vec_to_point); - do_kink(&key, &par, 0, guidetime, pd->kink_freq, pd->kink_shape, pd->kink_amp, 0.f, pd->kink, pd->kink_axis, 0, 0); - do_clump(&key, &par, guidetime, pd->clump_fac, pd->clump_pow, 1.0f); - copy_v3_v3(vec_to_point, key.co); + par.co[0] = par.co[1] = par.co[2] = 0.0f; + copy_v3_v3(key.co, vec_to_point); + do_kink(&key, &par, 0, guidetime, pd->kink_freq, pd->kink_shape, pd->kink_amp, 0.f, pd->kink, pd->kink_axis, 0, 0); + do_clump(&key, &par, guidetime, pd->clump_fac, pd->clump_pow, 1.0f); + copy_v3_v3(vec_to_point, key.co); - add_v3_v3(vec_to_point, guidevec); + add_v3_v3(vec_to_point, guidevec); - //sub_v3_v3v3(pa_loc, pa_loc, pa_zero); - madd_v3_v3fl(effect, vec_to_point, data->strength); - madd_v3_v3fl(veffect, guidedir, data->strength); - totstrength += data->strength; + //sub_v3_v3v3(pa_loc, pa_loc, pa_zero); + madd_v3_v3fl(effect, vec_to_point, data->strength); + madd_v3_v3fl(veffect, guidedir, data->strength); + totstrength += data->strength; - if (pd->flag & PFIELD_GUIDE_PATH_WEIGHT) - totstrength *= weight; - } + if (pd->flag & PFIELD_GUIDE_PATH_WEIGHT) + totstrength *= weight; + } if (totstrength != 0.0f) { if (totstrength > 1.0f) @@ -2232,13 +2232,13 @@ static void do_rough(float *loc, float mat[4][4], float t, float fac, float size float rco[3]; if (thres != 0.0f) - if ((float)fabs((float)(-1.5f+loc[0]+loc[1]+loc[2]))<1.5f*thres) return; + if ((float)fabs((float)(-1.5f + loc[0] + loc[1] + loc[2])) < 1.5f * thres) return; copy_v3_v3(rco, loc); mul_v3_fl(rco, t); - rough[0]=-1.0f+2.0f*BLI_gTurbulence(size, rco[0], rco[1], rco[2], 2, 0, 2); - rough[1]=-1.0f+2.0f*BLI_gTurbulence(size, rco[1], rco[2], rco[0], 2, 0, 2); - rough[2]=-1.0f+2.0f*BLI_gTurbulence(size, rco[2], rco[0], rco[1], 2, 0, 2); + rough[0] = -1.0f + 2.0f * BLI_gTurbulence(size, rco[0], rco[1], rco[2], 2, 0, 2); + rough[1] = -1.0f + 2.0f * BLI_gTurbulence(size, rco[1], rco[2], rco[0], 2, 0, 2); + rough[2] = -1.0f + 2.0f * BLI_gTurbulence(size, rco[2], rco[0], rco[1], 2, 0, 2); madd_v3_v3fl(state->co, mat[0], fac * rough[0]); madd_v3_v3fl(state->co, mat[1], fac * rough[1]); @@ -2249,10 +2249,10 @@ static void do_rough_end(float *loc, float mat[4][4], float t, float fac, float float rough[2]; float roughfac; - roughfac=fac*(float)pow((double)t, shape); + roughfac = fac * (float)pow((double)t, shape); copy_v2_v2(rough, loc); - rough[0]=-1.0f+2.0f*rough[0]; - rough[1]=-1.0f+2.0f*rough[1]; + rough[0] = -1.0f + 2.0f * rough[0]; + rough[1] = -1.0f + 2.0f * rough[1]; mul_v2_fl(rough, roughfac); madd_v3_v3fl(state->co, mat[0], rough[0]); @@ -2268,23 +2268,23 @@ static void do_path_effectors(ParticleSimulationData *sim, int i, ParticleCacheK if (sim->psys->flag & PSYS_HAIR_DYNAMICS) return; - copy_v3_v3(eff_key.co, (ca-1)->co); - copy_v3_v3(eff_key.vel, (ca-1)->vel); - copy_qt_qt(eff_key.rot, (ca-1)->rot); + copy_v3_v3(eff_key.co, (ca - 1)->co); + copy_v3_v3(eff_key.vel, (ca - 1)->vel); + copy_qt_qt(eff_key.rot, (ca - 1)->rot); - pd_point_from_particle(sim, sim->psys->particles+i, &eff_key, &epoint); + pd_point_from_particle(sim, sim->psys->particles + i, &eff_key, &epoint); pdDoEffectors(sim->psys->effectors, sim->colliders, sim->psys->part->effector_weights, &epoint, force, NULL); - mul_v3_fl(force, effector*powf((float)k / (float)steps, 100.0f * sim->psys->part->eff_hair) / (float)steps); + mul_v3_fl(force, effector * powf((float)k / (float)steps, 100.0f * sim->psys->part->eff_hair) / (float)steps); add_v3_v3(force, vec); normalize_v3(force); if (k < steps) - sub_v3_v3v3(vec, (ca+1)->co, ca->co); + sub_v3_v3v3(vec, (ca + 1)->co, ca->co); - madd_v3_v3v3fl(ca->co, (ca-1)->co, force, *length); + madd_v3_v3v3fl(ca->co, (ca - 1)->co, force, *length); if (k < steps) *length = len_v3(vec); @@ -2296,10 +2296,10 @@ static int check_path_length(int k, ParticleCacheKey *keys, ParticleCacheKey *st add_v3_v3v3(state->co, (state - 1)->co, dvec); keys->steps = k; /* something over the maximum step value */ - return k=100000; + return k = 100000; } else { - *cur_length+=length; + *cur_length += length; return k; } } @@ -2308,7 +2308,7 @@ static void offset_child(ChildParticle *cpa, ParticleKey *par, float *par_rot, P copy_v3_v3(child->co, cpa->fuv); mul_v3_fl(child->co, radius); - child->co[0]*=flat; + child->co[0] *= flat; copy_v3_v3(child->vel, par->vel); @@ -2323,7 +2323,7 @@ static void offset_child(ChildParticle *cpa, ParticleKey *par, float *par_rot, P } float *psys_cache_vgroup(DerivedMesh *dm, ParticleSystem *psys, int vgroup) { - float *vg=0; + float *vg = 0; if (vgroup < 0) { /* hair dynamics pinning vgroup */ @@ -2332,15 +2332,15 @@ float *psys_cache_vgroup(DerivedMesh *dm, ParticleSystem *psys, int vgroup) else if (psys->vgroup[vgroup]) { MDeformVert *dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); if (dvert) { - int totvert=dm->getNumVerts(dm), i; - vg=MEM_callocN(sizeof(float)*totvert, "vg_cache"); - if (psys->vg_neg&(1<<vgroup)) { - for (i=0; i<totvert; i++) - vg[i]= 1.0f - defvert_find_weight(&dvert[i], psys->vgroup[vgroup] - 1); + int totvert = dm->getNumVerts(dm), i; + vg = MEM_callocN(sizeof(float) * totvert, "vg_cache"); + if (psys->vg_neg & (1 << vgroup)) { + for (i = 0; i < totvert; i++) + vg[i] = 1.0f - defvert_find_weight(&dvert[i], psys->vgroup[vgroup] - 1); } else { - for (i=0; i<totvert; i++) - vg[i]= defvert_find_weight(&dvert[i], psys->vgroup[vgroup] - 1); + for (i = 0; i < totvert; i++) + vg[i] = defvert_find_weight(&dvert[i], psys->vgroup[vgroup] - 1); } } } @@ -2348,29 +2348,29 @@ float *psys_cache_vgroup(DerivedMesh *dm, ParticleSystem *psys, int vgroup) } void psys_find_parents(ParticleSimulationData *sim) { - ParticleSettings *part=sim->psys->part; + ParticleSettings *part = sim->psys->part; KDTree *tree; ChildParticle *cpa; - int p, totparent, totchild=sim->psys->totchild; + int p, totparent, totchild = sim->psys->totchild; float co[3], orco[3]; - int from=PART_FROM_FACE; - totparent=(int)(totchild*part->parents*0.3f); + int from = PART_FROM_FACE; + totparent = (int)(totchild * part->parents * 0.3f); if (G.rendering && part->child_nbr && part->ren_child_nbr) - totparent*=(float)part->child_nbr/(float)part->ren_child_nbr; + totparent *= (float)part->child_nbr / (float)part->ren_child_nbr; - tree=BLI_kdtree_new(totparent); + tree = BLI_kdtree_new(totparent); - for (p=0, cpa=sim->psys->child; p<totparent; p++, cpa++) { + for (p = 0, cpa = sim->psys->child; p < totparent; p++, cpa++) { psys_particle_on_emitter(sim->psmd, from, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co, 0, 0, 0, orco, 0); BLI_kdtree_insert(tree, p, orco, NULL); } BLI_kdtree_balance(tree); - for (; p<totchild; p++, cpa++) { + for (; p < totchild; p++, cpa++) { psys_particle_on_emitter(sim->psmd, from, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co, 0, 0, 0, orco, 0); - cpa->parent=BLI_kdtree_find_nearest(tree, orco, NULL, NULL); + cpa->parent = BLI_kdtree_find_nearest(tree, orco, NULL, NULL); } BLI_kdtree_free(tree); @@ -2399,7 +2399,7 @@ static void get_strand_normal(Material *ma, const float surfnor[3], float surfdi if (ma->strand_surfnor > 0.0f) { if (ma->strand_surfnor > surfdist) { - blend= (ma->strand_surfnor - surfdist)/ma->strand_surfnor; + blend = (ma->strand_surfnor - surfdist) / ma->strand_surfnor; interp_v3_v3v3(vnor, vnor, surfnor, blend); normalize_v3(vnor); } @@ -2410,64 +2410,64 @@ static void get_strand_normal(Material *ma, const float surfnor[3], float surfdi static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float cfra, int editupdate) { - ParticleThreadContext *ctx= threads[0].ctx; + ParticleThreadContext *ctx = threads[0].ctx; /* Object *ob= ctx->sim.ob; */ - ParticleSystem *psys= ctx->sim.psys; + ParticleSystem *psys = ctx->sim.psys; ParticleSettings *part = psys->part; /* ParticleEditSettings *pset = &scene->toolsettings->particle; */ - int totparent=0, between=0; + int totparent = 0, between = 0; int steps = (int)pow(2.0, (double)part->draw_step); int totchild = psys->totchild; - int i, seed, totthread= threads[0].tot; + int i, seed, totthread = threads[0].tot; /*---start figuring out what is actually wanted---*/ if (psys_in_edit_mode(scene, psys)) { ParticleEditSettings *pset = &scene->toolsettings->particle; - if (psys->renderdata==0 && (psys->edit==NULL || pset->flag & PE_DRAW_PART)==0) - totchild=0; + if (psys->renderdata == 0 && (psys->edit == NULL || pset->flag & PE_DRAW_PART) == 0) + totchild = 0; steps = (int)pow(2.0, (double)pset->draw_step); } - if (totchild && part->childtype==PART_CHILD_FACES) { - totparent=(int)(totchild*part->parents*0.3f); + if (totchild && part->childtype == PART_CHILD_FACES) { + totparent = (int)(totchild * part->parents * 0.3f); if (G.rendering && part->child_nbr && part->ren_child_nbr) - totparent*=(float)part->child_nbr/(float)part->ren_child_nbr; + totparent *= (float)part->child_nbr / (float)part->ren_child_nbr; /* part->parents could still be 0 so we can't test with totparent */ - between=1; + between = 1; } if (psys->renderdata) - steps=(int)pow(2.0, (double)part->ren_step); + steps = (int)pow(2.0, (double)part->ren_step); else { - totchild=(int)((float)totchild*(float)part->disp/100.0f); - totparent=MIN2(totparent, totchild); + totchild = (int)((float)totchild * (float)part->disp / 100.0f); + totparent = MIN2(totparent, totchild); } - if (totchild==0) return 0; + if (totchild == 0) return 0; /* init random number generator */ - seed= 31415926 + ctx->sim.psys->seed; + seed = 31415926 + ctx->sim.psys->seed; if (ctx->editupdate || totchild < 10000) - totthread= 1; + totthread = 1; - for (i=0; i<totthread; i++) { - threads[i].rng_path= rng_new(seed); - threads[i].tot= totthread; + for (i = 0; i < totthread; i++) { + threads[i].rng_path = rng_new(seed); + threads[i].tot = totthread; } /* fill context values */ - ctx->between= between; - ctx->steps= steps; - ctx->totchild= totchild; - ctx->totparent= totparent; - ctx->parent_pass= 0; - ctx->cfra= cfra; - ctx->editupdate= editupdate; + ctx->between = between; + ctx->steps = steps; + ctx->totchild = totchild; + ctx->totparent = totparent; + ctx->parent_pass = 0; + ctx->cfra = cfra; + ctx->editupdate = editupdate; psys->lattice = psys_get_lattice(&ctx->sim); @@ -2483,7 +2483,7 @@ static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float c /* set correct ipo timing */ #if 0 // XXX old animation system - if (part->flag&PART_ABS_TIME && part->ipo) { + if (part->flag & PART_ABS_TIME && part->ipo) { calc_ipo(part->ipo, cfra); execute_ipo((ID *)part, part->ipo); } @@ -2495,15 +2495,15 @@ static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float c /* note: this function must be thread safe, except for branching! */ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle *cpa, ParticleCacheKey *child_keys, int i) { - ParticleThreadContext *ctx= thread->ctx; - Object *ob= ctx->sim.ob; + ParticleThreadContext *ctx = thread->ctx; + Object *ob = ctx->sim.ob; ParticleSystem *psys = ctx->sim.psys; ParticleSettings *part = psys->part; - ParticleCacheKey **cache= psys->childcache; - ParticleCacheKey **pcache= psys_in_edit_mode(ctx->sim.scene, psys) ? psys->edit->pathcache : psys->pathcache; + ParticleCacheKey **cache = psys->childcache; + ParticleCacheKey **pcache = psys_in_edit_mode(ctx->sim.scene, psys) ? psys->edit->pathcache : psys->pathcache; ParticleCacheKey *child, *par = NULL, *key[4]; ParticleTexture ptex; - float *cpa_fuv=0, *par_rot=0, rot[4]; + float *cpa_fuv = 0, *par_rot = 0, rot[4]; float orco[3], ornor[3], hairmat[4][4], t, dvec[3], off1[4][3], off2[4][3]; float length, max_length = 1.0f, cur_length = 0.0f; float eff_length, eff_vec[3], weight[4]; @@ -2516,7 +2516,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle if (ctx->between) { ParticleData *pa = psys->particles + cpa->pa[0]; int w, needupdate; - float foffset, wsum=0.f; + float foffset, wsum = 0.f; float co[3]; float p_min = part->parting_min; float p_max = part->parting_max; @@ -2524,11 +2524,11 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle float p_fac = part->parents > 0.f ? 0.f : part->parting_fac; if (ctx->editupdate) { - needupdate= 0; - w= 0; - while (w<4 && cpa->pa[w]>=0) { + needupdate = 0; + w = 0; + while (w < 4 && cpa->pa[w] >= 0) { if (psys->edit->points[cpa->pa[w]].flag & PEP_EDIT_RECALC) { - needupdate= 1; + needupdate = 1; break; } w++; @@ -2537,11 +2537,11 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle if (!needupdate) return; else - memset(child_keys, 0, sizeof(*child_keys)*(ctx->steps+1)); + memset(child_keys, 0, sizeof(*child_keys) * (ctx->steps + 1)); } /* get parent paths */ - for (w=0; w<4; w++) { + for (w = 0; w < 4; w++) { if (cpa->pa[w] >= 0) { key[w] = pcache[cpa->pa[w]]; weight[w] = cpa->w[w]; @@ -2554,20 +2554,20 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle /* modify weights to create parting */ if (p_fac > 0.f) { - for (w=0; w<4; w++) { + for (w = 0; w < 4; w++) { if (w && weight[w] > 0.f) { float d; if (part->flag & PART_CHILD_LONG_HAIR) { /* For long hair use tip distance/root distance as parting factor instead of root to tip angle. */ float d1 = len_v3v3(key[0]->co, key[w]->co); - float d2 = len_v3v3((key[0]+key[0]->steps-1)->co, (key[w]+key[w]->steps-1)->co); + float d2 = len_v3v3((key[0] + key[0]->steps - 1)->co, (key[w] + key[w]->steps - 1)->co); - d = d1 > 0.f ? d2/d1 - 1.f : 10000.f; + d = d1 > 0.f ? d2 / d1 - 1.f : 10000.f; } else { float v1[3], v2[3]; - sub_v3_v3v3(v1, (key[0]+key[0]->steps-1)->co, key[0]->co); - sub_v3_v3v3(v2, (key[w]+key[w]->steps-1)->co, key[w]->co); + sub_v3_v3v3(v1, (key[0] + key[0]->steps - 1)->co, key[0]->co); + sub_v3_v3v3(v2, (key[w] + key[w]->steps - 1)->co, key[w]->co); normalize_v3(v1); normalize_v3(v2); @@ -2575,7 +2575,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle } if (p_max > p_min) - d = (d - p_min)/(p_max - p_min); + d = (d - p_min) / (p_max - p_min); else d = (d - p_min) <= 0.f ? 0.f : 1.f; @@ -2586,7 +2586,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle } wsum += weight[w]; } - for (w=0; w<4; w++) + for (w = 0; w < 4; w++) weight[w] /= wsum; interp_v4_v4v4(weight, cpa->w, weight, p_fac); @@ -2603,7 +2603,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle mul_m4_v3(ob->obmat, co); - for (w=0; w<4; w++) + for (w = 0; w < 4; w++) sub_v3_v3v3(off1[w], co, key[w]->co); psys_mat_hair_to_global(ob, ctx->sim.psmd->dm, psys->part->from, pa, hairmat); @@ -2615,7 +2615,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle if (!(psys->edit->points[cpa->parent].flag & PEP_EDIT_RECALC)) return; - memset(child_keys, 0, sizeof(*child_keys)*(ctx->steps+1)); + memset(child_keys, 0, sizeof(*child_keys) * (ctx->steps + 1)); } /* get the parent path */ @@ -2642,66 +2642,66 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle } /* create the child path */ - for (k=0, child=child_keys; k<=ctx->steps; k++, child++) { + for (k = 0, child = child_keys; k <= ctx->steps; k++, child++) { if (ctx->between) { - int w=0; + int w = 0; zero_v3(child->co); zero_v3(child->vel); unit_qt(child->rot); - for (w=0; w<4; w++) { + for (w = 0; w < 4; w++) { copy_v3_v3(off2[w], off1[w]); if (part->flag & PART_CHILD_LONG_HAIR) { /* Use parent rotation (in addition to emission location) to determine child offset. */ if (k) - mul_qt_v3((key[w]+k)->rot, off2[w]); + mul_qt_v3((key[w] + k)->rot, off2[w]); /* Fade the effect of rotation for even lengths in the end */ - project_v3_v3v3(dvec, off2[w], (key[w]+k)->vel); - madd_v3_v3fl(off2[w], dvec, -(float)k/(float)ctx->steps); + project_v3_v3v3(dvec, off2[w], (key[w] + k)->vel); + madd_v3_v3fl(off2[w], dvec, -(float)k / (float)ctx->steps); } - add_v3_v3(off2[w], (key[w]+k)->co); + add_v3_v3(off2[w], (key[w] + k)->co); } /* child position is the weighted sum of parent positions */ interp_v3_v3v3v3v3(child->co, off2[0], off2[1], off2[2], off2[3], weight); - interp_v3_v3v3v3v3(child->vel, (key[0]+k)->vel, (key[1]+k)->vel, (key[2]+k)->vel, (key[3]+k)->vel, weight); + interp_v3_v3v3v3v3(child->vel, (key[0] + k)->vel, (key[1] + k)->vel, (key[2] + k)->vel, (key[3] + k)->vel, weight); - copy_qt_qt(child->rot, (key[0]+k)->rot); + copy_qt_qt(child->rot, (key[0] + k)->rot); } else { if (k) { - mul_qt_qtqt(rot, (key[0]+k)->rot, key[0]->rot); + mul_qt_qtqt(rot, (key[0] + k)->rot, key[0]->rot); par_rot = rot; } else { par_rot = key[0]->rot; } /* offset the child from the parent position */ - offset_child(cpa, (ParticleKey*)(key[0]+k), par_rot, (ParticleKey*)child, part->childflat, part->childrad); + offset_child(cpa, (ParticleKey *)(key[0] + k), par_rot, (ParticleKey *)child, part->childflat, part->childrad); } - child->time = (float)k/(float)ctx->steps; + child->time = (float)k / (float)ctx->steps; } /* apply effectors */ if (part->flag & PART_CHILD_EFFECT) { - for (k=0, child=child_keys; k<=ctx->steps; k++, child++) { + for (k = 0, child = child_keys; k <= ctx->steps; k++, child++) { if (k) { do_path_effectors(&ctx->sim, cpa->pa[0], child, k, ctx->steps, child_keys->co, ptex.effector, 0.0f, ctx->cfra, &eff_length, eff_vec); } else { - sub_v3_v3v3(eff_vec, (child+1)->co, child->co); + sub_v3_v3v3(eff_vec, (child + 1)->co, child->co); eff_length = len_v3(eff_vec); } } } - for (k=0, child=child_keys; k<=ctx->steps; k++, child++) { - t = (float)k/(float)ctx->steps; + for (k = 0, child = child_keys; k <= ctx->steps; k++, child++) { + t = (float)k / (float)ctx->steps; if (ctx->totparent) /* this is now threadsafe, virtual parents are calculated before rest of children */ @@ -2711,7 +2711,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle if (par) { if (k) { - mul_qt_qtqt(rot, (par+k)->rot, par->rot); + mul_qt_qtqt(rot, (par + k)->rot, par->rot); par_rot = rot; } else { @@ -2724,21 +2724,21 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle do_child_modifiers(&ctx->sim, &ptex, (ParticleKey *)par, par_rot, cpa, orco, hairmat, (ParticleKey *)child, t); /* we have to correct velocity because of kink & clump */ - if (k>1) { - sub_v3_v3v3((child-1)->vel, child->co, (child-2)->co); - mul_v3_fl((child-1)->vel, 0.5); + if (k > 1) { + sub_v3_v3v3((child - 1)->vel, child->co, (child - 2)->co); + mul_v3_fl((child - 1)->vel, 0.5); if (ctx->ma && (part->draw_col == PART_DRAW_COL_MAT)) - get_strand_normal(ctx->ma, ornor, cur_length, (child-1)->vel); + get_strand_normal(ctx->ma, ornor, cur_length, (child - 1)->vel); } if (k == ctx->steps) - sub_v3_v3v3(child->vel, child->co, (child-1)->co); + sub_v3_v3v3(child->vel, child->co, (child - 1)->co); /* check if path needs to be cut before actual end of data points */ if (k) { - sub_v3_v3v3(dvec, child->co, (child-1)->co); - length = 1.0f/(float)ctx->steps; + sub_v3_v3v3(dvec, child->co, (child - 1)->co); + length = 1.0f / (float)ctx->steps; k = check_path_length(k, child_keys, child, max_length, &cur_length, length, dvec); } else { @@ -2760,20 +2760,20 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle static void *exec_child_path_cache(void *data) { - ParticleThread *thread= (ParticleThread*)data; - ParticleThreadContext *ctx= thread->ctx; - ParticleSystem *psys= ctx->sim.psys; - ParticleCacheKey **cache= psys->childcache; + ParticleThread *thread = (ParticleThread *)data; + ParticleThreadContext *ctx = thread->ctx; + ParticleSystem *psys = ctx->sim.psys; + ParticleCacheKey **cache = psys->childcache; ChildParticle *cpa; - int i, totchild= ctx->totchild, first= 0; + int i, totchild = ctx->totchild, first = 0; if (thread->tot > 1) { - first= ctx->parent_pass? 0 : ctx->totparent; - totchild= ctx->parent_pass? ctx->totparent : ctx->totchild; + first = ctx->parent_pass ? 0 : ctx->totparent; + totchild = ctx->parent_pass ? ctx->totparent : ctx->totchild; } - cpa= psys->child + first + thread->num; - for (i=first+thread->num; i<totchild; i+=thread->tot, cpa+=thread->tot) + cpa = psys->child + first + thread->num; + for (i = first + thread->num; i < totchild; i += thread->tot, cpa += thread->tot) psys_thread_create_path(thread, cpa, cache[i], i); return 0; @@ -2789,16 +2789,16 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd if (sim->psys->flag & PSYS_GLOBAL_HAIR) return; - pthreads= psys_threads_create(sim); + pthreads = psys_threads_create(sim); if (!psys_threads_init_path(pthreads, sim->scene, cfra, editupdate)) { psys_threads_free(pthreads); return; } - ctx= pthreads[0].ctx; - totchild= ctx->totchild; - totparent= ctx->totparent; + ctx = pthreads[0].ctx; + totchild = ctx->totchild; + totparent = ctx->totparent; if (editupdate && sim->psys->childcache && totchild == sim->psys->totchildcache) { ; /* just overwrite the existing cache */ @@ -2806,11 +2806,11 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd else { /* clear out old and create new empty path cache */ free_child_path_cache(sim->psys); - sim->psys->childcache= psys_alloc_path_cache_buffers(&sim->psys->childcachebufs, totchild, ctx->steps+1); + sim->psys->childcache = psys_alloc_path_cache_buffers(&sim->psys->childcachebufs, totchild, ctx->steps + 1); sim->psys->totchildcache = totchild; } - totthread= pthreads[0].tot; + totthread = pthreads[0].tot; if (totthread > 1) { @@ -2818,20 +2818,20 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd if (totparent) { BLI_init_threads(&threads, exec_child_path_cache, totthread); - for (i=0; i<totthread; i++) { + for (i = 0; i < totthread; i++) { pthreads[i].ctx->parent_pass = 1; BLI_insert_thread(&threads, &pthreads[i]); } BLI_end_threads(&threads); - for (i=0; i<totthread; i++) + for (i = 0; i < totthread; i++) pthreads[i].ctx->parent_pass = 0; } BLI_init_threads(&threads, exec_child_path_cache, totthread); - for (i=0; i<totthread; i++) + for (i = 0; i < totthread; i++) BLI_insert_thread(&threads, &pthreads[i]); BLI_end_threads(&threads); @@ -2847,35 +2847,35 @@ static void cache_key_incremental_rotation(ParticleCacheKey *key0, ParticleCache float cosangle, angle, tangent[3], normal[3], q[4]; switch (i) { - case 0: - /* start from second key */ - break; - case 1: - /* calculate initial tangent for incremental rotations */ - sub_v3_v3v3(prev_tangent, key0->co, key1->co); - normalize_v3(prev_tangent); - unit_qt(key1->rot); - break; - default: - sub_v3_v3v3(tangent, key0->co, key1->co); - normalize_v3(tangent); - - cosangle= dot_v3v3(tangent, prev_tangent); - - /* note we do the comparison on cosangle instead of - * angle, since floating point accuracy makes it give - * different results across platforms */ - if (cosangle > 0.999999f) { - copy_v4_v4(key1->rot, key2->rot); - } - else { - angle= saacos(cosangle); - cross_v3_v3v3(normal, prev_tangent, tangent); - axis_angle_to_quat(q, normal, angle); - mul_qt_qtqt(key1->rot, q, key2->rot); - } + case 0: + /* start from second key */ + break; + case 1: + /* calculate initial tangent for incremental rotations */ + sub_v3_v3v3(prev_tangent, key0->co, key1->co); + normalize_v3(prev_tangent); + unit_qt(key1->rot); + break; + default: + sub_v3_v3v3(tangent, key0->co, key1->co); + normalize_v3(tangent); + + cosangle = dot_v3v3(tangent, prev_tangent); - copy_v3_v3(prev_tangent, tangent); + /* note we do the comparison on cosangle instead of + * angle, since floating point accuracy makes it give + * different results across platforms */ + if (cosangle > 0.999999f) { + copy_v4_v4(key1->rot, key2->rot); + } + else { + angle = saacos(cosangle); + cross_v3_v3v3(normal, prev_tangent, tangent); + axis_angle_to_quat(q, normal, angle); + mul_qt_qtqt(key1->rot, q, key2->rot); + } + + copy_v3_v3(prev_tangent, tangent); } } @@ -2892,7 +2892,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) ParticleSettings *part = psys->part; ParticleCacheKey *ca, **cache; - DerivedMesh *hair_dm = (psys->part->type==PART_HAIR && psys->flag & PSYS_HAIR_DYNAMICS) ? psys->hair_out_dm : NULL; + DerivedMesh *hair_dm = (psys->part->type == PART_HAIR && psys->flag & PSYS_HAIR_DYNAMICS) ? psys->hair_out_dm : NULL; ParticleKey result; @@ -2911,16 +2911,16 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) int steps = (int)pow(2.0, (double)(psys->renderdata ? part->ren_step : part->draw_step)); int totpart = psys->totpart; float length, vec[3]; - float *vg_effector= NULL; - float *vg_length= NULL, pa_length=1.0f; + float *vg_effector = NULL; + float *vg_length = NULL, pa_length = 1.0f; int keyed, baked; /* we don't have anything valid to create paths from so let's quit here */ - if ((psys->flag & PSYS_HAIR_DONE || psys->flag & PSYS_KEYED || psys->pointcache)==0) + if ((psys->flag & PSYS_HAIR_DONE || psys->flag & PSYS_KEYED || psys->pointcache) == 0) return; if (psys_in_edit_mode(sim->scene, psys)) - if (psys->renderdata==0 && (psys->edit==NULL || pset->flag & PE_DRAW_PART)==0) + if (psys->renderdata == 0 && (psys->edit == NULL || pset->flag & PE_DRAW_PART) == 0) return; keyed = psys->flag & PSYS_KEYED; @@ -2928,15 +2928,15 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) /* clear out old and create new empty path cache */ psys_free_path_cache(psys, psys->edit); - cache= psys->pathcache= psys_alloc_path_cache_buffers(&psys->pathcachebufs, totpart, steps+1); + cache = psys->pathcache = psys_alloc_path_cache_buffers(&psys->pathcachebufs, totpart, steps + 1); psys->lattice = psys_get_lattice(sim); - ma= give_current_material(sim->ob, psys->part->omat); + ma = give_current_material(sim->ob, psys->part->omat); if (ma && (psys->part->draw_col == PART_DRAW_COL_MAT)) copy_v3_v3(col, &ma->r); - if ((psys->flag & PSYS_GLOBAL_HAIR)==0) { - if ((psys->part->flag & PART_CHILD_EFFECT)==0) + if ((psys->flag & PSYS_GLOBAL_HAIR) == 0) { + if ((psys->part->flag & PART_CHILD_EFFECT) == 0) vg_effector = psys_cache_vgroup(psmd->dm, psys, PSYS_VG_EFFECTOR); if (!psys->totchild) @@ -2963,7 +2963,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) pind.bspline = (psys->part->flag & PART_HAIR_BSPLINE); pind.dm = hair_dm; - memset(cache[p], 0, sizeof(*cache[p])*(steps+1)); + memset(cache[p], 0, sizeof(*cache[p]) * (steps + 1)); cache[p]->steps = steps; @@ -2994,7 +2994,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) dietime = birthtime + pa_length * (dietime - birthtime); /*--interpolate actual path from data points--*/ - for (k=0, ca=cache[p]; k<=steps; k++, ca++) { + for (k = 0, ca = cache[p]; k <= steps; k++, ca++) { time = (float)k / (float)steps; t = birthtime + time * (dietime - birthtime); result.time = -t; @@ -3016,45 +3016,45 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) if (!(psys->flag & PSYS_GLOBAL_HAIR)) { /* apply effectors */ if ((psys->part->flag & PART_CHILD_EFFECT) == 0) { - float effector= 1.0f; + float effector = 1.0f; if (vg_effector) - effector*= psys_particle_value_from_verts(psmd->dm, psys->part->from, pa, vg_effector); + effector *= psys_particle_value_from_verts(psmd->dm, psys->part->from, pa, vg_effector); - sub_v3_v3v3(vec, (cache[p]+1)->co, cache[p]->co); + sub_v3_v3v3(vec, (cache[p] + 1)->co, cache[p]->co); length = len_v3(vec); - for (k=1, ca=cache[p]+1; k<=steps; k++, ca++) + for (k = 1, ca = cache[p] + 1; k <= steps; k++, ca++) do_path_effectors(sim, p, ca, k, steps, cache[p]->co, effector, dfra, cfra, &length, vec); } /* apply guide curves to path data */ - if (sim->psys->effectors && (psys->part->flag & PART_CHILD_EFFECT)==0) { - for (k=0, ca=cache[p]; k<=steps; k++, ca++) + if (sim->psys->effectors && (psys->part->flag & PART_CHILD_EFFECT) == 0) { + for (k = 0, ca = cache[p]; k <= steps; k++, ca++) /* ca is safe to cast, since only co and vel are used */ - do_guides(sim->psys->effectors, (ParticleKey*)ca, p, (float)k/(float)steps); + do_guides(sim->psys->effectors, (ParticleKey *)ca, p, (float)k / (float)steps); } /* lattices have to be calculated separately to avoid mixups between effector calculations */ if (psys->lattice) { - for (k=0, ca=cache[p]; k<=steps; k++, ca++) + for (k = 0, ca = cache[p]; k <= steps; k++, ca++) calc_latt_deform(psys->lattice, ca->co, 1.0f); } } /* finally do rotation & velocity */ - for (k=1, ca=cache[p]+1; k<=steps; k++, ca++) { + for (k = 1, ca = cache[p] + 1; k <= steps; k++, ca++) { cache_key_incremental_rotation(ca, ca - 1, ca - 2, prev_tangent, k); if (k == steps) copy_qt_qt(ca->rot, (ca - 1)->rot); /* set velocity */ - sub_v3_v3v3(ca->vel, ca->co, (ca-1)->co); + sub_v3_v3v3(ca->vel, ca->co, (ca - 1)->co); - if (k==1) - copy_v3_v3((ca-1)->vel, ca->vel); + if (k == 1) + copy_v3_v3((ca - 1)->vel, ca->vel); - ca->time = (float)k/(float)steps; + ca->time = (float)k / (float)steps; } /* First rotation is based on emitting face orientation. * This is way better than having flipping rotations resulting @@ -3070,7 +3070,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) if (psys->lattice) { end_latt_deform(psys->lattice); - psys->lattice= NULL; + psys->lattice = NULL; } if (vg_effector) @@ -3081,7 +3081,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) } void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cfra) { - ParticleCacheKey *ca, **cache= edit->pathcache; + ParticleCacheKey *ca, **cache = edit->pathcache; ParticleEditSettings *pset = &scene->toolsettings->particle; PTCacheEditPoint *point = NULL; @@ -3099,7 +3099,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf float hairmat[4][4], rotmat[3][3], prev_tangent[3] = {0.0f, 0.0f, 0.0f}; int k, i; int steps = (int)pow(2.0, (double)pset->draw_step); - int totpart = edit->totpoint, recalc_set=0; + int totpart = edit->totpoint, recalc_set = 0; float sel_col[3]; float nosel_col[3]; @@ -3108,10 +3108,10 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf if (!cache || edit->totpoint != edit->totcached) { /* clear out old and create new empty path cache */ psys_free_path_cache(edit->psys, edit); - cache= edit->pathcache= psys_alloc_path_cache_buffers(&edit->pathcachebufs, totpart, steps+1); + cache = edit->pathcache = psys_alloc_path_cache_buffers(&edit->pathcachebufs, totpart, steps + 1); /* set flag for update (child particles check this too) */ - for (i=0, point=edit->points; i<totpart; i++, point++) + for (i = 0, point = edit->points; i < totpart; i++, point++) point->flag |= PEP_EDIT_RECALC; recalc_set = 1; } @@ -3119,7 +3119,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf /* frs_sec = (psys || edit->pid.flag & PTCACHE_VEL_PER_SEC) ? 25.0f : 1.0f; */ /* UNUSED */ if (pset->brushtype == PE_BRUSH_WEIGHT) { - ;/* use weight painting colors now... */ + ; /* use weight painting colors now... */ } else { sel_col[0] = (float)edit->sel_col[0] / 255.0f; @@ -3131,7 +3131,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf } /*---first main loop: create all actual particles' paths---*/ - for (i=0, point=edit->points; i<totpart; i++, pa+=pa?1:0, point++) { + for (i = 0, point = edit->points; i < totpart; i++, pa += pa ? 1 : 0, point++) { if (edit->totcached && !(point->flag & PEP_EDIT_RECALC)) continue; @@ -3148,14 +3148,14 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf /* should init_particle_interpolation set this ? */ - if (pset->brushtype==PE_BRUSH_WEIGHT) { + if (pset->brushtype == PE_BRUSH_WEIGHT) { pind.hkey[0] = NULL; /* pa != NULL since the weight brush is only available for hair */ pind.hkey[1] = pa->hair; } - memset(cache[i], 0, sizeof(*cache[i])*(steps+1)); + memset(cache[i], 0, sizeof(*cache[i]) * (steps + 1)); cache[i]->steps = steps; @@ -3178,14 +3178,14 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf } /*--interpolate actual path from data points--*/ - for (k=0, ca=cache[i]; k<=steps; k++, ca++) { + for (k = 0, ca = cache[i]; k <= steps; k++, ca++) { time = (float)k / (float)steps; t = birthtime + time * (dietime - birthtime); result.time = -t; do_particle_interpolation(psys, i, pa, t, &pind, &result); copy_v3_v3(ca->co, result.co); - /* non-hair points are already in global space */ + /* non-hair points are already in global space */ if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { mul_m4_v3(hairmat, ca->co); @@ -3198,7 +3198,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf /* set velocity */ sub_v3_v3v3(ca->vel, ca->co, (ca - 1)->co); - if (k==1) + if (k == 1) copy_v3_v3((ca - 1)->vel, ca->vel); } } @@ -3208,15 +3208,15 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf } /* selection coloring in edit mode */ - if (pset->brushtype==PE_BRUSH_WEIGHT) { + if (pset->brushtype == PE_BRUSH_WEIGHT) { float t2; - if (k==0) { + if (k == 0) { weight_to_rgb(ca->col, pind.hkey[1]->weight); } else { float w1[3], w2[3]; - keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); + keytime = (t - (*pind.ekey[0]->time)) / ((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); weight_to_rgb(w1, pind.hkey[0]->weight); weight_to_rgb(w2, pind.hkey[1]->weight); @@ -3226,7 +3226,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf /* at the moment this is only used for weight painting. * will need to move out of this check if its used elsewhere. */ - t2 = birthtime + ((float)k/(float)steps) * (dietime - birthtime); + t2 = birthtime + ((float)k / (float)steps) * (dietime - birthtime); while (pind.hkey[1]->time < t2) pind.hkey[1]++; pind.hkey[0] = pind.hkey[1] - 1; @@ -3237,13 +3237,13 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf copy_v3_v3(ca->col, sel_col); } else { - keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); + keytime = (t - (*pind.ekey[0]->time)) / ((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); interp_v3_v3v3(ca->col, sel_col, nosel_col, keytime); } } else { if ((ekey + (pind.ekey[1] - point->keys))->flag & PEK_SELECT) { - keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); + keytime = (t - (*pind.ekey[0]->time)) / ((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); interp_v3_v3v3(ca->col, nosel_col, sel_col, keytime); } else { @@ -3269,18 +3269,18 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf edit->totcached = totpart; if (psys) { - ParticleSimulationData sim= {0}; - sim.scene= scene; - sim.ob= ob; - sim.psys= psys; - sim.psmd= psys_get_modifier(ob, psys); + ParticleSimulationData sim = {0}; + sim.scene = scene; + sim.ob = ob; + sim.psys = psys; + sim.psmd = psys_get_modifier(ob, psys); psys_cache_child_paths(&sim, cfra, 1); } /* clear recalc flag if set here */ if (recalc_set) { - for (i=0, point=edit->points; i<totpart; i++, point++) + for (i = 0, point = edit->points; i < totpart; i++, point++) point->flag &= ~PEP_EDIT_RECALC; } } @@ -3293,9 +3293,9 @@ void copy_particle_key(ParticleKey *to, ParticleKey *from, int time) memcpy(to, from, sizeof(ParticleKey)); } else { - float to_time=to->time; + float to_time = to->time; memcpy(to, from, sizeof(ParticleKey)); - to->time=to_time; + to->time = to_time; } } void psys_get_from_key(ParticleKey *key, float *loc, float *vel, float *rot, float *time) @@ -3303,7 +3303,7 @@ void psys_get_from_key(ParticleKey *key, float *loc, float *vel, float *rot, flo if (loc) copy_v3_v3(loc, key->co); if (vel) copy_v3_v3(vel, key->vel); if (rot) copy_qt_qt(rot, key->rot); - if (time) *time=key->time; + if (time) *time = key->time; } /*-------changing particle keys from space to another-------*/ #if 0 @@ -3326,33 +3326,33 @@ static void triatomat(float *v1, float *v2, float *v3, float (*uv)[2], float mat { float det, w1, w2, d1[2], d2[2]; - memset(mat, 0, sizeof(float)*4*4); - mat[3][3]= 1.0f; + memset(mat, 0, sizeof(float) * 4 * 4); + mat[3][3] = 1.0f; /* first axis is the normal */ normal_tri_v3(mat[2], v1, v2, v3); /* second axis along (1, 0) in uv space */ if (uv) { - d1[0]= uv[1][0] - uv[0][0]; - d1[1]= uv[1][1] - uv[0][1]; - d2[0]= uv[2][0] - uv[0][0]; - d2[1]= uv[2][1] - uv[0][1]; + d1[0] = uv[1][0] - uv[0][0]; + d1[1] = uv[1][1] - uv[0][1]; + d2[0] = uv[2][0] - uv[0][0]; + d2[1] = uv[2][1] - uv[0][1]; - det = d2[0]*d1[1] - d2[1]*d1[0]; + det = d2[0] * d1[1] - d2[1] * d1[0]; if (det != 0.0f) { - det= 1.0f/det; - w1= -d2[1]*det; - w2= d1[1]*det; + det = 1.0f / det; + w1 = -d2[1] * det; + w2 = d1[1] * det; - mat[1][0]= w1*(v2[0] - v1[0]) + w2*(v3[0] - v1[0]); - mat[1][1]= w1*(v2[1] - v1[1]) + w2*(v3[1] - v1[1]); - mat[1][2]= w1*(v2[2] - v1[2]) + w2*(v3[2] - v1[2]); + mat[1][0] = w1 * (v2[0] - v1[0]) + w2 * (v3[0] - v1[0]); + mat[1][1] = w1 * (v2[1] - v1[1]) + w2 * (v3[1] - v1[1]); + mat[1][2] = w1 * (v2[2] - v1[2]) + w2 * (v3[2] - v1[2]); normalize_v3(mat[1]); } else - mat[1][0]= mat[1][1]= mat[1][2]= 0.0f; + mat[1][0] = mat[1][1] = mat[1][2] = 0.0f; } else { sub_v3_v3v3(mat[1], v2, v1); @@ -3370,14 +3370,14 @@ static void psys_face_mat(Object *ob, DerivedMesh *dm, ParticleData *pa, float m OrigSpaceFace *osface; float (*orcodata)[3]; - int i = pa->num_dmcache==DMCACHE_NOTFOUND ? pa->num : pa->num_dmcache; + int i = pa->num_dmcache == DMCACHE_NOTFOUND ? pa->num : pa->num_dmcache; - if (i==-1 || i >= dm->getNumTessFaces(dm)) { unit_m4(mat); return; } + if (i == -1 || i >= dm->getNumTessFaces(dm)) { unit_m4(mat); return; } - mface=dm->getTessFaceData(dm, i, CD_MFACE); - osface=dm->getTessFaceData(dm, i, CD_ORIGSPACE); + mface = dm->getTessFaceData(dm, i, CD_MFACE); + osface = dm->getTessFaceData(dm, i, CD_ORIGSPACE); - if (orco && (orcodata=dm->getVertDataArray(dm, CD_ORCO))) { + if (orco && (orcodata = dm->getVertDataArray(dm, CD_ORCO))) { copy_v3_v3(v[0], orcodata[mface->v1]); copy_v3_v3(v[1], orcodata[mface->v2]); copy_v3_v3(v[2], orcodata[mface->v3]); @@ -3393,7 +3393,7 @@ static void psys_face_mat(Object *ob, DerivedMesh *dm, ParticleData *pa, float m dm->getVertCo(dm, mface->v3, v[2]); } - triatomat(v[0], v[1], v[2], (osface)? osface->uv: NULL, mat); + triatomat(v[0], v[1], v[2], (osface) ? osface->uv : NULL, mat); } void psys_mat_hair_to_object(Object *UNUSED(ob), DerivedMesh *dm, short from, ParticleData *pa, float hairmat[][4]) @@ -3449,7 +3449,7 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *n return NULL; psys = ob->particlesystem.first; - for (; psys; psys=psys->next) + for (; psys; psys = psys->next) psys->flag &= ~PSYS_CURRENT; psys = MEM_callocN(sizeof(ParticleSystem), "particle_system"); @@ -3458,23 +3458,23 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *n psys->part = psys_new_settings("ParticleSettings", NULL); - if (BLI_countlist(&ob->particlesystem)>1) + if (BLI_countlist(&ob->particlesystem) > 1) BLI_snprintf(psys->name, sizeof(psys->name), "ParticleSystem %i", BLI_countlist(&ob->particlesystem)); else strcpy(psys->name, "ParticleSystem"); - md= modifier_new(eModifierType_ParticleSystem); + md = modifier_new(eModifierType_ParticleSystem); - if (name) BLI_strncpy(md->name, name, sizeof(md->name)); - else BLI_snprintf(md->name, sizeof(md->name), "ParticleSystem %i", BLI_countlist(&ob->particlesystem)); + if (name) BLI_strncpy(md->name, name, sizeof(md->name)); + else BLI_snprintf(md->name, sizeof(md->name), "ParticleSystem %i", BLI_countlist(&ob->particlesystem)); modifier_unique_name(&ob->modifiers, md); - psmd= (ParticleSystemModifierData*) md; - psmd->psys=psys; + psmd = (ParticleSystemModifierData *) md; + psmd->psys = psys; BLI_addtail(&ob->modifiers, md); - psys->totpart=0; - psys->flag = PSYS_ENABLED|PSYS_CURRENT; + psys->totpart = 0; + psys->flag = PSYS_ENABLED | PSYS_CURRENT; psys->cfra = BKE_scene_frame_get_from_ctime(scene, CFRA + 1); DAG_scene_sort(G.main, scene); @@ -3507,7 +3507,7 @@ void object_remove_particle_system(Scene *scene, Object *ob) } /* clear modifier */ - psmd= psys_get_modifier(ob, psys); + psmd = psys_get_modifier(ob, psys); BLI_remlink(&ob->modifiers, psmd); modifier_free((ModifierData *)psmd); @@ -3525,64 +3525,64 @@ void object_remove_particle_system(Scene *scene, Object *ob) } static void default_particle_settings(ParticleSettings *part) { - part->type= PART_EMITTER; - part->distr= PART_DISTR_JIT; + part->type = PART_EMITTER; + part->distr = PART_DISTR_JIT; part->draw_as = PART_DRAW_REND; part->ren_as = PART_DRAW_HALO; - part->bb_uv_split=1; - part->bb_align=PART_BB_VIEW; - part->bb_split_offset=PART_BB_OFF_LINEAR; - part->flag=PART_EDISTR|PART_TRAND|PART_HIDE_ADVANCED_HAIR; - - part->sta= 1.0; - part->end= 200.0; - part->lifetime= 50.0; - part->jitfac= 1.0; - part->totpart= 1000; - part->grid_res= 10; - part->timetweak= 1.0; + part->bb_uv_split = 1; + part->bb_align = PART_BB_VIEW; + part->bb_split_offset = PART_BB_OFF_LINEAR; + part->flag = PART_EDISTR | PART_TRAND | PART_HIDE_ADVANCED_HAIR; + + part->sta = 1.0; + part->end = 200.0; + part->lifetime = 50.0; + part->jitfac = 1.0; + part->totpart = 1000; + part->grid_res = 10; + part->timetweak = 1.0; part->courant_target = 0.2; - part->integrator= PART_INT_MIDPOINT; - part->phystype= PART_PHYS_NEWTON; - part->hair_step= 5; - part->keys_step= 5; - part->draw_step= 2; - part->ren_step= 3; - part->adapt_angle= 5; - part->adapt_pix= 3; - part->kink_axis= 2; - part->kink_amp_clump= 1.f; - part->reactevent= PART_EVENT_DEATH; - part->disp=100; - part->from= PART_FROM_FACE; - - part->normfac= 1.0f; - - part->mass=1.0; - part->size=0.05; - part->childsize=1.0; + part->integrator = PART_INT_MIDPOINT; + part->phystype = PART_PHYS_NEWTON; + part->hair_step = 5; + part->keys_step = 5; + part->draw_step = 2; + part->ren_step = 3; + part->adapt_angle = 5; + part->adapt_pix = 3; + part->kink_axis = 2; + part->kink_amp_clump = 1.f; + part->reactevent = PART_EVENT_DEATH; + part->disp = 100; + part->from = PART_FROM_FACE; + + part->normfac = 1.0f; + + part->mass = 1.0; + part->size = 0.05; + part->childsize = 1.0; part->rotmode = PART_ROT_VEL; part->avemode = PART_AVE_VELOCITY; - part->child_nbr=10; - part->ren_child_nbr=100; - part->childrad=0.2f; - part->childflat=0.0f; - part->clumppow=0.0f; - part->kink_amp=0.2f; - part->kink_freq=2.0; + part->child_nbr = 10; + part->ren_child_nbr = 100; + part->childrad = 0.2f; + part->childflat = 0.0f; + part->clumppow = 0.0f; + part->kink_amp = 0.2f; + part->kink_freq = 2.0; - part->rough1_size=1.0; - part->rough2_size=1.0; - part->rough_end_shape=1.0; + part->rough1_size = 1.0; + part->rough2_size = 1.0; + part->rough_end_shape = 1.0; - part->clength=1.0f; - part->clength_thres=0.0f; + part->clength = 1.0f; + part->clength_thres = 0.0f; - part->draw= PART_DRAW_EMITTER; - part->draw_line[0]=0.5; + part->draw = PART_DRAW_EMITTER; + part->draw_line[0] = 0.5; part->path_start = 0.0f; part->path_end = 1.0f; @@ -3593,10 +3593,10 @@ static void default_particle_settings(ParticleSettings *part) part->color_vec_max = 1.f; part->draw_col = PART_DRAW_COL_MAT; - part->simplify_refsize= 1920; - part->simplify_rate= 1.0f; - part->simplify_transition= 0.1f; - part->simplify_viewport= 0.8; + part->simplify_refsize = 1920; + part->simplify_rate = 1.0f; + part->simplify_transition = 0.1f; + part->simplify_viewport = 0.8; if (!part->effector_weights) part->effector_weights = BKE_add_effector_weights(NULL); @@ -3607,10 +3607,10 @@ ParticleSettings *psys_new_settings(const char *name, Main *main) { ParticleSettings *part; - if (main==NULL) + if (main == NULL) main = G.main; - part= BKE_libblock_alloc(&main->particle, ID_PA, name); + part = BKE_libblock_alloc(&main->particle, ID_PA, name); default_particle_settings(part); @@ -3622,17 +3622,17 @@ ParticleSettings *BKE_particlesettings_copy(ParticleSettings *part) ParticleSettings *partn; int a; - partn= BKE_libblock_copy(&part->id); - partn->pd= MEM_dupallocN(part->pd); - partn->pd2= MEM_dupallocN(part->pd2); - partn->effector_weights= MEM_dupallocN(part->effector_weights); - partn->fluid= MEM_dupallocN(part->fluid); + partn = BKE_libblock_copy(&part->id); + partn->pd = MEM_dupallocN(part->pd); + partn->pd2 = MEM_dupallocN(part->pd2); + partn->effector_weights = MEM_dupallocN(part->effector_weights); + partn->fluid = MEM_dupallocN(part->fluid); partn->boids = boid_copy_settings(part->boids); - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (part->mtex[a]) { - partn->mtex[a]= MEM_mallocN(sizeof(MTex), "psys_copy_tex"); + partn->mtex[a] = MEM_mallocN(sizeof(MTex), "psys_copy_tex"); memcpy(partn->mtex[a], part->mtex[a], sizeof(MTex)); id_us_plus((ID *)partn->mtex[a]->tex); } @@ -3648,57 +3648,57 @@ static void expand_local_particlesettings(ParticleSettings *part) int i; id_lib_extern((ID *)part->dup_group); - for (i=0; i<MAX_MTEX; i++) { + for (i = 0; i < MAX_MTEX; i++) { if (part->mtex[i]) id_lib_extern((ID *)part->mtex[i]->tex); } } void BKE_particlesettings_make_local(ParticleSettings *part) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (part->id.lib==0) return; - if (part->id.us==1) { + if (part->id.lib == 0) return; + if (part->id.us == 1) { id_clear_lib_data(bmain, &part->id); expand_local_particlesettings(part); return; } /* test objects */ - 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) is_lib= TRUE; - else is_local= TRUE; + 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) is_lib = TRUE; + else is_local = TRUE; } } } - if (is_local && is_lib==FALSE) { + if (is_local && is_lib == FALSE) { id_clear_lib_data(bmain, &part->id); expand_local_particlesettings(part); } else if (is_local && is_lib) { - ParticleSettings *part_new= BKE_particlesettings_copy(part); - part_new->id.us= 0; + ParticleSettings *part_new = BKE_particlesettings_copy(part); + part_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, part->id.lib, &part_new->id); /* do objects */ - for (ob= bmain->object.first; ob; ob= ob->id.next) { + for (ob = bmain->object.first; ob; ob = ob->id.next) { ParticleSystem *psys; - for (psys= ob->particlesystem.first; psys; psys=psys->next) { - if (psys->part==part && ob->id.lib==0) { - psys->part= part_new; + for (psys = ob->particlesystem.first; psys; psys = psys->next) { + if (psys->part == part && ob->id.lib == 0) { + psys->part = part_new; part_new->id.us++; part->id.us--; } @@ -3717,42 +3717,42 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, co MTFace *tf; int i; - tf= CustomData_get_layer_named(&dm->faceData, CD_MTFACE, name); + tf = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, name); if (tf == NULL) - tf= CustomData_get_layer(&dm->faceData, CD_MTFACE); + tf = CustomData_get_layer(&dm->faceData, CD_MTFACE); if (tf == NULL) return 0; if (pa) { - i= (pa->num_dmcache==DMCACHE_NOTFOUND)? pa->num: pa->num_dmcache; + i = (pa->num_dmcache == DMCACHE_NOTFOUND) ? pa->num : pa->num_dmcache; if (i >= dm->getNumTessFaces(dm)) i = -1; } else - i= face_index; + i = face_index; - if (i==-1) { - texco[0]= 0.0f; - texco[1]= 0.0f; - texco[2]= 0.0f; + if (i == -1) { + texco[0] = 0.0f; + texco[1] = 0.0f; + texco[2] = 0.0f; } else { - mf= dm->getTessFaceData(dm, i, CD_MFACE); + mf = dm->getTessFaceData(dm, i, CD_MFACE); psys_interpolate_uvs(&tf[i], mf->v4, fuv, texco); - texco[0]= texco[0]*2.0f - 1.0f; - texco[1]= texco[1]*2.0f - 1.0f; - texco[2]= 0.0f; + texco[0] = texco[0] * 2.0f - 1.0f; + texco[1] = texco[1] * 2.0f - 1.0f; + texco[2] = 0.0f; } return 1; } -#define SET_PARTICLE_TEXTURE(type, pvalue, texfac) if ((event & mtex->mapto) & type) {pvalue = texture_value_blend(def, pvalue, value, texfac, blend);} -#define CLAMP_PARTICLE_TEXTURE_POS(type, pvalue) if (event & type) { if (pvalue < 0.f) pvalue = 1.f+pvalue; CLAMP(pvalue, 0.0f, 1.0f); } +#define SET_PARTICLE_TEXTURE(type, pvalue, texfac) if ((event & mtex->mapto) & type) {pvalue = texture_value_blend(def, pvalue, value, texfac, blend); } +#define CLAMP_PARTICLE_TEXTURE_POS(type, pvalue) if (event & type) { if (pvalue < 0.f) pvalue = 1.f + pvalue; CLAMP(pvalue, 0.0f, 1.0f); } #define CLAMP_PARTICLE_TEXTURE_POSNEG(type, pvalue) if (event & type) { CLAMP(pvalue, -1.0f, 1.0f); } static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSettings *part, ParticleData *par, int child_index, int face_index, const float fw[4], float *orco, ParticleTexture *ptex, int event, float cfra) @@ -3762,50 +3762,50 @@ static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSetti float value, rgba[4], texvec[3]; ptex->ivel = ptex->life = ptex->exist = ptex->size = ptex->damp = - ptex->gravity = ptex->field = ptex->time = ptex->clump = ptex->kink = - ptex->effector = ptex->rough1 = ptex->rough2 = ptex->roughe = 1.f; + ptex->gravity = ptex->field = ptex->time = ptex->clump = ptex->kink = + ptex->effector = ptex->rough1 = ptex->rough2 = ptex->roughe = 1.f; - ptex->length= 1.0f - part->randlength * PSYS_FRAND(child_index + 26); - ptex->length*= part->clength_thres < PSYS_FRAND(child_index + 27) ? part->clength : 1.0f; + ptex->length = 1.0f - part->randlength *PSYS_FRAND(child_index + 26); + ptex->length *= part->clength_thres < PSYS_FRAND(child_index + 27) ? part->clength : 1.0f; - for (m=0; m<MAX_MTEX; m++, mtexp++) { + for (m = 0; m < MAX_MTEX; m++, mtexp++) { mtex = *mtexp; if (mtex && mtex->mapto) { - float def=mtex->def_var; - short blend=mtex->blendtype; + float def = mtex->def_var; + short blend = mtex->blendtype; short texco = mtex->texco; if (ELEM(texco, TEXCO_UV, TEXCO_ORCO) && (ELEM(part->from, PART_FROM_FACE, PART_FROM_VOLUME) == 0 || part->distr == PART_DISTR_GRID)) texco = TEXCO_GLOB; switch (texco) { - case TEXCO_GLOB: - copy_v3_v3(texvec, par->state.co); - break; - case TEXCO_OBJECT: - copy_v3_v3(texvec, par->state.co); - if (mtex->object) - mul_m4_v3(mtex->object->imat, texvec); - break; - case TEXCO_UV: - if (fw && get_particle_uv(dm, NULL, face_index, fw, mtex->uvname, texvec)) + case TEXCO_GLOB: + copy_v3_v3(texvec, par->state.co); break; + case TEXCO_OBJECT: + copy_v3_v3(texvec, par->state.co); + if (mtex->object) + mul_m4_v3(mtex->object->imat, texvec); + break; + case TEXCO_UV: + if (fw && get_particle_uv(dm, NULL, face_index, fw, mtex->uvname, texvec)) + break; /* no break, failed to get uv's, so let's try orco's */ - case TEXCO_ORCO: - copy_v3_v3(texvec, orco); - break; - case TEXCO_PARTICLE: - /* texture coordinates in range [-1, 1] */ - texvec[0] = 2.f * (cfra - par->time)/(par->dietime-par->time) - 1.f; - texvec[1] = 0.f; - texvec[2] = 0.f; - break; + case TEXCO_ORCO: + copy_v3_v3(texvec, orco); + break; + case TEXCO_PARTICLE: + /* texture coordinates in range [-1, 1] */ + texvec[0] = 2.f * (cfra - par->time) / (par->dietime - par->time) - 1.f; + texvec[1] = 0.f; + texvec[2] = 0.f; + break; } - externtex(mtex, texvec, &value, rgba, rgba+1, rgba+2, rgba+3, 0); + externtex(mtex, texvec, &value, rgba, rgba + 1, rgba + 2, rgba + 3, 0); if ((event & mtex->mapto) & PAMAP_ROUGH) - ptex->rough1= ptex->rough2= ptex->roughe= texture_value_blend(def, ptex->rough1, value, mtex->roughfac, blend); + ptex->rough1 = ptex->rough2 = ptex->roughe = texture_value_blend(def, ptex->rough1, value, mtex->roughfac, blend); SET_PARTICLE_TEXTURE(PAMAP_LENGTH, ptex->length, mtex->lengthfac); SET_PARTICLE_TEXTURE(PAMAP_CLUMP, ptex->clump, mtex->clumpfac); @@ -3827,62 +3827,62 @@ void psys_get_texture(ParticleSimulationData *sim, ParticleData *pa, ParticleTex MTex *mtex; int m; float value, rgba[4], co[3], texvec[3]; - int setvars=0; + int setvars = 0; /* initialize ptex */ ptex->ivel = ptex->life = ptex->exist = ptex->size = ptex->damp = - ptex->gravity = ptex->field = ptex->length = ptex->clump = ptex->kink = - ptex->effector = ptex->rough1 = ptex->rough2 = ptex->roughe = 1.f; + ptex->gravity = ptex->field = ptex->length = ptex->clump = ptex->kink = + ptex->effector = ptex->rough1 = ptex->rough2 = ptex->roughe = 1.0f; - ptex->time = (float)(pa - sim->psys->particles)/(float)sim->psys->totpart; + ptex->time = (float)(pa - sim->psys->particles) / (float)sim->psys->totpart; - for (m=0; m<MAX_MTEX; m++, mtexp++) { + for (m = 0; m < MAX_MTEX; m++, mtexp++) { mtex = *mtexp; if (mtex && mtex->mapto) { - float def=mtex->def_var; - short blend=mtex->blendtype; + float def = mtex->def_var; + short blend = mtex->blendtype; short texco = mtex->texco; if (texco == TEXCO_UV && (ELEM(part->from, PART_FROM_FACE, PART_FROM_VOLUME) == 0 || part->distr == PART_DISTR_GRID)) texco = TEXCO_GLOB; switch (texco) { - case TEXCO_GLOB: - copy_v3_v3(texvec, pa->state.co); - break; - case TEXCO_OBJECT: - copy_v3_v3(texvec, pa->state.co); - if (mtex->object) - mul_m4_v3(mtex->object->imat, texvec); - break; - case TEXCO_UV: - if (get_particle_uv(sim->psmd->dm, pa, 0, pa->fuv, mtex->uvname, texvec)) + case TEXCO_GLOB: + copy_v3_v3(texvec, pa->state.co); + break; + case TEXCO_OBJECT: + copy_v3_v3(texvec, pa->state.co); + if (mtex->object) + mul_m4_v3(mtex->object->imat, texvec); break; + case TEXCO_UV: + if (get_particle_uv(sim->psmd->dm, pa, 0, pa->fuv, mtex->uvname, texvec)) + break; /* no break, failed to get uv's, so let's try orco's */ - case TEXCO_ORCO: - psys_particle_on_emitter(sim->psmd, sim->psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co, 0, 0, 0, texvec, 0); - break; - case TEXCO_PARTICLE: - /* texture coordinates in range [-1, 1] */ - texvec[0] = 2.f * (cfra - pa->time)/(pa->dietime-pa->time) - 1.f; - texvec[1] = 0.f; - texvec[2] = 0.f; - break; + case TEXCO_ORCO: + psys_particle_on_emitter(sim->psmd, sim->psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co, 0, 0, 0, texvec, 0); + break; + case TEXCO_PARTICLE: + /* texture coordinates in range [-1, 1] */ + texvec[0] = 2.f * (cfra - pa->time) / (pa->dietime - pa->time) - 1.f; + texvec[1] = 0.f; + texvec[2] = 0.f; + break; } - externtex(mtex, texvec, &value, rgba, rgba+1, rgba+2, rgba+3, 0); + externtex(mtex, texvec, &value, rgba, rgba + 1, rgba + 2, rgba + 3, 0); if ((event & mtex->mapto) & PAMAP_TIME) { /* the first time has to set the base value for time regardless of blend mode */ - if ((setvars&MAP_PA_TIME)==0) { - int flip= (mtex->timefac < 0.0f); - float timefac= fabsf(mtex->timefac); + if ((setvars & MAP_PA_TIME) == 0) { + int flip = (mtex->timefac < 0.0f); + float timefac = fabsf(mtex->timefac); ptex->time *= 1.0f - timefac; - ptex->time += timefac * ((flip)? 1.0f - value : value); + ptex->time += timefac * ((flip) ? 1.0f - value : value); setvars |= MAP_PA_TIME; } else - ptex->time= texture_value_blend(def, ptex->time, value, mtex->timefac, blend); + ptex->time = texture_value_blend(def, ptex->time, value, mtex->timefac, blend); } SET_PARTICLE_TEXTURE(PAMAP_LIFE, ptex->life, mtex->lifefac) SET_PARTICLE_TEXTURE(PAMAP_DENS, ptex->exist, mtex->padensfac) @@ -3917,11 +3917,11 @@ float psys_get_child_time(ParticleSystem *psys, ChildParticle *cpa, float cfra, ParticleSettings *part = psys->part; float time, life; - if (part->childtype==PART_CHILD_FACES) { - int w=0; - time=0.0; - while (w<4 && cpa->pa[w]>=0) { - time+=cpa->w[w]*(psys->particles+cpa->pa[w])->time; + if (part->childtype == PART_CHILD_FACES) { + int w = 0; + time = 0.0; + while (w < 4 && cpa->pa[w] >= 0) { + time += cpa->w[w] * (psys->particles + cpa->pa[w])->time; w++; } @@ -3937,24 +3937,24 @@ float psys_get_child_time(ParticleSystem *psys, ChildParticle *cpa, float cfra, if (birthtime) *birthtime = time; if (dietime) - *dietime = time+life; + *dietime = time + life; - return (cfra-time)/life; + return (cfra - time) / life; } float psys_get_child_size(ParticleSystem *psys, ChildParticle *cpa, float UNUSED(cfra), float *UNUSED(pa_time)) { ParticleSettings *part = psys->part; float size; // time XXX - if (part->childtype==PART_CHILD_FACES) - size=part->size; + if (part->childtype == PART_CHILD_FACES) + size = part->size; else - size=psys->particles[cpa->parent].size; + size = psys->particles[cpa->parent].size; - size*=part->childsize; + size *= part->childsize; if (part->childrandsize != 0.0f) - size *= 1.0f - part->childrandsize * PSYS_FRAND(cpa - psys->child + 26); + size *= 1.0f - part->childrandsize *PSYS_FRAND(cpa - psys->child + 26); return size; } @@ -3963,26 +3963,26 @@ static void get_child_modifier_parameters(ParticleSettings *part, ParticleThread ParticleSystem *psys = ctx->sim.psys; int i = cpa - psys->child; - get_cpa_texture(ctx->dm, psys, part, psys->particles + cpa->pa[0], i, cpa_num, cpa_fuv, orco, ptex, PAMAP_DENS|PAMAP_CHILD, psys->cfra); + get_cpa_texture(ctx->dm, psys, part, psys->particles + cpa->pa[0], i, cpa_num, cpa_fuv, orco, ptex, PAMAP_DENS | PAMAP_CHILD, psys->cfra); if (ptex->exist < PSYS_FRAND(i + 24)) return; if (ctx->vg_length) - ptex->length*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_length); + ptex->length *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_length); if (ctx->vg_clump) - ptex->clump*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_clump); + ptex->clump *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_clump); if (ctx->vg_kink) - ptex->kink*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_kink); + ptex->kink *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_kink); if (ctx->vg_rough1) - ptex->rough1*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_rough1); + ptex->rough1 *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_rough1); if (ctx->vg_rough2) - ptex->rough2*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_rough2); + ptex->rough2 *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_rough2); if (ctx->vg_roughe) - ptex->roughe*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_roughe); + ptex->roughe *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_roughe); if (ctx->vg_effector) - ptex->effector*=psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_effector); + ptex->effector *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_effector); } static void do_child_modifiers(ParticleSimulationData *sim, ParticleTexture *ptex, ParticleKey *par, float *par_rot, ChildParticle *cpa, float *orco, float mat[4][4], ParticleKey *state, float t) { @@ -4004,17 +4004,17 @@ static void do_child_modifiers(ParticleSimulationData *sim, ParticleTexture *pte if (part->flag & PART_CHILD_EFFECT) /* state is safe to cast, since only co and vel are used */ - guided = do_guides(sim->psys->effectors, (ParticleKey*)state, cpa->parent, t); + guided = do_guides(sim->psys->effectors, (ParticleKey *)state, cpa->parent, t); - if (guided==0) { + if (guided == 0) { float clump = do_clump(state, par, t, part->clumpfac, part->clumppow, ptex ? ptex->clump : 1.f); if (kink_freq != 0.f) { float kink_amp = part->kink_amp * (1.f - part->kink_amp_clump * clump); do_kink(state, par, par_rot, t, kink_freq, part->kink_shape, - kink_amp, part->kink_flat, part->kink, part->kink_axis, - sim->ob->obmat, sim->psys->part->childtype == PART_CHILD_FACES); + kink_amp, part->kink_flat, part->kink, part->kink_axis, + sim->ob->obmat, sim->psys->part->childtype == PART_CHILD_FACES); } } @@ -4037,7 +4037,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * ParticleData *pa; ChildParticle *cpa; ParticleTexture ptex; - ParticleKey *par=0, keys[4], tstate; + ParticleKey *par = 0, keys[4], tstate; ParticleThreadContext ctx; /* fake thread context for child modifiers */ ParticleInterpolationData pind; @@ -4054,12 +4054,12 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * float *cpa_fuv; int cpa_num; short cpa_from; /* initialize keys to zero */ - memset(keys, 0, 4*sizeof(ParticleKey)); + memset(keys, 0, 4 * sizeof(ParticleKey)); - t=state->time; + t = state->time; CLAMP(t, 0.0f, 1.0f); - if (p<totpart) { + if (p < totpart) { /* interpolate pathcache directly if it exist */ if (psys->pathcache) { ParticleCacheKey result; @@ -4087,17 +4087,17 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * mul_mat3_m4_v3(sim->ob->obmat, state->vel); } else if (!keyed && !cached && !(psys->flag & PSYS_GLOBAL_HAIR)) { - if ((pa->flag & PARS_REKEY)==0) { + if ((pa->flag & PARS_REKEY) == 0) { psys_mat_hair_to_global(sim->ob, sim->psmd->dm, part->from, pa, hairmat); mul_m4_v3(hairmat, state->co); mul_mat3_m4_v3(hairmat, state->vel); - if (sim->psys->effectors && (part->flag & PART_CHILD_GUIDE)==0) { + if (sim->psys->effectors && (part->flag & PART_CHILD_GUIDE) == 0) { do_guides(sim->psys->effectors, state, p, state->time); /* TODO: proper velocity handling */ } - if (psys->lattice && edit==0) + if (psys->lattice && edit == 0) calc_latt_deform(psys->lattice, state->co, 1.0f); } } @@ -4109,36 +4109,36 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * /* interpolate childcache directly if it exists */ if (psys->childcache) { ParticleCacheKey result; - interpolate_pathcache(psys->childcache[p-totpart], t, &result); + interpolate_pathcache(psys->childcache[p - totpart], t, &result); copy_v3_v3(state->co, result.co); copy_v3_v3(state->vel, result.vel); copy_qt_qt(state->rot, result.rot); } else { - cpa=psys->child+p-totpart; + cpa = psys->child + p - totpart; if (state->time < 0.0f) t = psys_get_child_time(psys, cpa, -state->time, NULL, NULL); - if (totchild && part->childtype==PART_CHILD_FACES) { + if (totchild && part->childtype == PART_CHILD_FACES) { /* part->parents could still be 0 so we can't test with totparent */ - between=1; + between = 1; } if (between) { int w = 0; float foffset; /* get parent states */ - while (w<4 && cpa->pa[w]>=0) { + while (w < 4 && cpa->pa[w] >= 0) { keys[w].time = state->time; - psys_get_particle_on_path(sim, cpa->pa[w], keys+w, 1); + psys_get_particle_on_path(sim, cpa->pa[w], keys + w, 1); w++; } /* get the original coordinates (orco) for texture usage */ - cpa_num=cpa->num; + cpa_num = cpa->num; - foffset= cpa->foffset; + foffset = cpa->foffset; cpa_fuv = cpa->fuv; cpa_from = PART_FROM_FACE; @@ -4156,7 +4156,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * else unit_m4(hairmat); - pa=0; + pa = 0; } else { /* get the parent state */ @@ -4164,11 +4164,11 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * psys_get_particle_on_path(sim, cpa->parent, keys, 1); /* get the original coordinates (orco) for texture usage */ - pa=psys->particles+cpa->parent; + pa = psys->particles + cpa->parent; - cpa_from=part->from; - cpa_num=pa->num; - cpa_fuv=pa->fuv; + cpa_from = part->from; + cpa_num = pa->num; + cpa_fuv = pa->fuv; @@ -4184,8 +4184,8 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * /* correct child ipo timing */ #if 0 // XXX old animation system - if ((part->flag&PART_ABS_TIME)==0 && part->ipo) { - calc_ipo(part->ipo, 100.0f*t); + if ((part->flag & PART_ABS_TIME) == 0 && part->ipo) { + calc_ipo(part->ipo, 100.0f * t); execute_ipo((ID *)part, part->ipo); } #endif // XXX old animation system @@ -4199,13 +4199,13 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * get_child_modifier_parameters(part, &ctx, cpa, cpa_from, cpa_num, cpa_fuv, orco, &ptex); if (between) { - int w=0; + int w = 0; state->co[0] = state->co[1] = state->co[2] = 0.0f; state->vel[0] = state->vel[1] = state->vel[2] = 0.0f; /* child position is the weighted sum of parent positions */ - while (w<4 && cpa->pa[w]>=0) { + while (w < 4 && cpa->pa[w] >= 0) { state->co[0] += cpa->w[w] * keys[w].co[0]; state->co[1] += cpa->w[w] * keys[w].co[1]; state->co[2] += cpa->w[w] * keys[w].co[2]; @@ -4236,14 +4236,14 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * ParticleKey tstate; float length = len_v3(state->vel); - if (t>=0.001f) { - tstate.time=t-0.001f; + if (t >= 0.001f) { + tstate.time = t - 0.001f; psys_get_particle_on_path(sim, p, &tstate, 0); sub_v3_v3v3(state->vel, state->co, tstate.co); normalize_v3(state->vel); } else { - tstate.time=t+0.001f; + tstate.time = t + 0.001f; psys_get_particle_on_path(sim, p, &tstate, 0); sub_v3_v3v3(state->vel, tstate.co, state->co); normalize_v3(state->vel); @@ -4268,7 +4268,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta /* negative time means "use current time" */ cfra = state->time > 0 ? state->time : BKE_scene_frame_get(sim->scene); - if (p>=totpart) { + if (p >= totpart) { if (!psys->totchild) return 0; @@ -4288,7 +4288,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta } } - state->time= (cfra - (part->sta + (part->end - part->sta) * PSYS_FRAND(p + 23))) / (part->lifetime * PSYS_FRAND(p + 24)); + state->time = (cfra - (part->sta + (part->end - part->sta) * PSYS_FRAND(p + 23))) / (part->lifetime * PSYS_FRAND(p + 24)); psys_get_particle_on_path(sim, p, state, 1); return 1; @@ -4315,7 +4315,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta } if (sim->psys->flag & PSYS_KEYED) { - state->time= -cfra; + state->time = -cfra; psys_get_particle_on_path(sim, p, state, 1); return 1; } @@ -4325,7 +4325,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta ParticleKey *key1; float t = (cfra - pa->time) / pa->lifetime; - key1=&pa->state; + key1 = &pa->state; offset_child(cpa, key1, key1->rot, state, part->childflat, part->childrad); CLAMP(t, 0.0f, 1.0f); @@ -4337,9 +4337,9 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta calc_latt_deform(sim->psys->lattice, state->co, 1.0f); } else { - if (pa->state.time==cfra || ELEM(part->phystype, PART_PHYS_NO, PART_PHYS_KEYED)) + if (pa->state.time == cfra || ELEM(part->phystype, PART_PHYS_NO, PART_PHYS_KEYED)) copy_particle_key(state, &pa->state, 1); - else if (pa->prev_state.time==cfra) + else if (pa->prev_state.time == cfra) copy_particle_key(state, &pa->prev_state, 1); else { float dfra, frs_sec = sim->scene->r.frs_sec; @@ -4351,14 +4351,14 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta copy_particle_key(state, &pa->state, 1); - madd_v3_v3v3fl(state->co, state->co, state->vel, dfra/frs_sec); + madd_v3_v3v3fl(state->co, state->co, state->vel, dfra / frs_sec); } else { ParticleKey keys[4]; float keytime; - copy_particle_key(keys+1, &pa->prev_state, 1); - copy_particle_key(keys+2, &pa->state, 1); + copy_particle_key(keys + 1, &pa->prev_state, 1); + copy_particle_key(keys + 2, &pa->state, 1); dfra = keys[2].time - keys[1].time; @@ -4384,7 +4384,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta copy_particle_key(state, &pa->state, 1); - madd_v3_v3v3fl(state->co, state->co, state->vel, dfra/frs_sec); + madd_v3_v3v3fl(state->co, state->co, state->vel, dfra / frs_sec); } else { /* extrapolating over big ranges is not accurate so let's just give something close to reasonable back */ @@ -4411,9 +4411,9 @@ void psys_get_dupli_texture(ParticleSystem *psys, ParticleSettings *part, Partic if (cpa) { if (part->childtype == PART_CHILD_FACES) { - mtface= CustomData_get_layer(&psmd->dm->faceData, CD_MTFACE); + mtface = CustomData_get_layer(&psmd->dm->faceData, CD_MTFACE); if (mtface) { - mface= psmd->dm->getTessFaceData(psmd->dm, cpa->num, CD_MFACE); + mface = psmd->dm->getTessFaceData(psmd->dm, cpa->num, CD_MFACE); mtface += cpa->num; psys_interpolate_uvs(mtface, mface->v4, cpa->fuv, uv); } @@ -4427,20 +4427,20 @@ void psys_get_dupli_texture(ParticleSystem *psys, ParticleSettings *part, Partic } if (part->from == PART_FROM_FACE) { - mtface= CustomData_get_layer(&psmd->dm->faceData, CD_MTFACE); - num= pa->num_dmcache; + mtface = CustomData_get_layer(&psmd->dm->faceData, CD_MTFACE); + num = pa->num_dmcache; if (num == DMCACHE_NOTFOUND) - num= pa->num; + num = pa->num; if (num >= psmd->dm->getNumTessFaces(psmd->dm)) { /* happens when simplify is enabled * gives invalid coords but would crash otherwise */ - num= DMCACHE_NOTFOUND; + num = DMCACHE_NOTFOUND; } if (mtface && num != DMCACHE_NOTFOUND) { - mface= psmd->dm->getTessFaceData(psmd->dm, num, CD_MFACE); + mface = psmd->dm->getTessFaceData(psmd->dm, num, CD_MFACE); mtface += num; psys_interpolate_uvs(mtface, mface->v4, pa->fuv, uv); } @@ -4457,8 +4457,8 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa float loc[3], nor[3], vec[3], side[3], len; float xvec[3] = {-1.0, 0.0, 0.0}, nmat[3][3]; - sub_v3_v3v3(vec, (cache+cache->steps)->co, cache->co); - len= normalize_v3(vec); + sub_v3_v3v3(vec, (cache + cache->steps)->co, cache->co); + len = normalize_v3(vec); if (pa == NULL && psys->part->childflat != PART_CHILD_FACES) pa = psys->particles + cpa->pa[0]; @@ -4475,8 +4475,8 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa normalize_v3(nor); /* make sure that we get a proper side vector */ - if (fabs(dot_v3v3(nor, vec))>0.999999) { - if (fabs(dot_v3v3(nor, xvec))>0.999999) { + if (fabs(dot_v3v3(nor, vec)) > 0.999999) { + if (fabs(dot_v3v3(nor, xvec)) > 0.999999) { nor[0] = 0.0f; nor[1] = 1.0f; nor[2] = 0.0f; @@ -4495,8 +4495,8 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa float q_phase[4]; float phasefac = psys->part->phasefac; if (psys->part->randphasefac != 0.0f) - phasefac += psys->part->randphasefac * PSYS_FRAND((pa-psys->particles) + 20); - axis_angle_to_quat(q_phase, vec, phasefac*(float)M_PI); + phasefac += psys->part->randphasefac * PSYS_FRAND((pa - psys->particles) + 20); + axis_angle_to_quat(q_phase, vec, phasefac * (float)M_PI); mul_qt_v3(q_phase, side); } @@ -4512,7 +4512,7 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa quat_to_mat4(mat, pa->state.rot); } - *scale= len; + *scale = len; } void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3], float zvec[3], float center[3]) @@ -4525,7 +4525,7 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3] /* can happen with bad pointcache or physics calculation * since this becomes geometry, nan's and inf's crash raytrace code. * better not allow this. */ - if ( !finite(bb->vec[0]) || !finite(bb->vec[1]) || !finite(bb->vec[2]) || + if (!finite(bb->vec[0]) || !finite(bb->vec[1]) || !finite(bb->vec[2]) || !finite(bb->vel[0]) || !finite(bb->vel[1]) || !finite(bb->vel[2]) ) { zero_v3(bb->vec); @@ -4540,7 +4540,7 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3] } if (bb->align < PART_BB_VIEW) - onevec[bb->align]=1.0f; + onevec[bb->align] = 1.0f; if (bb->lock && (bb->align == PART_BB_VIEW)) { normalize_v3_v3(xvec, bb->ob->obmat[0]); @@ -4601,11 +4601,11 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3] void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys) { - ParticleSimulationData sim= {0}; - sim.scene= scene; - sim.ob= ob; - sim.psys= psys; - sim.psmd= psys_get_modifier(ob, psys); + ParticleSimulationData sim = {0}; + sim.scene = scene; + sim.ob = ob; + sim.psys = psys; + sim.psmd = psys_get_modifier(ob, psys); psys->lattice = psys_get_lattice(&sim); @@ -4615,12 +4615,12 @@ void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys) int p, h; float hairmat[4][4], imat[4][4]; - for (p=0; p<psys->totpart; p++, pa++) { + for (p = 0; p < psys->totpart; p++, pa++) { psys_mat_hair_to_global(sim.ob, sim.psmd->dm, psys->part->from, pa, hairmat); invert_m4_m4(imat, hairmat); hkey = pa->hair; - for (h=0; h<pa->totkey; h++, hkey++) { + for (h = 0; h < pa->totkey; h++, hkey++) { mul_m4_v3(hairmat, hkey->co); calc_latt_deform(psys->lattice, hkey->co, 1.0f); mul_m4_v3(imat, hkey->co); @@ -4628,7 +4628,7 @@ void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys) } end_latt_deform(psys->lattice); - psys->lattice= NULL; + psys->lattice = NULL; /* protect the applied shape */ psys->flag |= PSYS_EDITED; diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 37d7cc06fe7..968f49357e6 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -118,20 +118,20 @@ Scene *BKE_scene_copy(Scene *sce, int type) if (type == SCE_COPY_EMPTY) { ListBase lb; - scen= BKE_scene_add(sce->id.name+2); + scen = BKE_scene_add(sce->id.name + 2); - lb= scen->r.layers; - scen->r= sce->r; - scen->r.layers= lb; - scen->unit= sce->unit; - scen->physics_settings= sce->physics_settings; - scen->gm= sce->gm; - scen->audio= sce->audio; + lb = scen->r.layers; + scen->r = sce->r; + scen->r.layers = lb; + scen->unit = sce->unit; + scen->physics_settings = sce->physics_settings; + scen->gm = sce->gm; + scen->audio = sce->audio; MEM_freeN(scen->toolsettings); } else { - scen= BKE_libblock_copy(&sce->id); + scen = BKE_libblock_copy(&sce->id); BLI_duplicatelist(&(scen->base), &(sce->base)); clear_id_newpoins(); @@ -140,11 +140,11 @@ Scene *BKE_scene_copy(Scene *sce, int type) id_us_plus((ID *)scen->set); id_us_plus((ID *)scen->gm.dome.warptext); - scen->ed= NULL; - scen->theDag= NULL; - scen->obedit= NULL; - scen->stats= NULL; - scen->fps_info= NULL; + scen->ed = NULL; + scen->theDag = NULL; + scen->obedit = NULL; + scen->stats = NULL; + scen->fps_info = NULL; BLI_duplicatelist(&(scen->markers), &(sce->markers)); BLI_duplicatelist(&(scen->transform_spaces), &(sce->transform_spaces)); @@ -152,48 +152,48 @@ Scene *BKE_scene_copy(Scene *sce, int type) BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets)); if (sce->nodetree) { - scen->nodetree= ntreeCopyTree(sce->nodetree); /* copies actions */ + scen->nodetree = ntreeCopyTree(sce->nodetree); /* copies actions */ ntreeSwitchID(scen->nodetree, &sce->id, &scen->id); } - obase= sce->base.first; - base= scen->base.first; + obase = sce->base.first; + base = scen->base.first; while (base) { id_us_plus(&base->object->id); - if (obase==sce->basact) scen->basact= base; + if (obase == sce->basact) scen->basact = base; - obase= obase->next; - base= base->next; + obase = obase->next; + base = base->next; } } /* tool settings */ - scen->toolsettings= MEM_dupallocN(sce->toolsettings); + scen->toolsettings = MEM_dupallocN(sce->toolsettings); - ts= scen->toolsettings; + ts = scen->toolsettings; if (ts) { if (ts->vpaint) { - ts->vpaint= MEM_dupallocN(ts->vpaint); - ts->vpaint->paintcursor= NULL; - ts->vpaint->vpaint_prev= NULL; - ts->vpaint->wpaint_prev= NULL; + ts->vpaint = MEM_dupallocN(ts->vpaint); + ts->vpaint->paintcursor = NULL; + ts->vpaint->vpaint_prev = NULL; + ts->vpaint->wpaint_prev = NULL; copy_paint(&ts->vpaint->paint, &ts->vpaint->paint); } if (ts->wpaint) { - ts->wpaint= MEM_dupallocN(ts->wpaint); - ts->wpaint->paintcursor= NULL; - ts->wpaint->vpaint_prev= NULL; - ts->wpaint->wpaint_prev= NULL; + ts->wpaint = MEM_dupallocN(ts->wpaint); + ts->wpaint->paintcursor = NULL; + ts->wpaint->vpaint_prev = NULL; + ts->wpaint->wpaint_prev = NULL; copy_paint(&ts->wpaint->paint, &ts->wpaint->paint); } if (ts->sculpt) { - ts->sculpt= MEM_dupallocN(ts->sculpt); + ts->sculpt = MEM_dupallocN(ts->sculpt); copy_paint(&ts->sculpt->paint, &ts->sculpt->paint); } copy_paint(&ts->imapaint.paint, &ts->imapaint.paint); - ts->imapaint.paintcursor= NULL; - ts->particle.paintcursor= NULL; + ts->imapaint.paintcursor = NULL; + ts->particle.paintcursor = NULL; } /* make a private copy of the avicodecdata */ @@ -210,7 +210,7 @@ Scene *BKE_scene_copy(Scene *sce, int type) } if (sce->r.ffcodecdata.properties) { /* intentionally check scen not sce. */ - scen->r.ffcodecdata.properties= IDP_CopyProperty(sce->r.ffcodecdata.properties); + scen->r.ffcodecdata.properties = IDP_CopyProperty(sce->r.ffcodecdata.properties); } /* NOTE: part of SCE_COPY_LINK_DATA and SCE_COPY_FULL operations @@ -229,13 +229,13 @@ Scene *BKE_scene_copy(Scene *sce, int type) BKE_copy_animdata_id_action((ID *)scen); if (scen->world) { id_us_plus((ID *)scen->world); - scen->world= BKE_world_copy(scen->world); + scen->world = BKE_world_copy(scen->world); BKE_copy_animdata_id_action((ID *)scen->world); } if (sce->ed) { - scen->ed= MEM_callocN(sizeof(Editing), "addseq"); - scen->ed->seqbasep= &scen->ed->seqbase; + scen->ed = MEM_callocN(sizeof(Editing), "addseq"); + scen->ed->seqbasep = &scen->ed->seqbase; seqbase_dupli_recursive(sce, scen, &scen->ed->seqbase, &sce->ed->seqbase, SEQ_DUPE_ALL); } } @@ -248,10 +248,10 @@ void BKE_scene_free(Scene *sce) { Base *base; - base= sce->base.first; + base = sce->base.first; while (base) { base->object->id.us--; - base= base->next; + base = base->next; } /* do not free objects! */ @@ -262,7 +262,7 @@ void BKE_scene_free(Scene *sce) // its probably safe not to do this, some save and reload will free this. sce->gpd->id.us--; #endif - sce->gpd= NULL; + sce->gpd = NULL; } BLI_freelistN(&sce->base); @@ -334,74 +334,74 @@ void BKE_scene_free(Scene *sce) Scene *BKE_scene_add(const char *name) { - Main *bmain= G.main; + Main *bmain = G.main; Scene *sce; ParticleEditSettings *pset; int a; - sce= BKE_libblock_alloc(&bmain->scene, ID_SCE, name); - sce->lay= sce->layact= 1; + sce = BKE_libblock_alloc(&bmain->scene, ID_SCE, name); + sce->lay = sce->layact = 1; - sce->r.mode= R_GAMMA|R_OSA|R_SHADOW|R_SSS|R_ENVMAP|R_RAYTRACE; - sce->r.cfra= 1; - sce->r.sfra= 1; - sce->r.efra= 250; - sce->r.frame_step= 1; - sce->r.xsch= 1920; - sce->r.ysch= 1080; - sce->r.xasp= 1; - sce->r.yasp= 1; - sce->r.xparts= 8; - sce->r.yparts= 8; - sce->r.mblur_samples= 1; - sce->r.filtertype= R_FILTER_MITCH; - sce->r.size= 50; - - sce->r.im_format.planes= R_IMF_PLANES_RGB; - sce->r.im_format.imtype= R_IMF_IMTYPE_PNG; - sce->r.im_format.quality= 90; - - sce->r.displaymode= R_OUTPUT_AREA; - sce->r.framapto= 100; - sce->r.images= 100; - sce->r.framelen= 1.0; - sce->r.blurfac= 0.5; - sce->r.frs_sec= 24; - sce->r.frs_sec_base= 1; - sce->r.edgeint= 10; + sce->r.mode = R_GAMMA | R_OSA | R_SHADOW | R_SSS | R_ENVMAP | R_RAYTRACE; + sce->r.cfra = 1; + sce->r.sfra = 1; + sce->r.efra = 250; + sce->r.frame_step = 1; + sce->r.xsch = 1920; + sce->r.ysch = 1080; + sce->r.xasp = 1; + sce->r.yasp = 1; + sce->r.xparts = 8; + sce->r.yparts = 8; + sce->r.mblur_samples = 1; + sce->r.filtertype = R_FILTER_MITCH; + sce->r.size = 50; + + sce->r.im_format.planes = R_IMF_PLANES_RGB; + sce->r.im_format.imtype = R_IMF_IMTYPE_PNG; + sce->r.im_format.quality = 90; + + sce->r.displaymode = R_OUTPUT_AREA; + sce->r.framapto = 100; + sce->r.images = 100; + sce->r.framelen = 1.0; + sce->r.blurfac = 0.5; + sce->r.frs_sec = 24; + sce->r.frs_sec_base = 1; + sce->r.edgeint = 10; sce->r.ocres = 128; sce->r.color_mgt_flag |= R_COLOR_MANAGEMENT; - sce->r.gauss= 1.0; + sce->r.gauss = 1.0; /* deprecated but keep for upwards compat */ - sce->r.postgamma= 1.0; - sce->r.posthue= 0.0; - sce->r.postsat= 1.0; - - sce->r.bake_mode= 1; /* prevent to include render stuff here */ - sce->r.bake_filter= 2; - sce->r.bake_osa= 5; - sce->r.bake_flag= R_BAKE_CLEAR; - sce->r.bake_normal_space= R_BAKE_SPACE_TANGENT; - sce->r.scemode= R_DOCOMP|R_DOSEQ|R_EXTENSION; - sce->r.stamp= R_STAMP_TIME|R_STAMP_FRAME|R_STAMP_DATE|R_STAMP_CAMERA|R_STAMP_SCENE|R_STAMP_FILENAME|R_STAMP_RENDERTIME; - sce->r.stamp_font_id= 12; - sce->r.fg_stamp[0]= sce->r.fg_stamp[1]= sce->r.fg_stamp[2]= 0.8f; - sce->r.fg_stamp[3]= 1.0f; - sce->r.bg_stamp[0]= sce->r.bg_stamp[1]= sce->r.bg_stamp[2]= 0.0f; - sce->r.bg_stamp[3]= 0.25f; + sce->r.postgamma = 1.0; + sce->r.posthue = 0.0; + sce->r.postsat = 1.0; + + sce->r.bake_mode = 1; /* prevent to include render stuff here */ + sce->r.bake_filter = 2; + sce->r.bake_osa = 5; + sce->r.bake_flag = R_BAKE_CLEAR; + sce->r.bake_normal_space = R_BAKE_SPACE_TANGENT; + sce->r.scemode = R_DOCOMP | R_DOSEQ | R_EXTENSION; + sce->r.stamp = R_STAMP_TIME | R_STAMP_FRAME | R_STAMP_DATE | R_STAMP_CAMERA | R_STAMP_SCENE | R_STAMP_FILENAME | R_STAMP_RENDERTIME; + sce->r.stamp_font_id = 12; + sce->r.fg_stamp[0] = sce->r.fg_stamp[1] = sce->r.fg_stamp[2] = 0.8f; + sce->r.fg_stamp[3] = 1.0f; + sce->r.bg_stamp[0] = sce->r.bg_stamp[1] = sce->r.bg_stamp[2] = 0.0f; + sce->r.bg_stamp[3] = 0.25f; sce->r.raytrace_options = R_RAYTRACE_USE_INSTANCES; - sce->r.seq_prev_type= OB_SOLID; - sce->r.seq_rend_type= OB_SOLID; - sce->r.seq_flag= R_SEQ_GL_PREV; + sce->r.seq_prev_type = OB_SOLID; + sce->r.seq_rend_type = OB_SOLID; + sce->r.seq_flag = R_SEQ_GL_PREV; - sce->r.threads= 1; + sce->r.threads = 1; - sce->r.simplify_subsurf= 6; - sce->r.simplify_particles= 1.0f; - sce->r.simplify_shadowsamples= 16; - sce->r.simplify_aosss= 1.0f; + sce->r.simplify_subsurf = 6; + sce->r.simplify_particles = 1.0f; + sce->r.simplify_shadowsamples = 16; + sce->r.simplify_aosss = 1.0f; sce->r.border.xmin = 0.0f; sce->r.border.ymin = 0.0f; @@ -409,7 +409,7 @@ Scene *BKE_scene_add(const char *name) sce->r.border.ymax = 1.0f; sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings), "Tool Settings Struct"); - sce->toolsettings->cornertype=1; + sce->toolsettings->cornertype = 1; sce->toolsettings->degr = 90; sce->toolsettings->step = 9; sce->toolsettings->turn = 1; @@ -423,25 +423,25 @@ Scene *BKE_scene_add(const char *name) sce->toolsettings->uvcalc_mapdir = 1; sce->toolsettings->uvcalc_mapalign = 1; sce->toolsettings->unwrapper = 1; - sce->toolsettings->select_thresh= 0.01f; + sce->toolsettings->select_thresh = 0.01f; sce->toolsettings->jointrilimit = 0.8f; - sce->toolsettings->selectmode= SCE_SELECT_VERTEX; - sce->toolsettings->uv_selectmode= UV_SELECT_VERTEX; - sce->toolsettings->normalsize= 0.1; - sce->toolsettings->autokey_mode= U.autokey_mode; + sce->toolsettings->selectmode = SCE_SELECT_VERTEX; + sce->toolsettings->uv_selectmode = UV_SELECT_VERTEX; + sce->toolsettings->normalsize = 0.1; + sce->toolsettings->autokey_mode = U.autokey_mode; sce->toolsettings->skgen_resolution = 100; - sce->toolsettings->skgen_threshold_internal = 0.01f; - sce->toolsettings->skgen_threshold_external = 0.01f; - sce->toolsettings->skgen_angle_limit = 45.0f; - sce->toolsettings->skgen_length_ratio = 1.3f; - sce->toolsettings->skgen_length_limit = 1.5f; - sce->toolsettings->skgen_correlation_limit = 0.98f; - sce->toolsettings->skgen_symmetry_limit = 0.1f; + sce->toolsettings->skgen_threshold_internal = 0.01f; + sce->toolsettings->skgen_threshold_external = 0.01f; + sce->toolsettings->skgen_angle_limit = 45.0f; + sce->toolsettings->skgen_length_ratio = 1.3f; + sce->toolsettings->skgen_length_limit = 1.5f; + sce->toolsettings->skgen_correlation_limit = 0.98f; + sce->toolsettings->skgen_symmetry_limit = 0.1f; sce->toolsettings->skgen_postpro = SKGEN_SMOOTH; sce->toolsettings->skgen_postpro_passes = 1; - sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL|SKGEN_FILTER_EXTERNAL|SKGEN_FILTER_SMART|SKGEN_HARMONIC|SKGEN_SUB_CORRELATION|SKGEN_STICK_TO_EMBEDDING; + sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL | SKGEN_FILTER_EXTERNAL | SKGEN_FILTER_SMART | SKGEN_HARMONIC | SKGEN_SUB_CORRELATION | SKGEN_STICK_TO_EMBEDDING; sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION; sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH; sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE; @@ -455,22 +455,22 @@ Scene *BKE_scene_add(const char *name) sce->unit.scale_length = 1.0f; - pset= &sce->toolsettings->particle; - pset->flag= PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER|PE_AUTO_VELOCITY; - pset->emitterdist= 0.25f; - pset->totrekey= 5; - pset->totaddkey= 5; - pset->brushtype= PE_BRUSH_NONE; - pset->draw_step= 2; - pset->fade_frames= 2; - pset->selectmode= SCE_SELECT_PATH; - for (a=0; a<PE_TOT_BRUSH; a++) { - pset->brush[a].strength= 0.5; - pset->brush[a].size= 50; - pset->brush[a].step= 10; - pset->brush[a].count= 10; + pset = &sce->toolsettings->particle; + pset->flag = PE_KEEP_LENGTHS | PE_LOCK_FIRST | PE_DEFLECT_EMITTER | PE_AUTO_VELOCITY; + pset->emitterdist = 0.25f; + pset->totrekey = 5; + pset->totaddkey = 5; + pset->brushtype = PE_BRUSH_NONE; + pset->draw_step = 2; + pset->fade_frames = 2; + pset->selectmode = SCE_SELECT_PATH; + for (a = 0; a < PE_TOT_BRUSH; a++) { + pset->brush[a].strength = 0.5; + pset->brush[a].size = 50; + pset->brush[a].step = 10; + pset->brush[a].count = 10; } - pset->brush[PE_BRUSH_CUT].strength= 100; + pset->brush[PE_BRUSH_CUT].strength = 100; sce->r.ffcodecdata.audio_mixrate = 44100; sce->r.ffcodecdata.audio_volume = 1.0f; @@ -487,7 +487,7 @@ Scene *BKE_scene_add(const char *name) BLI_strncpy(sce->r.pic, U.renderdir, sizeof(sce->r.pic)); BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f); - sce->r.osa= 8; + sce->r.osa = 8; /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */ BKE_scene_add_render_layer(sce, NULL); @@ -503,13 +503,13 @@ Scene *BKE_scene_add(const char *name) sce->gm.dome.resbuf = 1.0f; sce->gm.dome.tilt = 0; - sce->gm.xplay= 640; - sce->gm.yplay= 480; - sce->gm.freqplay= 60; - sce->gm.depth= 32; + sce->gm.xplay = 640; + sce->gm.yplay = 480; + sce->gm.freqplay = 60; + sce->gm.depth = 32; - sce->gm.gravity= 9.8f; - sce->gm.physicsEngine= WOPHY_BULLET; + sce->gm.gravity = 9.8f; + sce->gm.physicsEngine = WOPHY_BULLET; sce->gm.mode = 32; //XXX ugly harcoding, still not sure we should drop mode. 32 == 1 << 5 == use_occlusion_culling sce->gm.occlusionRes = 128; sce->gm.ticrate = 60; @@ -520,12 +520,12 @@ Scene *BKE_scene_add(const char *name) sce->gm.flag = GAME_DISPLAY_LISTS; sce->gm.matmode = GAME_MAT_MULTITEX; - sce->gm.obstacleSimulation= OBSTSIMULATION_NONE; + sce->gm.obstacleSimulation = OBSTSIMULATION_NONE; sce->gm.levelHeight = 2.f; sce->gm.recastData.cellsize = 0.3f; sce->gm.recastData.cellheight = 0.2f; - sce->gm.recastData.agentmaxslope = M_PI/2; + sce->gm.recastData.agentmaxslope = M_PI / 2; sce->gm.recastData.agentmaxclimb = 0.9f; sce->gm.recastData.agentheight = 2.0f; sce->gm.recastData.agentradius = 0.6f; @@ -548,10 +548,10 @@ Base *BKE_scene_base_find(Scene *scene, Object *ob) { Base *base; - base= scene->base.first; + base = scene->base.first; while (base) { if (base->object == ob) return base; - base= base->next; + base = base->next; } return NULL; } @@ -570,18 +570,18 @@ void BKE_scene_set_background(Main *bmain, Scene *scene) /* can happen when switching modes in other scenes */ if (scene->obedit && !(scene->obedit->mode & OB_MODE_EDIT)) - scene->obedit= NULL; + scene->obedit = NULL; /* deselect objects (for dataselect) */ - for (ob= bmain->object.first; ob; ob= ob->id.next) - ob->flag &= ~(SELECT|OB_FROMGROUP); + for (ob = bmain->object.first; ob; ob = ob->id.next) + ob->flag &= ~(SELECT | OB_FROMGROUP); /* group flags again */ - for (group= bmain->group.first; group; group= group->id.next) { - go= group->gobject.first; + for (group = bmain->group.first; group; group = group->id.next) { + go = group->gobject.first; while (go) { if (go->ob) go->ob->flag |= OB_FROMGROUP; - go= go->next; + go = go->next; } } @@ -589,25 +589,25 @@ void BKE_scene_set_background(Main *bmain, Scene *scene) DAG_scene_sort(bmain, scene); /* ensure dags are built for sets */ - for (sce= scene->set; sce; sce= sce->set) - if (sce->theDag==NULL) + for (sce = scene->set; sce; sce = sce->set) + if (sce->theDag == NULL) DAG_scene_sort(bmain, sce); /* copy layers and flags from bases to objects */ - for (base= scene->base.first; base; base= base->next) { - ob= base->object; - ob->lay= base->lay; + for (base = scene->base.first; base; base = base->next) { + ob = base->object; + ob->lay = base->lay; /* group patch... */ base->flag &= ~(OB_FROMGROUP); - flag= ob->flag & (OB_FROMGROUP); + flag = ob->flag & (OB_FROMGROUP); base->flag |= flag; /* not too nice... for recovering objects with lost data */ //if (ob->pose==NULL) base->flag &= ~OB_POSEMODE; - ob->flag= base->flag; + ob->flag = base->flag; - ob->ctime= -1234567.0; /* force ipo to be calculated later */ + ob->ctime = -1234567.0; /* force ipo to be calculated later */ } /* no full animation update, this to enable render code to work (render code calls own animation updates) */ } @@ -632,9 +632,9 @@ void BKE_scene_unlink(Main *bmain, Scene *sce, Scene *newsce) bScreen *sc; /* check all sets */ - for (sce1= bmain->scene.first; sce1; sce1= sce1->id.next) + for (sce1 = bmain->scene.first; sce1; sce1 = sce1->id.next) if (sce1->set == sce) - sce1->set= NULL; + sce1->set = NULL; /* check all sequences */ clear_scene_in_allseqs(bmain, sce); @@ -643,9 +643,9 @@ void BKE_scene_unlink(Main *bmain, Scene *sce, Scene *newsce) clear_scene_in_nodes(bmain, sce); /* al screens */ - for (sc= bmain->screen.first; sc; sc= sc->id.next) + for (sc = bmain->screen.first; sc; sc = sc->id.next) if (sc->scene == sce) - sc->scene= newsce; + sc->scene = newsce; BKE_libblock_free(&bmain->scene, sce); } @@ -655,15 +655,15 @@ void BKE_scene_unlink(Main *bmain, Scene *sce, Scene *newsce) */ int BKE_scene_base_iter_next(Scene **scene, int val, Base **base, Object **ob) { - static ListBase *duplilist= NULL; + static ListBase *duplilist = NULL; static DupliObject *dupob; - static int fase= F_START, in_next_object= 0; - int run_again=1; + static int fase = F_START, in_next_object = 0; + int run_again = 1; /* init */ - if (val==0) { - fase= F_START; - dupob= NULL; + if (val == 0) { + fase = F_START; + dupob = NULL; /* XXX particle systems with metas+dupligroups call this recursively */ /* see bug #18725 */ @@ -674,44 +674,44 @@ int BKE_scene_base_iter_next(Scene **scene, int val, Base **base, Object **ob) } } else { - in_next_object= 1; + in_next_object = 1; /* run_again is set when a duplilist has been ended */ while (run_again) { - run_again= 0; + run_again = 0; /* the first base */ - if (fase==F_START) { - *base= (*scene)->base.first; + if (fase == F_START) { + *base = (*scene)->base.first; if (*base) { - *ob= (*base)->object; - fase= F_SCENE; + *ob = (*base)->object; + fase = F_SCENE; } else { /* exception: empty scene */ while ((*scene)->set) { - (*scene)= (*scene)->set; + (*scene) = (*scene)->set; if ((*scene)->base.first) { - *base= (*scene)->base.first; - *ob= (*base)->object; - fase= F_SCENE; + *base = (*scene)->base.first; + *ob = (*base)->object; + fase = F_SCENE; break; } } } } else { - if (*base && fase!=F_DUPLI) { - *base= (*base)->next; - if (*base) *ob= (*base)->object; + if (*base && fase != F_DUPLI) { + *base = (*base)->next; + if (*base) *ob = (*base)->object; else { - if (fase==F_SCENE) { + if (fase == F_SCENE) { /* (*scene) is finished, now do the set */ while ((*scene)->set) { - (*scene)= (*scene)->set; + (*scene) = (*scene)->set; if ((*scene)->base.first) { - *base= (*scene)->base.first; - *ob= (*base)->object; + *base = (*scene)->base.first; + *ob = (*base)->object; break; } } @@ -720,17 +720,17 @@ int BKE_scene_base_iter_next(Scene **scene, int val, Base **base, Object **ob) } } - if (*base == NULL) fase= F_START; + if (*base == NULL) fase = F_START; else { - if (fase!=F_DUPLI) { + if (fase != F_DUPLI) { if ( (*base)->object->transflag & OB_DUPLI) { /* groups cannot be duplicated for mballs yet, * this enters eternal loop because of * makeDispListMBall getting called inside of group_duplilist */ if ((*base)->object->dup_group == NULL) { - duplilist= object_duplilist((*scene), (*base)->object); + duplilist = object_duplilist((*scene), (*base)->object); - dupob= duplilist->first; + dupob = duplilist->first; if (!dupob) free_object_duplilist(duplilist); @@ -743,22 +743,22 @@ int BKE_scene_base_iter_next(Scene **scene, int val, Base **base, Object **ob) copy_m4_m4(dupob->ob->obmat, dupob->mat); (*base)->flag |= OB_FROMDUPLI; - *ob= dupob->ob; - fase= F_DUPLI; + *ob = dupob->ob; + fase = F_DUPLI; - dupob= dupob->next; + dupob = dupob->next; } - else if (fase==F_DUPLI) { - fase= F_SCENE; + else if (fase == F_DUPLI) { + fase = F_SCENE; (*base)->flag &= ~OB_FROMDUPLI; - for (dupob= duplilist->first; dupob; dupob= dupob->next) { + for (dupob = duplilist->first; dupob; dupob = dupob->next) { copy_m4_m4(dupob->ob->obmat, dupob->omat); } free_object_duplilist(duplilist); - duplilist= NULL; - run_again= 1; + duplilist = NULL; + run_again = 1; } } } @@ -766,12 +766,12 @@ int BKE_scene_base_iter_next(Scene **scene, int val, Base **base, Object **ob) #if 0 if (ob && *ob) { - printf("Scene: '%s', '%s'\n", (*scene)->id.name+2, (*ob)->id.name+2); + printf("Scene: '%s', '%s'\n", (*scene)->id.name + 2, (*ob)->id.name + 2); } #endif /* reset recursion test */ - in_next_object= 0; + in_next_object = 0; return fase; } @@ -780,8 +780,8 @@ Object *BKE_scene_camera_find(Scene *sc) { Base *base; - for (base= sc->base.first; base; base= base->next) - if (base->object->type==OB_CAMERA) + for (base = sc->base.first; base; base = base->next) + if (base->object->type == OB_CAMERA) return base->object; return NULL; @@ -793,12 +793,12 @@ Object *BKE_scene_camera_switch_find(Scene *scene) TimeMarker *m; int cfra = scene->r.cfra; int frame = -(MAXFRAME + 1); - Object *camera= NULL; + Object *camera = NULL; - for (m= scene->markers.first; m; m= m->next) { - if (m->camera && (m->camera->restrictflag & OB_RESTRICT_RENDER)==0 && (m->frame <= cfra) && (m->frame > frame)) { - camera= m->camera; - frame= m->frame; + for (m = scene->markers.first; m; m = m->next) { + if (m->camera && (m->camera->restrictflag & OB_RESTRICT_RENDER) == 0 && (m->frame <= cfra) && (m->frame > frame)) { + camera = m->camera; + frame = m->frame; if (frame == cfra) break; @@ -812,9 +812,9 @@ Object *BKE_scene_camera_switch_find(Scene *scene) int BKE_scene_camera_switch_update(Scene *scene) { #ifdef DURIAN_CAMERA_SWITCH - Object *camera= BKE_scene_camera_switch_find(scene); + Object *camera = BKE_scene_camera_switch_find(scene); if (camera) { - scene->camera= camera; + scene->camera = camera; return 1; } #else @@ -825,18 +825,18 @@ int BKE_scene_camera_switch_update(Scene *scene) char *BKE_scene_find_marker_name(Scene *scene, int frame) { - ListBase *markers= &scene->markers; + ListBase *markers = &scene->markers; TimeMarker *m1, *m2; /* search through markers for match */ - for (m1=markers->first, m2=markers->last; m1 && m2; m1=m1->next, m2=m2->prev) { - if (m1->frame==frame) + for (m1 = markers->first, m2 = markers->last; m1 && m2; m1 = m1->next, m2 = m2->prev) { + if (m1->frame == frame) return m1->name; if (m1 == m2) break; - if (m2->frame==frame) + if (m2->frame == frame) return m2->name; } @@ -848,13 +848,13 @@ char *BKE_scene_find_marker_name(Scene *scene, int frame) char *BKE_scene_find_last_marker_name(Scene *scene, int frame) { TimeMarker *marker, *best_marker = NULL; - int best_frame = -MAXFRAME*2; - for (marker= scene->markers.first; marker; marker= marker->next) { - if (marker->frame==frame) { + int best_frame = -MAXFRAME * 2; + for (marker = scene->markers.first; marker; marker = marker->next) { + if (marker->frame == frame) { return marker->name; } - if ( marker->frame > best_frame && marker->frame < frame) { + if (marker->frame > best_frame && marker->frame < frame) { best_marker = marker; best_frame = marker->frame; } @@ -866,12 +866,12 @@ char *BKE_scene_find_last_marker_name(Scene *scene, int frame) Base *BKE_scene_base_add(Scene *sce, Object *ob) { - Base *b= MEM_callocN(sizeof(*b), "BKE_scene_base_add"); + Base *b = MEM_callocN(sizeof(*b), "BKE_scene_base_add"); BLI_addhead(&sce->base, b); - b->object= ob; - b->flag= ob->flag; - b->lay= ob->lay; + b->object = ob; + b->flag = ob->flag; + b->lay = ob->lay; return b; } @@ -880,18 +880,18 @@ void BKE_scene_base_deselect_all(Scene *sce) { Base *b; - for (b= sce->base.first; b; b= b->next) { - b->flag&= ~SELECT; - b->object->flag= b->flag; + for (b = sce->base.first; b; b = b->next) { + b->flag &= ~SELECT; + b->object->flag = b->flag; } } void BKE_scene_base_select(Scene *sce, Base *selbase) { selbase->flag |= SELECT; - selbase->object->flag= selbase->flag; + selbase->object->flag = selbase->flag; - sce->basact= selbase; + sce->basact = selbase; } /* checks for cycle, returns 1 if it's all OK */ @@ -900,17 +900,17 @@ int BKE_scene_validate_setscene(Main *bmain, Scene *sce) Scene *scene; int a, totscene; - if (sce->set==NULL) return 1; + if (sce->set == NULL) return 1; - totscene= 0; - for (scene= bmain->scene.first; scene; scene= scene->id.next) + totscene = 0; + for (scene = bmain->scene.first; scene; scene = scene->id.next) totscene++; - for (a=0, scene=sce; scene->set; scene=scene->set, a++) { + for (a = 0, scene = sce; scene->set; scene = scene->set, a++) { /* more iterations than scenes means we have a cycle */ if (a > totscene) { /* the tested scene gets zero'ed, that's typically current scene */ - sce->set= NULL; + sce->set = NULL; return 0; } } @@ -937,7 +937,7 @@ float BKE_scene_frame_get_from_ctime(Scene *scene, const float frame) } /* drivers support/hacks - * - this method is called from scene_update_tagged_recursive(), so gets included in viewport + render + * - this method is called from scene_update_tagged_recursive(), so gets included in viewport + render * - these are always run since the depsgraph can't handle non-object data * - these happen after objects are all done so that we can read in their final transform values, * though this means that objects can't refer to scene info for guidance... @@ -955,7 +955,7 @@ static void scene_update_drivers(Main *UNUSED(bmain), Scene *scene) // TODO: what about world textures? but then those have nodes too... if (scene->world) { ID *wid = (ID *)scene->world; - AnimData *adt= BKE_animdata_from_id(wid); + AnimData *adt = BKE_animdata_from_id(wid); if (adt && adt->drivers.first) BKE_animsys_evaluate_animdata(scene, wid, adt, ctime, ADT_RECALC_DRIVERS); @@ -964,7 +964,7 @@ static void scene_update_drivers(Main *UNUSED(bmain), Scene *scene) /* nodes */ if (scene->nodetree) { ID *nid = (ID *)scene->nodetree; - AnimData *adt= BKE_animdata_from_id(nid); + AnimData *adt = BKE_animdata_from_id(nid); if (adt && adt->drivers.first) BKE_animsys_evaluate_animdata(scene, nid, adt, ctime, ADT_RECALC_DRIVERS); @@ -976,7 +976,7 @@ static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scen Base *base; - scene->customdata_mask= scene_parent->customdata_mask; + scene->customdata_mask = scene_parent->customdata_mask; /* sets first, we allow per definition current scene to have * dependencies on sets, but not the other way around. */ @@ -984,8 +984,8 @@ static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scen scene_update_tagged_recursive(bmain, scene->set, scene_parent); /* scene objects */ - for (base= scene->base.first; base; base= base->next) { - Object *ob= base->object; + for (base = scene->base.first; base; base = base->next) { + Object *ob = base->object; BKE_object_handle_update(scene_parent, ob); @@ -993,7 +993,7 @@ static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scen group_handle_recalc_and_update(scene_parent, ob, ob->dup_group); /* always update layer, so that animating layers works */ - base->lay= ob->lay; + base->lay = ob->lay; } /* scene drivers... */ @@ -1012,7 +1012,7 @@ void BKE_scene_update_tagged(Main *bmain, Scene *scene) /* flush recalc flags to dependencies */ DAG_ids_flush_tagged(bmain); - scene->physics_settings.quick_cache_step= 0; + scene->physics_settings.quick_cache_step = 0; /* update all objects: drivers, matrices, displists, etc. flags set * by depgraph or manual, no layer check here, gets correct flushed @@ -1023,7 +1023,7 @@ void BKE_scene_update_tagged(Main *bmain, Scene *scene) /* extra call here to recalc scene animation (for sequencer) */ { - AnimData *adt= BKE_animdata_from_id(&scene->id); + AnimData *adt = BKE_animdata_from_id(&scene->id); float ctime = BKE_scene_frame_get(scene); if (adt && (adt->recalc & ADT_RECALC_ANIM)) @@ -1057,8 +1057,8 @@ void BKE_scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay) /* clear animation overrides */ // XXX TODO... - for (sce_iter= sce; sce_iter; sce_iter= sce_iter->set) { - if (sce_iter->theDag==NULL) + for (sce_iter = sce; sce_iter; sce_iter = sce_iter->set) { + if (sce_iter->theDag == NULL) DAG_scene_sort(bmain, sce_iter); } @@ -1099,24 +1099,24 @@ SceneRenderLayer *BKE_scene_add_render_layer(Scene *sce, const char *name) SceneRenderLayer *srl; if (!name) - name= "RenderLayer"; + name = "RenderLayer"; - srl= MEM_callocN(sizeof(SceneRenderLayer), "new render layer"); + srl = MEM_callocN(sizeof(SceneRenderLayer), "new render layer"); BLI_strncpy(srl->name, name, sizeof(srl->name)); BLI_uniquename(&sce->r.layers, srl, "RenderLayer", '.', offsetof(SceneRenderLayer, name), sizeof(srl->name)); BLI_addtail(&sce->r.layers, srl); /* note, this is also in render, pipeline.c, to make layer when scenedata doesnt have it */ - srl->lay= (1<<20) -1; - srl->layflag= 0x7FFF; /* solid ztra halo edge strand */ - srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z; + srl->lay = (1 << 20) - 1; + srl->layflag = 0x7FFF; /* solid ztra halo edge strand */ + srl->passflag = SCE_PASS_COMBINED | SCE_PASS_Z; return srl; } int BKE_scene_remove_render_layer(Main *bmain, Scene *scene, SceneRenderLayer *srl) { - const int act= BLI_findindex(&scene->r.layers, srl); + const int act = BLI_findindex(&scene->r.layers, srl); Scene *sce; if (act == -1) { @@ -1132,16 +1132,16 @@ int BKE_scene_remove_render_layer(Main *bmain, Scene *scene, SceneRenderLayer *s BLI_remlink(&scene->r.layers, srl); MEM_freeN(srl); - scene->r.actlay= 0; + scene->r.actlay = 0; for (sce = bmain->scene.first; sce; sce = sce->id.next) { if (sce->nodetree) { bNode *node; for (node = sce->nodetree->nodes.first; node; node = node->next) { - if (node->type==CMP_NODE_R_LAYERS && (Scene*)node->id==scene) { - if (node->custom1==act) - node->custom1= 0; - else if (node->custom1>act) + if (node->type == CMP_NODE_R_LAYERS && (Scene *)node->id == scene) { + if (node->custom1 == act) + node->custom1 = 0; + else if (node->custom1 > act) node->custom1--; } } @@ -1164,7 +1164,7 @@ int get_render_subsurf_level(RenderData *r, int lvl) int get_render_child_particle_number(RenderData *r, int num) { if (r->mode & R_SIMPLIFY) - return (int)(r->simplify_particles*num); + return (int)(r->simplify_particles * num); else return num; } @@ -1180,7 +1180,7 @@ int get_render_shadow_samples(RenderData *r, int samples) float get_render_aosss_error(RenderData *r, float error) { if (r->mode & R_SIMPLIFY) - return ((1.0f-r->simplify_aosss)*10.0f + 1.0f)*error; + return ((1.0f - r->simplify_aosss) * 10.0f + 1.0f) * error; else return error; } @@ -1192,14 +1192,14 @@ Base *_setlooper_base_step(Scene **sce_iter, Base *base) /* common case, step to the next */ return base->next; } - else if (base==NULL && (*sce_iter)->base.first) { + else if (base == NULL && (*sce_iter)->base.first) { /* first time looping, return the scenes first base */ return (Base *)(*sce_iter)->base.first; } else { /* reached the end, get the next base in the set */ - while ((*sce_iter= (*sce_iter)->set)) { - base= (Base *)(*sce_iter)->base.first; + while ((*sce_iter = (*sce_iter)->set)) { + base = (Base *)(*sce_iter)->base.first; if (base) { return base; } @@ -1211,26 +1211,26 @@ Base *_setlooper_base_step(Scene **sce_iter, Base *base) int BKE_scene_use_new_shading_nodes(Scene *scene) { - RenderEngineType *type= RE_engines_find(scene->r.engine); + RenderEngineType *type = RE_engines_find(scene->r.engine); return (type && type->flag & RE_USE_SHADING_NODES); } void BKE_scene_base_flag_to_objects(struct Scene *scene) { - Base *base= scene->base.first; + Base *base = scene->base.first; while (base) { - base->object->flag= base->flag; - base= base->next; + base->object->flag = base->flag; + base = base->next; } } void BKE_scene_base_flag_from_objects(struct Scene *scene) { - Base *base= scene->base.first; + Base *base = scene->base.first; while (base) { - base->flag= base->object->flag; - base= base->next; + base->flag = base->object->flag; + base = base->next; } } diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index 8e380c3674f..1f129b1c547 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -51,7 +51,7 @@ /* ************ Spacetype/regiontype handling ************** */ /* keep global; this has to be accessible outside of windowmanager */ -static ListBase spacetypes= {NULL, NULL}; +static ListBase spacetypes = {NULL, NULL}; /* not SpaceType itself */ static void spacetype_free(SpaceType *st) @@ -60,14 +60,14 @@ static void spacetype_free(SpaceType *st) PanelType *pt; HeaderType *ht; - for (art= st->regiontypes.first; art; art= art->next) { + for (art = st->regiontypes.first; art; art = art->next) { BLI_freelistN(&art->drawcalls); - for (pt= art->paneltypes.first; pt; pt= pt->next) + for (pt = art->paneltypes.first; pt; pt = pt->next) if (pt->ext.free) pt->ext.free(pt->ext.data); - for (ht= art->headertypes.first; ht; ht= ht->next) + for (ht = art->headertypes.first; ht; ht = ht->next) if (ht->ext.free) ht->ext.free(ht->ext.data); @@ -84,7 +84,7 @@ void BKE_spacetypes_free(void) { SpaceType *st; - for (st= spacetypes.first; st; st= st->next) { + for (st = spacetypes.first; st; st = st->next) { spacetype_free(st); } @@ -95,8 +95,8 @@ SpaceType *BKE_spacetype_from_id(int spaceid) { SpaceType *st; - for (st= spacetypes.first; st; st= st->next) { - if (st->spaceid==spaceid) + for (st = spacetypes.first; st; st = st->next) { + if (st->spaceid == spaceid) return st; } return NULL; @@ -106,8 +106,8 @@ ARegionType *BKE_regiontype_from_id(SpaceType *st, int regionid) { ARegionType *art; - for (art= st->regiontypes.first; art; art= art->next) - if (art->regionid==regionid) + for (art = st->regiontypes.first; art; art = art->next) + if (art->regionid == regionid) return art; printf("Error, region type missing in - name:\"%s\", id:%d\n", st->name, st->spaceid); @@ -125,7 +125,7 @@ void BKE_spacetype_register(SpaceType *st) SpaceType *stype; /* sanity check */ - stype= BKE_spacetype_from_id(st->spaceid); + stype = BKE_spacetype_from_id(st->spaceid); if (stype) { printf("error: redefinition of spacetype %s\n", stype->name); spacetype_free(stype); @@ -142,11 +142,11 @@ void BKE_spacedata_freelist(ListBase *lb) SpaceLink *sl; ARegion *ar; - for (sl= lb->first; sl; sl= sl->next) { - SpaceType *st= BKE_spacetype_from_id(sl->spacetype); + for (sl = lb->first; sl; sl = sl->next) { + SpaceType *st = BKE_spacetype_from_id(sl->spacetype); /* free regions for pushed spaces */ - for (ar=sl->regionbase.first; ar; ar=ar->next) + for (ar = sl->regionbase.first; ar; ar = ar->next) BKE_area_region_free(st, ar); BLI_freelistN(&sl->regionbase); @@ -160,41 +160,41 @@ void BKE_spacedata_freelist(ListBase *lb) ARegion *BKE_area_region_copy(SpaceType *st, ARegion *ar) { - ARegion *newar= MEM_dupallocN(ar); + ARegion *newar = MEM_dupallocN(ar); Panel *pa, *newpa, *patab; - newar->prev= newar->next= NULL; - newar->handlers.first= newar->handlers.last= NULL; - newar->uiblocks.first= newar->uiblocks.last= NULL; - newar->swinid= 0; + newar->prev = newar->next = NULL; + newar->handlers.first = newar->handlers.last = NULL; + newar->uiblocks.first = newar->uiblocks.last = NULL; + newar->swinid = 0; /* use optional regiondata callback */ if (ar->regiondata) { - ARegionType *art= BKE_regiontype_from_id(st, ar->regiontype); + ARegionType *art = BKE_regiontype_from_id(st, ar->regiontype); if (art && art->duplicate) - newar->regiondata= art->duplicate(ar->regiondata); + newar->regiondata = art->duplicate(ar->regiondata); else - newar->regiondata= MEM_dupallocN(ar->regiondata); + newar->regiondata = MEM_dupallocN(ar->regiondata); } if (ar->v2d.tab_offset) - newar->v2d.tab_offset= MEM_dupallocN(ar->v2d.tab_offset); + newar->v2d.tab_offset = MEM_dupallocN(ar->v2d.tab_offset); - newar->panels.first= newar->panels.last= NULL; + newar->panels.first = newar->panels.last = NULL; BLI_duplicatelist(&newar->panels, &ar->panels); /* copy panel pointers */ - for (newpa= newar->panels.first; newpa; newpa= newpa->next) { - patab= newar->panels.first; - pa= ar->panels.first; + for (newpa = newar->panels.first; newpa; newpa = newpa->next) { + patab = newar->panels.first; + pa = ar->panels.first; while (patab) { if (newpa->paneltab == pa) { newpa->paneltab = patab; break; } - patab= patab->next; - pa= pa->next; + patab = patab->next; + pa = pa->next; } } @@ -208,10 +208,10 @@ static void region_copylist(SpaceType *st, ListBase *lb1, ListBase *lb2) ARegion *ar; /* to be sure */ - lb1->first= lb1->last= NULL; + lb1->first = lb1->last = NULL; - for (ar= lb2->first; ar; ar= ar->next) { - ARegion *arnew= BKE_area_region_copy(st, ar); + for (ar = lb2->first; ar; ar = ar->next) { + ARegion *arnew = BKE_area_region_copy(st, ar); BLI_addtail(lb1, arnew); } } @@ -222,13 +222,13 @@ void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2) { SpaceLink *sl; - lb1->first= lb1->last= NULL; /* to be sure */ + lb1->first = lb1->last = NULL; /* to be sure */ - for (sl= lb2->first; sl; sl= sl->next) { - SpaceType *st= BKE_spacetype_from_id(sl->spacetype); + for (sl = lb2->first; sl; sl = sl->next) { + SpaceType *st = BKE_spacetype_from_id(sl->spacetype); if (st && st->duplicate) { - SpaceLink *slnew= st->duplicate(sl); + SpaceLink *slnew = st->duplicate(sl); BLI_addtail(lb1, slnew); @@ -244,14 +244,14 @@ void BKE_spacedata_draw_locks(int set) { SpaceType *st; - for (st= spacetypes.first; st; st= st->next) { + for (st = spacetypes.first; st; st = st->next) { ARegionType *art; - for (art= st->regiontypes.first; art; art= art->next) { + for (art = st->regiontypes.first; art; art = art->next) { if (set) - art->do_lock= art->lock; + art->do_lock = art->lock; else - art->do_lock= 0; + art->do_lock = 0; } } } @@ -261,7 +261,7 @@ void BKE_spacedata_draw_locks(int set) void BKE_area_region_free(SpaceType *st, ARegion *ar) { if (st) { - ARegionType *art= BKE_regiontype_from_id(st, ar->regiontype); + ARegionType *art = BKE_regiontype_from_id(st, ar->regiontype); if (art && art->free) art->free(ar); @@ -274,7 +274,7 @@ void BKE_area_region_free(SpaceType *st, ARegion *ar) if (ar->v2d.tab_offset) { MEM_freeN(ar->v2d.tab_offset); - ar->v2d.tab_offset= NULL; + ar->v2d.tab_offset = NULL; } BLI_freelistN(&ar->panels); @@ -283,10 +283,10 @@ void BKE_area_region_free(SpaceType *st, ARegion *ar) /* not area itself */ void BKE_screen_area_free(ScrArea *sa) { - SpaceType *st= BKE_spacetype_from_id(sa->spacetype); + SpaceType *st = BKE_spacetype_from_id(sa->spacetype); ARegion *ar; - for (ar=sa->regionbase.first; ar; ar=ar->next) + for (ar = sa->regionbase.first; ar; ar = ar->next) BKE_area_region_free(st, ar); BLI_freelistN(&sa->regionbase); @@ -302,13 +302,13 @@ void BKE_screen_free(bScreen *sc) ScrArea *sa, *san; ARegion *ar; - for (ar=sc->regionbase.first; ar; ar=ar->next) + for (ar = sc->regionbase.first; ar; ar = ar->next) BKE_area_region_free(NULL, ar); BLI_freelistN(&sc->regionbase); - for (sa= sc->areabase.first; sa; sa= san) { - san= sa->next; + for (sa = sc->areabase.first; sa; sa = san) { + san = sa->next; BKE_screen_area_free(sa); } @@ -321,12 +321,12 @@ void BKE_screen_free(bScreen *sc) unsigned int BKE_screen_visible_layers(bScreen *screen, Scene *scene) { ScrArea *sa; - unsigned int layer= 0; + unsigned int layer = 0; if (screen) { /* get all used view3d layers */ - for (sa= screen->areabase.first; sa; sa= sa->next) - if (sa->spacetype==SPACE_VIEW3D) + for (sa = screen->areabase.first; sa; sa = sa->next) + if (sa->spacetype == SPACE_VIEW3D) layer |= ((View3D *)sa->spacedata.first)->lay; } @@ -344,7 +344,7 @@ ARegion *BKE_area_find_region_type(ScrArea *sa, int type) if (sa) { ARegion *ar; - for (ar=sa->regionbase.first; ar; ar= ar->next) { + for (ar = sa->regionbase.first; ar; ar = ar->next) { if (ar->regiontype == type) return ar; } @@ -357,16 +357,16 @@ ARegion *BKE_area_find_region_type(ScrArea *sa, int type) * -1 for any type */ struct ScrArea *BKE_screen_find_big_area(struct bScreen *sc, const int spacetype, const short min) { - ScrArea *sa, *big= NULL; - int size, maxsize= 0; + ScrArea *sa, *big = NULL; + int size, maxsize = 0; - for (sa= sc->areabase.first; sa; sa= sa->next) { + for (sa = sc->areabase.first; sa; sa = sa->next) { if ((spacetype == -1) || sa->spacetype == spacetype) { if (min <= sa->winx && min <= sa->winy) { - size= sa->winx*sa->winy; + size = sa->winx * sa->winy; if (size > maxsize) { - maxsize= size; - big= sa; + maxsize = size; + big = sa; } } } @@ -379,26 +379,26 @@ void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene) { int bit; - if (v3d->scenelock && v3d->localvd==NULL) { - v3d->lay= scene->lay; - v3d->camera= scene->camera; + if (v3d->scenelock && v3d->localvd == NULL) { + v3d->lay = scene->lay; + v3d->camera = scene->camera; - if (v3d->camera==NULL) { + if (v3d->camera == NULL) { ARegion *ar; - for (ar=v3d->regionbase.first; ar; ar= ar->next) { + for (ar = v3d->regionbase.first; ar; ar = ar->next) { if (ar->regiontype == RGN_TYPE_WINDOW) { - RegionView3D *rv3d= ar->regiondata; - if (rv3d->persp==RV3D_CAMOB) - rv3d->persp= RV3D_PERSP; + RegionView3D *rv3d = ar->regiondata; + if (rv3d->persp == RV3D_CAMOB) + rv3d->persp = RV3D_PERSP; } } } if ((v3d->lay & v3d->layact) == 0) { - for (bit= 0; bit<32; bit++) { - if (v3d->lay & (1<<bit)) { - v3d->layact= 1<<bit; + for (bit = 0; bit < 32; bit++) { + if (v3d->lay & (1 << bit)) { + v3d->layact = 1 << bit; break; } } @@ -410,11 +410,11 @@ void BKE_screen_view3d_scene_sync(bScreen *sc) { /* are there cameras in the views that are not in the scene? */ ScrArea *sa; - for (sa= sc->areabase.first; sa; sa= sa->next) { + for (sa = sc->areabase.first; sa; sa = sa->next) { SpaceLink *sl; - for (sl= sa->spacedata.first; sl; sl= sl->next) { - if (sl->spacetype==SPACE_VIEW3D) { - View3D *v3d= (View3D*) sl; + for (sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *) sl; BKE_screen_view3d_sync(v3d, sc->scene); } } @@ -428,14 +428,14 @@ void BKE_screen_view3d_main_sync(ListBase *screen_lb, Scene *scene) SpaceLink *sl; /* from scene copy to the other views */ - for (sc=screen_lb->first; sc; sc=sc->id.next) { - if (sc->scene!=scene) + for (sc = screen_lb->first; sc; sc = sc->id.next) { + if (sc->scene != scene) continue; - for (sa=sc->areabase.first; sa; sa=sa->next) - for (sl=sa->spacedata.first; sl; sl=sl->next) - if (sl->spacetype==SPACE_VIEW3D) - BKE_screen_view3d_sync((View3D*)sl, scene); + for (sa = sc->areabase.first; sa; sa = sa->next) + for (sl = sa->spacedata.first; sl; sl = sl->next) + if (sl->spacetype == SPACE_VIEW3D) + BKE_screen_view3d_sync((View3D *)sl, scene); } } @@ -449,7 +449,7 @@ void BKE_screen_view3d_main_sync(ListBase *screen_lb, Scene *scene) */ float BKE_screen_view3d_zoom_to_fac(float camzoom) { - return powf(((float)M_SQRT2 + camzoom/50.0f), 2.0f) / 4.0f; + return powf(((float)M_SQRT2 + camzoom / 50.0f), 2.0f) / 4.0f; } float BKE_screen_view3d_zoom_from_fac(float zoomfac) diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index da73491eaa3..84d2bf815bc 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -63,16 +63,16 @@ // evil quiet NaN definition static const int NAN_INT = 0x7FC00000; -#define NAN_FLT *((float*)(&NAN_INT)) +#define NAN_FLT *((float *)(&NAN_INT)) #ifdef WITH_AUDASPACE // evil global ;-) static int sound_cfra; #endif -struct bSound* sound_new_file(struct Main *bmain, const char *filename) +struct bSound *sound_new_file(struct Main *bmain, const char *filename) { - bSound* sound = NULL; + bSound *sound = NULL; char str[FILE_MAX]; char *path; @@ -86,10 +86,10 @@ struct bSound* sound_new_file(struct Main *bmain, const char *filename) BLI_path_abs(str, path); len = strlen(filename); - while (len > 0 && filename[len-1] != '/' && filename[len-1] != '\\') + while (len > 0 && filename[len - 1] != '/' && filename[len - 1] != '\\') len--; - sound = BKE_libblock_alloc(&bmain->sound, ID_SO, filename+len); + sound = BKE_libblock_alloc(&bmain->sound, ID_SO, filename + len); BLI_strncpy(sound->name, filename, FILE_MAX); // XXX unused currently sound->type = SOUND_TYPE_FILE; @@ -103,7 +103,7 @@ struct bSound* sound_new_file(struct Main *bmain, const char *filename) return sound; } -void BKE_sound_free(struct bSound* sound) +void BKE_sound_free(struct bSound *sound) { if (sound->packedfile) { freePackedFile(sound->packedfile); @@ -131,10 +131,10 @@ void BKE_sound_free(struct bSound* sound) static int force_device = -1; #ifdef WITH_JACK -static void sound_sync_callback(void* data, int mode, float time) +static void sound_sync_callback(void *data, int mode, float time) { - struct Main* bmain = (struct Main*)data; - struct Scene* scene; + struct Main *bmain = (struct Main *)data; + struct Scene *scene; scene = bmain->scene.first; while (scene) { @@ -223,11 +223,11 @@ void sound_exit(void) // XXX unused currently #if 0 -struct bSound* sound_new_buffer(struct Main *bmain, struct bSound *source) +struct bSound *sound_new_buffer(struct Main *bmain, struct bSound *source) { - bSound* sound = NULL; + bSound *sound = NULL; - char name[MAX_ID_NAME+5]; + char name[MAX_ID_NAME + 5]; strcpy(name, "buf_"); strcpy(name + 4, source->id.name); @@ -247,11 +247,11 @@ struct bSound* sound_new_buffer(struct Main *bmain, struct bSound *source) return sound; } -struct bSound* sound_new_limiter(struct Main *bmain, struct bSound *source, float start, float end) +struct bSound *sound_new_limiter(struct Main *bmain, struct bSound *source, float start, float end) { - bSound* sound = NULL; + bSound *sound = NULL; - char name[MAX_ID_NAME+5]; + char name[MAX_ID_NAME + 5]; strcpy(name, "lim_"); strcpy(name + 4, source->id.name); @@ -274,7 +274,7 @@ struct bSound* sound_new_limiter(struct Main *bmain, struct bSound *source, floa } #endif -void sound_delete(struct Main *bmain, struct bSound* sound) +void sound_delete(struct Main *bmain, struct bSound *sound) { if (sound) { BKE_sound_free(sound); @@ -283,7 +283,7 @@ void sound_delete(struct Main *bmain, struct bSound* sound) } } -void sound_cache(struct bSound* sound) +void sound_cache(struct bSound *sound) { sound->flags |= SOUND_FLAGS_CACHING; if (sound->cache) @@ -296,13 +296,13 @@ void sound_cache(struct bSound* sound) sound->playback_handle = sound->handle; } -void sound_cache_notifying(struct Main* main, struct bSound* sound) +void sound_cache_notifying(struct Main *main, struct bSound *sound) { sound_cache(sound); sound_update_sequencer(main, sound); } -void sound_delete_cache(struct bSound* sound) +void sound_delete_cache(struct bSound *sound) { sound->flags &= ~SOUND_FLAGS_CACHING; if (sound->cache) { @@ -312,7 +312,7 @@ void sound_delete_cache(struct bSound* sound) } } -void sound_load(struct Main *bmain, struct bSound* sound) +void sound_load(struct Main *bmain, struct bSound *sound) { if (sound) { if (sound->cache) { @@ -332,13 +332,13 @@ void sound_load(struct Main *bmain, struct bSound* sound) #if 0 switch (sound->type) { - case SOUND_TYPE_FILE: + case SOUND_TYPE_FILE: #endif { char fullpath[FILE_MAX]; /* load sound */ - PackedFile* pf = sound->packedfile; + PackedFile *pf = sound->packedfile; /* don't modify soundact->sound->name, only change a copy */ BLI_strncpy(fullpath, sound->name, sizeof(fullpath)); @@ -346,7 +346,7 @@ void sound_load(struct Main *bmain, struct bSound* sound) /* but we need a packed file then */ if (pf) - sound->handle = AUD_loadBuffer((unsigned char*) pf->data, pf->size); + sound->handle = AUD_loadBuffer((unsigned char *) pf->data, pf->size); /* or else load it from disk */ else sound->handle = AUD_load(fullpath); @@ -366,7 +366,7 @@ void sound_load(struct Main *bmain, struct bSound* sound) } #endif if (sound->flags & SOUND_FLAGS_MONO) { - void* handle = AUD_monoSound(sound->handle); + void *handle = AUD_monoSound(sound->handle); AUD_unload(sound->handle); sound->handle = handle; } @@ -384,7 +384,7 @@ void sound_load(struct Main *bmain, struct bSound* sound) } } -AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume) +AUD_Device *sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume) { return AUD_openMixdownDevice(specs, scene->sound_scene, volume, start / FPS); } @@ -393,7 +393,7 @@ void sound_create_scene(struct Scene *scene) { scene->sound_scene = AUD_createSequencer(FPS, scene->audio.flag & AUDIO_MUTE); AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound, - scene->audio.doppler_factor, scene->audio.distance_model); + scene->audio.doppler_factor, scene->audio.distance_model); scene->sound_scene_handle = NULL; scene->sound_scrub_handle = NULL; scene->speaker_handles = NULL; @@ -426,26 +426,26 @@ void sound_update_fps(struct Scene *scene) void sound_update_scene_listener(struct Scene *scene) { AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound, - scene->audio.doppler_factor, scene->audio.distance_model); + scene->audio.doppler_factor, scene->audio.distance_model); } -void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip) +void *sound_scene_add_scene_sound(struct Scene *scene, struct Sequence *sequence, int startframe, int endframe, int frameskip) { if (scene != sequence->scene) return AUD_addSequence(scene->sound_scene, sequence->scene->sound_scene, startframe / FPS, endframe / FPS, frameskip / FPS); return NULL; } -void* sound_scene_add_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence) +void *sound_scene_add_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) { return sound_scene_add_scene_sound(scene, sequence, sequence->startdisp, sequence->enddisp, sequence->startofs + sequence->anim_startofs); } -void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip) +void *sound_add_scene_sound(struct Scene *scene, struct Sequence *sequence, int startframe, int endframe, int frameskip) { - void* handle = AUD_addSequence(scene->sound_scene, sequence->sound->playback_handle, startframe / FPS, endframe / FPS, frameskip / FPS); + void *handle = AUD_addSequence(scene->sound_scene, sequence->sound->playback_handle, startframe / FPS, endframe / FPS, frameskip / FPS); AUD_muteSequence(handle, (sequence->flag & SEQ_MUTE) != 0); AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, CFRA, &sequence->volume, 0); AUD_setSequenceAnimData(handle, AUD_AP_PITCH, CFRA, &sequence->pitch, 0); @@ -453,29 +453,29 @@ void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int return handle; } -void* sound_add_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence) +void *sound_add_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) { return sound_add_scene_sound(scene, sequence, sequence->startdisp, sequence->enddisp, sequence->startofs + sequence->anim_startofs); } -void sound_remove_scene_sound(struct Scene *scene, void* handle) +void sound_remove_scene_sound(struct Scene *scene, void *handle) { AUD_removeSequence(scene->sound_scene, handle); } -void sound_mute_scene_sound(void* handle, char mute) +void sound_mute_scene_sound(void *handle, char mute) { AUD_muteSequence(handle, mute); } -void sound_move_scene_sound(struct Scene *scene, void* handle, int startframe, int endframe, int frameskip) +void sound_move_scene_sound(struct Scene *scene, void *handle, int startframe, int endframe, int frameskip) { AUD_moveSequence(handle, startframe / FPS, endframe / FPS, frameskip / FPS); } -void sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence) +void sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) { if (sequence->scene_sound) { sound_move_scene_sound(scene, sequence->scene_sound, @@ -484,7 +484,7 @@ void sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence* seque } } -void sound_update_scene_sound(void* handle, struct bSound* sound) +void sound_update_scene_sound(void *handle, struct bSound *sound) { AUD_updateSequenceSound(handle, sound->playback_handle); } @@ -499,24 +499,24 @@ void sound_set_scene_volume(struct Scene *scene, float volume) AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_VOLUME, CFRA, &volume, (scene->audio.flag & AUDIO_VOLUME_ANIMATED) != 0); } -void sound_set_scene_sound_volume(void* handle, float volume, char animated) +void sound_set_scene_sound_volume(void *handle, float volume, char animated) { AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, sound_cfra, &volume, animated); } -void sound_set_scene_sound_pitch(void* handle, float pitch, char animated) +void sound_set_scene_sound_pitch(void *handle, float pitch, char animated) { AUD_setSequenceAnimData(handle, AUD_AP_PITCH, sound_cfra, &pitch, animated); } -void sound_set_scene_sound_pan(void* handle, float pan, char animated) +void sound_set_scene_sound_pan(void *handle, float pan, char animated) { AUD_setSequenceAnimData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated); } -void sound_update_sequencer(struct Main* main, struct bSound* sound) +void sound_update_sequencer(struct Main *main, struct bSound *sound) { - struct Scene* scene; + struct Scene *scene; for (scene = main->scene.first; scene; scene = scene->id.next) { seq_update_sound(scene, sound); @@ -592,7 +592,7 @@ void sound_seek_scene(struct Main *bmain, struct Scene *scene) } animation_playing = 0; - for (screen=bmain->screen.first; screen; screen=screen->id.next) { + for (screen = bmain->screen.first; screen; screen = screen->id.next) { if (screen->animtimer) { animation_playing = 1; } @@ -645,24 +645,24 @@ int sound_scene_playing(struct Scene *scene) return -1; } -void sound_free_waveform(struct bSound* sound) +void sound_free_waveform(struct bSound *sound) { if (sound->waveform) { - MEM_freeN(((SoundWaveform*)sound->waveform)->data); + MEM_freeN(((SoundWaveform *)sound->waveform)->data); MEM_freeN(sound->waveform); } sound->waveform = NULL; } -void sound_read_waveform(struct bSound* sound) +void sound_read_waveform(struct bSound *sound) { AUD_SoundInfo info; info = AUD_getInfo(sound->playback_handle); if (info.length > 0) { - SoundWaveform* waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform"); + SoundWaveform *waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform"); int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND; waveform->data = MEM_mallocN(length * sizeof(float) * 3, "SoundWaveform.samples"); @@ -673,17 +673,17 @@ void sound_read_waveform(struct bSound* sound) } } -void sound_update_scene(struct Scene* scene) +void sound_update_scene(struct Scene *scene) { - Object* ob; - Base* base; - NlaTrack* track; - NlaStrip* strip; - Speaker* speaker; - Scene* sce_it; + Object *ob; + Base *base; + NlaTrack *track; + NlaStrip *strip; + Speaker *speaker; + Scene *sce_it; - void* new_set = AUD_createSet(); - void* handle; + void *new_set = AUD_createSet(); + void *handle; float quat[4]; for (SETLOOPER(scene, sce_it, base)) { @@ -693,7 +693,7 @@ void sound_update_scene(struct Scene* scene) for (track = ob->adt->nla_tracks.first; track; track = track->next) { for (strip = track->strips.first; strip; strip = strip->next) { if (strip->type == NLASTRIP_TYPE_SOUND) { - speaker = (Speaker*)ob->data; + speaker = (Speaker *)ob->data; if (AUD_removeSet(scene->speaker_handles, strip->speaker_handle)) { if (speaker->sound) @@ -713,10 +713,10 @@ void sound_update_scene(struct Scene* scene) if (strip->speaker_handle) { AUD_addSet(new_set, strip->speaker_handle); AUD_updateSequenceData(strip->speaker_handle, speaker->volume_max, - speaker->volume_min, speaker->distance_max, - speaker->distance_reference, speaker->attenuation, - speaker->cone_angle_outer, speaker->cone_angle_inner, - speaker->cone_volume_outer); + speaker->volume_min, speaker->distance_max, + speaker->distance_reference, speaker->attenuation, + speaker->cone_angle_outer, speaker->cone_angle_inner, + speaker->cone_volume_outer); mat4_to_quat(quat, ob->obmat); AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_LOCATION, CFRA, ob->obmat[3], 1); @@ -747,9 +747,9 @@ void sound_update_scene(struct Scene* scene) scene->speaker_handles = new_set; } -void* sound_get_factory(void* sound) +void *sound_get_factory(void *sound) { - return ((struct bSound*) sound)->playback_handle; + return ((struct bSound *) sound)->playback_handle; } #else // WITH_AUDASPACE diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c index e94a11b8f89..09440591826 100644 --- a/source/blender/blenkernel/intern/speaker.c +++ b/source/blender/blenkernel/intern/speaker.c @@ -47,7 +47,7 @@ void *BKE_speaker_add(const char *name) { Speaker *spk; - spk= BKE_libblock_alloc(&G.main->speaker, ID_SPK, name); + spk = BKE_libblock_alloc(&G.main->speaker, ID_SPK, name); spk->attenuation = 1.0f; spk->cone_angle_inner = 360.0f; @@ -69,7 +69,7 @@ Speaker *BKE_speaker_copy(Speaker *spk) { Speaker *spkn; - spkn= BKE_libblock_copy(&spk->id); + spkn = BKE_libblock_copy(&spk->id); if (spkn->sound) spkn->sound->id.us++; @@ -78,51 +78,51 @@ Speaker *BKE_speaker_copy(Speaker *spk) void BKE_speaker_make_local(Speaker *spk) { - Main *bmain= G.main; + Main *bmain = G.main; Object *ob; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (spk->id.lib==NULL) return; - if (spk->id.us==1) { + if (spk->id.lib == NULL) return; + if (spk->id.us == 1) { id_clear_lib_data(bmain, &spk->id); return; } - ob= bmain->object.first; + ob = bmain->object.first; while (ob) { - if (ob->data==spk) { - if (ob->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (ob->data == spk) { + if (ob->id.lib) is_lib = TRUE; + else is_local = TRUE; } - ob= ob->id.next; + ob = ob->id.next; } if (is_local && is_lib == FALSE) { id_clear_lib_data(bmain, &spk->id); } else if (is_local && is_lib) { - Speaker *spk_new= BKE_speaker_copy(spk); - spk_new->id.us= 0; + Speaker *spk_new = BKE_speaker_copy(spk); + spk_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, spk->id.lib, &spk_new->id); - ob= bmain->object.first; + ob = bmain->object.first; while (ob) { - if (ob->data==spk) { + if (ob->data == spk) { - if (ob->id.lib==NULL) { - ob->data= spk_new; + if (ob->id.lib == NULL) { + ob->data = spk_new; spk_new->id.us++; spk->id.us--; } } - ob= ob->id.next; + ob = ob->id.next; } } } diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index e3e4f663e27..e8010ceceff 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -135,8 +135,8 @@ static void txt_pop_last(Text *text); static void txt_undo_add_op(Text *text, int op); static void txt_undo_add_block(Text *text, int op, const char *buf); static void txt_delete_line(Text *text, TextLine *line); -static void txt_delete_sel (Text *text); -static void txt_make_dirty (Text *text); +static void txt_delete_sel(Text *text); +static void txt_make_dirty(Text *text); /***/ @@ -155,19 +155,19 @@ int txt_get_undostate(void) static void init_undo_text(Text *text) { - text->undo_pos= -1; - text->undo_len= TXT_INIT_UNDO; - text->undo_buf= MEM_mallocN(text->undo_len, "undo buf"); + text->undo_pos = -1; + text->undo_len = TXT_INIT_UNDO; + text->undo_buf = MEM_mallocN(text->undo_len, "undo buf"); } void BKE_text_free(Text *text) { TextLine *tmp; - for (tmp= text->lines.first; tmp; tmp= tmp->next) { + for (tmp = text->lines.first; tmp; tmp = tmp->next) { MEM_freeN(tmp->line); if (tmp->format) - MEM_freeN(tmp->format); + MEM_freeN(tmp->format); } BLI_freelistN(&text->lines); @@ -182,41 +182,41 @@ void BKE_text_free(Text *text) Text *BKE_text_add(const char *name) { - Main *bmain= G.main; + Main *bmain = G.main; Text *ta; TextLine *tmp; - ta= BKE_libblock_alloc(&bmain->text, ID_TXT, name); - ta->id.us= 1; + ta = BKE_libblock_alloc(&bmain->text, ID_TXT, name); + ta->id.us = 1; - ta->name= NULL; + ta->name = NULL; init_undo_text(ta); - ta->nlines=1; - ta->flags= TXT_ISDIRTY | TXT_ISMEM; - if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE)==0) + ta->nlines = 1; + ta->flags = TXT_ISDIRTY | TXT_ISMEM; + if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE) == 0) ta->flags |= TXT_TABSTOSPACES; - ta->lines.first= ta->lines.last= NULL; - ta->markers.first= ta->markers.last= NULL; + ta->lines.first = ta->lines.last = NULL; + ta->markers.first = ta->markers.last = NULL; - tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= (char*) MEM_mallocN(1, "textline_string"); - tmp->format= NULL; + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = (char *) MEM_mallocN(1, "textline_string"); + tmp->format = NULL; - tmp->line[0]=0; - tmp->len= 0; + tmp->line[0] = 0; + tmp->len = 0; - tmp->next= NULL; - tmp->prev= NULL; + tmp->next = NULL; + tmp->prev = NULL; BLI_addhead(&ta->lines, tmp); - ta->curl= ta->lines.first; - ta->curc= 0; - ta->sell= ta->lines.first; - ta->selc= 0; + ta->curl = ta->lines.first; + ta->curc = 0; + ta->sell = ta->lines.first; + ta->selc = 0; return ta; } @@ -225,35 +225,35 @@ Text *BKE_text_add(const char *name) /* to a valid utf-8 sequences */ int txt_extended_ascii_as_utf8(char **str) { - int bad_char, added= 0, i= 0; + int bad_char, added = 0, i = 0; int length = strlen(*str); while ((*str)[i]) { - if ((bad_char= BLI_utf8_invalid_byte(*str+i, length-i)) == -1) + if ((bad_char = BLI_utf8_invalid_byte(*str + i, length - i)) == -1) break; added++; - i+= bad_char + 1; + i += bad_char + 1; } if (added != 0) { - char *newstr = MEM_mallocN(length+added+1, "text_line"); + char *newstr = MEM_mallocN(length + added + 1, "text_line"); int mi = 0; - i= 0; + i = 0; while ((*str)[i]) { - if ((bad_char= BLI_utf8_invalid_byte((*str)+i, length-i)) == -1) { - memcpy(newstr+mi, (*str)+i, length - i + 1); + if ((bad_char = BLI_utf8_invalid_byte((*str) + i, length - i)) == -1) { + memcpy(newstr + mi, (*str) + i, length - i + 1); break; } - memcpy(newstr+mi, (*str)+i, bad_char); + memcpy(newstr + mi, (*str) + i, bad_char); - BLI_str_utf8_from_unicode((*str)[i+bad_char], newstr+mi+bad_char); - i+= bad_char+1; - mi+= bad_char+2; + BLI_str_utf8_from_unicode((*str)[i + bad_char], newstr + mi + bad_char); + i += bad_char + 1; + mi += bad_char + 2; } - newstr[length+added] = '\0'; + newstr[length + added] = '\0'; MEM_freeN(*str); *str = newstr; } @@ -264,18 +264,18 @@ int txt_extended_ascii_as_utf8(char **str) // this function removes any control characters from // a textline and fixes invalid utf-8 sequences -static void cleanup_textline(TextLine * tl) +static void cleanup_textline(TextLine *tl) { int i; - for (i = 0; i < tl->len; i++ ) { + for (i = 0; i < tl->len; i++) { if (tl->line[i] < ' ' && tl->line[i] != '\t') { memmove(tl->line + i, tl->line + i + 1, tl->len - i); tl->len--; i--; } } - tl->len+= txt_extended_ascii_as_utf8(&tl->line); + tl->len += txt_extended_ascii_as_utf8(&tl->line); } int BKE_text_reload(Text *text) @@ -292,32 +292,32 @@ int BKE_text_reload(Text *text) BLI_strncpy(str, text->name, FILE_MAX); BLI_path_abs(str, G.main->name); - fp= BLI_fopen(str, "r"); - if (fp==NULL) return 0; + fp = BLI_fopen(str, "r"); + if (fp == NULL) return 0; /* free memory: */ - for (tmp= text->lines.first; tmp; tmp= tmp->next) { + for (tmp = text->lines.first; tmp; tmp = tmp->next) { MEM_freeN(tmp->line); if (tmp->format) MEM_freeN(tmp->format); } BLI_freelistN(&text->lines); - text->lines.first= text->lines.last= NULL; - text->curl= text->sell= NULL; + text->lines.first = text->lines.last = NULL; + text->curl = text->sell = NULL; /* clear undo buffer */ MEM_freeN(text->undo_buf); init_undo_text(text); fseek(fp, 0L, SEEK_END); - len= ftell(fp); + len = ftell(fp); fseek(fp, 0L, SEEK_SET); - text->undo_pos= -1; + text->undo_pos = -1; - buffer= MEM_mallocN(len, "text_buffer"); + buffer = MEM_mallocN(len, "text_buffer"); // under windows fread can return less then len bytes because // of CR stripping len = fread(buffer, 1, len, fp); @@ -325,40 +325,40 @@ int BKE_text_reload(Text *text) fclose(fp); stat(str, &st); - text->mtime= st.st_mtime; - - text->nlines=0; - llen=0; - for (i=0; i<len; i++) { - if (buffer[i]=='\n') { - tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= (char*) MEM_mallocN(llen+1, "textline_string"); - tmp->format= NULL; - - if (llen) memcpy(tmp->line, &buffer[i-llen], llen); - tmp->line[llen]=0; - tmp->len= llen; + text->mtime = st.st_mtime; + + text->nlines = 0; + llen = 0; + for (i = 0; i < len; i++) { + if (buffer[i] == '\n') { + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); + tmp->format = NULL; + + if (llen) memcpy(tmp->line, &buffer[i - llen], llen); + tmp->line[llen] = 0; + tmp->len = llen; cleanup_textline(tmp); BLI_addtail(&text->lines, tmp); text->nlines++; - llen=0; + llen = 0; continue; } llen++; } - if (llen!=0 || text->nlines==0) { - tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= (char*) MEM_mallocN(llen+1, "textline_string"); - tmp->format= NULL; + if (llen != 0 || text->nlines == 0) { + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); + tmp->format = NULL; - if (llen) memcpy(tmp->line, &buffer[i-llen], llen); + if (llen) memcpy(tmp->line, &buffer[i - llen], llen); - tmp->line[llen]=0; - tmp->len= llen; + tmp->line[llen] = 0; + tmp->len = llen; cleanup_textline(tmp); @@ -366,8 +366,8 @@ int BKE_text_reload(Text *text) text->nlines++; } - text->curl= text->sell= text->lines.first; - text->curc= text->selc= 0; + text->curl = text->sell = text->lines.first; + text->curc = text->selc = 0; MEM_freeN(buffer); return 1; @@ -375,7 +375,7 @@ int BKE_text_reload(Text *text) Text *BKE_text_load(const char *file, const char *relpath) { - Main *bmain= G.main; + Main *bmain = G.main; FILE *fp; int i, llen, len; unsigned char *buffer; @@ -388,29 +388,29 @@ Text *BKE_text_load(const char *file, const char *relpath) if (relpath) /* can be NULL (bg mode) */ BLI_path_abs(str, relpath); - fp= BLI_fopen(str, "r"); - if (fp==NULL) return NULL; + fp = BLI_fopen(str, "r"); + if (fp == NULL) return NULL; - ta= BKE_libblock_alloc(&bmain->text, ID_TXT, BLI_path_basename(str)); - ta->id.us= 1; + ta = BKE_libblock_alloc(&bmain->text, ID_TXT, BLI_path_basename(str)); + ta->id.us = 1; - ta->lines.first= ta->lines.last= NULL; - ta->markers.first= ta->markers.last= NULL; - ta->curl= ta->sell= NULL; + ta->lines.first = ta->lines.last = NULL; + ta->markers.first = ta->markers.last = NULL; + ta->curl = ta->sell = NULL; - if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE)==0) - ta->flags= TXT_TABSTOSPACES; + if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE) == 0) + ta->flags = TXT_TABSTOSPACES; fseek(fp, 0L, SEEK_END); - len= ftell(fp); + len = ftell(fp); fseek(fp, 0L, SEEK_SET); - ta->name= MEM_mallocN(strlen(file)+1, "text_name"); + ta->name = MEM_mallocN(strlen(file) + 1, "text_name"); strcpy(ta->name, file); init_undo_text(ta); - buffer= MEM_mallocN(len, "text_buffer"); + buffer = MEM_mallocN(len, "text_buffer"); // under windows fread can return less then len bytes because // of CR stripping len = fread(buffer, 1, len, fp); @@ -418,26 +418,26 @@ Text *BKE_text_load(const char *file, const char *relpath) fclose(fp); stat(str, &st); - ta->mtime= st.st_mtime; - - ta->nlines=0; - llen=0; - for (i=0; i<len; i++) { - if (buffer[i]=='\n') { - tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= (char*) MEM_mallocN(llen+1, "textline_string"); - tmp->format= NULL; - - if (llen) memcpy(tmp->line, &buffer[i-llen], llen); - tmp->line[llen]=0; - tmp->len= llen; + ta->mtime = st.st_mtime; + + ta->nlines = 0; + llen = 0; + for (i = 0; i < len; i++) { + if (buffer[i] == '\n') { + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); + tmp->format = NULL; + + if (llen) memcpy(tmp->line, &buffer[i - llen], llen); + tmp->line[llen] = 0; + tmp->len = llen; cleanup_textline(tmp); BLI_addtail(&ta->lines, tmp); ta->nlines++; - llen=0; + llen = 0; continue; } llen++; @@ -449,15 +449,15 @@ Text *BKE_text_load(const char *file, const char *relpath) * - file is empty. in this case new line is needed to start editing from. * - last characted in buffer is \n. in this case new line is needed to * deal with newline at end of file. (see [#28087]) (sergey) */ - if (llen!=0 || ta->nlines==0 || buffer[len-1]=='\n') { - tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= (char*) MEM_mallocN(llen+1, "textline_string"); - tmp->format= NULL; + if (llen != 0 || ta->nlines == 0 || buffer[len - 1] == '\n') { + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = (char *) MEM_mallocN(llen + 1, "textline_string"); + tmp->format = NULL; - if (llen) memcpy(tmp->line, &buffer[i-llen], llen); + if (llen) memcpy(tmp->line, &buffer[i - llen], llen); - tmp->line[llen]=0; - tmp->len= llen; + tmp->line[llen] = 0; + tmp->len = llen; cleanup_textline(tmp); @@ -465,8 +465,8 @@ Text *BKE_text_load(const char *file, const char *relpath) ta->nlines++; } - ta->curl= ta->sell= ta->lines.first; - ta->curc= ta->selc= 0; + ta->curl = ta->sell = ta->lines.first; + ta->curc = ta->selc = 0; MEM_freeN(buffer); @@ -478,43 +478,43 @@ Text *BKE_text_copy(Text *ta) Text *tan; TextLine *line, *tmp; - tan= BKE_libblock_copy(&ta->id); + tan = BKE_libblock_copy(&ta->id); /* file name can be NULL */ if (ta->name) { - tan->name= MEM_mallocN(strlen(ta->name)+1, "text_name"); + tan->name = MEM_mallocN(strlen(ta->name) + 1, "text_name"); strcpy(tan->name, ta->name); } else { - tan->name= NULL; + tan->name = NULL; } tan->flags = ta->flags | TXT_ISDIRTY; - tan->lines.first= tan->lines.last= NULL; - tan->markers.first= tan->markers.last= NULL; - tan->curl= tan->sell= NULL; + tan->lines.first = tan->lines.last = NULL; + tan->markers.first = tan->markers.last = NULL; + tan->curl = tan->sell = NULL; - tan->nlines= ta->nlines; + tan->nlines = ta->nlines; - line= ta->lines.first; + line = ta->lines.first; /* Walk down, reconstructing */ while (line) { - tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= MEM_mallocN(line->len+1, "textline_string"); - tmp->format= NULL; + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = MEM_mallocN(line->len + 1, "textline_string"); + tmp->format = NULL; strcpy(tmp->line, line->line); - tmp->len= line->len; + tmp->len = line->len; BLI_addtail(&tan->lines, tmp); - line= line->next; + line = line->next; } - tan->curl= tan->sell= tan->lines.first; - tan->curc= tan->selc= 0; + tan->curl = tan->sell = tan->lines.first; + tan->curc = tan->selc = 0; init_undo_text(tan); @@ -531,27 +531,27 @@ void BKE_text_unlink(Main *bmain, Text *text) bConstraint *con; short update; - for (ob=bmain->object.first; ob; ob=ob->id.next) { + for (ob = bmain->object.first; ob; ob = ob->id.next) { /* game controllers */ - for (cont=ob->controllers.first; cont; cont=cont->next) { - if (cont->type==CONT_PYTHON) { + for (cont = ob->controllers.first; cont; cont = cont->next) { + if (cont->type == CONT_PYTHON) { bPythonCont *pc; - pc= cont->data; - if (pc->text==text) pc->text= NULL; + pc = cont->data; + if (pc->text == text) pc->text = NULL; } } /* pyconstraints */ update = 0; - if (ob->type==OB_ARMATURE && ob->pose) { + if (ob->type == OB_ARMATURE && ob->pose) { bPoseChannel *pchan; - for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - for (con = pchan->constraints.first; con; con=con->next) { - if (con->type==CONSTRAINT_TYPE_PYTHON) { + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + for (con = pchan->constraints.first; con; con = con->next) { + if (con->type == CONSTRAINT_TYPE_PYTHON) { bPythonConstraint *data = con->data; - if (data->text==text) data->text = NULL; + if (data->text == text) data->text = NULL; update = 1; } @@ -559,10 +559,10 @@ void BKE_text_unlink(Main *bmain, Text *text) } } - for (con = ob->constraints.first; con; con=con->next) { - if (con->type==CONSTRAINT_TYPE_PYTHON) { + for (con = ob->constraints.first; con; con = con->next) { + if (con->type == CONSTRAINT_TYPE_PYTHON) { bPythonConstraint *data = con->data; - if (data->text==text) data->text = NULL; + if (data->text == text) data->text = NULL; update = 1; } } @@ -575,22 +575,22 @@ void BKE_text_unlink(Main *bmain, Text *text) // XXX nodeDynamicUnlinkText(&text->id); /* text space */ - for (scr= bmain->screen.first; scr; scr= scr->id.next) { - for (area= scr->areabase.first; area; area= area->next) { - for (sl= area->spacedata.first; sl; sl= sl->next) { - if (sl->spacetype==SPACE_TEXT) { - SpaceText *st= (SpaceText*) sl; - - if (st->text==text) { - st->text= NULL; - st->top= 0; + for (scr = bmain->screen.first; scr; scr = scr->id.next) { + for (area = scr->areabase.first; area; area = area->next) { + for (sl = area->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_TEXT) { + SpaceText *st = (SpaceText *) sl; + + if (st->text == text) { + st->text = NULL; + st->top = 0; } } } } } - text->id.us= 0; + text->id.us = 0; } void BKE_text_clear(Text *text) /* called directly from rna */ @@ -627,25 +627,25 @@ static void make_new_line(TextLine *line, char *newline) if (line->line) MEM_freeN(line->line); if (line->format) MEM_freeN(line->format); - line->line= newline; - line->len= strlen(newline); - line->format= NULL; + line->line = newline; + line->len = strlen(newline); + line->format = NULL; } static TextLine *txt_new_line(const char *str) { TextLine *tmp; - if (!str) str= ""; + if (!str) str = ""; - tmp= (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= MEM_mallocN(strlen(str)+1, "textline_string"); - tmp->format= NULL; + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = MEM_mallocN(strlen(str) + 1, "textline_string"); + tmp->format = NULL; strcpy(tmp->line, str); - tmp->len= strlen(str); - tmp->next= tmp->prev= NULL; + tmp->len = strlen(str); + tmp->next = tmp->prev = NULL; return tmp; } @@ -654,14 +654,14 @@ static TextLine *txt_new_linen(const char *str, int n) { TextLine *tmp; - tmp= (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); - tmp->line= MEM_mallocN(n+1, "textline_string"); - tmp->format= NULL; + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); + tmp->line = MEM_mallocN(n + 1, "textline_string"); + tmp->format = NULL; - BLI_strncpy(tmp->line, (str)? str: "", n+1); + BLI_strncpy(tmp->line, (str) ? str : "", n + 1); - tmp->len= strlen(tmp->line); - tmp->next= tmp->prev= NULL; + tmp->len = strlen(tmp->line); + tmp->next = tmp->prev = NULL; return tmp; } @@ -673,61 +673,61 @@ void txt_clean_text(Text *text) if (!text) return; if (!text->lines.first) { - if (text->lines.last) text->lines.first= text->lines.last; - else text->lines.first= text->lines.last= txt_new_line(NULL); + if (text->lines.last) text->lines.first = text->lines.last; + else text->lines.first = text->lines.last = txt_new_line(NULL); } - if (!text->lines.last) text->lines.last= text->lines.first; + if (!text->lines.last) text->lines.last = text->lines.first; - top= (TextLine **) &text->lines.first; - bot= (TextLine **) &text->lines.last; + top = (TextLine **) &text->lines.first; + bot = (TextLine **) &text->lines.last; - while ((*top)->prev) *top= (*top)->prev; - while ((*bot)->next) *bot= (*bot)->next; + while ((*top)->prev) *top = (*top)->prev; + while ((*bot)->next) *bot = (*bot)->next; if (!text->curl) { - if (text->sell) text->curl= text->sell; - else text->curl= text->lines.first; - text->curc= 0; + if (text->sell) text->curl = text->sell; + else text->curl = text->lines.first; + text->curc = 0; } if (!text->sell) { - text->sell= text->curl; - text->selc= 0; + text->sell = text->curl; + text->selc = 0; } } int txt_get_span(TextLine *from, TextLine *to) { - int ret=0; - TextLine *tmp= from; + int ret = 0; + TextLine *tmp = from; if (!to || !from) return 0; - if (from==to) return 0; + if (from == to) return 0; /* Look forwards */ while (tmp) { if (tmp == to) return ret; ret++; - tmp= tmp->next; + tmp = tmp->next; } /* Look backwards */ if (!tmp) { - tmp= from; - ret=0; + tmp = from; + ret = 0; while (tmp) { if (tmp == to) break; ret--; - tmp= tmp->prev; + tmp = tmp->prev; } - if (!tmp) ret=0; + if (!tmp) ret = 0; } return ret; } -static void txt_make_dirty (Text *text) +static void txt_make_dirty(Text *text) { text->flags |= TXT_ISDIRTY; #ifdef WITH_PYTHON @@ -739,30 +739,30 @@ static void txt_make_dirty (Text *text) /* Cursor utility functions */ /****************************/ -static void txt_curs_cur (Text *text, TextLine ***linep, int **charp) +static void txt_curs_cur(Text *text, TextLine ***linep, int **charp) { - *linep= &text->curl; *charp= &text->curc; + *linep = &text->curl; *charp = &text->curc; } -static void txt_curs_sel (Text *text, TextLine ***linep, int **charp) +static void txt_curs_sel(Text *text, TextLine ***linep, int **charp) { - *linep= &text->sell; *charp= &text->selc; + *linep = &text->sell; *charp = &text->selc; } -static void txt_curs_first (Text *text, TextLine **linep, int *charp) +static void txt_curs_first(Text *text, TextLine **linep, int *charp) { - if (text->curl==text->sell) { - *linep= text->curl; - if (text->curc<text->selc) *charp= text->curc; - else *charp= text->selc; + if (text->curl == text->sell) { + *linep = text->curl; + if (text->curc < text->selc) *charp = text->curc; + else *charp = text->selc; } - else if (txt_get_span(text->lines.first, text->curl)<txt_get_span(text->lines.first, text->sell)) { - *linep= text->curl; - *charp= text->curc; + else if (txt_get_span(text->lines.first, text->curl) < txt_get_span(text->lines.first, text->sell)) { + *linep = text->curl; + *charp = text->curc; } else { - *linep= text->sell; - *charp= text->selc; + *linep = text->sell; + *charp = text->selc; } } @@ -772,7 +772,7 @@ static void txt_curs_first (Text *text, TextLine **linep, int *charp) int txt_utf8_offset_to_index(const char *str, int offset) { - int index= 0, pos= 0; + int index = 0, pos = 0; while (pos != offset) { pos += BLI_str_utf8_size(str + pos); index++; @@ -782,7 +782,7 @@ int txt_utf8_offset_to_index(const char *str, int offset) int txt_utf8_index_to_offset(const char *str, int index) { - int offset= 0, pos= 0; + int offset = 0, pos = 0; while (pos != index) { offset += BLI_str_utf8_size(str + offset); pos++; @@ -796,7 +796,7 @@ static int txt_utf8_len(const char *src) { int len; - for (len=0; *src; len++) { + for (len = 0; *src; len++) { src += BLI_str_utf8_size(src); } @@ -817,12 +817,12 @@ void txt_move_up(Text *text, short sel) if ((*linep)->prev) { int index = txt_utf8_offset_to_index((*linep)->line, *charp); - *linep= (*linep)->prev; - if (index > txt_utf8_len((*linep)->line)) *charp= (*linep)->len; - else *charp= txt_utf8_index_to_offset((*linep)->line, index); + *linep = (*linep)->prev; + if (index > txt_utf8_len((*linep)->line)) *charp = (*linep)->len; + else *charp = txt_utf8_index_to_offset((*linep)->line, index); if (!undoing) - txt_undo_add_op(text, sel?UNDO_SUP:UNDO_CUP); + txt_undo_add_op(text, sel ? UNDO_SUP : UNDO_CUP); } else { txt_move_bol(text, sel); @@ -845,12 +845,12 @@ void txt_move_down(Text *text, short sel) if ((*linep)->next) { int index = txt_utf8_offset_to_index((*linep)->line, *charp); - *linep= (*linep)->next; - if (index > txt_utf8_len((*linep)->line)) *charp= (*linep)->len; - else *charp= txt_utf8_index_to_offset((*linep)->line, index); + *linep = (*linep)->next; + if (index > txt_utf8_len((*linep)->line)) *charp = (*linep)->len; + else *charp = txt_utf8_index_to_offset((*linep)->line, index); if (!undoing) - txt_undo_add_op(text, sel?UNDO_SDOWN:UNDO_CDOWN); + txt_undo_add_op(text, sel ? UNDO_SDOWN : UNDO_CDOWN); } else { txt_move_eol(text, sel); @@ -862,49 +862,49 @@ void txt_move_down(Text *text, short sel) void txt_move_left(Text *text, short sel) { TextLine **linep; - int *charp, oundoing= undoing; - int tabsize= 0, i= 0; + int *charp, oundoing = undoing; + int tabsize = 0, i = 0; if (!text) return; if (sel) txt_curs_sel(text, &linep, &charp); else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); } if (!*linep) return; - undoing= 1; + undoing = 1; - if (*charp== 0) { + if (*charp == 0) { if ((*linep)->prev) { txt_move_up(text, sel); - *charp= (*linep)->len; + *charp = (*linep)->len; } } else { // do nice left only if there are only spaces // TXT_TABSIZE hardcoded in DNA_text_types.h if (text->flags & TXT_TABSTOSPACES) { - tabsize= (*charp < TXT_TABSIZE) ? *charp : TXT_TABSIZE; + tabsize = (*charp < TXT_TABSIZE) ? *charp : TXT_TABSIZE; - for (i=0; i<(*charp); i++) + for (i = 0; i < (*charp); i++) if ((*linep)->line[i] != ' ') { - tabsize= 0; + tabsize = 0; break; } // if in the middle of the space-tab if (tabsize && (*charp) % TXT_TABSIZE != 0) - tabsize= ((*charp) % TXT_TABSIZE); + tabsize = ((*charp) % TXT_TABSIZE); } if (tabsize) - (*charp)-= tabsize; + (*charp) -= tabsize; else { - const char *prev= BLI_str_prev_char_utf8((*linep)->line + *charp); - *charp= prev - (*linep)->line; + const char *prev = BLI_str_prev_char_utf8((*linep)->line + *charp); + *charp = prev - (*linep)->line; } } - undoing= oundoing; - if (!undoing) txt_undo_add_op(text, sel?UNDO_SLEFT:UNDO_CLEFT); + undoing = oundoing; + if (!undoing) txt_undo_add_op(text, sel ? UNDO_SLEFT : UNDO_CLEFT); if (!sel) txt_pop_sel(text); } @@ -912,44 +912,44 @@ void txt_move_left(Text *text, short sel) void txt_move_right(Text *text, short sel) { TextLine **linep; - int *charp, oundoing= undoing, do_tab= 0, i; + int *charp, oundoing = undoing, do_tab = 0, i; if (!text) return; if (sel) txt_curs_sel(text, &linep, &charp); else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); } if (!*linep) return; - undoing= 1; + undoing = 1; - if (*charp== (*linep)->len) { + if (*charp == (*linep)->len) { if ((*linep)->next) { txt_move_down(text, sel); - *charp= 0; + *charp = 0; } } else { // do nice right only if there are only spaces // spaces hardcoded in DNA_text_types.h - if (text->flags & TXT_TABSTOSPACES && (*linep)->line[*charp]== ' ') { - do_tab= 1; - for (i=0; i<*charp; i++) - if ((*linep)->line[i]!= ' ') { - do_tab= 0; + if (text->flags & TXT_TABSTOSPACES && (*linep)->line[*charp] == ' ') { + do_tab = 1; + for (i = 0; i < *charp; i++) + if ((*linep)->line[i] != ' ') { + do_tab = 0; break; } } if (do_tab) { - int tabsize= (*charp) % TXT_TABSIZE + 1; - for (i=*charp+1; (*linep)->line[i]==' ' && tabsize<TXT_TABSIZE; i++) + int tabsize = (*charp) % TXT_TABSIZE + 1; + for (i = *charp + 1; (*linep)->line[i] == ' ' && tabsize < TXT_TABSIZE; i++) tabsize++; - (*charp)= i; + (*charp) = i; } - else (*charp)+= BLI_str_utf8_size((*linep)->line + *charp); + else (*charp) += BLI_str_utf8_size((*linep)->line + *charp); } - undoing= oundoing; - if (!undoing) txt_undo_add_op(text, sel?UNDO_SRIGHT:UNDO_CRIGHT); + undoing = oundoing; + if (!undoing) txt_undo_add_op(text, sel ? UNDO_SRIGHT : UNDO_CRIGHT); if (!sel) txt_pop_sel(text); } @@ -968,19 +968,19 @@ void txt_jump_left(Text *text, short sel) oldflags = text->flags; text->flags &= ~TXT_TABSTOSPACES; - oldl= *linep; - oldc= *charp; - oldu= undoing; - undoing= 1; /* Don't push individual moves to undo stack */ + oldl = *linep; + oldc = *charp; + oldu = undoing; + undoing = 1; /* Don't push individual moves to undo stack */ BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len, - charp, STRCUR_DIR_PREV, + charp, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM); text->flags = oldflags; - undoing= oldu; - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + undoing = oldu; + if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); } void txt_jump_right(Text *text, short sel) @@ -997,19 +997,19 @@ void txt_jump_right(Text *text, short sel) oldflags = text->flags; text->flags &= ~TXT_TABSTOSPACES; - oldl= *linep; - oldc= *charp; - oldu= undoing; - undoing= 1; /* Don't push individual moves to undo stack */ + oldl = *linep; + oldc = *charp; + oldu = undoing; + undoing = 1; /* Don't push individual moves to undo stack */ BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len, - charp, STRCUR_DIR_NEXT, + charp, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM); text->flags = oldflags; - undoing= oldu; - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + undoing = oldu; + if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); } void txt_move_bol(Text *text, short sel) @@ -1021,12 +1021,12 @@ void txt_move_bol(Text *text, short sel) if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; - old= *charp; + old = *charp; - *charp= 0; + *charp = 0; if (!sel) txt_pop_sel(text); - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); } void txt_move_eol(Text *text, short sel) @@ -1038,12 +1038,12 @@ void txt_move_eol(Text *text, short sel) if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; - old= *charp; + old = *charp; - *charp= (*linep)->len; + *charp = (*linep)->len; if (!sel) txt_pop_sel(text); - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); } void txt_move_bof(Text *text, short sel) @@ -1055,13 +1055,13 @@ void txt_move_bof(Text *text, short sel) if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; - old= *charp; + old = *charp; - *linep= text->lines.first; - *charp= 0; + *linep = text->lines.first; + *charp = 0; if (!sel) txt_pop_sel(text); - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); } void txt_move_eof(Text *text, short sel) @@ -1073,13 +1073,13 @@ void txt_move_eof(Text *text, short sel) if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; - old= *charp; + old = *charp; - *linep= text->lines.last; - *charp= (*linep)->len; + *linep = text->lines.last; + *charp = (*linep)->len; if (!sel) txt_pop_sel(text); - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); } void txt_move_toline(Text *text, unsigned int line, short sel) @@ -1098,71 +1098,71 @@ void txt_move_to(Text *text, unsigned int line, unsigned int ch, short sel) if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; - oldc= *charp; - oldl= *linep; + oldc = *charp; + oldl = *linep; - *linep= text->lines.first; - for (i=0; i<line; i++) { - if ((*linep)->next) *linep= (*linep)->next; + *linep = text->lines.first; + for (i = 0; i < line; i++) { + if ((*linep)->next) *linep = (*linep)->next; else break; } - if (ch>(unsigned int)((*linep)->len)) - ch= (unsigned int)((*linep)->len); - *charp= ch; + if (ch > (unsigned int)((*linep)->len)) + ch = (unsigned int)((*linep)->len); + *charp = ch; if (!sel) txt_pop_sel(text); - if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); } /****************************/ /* Text selection functions */ /****************************/ -static void txt_curs_swap (Text *text) +static void txt_curs_swap(Text *text) { TextLine *tmpl; int tmpc; - tmpl= text->curl; - text->curl= text->sell; - text->sell= tmpl; - - tmpc= text->curc; - text->curc= text->selc; - text->selc= tmpc; + tmpl = text->curl; + text->curl = text->sell; + text->sell = tmpl; + + tmpc = text->curc; + text->curc = text->selc; + text->selc = tmpc; if (!undoing) txt_undo_add_op(text, UNDO_SWAP); } -static void txt_pop_first (Text *text) +static void txt_pop_first(Text *text) { - if (txt_get_span(text->curl, text->sell)<0 || - (text->curl==text->sell && text->curc>text->selc)) { + if (txt_get_span(text->curl, text->sell) < 0 || + (text->curl == text->sell && text->curc > text->selc)) { txt_curs_swap(text); } if (!undoing) txt_undo_add_toop(text, UNDO_STO, - txt_get_span(text->lines.first, text->sell), - text->selc, - txt_get_span(text->lines.first, text->curl), - text->curc); + txt_get_span(text->lines.first, text->sell), + text->selc, + txt_get_span(text->lines.first, text->curl), + text->curc); txt_pop_sel(text); } -static void txt_pop_last (Text *text) +static void txt_pop_last(Text *text) { - if (txt_get_span(text->curl, text->sell)>0 || - (text->curl==text->sell && text->curc<text->selc)) { + if (txt_get_span(text->curl, text->sell) > 0 || + (text->curl == text->sell && text->curc < text->selc)) { txt_curs_swap(text); } if (!undoing) txt_undo_add_toop(text, UNDO_STO, - txt_get_span(text->lines.first, text->sell), - text->selc, - txt_get_span(text->lines.first, text->curl), - text->curc); + txt_get_span(text->lines.first, text->sell), + text->selc, + txt_get_span(text->lines.first, text->curl), + text->curc); txt_pop_sel(text); } @@ -1172,8 +1172,8 @@ static void txt_pop_last (Text *text) void txt_pop_sel(Text *text) { - text->sell= text->curl; - text->selc= text->curc; + text->sell = text->curl; + text->selc = text->curc; } void txt_order_cursors(Text *text) @@ -1182,7 +1182,7 @@ void txt_order_cursors(Text *text) if (!text->curl) return; if (!text->sell) return; - /* Flip so text->curl is before text->sell */ + /* Flip so text->curl is before text->sell */ if ((txt_get_span(text->curl, text->sell) < 0) || (text->curl == text->sell && text->curc > text->selc)) { @@ -1192,10 +1192,10 @@ void txt_order_cursors(Text *text) int txt_has_sel(Text *text) { - return ((text->curl!=text->sell) || (text->curc!=text->selc)); + return ((text->curl != text->sell) || (text->curc != text->selc)); } -static void txt_delete_sel (Text *text) +static void txt_delete_sel(Text *text) { TextLine *tmpl; TextMarker *mrk; @@ -1211,62 +1211,62 @@ static void txt_delete_sel (Text *text) txt_order_cursors(text); if (!undoing) { - buf= txt_sel_to_buf(text); + buf = txt_sel_to_buf(text); txt_undo_add_block(text, UNDO_DBLOCK, buf); MEM_freeN(buf); } - buf= MEM_mallocN(text->curc+(text->sell->len - text->selc)+1, "textline_string"); + buf = MEM_mallocN(text->curc + (text->sell->len - text->selc) + 1, "textline_string"); if (text->curl != text->sell) { txt_clear_marker_region(text, text->curl, text->curc, text->curl->len, 0, 0); - move= txt_get_span(text->curl, text->sell); + move = txt_get_span(text->curl, text->sell); } else { - mrk= txt_find_marker_region(text, text->curl, text->curc, text->selc, 0, 0); + mrk = txt_find_marker_region(text, text->curl, text->curc, text->selc, 0, 0); if (mrk && (mrk->start > text->curc || mrk->end < text->selc)) txt_clear_marker_region(text, text->curl, text->curc, text->selc, 0, 0); - move= 0; + move = 0; } - mrk= txt_find_marker_region(text, text->sell, text->selc-1, text->sell->len, 0, 0); + mrk = txt_find_marker_region(text, text->sell, text->selc - 1, text->sell->len, 0, 0); if (mrk) { - lineno= mrk->lineno; + lineno = mrk->lineno; do { mrk->lineno -= move; if (mrk->start > text->curc) mrk->start -= text->selc - text->curc; mrk->end -= text->selc - text->curc; - mrk= mrk->next; - } while (mrk && mrk->lineno==lineno); + mrk = mrk->next; + } while (mrk && mrk->lineno == lineno); } strncpy(buf, text->curl->line, text->curc); - strcpy(buf+text->curc, text->sell->line + text->selc); - buf[text->curc+(text->sell->len - text->selc)]=0; + strcpy(buf + text->curc, text->sell->line + text->selc); + buf[text->curc + (text->sell->len - text->selc)] = 0; make_new_line(text->curl, buf); - tmpl= text->sell; + tmpl = text->sell; while (tmpl != text->curl) { - tmpl= tmpl->prev; + tmpl = tmpl->prev; if (!tmpl) break; txt_delete_line(text, tmpl->next); } - text->sell= text->curl; - text->selc= text->curc; + text->sell = text->curl; + text->selc = text->curc; } void txt_sel_all(Text *text) { if (!text) return; - text->curl= text->lines.first; - text->curc= 0; + text->curl = text->lines.first; + text->curc = 0; - text->sell= text->lines.last; - text->selc= text->sell->len; + text->sell = text->lines.last; + text->selc = text->sell->len; } void txt_sel_line(Text *text) @@ -1274,16 +1274,16 @@ void txt_sel_line(Text *text) if (!text) return; if (!text->curl) return; - text->curc= 0; - text->sell= text->curl; - text->selc= text->sell->len; + text->curc = 0; + text->sell = text->curl; + text->selc = text->sell->len; } /***************************/ /* Cut and paste functions */ /***************************/ -char *txt_to_buf (Text *text) +char *txt_to_buf(Text *text) { int length; TextLine *tmp, *linef, *linel; @@ -1295,53 +1295,53 @@ char *txt_to_buf (Text *text) if (!text->sell) return NULL; if (!text->lines.first) return NULL; - linef= text->lines.first; - charf= 0; + linef = text->lines.first; + charf = 0; - linel= text->lines.last; - charl= linel->len; + linel = text->lines.last; + charl = linel->len; if (linef == text->lines.last) { - length= charl-charf; + length = charl - charf; - buf= MEM_mallocN(length+2, "text buffer"); + buf = MEM_mallocN(length + 2, "text buffer"); - BLI_strncpy(buf, linef->line + charf, length+1); - buf[length]=0; + BLI_strncpy(buf, linef->line + charf, length + 1); + buf[length] = 0; } else { - length= linef->len - charf; - length+= charl; - length+= 2; /* For the 2 '\n' */ + length = linef->len - charf; + length += charl; + length += 2; /* For the 2 '\n' */ - tmp= linef->next; - while (tmp && tmp!= linel) { - length+= tmp->len+1; - tmp= tmp->next; + tmp = linef->next; + while (tmp && tmp != linel) { + length += tmp->len + 1; + tmp = tmp->next; } - buf= MEM_mallocN(length+1, "cut buffer"); + buf = MEM_mallocN(length + 1, "cut buffer"); - strncpy(buf, linef->line + charf, linef->len-charf); - length= linef->len - charf; + strncpy(buf, linef->line + charf, linef->len - charf); + length = linef->len - charf; - buf[length++]='\n'; + buf[length++] = '\n'; - tmp= linef->next; - while (tmp && tmp!=linel) { - strncpy(buf+length, tmp->line, tmp->len); - length+= tmp->len; + tmp = linef->next; + while (tmp && tmp != linel) { + strncpy(buf + length, tmp->line, tmp->len); + length += tmp->len; - buf[length++]='\n'; + buf[length++] = '\n'; - tmp= tmp->next; + tmp = tmp->next; } - strncpy(buf+length, linel->line, charl); - length+= charl; + strncpy(buf + length, linel->line, charl); + length += charl; /* python compiler wants an empty end line */ - buf[length++]='\n'; - buf[length]=0; + buf[length++] = '\n'; + buf[length] = 0; } return buf; @@ -1350,34 +1350,34 @@ char *txt_to_buf (Text *text) int txt_find_string(Text *text, const char *findstr, int wrap, int match_case) { TextLine *tl, *startl; - char *s= NULL; + char *s = NULL; if (!text || !text->curl || !text->sell) return 0; txt_order_cursors(text); - tl= startl= text->sell; + tl = startl = text->sell; - if (match_case) s= strstr(&tl->line[text->selc], findstr); - else s= BLI_strcasestr(&tl->line[text->selc], findstr); + if (match_case) s = strstr(&tl->line[text->selc], findstr); + else s = BLI_strcasestr(&tl->line[text->selc], findstr); while (!s) { - tl= tl->next; + tl = tl->next; if (!tl) { if (wrap) - tl= text->lines.first; + tl = text->lines.first; else break; } - if (match_case) s= strstr(tl->line, findstr); - else s= BLI_strcasestr(tl->line, findstr); - if (tl==startl) + if (match_case) s = strstr(tl->line, findstr); + else s = BLI_strcasestr(tl->line, findstr); + if (tl == startl) break; } if (s) { - int newl= txt_get_span(text->lines.first, tl); - int newc= (int)(s-tl->line); + int newl = txt_get_span(text->lines.first, tl); + int newc = (int)(s - tl->line); txt_move_to(text, newl, newc, 0); txt_move_to(text, newl, newc + strlen(findstr), 1); return 1; @@ -1386,10 +1386,10 @@ int txt_find_string(Text *text, const char *findstr, int wrap, int match_case) return 0; } -char *txt_sel_to_buf (Text *text) +char *txt_sel_to_buf(Text *text) { char *buf; - int length=0; + int length = 0; TextLine *tmp, *linef, *linel; int charf, charl; @@ -1397,71 +1397,71 @@ char *txt_sel_to_buf (Text *text) if (!text->curl) return NULL; if (!text->sell) return NULL; - if (text->curl==text->sell) { - linef= linel= text->curl; + if (text->curl == text->sell) { + linef = linel = text->curl; if (text->curc < text->selc) { - charf= text->curc; - charl= text->selc; + charf = text->curc; + charl = text->selc; } else { - charf= text->selc; - charl= text->curc; + charf = text->selc; + charl = text->curc; } } - else if (txt_get_span(text->curl, text->sell)<0) { - linef= text->sell; - linel= text->curl; + else if (txt_get_span(text->curl, text->sell) < 0) { + linef = text->sell; + linel = text->curl; - charf= text->selc; - charl= text->curc; + charf = text->selc; + charl = text->curc; } else { - linef= text->curl; - linel= text->sell; + linef = text->curl; + linel = text->sell; - charf= text->curc; - charl= text->selc; + charf = text->curc; + charl = text->selc; } if (linef == linel) { - length= charl-charf; + length = charl - charf; - buf= MEM_mallocN(length+1, "sel buffer"); + buf = MEM_mallocN(length + 1, "sel buffer"); - BLI_strncpy(buf, linef->line + charf, length+1); + BLI_strncpy(buf, linef->line + charf, length + 1); } else { - length+= linef->len - charf; - length+= charl; + length += linef->len - charf; + length += charl; length++; /* For the '\n' */ - tmp= linef->next; - while (tmp && tmp!= linel) { - length+= tmp->len+1; - tmp= tmp->next; + tmp = linef->next; + while (tmp && tmp != linel) { + length += tmp->len + 1; + tmp = tmp->next; } - buf= MEM_mallocN(length+1, "sel buffer"); + buf = MEM_mallocN(length + 1, "sel buffer"); - strncpy(buf, linef->line+ charf, linef->len-charf); - length= linef->len-charf; + strncpy(buf, linef->line + charf, linef->len - charf); + length = linef->len - charf; - buf[length++]='\n'; + buf[length++] = '\n'; - tmp= linef->next; - while (tmp && tmp!=linel) { - strncpy(buf+length, tmp->line, tmp->len); - length+= tmp->len; + tmp = linef->next; + while (tmp && tmp != linel) { + strncpy(buf + length, tmp->line, tmp->len); + length += tmp->len; - buf[length++]='\n'; + buf[length++] = '\n'; - tmp= tmp->next; + tmp = tmp->next; } - strncpy(buf+length, linel->line, charl); - length+= charl; + strncpy(buf + length, linel->line, charl); + length += charl; - buf[length]=0; + buf[length] = 0; } return buf; @@ -1471,16 +1471,16 @@ static void txt_shift_markers(Text *text, int lineno, int count) { TextMarker *marker; - for (marker=text->markers.first; marker; marker= marker->next) - if (marker->lineno>=lineno) { - marker->lineno+= count; + for (marker = text->markers.first; marker; marker = marker->next) + if (marker->lineno >= lineno) { + marker->lineno += count; } } void txt_insert_buf(Text *text, const char *in_buffer) { - int l=0, u, len, lineno= -1, count= 0; - size_t i=0, j; + int l = 0, u, len, lineno = -1, count = 0; + size_t i = 0, j; TextLine *add; char *buffer; @@ -1489,35 +1489,35 @@ void txt_insert_buf(Text *text, const char *in_buffer) txt_delete_sel(text); - len= strlen(in_buffer); - buffer= BLI_strdupn(in_buffer, len); - len+= txt_extended_ascii_as_utf8(&buffer); + len = strlen(in_buffer); + buffer = BLI_strdupn(in_buffer, len); + len += txt_extended_ascii_as_utf8(&buffer); if (!undoing) txt_undo_add_block(text, UNDO_IBLOCK, buffer); - u= undoing; - undoing= 1; + u = undoing; + undoing = 1; /* Read the first line (or as close as possible */ - while (buffer[i] && buffer[i]!='\n') + while (buffer[i] && buffer[i] != '\n') txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &i)); - if (buffer[i]=='\n') txt_split_curline(text); + if (buffer[i] == '\n') txt_split_curline(text); else { undoing = u; MEM_freeN(buffer); return; } i++; /* Read as many full lines as we can */ - lineno= txt_get_span(text->lines.first, text->curl); + lineno = txt_get_span(text->lines.first, text->curl); - while (i<len) { - l=0; + while (i < len) { + l = 0; - while (buffer[i] && buffer[i]!='\n') { + while (buffer[i] && buffer[i] != '\n') { i++; l++; } - if (buffer[i]=='\n') { - add= txt_new_linen(buffer +(i-l), l); + if (buffer[i] == '\n') { + add = txt_new_linen(buffer + (i - l), l); BLI_insertlinkbefore(&text->lines, text->curl, add); i++; count++; @@ -1525,10 +1525,10 @@ void txt_insert_buf(Text *text, const char *in_buffer) else { if (count) { txt_shift_markers(text, lineno, count); - count= 0; + count = 0; } - for (j= i-l; j<i && j<len; ) + for (j = i - l; j < i && j < len; ) txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &j)); break; } @@ -1540,7 +1540,7 @@ void txt_insert_buf(Text *text, const char *in_buffer) txt_shift_markers(text, lineno, count); } - undoing= u; + undoing = u; } /******************/ @@ -1549,18 +1549,18 @@ void txt_insert_buf(Text *text, const char *in_buffer) static int max_undo_test(Text *text, int x) { - while (text->undo_pos+x >= text->undo_len) { - if (text->undo_len*2 > TXT_MAX_UNDO) { + while (text->undo_pos + x >= text->undo_len) { + if (text->undo_len * 2 > TXT_MAX_UNDO) { /* XXX error("Undo limit reached, buffer cleared\n"); */ MEM_freeN(text->undo_buf); init_undo_text(text); return 0; } else { - void *tmp= text->undo_buf; - text->undo_buf= MEM_callocN(text->undo_len*2, "undo buf"); + void *tmp = text->undo_buf; + text->undo_buf = MEM_callocN(text->undo_len * 2, "undo buf"); memcpy(text->undo_buf, tmp, text->undo_len); - text->undo_len*=2; + text->undo_len *= 2; MEM_freeN(tmp); } } @@ -1570,218 +1570,218 @@ static int max_undo_test(Text *text, int x) static void dump_buffer(Text *text) { - int i= 0; + int i = 0; - while (i++<text->undo_pos) printf("%d: %d %c\n", i, text->undo_buf[i], text->undo_buf[i]); + while (i++ < text->undo_pos) printf("%d: %d %c\n", i, text->undo_buf[i], text->undo_buf[i]); } void txt_print_undo(Text *text) { - int i= 0; + int i = 0; int op; const char *ops; int linep, charp; dump_buffer(text); - printf ("---< Undo Buffer >---\n"); + printf("---< Undo Buffer >---\n"); - printf ("UndoPosition is %d\n", text->undo_pos); + printf("UndoPosition is %d\n", text->undo_pos); - while (i<=text->undo_pos) { - op= text->undo_buf[i]; + while (i <= text->undo_pos) { + op = text->undo_buf[i]; - if (op==UNDO_CLEFT) { - ops= "Cursor left"; + if (op == UNDO_CLEFT) { + ops = "Cursor left"; } - else if (op==UNDO_CRIGHT) { - ops= "Cursor right"; + else if (op == UNDO_CRIGHT) { + ops = "Cursor right"; } - else if (op==UNDO_CUP) { - ops= "Cursor up"; + else if (op == UNDO_CUP) { + ops = "Cursor up"; } - else if (op==UNDO_CDOWN) { - ops= "Cursor down"; + else if (op == UNDO_CDOWN) { + ops = "Cursor down"; } - else if (op==UNDO_SLEFT) { - ops= "Selection left"; + else if (op == UNDO_SLEFT) { + ops = "Selection left"; } - else if (op==UNDO_SRIGHT) { - ops= "Selection right"; + else if (op == UNDO_SRIGHT) { + ops = "Selection right"; } - else if (op==UNDO_SUP) { - ops= "Selection up"; + else if (op == UNDO_SUP) { + ops = "Selection up"; } - else if (op==UNDO_SDOWN) { - ops= "Selection down"; + else if (op == UNDO_SDOWN) { + ops = "Selection down"; } - else if (op==UNDO_STO) { - ops= "Selection "; + else if (op == UNDO_STO) { + ops = "Selection "; } - else if (op==UNDO_CTO) { - ops= "Cursor "; + else if (op == UNDO_CTO) { + ops = "Cursor "; } - else if (op==UNDO_INSERT_1) { - ops= "Insert ascii "; + else if (op == UNDO_INSERT_1) { + ops = "Insert ascii "; } - else if (op==UNDO_INSERT_2) { - ops= "Insert 2 bytes "; + else if (op == UNDO_INSERT_2) { + ops = "Insert 2 bytes "; } - else if (op==UNDO_INSERT_3) { - ops= "Insert 3 bytes "; + else if (op == UNDO_INSERT_3) { + ops = "Insert 3 bytes "; } - else if (op==UNDO_INSERT_4) { - ops= "Insert unicode "; + else if (op == UNDO_INSERT_4) { + ops = "Insert unicode "; } - else if (op==UNDO_BS_1) { - ops= "Backspace for ascii "; + else if (op == UNDO_BS_1) { + ops = "Backspace for ascii "; } - else if (op==UNDO_BS_2) { - ops= "Backspace for 2 bytes "; + else if (op == UNDO_BS_2) { + ops = "Backspace for 2 bytes "; } - else if (op==UNDO_BS_3) { - ops= "Backspace for 3 bytes "; + else if (op == UNDO_BS_3) { + ops = "Backspace for 3 bytes "; } - else if (op==UNDO_BS_4) { - ops= "Backspace for unicode "; + else if (op == UNDO_BS_4) { + ops = "Backspace for unicode "; } - else if (op==UNDO_DEL_1) { - ops= "Delete ascii "; + else if (op == UNDO_DEL_1) { + ops = "Delete ascii "; } - else if (op==UNDO_DEL_2) { - ops= "Delete 2 bytes "; + else if (op == UNDO_DEL_2) { + ops = "Delete 2 bytes "; } - else if (op==UNDO_DEL_3) { - ops= "Delete 3 bytes "; + else if (op == UNDO_DEL_3) { + ops = "Delete 3 bytes "; } - else if (op==UNDO_DEL_4) { - ops= "Delete unicode "; + else if (op == UNDO_DEL_4) { + ops = "Delete unicode "; } - else if (op==UNDO_SWAP) { - ops= "Cursor swap"; + else if (op == UNDO_SWAP) { + ops = "Cursor swap"; } - else if (op==UNDO_DBLOCK) { - ops= "Delete text block"; + else if (op == UNDO_DBLOCK) { + ops = "Delete text block"; } - else if (op==UNDO_IBLOCK) { - ops= "Insert text block"; + else if (op == UNDO_IBLOCK) { + ops = "Insert text block"; } - else if (op==UNDO_INDENT) { - ops= "Indent "; + else if (op == UNDO_INDENT) { + ops = "Indent "; } - else if (op==UNDO_UNINDENT) { - ops= "Unindent "; + else if (op == UNDO_UNINDENT) { + ops = "Unindent "; } - else if (op==UNDO_COMMENT) { - ops= "Comment "; + else if (op == UNDO_COMMENT) { + ops = "Comment "; } - else if (op==UNDO_UNCOMMENT) { - ops= "Uncomment "; + else if (op == UNDO_UNCOMMENT) { + ops = "Uncomment "; } else { - ops= "Unknown"; + ops = "Unknown"; } - printf ("Op (%o) at %d = %s", op, i, ops); + printf("Op (%o) at %d = %s", op, i, ops); if (op >= UNDO_INSERT_1 && op <= UNDO_DEL_4) { i++; - printf (" - Char is "); + printf(" - Char is "); switch (op) { case UNDO_INSERT_1: case UNDO_BS_1: case UNDO_DEL_1: - printf ("%c", text->undo_buf[i]); + printf("%c", text->undo_buf[i]); i++; break; case UNDO_INSERT_2: case UNDO_BS_2: case UNDO_DEL_2: - printf ("%c%c", text->undo_buf[i], text->undo_buf[i+1]); - i+=2; + printf("%c%c", text->undo_buf[i], text->undo_buf[i + 1]); + i += 2; break; case UNDO_INSERT_3: case UNDO_BS_3: case UNDO_DEL_3: - printf ("%c%c%c", text->undo_buf[i], text->undo_buf[i+1], text->undo_buf[i+2]); - i+=3; + printf("%c%c%c", text->undo_buf[i], text->undo_buf[i + 1], text->undo_buf[i + 2]); + i += 3; break; case UNDO_INSERT_4: case UNDO_BS_4: case UNDO_DEL_4: { unsigned int uc; - char c[BLI_UTF8_MAX+1]; + char c[BLI_UTF8_MAX + 1]; size_t c_len; - uc= text->undo_buf[i]; i++; - uc= uc+(text->undo_buf[i]<<8); i++; - uc= uc+(text->undo_buf[i]<<16); i++; - uc= uc+(text->undo_buf[i]<<24); i++; - c_len= BLI_str_utf8_from_unicode(uc, c); - c[c_len]= '\0'; + uc = text->undo_buf[i]; i++; + uc = uc + (text->undo_buf[i] << 8); i++; + uc = uc + (text->undo_buf[i] << 16); i++; + uc = uc + (text->undo_buf[i] << 24); i++; + c_len = BLI_str_utf8_from_unicode(uc, c); + c[c_len] = '\0'; puts(c); } } } - else if (op==UNDO_STO || op==UNDO_CTO) { + else if (op == UNDO_STO || op == UNDO_CTO) { i++; - charp= text->undo_buf[i]; i++; - charp= charp+(text->undo_buf[i]<<8); i++; + charp = text->undo_buf[i]; i++; + charp = charp + (text->undo_buf[i] << 8); i++; - linep= text->undo_buf[i]; i++; - linep= linep+(text->undo_buf[i]<<8); i++; - linep= linep+(text->undo_buf[i]<<16); i++; - linep= linep+(text->undo_buf[i]<<24); i++; + linep = text->undo_buf[i]; i++; + linep = linep + (text->undo_buf[i] << 8); i++; + linep = linep + (text->undo_buf[i] << 16); i++; + linep = linep + (text->undo_buf[i] << 24); i++; - printf ("to <%d, %d> ", linep, charp); + printf("to <%d, %d> ", linep, charp); - charp= text->undo_buf[i]; i++; - charp= charp+(text->undo_buf[i]<<8); i++; + charp = text->undo_buf[i]; i++; + charp = charp + (text->undo_buf[i] << 8); i++; - linep= text->undo_buf[i]; i++; - linep= linep+(text->undo_buf[i]<<8); i++; - linep= linep+(text->undo_buf[i]<<16); i++; - linep= linep+(text->undo_buf[i]<<24); i++; + linep = text->undo_buf[i]; i++; + linep = linep + (text->undo_buf[i] << 8); i++; + linep = linep + (text->undo_buf[i] << 16); i++; + linep = linep + (text->undo_buf[i] << 24); i++; - printf ("from <%d, %d>", linep, charp); + printf("from <%d, %d>", linep, charp); } - else if (op==UNDO_DBLOCK || op==UNDO_IBLOCK) { + else if (op == UNDO_DBLOCK || op == UNDO_IBLOCK) { i++; - linep= text->undo_buf[i]; i++; - linep= linep+(text->undo_buf[i]<<8); i++; - linep= linep+(text->undo_buf[i]<<16); i++; - linep= linep+(text->undo_buf[i]<<24); i++; + linep = text->undo_buf[i]; i++; + linep = linep + (text->undo_buf[i] << 8); i++; + linep = linep + (text->undo_buf[i] << 16); i++; + linep = linep + (text->undo_buf[i] << 24); i++; - printf (" (length %d) <", linep); + printf(" (length %d) <", linep); - while (linep>0) { + while (linep > 0) { putchar(text->undo_buf[i]); linep--; i++; } - linep= text->undo_buf[i]; i++; - linep= linep+(text->undo_buf[i]<<8); i++; - linep= linep+(text->undo_buf[i]<<16); i++; - linep= linep+(text->undo_buf[i]<<24); i++; - printf ("> (%d)", linep); + linep = text->undo_buf[i]; i++; + linep = linep + (text->undo_buf[i] << 8); i++; + linep = linep + (text->undo_buf[i] << 16); i++; + linep = linep + (text->undo_buf[i] << 24); i++; + printf("> (%d)", linep); } - else if (op==UNDO_INDENT || op==UNDO_UNINDENT) { + else if (op == UNDO_INDENT || op == UNDO_UNINDENT) { i++; - charp= text->undo_buf[i]; i++; - charp= charp+(text->undo_buf[i]<<8); i++; + charp = text->undo_buf[i]; i++; + charp = charp + (text->undo_buf[i] << 8); i++; - linep= text->undo_buf[i]; i++; - linep= linep+(text->undo_buf[i]<<8); i++; - linep= linep+(text->undo_buf[i]<<16); i++; - linep= linep+(text->undo_buf[i]<<24); i++; + linep = text->undo_buf[i]; i++; + linep = linep + (text->undo_buf[i] << 8); i++; + linep = linep + (text->undo_buf[i] << 16); i++; + linep = linep + (text->undo_buf[i] << 24); i++; - printf ("to <%d, %d> ", linep, charp); + printf("to <%d, %d> ", linep, charp); - charp= text->undo_buf[i]; i++; - charp= charp+(text->undo_buf[i]<<8); i++; + charp = text->undo_buf[i]; i++; + charp = charp + (text->undo_buf[i] << 8); i++; - linep= text->undo_buf[i]; i++; - linep= linep+(text->undo_buf[i]<<8); i++; - linep= linep+(text->undo_buf[i]<<16); i++; - linep= linep+(text->undo_buf[i]<<24); i++; + linep = text->undo_buf[i]; i++; + linep = linep + (text->undo_buf[i] << 8); i++; + linep = linep + (text->undo_buf[i] << 16); i++; + linep = linep + (text->undo_buf[i] << 24); i++; - printf ("from <%d, %d>", linep, charp); + printf("from <%d, %d>", linep, charp); } - printf (" %d\n", i); + printf(" %d\n", i); i++; } } @@ -1792,50 +1792,50 @@ static void txt_undo_add_op(Text *text, int op) return; text->undo_pos++; - text->undo_buf[text->undo_pos]= op; - text->undo_buf[text->undo_pos+1]= 0; + text->undo_buf[text->undo_pos] = op; + text->undo_buf[text->undo_pos + 1] = 0; } static void txt_undo_store_uint16(char *undo_buf, int *undo_pos, unsigned short value) { - undo_buf[*undo_pos]= (value)&0xff; + undo_buf[*undo_pos] = (value) & 0xff; (*undo_pos)++; - undo_buf[*undo_pos]= (value>>8)&0xff; + undo_buf[*undo_pos] = (value >> 8) & 0xff; (*undo_pos)++; } static void txt_undo_store_uint32(char *undo_buf, int *undo_pos, unsigned int value) { - undo_buf[*undo_pos]= (value)&0xff; + undo_buf[*undo_pos] = (value) & 0xff; (*undo_pos)++; - undo_buf[*undo_pos]= (value>>8)&0xff; + undo_buf[*undo_pos] = (value >> 8) & 0xff; (*undo_pos)++; - undo_buf[*undo_pos]= (value>>16)&0xff; + undo_buf[*undo_pos] = (value >> 16) & 0xff; (*undo_pos)++; - undo_buf[*undo_pos]= (value>>24)&0xff; + undo_buf[*undo_pos] = (value >> 24) & 0xff; (*undo_pos)++; } static void txt_undo_add_block(Text *text, int op, const char *buf) { - unsigned int length= strlen(buf); + unsigned int length = strlen(buf); - if (!max_undo_test(text, length+11)) + if (!max_undo_test(text, length + 11)) return; text->undo_pos++; - text->undo_buf[text->undo_pos]= op; + text->undo_buf[text->undo_pos] = op; text->undo_pos++; txt_undo_store_uint32(text->undo_buf, &text->undo_pos, length); - strncpy(text->undo_buf+text->undo_pos, buf, length); - text->undo_pos+=length; + strncpy(text->undo_buf + text->undo_pos, buf, length); + text->undo_pos += length; txt_undo_store_uint32(text->undo_buf, &text->undo_pos, length); - text->undo_buf[text->undo_pos]= op; + text->undo_buf[text->undo_pos] = op; - text->undo_buf[text->undo_pos+1]= 0; + text->undo_buf[text->undo_pos + 1] = 0; } void txt_undo_add_toop(Text *text, int op, unsigned int froml, unsigned short fromc, unsigned int tol, unsigned short toc) @@ -1843,10 +1843,10 @@ void txt_undo_add_toop(Text *text, int op, unsigned int froml, unsigned short fr if (!max_undo_test(text, 15)) return; - if (froml==tol && fromc==toc) return; + if (froml == tol && fromc == toc) return; text->undo_pos++; - text->undo_buf[text->undo_pos]= op; + text->undo_buf[text->undo_pos] = op; text->undo_pos++; @@ -1855,9 +1855,9 @@ void txt_undo_add_toop(Text *text, int op, unsigned int froml, unsigned short fr txt_undo_store_uint16(text->undo_buf, &text->undo_pos, toc); txt_undo_store_uint32(text->undo_buf, &text->undo_pos, tol); - text->undo_buf[text->undo_pos]= op; + text->undo_buf[text->undo_pos] = op; - text->undo_buf[text->undo_pos+1]= 0; + text->undo_buf[text->undo_pos + 1] = 0; } static void txt_undo_add_charop(Text *text, int op_start, unsigned int c) @@ -1871,48 +1871,48 @@ static void txt_undo_add_charop(Text *text, int op_start, unsigned int c) text->undo_pos++; if (utf8_size < 4) { - text->undo_buf[text->undo_pos]= op_start + utf8_size - 1; + text->undo_buf[text->undo_pos] = op_start + utf8_size - 1; text->undo_pos++; for (i = 0; i < utf8_size; i++) { - text->undo_buf[text->undo_pos]= utf8[i]; + text->undo_buf[text->undo_pos] = utf8[i]; text->undo_pos++; } - text->undo_buf[text->undo_pos]= op_start + utf8_size - 1; + text->undo_buf[text->undo_pos] = op_start + utf8_size - 1; } else { - text->undo_buf[text->undo_pos]= op_start + 3; + text->undo_buf[text->undo_pos] = op_start + 3; text->undo_pos++; txt_undo_store_uint32(text->undo_buf, &text->undo_pos, c); - text->undo_buf[text->undo_pos]= op_start + 3; + text->undo_buf[text->undo_pos] = op_start + 3; } - text->undo_buf[text->undo_pos+1]= 0; + text->undo_buf[text->undo_pos + 1] = 0; } static unsigned short txt_undo_read_uint16(const char *undo_buf, int *undo_pos) { unsigned short val; - val= undo_buf[*undo_pos]; (*undo_pos)--; - val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--; + val = undo_buf[*undo_pos]; (*undo_pos)--; + val = (val << 8) + undo_buf[*undo_pos]; (*undo_pos)--; return val; } static unsigned int txt_undo_read_uint32(const char *undo_buf, int *undo_pos) { unsigned int val; - val= undo_buf[*undo_pos]; (*undo_pos)--; - val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--; - val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--; - val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--; + val = undo_buf[*undo_pos]; (*undo_pos)--; + val = (val << 8) + undo_buf[*undo_pos]; (*undo_pos)--; + val = (val << 8) + undo_buf[*undo_pos]; (*undo_pos)--; + val = (val << 8) + undo_buf[*undo_pos]; (*undo_pos)--; return val; } static unsigned int txt_undo_read_unicode(const char *undo_buf, int *undo_pos, short bytes) { unsigned int unicode; - char utf8[BLI_UTF8_MAX+1]; + char utf8[BLI_UTF8_MAX + 1]; switch (bytes) { case 1: /* ascii */ @@ -1922,21 +1922,21 @@ static unsigned int txt_undo_read_unicode(const char *undo_buf, int *undo_pos, s utf8[2] = '\0'; utf8[1] = undo_buf[*undo_pos]; (*undo_pos)--; utf8[0] = undo_buf[*undo_pos]; (*undo_pos)--; - unicode= BLI_str_utf8_as_unicode(utf8); + unicode = BLI_str_utf8_as_unicode(utf8); break; case 3: /* 3-byte symbol */ utf8[3] = '\0'; utf8[2] = undo_buf[*undo_pos]; (*undo_pos)--; utf8[1] = undo_buf[*undo_pos]; (*undo_pos)--; utf8[0] = undo_buf[*undo_pos]; (*undo_pos)--; - unicode= BLI_str_utf8_as_unicode(utf8); + unicode = BLI_str_utf8_as_unicode(utf8); break; case 4: /* 32-bit unicode symbol */ - unicode= txt_undo_read_uint32(undo_buf, undo_pos); + unicode = txt_undo_read_uint32(undo_buf, undo_pos); default: /* should never happen */ BLI_assert(0); - unicode= 0; + unicode = 0; } return unicode; @@ -1946,24 +1946,24 @@ static unsigned short txt_redo_read_uint16(const char *undo_buf, int *undo_pos) { unsigned short val; val = undo_buf[*undo_pos]; (*undo_pos)++; - val = val+(undo_buf[*undo_pos]<<8); (*undo_pos)++; + val = val + (undo_buf[*undo_pos] << 8); (*undo_pos)++; return val; } static unsigned int txt_redo_read_uint32(const char *undo_buf, int *undo_pos) { unsigned int val; - val= undo_buf[*undo_pos]; (*undo_pos)++; - val= val+(undo_buf[*undo_pos]<<8); (*undo_pos)++; - val= val+(undo_buf[*undo_pos]<<16); (*undo_pos)++; - val= val+(undo_buf[*undo_pos]<<24); (*undo_pos)++; + val = undo_buf[*undo_pos]; (*undo_pos)++; + val = val + (undo_buf[*undo_pos] << 8); (*undo_pos)++; + val = val + (undo_buf[*undo_pos] << 16); (*undo_pos)++; + val = val + (undo_buf[*undo_pos] << 24); (*undo_pos)++; return val; } static unsigned int txt_redo_read_unicode(const char *undo_buf, int *undo_pos, short bytes) { unsigned int unicode; - char utf8[BLI_UTF8_MAX+1]; + char utf8[BLI_UTF8_MAX + 1]; switch (bytes) { case 1: /* ascii */ @@ -1973,21 +1973,21 @@ static unsigned int txt_redo_read_unicode(const char *undo_buf, int *undo_pos, s utf8[0] = undo_buf[*undo_pos]; (*undo_pos)++; utf8[1] = undo_buf[*undo_pos]; (*undo_pos)++; utf8[2] = '\0'; - unicode= BLI_str_utf8_as_unicode(utf8); + unicode = BLI_str_utf8_as_unicode(utf8); break; case 3: /* 3-byte symbol */ utf8[0] = undo_buf[*undo_pos]; (*undo_pos)++; utf8[1] = undo_buf[*undo_pos]; (*undo_pos)++; utf8[2] = undo_buf[*undo_pos]; (*undo_pos)++; utf8[3] = '\0'; - unicode= BLI_str_utf8_as_unicode(utf8); + unicode = BLI_str_utf8_as_unicode(utf8); break; case 4: /* 32-bit unicode symbol */ - unicode= txt_undo_read_uint32(undo_buf, undo_pos); + unicode = txt_undo_read_uint32(undo_buf, undo_pos); default: /* should never happen */ BLI_assert(0); - unicode= 0; + unicode = 0; } return unicode; @@ -1995,20 +1995,20 @@ static unsigned int txt_redo_read_unicode(const char *undo_buf, int *undo_pos, s void txt_do_undo(Text *text) { - int op= text->undo_buf[text->undo_pos]; + int op = text->undo_buf[text->undo_pos]; unsigned int linep, i; unsigned short charp; TextLine *holdl; int holdc, holdln; char *buf; - if (text->undo_pos<0) { + if (text->undo_pos < 0) { return; } text->undo_pos--; - undoing= 1; + undoing = 1; switch (op) { case UNDO_CLEFT: @@ -2053,17 +2053,17 @@ void txt_do_undo(Text *text) text->undo_pos--; text->undo_pos--; - linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos); - charp= txt_undo_read_uint16(text->undo_buf, &text->undo_pos); + linep = txt_undo_read_uint32(text->undo_buf, &text->undo_pos); + charp = txt_undo_read_uint16(text->undo_buf, &text->undo_pos); - if (op==UNDO_CTO) { + if (op == UNDO_CTO) { txt_move_toline(text, linep, 0); - text->curc= charp; + text->curc = charp; txt_pop_sel(text); } else { txt_move_toline(text, linep, 1); - text->selc= charp; + text->selc = charp; } text->undo_pos--; @@ -2071,7 +2071,7 @@ void txt_do_undo(Text *text) case UNDO_INSERT_1: case UNDO_INSERT_2: case UNDO_INSERT_3: case UNDO_INSERT_4: txt_backspace_char(text); - text->undo_pos-= op - UNDO_INSERT_1 + 1; + text->undo_pos -= op - UNDO_INSERT_1 + 1; text->undo_pos--; break; @@ -2093,29 +2093,29 @@ void txt_do_undo(Text *text) break; case UNDO_DBLOCK: - linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_undo_read_uint32(text->undo_buf, &text->undo_pos); - buf= MEM_mallocN(linep+1, "dblock buffer"); - for (i=0; i < linep; i++) { - buf[(linep-1)-i]= text->undo_buf[text->undo_pos]; + buf = MEM_mallocN(linep + 1, "dblock buffer"); + for (i = 0; i < linep; i++) { + buf[(linep - 1) - i] = text->undo_buf[text->undo_pos]; text->undo_pos--; } - buf[i]= 0; + buf[i] = 0; txt_curs_first(text, &holdl, &holdc); - holdln= txt_get_span(text->lines.first, holdl); + holdln = txt_get_span(text->lines.first, holdl); txt_insert_buf(text, buf); MEM_freeN(buf); - text->curl= text->lines.first; - while (holdln>0) { + text->curl = text->lines.first; + while (holdln > 0) { if (text->curl->next) - text->curl= text->curl->next; + text->curl = text->curl->next; holdln--; } - text->curc= holdc; + text->curc = holdc; text->undo_pos--; text->undo_pos--; @@ -2127,20 +2127,20 @@ void txt_do_undo(Text *text) break; case UNDO_IBLOCK: - linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_undo_read_uint32(text->undo_buf, &text->undo_pos); txt_delete_sel(text); /* txt_backspace_char removes utf8-characters, not bytes */ - buf= MEM_mallocN(linep+1, "iblock buffer"); - for (i=0; i < linep; i++) { - buf[(linep-1)-i]= text->undo_buf[text->undo_pos]; + buf = MEM_mallocN(linep + 1, "iblock buffer"); + for (i = 0; i < linep; i++) { + buf[(linep - 1) - i] = text->undo_buf[text->undo_pos]; text->undo_pos--; } - buf[i]= 0; - linep= txt_utf8_len(buf); + buf[i] = 0; + linep = txt_utf8_len(buf); MEM_freeN(buf); - while (linep>0) { + while (linep > 0) { txt_backspace_char(text); linep--; } @@ -2157,7 +2157,7 @@ void txt_do_undo(Text *text) case UNDO_UNINDENT: case UNDO_COMMENT: case UNDO_UNCOMMENT: - linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_undo_read_uint32(text->undo_buf, &text->undo_pos); //linep is now the end line of the selection charp = txt_undo_read_uint16(text->undo_buf, &text->undo_pos); @@ -2166,11 +2166,11 @@ void txt_do_undo(Text *text) //set the selection for this now text->selc = charp; text->sell = text->lines.first; - for (i= 0; i < linep; i++) { + for (i = 0; i < linep; i++) { text->sell = text->sell->next; } - linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_undo_read_uint32(text->undo_buf, &text->undo_pos); //first line to be selected charp = txt_undo_read_uint16(text->undo_buf, &text->undo_pos); @@ -2182,10 +2182,10 @@ void txt_do_undo(Text *text) } - if (op==UNDO_INDENT) { + if (op == UNDO_INDENT) { txt_unindent(text); } - else if (op== UNDO_UNINDENT) { + else if (op == UNDO_UNINDENT) { txt_indent(text); } else if (op == UNDO_COMMENT) { @@ -2208,13 +2208,13 @@ void txt_do_undo(Text *text) break; default: //XXX error("Undo buffer error - resetting"); - text->undo_pos= -1; + text->undo_pos = -1; break; } /* next undo step may need evaluating */ - if (text->undo_pos>=0) { + if (text->undo_pos >= 0) { switch (text->undo_buf[text->undo_pos]) { case UNDO_STO: txt_do_undo(text); @@ -2226,7 +2226,7 @@ void txt_do_undo(Text *text) } } - undoing= 0; + undoing = 0; } void txt_do_redo(Text *text) @@ -2237,14 +2237,14 @@ void txt_do_redo(Text *text) char *buf; text->undo_pos++; - op= text->undo_buf[text->undo_pos]; + op = text->undo_buf[text->undo_pos]; if (!op) { text->undo_pos--; return; } - undoing= 1; + undoing = 1; switch (op) { case UNDO_CLEFT: @@ -2288,13 +2288,13 @@ void txt_do_redo(Text *text) case UNDO_BS_1: case UNDO_BS_2: case UNDO_BS_3: case UNDO_BS_4: text->undo_pos++; txt_backspace_char(text); - text->undo_pos+= op - UNDO_BS_1 + 1; + text->undo_pos += op - UNDO_BS_1 + 1; break; case UNDO_DEL_1: case UNDO_DEL_2: case UNDO_DEL_3: case UNDO_DEL_4: text->undo_pos++; txt_delete_char(text); - text->undo_pos+= op - UNDO_DEL_1 + 1; + text->undo_pos += op - UNDO_DEL_1 + 1; break; case UNDO_SWAP: @@ -2314,27 +2314,27 @@ void txt_do_redo(Text *text) text->undo_pos++; - charp= txt_redo_read_uint16(text->undo_buf, &text->undo_pos); - linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos); + charp = txt_redo_read_uint16(text->undo_buf, &text->undo_pos); + linep = txt_redo_read_uint32(text->undo_buf, &text->undo_pos); - if (op==UNDO_CTO) { + if (op == UNDO_CTO) { txt_move_toline(text, linep, 0); - text->curc= charp; + text->curc = charp; txt_pop_sel(text); } else { txt_move_toline(text, linep, 1); - text->selc= charp; + text->selc = charp; } break; case UNDO_DBLOCK: text->undo_pos++; - linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_redo_read_uint32(text->undo_buf, &text->undo_pos); txt_delete_sel(text); - text->undo_pos+=linep; + text->undo_pos += linep; text->undo_pos++; text->undo_pos++; @@ -2345,12 +2345,12 @@ void txt_do_redo(Text *text) case UNDO_IBLOCK: text->undo_pos++; - linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_redo_read_uint32(text->undo_buf, &text->undo_pos); - buf= MEM_mallocN(linep+1, "iblock buffer"); - memcpy (buf, &text->undo_buf[text->undo_pos], linep); - text->undo_pos+= linep; - buf[linep]= 0; + buf = MEM_mallocN(linep + 1, "iblock buffer"); + memcpy(buf, &text->undo_buf[text->undo_pos], linep); + text->undo_pos += linep; + buf[linep] = 0; txt_insert_buf(text, buf); MEM_freeN(buf); @@ -2369,19 +2369,19 @@ void txt_do_redo(Text *text) charp = txt_redo_read_uint16(text->undo_buf, &text->undo_pos); //charp is the first char selected or 0 - linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_redo_read_uint32(text->undo_buf, &text->undo_pos); //linep is now the first line of the selection //set the selcetion for this now text->curc = charp; text->curl = text->lines.first; - for (i= 0; i < linep; i++) { + for (i = 0; i < linep; i++) { text->curl = text->curl->next; } charp = txt_redo_read_uint16(text->undo_buf, &text->undo_pos); //last postion to be selected - linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos); + linep = txt_redo_read_uint32(text->undo_buf, &text->undo_pos); //Last line to be selected text->selc = charp; @@ -2390,10 +2390,10 @@ void txt_do_redo(Text *text) text->sell = text->sell->next; } - if (op==UNDO_INDENT) { + if (op == UNDO_INDENT) { txt_indent(text); } - else if (op== UNDO_UNINDENT) { + else if (op == UNDO_UNINDENT) { txt_unindent(text); } else if (op == UNDO_COMMENT) { @@ -2414,12 +2414,12 @@ void txt_do_redo(Text *text) break; default: //XXX error("Undo buffer error - resetting"); - text->undo_pos= -1; + text->undo_pos = -1; break; } - undoing= 0; + undoing = 0; } /**************************/ @@ -2431,7 +2431,7 @@ void txt_split_curline(Text *text) TextLine *ins; TextMarker *mrk; char *left, *right; - int lineno= -1; + int lineno = -1; if (!text) return; if (!text->curl) return; @@ -2440,10 +2440,10 @@ void txt_split_curline(Text *text) /* Move markers */ - lineno= txt_get_span(text->lines.first, text->curl); - mrk= text->markers.first; + lineno = txt_get_span(text->lines.first, text->curl); + mrk = text->markers.first; while (mrk) { - if (mrk->lineno==lineno && mrk->start>text->curc) { + if (mrk->lineno == lineno && mrk->start > text->curc) { mrk->lineno++; mrk->start -= text->curc; mrk->end -= text->curc; @@ -2451,35 +2451,35 @@ void txt_split_curline(Text *text) else if (mrk->lineno > lineno) { mrk->lineno++; } - mrk= mrk->next; + mrk = mrk->next; } /* Make the two half strings */ - left= MEM_mallocN(text->curc+1, "textline_string"); + left = MEM_mallocN(text->curc + 1, "textline_string"); if (text->curc) memcpy(left, text->curl->line, text->curc); - left[text->curc]=0; + left[text->curc] = 0; - right= MEM_mallocN(text->curl->len - text->curc+1, "textline_string"); - memcpy(right, text->curl->line+text->curc, text->curl->len-text->curc+1); + right = MEM_mallocN(text->curl->len - text->curc + 1, "textline_string"); + memcpy(right, text->curl->line + text->curc, text->curl->len - text->curc + 1); MEM_freeN(text->curl->line); if (text->curl->format) MEM_freeN(text->curl->format); /* Make the new TextLine */ - ins= MEM_mallocN(sizeof(TextLine), "textline"); - ins->line= left; - ins->format= NULL; - ins->len= text->curc; - - text->curl->line= right; - text->curl->format= NULL; - text->curl->len= text->curl->len - text->curc; + ins = MEM_mallocN(sizeof(TextLine), "textline"); + ins->line = left; + ins->format = NULL; + ins->len = text->curc; + + text->curl->line = right; + text->curl->format = NULL; + text->curl->len = text->curl->len - text->curc; BLI_insertlinkbefore(&text->lines, text->curl, ins); - text->curc=0; + text->curc = 0; txt_make_dirty(text); txt_clean_text(text); @@ -2488,26 +2488,26 @@ void txt_split_curline(Text *text) if (!undoing) txt_undo_add_charop(text, UNDO_INSERT_1, '\n'); } -static void txt_delete_line (Text *text, TextLine *line) +static void txt_delete_line(Text *text, TextLine *line) { - TextMarker *mrk=NULL, *nxt; - int lineno= -1; + TextMarker *mrk = NULL, *nxt; + int lineno = -1; if (!text) return; if (!text->curl) return; - lineno= txt_get_span(text->lines.first, line); - mrk= text->markers.first; + lineno = txt_get_span(text->lines.first, line); + mrk = text->markers.first; while (mrk) { - nxt= mrk->next; - if (mrk->lineno==lineno) + nxt = mrk->next; + if (mrk->lineno == lineno) BLI_freelinkN(&text->markers, mrk); else if (mrk->lineno > lineno) mrk->lineno--; - mrk= nxt; + mrk = nxt; } - BLI_remlink (&text->lines, line); + BLI_remlink(&text->lines, line); if (line->line) MEM_freeN(line->line); if (line->format) MEM_freeN(line->format); @@ -2518,29 +2518,29 @@ static void txt_delete_line (Text *text, TextLine *line) txt_clean_text(text); } -static void txt_combine_lines (Text *text, TextLine *linea, TextLine *lineb) +static void txt_combine_lines(Text *text, TextLine *linea, TextLine *lineb) { char *tmp; - TextMarker *mrk= NULL; - int lineno=-1; + TextMarker *mrk = NULL; + int lineno = -1; if (!text) return; if (!linea || !lineb) return; - mrk= txt_find_marker_region(text, lineb, 0, lineb->len, 0, 0); + mrk = txt_find_marker_region(text, lineb, 0, lineb->len, 0, 0); if (mrk) { - lineno= mrk->lineno; + lineno = mrk->lineno; do { mrk->lineno--; mrk->start += linea->len; mrk->end += linea->len; - mrk= mrk->next; - } while (mrk && mrk->lineno==lineno); + mrk = mrk->next; + } while (mrk && mrk->lineno == lineno); } - if (lineno==-1) lineno= txt_get_span(text->lines.first, lineb); + if (lineno == -1) lineno = txt_get_span(text->lines.first, lineb); - tmp= MEM_mallocN(linea->len+lineb->len+1, "textline_string"); + tmp = MEM_mallocN(linea->len + lineb->len + 1, "textline_string"); strcpy(tmp, linea->line); strcat(tmp, lineb->line); @@ -2572,7 +2572,7 @@ void txt_duplicate_line(Text *text) void txt_delete_char(Text *text) { - unsigned int c='\n'; + unsigned int c = '\n'; if (!text) return; if (!text->curl) return; @@ -2582,7 +2582,7 @@ void txt_delete_char(Text *text) txt_make_dirty(text); return; } - else if (text->curc== text->curl->len) { /* Appending two lines */ + else if (text->curc == text->curl->len) { /* Appending two lines */ if (text->curl->next) { txt_combine_lines(text, text->curl, text->curl->next); txt_pop_sel(text); @@ -2593,12 +2593,12 @@ void txt_delete_char(Text *text) else { /* Just deleting a char */ size_t c_len = 0; TextMarker *mrk; - c= BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &c_len); + c = BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &c_len); - mrk= txt_find_marker_region(text, text->curl, text->curc - c_len, text->curl->len, 0, 0); + mrk = txt_find_marker_region(text, text->curl, text->curc - c_len, text->curl->len, 0, 0); if (mrk) { - int lineno= mrk->lineno; - if (mrk->end==text->curc) { + int lineno = mrk->lineno; + if (mrk->end == text->curc) { if ((mrk->flags & TMARK_TEMP) && !(mrk->flags & TMARK_EDITALL)) { txt_clear_markers(text, mrk->group, TMARK_TEMP); } @@ -2608,15 +2608,15 @@ void txt_delete_char(Text *text) return; } do { - if (mrk->start>text->curc) mrk->start-= c_len; - mrk->end-= c_len; - mrk= mrk->next; - } while (mrk && mrk->lineno==lineno); + if (mrk->start > text->curc) mrk->start -= c_len; + mrk->end -= c_len; + mrk = mrk->next; + } while (mrk && mrk->lineno == lineno); } - memmove(text->curl->line+text->curc, text->curl->line+text->curc+c_len, text->curl->len-text->curc-c_len+1); + memmove(text->curl->line + text->curc, text->curl->line + text->curc + c_len, text->curl->len - text->curc - c_len + 1); - text->curl->len-= c_len; + text->curl->len -= c_len; txt_pop_sel(text); } @@ -2635,7 +2635,7 @@ void txt_delete_word(Text *text) void txt_backspace_char(Text *text) { - unsigned int c='\n'; + unsigned int c = '\n'; if (!text) return; if (!text->curl) return; @@ -2645,11 +2645,11 @@ void txt_backspace_char(Text *text) txt_make_dirty(text); return; } - else if (text->curc==0) { /* Appending two lines */ + else if (text->curc == 0) { /* Appending two lines */ if (!text->curl->prev) return; - text->curl= text->curl->prev; - text->curc= text->curl->len; + text->curl = text->curl->prev; + text->curc = text->curl->len; txt_combine_lines(text, text->curl, text->curl->next); txt_pop_sel(text); @@ -2658,12 +2658,12 @@ void txt_backspace_char(Text *text) size_t c_len = 0; TextMarker *mrk; char *prev = BLI_str_prev_char_utf8(text->curl->line + text->curc); - c= BLI_str_utf8_as_unicode_and_size(prev, &c_len); + c = BLI_str_utf8_as_unicode_and_size(prev, &c_len); - mrk= txt_find_marker_region(text, text->curl, text->curc - c_len, text->curl->len, 0, 0); + mrk = txt_find_marker_region(text, text->curl, text->curc - c_len, text->curl->len, 0, 0); if (mrk) { - int lineno= mrk->lineno; - if (mrk->start==text->curc) { + int lineno = mrk->lineno; + if (mrk->start == text->curc) { if ((mrk->flags & TMARK_TEMP) && !(mrk->flags & TMARK_EDITALL)) { txt_clear_markers(text, mrk->group, TMARK_TEMP); } @@ -2673,10 +2673,10 @@ void txt_backspace_char(Text *text) return; } do { - if (mrk->start>text->curc - c_len) mrk->start-= c_len; - mrk->end-= c_len; - mrk= mrk->next; - } while (mrk && mrk->lineno==lineno); + if (mrk->start > text->curc - c_len) mrk->start -= c_len; + mrk->end -= c_len; + mrk = mrk->next; + } while (mrk && mrk->lineno == lineno); } /* source and destination overlap, don't use memcpy() */ @@ -2684,8 +2684,8 @@ void txt_backspace_char(Text *text) text->curl->line + text->curc, text->curl->len - text->curc + 1); - text->curl->len-= c_len; - text->curc-= c_len; + text->curl->len -= c_len; + text->curc -= c_len; txt_pop_sel(text); } @@ -2707,7 +2707,7 @@ void txt_backspace_word(Text *text) * Remember to change this string according to max tab size */ static char tab_to_spaces[] = " "; -static void txt_convert_tab_to_spaces (Text *text) +static void txt_convert_tab_to_spaces(Text *text) { /* sb aims to pad adjust the tab-width needed so that the right number of spaces * is added so that the indention of the line is the right width (i.e. aligned @@ -2717,7 +2717,7 @@ static void txt_convert_tab_to_spaces (Text *text) txt_insert_buf(text, sb); } -static int txt_add_char_intern (Text *text, unsigned int add, int replace_tabs) +static int txt_add_char_intern(Text *text, unsigned int add, int replace_tabs) { int lineno; char *tmp, ch[BLI_UTF8_MAX]; @@ -2727,7 +2727,7 @@ static int txt_add_char_intern (Text *text, unsigned int add, int replace_tabs) if (!text) return 0; if (!text->curl) return 0; - if (add=='\n') { + if (add == '\n') { txt_split_curline(text); return 1; } @@ -2741,25 +2741,25 @@ static int txt_add_char_intern (Text *text, unsigned int add, int replace_tabs) txt_delete_sel(text); add_len = BLI_str_utf8_from_unicode(add, ch); - mrk= txt_find_marker_region(text, text->curl, text->curc-1, text->curl->len, 0, 0); + mrk = txt_find_marker_region(text, text->curl, text->curc - 1, text->curl->len, 0, 0); if (mrk) { - lineno= mrk->lineno; + lineno = mrk->lineno; do { - if (mrk->start>text->curc) mrk->start+= add_len; - mrk->end+= add_len; - mrk= mrk->next; - } while (mrk && mrk->lineno==lineno); + if (mrk->start > text->curc) mrk->start += add_len; + mrk->end += add_len; + mrk = mrk->next; + } while (mrk && mrk->lineno == lineno); } - tmp= MEM_mallocN(text->curl->len+add_len+1, "textline_string"); + tmp = MEM_mallocN(text->curl->len + add_len + 1, "textline_string"); memcpy(tmp, text->curl->line, text->curc); - memcpy(tmp+text->curc, ch, add_len); - memcpy(tmp+text->curc+add_len, text->curl->line+text->curc, text->curl->len-text->curc+1); + memcpy(tmp + text->curc, ch, add_len); + memcpy(tmp + text->curc + add_len, text->curl->line + text->curc, text->curl->len - text->curc + 1); make_new_line(text->curl, tmp); - text->curc+= add_len; + text->curc += add_len; txt_pop_sel(text); @@ -2796,30 +2796,30 @@ int txt_replace_char(Text *text, unsigned int add) if (!text->curl) return 0; /* If text is selected or we're at the end of the line just use txt_add_char */ - if (text->curc==text->curl->len || txt_has_sel(text) || add=='\n') { - int i= txt_add_char(text, add); - TextMarker *mrk= txt_find_marker(text, text->curl, text->curc, 0, 0); + if (text->curc == text->curl->len || txt_has_sel(text) || add == '\n') { + int i = txt_add_char(text, add); + TextMarker *mrk = txt_find_marker(text, text->curl, text->curc, 0, 0); if (mrk) BLI_freelinkN(&text->markers, mrk); return i; } - del= BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &del_size); - add_size= BLI_str_utf8_from_unicode(add, ch); + del = BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &del_size); + add_size = BLI_str_utf8_from_unicode(add, ch); if (add_size > del_size) { - char *tmp= MEM_mallocN(text->curl->len+add_size-del_size+1, "textline_string"); + char *tmp = MEM_mallocN(text->curl->len + add_size - del_size + 1, "textline_string"); memcpy(tmp, text->curl->line, text->curc); - memcpy(tmp+text->curc+add_size, text->curl->line+text->curc+del_size, text->curl->len-text->curc-del_size+1); + memcpy(tmp + text->curc + add_size, text->curl->line + text->curc + del_size, text->curl->len - text->curc - del_size + 1); MEM_freeN(text->curl->line); text->curl->line = tmp; } else if (add_size < del_size) { - char *tmp= text->curl->line; - memmove(tmp+text->curc+add_size, tmp+text->curc+del_size, text->curl->len-text->curc-del_size+1); + char *tmp = text->curl->line; + memmove(tmp + text->curc + add_size, tmp + text->curc + del_size, text->curl->len - text->curc - del_size + 1); } memcpy(text->curl->line + text->curc, ch, add_size); - text->curc+= add_size; + text->curc += add_size; txt_pop_sel(text); txt_make_dirty(text); @@ -2860,19 +2860,19 @@ void txt_indent(Text *text) num = 0; while (TRUE) { - tmp= MEM_mallocN(text->curl->len+indentlen+1, "textline_string"); + tmp = MEM_mallocN(text->curl->len + indentlen + 1, "textline_string"); text->curc = 0; - if (text->curc) memcpy(tmp, text->curl->line, text->curc); /* XXX never true, check prev line */ - memcpy(tmp+text->curc, add, indentlen); + if (text->curc) memcpy(tmp, text->curl->line, text->curc); /* XXX never true, check prev line */ + memcpy(tmp + text->curc, add, indentlen); - len= text->curl->len - text->curc; - if (len>0) memcpy(tmp+text->curc+indentlen, text->curl->line+text->curc, len); - tmp[text->curl->len+indentlen]= 0; + len = text->curl->len - text->curc; + if (len > 0) memcpy(tmp + text->curc + indentlen, text->curl->line + text->curc, len); + tmp[text->curl->len + indentlen] = 0; make_new_line(text->curl, tmp); - text->curc+= indentlen; + text->curc += indentlen; txt_make_dirty(text); txt_clean_text(text); @@ -2887,7 +2887,7 @@ void txt_indent(Text *text) } } text->curc = 0; - while ( num > 0 ) { + while (num > 0) { text->curl = text->curl->prev; num--; } @@ -2920,11 +2920,11 @@ void txt_unindent(Text *text) int i = 0; if (BLI_strncasecmp(text->curl->line, remove, indent) == 0) { - while (i< text->curl->len) { - text->curl->line[i]= text->curl->line[i+indent]; + while (i < text->curl->len) { + text->curl->line[i] = text->curl->line[i + indent]; i++; } - text->curl->len-= indent; + text->curl->len -= indent; } txt_make_dirty(text); @@ -2941,7 +2941,7 @@ void txt_unindent(Text *text) } text->curc = 0; - while ( num > 0 ) { + while (num > 0) { text->curl = text->curl->prev; num--; } @@ -2959,19 +2959,19 @@ void txt_comment(Text *text) if (!text) return; if (!text->curl) return; - if (!text->sell) return;// Need to change this need to check if only one line is selected to more then one + if (!text->sell) return; // Need to change this need to check if only one line is selected to more then one num = 0; while (TRUE) { - tmp= MEM_mallocN(text->curl->len+2, "textline_string"); + tmp = MEM_mallocN(text->curl->len + 2, "textline_string"); text->curc = 0; if (text->curc) memcpy(tmp, text->curl->line, text->curc); - tmp[text->curc]= add; + tmp[text->curc] = add; - len= text->curl->len - text->curc; - if (len>0) memcpy(tmp+text->curc+1, text->curl->line+text->curc, len); - tmp[text->curl->len+1]=0; + len = text->curl->len - text->curc; + if (len > 0) memcpy(tmp + text->curc + 1, text->curl->line + text->curc, len); + tmp[text->curl->len + 1] = 0; make_new_line(text->curl, tmp); @@ -2990,7 +2990,7 @@ void txt_comment(Text *text) } } text->curc = 0; - while ( num > 0 ) { + while (num > 0) { text->curl = text->curl->prev; num--; } @@ -3013,8 +3013,8 @@ void txt_uncomment(Text *text) int i = 0; if (text->curl->line[i] == remove) { - while (i< text->curl->len) { - text->curl->line[i]= text->curl->line[i+1]; + while (i < text->curl->len) { + text->curl->line[i] = text->curl->line[i + 1]; i++; } text->curl->len--; @@ -3035,7 +3035,7 @@ void txt_uncomment(Text *text) } text->curc = 0; - while ( num > 0 ) { + while (num > 0) { text->curl = text->curl->prev; num--; } @@ -3054,7 +3054,7 @@ void txt_move_lines_up(struct Text *text) txt_order_cursors(text); - prev_line= text->curl->prev; + prev_line = text->curl->prev; if (!prev_line) return; @@ -3106,8 +3106,8 @@ int setcurr_tab_spaces(Text *text, int space) int test = 0; const char *word = ":"; const char *comm = "#"; - const char indent= (text->flags & TXT_TABSTOSPACES) ? ' ' : '\t'; - static const char *back_words[]= {"return", "break", "continue", "pass", "yield", NULL}; + const char indent = (text->flags & TXT_TABSTOSPACES) ? ' ' : '\t'; + static const char *back_words[] = {"return", "break", "continue", "pass", "yield", NULL}; if (!text) return 0; if (!text->curl) return 0; @@ -3122,20 +3122,20 @@ int setcurr_tab_spaces(Text *text, int space) } if (strstr(text->curl->line, word)) { /* if we find a ':' on this line, then add a tab but not if it is: - * 1) in a comment - * 2) within an identifier + * 1) in a comment + * 2) within an identifier * 3) after the cursor (text->curc), i.e. when creating space before a function def [#25414] */ int a, is_indent = 0; - for (a=0; (a < text->curc) && (text->curl->line[a] != '\0'); a++) { - char ch= text->curl->line[a]; - if (ch=='#') { + for (a = 0; (a < text->curc) && (text->curl->line[a] != '\0'); a++) { + char ch = text->curl->line[a]; + if (ch == '#') { break; } - else if (ch==':') { + else if (ch == ':') { is_indent = 1; } - else if (ch!=' ' && ch!='\t') { + else if (ch != ' ' && ch != '\t') { is_indent = 0; } } @@ -3144,7 +3144,7 @@ int setcurr_tab_spaces(Text *text, int space) } } - for (test=0; back_words[test]; test++) { + for (test = 0; back_words[test]; test++) { /* if there are these key words then remove a tab because we are done with the block */ if (strstr(text->curl->line, back_words[test]) && i > 0) { if (strcspn(text->curl->line, back_words[test]) < strcspn(text->curl->line, comm)) { @@ -3164,21 +3164,21 @@ void txt_add_marker(Text *text, TextLine *line, int start, int end, const unsign { TextMarker *tmp, *marker; - marker= MEM_mallocN(sizeof(TextMarker), "text_marker"); + marker = MEM_mallocN(sizeof(TextMarker), "text_marker"); - marker->lineno= txt_get_span(text->lines.first, line); - marker->start= MIN2(start, end); - marker->end= MAX2(start, end); - marker->group= group; - marker->flags= flags; + marker->lineno = txt_get_span(text->lines.first, line); + marker->start = MIN2(start, end); + marker->end = MAX2(start, end); + marker->group = group; + marker->flags = flags; - marker->color[0]= color[0]; - marker->color[1]= color[1]; - marker->color[2]= color[2]; - marker->color[3]= color[3]; + marker->color[0] = color[0]; + marker->color[1] = color[1]; + marker->color[2] = color[2]; + marker->color[3] = color[3]; - for (tmp=text->markers.last; tmp; tmp=tmp->prev) - if (tmp->lineno < marker->lineno || (tmp->lineno==marker->lineno && tmp->start < marker->start)) + for (tmp = text->markers.last; tmp; tmp = tmp->prev) + if (tmp->lineno < marker->lineno || (tmp->lineno == marker->lineno && tmp->start < marker->start)) break; if (tmp) BLI_insertlinkafter(&text->markers, tmp, marker); @@ -3191,18 +3191,18 @@ void txt_add_marker(Text *text, TextLine *line, int start, int end, const unsign TextMarker *txt_find_marker_region(Text *text, TextLine *line, int start, int end, int group, int flags) { TextMarker *marker, *next; - int lineno= txt_get_span(text->lines.first, line); + int lineno = txt_get_span(text->lines.first, line); - for (marker=text->markers.first; marker; marker=next) { - next= marker->next; + for (marker = text->markers.first; marker; marker = next) { + next = marker->next; - if (group && marker->group != group) continue; + if (group && marker->group != group) continue; else if ((marker->flags & flags) != flags) continue; - else if (marker->lineno < lineno) continue; + else if (marker->lineno < lineno) continue; else if (marker->lineno > lineno) break; - if ((marker->start==marker->end && start<=marker->start && marker->start<=end) || - (marker->start<end && marker->end>start)) + if ((marker->start == marker->end && start <= marker->start && marker->start <= end) || + (marker->start < end && marker->end > start)) { return marker; } @@ -3216,21 +3216,21 @@ TextMarker *txt_find_marker_region(Text *text, TextLine *line, int start, int en short txt_clear_marker_region(Text *text, TextLine *line, int start, int end, int group, int flags) { TextMarker *marker, *next; - int lineno= txt_get_span(text->lines.first, line); - short cleared= 0; + int lineno = txt_get_span(text->lines.first, line); + short cleared = 0; - for (marker=text->markers.first; marker; marker=next) { - next= marker->next; + for (marker = text->markers.first; marker; marker = next) { + next = marker->next; if (group && marker->group != group) continue; else if ((marker->flags & flags) != flags) continue; else if (marker->lineno < lineno) continue; else if (marker->lineno > lineno) break; - if ((marker->start==marker->end && start<=marker->start && marker->start<=end) || - (marker->start<end && marker->end>start)) { + if ((marker->start == marker->end && start <= marker->start && marker->start <= end) || + (marker->start < end && marker->end > start)) { BLI_freelinkN(&text->markers, marker); - cleared= 1; + cleared = 1; } } return cleared; @@ -3242,15 +3242,15 @@ short txt_clear_marker_region(Text *text, TextLine *line, int start, int end, in short txt_clear_markers(Text *text, int group, int flags) { TextMarker *marker, *next; - short cleared= 0; + short cleared = 0; - for (marker=text->markers.first; marker; marker=next) { - next= marker->next; + for (marker = text->markers.first; marker; marker = next) { + next = marker->next; - if ((!group || marker->group==group) && - (marker->flags & flags) == flags) { + if ((!group || marker->group == group) && + (marker->flags & flags) == flags) { BLI_freelinkN(&text->markers, marker); - cleared= 1; + cleared = 1; } } return cleared; @@ -3261,9 +3261,9 @@ short txt_clear_markers(Text *text, int group, int flags) TextMarker *txt_find_marker(Text *text, TextLine *line, int curs, int group, int flags) { TextMarker *marker; - int lineno= txt_get_span(text->lines.first, line); + int lineno = txt_get_span(text->lines.first, line); - for (marker=text->markers.first; marker; marker=marker->next) { + for (marker = text->markers.first; marker; marker = marker->next) { if (group && marker->group != group) continue; else if ((marker->flags & flags) != flags) continue; else if (marker->lineno < lineno) continue; @@ -3279,10 +3279,10 @@ TextMarker *txt_find_marker(Text *text, TextLine *line, int curs, int group, int * marker will be returned */ TextMarker *txt_prev_marker(Text *text, TextMarker *marker) { - TextMarker *tmp= marker; + TextMarker *tmp = marker; while (tmp) { - if (tmp->prev) tmp= tmp->prev; - else tmp= text->markers.last; + if (tmp->prev) tmp = tmp->prev; + else tmp = text->markers.last; if (tmp->group == marker->group) return tmp; } @@ -3293,10 +3293,10 @@ TextMarker *txt_prev_marker(Text *text, TextMarker *marker) * marker will be returned */ TextMarker *txt_next_marker(Text *text, TextMarker *marker) { - TextMarker *tmp= marker; + TextMarker *tmp = marker; while (tmp) { - if (tmp->next) tmp= tmp->next; - else tmp= text->markers.first; + if (tmp->next) tmp = tmp->next; + else tmp = text->markers.first; if (tmp->group == marker->group) return tmp; } @@ -3314,11 +3314,11 @@ int text_check_bracket(const char ch) char opens[] = "([{"; char close[] = ")]}"; - for (a=0; a<(sizeof(opens)-1); a++) { - if (ch==opens[a]) - return a+1; - else if (ch==close[a]) - return -(a+1); + for (a = 0; a < (sizeof(opens) - 1); a++) { + if (ch == opens[a]) + return a + 1; + else if (ch == close[a]) + return -(a + 1); } return 0; } @@ -3329,8 +3329,8 @@ int text_check_delim(const char ch) int a; char delims[] = "():\"\' ~!%^&*-+=[]{};/<>|.#\t,@"; - for (a=0; a<(sizeof(delims)-1); a++) { - if (ch==delims[a]) + for (a = 0; a < (sizeof(delims) - 1); a++) { + if (ch == delims[a]) return 1; } return 0; diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 9b3689df941..98f5f45f525 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -80,7 +80,7 @@ int test_dlerr(const char *name, const char *symbol) { char *err; - err= BLI_dynlib_get_error_as_string(NULL); + err = BLI_dynlib_get_error_as_string(NULL); if (err) { printf("var1: %s, var2: %s, var3: %s\n", name, symbol, err); return 1; @@ -96,14 +96,14 @@ void open_plugin_tex(PluginTex *pit) int (*version)(void); /* init all the happy variables */ - pit->doit= NULL; - pit->pname= NULL; - pit->stnames= NULL; - pit->varstr= NULL; - pit->result= NULL; - pit->cfra= NULL; - pit->version= 0; - pit->instance_init= NULL; + pit->doit = NULL; + pit->pname = NULL; + pit->stnames = NULL; + pit->varstr = NULL; + pit->result = NULL; + pit->cfra = NULL; + pit->version = 0; + pit->instance_init = NULL; /* clear the error list */ BLI_dynlib_get_error_as_string(NULL); @@ -113,42 +113,42 @@ void open_plugin_tex(PluginTex *pit) /* pit->handle= 0; */ /* open the needed object */ - pit->handle= BLI_dynlib_open(pit->name); + pit->handle = BLI_dynlib_open(pit->name); if (test_dlerr(pit->name, pit->name)) return; if (pit->handle != NULL) { /* find the address of the version function */ - version= (int (*)(void)) BLI_dynlib_find_symbol(pit->handle, "plugin_tex_getversion"); + version = (int (*)(void))BLI_dynlib_find_symbol(pit->handle, "plugin_tex_getversion"); if (test_dlerr(pit->name, "plugin_tex_getversion")) return; if (version != NULL) { - pit->version= version(); - if ( pit->version >= 2 && pit->version <=6) { + pit->version = version(); + if (pit->version >= 2 && pit->version <= 6) { int (*info_func)(PluginInfo *); - PluginInfo *info= (PluginInfo*) MEM_mallocN(sizeof(PluginInfo), "plugin_info"); + PluginInfo *info = (PluginInfo *) MEM_mallocN(sizeof(PluginInfo), "plugin_info"); - info_func= (int (*)(PluginInfo *))BLI_dynlib_find_symbol(pit->handle, "plugin_getinfo"); + info_func = (int (*)(PluginInfo *))BLI_dynlib_find_symbol(pit->handle, "plugin_getinfo"); if (!test_dlerr(pit->name, "plugin_getinfo")) { info->instance_init = NULL; info_func(info); - pit->doit= (int(*)(void)) info->tex_doit; - pit->callback= (void(*)(unsigned short)) info->callback; - pit->stypes= info->stypes; - pit->vars= info->nvars; - pit->pname= info->name; - pit->stnames= info->snames; - pit->varstr= info->varstr; - pit->result= info->result; - pit->cfra= info->cfra; + pit->doit = (int (*)(void))info->tex_doit; + pit->callback = (void (*)(unsigned short))info->callback; + pit->stypes = info->stypes; + pit->vars = info->nvars; + pit->pname = info->name; + pit->stnames = info->snames; + pit->varstr = info->varstr; + pit->result = info->result; + pit->cfra = info->cfra; pit->instance_init = info->instance_init; if (info->init) info->init(); } MEM_freeN(info); } else { - printf ("Plugin returned unrecognized version number\n"); + printf("Plugin returned unrecognized version number\n"); return; } } @@ -158,8 +158,8 @@ void open_plugin_tex(PluginTex *pit) /* ------------------------------------------------------------------------- */ /* very badlevel define to bypass linking with BIF_interface.h */ -#define INT 96 -#define FLO 128 +#define INT 96 +#define FLO 128 PluginTex *add_plugin_tex(char *str) { @@ -167,24 +167,24 @@ PluginTex *add_plugin_tex(char *str) VarStruct *varstr; int a; - pit= MEM_callocN(sizeof(PluginTex), "plugintex"); + pit = MEM_callocN(sizeof(PluginTex), "plugintex"); BLI_strncpy(pit->name, str, sizeof(pit->name)); open_plugin_tex(pit); - if (pit->doit==NULL) { - if (pit->handle==NULL) {;} //XXX error("no plugin: %s", str); - else {;} //XXX error("in plugin: %s", str); + if (pit->doit == NULL) { + if (pit->handle == NULL) {; } //XXX error("no plugin: %s", str); + else {; } //XXX error("in plugin: %s", str); MEM_freeN(pit); return NULL; } - varstr= pit->varstr; - for (a=0; a<pit->vars; a++, varstr++) { - if ( (varstr->type & FLO)==FLO) - pit->data[a]= varstr->def; - else if ( (varstr->type & INT)==INT) - *((int *)(pit->data+a))= (int) varstr->def; + varstr = pit->varstr; + for (a = 0; a < pit->vars; a++, varstr++) { + if ( (varstr->type & FLO) == FLO) + pit->data[a] = varstr->def; + else if ( (varstr->type & INT) == INT) + *((int *)(pit->data + a)) = (int) varstr->def; } if (pit->instance_init) @@ -197,7 +197,7 @@ PluginTex *add_plugin_tex(char *str) void free_plugin_tex(PluginTex *pit) { - if (pit==NULL) return; + if (pit == NULL) return; /* no BLI_dynlib_close: same plugin can be opened multiple times, 1 handle */ MEM_freeN(pit); @@ -207,7 +207,7 @@ void free_plugin_tex(PluginTex *pit) TexMapping *add_tex_mapping(void) { - TexMapping *texmap= MEM_callocN(sizeof(TexMapping), "TexMapping"); + TexMapping *texmap = MEM_callocN(sizeof(TexMapping), "TexMapping"); default_tex_mapping(texmap); @@ -218,14 +218,14 @@ void default_tex_mapping(TexMapping *texmap) { memset(texmap, 0, sizeof(TexMapping)); - texmap->size[0]= texmap->size[1]= texmap->size[2]= 1.0f; - texmap->max[0]= texmap->max[1]= texmap->max[2]= 1.0f; + texmap->size[0] = texmap->size[1] = texmap->size[2] = 1.0f; + texmap->max[0] = texmap->max[1] = texmap->max[2] = 1.0f; unit_m4(texmap->mat); - texmap->projx= PROJ_X; - texmap->projy= PROJ_Y; - texmap->projz= PROJ_Z; - texmap->mapping= MTEX_FLAT; + texmap->projx = PROJ_X; + texmap->projy = PROJ_Y; + texmap->projz = PROJ_Z; + texmap->mapping = MTEX_FLAT; } void init_tex_mapping(TexMapping *texmap) @@ -233,7 +233,7 @@ void init_tex_mapping(TexMapping *texmap) float smat[3][3], rmat[3][3], mat[3][3], proj[3][3]; if (texmap->projx == PROJ_X && texmap->projy == PROJ_Y && texmap->projz == PROJ_Z && - is_zero_v3(texmap->loc) && is_zero_v3(texmap->rot) && is_one_v3(texmap->size)) { + is_zero_v3(texmap->loc) && is_zero_v3(texmap->rot) && is_one_v3(texmap->size)) { unit_m4(texmap->mat); texmap->flag |= TEXMAP_UNIT_MATRIX; @@ -243,11 +243,11 @@ void init_tex_mapping(TexMapping *texmap) zero_m3(proj); if (texmap->projx != PROJ_N) - proj[texmap->projx-1][0]= 1.0f; + proj[texmap->projx - 1][0] = 1.0f; if (texmap->projy != PROJ_N) - proj[texmap->projy-1][1]= 1.0f; + proj[texmap->projy - 1][1] = 1.0f; if (texmap->projz != PROJ_N) - proj[texmap->projz-1][2]= 1.0f; + proj[texmap->projz - 1][2] = 1.0f; /* scale */ size_to_mat3(smat, texmap->size); @@ -270,7 +270,7 @@ void init_tex_mapping(TexMapping *texmap) ColorMapping *add_color_mapping(void) { - ColorMapping *colormap= MEM_callocN(sizeof(ColorMapping), "ColorMapping"); + ColorMapping *colormap = MEM_callocN(sizeof(ColorMapping), "ColorMapping"); default_color_mapping(colormap); @@ -283,15 +283,15 @@ void default_color_mapping(ColorMapping *colormap) init_colorband(&colormap->coba, 1); - colormap->bright= 1.0; - colormap->contrast= 1.0; - colormap->saturation= 1.0; + colormap->bright = 1.0; + colormap->contrast = 1.0; + colormap->saturation = 1.0; - colormap->blend_color[0]= 0.8f; - colormap->blend_color[1]= 0.8f; - colormap->blend_color[2]= 0.8f; - colormap->blend_type= MA_RAMP_BLEND; - colormap->blend_factor= 0.0f; + colormap->blend_color[0] = 0.8f; + colormap->blend_color[1] = 0.8f; + colormap->blend_color[2] = 0.8f; + colormap->blend_type = MA_RAMP_BLEND; + colormap->blend_factor = 0.0f; } /* ****************** COLORBAND ******************* */ @@ -300,41 +300,41 @@ void init_colorband(ColorBand *coba, int rangetype) { int a; - coba->data[0].pos= 0.0; - coba->data[1].pos= 1.0; + coba->data[0].pos = 0.0; + coba->data[1].pos = 1.0; - if (rangetype==0) { - coba->data[0].r= 0.0; - coba->data[0].g= 0.0; - coba->data[0].b= 0.0; - coba->data[0].a= 0.0; - - coba->data[1].r= 1.0; - coba->data[1].g= 1.0; - coba->data[1].b= 1.0; - coba->data[1].a= 1.0; + if (rangetype == 0) { + coba->data[0].r = 0.0; + coba->data[0].g = 0.0; + coba->data[0].b = 0.0; + coba->data[0].a = 0.0; + + coba->data[1].r = 1.0; + coba->data[1].g = 1.0; + coba->data[1].b = 1.0; + coba->data[1].a = 1.0; } else { - coba->data[0].r= 0.0; - coba->data[0].g= 0.0; - coba->data[0].b= 0.0; - coba->data[0].a= 1.0; - - coba->data[1].r= 1.0; - coba->data[1].g= 1.0; - coba->data[1].b= 1.0; - coba->data[1].a= 1.0; + coba->data[0].r = 0.0; + coba->data[0].g = 0.0; + coba->data[0].b = 0.0; + coba->data[0].a = 1.0; + + coba->data[1].r = 1.0; + coba->data[1].g = 1.0; + coba->data[1].b = 1.0; + coba->data[1].a = 1.0; } - - for (a=2; a<MAXCOLORBAND; a++) { - coba->data[a].r= 0.5; - coba->data[a].g= 0.5; - coba->data[a].b= 0.5; - coba->data[a].a= 1.0; - coba->data[a].pos= 0.5; + + for (a = 2; a < MAXCOLORBAND; a++) { + coba->data[a].r = 0.5; + coba->data[a].g = 0.5; + coba->data[a].b = 0.5; + coba->data[a].a = 1.0; + coba->data[a].pos = 0.5; } - coba->tot= 2; + coba->tot = 2; } @@ -342,7 +342,7 @@ ColorBand *add_colorband(int rangetype) { ColorBand *coba; - coba= MEM_callocN(sizeof(ColorBand), "colorband"); + coba = MEM_callocN(sizeof(ColorBand), "colorband"); init_colorband(coba, rangetype); return coba; @@ -356,85 +356,85 @@ int do_colorband(const ColorBand *coba, float in, float out[4]) float fac, mfac, t[4]; int a; - if (coba==NULL || coba->tot==0) return 0; + if (coba == NULL || coba->tot == 0) return 0; - cbd1= coba->data; - if (coba->tot==1) { - out[0]= cbd1->r; - out[1]= cbd1->g; - out[2]= cbd1->b; - out[3]= cbd1->a; + cbd1 = coba->data; + if (coba->tot == 1) { + out[0] = cbd1->r; + out[1] = cbd1->g; + out[2] = cbd1->b; + out[3] = cbd1->a; } else { - if (in <= cbd1->pos && coba->ipotype<2) { - out[0]= cbd1->r; - out[1]= cbd1->g; - out[2]= cbd1->b; - out[3]= cbd1->a; + if (in <= cbd1->pos && coba->ipotype < 2) { + out[0] = cbd1->r; + out[1] = cbd1->g; + out[2] = cbd1->b; + out[3] = cbd1->a; } else { CBData left, right; /* we're looking for first pos > in */ - for (a=0; a<coba->tot; a++, cbd1++) if (cbd1->pos > in) break; + for (a = 0; a < coba->tot; a++, cbd1++) if (cbd1->pos > in) break; - if (a==coba->tot) { - cbd2= cbd1-1; - right= *cbd2; - right.pos= 1.0f; - cbd1= &right; + if (a == coba->tot) { + cbd2 = cbd1 - 1; + right = *cbd2; + right.pos = 1.0f; + cbd1 = &right; } - else if (a==0) { - left= *cbd1; - left.pos= 0.0f; - cbd2= &left; + else if (a == 0) { + left = *cbd1; + left.pos = 0.0f; + cbd2 = &left; } - else cbd2= cbd1-1; + else cbd2 = cbd1 - 1; - if (in >= cbd1->pos && coba->ipotype<2) { - out[0]= cbd1->r; - out[1]= cbd1->g; - out[2]= cbd1->b; - out[3]= cbd1->a; + if (in >= cbd1->pos && coba->ipotype < 2) { + out[0] = cbd1->r; + out[1] = cbd1->g; + out[2] = cbd1->b; + out[3] = cbd1->a; } else { - if (cbd2->pos!=cbd1->pos) - fac= (in-cbd1->pos)/(cbd2->pos-cbd1->pos); + if (cbd2->pos != cbd1->pos) + fac = (in - cbd1->pos) / (cbd2->pos - cbd1->pos); else { /* was setting to 0.0 in 2.56 & previous, but this * is incorrect for the last element, see [#26732] */ - fac= (a != coba->tot) ? 0.0f : 1.0f; + fac = (a != coba->tot) ? 0.0f : 1.0f; } - if (coba->ipotype==4) { + if (coba->ipotype == 4) { /* constant */ - out[0]= cbd2->r; - out[1]= cbd2->g; - out[2]= cbd2->b; - out[3]= cbd2->a; + out[0] = cbd2->r; + out[1] = cbd2->g; + out[2] = cbd2->b; + out[3] = cbd2->a; return 1; } - if (coba->ipotype>=2) { + if (coba->ipotype >= 2) { /* ipo from right to left: 3 2 1 0 */ - if (a>=coba->tot-1) cbd0= cbd1; - else cbd0= cbd1+1; - if (a<2) cbd3= cbd2; - else cbd3= cbd2-1; + if (a >= coba->tot - 1) cbd0 = cbd1; + else cbd0 = cbd1 + 1; + if (a < 2) cbd3 = cbd2; + else cbd3 = cbd2 - 1; CLAMP(fac, 0.0f, 1.0f); - if (coba->ipotype==3) + if (coba->ipotype == 3) key_curve_position_weights(fac, t, KEY_CARDINAL); else key_curve_position_weights(fac, t, KEY_BSPLINE); - out[0]= t[3]*cbd3->r +t[2]*cbd2->r +t[1]*cbd1->r +t[0]*cbd0->r; - out[1]= t[3]*cbd3->g +t[2]*cbd2->g +t[1]*cbd1->g +t[0]*cbd0->g; - out[2]= t[3]*cbd3->b +t[2]*cbd2->b +t[1]*cbd1->b +t[0]*cbd0->b; - out[3]= t[3]*cbd3->a +t[2]*cbd2->a +t[1]*cbd1->a +t[0]*cbd0->a; + out[0] = t[3] * cbd3->r + t[2] * cbd2->r + t[1] * cbd1->r + t[0] * cbd0->r; + out[1] = t[3] * cbd3->g + t[2] * cbd2->g + t[1] * cbd1->g + t[0] * cbd0->g; + out[2] = t[3] * cbd3->b + t[2] * cbd2->b + t[1] * cbd1->b + t[0] * cbd0->b; + out[3] = t[3] * cbd3->a + t[2] * cbd2->a + t[1] * cbd1->a + t[0] * cbd0->a; CLAMP(out[0], 0.0f, 1.0f); CLAMP(out[1], 0.0f, 1.0f); CLAMP(out[2], 0.0f, 1.0f); @@ -442,40 +442,40 @@ int do_colorband(const ColorBand *coba, float in, float out[4]) } else { - if (coba->ipotype==1) { /* EASE */ - mfac= fac*fac; - fac= 3.0f*mfac-2.0f*mfac*fac; + if (coba->ipotype == 1) { /* EASE */ + mfac = fac * fac; + fac = 3.0f * mfac - 2.0f * mfac * fac; } - mfac= 1.0f-fac; + mfac = 1.0f - fac; - out[0]= mfac*cbd1->r + fac*cbd2->r; - out[1]= mfac*cbd1->g + fac*cbd2->g; - out[2]= mfac*cbd1->b + fac*cbd2->b; - out[3]= mfac*cbd1->a + fac*cbd2->a; + out[0] = mfac * cbd1->r + fac * cbd2->r; + out[1] = mfac * cbd1->g + fac * cbd2->g; + out[2] = mfac * cbd1->b + fac * cbd2->b; + out[3] = mfac * cbd1->a + fac * cbd2->a; } } } } - return 1; /* OK */ + return 1; /* OK */ } void colorband_table_RGBA(ColorBand *coba, float **array, int *size) { int a; - *size = CM_TABLE+1; - *array = MEM_callocN(sizeof(float)*(*size)*4, "ColorBand"); + *size = CM_TABLE + 1; + *array = MEM_callocN(sizeof(float) * (*size) * 4, "ColorBand"); - for (a=0; a<*size; a++) - do_colorband(coba, (float)a/(float)CM_TABLE, &(*array)[a*4]); + for (a = 0; a < *size; a++) + do_colorband(coba, (float)a / (float)CM_TABLE, &(*array)[a * 4]); } int vergcband(const void *a1, const void *a2) { - const CBData *x1=a1, *x2=a2; + const CBData *x1 = a1, *x2 = a2; - if ( x1->pos > x2->pos ) return 1; - else if ( x1->pos < x2->pos) return -1; + if (x1->pos > x2->pos) return 1; + else if (x1->pos < x2->pos) return -1; return 0; } @@ -483,17 +483,17 @@ void colorband_update_sort(ColorBand *coba) { int a; - if (coba->tot<2) + if (coba->tot < 2) return; - for (a=0; a<coba->tot; a++) - coba->data[a].cur= a; + for (a = 0; a < coba->tot; a++) + coba->data[a].cur = a; qsort(coba->data, coba->tot, sizeof(CBData), vergcband); - for (a=0; a<coba->tot; a++) { - if (coba->data[a].cur==coba->cur) { - coba->cur= a; + for (a = 0; a < coba->tot; a++) { + if (coba->data[a].cur == coba->cur) { + coba->cur = a; break; } } @@ -501,7 +501,7 @@ void colorband_update_sort(ColorBand *coba) CBData *colorband_element_add(struct ColorBand *coba, float position) { - if (coba->tot==MAXCOLORBAND) { + if (coba->tot == MAXCOLORBAND) { return NULL; } else if (coba->tot > 0) { @@ -520,7 +520,7 @@ CBData *colorband_element_add(struct ColorBand *coba, float position) } coba->tot++; - coba->cur = coba->tot-1; + coba->cur = coba->tot - 1; colorband_update_sort(coba); @@ -559,7 +559,7 @@ void BKE_texture_free(Tex *tex) BKE_free_animdata((struct ID *)tex); BKE_previewimg_free(&tex->preview); - BKE_icon_delete((struct ID*)tex); + BKE_icon_delete((struct ID *)tex); tex->id.icon_id = 0; if (tex->nodetree) { @@ -576,31 +576,31 @@ void default_tex(Tex *tex) VarStruct *varstr; int a; - tex->type= TEX_CLOUDS; - tex->stype= 0; - tex->flag= TEX_CHECKER_ODD; - tex->imaflag= TEX_INTERPOL|TEX_MIPMAP|TEX_USEALPHA; - tex->extend= TEX_REPEAT; - tex->cropxmin= tex->cropymin= 0.0; - tex->cropxmax= tex->cropymax= 1.0; + tex->type = TEX_CLOUDS; + tex->stype = 0; + tex->flag = TEX_CHECKER_ODD; + tex->imaflag = TEX_INTERPOL | TEX_MIPMAP | TEX_USEALPHA; + tex->extend = TEX_REPEAT; + tex->cropxmin = tex->cropymin = 0.0; + tex->cropxmax = tex->cropymax = 1.0; tex->texfilter = TXF_EWA; tex->afmax = 8; - tex->xrepeat= tex->yrepeat= 1; - tex->fie_ima= 2; - tex->sfra= 1; - tex->frames= 0; - tex->offset= 0; - tex->noisesize= 0.25; - tex->noisedepth= 2; - tex->turbul= 5.0; - tex->nabla= 0.025; // also in do_versions - tex->bright= 1.0; - tex->contrast= 1.0; - tex->saturation= 1.0; - tex->filtersize= 1.0; - tex->rfac= 1.0; - tex->gfac= 1.0; - tex->bfac= 1.0; + tex->xrepeat = tex->yrepeat = 1; + tex->fie_ima = 2; + tex->sfra = 1; + tex->frames = 0; + tex->offset = 0; + tex->noisesize = 0.25; + tex->noisedepth = 2; + tex->turbul = 5.0; + tex->nabla = 0.025; // also in do_versions + tex->bright = 1.0; + tex->contrast = 1.0; + tex->saturation = 1.0; + tex->filtersize = 1.0; + tex->rfac = 1.0; + tex->gfac = 1.0; + tex->bfac = 1.0; /* newnoise: init. */ tex->noisebasis = 0; tex->noisebasis2 = 0; @@ -621,11 +621,11 @@ void default_tex(Tex *tex) tex->vn_coltype = 0; if (tex->env) { - tex->env->stype=ENV_ANIM; - tex->env->clipsta=0.1; - tex->env->clipend=100; - tex->env->cuberes=600; - tex->env->depth=0; + tex->env->stype = ENV_ANIM; + tex->env->clipsta = 0.1; + tex->env->clipend = 100; + tex->env->cuberes = 600; + tex->env->depth = 0; } if (tex->pd) { @@ -635,8 +635,8 @@ void default_tex(Tex *tex) if (tex->vd) { tex->vd->resol[0] = tex->vd->resol[1] = tex->vd->resol[2] = 0; - tex->vd->interp_type=TEX_VD_LINEAR; - tex->vd->file_format=TEX_VD_SMOKE; + tex->vd->interp_type = TEX_VD_LINEAR; + tex->vd->file_format = TEX_VD_SMOKE; } if (tex->ot) { @@ -645,18 +645,18 @@ void default_tex(Tex *tex) } pit = tex->plugin; if (pit) { - varstr= pit->varstr; + varstr = pit->varstr; if (varstr) { - for (a=0; a<pit->vars; a++, varstr++) { + for (a = 0; a < pit->vars; a++, varstr++) { pit->data[a] = varstr->def; } } } - tex->iuser.fie_ima= 2; - tex->iuser.ok= 1; - tex->iuser.frames= 100; - tex->iuser.sfra= 1; + tex->iuser.fie_ima = 2; + tex->iuser.ok = 1; + tex->iuser.frames = 100; + tex->iuser.sfra = 1; tex->preview = NULL; } @@ -690,10 +690,10 @@ void tex_set_type(Tex *tex, int type) Tex *add_texture(const char *name) { - Main *bmain= G.main; + Main *bmain = G.main; Tex *tex; - tex= BKE_libblock_alloc(&bmain->tex, ID_TE, name); + tex = BKE_libblock_alloc(&bmain->tex, ID_TE, name); default_tex(tex); @@ -704,65 +704,65 @@ Tex *add_texture(const char *name) void default_mtex(MTex *mtex) { - mtex->texco= TEXCO_ORCO; - mtex->mapto= MAP_COL; - mtex->object= NULL; - mtex->projx= PROJ_X; - mtex->projy= PROJ_Y; - mtex->projz= PROJ_Z; - mtex->mapping= MTEX_FLAT; - mtex->ofs[0]= 0.0; - mtex->ofs[1]= 0.0; - mtex->ofs[2]= 0.0; - mtex->size[0]= 1.0; - mtex->size[1]= 1.0; - mtex->size[2]= 1.0; - mtex->tex= NULL; - mtex->texflag= MTEX_3TAP_BUMP | MTEX_BUMP_OBJECTSPACE; - mtex->colormodel= 0; - mtex->r= 1.0; - mtex->g= 0.0; - mtex->b= 1.0; - mtex->k= 1.0; - mtex->def_var= 1.0; - mtex->blendtype= MTEX_BLEND; - mtex->colfac= 1.0; - mtex->norfac= 1.0; - mtex->varfac= 1.0; - mtex->dispfac=0.2; - mtex->colspecfac= 1.0f; - mtex->mirrfac= 1.0f; - mtex->alphafac= 1.0f; - mtex->difffac= 1.0f; - mtex->specfac= 1.0f; - mtex->emitfac= 1.0f; - mtex->hardfac= 1.0f; - mtex->raymirrfac= 1.0f; - mtex->translfac= 1.0f; - mtex->ambfac= 1.0f; - mtex->colemitfac= 1.0f; - mtex->colreflfac= 1.0f; - mtex->coltransfac= 1.0f; - mtex->densfac= 1.0f; - mtex->scatterfac= 1.0f; - mtex->reflfac= 1.0f; - mtex->shadowfac= 1.0f; - mtex->zenupfac= 1.0f; - mtex->zendownfac= 1.0f; - mtex->blendfac= 1.0f; - mtex->timefac= 1.0f; - mtex->lengthfac= 1.0f; - mtex->clumpfac= 1.0f; - mtex->kinkfac= 1.0f; - mtex->roughfac= 1.0f; - mtex->padensfac= 1.0f; - mtex->lifefac= 1.0f; - mtex->sizefac= 1.0f; - mtex->ivelfac= 1.0f; - mtex->dampfac= 1.0f; - mtex->gravityfac= 1.0f; - mtex->fieldfac= 1.0f; - mtex->normapspace= MTEX_NSPACE_TANGENT; + mtex->texco = TEXCO_ORCO; + mtex->mapto = MAP_COL; + mtex->object = NULL; + mtex->projx = PROJ_X; + mtex->projy = PROJ_Y; + mtex->projz = PROJ_Z; + mtex->mapping = MTEX_FLAT; + mtex->ofs[0] = 0.0; + mtex->ofs[1] = 0.0; + mtex->ofs[2] = 0.0; + mtex->size[0] = 1.0; + mtex->size[1] = 1.0; + mtex->size[2] = 1.0; + mtex->tex = NULL; + mtex->texflag = MTEX_3TAP_BUMP | MTEX_BUMP_OBJECTSPACE; + mtex->colormodel = 0; + mtex->r = 1.0; + mtex->g = 0.0; + mtex->b = 1.0; + mtex->k = 1.0; + mtex->def_var = 1.0; + mtex->blendtype = MTEX_BLEND; + mtex->colfac = 1.0; + mtex->norfac = 1.0; + mtex->varfac = 1.0; + mtex->dispfac = 0.2; + mtex->colspecfac = 1.0f; + mtex->mirrfac = 1.0f; + mtex->alphafac = 1.0f; + mtex->difffac = 1.0f; + mtex->specfac = 1.0f; + mtex->emitfac = 1.0f; + mtex->hardfac = 1.0f; + mtex->raymirrfac = 1.0f; + mtex->translfac = 1.0f; + mtex->ambfac = 1.0f; + mtex->colemitfac = 1.0f; + mtex->colreflfac = 1.0f; + mtex->coltransfac = 1.0f; + mtex->densfac = 1.0f; + mtex->scatterfac = 1.0f; + mtex->reflfac = 1.0f; + mtex->shadowfac = 1.0f; + mtex->zenupfac = 1.0f; + mtex->zendownfac = 1.0f; + mtex->blendfac = 1.0f; + mtex->timefac = 1.0f; + mtex->lengthfac = 1.0f; + mtex->clumpfac = 1.0f; + mtex->kinkfac = 1.0f; + mtex->roughfac = 1.0f; + mtex->padensfac = 1.0f; + mtex->lifefac = 1.0f; + mtex->sizefac = 1.0f; + mtex->ivelfac = 1.0f; + mtex->dampfac = 1.0f; + mtex->gravityfac = 1.0f; + mtex->fieldfac = 1.0f; + mtex->normapspace = MTEX_NSPACE_TANGENT; } @@ -772,7 +772,7 @@ MTex *add_mtex(void) { MTex *mtex; - mtex= MEM_callocN(sizeof(MTex), "add_mtex"); + mtex = MEM_callocN(sizeof(MTex), "add_mtex"); default_mtex(mtex); @@ -787,16 +787,16 @@ MTex *add_mtex_id(ID *id, int slot) give_active_mtex(id, &mtex_ar, &act); - if (mtex_ar==NULL) { + if (mtex_ar == NULL) { return NULL; } - if (slot==-1) { + if (slot == -1) { /* find first free */ int i; - for (i= 0; i < MAX_MTEX; i++) { + for (i = 0; i < MAX_MTEX; i++) { if (!mtex_ar[i]) { - slot= i; + slot = i; break; } } @@ -814,10 +814,10 @@ MTex *add_mtex_id(ID *id, int slot) if (mtex_ar[slot]) { id_us_min((ID *)mtex_ar[slot]->tex); MEM_freeN(mtex_ar[slot]); - mtex_ar[slot]= NULL; + mtex_ar[slot] = NULL; } - mtex_ar[slot]= add_mtex(); + mtex_ar[slot] = add_mtex(); return mtex_ar[slot]; } @@ -828,27 +828,27 @@ Tex *BKE_texture_copy(Tex *tex) { Tex *texn; - texn= BKE_libblock_copy(&tex->id); - if (texn->type==TEX_IMAGE) id_us_plus((ID *)texn->ima); - else texn->ima= NULL; + texn = BKE_libblock_copy(&tex->id); + if (texn->type == TEX_IMAGE) id_us_plus((ID *)texn->ima); + else texn->ima = NULL; if (texn->plugin) { - texn->plugin= MEM_dupallocN(texn->plugin); + texn->plugin = MEM_dupallocN(texn->plugin); open_plugin_tex(texn->plugin); } - if (texn->coba) texn->coba= MEM_dupallocN(texn->coba); - if (texn->env) texn->env= BKE_copy_envmap(texn->env); - if (texn->pd) texn->pd= BKE_copy_pointdensity(texn->pd); - if (texn->vd) texn->vd= MEM_dupallocN(texn->vd); - if (texn->ot) texn->ot= BKE_copy_oceantex(texn->ot); + if (texn->coba) texn->coba = MEM_dupallocN(texn->coba); + if (texn->env) texn->env = BKE_copy_envmap(texn->env); + if (texn->pd) texn->pd = BKE_copy_pointdensity(texn->pd); + if (texn->vd) texn->vd = MEM_dupallocN(texn->vd); + if (texn->ot) texn->ot = BKE_copy_oceantex(texn->ot); if (tex->preview) texn->preview = BKE_previewimg_copy(tex->preview); if (tex->nodetree) { if (tex->nodetree->execdata) { ntreeTexEndExecTree(tex->nodetree->execdata, 1); } - texn->nodetree= ntreeCopyTree(tex->nodetree); + texn->nodetree = ntreeCopyTree(tex->nodetree); } return texn; @@ -859,35 +859,35 @@ Tex *localize_texture(Tex *tex) { Tex *texn; - texn= BKE_libblock_copy(&tex->id); + texn = BKE_libblock_copy(&tex->id); BLI_remlink(&G.main->tex, texn); /* image texture: BKE_texture_free also doesn't decrease */ if (texn->plugin) { - texn->plugin= MEM_dupallocN(texn->plugin); + texn->plugin = MEM_dupallocN(texn->plugin); open_plugin_tex(texn->plugin); } - if (texn->coba) texn->coba= MEM_dupallocN(texn->coba); + if (texn->coba) texn->coba = MEM_dupallocN(texn->coba); if (texn->env) { - texn->env= BKE_copy_envmap(texn->env); + texn->env = BKE_copy_envmap(texn->env); id_us_min(&texn->env->ima->id); } - if (texn->pd) texn->pd= BKE_copy_pointdensity(texn->pd); + if (texn->pd) texn->pd = BKE_copy_pointdensity(texn->pd); if (texn->vd) { - texn->vd= MEM_dupallocN(texn->vd); + texn->vd = MEM_dupallocN(texn->vd); if (texn->vd->dataset) - texn->vd->dataset= MEM_dupallocN(texn->vd->dataset); + texn->vd->dataset = MEM_dupallocN(texn->vd->dataset); } if (texn->ot) { - texn->ot= BKE_copy_oceantex(tex->ot); + texn->ot = BKE_copy_oceantex(tex->ot); } texn->preview = NULL; if (tex->nodetree) { - texn->nodetree= ntreeLocalize(tex->nodetree); + texn->nodetree = ntreeLocalize(tex->nodetree); } return texn; @@ -903,74 +903,74 @@ static void extern_local_texture(Tex *tex) void BKE_texture_make_local(Tex *tex) { - Main *bmain= G.main; + Main *bmain = G.main; Material *ma; World *wrld; Lamp *la; Brush *br; ParticleSettings *pa; - int a, is_local= FALSE, is_lib= FALSE; + int a, is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (tex->id.lib==NULL) return; + if (tex->id.lib == NULL) return; - if (tex->id.us==1) { + if (tex->id.us == 1) { id_clear_lib_data(bmain, &tex->id); extern_local_texture(tex); return; } - ma= bmain->mat.first; + ma = bmain->mat.first; while (ma) { - for (a=0; a<MAX_MTEX; a++) { - if (ma->mtex[a] && ma->mtex[a]->tex==tex) { - if (ma->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < MAX_MTEX; a++) { + if (ma->mtex[a] && ma->mtex[a]->tex == tex) { + if (ma->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - ma= ma->id.next; + ma = ma->id.next; } - la= bmain->lamp.first; + la = bmain->lamp.first; while (la) { - for (a=0; a<MAX_MTEX; a++) { - if (la->mtex[a] && la->mtex[a]->tex==tex) { - if (la->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < MAX_MTEX; a++) { + if (la->mtex[a] && la->mtex[a]->tex == tex) { + if (la->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - la= la->id.next; + la = la->id.next; } - wrld= bmain->world.first; + wrld = bmain->world.first; while (wrld) { - for (a=0; a<MAX_MTEX; a++) { - if (wrld->mtex[a] && wrld->mtex[a]->tex==tex) { - if (wrld->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < MAX_MTEX; a++) { + if (wrld->mtex[a] && wrld->mtex[a]->tex == tex) { + if (wrld->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - wrld= wrld->id.next; + wrld = wrld->id.next; } - br= bmain->brush.first; + br = bmain->brush.first; while (br) { - if (br->mtex.tex==tex) { - if (br->id.lib) is_lib= TRUE; - else is_local= TRUE; + if (br->mtex.tex == tex) { + if (br->id.lib) is_lib = TRUE; + else is_local = TRUE; } - br= br->id.next; + br = br->id.next; } - pa= bmain->particle.first; + pa = bmain->particle.first; while (pa) { - for (a=0; a<MAX_MTEX; a++) { - if (pa->mtex[a] && pa->mtex[a]->tex==tex) { - if (pa->id.lib) is_lib= TRUE; - else is_local= TRUE; + for (a = 0; a < MAX_MTEX; a++) { + if (pa->mtex[a] && pa->mtex[a]->tex == tex) { + if (pa->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - pa= pa->id.next; + pa = pa->id.next; } if (is_local && is_lib == FALSE) { @@ -978,75 +978,75 @@ void BKE_texture_make_local(Tex *tex) extern_local_texture(tex); } else if (is_local && is_lib) { - Tex *tex_new= BKE_texture_copy(tex); + Tex *tex_new = BKE_texture_copy(tex); - tex_new->id.us= 0; + tex_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, tex->id.lib, &tex_new->id); - ma= bmain->mat.first; + ma = bmain->mat.first; while (ma) { - for (a=0; a<MAX_MTEX; a++) { - if (ma->mtex[a] && ma->mtex[a]->tex==tex) { - if (ma->id.lib==NULL) { - ma->mtex[a]->tex= tex_new; + for (a = 0; a < MAX_MTEX; a++) { + if (ma->mtex[a] && ma->mtex[a]->tex == tex) { + if (ma->id.lib == NULL) { + ma->mtex[a]->tex = tex_new; tex_new->id.us++; tex->id.us--; } } } - ma= ma->id.next; + ma = ma->id.next; } - la= bmain->lamp.first; + la = bmain->lamp.first; while (la) { - for (a=0; a<MAX_MTEX; a++) { - if (la->mtex[a] && la->mtex[a]->tex==tex) { - if (la->id.lib==NULL) { - la->mtex[a]->tex= tex_new; + for (a = 0; a < MAX_MTEX; a++) { + if (la->mtex[a] && la->mtex[a]->tex == tex) { + if (la->id.lib == NULL) { + la->mtex[a]->tex = tex_new; tex_new->id.us++; tex->id.us--; } } } - la= la->id.next; + la = la->id.next; } - wrld= bmain->world.first; + wrld = bmain->world.first; while (wrld) { - for (a=0; a<MAX_MTEX; a++) { - if (wrld->mtex[a] && wrld->mtex[a]->tex==tex) { - if (wrld->id.lib==NULL) { - wrld->mtex[a]->tex= tex_new; + for (a = 0; a < MAX_MTEX; a++) { + if (wrld->mtex[a] && wrld->mtex[a]->tex == tex) { + if (wrld->id.lib == NULL) { + wrld->mtex[a]->tex = tex_new; tex_new->id.us++; tex->id.us--; } } } - wrld= wrld->id.next; + wrld = wrld->id.next; } - br= bmain->brush.first; + br = bmain->brush.first; while (br) { - if (br->mtex.tex==tex) { - if (br->id.lib==NULL) { - br->mtex.tex= tex_new; + if (br->mtex.tex == tex) { + if (br->id.lib == NULL) { + br->mtex.tex = tex_new; tex_new->id.us++; tex->id.us--; } } - br= br->id.next; + br = br->id.next; } - pa= bmain->particle.first; + pa = bmain->particle.first; while (pa) { - for (a=0; a<MAX_MTEX; a++) { - if (pa->mtex[a] && pa->mtex[a]->tex==tex) { - if (pa->id.lib==NULL) { - pa->mtex[a]->tex= tex_new; + for (a = 0; a < MAX_MTEX; a++) { + if (pa->mtex[a] && pa->mtex[a]->tex == tex) { + if (pa->id.lib == NULL) { + pa->mtex[a]->tex = tex_new; tex_new->id.us++; tex->id.us--; } } } - pa= pa->id.next; + pa = pa->id.next; } } } @@ -1055,10 +1055,10 @@ void BKE_texture_make_local(Tex *tex) #if 0 /* UNUSED */ void autotexname(Tex *tex) { - Main *bmain= G.main; - char texstr[20][15]= {"None", "Clouds", "Wood", "Marble", "Magic", "Blend", - "Stucci", "Noise", "Image", "Plugin", "EnvMap", "Musgrave", - "Voronoi", "DistNoise", "Point Density", "Voxel Data", "Ocean", "", "", ""}; + Main *bmain = G.main; + char texstr[20][15] = {"None", "Clouds", "Wood", "Marble", "Magic", "Blend", + "Stucci", "Noise", "Image", "Plugin", "EnvMap", "Musgrave", + "Voronoi", "DistNoise", "Point Density", "Voxel Data", "Ocean", "", "", ""}; Image *ima; char di[FILE_MAXDIR], fi[FILE_MAXFILE]; @@ -1067,8 +1067,8 @@ void autotexname(Tex *tex) new_id(&bmain->tex, (ID *)tex, "Noddy"); } else - if (tex->type==TEX_IMAGE) { - ima= tex->ima; + if (tex->type == TEX_IMAGE) { + ima = tex->ima; if (ima) { BLI_strncpy(di, ima->name, sizeof(di)); BLI_splitdirstring(di, fi); @@ -1078,7 +1078,7 @@ void autotexname(Tex *tex) } else new_id(&bmain->tex, (ID *)tex, texstr[tex->type]); } - else if (tex->type==TEX_PLUGIN && tex->plugin) new_id(&bmain->tex, (ID *)tex, tex->plugin->pname); + else if (tex->type == TEX_PLUGIN && tex->plugin) new_id(&bmain->tex, (ID *)tex, tex->plugin->pname); else new_id(&bmain->tex, (ID *)tex, texstr[tex->type]); } } @@ -1089,21 +1089,21 @@ void autotexname(Tex *tex) Tex *give_current_object_texture(Object *ob) { Material *ma, *node_ma; - Tex *tex= NULL; + Tex *tex = NULL; - if (ob==NULL) return NULL; - if (ob->totcol==0 && !(ob->type==OB_LAMP)) return NULL; + if (ob == NULL) return NULL; + if (ob->totcol == 0 && !(ob->type == OB_LAMP)) return NULL; - if (ob->type==OB_LAMP) { - tex= give_current_lamp_texture(ob->data); + if (ob->type == OB_LAMP) { + tex = give_current_lamp_texture(ob->data); } else { - ma= give_current_material(ob, ob->actcol); + ma = give_current_material(ob, ob->actcol); - if ((node_ma=give_node_material(ma))) - ma= node_ma; + if ((node_ma = give_node_material(ma))) + ma = node_ma; - tex= give_current_material_texture(ma); + tex = give_current_material_texture(ma); } return tex; @@ -1111,12 +1111,12 @@ Tex *give_current_object_texture(Object *ob) Tex *give_current_lamp_texture(Lamp *la) { - MTex *mtex= NULL; - Tex *tex= NULL; + MTex *mtex = NULL; + Tex *tex = NULL; if (la) { - mtex= la->mtex[(int)(la->texact)]; - if (mtex) tex= mtex->tex; + mtex = la->mtex[(int)(la->texact)]; + if (mtex) tex = mtex->tex; } return tex; @@ -1124,23 +1124,23 @@ Tex *give_current_lamp_texture(Lamp *la) void set_current_lamp_texture(Lamp *la, Tex *newtex) { - int act= la->texact; + int act = la->texact; if (la->mtex[act] && la->mtex[act]->tex) id_us_min(&la->mtex[act]->tex->id); if (newtex) { if (!la->mtex[act]) { - la->mtex[act]= add_mtex(); - la->mtex[act]->texco= TEXCO_GLOB; + la->mtex[act] = add_mtex(); + la->mtex[act]->texco = TEXCO_GLOB; } - la->mtex[act]->tex= newtex; + la->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } else if (la->mtex[act]) { MEM_freeN(la->mtex[act]); - la->mtex[act]= NULL; + la->mtex[act] = NULL; } } @@ -1154,25 +1154,25 @@ bNode *give_current_material_texture_node(Material *ma) Tex *give_current_material_texture(Material *ma) { - MTex *mtex= NULL; - Tex *tex= NULL; + MTex *mtex = NULL; + Tex *tex = NULL; bNode *node; if (ma && ma->use_nodes && ma->nodetree) { /* first check texture, then material, this works together * with a hack that clears the active ID flag for textures on * making a material node active */ - node= nodeGetActiveID(ma->nodetree, ID_TE); + node = nodeGetActiveID(ma->nodetree, ID_TE); if (node) { - tex= (Tex *)node->id; - ma= NULL; + tex = (Tex *)node->id; + ma = NULL; } } if (ma) { - mtex= ma->mtex[(int)(ma->texact)]; - if (mtex) tex= mtex->tex; + mtex = ma->mtex[(int)(ma->texact)]; + if (mtex) tex = mtex->tex; } return tex; @@ -1181,26 +1181,26 @@ Tex *give_current_material_texture(Material *ma) int give_active_mtex(ID *id, MTex ***mtex_ar, short *act) { switch (GS(id->name)) { - case ID_MA: - *mtex_ar= ((Material *)id)->mtex; - if (act) *act= (((Material *)id)->texact); - break; - case ID_WO: - *mtex_ar= ((World *)id)->mtex; - if (act) *act= (((World *)id)->texact); - break; - case ID_LA: - *mtex_ar= ((Lamp *)id)->mtex; - if (act) *act= (((Lamp *)id)->texact); - break; - case ID_PA: - *mtex_ar= ((ParticleSettings *)id)->mtex; - if (act) *act= (((ParticleSettings *)id)->texact); - break; - default: - *mtex_ar = NULL; - if (act) *act= 0; - return FALSE; + case ID_MA: + *mtex_ar = ((Material *)id)->mtex; + if (act) *act = (((Material *)id)->texact); + break; + case ID_WO: + *mtex_ar = ((World *)id)->mtex; + if (act) *act = (((World *)id)->texact); + break; + case ID_LA: + *mtex_ar = ((Lamp *)id)->mtex; + if (act) *act = (((Lamp *)id)->texact); + break; + case ID_PA: + *mtex_ar = ((ParticleSettings *)id)->mtex; + if (act) *act = (((ParticleSettings *)id)->texact); + break; + default: + *mtex_ar = NULL; + if (act) *act = 0; + return FALSE; } return TRUE; @@ -1208,57 +1208,57 @@ int give_active_mtex(ID *id, MTex ***mtex_ar, short *act) void set_active_mtex(ID *id, short act) { - if (act<0) act= 0; - else if (act>=MAX_MTEX) act= MAX_MTEX-1; + if (act < 0) act = 0; + else if (act >= MAX_MTEX) act = MAX_MTEX - 1; switch (GS(id->name)) { - case ID_MA: - ((Material *)id)->texact= act; - break; - case ID_WO: - ((World *)id)->texact= act; - break; - case ID_LA: - ((Lamp *)id)->texact= act; - break; - case ID_PA: - ((ParticleSettings *)id)->texact= act; - break; + case ID_MA: + ((Material *)id)->texact = act; + break; + case ID_WO: + ((World *)id)->texact = act; + break; + case ID_LA: + ((Lamp *)id)->texact = act; + break; + case ID_PA: + ((ParticleSettings *)id)->texact = act; + break; } } void set_current_material_texture(Material *ma, Tex *newtex) { - Tex *tex= NULL; + Tex *tex = NULL; bNode *node; if (ma && ma->use_nodes && ma->nodetree) { - node= nodeGetActiveID(ma->nodetree, ID_TE); + node = nodeGetActiveID(ma->nodetree, ID_TE); if (node) { - tex= (Tex *)node->id; + tex = (Tex *)node->id; id_us_min(&tex->id); - node->id= &newtex->id; + node->id = &newtex->id; id_us_plus(&newtex->id); - ma= NULL; + ma = NULL; } } if (ma) { - int act= (int)ma->texact; + int act = (int)ma->texact; - tex= (ma->mtex[act])? ma->mtex[act]->tex: NULL; + tex = (ma->mtex[act]) ? ma->mtex[act]->tex : NULL; id_us_min(&tex->id); if (newtex) { if (!ma->mtex[act]) - ma->mtex[act]= add_mtex(); + ma->mtex[act] = add_mtex(); - ma->mtex[act]->tex= newtex; + ma->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } else if (ma->mtex[act]) { MEM_freeN(ma->mtex[act]); - ma->mtex[act]= NULL; + ma->mtex[act] = NULL; } } } @@ -1268,7 +1268,7 @@ int has_current_material_texture(Material *ma) bNode *node; if (ma && ma->use_nodes && ma->nodetree) { - node= nodeGetActiveID(ma->nodetree, ID_TE); + node = nodeGetActiveID(ma->nodetree, ID_TE); if (node) return 1; @@ -1279,36 +1279,36 @@ int has_current_material_texture(Material *ma) Tex *give_current_world_texture(World *world) { - MTex *mtex= NULL; - Tex *tex= NULL; + MTex *mtex = NULL; + Tex *tex = NULL; if (!world) return NULL; - mtex= world->mtex[(int)(world->texact)]; - if (mtex) tex= mtex->tex; + mtex = world->mtex[(int)(world->texact)]; + if (mtex) tex = mtex->tex; return tex; } void set_current_world_texture(World *wo, Tex *newtex) { - int act= wo->texact; + int act = wo->texact; if (wo->mtex[act] && wo->mtex[act]->tex) id_us_min(&wo->mtex[act]->tex->id); if (newtex) { if (!wo->mtex[act]) { - wo->mtex[act]= add_mtex(); - wo->mtex[act]->texco= TEXCO_VIEW; + wo->mtex[act] = add_mtex(); + wo->mtex[act]->texco = TEXCO_VIEW; } - wo->mtex[act]->tex= newtex; + wo->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } else if (wo->mtex[act]) { MEM_freeN(wo->mtex[act]); - wo->mtex[act]= NULL; + wo->mtex[act] = NULL; } } @@ -1323,44 +1323,44 @@ void set_current_brush_texture(Brush *br, Tex *newtex) id_us_min(&br->mtex.tex->id); if (newtex) { - br->mtex.tex= newtex; + br->mtex.tex = newtex; id_us_plus(&newtex->id); } } Tex *give_current_particle_texture(ParticleSettings *part) { - MTex *mtex= NULL; - Tex *tex= NULL; + MTex *mtex = NULL; + Tex *tex = NULL; if (!part) return NULL; - mtex= part->mtex[(int)(part->texact)]; - if (mtex) tex= mtex->tex; + mtex = part->mtex[(int)(part->texact)]; + if (mtex) tex = mtex->tex; return tex; } void set_current_particle_texture(ParticleSettings *part, Tex *newtex) { - int act= part->texact; + int act = part->texact; if (part->mtex[act] && part->mtex[act]->tex) id_us_min(&part->mtex[act]->tex->id); if (newtex) { if (!part->mtex[act]) { - part->mtex[act]= add_mtex(); - part->mtex[act]->texco= TEXCO_ORCO; - part->mtex[act]->blendtype= MTEX_MUL; + part->mtex[act] = add_mtex(); + part->mtex[act]->texco = TEXCO_ORCO; + part->mtex[act]->blendtype = MTEX_MUL; } - part->mtex[act]->tex= newtex; + part->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } else if (part->mtex[act]) { MEM_freeN(part->mtex[act]); - part->mtex[act]= NULL; + part->mtex[act] = NULL; } } @@ -1370,12 +1370,12 @@ EnvMap *BKE_add_envmap(void) { EnvMap *env; - env= MEM_callocN(sizeof(EnvMap), "envmap"); - env->type= ENV_CUBE; - env->stype= ENV_ANIM; - env->clipsta= 0.1; - env->clipend= 100.0; - env->cuberes= 600; + env = MEM_callocN(sizeof(EnvMap), "envmap"); + env->type = ENV_CUBE; + env->stype = ENV_ANIM; + env->clipsta = 0.1; + env->clipend = 100.0; + env->cuberes = 600; env->viewscale = 0.5; return env; @@ -1388,9 +1388,9 @@ EnvMap *BKE_copy_envmap(EnvMap *env) EnvMap *envn; int a; - envn= MEM_dupallocN(env); - envn->ok= 0; - for (a=0; a<6; a++) envn->cube[a]= NULL; + envn = MEM_dupallocN(env); + envn->ok = 0; + for (a = 0; a < 6; a++) envn->cube[a] = NULL; if (envn->ima) id_us_plus((ID *)envn->ima); return envn; @@ -1402,12 +1402,12 @@ void BKE_free_envmapdata(EnvMap *env) { unsigned int part; - for (part=0; part<6; part++) { + for (part = 0; part < 6; part++) { if (env->cube[part]) IMB_freeImBuf(env->cube[part]); - env->cube[part]= NULL; + env->cube[part] = NULL; } - env->ok= 0; + env->ok = 0; } /* ------------------------------------------------------------------------- */ @@ -1426,7 +1426,7 @@ PointDensity *BKE_add_pointdensity(void) { PointDensity *pd; - pd= MEM_callocN(sizeof(PointDensity), "pointdensity"); + pd = MEM_callocN(sizeof(PointDensity), "pointdensity"); pd->flag = 0; pd->radius = 0.3f; pd->falloff_type = TEX_PD_FALLOFF_STD; @@ -1443,7 +1443,7 @@ PointDensity *BKE_add_pointdensity(void) pd->totpoints = 0; pd->object = NULL; pd->psys = 0; - pd->psys_cache_space= TEX_PD_WORLDSPACE; + pd->psys_cache_space = TEX_PD_WORLDSPACE; pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1); pd->falloff_curve->preset = CURVE_PRESET_LINE; @@ -1458,10 +1458,10 @@ PointDensity *BKE_copy_pointdensity(PointDensity *pd) { PointDensity *pdn; - pdn= MEM_dupallocN(pd); + pdn = MEM_dupallocN(pd); pdn->point_tree = NULL; pdn->point_data = NULL; - if (pdn->coba) pdn->coba= MEM_dupallocN(pdn->coba); + if (pdn->coba) pdn->coba = MEM_dupallocN(pdn->coba); pdn->falloff_curve = curvemapping_copy(pdn->falloff_curve); /* can be NULL */ return pdn; } @@ -1511,11 +1511,11 @@ struct VoxelData *BKE_add_voxeldata(void) { VoxelData *vd; - vd= MEM_callocN(sizeof(struct VoxelData), "voxeldata"); + vd = MEM_callocN(sizeof(struct VoxelData), "voxeldata"); vd->dataset = NULL; vd->resol[0] = vd->resol[1] = vd->resol[2] = 1; - vd->interp_type= TEX_VD_LINEAR; - vd->file_format= TEX_VD_SMOKE; + vd->interp_type = TEX_VD_LINEAR; + vd->file_format = TEX_VD_SMOKE; vd->int_multiplier = 1.0; vd->extend = TEX_CLIP; vd->object = NULL; @@ -1523,13 +1523,13 @@ struct VoxelData *BKE_add_voxeldata(void) vd->ok = 0; return vd; - } +} struct VoxelData *BKE_copy_voxeldata(struct VoxelData *vd) { VoxelData *vdn; - vdn= MEM_dupallocN(vd); + vdn = MEM_dupallocN(vd); vdn->dataset = NULL; return vdn; @@ -1541,7 +1541,7 @@ struct OceanTex *BKE_add_oceantex(void) { OceanTex *ot; - ot= MEM_callocN(sizeof(struct OceanTex), "ocean texture"); + ot = MEM_callocN(sizeof(struct OceanTex), "ocean texture"); ot->output = TEX_OCN_DISPLACEMENT; ot->object = NULL; @@ -1550,7 +1550,7 @@ struct OceanTex *BKE_add_oceantex(void) struct OceanTex *BKE_copy_oceantex(struct OceanTex *ot) { - OceanTex *otn= MEM_dupallocN(ot); + OceanTex *otn = MEM_dupallocN(ot); return otn; } @@ -1568,8 +1568,9 @@ int BKE_texture_dependsOnTime(const struct Tex *texture) // assume all plugins depend on time return 1; } - else if ( texture->ima && - ELEM(texture->ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) { + else if (texture->ima && + ELEM(texture->ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) + { return 1; } else if (texture->adt) { diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index f50a655236f..303098ea0bd 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -56,8 +56,8 @@ void BKE_world_free(World *wrld) MTex *mtex; int a; - for (a=0; a<MAX_MTEX; a++) { - mtex= wrld->mtex[a]; + for (a = 0; a < MAX_MTEX; a++) { + mtex = wrld->mtex[a]; if (mtex && mtex->tex) mtex->tex->id.us--; if (mtex) MEM_freeN(mtex); } @@ -71,40 +71,40 @@ void BKE_world_free(World *wrld) MEM_freeN(wrld->nodetree); } - BKE_icon_delete((struct ID*)wrld); + BKE_icon_delete((struct ID *)wrld); wrld->id.icon_id = 0; } World *add_world(const char *name) { - Main *bmain= G.main; + Main *bmain = G.main; World *wrld; - wrld= BKE_libblock_alloc(&bmain->world, ID_WO, name); + wrld = BKE_libblock_alloc(&bmain->world, ID_WO, name); - wrld->horr= 0.05f; - wrld->horg= 0.05f; - wrld->horb= 0.05f; - wrld->zenr= 0.01f; - wrld->zeng= 0.01f; - wrld->zenb= 0.01f; - wrld->skytype= 0; - wrld->stardist= 15.0f; - wrld->starsize= 2.0f; - - wrld->exp= 0.0f; - wrld->exposure=wrld->range= 1.0f; - - wrld->aodist= 10.0f; - wrld->aosamp= 5; - wrld->aoenergy= 1.0f; - wrld->ao_env_energy= 1.0f; - wrld->ao_indirect_energy= 1.0f; - wrld->ao_indirect_bounces= 1; - wrld->aobias= 0.05f; + wrld->horr = 0.05f; + wrld->horg = 0.05f; + wrld->horb = 0.05f; + wrld->zenr = 0.01f; + wrld->zeng = 0.01f; + wrld->zenb = 0.01f; + wrld->skytype = 0; + wrld->stardist = 15.0f; + wrld->starsize = 2.0f; + + wrld->exp = 0.0f; + wrld->exposure = wrld->range = 1.0f; + + wrld->aodist = 10.0f; + wrld->aosamp = 5; + wrld->aoenergy = 1.0f; + wrld->ao_env_energy = 1.0f; + wrld->ao_indirect_energy = 1.0f; + wrld->ao_indirect_bounces = 1; + wrld->aobias = 0.05f; wrld->ao_samp_method = WO_AOSAMP_HAMMERSLEY; - wrld->ao_approx_error= 0.25f; + wrld->ao_approx_error = 0.25f; wrld->preview = NULL; wrld->miststa = 5.0f; @@ -118,18 +118,18 @@ World *BKE_world_copy(World *wrld) World *wrldn; int a; - wrldn= BKE_libblock_copy(&wrld->id); + wrldn = BKE_libblock_copy(&wrld->id); - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (wrld->mtex[a]) { - wrldn->mtex[a]= MEM_mallocN(sizeof(MTex), "BKE_world_copy"); + wrldn->mtex[a] = MEM_mallocN(sizeof(MTex), "BKE_world_copy"); memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex)); id_us_plus((ID *)wrldn->mtex[a]->tex); } } if (wrld->nodetree) - wrldn->nodetree= ntreeCopyTree(wrld->nodetree); + wrldn->nodetree = ntreeCopyTree(wrld->nodetree); if (wrld->preview) wrldn->preview = BKE_previewimg_copy(wrld->preview); @@ -142,12 +142,12 @@ World *localize_world(World *wrld) World *wrldn; int a; - wrldn= BKE_libblock_copy(&wrld->id); + wrldn = BKE_libblock_copy(&wrld->id); BLI_remlink(&G.main->world, wrldn); - for (a=0; a<MAX_MTEX; a++) { + for (a = 0; a < MAX_MTEX; a++) { if (wrld->mtex[a]) { - wrldn->mtex[a]= MEM_mallocN(sizeof(MTex), "localize_world"); + wrldn->mtex[a] = MEM_mallocN(sizeof(MTex), "localize_world"); memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex)); /* free world decrements */ id_us_plus((ID *)wrldn->mtex[a]->tex); @@ -155,51 +155,51 @@ World *localize_world(World *wrld) } if (wrld->nodetree) - wrldn->nodetree= ntreeLocalize(wrld->nodetree); + wrldn->nodetree = ntreeLocalize(wrld->nodetree); - wrldn->preview= NULL; + wrldn->preview = NULL; return wrldn; } void BKE_world_make_local(World *wrld) { - Main *bmain= G.main; + Main *bmain = G.main; Scene *sce; - int is_local= FALSE, is_lib= FALSE; + int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - if (wrld->id.lib==NULL) return; - if (wrld->id.us==1) { + if (wrld->id.lib == NULL) return; + if (wrld->id.us == 1) { id_clear_lib_data(bmain, &wrld->id); return; } - for (sce= bmain->scene.first; sce && ELEM(FALSE, is_lib, is_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) is_lib= TRUE; - else is_local= TRUE; + if (sce->id.lib) is_lib = TRUE; + else is_local = TRUE; } } - if (is_local && is_lib==FALSE) { + if (is_local && is_lib == FALSE) { id_clear_lib_data(bmain, &wrld->id); } else if (is_local && is_lib) { - World *wrld_new= BKE_world_copy(wrld); - wrld_new->id.us= 0; + World *wrld_new = BKE_world_copy(wrld); + wrld_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, wrld->id.lib, &wrld_new->id); - for (sce= bmain->scene.first; sce; sce= sce->id.next) { + for (sce = bmain->scene.first; sce; sce = sce->id.next) { if (sce->world == wrld) { - if (sce->id.lib==NULL) { - sce->world= wrld_new; + if (sce->id.lib == NULL) { + sce->world = wrld_new; wrld_new->id.us++; wrld->id.us--; } |