diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-28 10:31:57 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-28 10:31:57 +0400 |
commit | b340f930ec5639f24e7e2d47fab221fb752b61dd (patch) | |
tree | 0e880a36bb528d133af6d10701fc090716b3b7f8 /source/blender/editors/armature | |
parent | 09dc600839904a198ab4ba3fad62ce58c2d3aa07 (diff) |
style cleanup: changes to brace placement / newlines - for/while/if/switch
Diffstat (limited to 'source/blender/editors/armature')
-rw-r--r-- | source/blender/editors/armature/editarmature.c | 5 | ||||
-rw-r--r-- | source/blender/editors/armature/editarmature_generate.c | 48 | ||||
-rw-r--r-- | source/blender/editors/armature/editarmature_retarget.c | 834 | ||||
-rw-r--r-- | source/blender/editors/armature/editarmature_sketch.c | 738 | ||||
-rw-r--r-- | source/blender/editors/armature/poselib.c | 8 | ||||
-rw-r--r-- | source/blender/editors/armature/reeb.c | 793 |
6 files changed, 818 insertions, 1608 deletions
diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index cc3d0c6e184..c529ad66d73 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -2458,8 +2458,7 @@ void preEditBoneDuplicate(ListBase *editbones) EditBone *eBone; /* clear temp */ - for (eBone = editbones->first; eBone; eBone = eBone->next) - { + for (eBone = editbones->first; eBone; eBone = eBone->next) { eBone->temp = NULL; } } @@ -5800,7 +5799,7 @@ void generateSkeletonFromReebGraph(Scene *scene, ReebGraph *rg) /* Loop over subdivision methods */ for (i = 0; lastBone == NULL && i < SKGEN_SUB_TOTAL; i++) { - switch(scene->toolsettings->skgen_subdivisions[i]) { + switch (scene->toolsettings->skgen_subdivisions[i]) { case SKGEN_SUB_LENGTH: lastBone = test_subdivideByLength(scene, obedit, arc, head, tail); break; diff --git a/source/blender/editors/armature/editarmature_generate.c b/source/blender/editors/armature/editarmature_generate.c index 37d095221c9..5b56f5fe7fe 100644 --- a/source/blender/editors/armature/editarmature_generate.c +++ b/source/blender/editors/armature/editarmature_generate.c @@ -52,8 +52,7 @@ void setBoneRollFromNormal(EditBone *bone, float *no, float UNUSED(invmat[][4]), float tmat[][3]) { - if (no != NULL && !is_zero_v3(no)) - { + if (no != NULL && !is_zero_v3(no)) { float normal[3]; copy_v3_v3(normal, no); @@ -67,16 +66,14 @@ float calcArcCorrelation(BArcIterator *iter, int start, int end, float v0[3], fl { int len = 2 + abs(end - start); - if (len > 2) - { + if (len > 2) { float avg_t = 0.0f; float s_t = 0.0f; float s_xyz = 0.0f; int i; /* First pass, calculate average */ - for (i = start; i <= end; i++) - { + for (i = start; i <= end; i++) { float v[3]; IT_peek(iter, i); @@ -89,8 +86,7 @@ float calcArcCorrelation(BArcIterator *iter, int start, int end, float v0[3], fl avg_t /= len; /* Second pass, calculate s_xyz and s_t */ - for (i = start; i <= end; i++) - { + for (i = start; i <= end; i++) { float v[3], d[3]; float dt; @@ -110,8 +106,7 @@ float calcArcCorrelation(BArcIterator *iter, int start, int end, float v0[3], fl return 1.0f - s_xyz / s_t; } - else - { + else { return 1.0f; } } @@ -125,15 +120,13 @@ int nextFixedSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int sta float length_threshold; int i; - if (stroke_length == 0) - { + if (stroke_length == 0) { current_length = 0; IT_peek(iter, start); v1 = iter->p; - for (i = start + 1; i <= end; i++) - { + for (i = start + 1; i <= end; i++) { IT_peek(iter, i); v2 = iter->p; @@ -154,8 +147,7 @@ int nextFixedSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int sta v1 = iter->p; /* < and not <= because we don't care about end, it is P_EXACT anyway */ - for (i = start + 1; i < end; i++) - { + for (i = start + 1; i < end; i++) { IT_peek(iter, i); v2 = iter->p; @@ -183,8 +175,7 @@ int nextAdaptativeSubdivision(ToolSettings *toolsettings, BArcIterator *iter, in IT_peek(iter, start); start_p = iter->p; - for (i = start + 2; i <= end; i++) - { + for (i = start + 2; i <= end; i++) { /* Calculate normal */ IT_peek(iter, i); sub_v3_v3v3(n, iter->p, head); @@ -206,8 +197,7 @@ int nextLengthSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int st int i; i = start + 1; - while (i <= end) - { + while (i <= end) { float *vec0; float *vec1; @@ -218,10 +208,8 @@ int nextLengthSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int st vec1 = iter->p; /* If lengthLimit hits the current segment */ - if (len_v3v3(vec1, head) > lengthLimit) - { - if (same == 0) - { + if (len_v3v3(vec1, head) > lengthLimit) { + if (same == 0) { float dv[3], off[3]; float a, b, c, f; @@ -260,8 +248,7 @@ int nextLengthSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int st return i - 1; /* restart at lower bound */ } - else - { + else { i++; same = 0; // Reset same } @@ -286,16 +273,14 @@ EditBone * subdivideArcBy(ToolSettings *toolsettings, bArmature *arm, ListBase * parent = ED_armature_edit_bone_add(arm, "Bone"); copy_v3_v3(parent->head, iter->p); - if (iter->size > 0) - { + if (iter->size > 0) { parent->rad_head = iter->size * size_buffer; } normal = iter->no; index = next_subdividion(toolsettings, iter, bone_start, end, parent->head, parent->tail); - while (index != -1) - { + while (index != -1) { IT_peek(iter, index); child = ED_armature_edit_bone_add(arm, "Bone"); @@ -303,8 +288,7 @@ EditBone * subdivideArcBy(ToolSettings *toolsettings, bArmature *arm, ListBase * child->parent = parent; child->flag |= BONE_CONNECTED; - if (iter->size > 0) - { + if (iter->size > 0) { child->rad_head = iter->size * size_buffer; parent->rad_tail = iter->size * size_buffer; } diff --git a/source/blender/editors/armature/editarmature_retarget.c b/source/blender/editors/armature/editarmature_retarget.c index f554b7b1c50..7e4d76cb794 100644 --- a/source/blender/editors/armature/editarmature_retarget.c +++ b/source/blender/editors/armature/editarmature_retarget.c @@ -119,10 +119,8 @@ static int countEditBoneChildren(ListBase *list, EditBone *parent) EditBone *ebone; int count = 0; - for (ebone = list->first; ebone; ebone = ebone->next) - { - if (ebone->parent == parent) - { + for (ebone = list->first; ebone; ebone = ebone->next) { + if (ebone->parent == parent) { count++; } } @@ -134,12 +132,9 @@ static EditBone* nextEditBoneChild(ListBase *list, EditBone *parent, int n) { EditBone *ebone; - for (ebone = list->first; ebone; ebone = ebone->next) - { - if (ebone->parent == parent) - { - if (n == 0) - { + for (ebone = list->first; ebone; ebone = ebone->next) { + if (ebone->parent == parent) { + if (n == 0) { return ebone; } n--; @@ -175,23 +170,19 @@ static float rollBoneByQuatAligned(EditBone *bone, float old_up_axis[3], float q normalize_v3(x_axis); normalize_v3(z_axis); - if (dot_v3v3(new_up_axis, x_axis) < 0) - { + if (dot_v3v3(new_up_axis, x_axis) < 0) { negate_v3(x_axis); } - if (dot_v3v3(new_up_axis, z_axis) < 0) - { + if (dot_v3v3(new_up_axis, z_axis) < 0) { negate_v3(z_axis); } - if (angle_normalized_v3v3(x_axis, new_up_axis) < angle_normalized_v3v3(z_axis, new_up_axis)) - { + if (angle_normalized_v3v3(x_axis, new_up_axis) < angle_normalized_v3v3(z_axis, new_up_axis)) { rotation_between_vecs_to_quat(qroll, new_up_axis, x_axis); /* set roll rotation quat */ return ED_rollBoneToVector(bone, x_axis, FALSE); } - else - { + else { rotation_between_vecs_to_quat(qroll, new_up_axis, z_axis); /* set roll rotation quat */ return ED_rollBoneToVector(bone, z_axis, FALSE); } @@ -199,26 +190,21 @@ static float rollBoneByQuatAligned(EditBone *bone, float old_up_axis[3], float q static float rollBoneByQuatJoint(RigEdge *edge, RigEdge *previous, float qrot[4], float qroll[4], float up_axis[3]) { - if (previous == NULL) - { + if (previous == NULL) { /* default to up_axis if no previous */ return rollBoneByQuatAligned(edge->bone, edge->up_axis, qrot, qroll, up_axis); } - else - { + else { float new_up_axis[3]; float vec_first[3], vec_second[3], normal[3]; - if (previous->bone) - { + if (previous->bone) { sub_v3_v3v3(vec_first, previous->bone->tail, previous->bone->head); } - else if (previous->prev->bone) - { + else if (previous->prev->bone) { sub_v3_v3v3(vec_first, edge->bone->head, previous->prev->bone->tail); } - else - { + else { /* default to up_axis if first bone in the chain is an offset */ return rollBoneByQuatAligned(edge->bone, edge->up_axis, qrot, qroll, up_axis); } @@ -274,19 +260,16 @@ void RIG_freeRigGraph(BGraph *rg) BLI_destroy_worker(rigg->worker); #endif - if (rigg->link_mesh) - { + if (rigg->link_mesh) { REEB_freeGraph(rigg->link_mesh); } - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { RIG_freeRigArc(arc); } BLI_freelistN(&rg->arcs); - for (node = rg->nodes.first; node; node = node->next) - { + for (node = rg->nodes.first; node; node = node->next) { BLI_freeNode(rg, (BNode*)node); } BLI_freelistN(&rg->nodes); @@ -296,8 +279,7 @@ void RIG_freeRigGraph(BGraph *rg) BLI_ghash_free(rigg->bones_map, NULL, NULL); BLI_ghash_free(rigg->controls_map, NULL, NULL); - if (rigg->flag & RIG_FREE_BONELIST) - { + if (rigg->flag & RIG_FREE_BONELIST) { BLI_freelistN(rigg->editbones); MEM_freeN(rigg->editbones); } @@ -409,12 +391,10 @@ static void RIG_appendEdgeToArc(RigArc *arc, RigEdge *edge) { BLI_addtail(&arc->edges, edge); - if (edge->prev == NULL) - { + if (edge->prev == NULL) { copy_v3_v3(edge->head, arc->head->p); } - else - { + else { RigEdge *last_edge = edge->prev; copy_v3_v3(edge->head, last_edge->tail); RIG_calculateEdgeAngles(last_edge, edge); @@ -436,8 +416,7 @@ static void RIG_addEdgeToArc(RigArc *arc, float tail[3], EditBone *bone) copy_v3_v3(edge->tail, tail); edge->bone = bone; - if (bone) - { + if (bone) { getEditBoneRollUpAxis(bone, bone->roll, edge->up_axis); } @@ -449,28 +428,22 @@ static void renameTemplateBone(char *name, char *template_name, ListBase *editbo { int i, j; - for (i = 0, j = 0; i < (MAXBONENAME-1) && j < (MAXBONENAME-1) && template_name[i] != '\0'; i++) - { - if (template_name[i] == '&') - { - if (template_name[i+1] == 'S' || template_name[i+1] == 's') - { + for (i = 0, j = 0; i < (MAXBONENAME-1) && j < (MAXBONENAME-1) && template_name[i] != '\0'; i++) { + if (template_name[i] == '&') { + if (template_name[i+1] == 'S' || template_name[i+1] == 's') { j += sprintf(name + j, "%s", side_string); i++; } - else if (template_name[i+1] == 'N' || template_name[i+1] == 'n') - { + else if (template_name[i+1] == 'N' || template_name[i+1] == 'n') { j += sprintf(name + j, "%s", num_string); i++; } - else - { + else { name[j] = template_name[i]; j++; } } - else - { + else { name[j] = template_name[i]; j++; } @@ -524,8 +497,7 @@ static RigArc *cloneArc(RigGraph *rg, RigGraph *src_rg, RigArc *src_arc, GHash * arc->count = src_arc->count; - for (src_edge = src_arc->edges.first; src_edge; src_edge = src_edge->next) - { + for (src_edge = src_arc->edges.first; src_edge; src_edge = src_edge->next) { RigEdge *edge; edge = MEM_callocN(sizeof(RigEdge), "rig edge"); @@ -538,8 +510,7 @@ static RigArc *cloneArc(RigGraph *rg, RigGraph *src_rg, RigArc *src_arc, GHash * edge->angle = src_edge->angle; edge->up_angle = src_edge->up_angle; - if (src_edge->bone != NULL) - { + if (src_edge->bone != NULL) { char name[MAXBONENAME]; renameTemplateBone(name, src_edge->bone->name, rg->editbones, side_string, num_string); edge->bone = duplicateEditBoneObjects(src_edge->bone, name, rg->editbones, src_rg->ob, rg->ob); @@ -572,8 +543,7 @@ static RigGraph *cloneRigGraph(RigGraph *src, ListBase *editbones, Object *ob, c preEditBoneDuplicate(src->editbones); /* prime bones for duplication */ /* Clone nodes */ - for (node = src->nodes.first; node; node = node->next) - { + for (node = src->nodes.first; node; node = node->next) { RigNode *cloned_node = newRigNode(rg, node->p); BLI_ghash_insert(ptr_hash, node, cloned_node); } @@ -581,40 +551,32 @@ static RigGraph *cloneRigGraph(RigGraph *src, ListBase *editbones, Object *ob, c rg->head = BLI_ghash_lookup(ptr_hash, src->head); /* Clone arcs */ - for (arc = src->arcs.first; arc; arc = arc->next) - { + for (arc = src->arcs.first; arc; arc = arc->next) { cloneArc(rg, src, arc, ptr_hash, side_string, num_string); } /* Clone controls */ - for (ctrl = src->controls.first; ctrl; ctrl = ctrl->next) - { + for (ctrl = src->controls.first; ctrl; ctrl = ctrl->next) { cloneControl(rg, src, ctrl, ptr_hash, side_string, num_string); } /* Relink bones properly */ - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { RigEdge *edge; - for (edge = arc->edges.first; edge; edge = edge->next) - { - if (edge->bone != NULL) - { + for (edge = arc->edges.first; edge; edge = edge->next) { + if (edge->bone != NULL) { EditBone *bone; updateDuplicateSubtargetObjects(edge->bone, src->editbones, src->ob, rg->ob); - if (edge->bone->parent) - { + if (edge->bone->parent) { bone = BLI_ghash_lookup(ptr_hash, edge->bone->parent); - if (bone != NULL) - { + if (bone != NULL) { edge->bone->parent = bone; } - else - { + else { /* disconnect since parent isn't cloned * this will only happen when cloning from selected bones * */ @@ -625,22 +587,18 @@ static RigGraph *cloneRigGraph(RigGraph *src, ListBase *editbones, Object *ob, c } } - for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) - { + for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) { EditBone *bone; updateDuplicateSubtargetObjects(ctrl->bone, src->editbones, src->ob, rg->ob); - if (ctrl->bone->parent) - { + if (ctrl->bone->parent) { bone = BLI_ghash_lookup(ptr_hash, ctrl->bone->parent); - if (bone != NULL) - { + if (bone != NULL) { ctrl->bone->parent = bone; } - else - { + else { /* disconnect since parent isn't cloned * this will only happen when cloning from selected bones * */ @@ -672,8 +630,7 @@ static void RIG_calculateEdgeAngles(RigEdge *edge_first, RigEdge *edge_second) edge_first->angle = angle_normalized_v3v3(vec_first, vec_second); - if (edge_second->bone != NULL) - { + if (edge_second->bone != NULL) { float normal[3]; cross_v3_v3v3(normal, vec_first, vec_second); @@ -699,16 +656,14 @@ static void RIG_addControlBone(RigGraph *rg, EditBone *bone) static int RIG_parentControl(RigControl *ctrl, EditBone *link) { - if (link) - { + if (link) { float offset[3]; int flag = 0; sub_v3_v3v3(offset, ctrl->bone->head, link->head); /* if root matches, check for direction too */ - if (dot_v3v3(offset, offset) < 0.0001f) - { + if (dot_v3v3(offset, offset) < 0.0001f) { float vbone[3], vparent[3]; flag |= RIG_CTRL_FIT_ROOT; @@ -717,45 +672,38 @@ static int RIG_parentControl(RigControl *ctrl, EditBone *link) sub_v3_v3v3(vparent, link->tail, link->head); /* test for opposite direction */ - if (dot_v3v3(vbone, vparent) > 0) - { + if (dot_v3v3(vbone, vparent) > 0) { float nor[3]; float len; cross_v3_v3v3(nor, vbone, vparent); len = dot_v3v3(nor, nor); - if (len < 0.0001f) - { + if (len < 0.0001f) { flag |= RIG_CTRL_FIT_BONE; } } } /* Bail out if old one is automatically better */ - if (flag < ctrl->flag) - { + if (flag < ctrl->flag) { return 0; } /* if there's already a link * overwrite only if new link is higher in the chain */ - if (ctrl->link && flag == ctrl->flag) - { + if (ctrl->link && flag == ctrl->flag) { EditBone *bone = NULL; - for (bone = ctrl->link; bone; bone = bone->parent) - { + for (bone = ctrl->link; bone; bone = bone->parent) { /* if link is in the chain, break and use that one */ - if (bone == link) - { + if (bone == link) { break; } } /* not in chain, don't update link */ - if (bone == NULL) - { + if (bone == NULL) { return 0; } } @@ -778,43 +726,34 @@ static void RIG_reconnectControlBones(RigGraph *rg) int change = 1; /* first pass, link to deform bones */ - for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) - { + for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) { bPoseChannel *pchan; bConstraint *con; int found = 0; /* DO SOME MAGIC HERE */ - for (pchan= rg->ob->pose->chanbase.first; pchan; pchan= pchan->next) - { - for (con= pchan->constraints.first; con; con= con->next) - { + for (pchan= rg->ob->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; /* constraint targets */ - if (cti && cti->get_constraint_targets) - { + if (cti && cti->get_constraint_targets) { int target_index; cti->get_constraint_targets(con, &targets); - for (target_index = 0, ct= targets.first; ct; target_index++, ct= ct->next) - { - if ((ct->tar == rg->ob) && strcmp(ct->subtarget, ctrl->bone->name) == 0) - { + for (target_index = 0, ct= targets.first; ct; target_index++, ct= ct->next) { + if ((ct->tar == rg->ob) && strcmp(ct->subtarget, ctrl->bone->name) == 0) { /* SET bone link to bone corresponding to pchan */ EditBone *link = BLI_ghash_lookup(rg->bones_map, pchan->name); /* Making sure bone is in this armature */ - if (link != NULL) - { + if (link != NULL) { /* for pole targets, link to parent bone instead, if possible */ - if (con->type == CONSTRAINT_TYPE_KINEMATIC && target_index == 1) - { - if (link->parent && BLI_ghash_haskey(rg->bones_map, link->parent->name)) - { + if (con->type == CONSTRAINT_TYPE_KINEMATIC && target_index == 1) { + if (link->parent && BLI_ghash_haskey(rg->bones_map, link->parent->name)) { link = link->parent; } } @@ -831,10 +770,8 @@ static void RIG_reconnectControlBones(RigGraph *rg) } /* if not found yet, check parent */ - if (found == 0) - { - if (ctrl->bone->parent) - { + if (found == 0) { + if (ctrl->bone->parent) { /* make sure parent is a deforming bone * NULL if not * */ @@ -849,24 +786,19 @@ static void RIG_reconnectControlBones(RigGraph *rg) RigArc *best_arc = NULL; EditBone *link = NULL; - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { RigEdge *edge; - for (edge = arc->edges.first; edge; edge = edge->next) - { - if (edge->bone) - { + for (edge = arc->edges.first; edge; edge = edge->next) { + if (edge->bone) { int fit = 0; fit = len_v3v3(ctrl->bone->head, edge->bone->head) < 0.0001f; fit = fit || len_v3v3(ctrl->bone->tail, edge->bone->tail) < 0.0001f; - if (fit) - { + if (fit) { /* pick the bone on the arc with the lowest symmetry level * means you connect control to the trunk of the skeleton */ - if (best_arc == NULL || arc->symmetry_level < best_arc->symmetry_level) - { + if (best_arc == NULL || arc->symmetry_level < best_arc->symmetry_level) { best_arc = arc; link = edge->bone; } @@ -880,23 +812,18 @@ static void RIG_reconnectControlBones(RigGraph *rg) } /* if not found yet, check child */ - if (found == 0) - { + if (found == 0) { RigArc *arc; RigArc *best_arc = NULL; EditBone *link = NULL; - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { RigEdge *edge; - for (edge = arc->edges.first; edge; edge = edge->next) - { - if (edge->bone && edge->bone->parent == ctrl->bone) - { + for (edge = arc->edges.first; edge; edge = edge->next) { + if (edge->bone && edge->bone->parent == ctrl->bone) { /* pick the bone on the arc with the lowest symmetry level * means you connect control to the trunk of the skeleton */ - if (best_arc == NULL || arc->symmetry_level < best_arc->symmetry_level) - { + if (best_arc == NULL || arc->symmetry_level < best_arc->symmetry_level) { best_arc = arc; link = edge->bone; } @@ -911,52 +838,42 @@ static void RIG_reconnectControlBones(RigGraph *rg) /* second pass, make chains in control bones */ - while (change) - { + while (change) { change = 0; - for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) - { + for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) { /* if control is not linked yet */ - if (ctrl->link == NULL) - { + if (ctrl->link == NULL) { bPoseChannel *pchan; bConstraint *con; RigControl *ctrl_parent = NULL; RigControl *ctrl_child; int found = 0; - if (ctrl->bone->parent) - { + if (ctrl->bone->parent) { ctrl_parent = BLI_ghash_lookup(rg->controls_map, ctrl->bone->parent->name); } /* check constraints first */ /* DO SOME MAGIC HERE */ - for (pchan= rg->ob->pose->chanbase.first; pchan; pchan= pchan->next) - { - for (con= pchan->constraints.first; con; con= con->next) - { + for (pchan= rg->ob->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; /* constraint targets */ - if (cti && cti->get_constraint_targets) - { + if (cti && cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); - for (ct= targets.first; ct; ct= ct->next) - { - if ((ct->tar == rg->ob) && strcmp(ct->subtarget, ctrl->bone->name) == 0) - { + for (ct= targets.first; ct; ct= ct->next) { + if ((ct->tar == rg->ob) && strcmp(ct->subtarget, ctrl->bone->name) == 0) { /* SET bone link to ctrl corresponding to pchan */ RigControl *link = BLI_ghash_lookup(rg->controls_map, pchan->name); /* if owner is a control bone, link with it */ - if (link && link->link) - { + if (link && link->link) { RIG_parentControl(ctrl, link->bone); found = 1; break; @@ -970,22 +887,17 @@ static void RIG_reconnectControlBones(RigGraph *rg) } } - if (found == 0) - { + if (found == 0) { /* check if parent is already linked */ - if (ctrl_parent && ctrl_parent->link) - { + if (ctrl_parent && ctrl_parent->link) { RIG_parentControl(ctrl, ctrl_parent->bone); change = 1; } - else - { + else { /* check childs */ - for (ctrl_child = rg->controls.first; ctrl_child; ctrl_child = ctrl_child->next) - { + for (ctrl_child = rg->controls.first; ctrl_child; ctrl_child = ctrl_child->next) { /* if a child is linked, link to that one */ - if (ctrl_child->link && ctrl_child->bone->parent == ctrl->bone) - { + if (ctrl_child->link && ctrl_child->bone->parent == ctrl->bone) { RIG_parentControl(ctrl, ctrl_child->bone); change = 1; break; @@ -998,31 +910,25 @@ static void RIG_reconnectControlBones(RigGraph *rg) } /* third pass, link control tails */ - for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) - { + for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) { /* fit bone already means full match, so skip those */ - if ((ctrl->flag & RIG_CTRL_FIT_BONE) == 0) - { + if ((ctrl->flag & RIG_CTRL_FIT_BONE) == 0) { GHashIterator ghi; /* look on deform bones first */ BLI_ghashIterator_init(&ghi, rg->bones_map); - for ( ; !BLI_ghashIterator_isDone(&ghi); BLI_ghashIterator_step(&ghi)) - { + for ( ; !BLI_ghashIterator_isDone(&ghi); BLI_ghashIterator_step(&ghi)) { EditBone *bone = (EditBone*)BLI_ghashIterator_getValue(&ghi); /* don't link with parent */ - if (bone->parent != ctrl->bone) - { - if (len_v3v3(ctrl->bone->tail, bone->head) < 0.01f) - { + if (bone->parent != ctrl->bone) { + if (len_v3v3(ctrl->bone->tail, bone->head) < 0.01f) { ctrl->tail_mode = TL_HEAD; ctrl->link_tail = bone; break; } - else if (len_v3v3(ctrl->bone->tail, bone->tail) < 0.01f) - { + else if (len_v3v3(ctrl->bone->tail, bone->tail) < 0.01f) { ctrl->tail_mode = TL_TAIL; ctrl->link_tail = bone; break; @@ -1031,8 +937,7 @@ static void RIG_reconnectControlBones(RigGraph *rg) } /* if we haven't found one yet, look in control bones */ - if (ctrl->tail_mode == TL_NONE) - { + if (ctrl->tail_mode == TL_NONE) { } } } @@ -1046,21 +951,18 @@ static void RIG_joinArcs(RigGraph *rg, RigNode *node, RigArc *joined_arc1, RigAr RigEdge *edge, *next_edge; /* ignore cases where joint is at start or end */ - if (joined_arc1->head == joined_arc2->head || joined_arc1->tail == joined_arc2->tail) - { + if (joined_arc1->head == joined_arc2->head || joined_arc1->tail == joined_arc2->tail) { return; } /* swap arcs to make sure arc1 is before arc2 */ - if (joined_arc1->head == joined_arc2->tail) - { + if (joined_arc1->head == joined_arc2->tail) { RigArc *tmp = joined_arc1; joined_arc1 = joined_arc2; joined_arc2 = tmp; } - for (edge = joined_arc2->edges.first; edge; edge = next_edge) - { + for (edge = joined_arc2->edges.first; edge; edge = next_edge) { next_edge = edge->next; RIG_appendEdgeToArc(joined_arc1, edge); @@ -1079,24 +981,18 @@ static void RIG_removeNormalNodes(RigGraph *rg) { RigNode *node, *next_node; - for (node = rg->nodes.first; node; node = next_node) - { + for (node = rg->nodes.first; node; node = next_node) { next_node = node->next; - if (node->degree == 2) - { + if (node->degree == 2) { RigArc *arc, *joined_arc1 = NULL, *joined_arc2 = NULL; - for (arc = rg->arcs.first; arc; arc = arc->next) - { - if (arc->head == node || arc->tail == node) - { - if (joined_arc1 == NULL) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { + if (arc->head == node || arc->tail == node) { + if (joined_arc1 == NULL) { joined_arc1 = arc; } - else - { + else { joined_arc2 = arc; break; } @@ -1112,36 +1008,29 @@ static void RIG_removeUneededOffsets(RigGraph *rg) { RigArc *arc; - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { RigEdge *first_edge, *last_edge; first_edge = arc->edges.first; last_edge = arc->edges.last; - if (first_edge->bone == NULL) - { - if (first_edge->bone == NULL && len_v3v3(first_edge->tail, arc->head->p) <= 0.001f) - { + if (first_edge->bone == NULL) { + if (first_edge->bone == NULL && len_v3v3(first_edge->tail, arc->head->p) <= 0.001f) { BLI_remlink(&arc->edges, first_edge); MEM_freeN(first_edge); } - else if (arc->head->degree == 1) - { + else if (arc->head->degree == 1) { RigNode *new_node = (RigNode*)BLI_FindNodeByPosition((BGraph*)rg, first_edge->tail, 0.001f); - if (new_node) - { + if (new_node) { BLI_remlink(&arc->edges, first_edge); MEM_freeN(first_edge); BLI_replaceNodeInArc((BGraph*)rg, (BArc*)arc, (BNode*)new_node, (BNode*)arc->head); } - else - { + else { RigEdge *next_edge = first_edge->next; - if (next_edge) - { + if (next_edge) { BLI_remlink(&arc->edges, first_edge); MEM_freeN(first_edge); @@ -1149,57 +1038,44 @@ static void RIG_removeUneededOffsets(RigGraph *rg) } } } - else - { + else { /* check if all arc connected start with a null edge */ RigArc *other_arc; - for (other_arc = rg->arcs.first; other_arc; other_arc = other_arc->next) - { - if (other_arc != arc) - { + for (other_arc = rg->arcs.first; other_arc; other_arc = other_arc->next) { + if (other_arc != arc) { RigEdge *test_edge; - if (other_arc->head == arc->head) - { + if (other_arc->head == arc->head) { test_edge = other_arc->edges.first; - if (test_edge->bone != NULL) - { + if (test_edge->bone != NULL) { break; } } - else if (other_arc->tail == arc->head) - { + else if (other_arc->tail == arc->head) { test_edge = other_arc->edges.last; - if (test_edge->bone != NULL) - { + if (test_edge->bone != NULL) { break; } } } } - if (other_arc == NULL) - { + if (other_arc == NULL) { RigNode *new_node = (RigNode*)BLI_FindNodeByPosition((BGraph*)rg, first_edge->tail, 0.001); - if (new_node) - { + if (new_node) { /* remove null edge in other arcs too */ - for (other_arc = rg->arcs.first; other_arc; other_arc = other_arc->next) - { - if (other_arc != arc) - { + for (other_arc = rg->arcs.first; other_arc; other_arc = other_arc->next) { + if (other_arc != arc) { RigEdge *test_edge; - if (other_arc->head == arc->head) - { + if (other_arc->head == arc->head) { BLI_replaceNodeInArc((BGraph*)rg, (BArc*)other_arc, (BNode*)new_node, (BNode*)other_arc->head); test_edge = other_arc->edges.first; BLI_remlink(&other_arc->edges, test_edge); MEM_freeN(test_edge); } - else if (other_arc->tail == arc->head) - { + else if (other_arc->tail == arc->head) { BLI_replaceNodeInArc((BGraph*)rg, (BArc*)other_arc, (BNode*)new_node, (BNode*)other_arc->tail); test_edge = other_arc->edges.last; BLI_remlink(&other_arc->edges, test_edge); @@ -1212,31 +1088,25 @@ static void RIG_removeUneededOffsets(RigGraph *rg) MEM_freeN(first_edge); BLI_replaceNodeInArc((BGraph*)rg, (BArc*)arc, (BNode*)new_node, (BNode*)arc->head); } - else - { + else { RigEdge *next_edge = first_edge->next; - if (next_edge) - { + if (next_edge) { BLI_remlink(&arc->edges, first_edge); MEM_freeN(first_edge); copy_v3_v3(arc->head->p, next_edge->head); /* remove null edge in other arcs too */ - for (other_arc = rg->arcs.first; other_arc; other_arc = other_arc->next) - { - if (other_arc != arc) - { + for (other_arc = rg->arcs.first; other_arc; other_arc = other_arc->next) { + if (other_arc != arc) { RigEdge *test_edge; - if (other_arc->head == arc->head) - { + if (other_arc->head == arc->head) { test_edge = other_arc->edges.first; BLI_remlink(&other_arc->edges, test_edge); MEM_freeN(test_edge); } - else if (other_arc->tail == arc->head) - { + else if (other_arc->tail == arc->head) { test_edge = other_arc->edges.last; BLI_remlink(&other_arc->edges, test_edge); MEM_freeN(test_edge); @@ -1249,19 +1119,15 @@ static void RIG_removeUneededOffsets(RigGraph *rg) } } - if (last_edge->bone == NULL) - { - if (len_v3v3(last_edge->head, arc->tail->p) <= 0.001f) - { + if (last_edge->bone == NULL) { + if (len_v3v3(last_edge->head, arc->tail->p) <= 0.001f) { BLI_remlink(&arc->edges, last_edge); MEM_freeN(last_edge); } - else if (arc->tail->degree == 1) - { + else if (arc->tail->degree == 1) { RigNode *new_node = (RigNode*)BLI_FindNodeByPosition((BGraph*)rg, last_edge->head, 0.001f); - if (new_node) - { + if (new_node) { RigEdge *previous_edge = last_edge->prev; BLI_remlink(&arc->edges, last_edge); @@ -1269,17 +1135,14 @@ static void RIG_removeUneededOffsets(RigGraph *rg) BLI_replaceNodeInArc((BGraph*)rg, (BArc*)arc, (BNode*)new_node, (BNode*)arc->tail); /* set previous angle to 0, since there's no following edges */ - if (previous_edge) - { + if (previous_edge) { previous_edge->angle = 0; } } - else - { + else { RigEdge *previous_edge = last_edge->prev; - if (previous_edge) - { + if (previous_edge) { BLI_remlink(&arc->edges, last_edge); MEM_freeN(last_edge); @@ -1298,32 +1161,25 @@ static void RIG_arcFromBoneChain(RigGraph *rg, ListBase *list, EditBone *root_bo RigArc *arc = NULL; int contain_head = 0; - for (bone = root_bone; bone; bone = nextEditBoneChild(list, bone, 0)) - { + for (bone = root_bone; bone; bone = nextEditBoneChild(list, bone, 0)) { int nb_children; - if (selected == 0 || (bone->flag & BONE_SELECTED)) - { - if ((bone->flag & BONE_NO_DEFORM) == 0) - { + if (selected == 0 || (bone->flag & BONE_SELECTED)) { + if ((bone->flag & BONE_NO_DEFORM) == 0) { BLI_ghash_insert(rg->bones_map, bone->name, bone); - if (arc == NULL) - { + if (arc == NULL) { arc = newRigArc(rg); - if (starting_node == NULL) - { + if (starting_node == NULL) { starting_node = newRigNodeHead(rg, arc, root_bone->head); } - else - { + else { addRigNodeHead(rg, arc, starting_node); } } - if (bone->parent && (bone->flag & BONE_CONNECTED) == 0) - { + if (bone->parent && (bone->flag & BONE_CONNECTED) == 0) { RIG_addEdgeToArc(arc, bone->head, NULL); } @@ -1331,34 +1187,28 @@ static void RIG_arcFromBoneChain(RigGraph *rg, ListBase *list, EditBone *root_bo last_bone = bone; - if (strcmp(bone->name, "head") == 0) - { + if (strcmp(bone->name, "head") == 0) { contain_head = 1; } } - else if ((bone->flag & BONE_EDITMODE_LOCKED) == 0) /* ignore locked bones */ - { + else if ((bone->flag & BONE_EDITMODE_LOCKED) == 0) { /* ignore locked bones */ RIG_addControlBone(rg, bone); } } nb_children = countEditBoneChildren(list, bone); - if (nb_children > 1) - { + if (nb_children > 1) { RigNode *end_node = NULL; int i; - if (arc != NULL) - { + if (arc != NULL) { end_node = newRigNodeTail(rg, arc, bone->tail); } - else - { + else { end_node = newRigNode(rg, bone->tail); } - for (i = 0; i < nb_children; i++) - { + for (i = 0; i < nb_children; i++) { root_bone = nextEditBoneChild(list, bone, i); RIG_arcFromBoneChain(rg, list, root_bone, end_node, selected); } @@ -1369,13 +1219,11 @@ static void RIG_arcFromBoneChain(RigGraph *rg, ListBase *list, EditBone *root_bo } /* If the loop exited without forking */ - if (arc != NULL && bone == NULL) - { + if (arc != NULL && bone == NULL) { newRigNodeTail(rg, arc, last_bone->tail); } - if (contain_head) - { + if (contain_head) { rg->head = arc->tail; } } @@ -1383,32 +1231,26 @@ static void RIG_arcFromBoneChain(RigGraph *rg, ListBase *list, EditBone *root_bo /*******************************************************************************************************/ static void RIG_findHead(RigGraph *rg) { - if (rg->head == NULL) - { - if (BLI_countlist(&rg->arcs) == 1) - { + if (rg->head == NULL) { + if (BLI_countlist(&rg->arcs) == 1) { RigArc *arc = rg->arcs.first; rg->head = (RigNode*)arc->head; } - else - { + else { RigArc *arc; - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { RigEdge *edge = arc->edges.last; - if (edge->bone->flag & (BONE_TIPSEL|BONE_SELECTED)) - { + if (edge->bone->flag & (BONE_TIPSEL|BONE_SELECTED)) { rg->head = arc->tail; break; } } } - if (rg->head == NULL) - { + if (rg->head == NULL) { rg->head = rg->nodes.first; } } @@ -1420,8 +1262,7 @@ static void RIG_printNode(RigNode *node, const char name[]) { printf("%s %p %i <%0.3f, %0.3f, %0.3f>\n", name, (void *)node, node->degree, node->p[0], node->p[1], node->p[2]); - if (node->symmetry_flag & SYM_TOPOLOGICAL) - { + if (node->symmetry_flag & SYM_TOPOLOGICAL) { if (node->symmetry_flag & SYM_AXIAL) printf("Symmetry AXIAL\n"); else if (node->symmetry_flag & SYM_RADIAL) @@ -1435,8 +1276,7 @@ void RIG_printArcBones(RigArc *arc) { RigEdge *edge; - for (edge = arc->edges.first; edge; edge = edge->next) - { + for (edge = arc->edges.first; edge; edge = edge->next) { if (edge->bone) printf("%s ", edge->bone->name); else @@ -1465,17 +1305,14 @@ static void RIG_printLinkedCtrl(RigGraph *rg, EditBone *bone, int tabs) char *s = indent; int i; - for (i = 0; i < tabs; i++) - { + for (i = 0; i < tabs; i++) { s[0] = '\t'; s++; } s[0] = 0; - for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) - { - if (ctrl->link == bone) - { + for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) { + if (ctrl->link == bone) { RIG_printCtrl(ctrl, indent); RIG_printLinkedCtrl(rg, ctrl->bone, tabs + 1); } @@ -1488,13 +1325,11 @@ void RIG_printArc(RigGraph *rg, RigArc *arc) RIG_printNode((RigNode*)arc->head, "head"); - for (edge = arc->edges.first; edge; edge = edge->next) - { + for (edge = arc->edges.first; edge; edge = edge->next) { printf("\tinner joints %0.3f %0.3f %0.3f\n", edge->tail[0], edge->tail[1], edge->tail[2]); printf("\t\tlength %f\n", edge->length); printf("\t\tangle %f\n", edge->angle * 180 / M_PI); - if (edge->bone) - { + if (edge->bone) { printf("\t\t%s\n", edge->bone->name); RIG_printLinkedCtrl(rg, edge->bone, 3); } @@ -1509,18 +1344,15 @@ void RIG_printGraph(RigGraph *rg) RigArc *arc; printf("---- ARCS ----\n"); - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { RIG_printArc(rg, arc); printf("\n"); } - if (rg->head) - { + if (rg->head) { RIG_printNode(rg->head, "HEAD NODE:"); } - else - { + else { printf("HEAD NODE: NONE\n"); } } @@ -1536,12 +1368,10 @@ RigGraph *RIG_graphFromArmature(const bContext *C, Object *ob, bArmature *arm) rg = newRigGraph(); - if (obedit == ob) - { + if (obedit == ob) { rg->editbones = ((bArmature *)obedit->data)->edbo; } - else - { + else { rg->editbones = MEM_callocN(sizeof(ListBase), "EditBones"); make_boneList(rg->editbones, &arm->bonebase, NULL, NULL); rg->flag |= RIG_FREE_BONELIST; @@ -1551,8 +1381,7 @@ RigGraph *RIG_graphFromArmature(const bContext *C, Object *ob, bArmature *arm) /* Do the rotations */ for (ebone = rg->editbones->first; ebone; ebone=ebone->next) { - if (ebone->parent == NULL) - { + if (ebone->parent == NULL) { RIG_arcFromBoneChain(rg, rg->editbones, ebone, NULL, 0); } } @@ -1571,8 +1400,7 @@ RigGraph *RIG_graphFromArmature(const bContext *C, Object *ob, bArmature *arm) RIG_reconnectControlBones(rg); /* after symmetry, because we use levels to find best match */ - if (BLI_isGraphCyclic((BGraph*)rg)) - { + if (BLI_isGraphCyclic((BGraph*)rg)) { printf("armature cyclic\n"); } @@ -1588,12 +1416,10 @@ static RigGraph *armatureSelectedToGraph(bContext *C, Object *ob, bArmature *arm rg = newRigGraph(); - if (obedit == ob) - { + if (obedit == ob) { rg->editbones = arm->edbo; } - else - { + else { rg->editbones = MEM_callocN(sizeof(ListBase), "EditBones"); make_boneList(rg->editbones, &arm->bonebase, NULL, NULL); rg->flag |= RIG_FREE_BONELIST; @@ -1603,8 +1429,7 @@ static RigGraph *armatureSelectedToGraph(bContext *C, Object *ob, bArmature *arm /* Do the rotations */ for (ebone = rg->editbones->first; ebone; ebone=ebone->next) { - if (ebone->parent == NULL) - { + if (ebone->parent == NULL) { RIG_arcFromBoneChain(rg, rg->editbones, ebone, NULL, 1); } } @@ -1623,8 +1448,7 @@ static RigGraph *armatureSelectedToGraph(bContext *C, Object *ob, bArmature *arm RIG_reconnectControlBones(rg); /* after symmetry, because we use levels to find best match */ - if (BLI_isGraphCyclic((BGraph*)rg)) - { + if (BLI_isGraphCyclic((BGraph*)rg)) { printf("armature cyclic\n"); } @@ -1721,8 +1545,7 @@ static void repositionTailControl(RigGraph *rigg, RigControl *ctrl); static void finalizeControl(RigGraph *rigg, RigControl *ctrl, float resize) { - if ((ctrl->flag & RIG_CTRL_DONE) == RIG_CTRL_DONE) - { + if ((ctrl->flag & RIG_CTRL_DONE) == RIG_CTRL_DONE) { RigControl *ctrl_child; #if 0 @@ -1737,17 +1560,14 @@ static void finalizeControl(RigGraph *rigg, RigControl *ctrl, float resize) #endif /* if there was a tail link: apply link, recalc resize factor and qrot */ - if (ctrl->tail_mode != TL_NONE) - { + if (ctrl->tail_mode != TL_NONE) { float *tail_vec = NULL; float v1[3], v2[3], qtail[4]; - if (ctrl->tail_mode == TL_TAIL) - { + if (ctrl->tail_mode == TL_TAIL) { tail_vec = ctrl->link_tail->tail; } - else if (ctrl->tail_mode == TL_HEAD) - { + else if (ctrl->tail_mode == TL_HEAD) { tail_vec = ctrl->link_tail->head; } @@ -1765,14 +1585,11 @@ static void finalizeControl(RigGraph *rigg, RigControl *ctrl, float resize) ctrl->bone->roll = rollBoneByQuat(ctrl->bone, ctrl->up_axis, ctrl->qrot); /* Cascade to connected control bones */ - for (ctrl_child = rigg->controls.first; ctrl_child; ctrl_child = ctrl_child->next) - { - if (ctrl_child->link == ctrl->bone) - { + for (ctrl_child = rigg->controls.first; ctrl_child; ctrl_child = ctrl_child->next) { + if (ctrl_child->link == ctrl->bone) { repositionControl(rigg, ctrl_child, ctrl->bone->head, ctrl->bone->tail, ctrl->qrot, resize); } - if (ctrl_child->link_tail == ctrl->bone) - { + if (ctrl_child->link_tail == ctrl->bone) { repositionTailControl(rigg, ctrl_child); } } @@ -1800,8 +1617,7 @@ static void repositionControl(RigGraph *rigg, RigControl *ctrl, float head[3], f copy_qt_qt(ctrl->qrot, qrot); - if (ctrl->tail_mode == TL_NONE) - { + if (ctrl->tail_mode == TL_NONE) { sub_v3_v3v3(tail_offset, ctrl->tail, ctrl->head); mul_v3_fl(tail_offset, resize); mul_qt_v3(qrot, tail_offset); @@ -1838,38 +1654,30 @@ static void repositionBone(bContext *C, RigGraph *rigg, RigEdge *edge, float vec copy_v3_v3(bone->head, vec0); copy_v3_v3(bone->tail, vec1); - if (!is_zero_v3(up_axis)) - { + if (!is_zero_v3(up_axis)) { float qroll[4]; - if (scene->toolsettings->skgen_retarget_roll == SK_RETARGET_ROLL_VIEW) - { + if (scene->toolsettings->skgen_retarget_roll == SK_RETARGET_ROLL_VIEW) { bone->roll = rollBoneByQuatAligned(bone, edge->up_axis, qrot, qroll, up_axis); } - else if (scene->toolsettings->skgen_retarget_roll == SK_RETARGET_ROLL_JOINT) - { + else if (scene->toolsettings->skgen_retarget_roll == SK_RETARGET_ROLL_JOINT) { bone->roll = rollBoneByQuatJoint(edge, edge->prev, qrot, qroll, up_axis); } - else - { + else { unit_qt(qroll); } mul_qt_qtqt(qrot, qroll, qrot); } - else - { + else { bone->roll = rollBoneByQuat(bone, edge->up_axis, qrot); } - for (ctrl = rigg->controls.first; ctrl; ctrl = ctrl->next) - { - if (ctrl->link == bone) - { + for (ctrl = rigg->controls.first; ctrl; ctrl = ctrl->next) { + if (ctrl->link == bone) { repositionControl(rigg, ctrl, vec0, vec1, qrot, resize); } - if (ctrl->link_tail == bone) - { + if (ctrl->link_tail == bone) { repositionTailControl(rigg, ctrl); } } @@ -1890,8 +1698,7 @@ static RetargetMode detectArcRetargetMode(RigArc *iarc) int nb_edges = 0; - for (edge = iarc->edges.first; edge; edge = edge->next) - { + for (edge = iarc->edges.first; edge; edge = edge->next) { avg_angle += edge->angle; nb_edges++; } @@ -1901,29 +1708,23 @@ static RetargetMode detectArcRetargetMode(RigArc *iarc) /* avg_length = iarc->length / nb_edges; */ /* UNUSED */ - if (nb_edges > 2) - { - for (edge = iarc->edges.first; edge; edge = edge->next) - { - if (fabs(edge->angle - avg_angle) > M_PI / 6) - { + if (nb_edges > 2) { + for (edge = iarc->edges.first; edge; edge = edge->next) { + if (fabs(edge->angle - avg_angle) > M_PI / 6) { large_angle = 1; } } } - else if (nb_edges == 2 && avg_angle > 0) - { + else if (nb_edges == 2 && avg_angle > 0) { large_angle = 1; } - if (large_angle == 0) - { + if (large_angle == 0) { mode = RETARGET_LENGTH; } - if (earc->bcount <= (iarc->count - 1)) - { + if (earc->bcount <= (iarc->count - 1)) { mode = RETARGET_LENGTH; } @@ -1936,8 +1737,7 @@ static void printMovesNeeded(int *positions, int nb_positions) int moves = 0; int i; - for (i = 0; i < nb_positions; i++) - { + for (i = 0; i < nb_positions; i++) { moves += positions[i] - (i + 1); } @@ -1948,8 +1748,7 @@ static void printPositions(int *positions, int nb_positions) { int i; - for (i = 0; i < nb_positions; i++) - { + for (i = 0; i < nb_positions; i++) { printf("%i ", positions[i]); } printf("\n"); @@ -1965,17 +1764,14 @@ static float costDistance(BArcIterator *iter, float *vec0, float *vec1, int i0, float v1[3], v2[3], c[3]; float v1_inpf; - if (distance_weight > 0) - { + if (distance_weight > 0) { sub_v3_v3v3(v1, vec0, vec1); v1_inpf = dot_v3v3(v1, v1); - if (v1_inpf > 0) - { + if (v1_inpf > 0) { int j; - for (j = i0 + 1; j < i1 - 1; j++) - { + for (j = i0 + 1; j < i1 - 1; j++) { float dist; bucket = IT_peek(iter, j); @@ -1991,48 +1787,40 @@ static float costDistance(BArcIterator *iter, float *vec0, float *vec1, int i0, return distance_weight * max_dist; } - else - { + else { return MAX_COST; } } - else - { + else { return 0; } } static float costAngle(float original_angle, float vec_first[3], float vec_second[3], float angle_weight) { - if (angle_weight > 0) - { + if (angle_weight > 0) { float current_angle; - if (!is_zero_v3(vec_first) && !is_zero_v3(vec_second)) - { + if (!is_zero_v3(vec_first) && !is_zero_v3(vec_second)) { current_angle = saacos(dot_v3v3(vec_first, vec_second)); return angle_weight * fabsf(current_angle - original_angle); } - else - { + else { return angle_weight * (float)M_PI; } } - else - { + else { return 0; } } static float costLength(float original_length, float current_length, float length_weight) { - if (current_length == 0) - { + if (current_length == 0) { return MAX_COST; } - else - { + else { float length_ratio = fabs((current_length - original_length) / original_length); return length_weight * length_ratio * length_ratio; } @@ -2062,8 +1850,7 @@ static float calcCostAngleLengthDistance(BArcIterator *iter, float **UNUSED(vec_ /* Angle cost */ - if (edge->prev) - { + if (edge->prev) { sub_v3_v3v3(vec_first, vec1, vec0); normalize_v3(vec_first); @@ -2089,8 +1876,7 @@ static void copyMemoPositions(int *positions, MemoNode *table, int nb_positions, int previous = 0, current = 0; int i = 0; - for (i = 0; joints_left > 0; joints_left--, i++) - { + for (i = 0; joints_left > 0; joints_left--, i++) { MemoNode *node; node = table + indexMemoNode(nb_positions, previous, current, joints_left); @@ -2108,12 +1894,10 @@ static MemoNode * solveJoints(MemoNode *table, BArcIterator *iter, float **vec_c node = table + index; - if (node->weight != 0) - { + if (node->weight != 0) { return node; } - else if (joints_left == 0) - { + else if (joints_left == 0) { float *vec0 = vec_cache[previous]; float *vec1 = vec_cache[current]; float *vec2 = vec_cache[nb_positions + 1]; @@ -2122,8 +1906,7 @@ static MemoNode * solveJoints(MemoNode *table, BArcIterator *iter, float **vec_c return node; } - else - { + else { MemoNode *min_node = NULL; float *vec0 = vec_cache[previous]; float *vec1 = vec_cache[current]; @@ -2131,8 +1914,7 @@ static MemoNode * solveJoints(MemoNode *table, BArcIterator *iter, float **vec_c int min_next= 0; int next; - for (next = current + 1; next <= nb_positions - (joints_left - 1); next++) - { + for (next = current + 1; next <= nb_positions - (joints_left - 1); next++) { MemoNode *next_node; float *vec2 = vec_cache[next]; float weight = 0.0f; @@ -2140,8 +1922,7 @@ static MemoNode * solveJoints(MemoNode *table, BArcIterator *iter, float **vec_c /* ADD WEIGHT OF PREVIOUS - CURRENT - NEXT triple */ weight = calcCostAngleLengthDistance(iter, vec_cache, edge, vec0, vec1, vec2, current, next, angle_weight, length_weight, distance_weight); - if (weight >= MAX_COST) - { + if (weight >= MAX_COST) { continue; } @@ -2149,22 +1930,19 @@ static MemoNode * solveJoints(MemoNode *table, BArcIterator *iter, float **vec_c next_node = solveJoints(table, iter, vec_cache, nb_joints, nb_positions, current, next, edge->next, joints_left - 1, angle_weight, length_weight, distance_weight); weight += next_node->weight; - if (min_node == NULL || weight < min_weight) - { + if (min_node == NULL || weight < min_weight) { min_weight = weight; min_node = next_node; min_next = next; } } - if (min_node) - { + if (min_node) { node->weight = min_weight; node->next = min_next; return node; } - else - { + else { node->weight = MAX_COST; return node; } @@ -2178,12 +1956,12 @@ static int testFlipArc(RigArc *iarc, RigNode *inode_start) ReebNode *enode_start = BIF_NodeFromIndex(earc, inode_start->link_mesh); /* no flip needed if both nodes are the same */ - if ((enode_start == earc->head && inode_start == iarc->head) || (enode_start == earc->tail && inode_start == iarc->tail)) + if ((enode_start == earc->head && inode_start == iarc->head) || + (enode_start == earc->tail && inode_start == iarc->tail)) { return 0; } - else - { + else { return 1; } } @@ -2209,38 +1987,32 @@ static void retargetArctoArcAggresive(bContext *C, RigGraph *rigg, RigArc *iarc, RetargetMethod method = METHOD_MEMOIZE; int i; - if (nb_joints > earc->bcount) - { + if (nb_joints > earc->bcount) { printf("NOT ENOUGH BUCKETS!\n"); return; } best_positions = MEM_callocN(sizeof(int) * nb_joints, "Best positions"); - if (testFlipArc(iarc, inode_start)) - { + if (testFlipArc(iarc, inode_start)) { node_start = earc->tail; node_end = earc->head; } - else - { + else { node_start = earc->head; node_end = earc->tail; } /* equal number of joints and potential position, just fill them in */ - if (nb_joints == earc->bcount) - { + if (nb_joints == earc->bcount) { int i; /* init with first values */ - for (i = 0; i < nb_joints; i++) - { + for (i = 0; i < nb_joints; i++) { best_positions[i] = i + 1; } } - if (method == METHOD_MEMOIZE) - { + if (method == METHOD_MEMOIZE) { int nb_positions = earc->bcount; int nb_memo_nodes = nb_positions * nb_positions * (nb_joints + 1); MemoNode *table = MEM_callocN(nb_memo_nodes * sizeof(MemoNode), "memoization table"); @@ -2255,8 +2027,7 @@ static void retargetArctoArcAggresive(bContext *C, RigGraph *rigg, RigArc *iarc, initArcIterator(iter, earc, node_start); - for (i = 1; i <= nb_positions; i++) - { + for (i = 1; i <= nb_positions; i++) { EmbedBucket *bucket = IT_peek(iter, i); positions_cache[i] = bucket->p; } @@ -2290,20 +2061,17 @@ static void retargetArctoArcAggresive(bContext *C, RigGraph *rigg, RigArc *iarc, edge = edge->next, i++) { float *no = NULL; - if (i < nb_joints) - { + if (i < nb_joints) { bucket = IT_peek(iter, best_positions[i]); vec1 = bucket->p; no = bucket->no; } - else - { + else { vec1 = node_end->p; no = node_end->no; } - if (edge->bone) - { + if (edge->bone) { repositionBone(C, rigg, edge, vec0, vec1, no); } @@ -2327,13 +2095,11 @@ static void retargetArctoArcLength(bContext *C, RigGraph *rigg, RigArc *iarc, Ri float *previous_vec = NULL; - if (testFlipArc(iarc, inode_start)) - { + if (testFlipArc(iarc, inode_start)) { node_start = (ReebNode*)earc->tail; node_end = (ReebNode*)earc->head; } - else - { + else { node_start = (ReebNode*)earc->head; node_end = (ReebNode*)earc->tail; } @@ -2344,8 +2110,7 @@ static void retargetArctoArcLength(bContext *C, RigGraph *rigg, RigArc *iarc, Ri vec0 = node_start->p; - while (bucket != NULL) - { + while (bucket != NULL) { vec1 = bucket->p; embedding_length += len_v3v3(vec0, vec1); @@ -2365,14 +2130,12 @@ static void retargetArctoArcLength(bContext *C, RigGraph *rigg, RigArc *iarc, Ri previous_vec = vec0; vec1 = bucket->p; - for (edge = iarc->edges.first; edge; edge = edge->next) - { + for (edge = iarc->edges.first; edge; edge = edge->next) { float new_bone_length = edge->length / iarc->length * embedding_length; float *no = NULL; float length = 0; - while (bucket && new_bone_length > length) - { + while (bucket && new_bone_length > length) { length += len_v3v3(previous_vec, vec1); bucket = IT_next(iter); previous_vec = vec1; @@ -2380,15 +2143,13 @@ static void retargetArctoArcLength(bContext *C, RigGraph *rigg, RigArc *iarc, Ri no = bucket->no; } - if (bucket == NULL) - { + if (bucket == NULL) { vec1 = node_end->p; no = node_end->no; } /* no need to move virtual edges (space between unconnected bones) */ - if (edge->bone) - { + if (edge->bone) { repositionBone(C, rigg, edge, vec0, vec1, no); } @@ -2429,29 +2190,23 @@ void *exec_retargetArctoArc(void *param) RigNode *inode_start = p->inode_start; ReebArc *earc = iarc->link_mesh; - if (BLI_countlist(&iarc->edges) == 1) - { + if (BLI_countlist(&iarc->edges) == 1) { RigEdge *edge = iarc->edges.first; - if (testFlipArc(iarc, inode_start)) - { + if (testFlipArc(iarc, inode_start)) { repositionBone(C, rigg, edge, earc->tail->p, earc->head->p, earc->head->no); } - else - { + else { repositionBone(C, rigg, edge, earc->head->p, earc->tail->p, earc->tail->no); } } - else - { + else { RetargetMode mode = detectArcRetargetMode(iarc); - if (mode == RETARGET_AGGRESSIVE) - { + if (mode == RETARGET_AGGRESSIVE) { retargetArctoArcAggresive(C, rigg, iarc, inode_start); } - else - { + else { retargetArctoArcLength(C, rigg, iarc, inode_start); } } @@ -2474,8 +2229,7 @@ static void matchMultiResolutionNode(RigGraph *rigg, RigNode *inode, ReebNode *t inode->link_mesh = enode; - while (ishape == eshape && enode->link_down) - { + while (ishape == eshape && enode->link_down) { inode->link_mesh = enode; enode = enode->link_down; @@ -2488,16 +2242,13 @@ static void markMultiResolutionChildArc(ReebNode *end_enode, ReebNode *enode) { int i; - for (i = 0; i < enode->degree; i++) - { + for (i = 0; i < enode->degree; i++) { ReebArc *earc = (ReebArc*)enode->arcs[i]; - if (earc->flag == ARC_FREE) - { + if (earc->flag == ARC_FREE) { earc->flag = ARC_TAKEN; - if (earc->tail->degree > 1 && earc->tail != end_enode) - { + if (earc->tail->degree > 1 && earc->tail != end_enode) { markMultiResolutionChildArc(end_enode, earc->tail); } break; @@ -2507,15 +2258,12 @@ static void markMultiResolutionChildArc(ReebNode *end_enode, ReebNode *enode) static void markMultiResolutionArc(ReebArc *start_earc) { - if (start_earc->link_up) - { + if (start_earc->link_up) { ReebArc *earc; - for (earc = start_earc->link_up ; earc; earc = earc->link_up) - { + for (earc = start_earc->link_up ; earc; earc = earc->link_up) { earc->flag = ARC_TAKEN; - if (earc->tail->index != start_earc->tail->index) - { + if (earc->tail->index != start_earc->tail->index) { markMultiResolutionChildArc(earc->tail, earc->tail); } } @@ -2531,8 +2279,7 @@ static void matchMultiResolutionArc(RigGraph *rigg, RigNode *start_node, RigArc ishape = BLI_subtreeShape((BGraph*)rigg, (BNode*)start_node, (BArc*)next_iarc, 1) % SHAPE_LEVELS; eshape = BLI_subtreeShape((BGraph*)reebg, (BNode*)enode, (BArc*)next_earc, 1) % SHAPE_LEVELS; - while (ishape != eshape && next_earc->link_up) - { + while (ishape != eshape && next_earc->link_up) { next_earc->flag = ARC_TAKEN; // mark previous as taken, to prevent backtrack on lower levels next_earc = next_earc->link_up; @@ -2563,8 +2310,7 @@ static void matchMultiResolutionStartingNode(RigGraph *rigg, ReebGraph *reebg, R ishape = BLI_subtreeShape((BGraph*)rigg, (BNode*)inode, NULL, 0) % SHAPE_LEVELS; eshape = BLI_subtreeShape((BGraph*)rigg->link_mesh, (BNode*)enode, NULL, 0) % SHAPE_LEVELS; - while (ishape != eshape && reebg->link_up) - { + while (ishape != eshape && reebg->link_up) { reebg = reebg->link_up; enode = reebg->nodes.first; @@ -2593,8 +2339,7 @@ static void findCorrespondingArc(RigGraph *rigg, RigArc *start_arc, RigNode *sta // RIG_printArcBones(next_iarc); // } - for (i = 0; i < enode->degree; i++) - { + for (i = 0; i < enode->degree; i++) { next_earc = (ReebArc*)enode->arcs[i]; // if (next_earc->flag == ARC_FREE) @@ -2619,20 +2364,17 @@ static void findCorrespondingArc(RigGraph *rigg, RigArc *start_arc, RigNode *sta } /* not found, try at higher nodes (lower node might have filtered internal arcs, messing shape of tree */ - if (next_iarc->link_mesh == NULL) - { + if (next_iarc->link_mesh == NULL) { // printf("NO CORRESPONDING ARC FOUND - GOING TO HIGHER LEVELS\n"); - if (enode->link_up) - { + if (enode->link_up) { start_node->link_mesh = enode->link_up; findCorrespondingArc(rigg, start_arc, start_node, next_iarc, 0); } } /* still not found, print debug info */ - if (root && next_iarc->link_mesh == NULL) - { + if (root && next_iarc->link_mesh == NULL) { start_node->link_mesh = enode; /* linking back with root node */ // printf("NO CORRESPONDING ARC FOUND\n"); @@ -2651,12 +2393,10 @@ static void findCorrespondingArc(RigGraph *rigg, RigArc *start_arc, RigNode *sta // } /* Emergency matching */ - for (i = 0; i < enode->degree; i++) - { + for (i = 0; i < enode->degree; i++) { next_earc = (ReebArc*)enode->arcs[i]; - if (next_earc->flag == ARC_FREE && next_earc->symmetry_level == symmetry_level) - { + if (next_earc->flag == ARC_FREE && next_earc->symmetry_level == symmetry_level) { // printf("USING:\n"); // printf("flag %i -- level %i -- flag %i -- group %i\n", next_earc->flag, next_earc->symmetry_level, next_earc->symmetry_flag, next_earc->symmetry_group); matchMultiResolutionArc(rigg, start_node, next_iarc, next_earc); @@ -2673,8 +2413,7 @@ static void retargetSubgraph(bContext *C, RigGraph *rigg, RigArc *start_arc, Rig int i; /* no start arc on first node */ - if (start_arc) - { + if (start_arc) { ReebNode *enode = start_node->link_mesh; ReebArc *earc = start_arc->link_mesh; @@ -2687,16 +2426,13 @@ static void retargetSubgraph(bContext *C, RigGraph *rigg, RigArc *start_arc, Rig matchMultiResolutionNode(rigg, inode, enode); } - for (i = 0; i < inode->degree; i++) - { + for (i = 0; i < inode->degree; i++) { RigArc *next_iarc = (RigArc*)inode->arcs[i]; /* no back tracking */ - if (next_iarc != start_arc) - { + if (next_iarc != start_arc) { findCorrespondingArc(rigg, start_arc, inode, next_iarc, 1); - if (next_iarc->link_mesh) - { + if (next_iarc->link_mesh) { retargetSubgraph(C, rigg, next_iarc, inode); } } @@ -2715,10 +2451,8 @@ static void adjustGraphs(bContext *C, RigGraph *rigg) bArmature *arm= rigg->ob->data; RigArc *arc; - for (arc = rigg->arcs.first; arc; arc = arc->next) - { - if (arc->link_mesh) - { + for (arc = rigg->arcs.first; arc; arc = arc->next) { + if (arc->link_mesh) { retargetArctoArc(C, rigg, arc, arc->head); } } @@ -2762,25 +2496,21 @@ const char *RIG_nameBone(RigGraph *rg, int arc_index, int bone_index) RigArc *arc = BLI_findlink(&rg->arcs, arc_index); RigEdge *iedge; - if (arc == NULL) - { + if (arc == NULL) { return "None"; } - if (bone_index == BLI_countlist(&arc->edges)) - { + if (bone_index == BLI_countlist(&arc->edges)) { return "Last joint"; } iedge = BLI_findlink(&arc->edges, bone_index); - if (iedge == NULL) - { + if (iedge == NULL) { return "Done"; } - if (iedge->bone == NULL) - { + if (iedge->bone == NULL) { return "Bone offset"; } @@ -2794,8 +2524,7 @@ int RIG_nbJoints(RigGraph *rg) total += BLI_countlist(&rg->nodes); - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { total += BLI_countlist(&arc->edges) - 1; /* -1 because end nodes are already counted */ } @@ -2804,8 +2533,7 @@ int RIG_nbJoints(RigGraph *rg) static void BIF_freeRetarget(void) { - if (GLOBAL_RIGG) - { + if (GLOBAL_RIGG) { RIG_freeRigGraph((BGraph*)GLOBAL_RIGG); GLOBAL_RIGG = NULL; } @@ -2830,8 +2558,7 @@ void BIF_retargetArmature(bContext *C) CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { Object *ob = base->object; - if (ob->type==OB_ARMATURE) - { + if (ob->type==OB_ARMATURE) { RigGraph *rigg; bArmature *arm; @@ -2910,8 +2637,7 @@ void BIF_retargetArc(bContext *C, ReebArc *earc, RigGraph *template_rigg) template_rigg = armatureSelectedToGraph(C, ob, ob->data); } - if (template_rigg->arcs.first == NULL) - { + if (template_rigg->arcs.first == NULL) { // XXX // error("No Template and no deforming bones selected"); return; @@ -2930,8 +2656,7 @@ void BIF_retargetArc(bContext *C, ReebArc *earc, RigGraph *template_rigg) finishRetarget(rigg); /* free template if it comes from the edit armature */ - if (free_template) - { + if (free_template) { RIG_freeRigGraph((BGraph*)template_rigg); } RIG_freeRigGraph((BGraph*)rigg); @@ -2944,8 +2669,7 @@ void BIF_retargetArc(bContext *C, ReebArc *earc, RigGraph *template_rigg) void BIF_adjustRetarget(bContext *C) { - if (GLOBAL_RIGG) - { + if (GLOBAL_RIGG) { adjustGraphs(C, GLOBAL_RIGG); } } diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c index 81b020a4cf9..4c7ab833e69 100644 --- a/source/blender/editors/armature/editarmature_sketch.c +++ b/source/blender/editors/armature/editarmature_sketch.c @@ -162,25 +162,21 @@ void BIF_makeListTemplates(const bContext *C) Base *base; int index = 0; - if (TEMPLATES_HASH != NULL) - { + if (TEMPLATES_HASH != NULL) { BLI_ghash_free(TEMPLATES_HASH, NULL, NULL); } TEMPLATES_HASH = BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp, "makeListTemplates gh"); TEMPLATES_CURRENT = 0; - for ( base = FIRSTBASE; base; base = base->next ) - { + for ( base = FIRSTBASE; base; base = base->next ) { Object *ob = base->object; - if (ob != obedit && ob->type == OB_ARMATURE) - { + if (ob != obedit && ob->type == OB_ARMATURE) { index++; BLI_ghash_insert(TEMPLATES_HASH, SET_INT_IN_POINTER(index), ob); - if (ob == ts->skgen_template) - { + if (ob == ts->skgen_template) { TEMPLATES_CURRENT = index; } } @@ -193,8 +189,7 @@ const char *BIF_listTemplates(const bContext *UNUSED(C)) char menu_header[] = "Template%t|None%x0|"; char *p; - if (TEMPLATES_MENU != NULL) - { + if (TEMPLATES_MENU != NULL) { MEM_freeN(TEMPLATES_MENU); } @@ -206,8 +201,7 @@ const char *BIF_listTemplates(const bContext *UNUSED(C)) BLI_ghashIterator_init(&ghi, TEMPLATES_HASH); - while (!BLI_ghashIterator_isDone(&ghi)) - { + while (!BLI_ghashIterator_isDone(&ghi)) { Object *ob = BLI_ghashIterator_getValue(&ghi); int key = GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(&ghi)); @@ -223,18 +217,15 @@ int BIF_currentTemplate(const bContext *C) { ToolSettings *ts = CTX_data_tool_settings(C); - if (TEMPLATES_CURRENT == 0 && ts->skgen_template != NULL) - { + if (TEMPLATES_CURRENT == 0 && ts->skgen_template != NULL) { GHashIterator ghi; BLI_ghashIterator_init(&ghi, TEMPLATES_HASH); - while (!BLI_ghashIterator_isDone(&ghi)) - { + while (!BLI_ghashIterator_isDone(&ghi)) { Object *ob = BLI_ghashIterator_getValue(&ghi); int key = GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(&ghi)); - if (ob == ts->skgen_template) - { + if (ob == ts->skgen_template) { TEMPLATES_CURRENT = key; break; } @@ -249,21 +240,17 @@ int BIF_currentTemplate(const bContext *C) static RigGraph* sk_makeTemplateGraph(const bContext *C, Object *ob) { Object *obedit = CTX_data_edit_object(C); - if (ob == obedit) - { + if (ob == obedit) { return NULL; } - if (ob != NULL) - { - if (TEMPLATE_RIGG && TEMPLATE_RIGG->ob != ob) - { + if (ob != NULL) { + if (TEMPLATE_RIGG && TEMPLATE_RIGG->ob != ob) { RIG_freeRigGraph((BGraph*)TEMPLATE_RIGG); TEMPLATE_RIGG = NULL; } - if (TEMPLATE_RIGG == NULL) - { + if (TEMPLATE_RIGG == NULL) { bArmature *arm; arm = ob->data; @@ -280,12 +267,10 @@ int BIF_nbJointsTemplate(const bContext *C) ToolSettings *ts = CTX_data_tool_settings(C); RigGraph *rg = sk_makeTemplateGraph(C, ts->skgen_template); - if (rg) - { + if (rg) { return RIG_nbJoints(rg); } - else - { + else { return -1; } } @@ -297,15 +282,13 @@ const char * BIF_nameBoneTemplate(const bContext *C) RigGraph *rg; int index = 0; - if (stk && stk->active_stroke != NULL) - { + if (stk && stk->active_stroke != NULL) { index = stk->active_stroke->nb_points; } rg = sk_makeTemplateGraph(C, ts->skgen_template); - if (rg == NULL) - { + if (rg == NULL) { return ""; } @@ -314,20 +297,17 @@ const char * BIF_nameBoneTemplate(const bContext *C) void BIF_freeTemplates(bContext *UNUSED(C)) { - if (TEMPLATES_MENU != NULL) - { + if (TEMPLATES_MENU != NULL) { MEM_freeN(TEMPLATES_MENU); TEMPLATES_MENU = NULL; } - if (TEMPLATES_HASH != NULL) - { + if (TEMPLATES_HASH != NULL) { BLI_ghash_free(TEMPLATES_HASH, NULL, NULL); TEMPLATES_HASH = NULL; } - if (TEMPLATE_RIGG != NULL) - { + if (TEMPLATE_RIGG != NULL) { RIG_freeRigGraph((BGraph*)TEMPLATE_RIGG); TEMPLATE_RIGG = NULL; } @@ -336,16 +316,13 @@ void BIF_freeTemplates(bContext *UNUSED(C)) void BIF_setTemplate(bContext *C, int index) { ToolSettings *ts = CTX_data_tool_settings(C); - if (index > 0) - { + if (index > 0) { ts->skgen_template = BLI_ghash_lookup(TEMPLATES_HASH, SET_INT_IN_POINTER(index)); } - else - { + else { ts->skgen_template = NULL; - if (TEMPLATE_RIGG != NULL) - { + if (TEMPLATE_RIGG != NULL) { RIG_freeRigGraph((BGraph*)TEMPLATE_RIGG); } TEMPLATE_RIGG = NULL; @@ -357,44 +334,35 @@ void BIF_setTemplate(bContext *C, int index) static void sk_autoname(bContext *C, ReebArc *arc) { ToolSettings *ts = CTX_data_tool_settings(C); - if (ts->skgen_retarget_options & SK_RETARGET_AUTONAME) - { - if (arc == NULL) - { + if (ts->skgen_retarget_options & SK_RETARGET_AUTONAME) { + if (arc == NULL) { char *num = ts->skgen_num_string; int i = atoi(num); i++; BLI_snprintf(num, 8, "%i", i); } - else - { + else { char *side = ts->skgen_side_string; int valid = 0; int caps = 0; - if (side[0] == '\0') - { + if (side[0] == '\0') { valid = 1; } - else if (strcmp(side, "R")==0 || strcmp(side, "L")==0) - { + else if (strcmp(side, "R")==0 || strcmp(side, "L")==0) { valid = 1; caps = 1; } - else if (strcmp(side, "r")==0 || strcmp(side, "l")==0) - { + else if (strcmp(side, "r")==0 || strcmp(side, "l")==0) { valid = 1; caps = 0; } - if (valid) - { - if (arc->head->p[0] < 0) - { + if (valid) { + if (arc->head->p[0] < 0) { BLI_snprintf(side, 8, caps?"R":"r"); } - else - { + else { BLI_snprintf(side, 8, caps?"L":"l"); } } @@ -428,8 +396,7 @@ static ReebArc *sk_strokeToArc(SK_Stroke *stk, float imat[][4], float tmat[][3]) arc->bcount = stk->nb_points - 2; /* first and last are nodes, don't count */ arc->buckets = MEM_callocN(sizeof(EmbedBucket) * arc->bcount, "Buckets"); - for (i = 0; i < arc->bcount; i++) - { + for (i = 0; i < arc->bcount; i++) { copy_v3_v3(arc->buckets[i].p, stk->points[i + 1].p); mul_m4_v3(imat, arc->buckets[i].p); @@ -473,8 +440,7 @@ static void sk_retargetStroke(bContext *C, SK_Stroke *stk) static void sk_cancelStroke(SK_Sketch *sketch) { - if (sketch->active_stroke != NULL) - { + if (sketch->active_stroke != NULL) { sk_resetOverdraw(sketch); sk_removeStroke(sketch, sketch->active_stroke); } @@ -501,8 +467,7 @@ static void sk_drawEdge(GLUquadric *quad, SK_Point *pt0, SK_Point *pt1, float si length = normalize_v3(vec1); cross_v3_v3v3(axis, vec2, vec1); - if (is_zero_v3(axis)) - { + if (is_zero_v3(axis)) { axis[1] = 1; } @@ -522,8 +487,7 @@ static void sk_drawNormal(GLUquadric *quad, SK_Point *pt, float size, float heig cross_v3_v3v3(axis, vec2, pt->no); - if (is_zero_v3(axis)) - { + if (is_zero_v3(axis)) { axis[1] = 1; } @@ -544,18 +508,15 @@ static void sk_drawStroke(SK_Stroke *stk, int id, float color[3], int start, int GLUquadric *quad = gluNewQuadric(); gluQuadricNormals(quad, GLU_SMOOTH); - if (id != -1) - { + if (id != -1) { glLoadName(id); - for (i = 0; i < stk->nb_points; i++) - { + for (i = 0; i < stk->nb_points; i++) { glPushMatrix(); sk_drawPoint(quad, stk->points + i, 0.1); - if (i > 0) - { + if (i > 0) { sk_drawEdge(quad, stk->points + i - 1, stk->points + i, 0.1); } @@ -563,44 +524,37 @@ static void sk_drawStroke(SK_Stroke *stk, int id, float color[3], int start, int } } - else - { + else { float d_rgb[3] = {1, 1, 1}; copy_v3_v3(rgb, color); sub_v3_v3(d_rgb, rgb); mul_v3_fl(d_rgb, 1.0f / (float)stk->nb_points); - for (i = 0; i < stk->nb_points; i++) - { + for (i = 0; i < stk->nb_points; i++) { SK_Point *pt = stk->points + i; glPushMatrix(); - if (pt->type == PT_EXACT) - { + if (pt->type == PT_EXACT) { glColor3f(0, 0, 0); sk_drawPoint(quad, pt, 0.15); sk_drawNormal(quad, pt, 0.05, 0.9); } - if (i >= start && i <= end) - { + if (i >= start && i <= end) { glColor3f(0.3, 0.3, 0.3); } - else - { + else { glColor3fv(rgb); } - if (pt->type != PT_EXACT) - { + if (pt->type != PT_EXACT) { sk_drawPoint(quad, pt, 0.1); } - if (i > 0) - { + if (i > 0) { sk_drawEdge(quad, pt - 1, pt, 0.1); } @@ -627,8 +581,7 @@ static void drawSubdividedStrokeBy(ToolSettings *toolsettings, BArcIterator *ite copy_v3_v3(head, iter->p); index = next_subdividion(toolsettings, iter, bone_start, end, head, tail); - while (index != -1) - { + while (index != -1) { SK_Point *pt = stk->points + index; glPushMatrix(); @@ -654,41 +607,32 @@ static void sk_drawStrokeSubdivision(ToolSettings *toolsettings, SK_Stroke *stk) int head_index = -1; int i; - if (toolsettings->bone_sketching_convert == SK_CONVERT_RETARGET) - { + if (toolsettings->bone_sketching_convert == SK_CONVERT_RETARGET) { return; } - for (i = 0; i < stk->nb_points; i++) - { + for (i = 0; i < stk->nb_points; i++) { SK_Point *pt = stk->points + i; - if (pt->type == PT_EXACT || i == stk->nb_points - 1) /* stop on exact or on last point */ - { - if (head_index == -1) - { + if (pt->type == PT_EXACT || i == stk->nb_points - 1) /* stop on exact or on last point */ { + if (head_index == -1) { head_index = i; } - else - { - if (i - head_index > 1) - { + else { + if (i - head_index > 1) { SK_StrokeIterator sk_iter; BArcIterator *iter = (BArcIterator*)&sk_iter; initStrokeIterator(iter, stk, head_index, i); - if (toolsettings->bone_sketching_convert == SK_CONVERT_CUT_ADAPTATIVE) - { + if (toolsettings->bone_sketching_convert == SK_CONVERT_CUT_ADAPTATIVE) { drawSubdividedStrokeBy(toolsettings, iter, nextAdaptativeSubdivision); } - else if (toolsettings->bone_sketching_convert == SK_CONVERT_CUT_LENGTH) - { + else if (toolsettings->bone_sketching_convert == SK_CONVERT_CUT_LENGTH) { drawSubdividedStrokeBy(toolsettings, iter, nextLengthSubdivision); } - else if (toolsettings->bone_sketching_convert == SK_CONVERT_CUT_FIXED) - { + else if (toolsettings->bone_sketching_convert == SK_CONVERT_CUT_FIXED) { drawSubdividedStrokeBy(toolsettings, iter, nextFixedSubdivision); } @@ -706,10 +650,8 @@ static SK_Point *sk_snapPointStroke(bContext *C, SK_Stroke *stk, int mval[2], in SK_Point *pt = NULL; int i; - for (i = 0; i < stk->nb_points; i++) - { - if (all_pts || stk->points[i].type == PT_EXACT) - { + for (i = 0; i < stk->nb_points; i++) { + if (all_pts || stk->points[i].type == PT_EXACT) { short pval[2]; int pdist; @@ -717,13 +659,11 @@ static SK_Point *sk_snapPointStroke(bContext *C, SK_Stroke *stk, int mval[2], in pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]); - if (pdist < *dist) - { + if (pdist < *dist) { *dist = pdist; pt = stk->points + i; - if (index != NULL) - { + if (index != NULL) { *index = i; } } @@ -801,75 +741,60 @@ int sk_hasOverdraw(SK_Sketch *sketch, SK_Stroke *stk) static void sk_updateOverdraw(bContext *C, SK_Sketch *sketch, SK_Stroke *stk, SK_DrawData *dd) { - if (sketch->over.target == NULL) - { + if (sketch->over.target == NULL) { SK_Stroke *target; int closest_index = -1; int dist = SNAP_MIN_DISTANCE * 2; - for (target = sketch->strokes.first; target; target = target->next) - { - if (target != stk) - { + for (target = sketch->strokes.first; target; target = target->next) { + if (target != stk) { int index; SK_Point *spt = sk_snapPointStroke(C, target, dd->mval, &dist, &index, 1); - if (spt != NULL) - { + if (spt != NULL) { sketch->over.target = target; closest_index = index; } } } - if (sketch->over.target != NULL) - { - if (closest_index > -1) - { - if (sk_lastStrokePoint(stk)->type == PT_EXACT) - { + if (sketch->over.target != NULL) { + if (closest_index > -1) { + if (sk_lastStrokePoint(stk)->type == PT_EXACT) { sketch->over.count = SK_OVERDRAW_LIMIT; } - else - { + else { sketch->over.count++; } } - if (stk->nb_points == 1) - { + if (stk->nb_points == 1) { sketch->over.start = closest_index; } - else - { + else { sketch->over.end = closest_index; } } } - else if (sketch->over.target != NULL) - { + else if (sketch->over.target != NULL) { SK_Point *closest_pt = NULL; int dist = SNAP_MIN_DISTANCE * 2; int index; closest_pt = sk_snapPointStroke(C, sketch->over.target, dd->mval, &dist, &index, 1); - if (closest_pt != NULL) - { - if (sk_lastStrokePoint(stk)->type == PT_EXACT) - { + if (closest_pt != NULL) { + if (sk_lastStrokePoint(stk)->type == PT_EXACT) { sketch->over.count = SK_OVERDRAW_LIMIT; } - else - { + else { sketch->over.count++; } sketch->over.end = index; } - else - { + else { sketch->over.end = -1; } } @@ -883,18 +808,15 @@ static int sk_adjustIndexes(SK_Sketch *sketch, int *start, int *end) *start = sketch->over.start; *end = sketch->over.end; - if (*start == -1) - { + if (*start == -1) { *start = 0; } - if (*end == -1) - { + if (*end == -1) { *end = sketch->over.target->nb_points - 1; } - if (*end < *start) - { + if (*end < *start) { int tmp = *start; *start = *end; *end = tmp; @@ -908,18 +830,15 @@ static void sk_endOverdraw(SK_Sketch *sketch) { SK_Stroke *stk = sketch->active_stroke; - if (sk_hasOverdraw(sketch, NULL)) - { + if (sk_hasOverdraw(sketch, NULL)) { int start; int end; - if (sk_adjustIndexes(sketch, &start, &end)) - { + if (sk_adjustIndexes(sketch, &start, &end)) { sk_reverseStroke(stk); } - if (stk->nb_points > 1) - { + if (stk->nb_points > 1) { stk->points->type = sketch->over.target->points[start].type; sk_lastStrokePoint(stk)->type = sketch->over.target->points[end].type; } @@ -948,8 +867,7 @@ static void sk_endStroke(bContext *C, SK_Sketch *sketch) ToolSettings *ts = CTX_data_tool_settings(C); sk_shrinkStrokeBuffer(sketch->active_stroke); - if (ts->bone_sketching & BONE_SKETCHING_ADJUST) - { + if (ts->bone_sketching & BONE_SKETCHING_ADJUST) { sk_endOverdraw(sketch); } @@ -977,8 +895,7 @@ static float sk_distanceDepth(bContext *C, float p1[3], float p2[3]) distance = len_v3(vec); - if (dot_v3v3(rv3d->viewinv[2], vec) > 0) - { + if (dot_v3v3(rv3d->viewinv[2], vec) > 0) { distance *= -1; } @@ -996,8 +913,7 @@ static void sk_interpolateDepth(bContext *C, SK_Stroke *stk, int start, int end, progress = len_v3v3(stk->points[start].p, stk->points[start - 1].p); - for (i = start; i <= end; i++) - { + for (i = start; i <= end; i++) { float ray_start[3], ray_normal[3]; float delta = len_v3v3(stk->points[i].p, stk->points[i + 1].p); float pval[2]; @@ -1022,8 +938,7 @@ static void sk_projectDrawPoint(bContext *C, float vec[3], SK_Stroke *stk, SK_Dr float dvec[3]; float mval_f[2]; - if (last != NULL) - { + if (last != NULL) { copy_v3_v3(fp, last->p); } @@ -1065,8 +980,7 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S ToolSettings *ts = CTX_data_tool_settings(C); int point_added = 0; - if (ts->snap_mode == SCE_SNAP_MODE_VOLUME) - { + if (ts->snap_mode == SCE_SNAP_MODE_VOLUME) { DepthPeel *p1, *p2; float *last_p = NULL; float dist = FLT_MAX; @@ -1081,20 +995,16 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S mvalf[1]= dd->mval[1]; peelObjectsContext(C, &sketch->depth_peels, mvalf, SNAP_ALL); - if (stk->nb_points > 0 && stk->points[stk->nb_points - 1].type == PT_CONTINUOUS) - { + if (stk->nb_points > 0 && stk->points[stk->nb_points - 1].type == PT_CONTINUOUS) { last_p = stk->points[stk->nb_points - 1].p; } - else if (LAST_SNAP_POINT_VALID) - { + else if (LAST_SNAP_POINT_VALID) { last_p = LAST_SNAP_POINT; } - for (p1 = sketch->depth_peels.first; p1; p1 = p1->next) - { - if (p1->flag == 0) - { + for (p1 = sketch->depth_peels.first; p1; p1 = p1->next) { + if (p1->flag == 0) { float vec[3]; float new_dist; float new_size = 0; @@ -1103,42 +1013,34 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S p1->flag = 1; /* if peeling objects, take the first and last from each object */ - if (ts->snap_flag & SCE_SNAP_PEEL_OBJECT) - { + if (ts->snap_flag & SCE_SNAP_PEEL_OBJECT) { DepthPeel *peel; - for (peel = p1->next; peel; peel = peel->next) - { - if (peel->ob == p1->ob) - { + for (peel = p1->next; peel; peel = peel->next) { + if (peel->ob == p1->ob) { peel->flag = 1; p2 = peel; } } } /* otherwise, pair first with second and so on */ - else - { - for (p2 = p1->next; p2 && p2->ob != p1->ob; p2 = p2->next) - { + else { + for (p2 = p1->next; p2 && p2->ob != p1->ob; p2 = p2->next) { /* nothing to do here */ } } - if (p2) - { + if (p2) { p2->flag = 1; add_v3_v3v3(vec, p1->p, p2->p); mul_v3_fl(vec, 0.5f); new_size = len_v3v3(p1->p, p2->p); } - else - { + else { copy_v3_v3(vec, p1->p); } - if (last_p == NULL) - { + if (last_p == NULL) { copy_v3_v3(p, vec); size = new_size; dist = 0; @@ -1147,8 +1049,7 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S new_dist = len_v3v3(last_p, vec); - if (new_dist < dist) - { + if (new_dist < dist) { copy_v3_v3(p, vec); dist = new_dist; size = new_size; @@ -1156,8 +1057,7 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S } } - if (dist != FLT_MAX) - { + if (dist != FLT_MAX) { pt->type = dd->type; pt->mode = PT_SNAP; pt->size = size / 2; @@ -1168,8 +1068,7 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S //BLI_freelistN(&depth_peels); } - else - { + else { SK_Stroke *snap_stk; float vec[3]; float no[3]; @@ -1179,20 +1078,16 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S /* snap to strokes */ // if (ts->snap_mode == SCE_SNAP_MODE_VERTEX) /* snap all the time to strokes */ - for (snap_stk = sketch->strokes.first; snap_stk; snap_stk = snap_stk->next) - { + for (snap_stk = sketch->strokes.first; snap_stk; snap_stk = snap_stk->next) { SK_Point *spt = NULL; - if (snap_stk == stk) - { + if (snap_stk == stk) { spt = sk_snapPointStroke(C, snap_stk, dd->mval, &dist, NULL, 0); } - else - { + else { spt = sk_snapPointStroke(C, snap_stk, dd->mval, &dist, NULL, 1); } - if (spt != NULL) - { + if (spt != NULL) { copy_v3_v3(pt->p, spt->p); point_added = 1; } @@ -1203,8 +1098,7 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S /* try to snap to closer object */ found = snapObjectsContext(C, mval, &dist, vec, no, SNAP_NOT_SELECTED); - if (found == 1) - { + if (found == 1) { pt->type = dd->type; pt->mode = PT_SNAP; copy_v3_v3(pt->p, vec); @@ -1227,8 +1121,7 @@ static int sk_addStrokeSnapPoint(bContext *C, SK_Sketch *sketch, SK_Stroke *stk, point_added = sk_getStrokeSnapPoint(C, &pt, sketch, stk, dd); - if (point_added) - { + if (point_added) { float final_p[3]; float length, distance; int total; @@ -1242,18 +1135,15 @@ static int sk_addStrokeSnapPoint(bContext *C, SK_Sketch *sketch, SK_Stroke *stk, /* update all previous point to give smooth Z progresion */ total = 0; length = 0; - for (i = stk->nb_points - 2; i > 0; i--) - { + for (i = stk->nb_points - 2; i > 0; i--) { length += len_v3v3(stk->points[i].p, stk->points[i + 1].p); total++; - if (stk->points[i].mode == PT_SNAP || stk->points[i].type == PT_EXACT) - { + if (stk->points[i].mode == PT_SNAP || stk->points[i].type == PT_EXACT) { break; } } - if (total > 1) - { + if (total > 1) { distance = sk_distanceDepth(C, final_p, stk->points[i].p); sk_interpolateDepth(C, stk, i + 1, stk->nb_points - 2, length, distance); @@ -1272,18 +1162,15 @@ static void sk_addStrokePoint(bContext *C, SK_Sketch *sketch, SK_Stroke *stk, SK ToolSettings *ts = CTX_data_tool_settings(C); int point_added = 0; - if (snap) - { + if (snap) { point_added = sk_addStrokeSnapPoint(C, sketch, stk, dd); } - if (point_added == 0) - { + if (point_added == 0) { point_added = sk_addStrokeDrawPoint(C, sketch, stk, dd); } - if (stk == sketch->active_stroke && ts->bone_sketching & BONE_SKETCHING_ADJUST) - { + if (stk == sketch->active_stroke && ts->bone_sketching & BONE_SKETCHING_ADJUST) { sk_updateOverdraw(C, sketch, stk, dd); } } @@ -1292,19 +1179,16 @@ static void sk_getStrokePoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, SK_S { int point_added = 0; - if (snap) - { + if (snap) { point_added = sk_getStrokeSnapPoint(C, pt, sketch, stk, dd); LAST_SNAP_POINT_VALID = 1; copy_v3_v3(LAST_SNAP_POINT, pt->p); } - else - { + else { LAST_SNAP_POINT_VALID = 0; } - if (point_added == 0) - { + if (point_added == 0) { point_added = sk_getStrokeDrawPoint(C, pt, sketch, stk, dd); } } @@ -1334,15 +1218,13 @@ static SK_Point* setIteratorValues(SK_StrokeIterator *iter, int index) { SK_Point *pt = NULL; - if (index >= 0 && index < iter->length) - { + if (index >= 0 && index < iter->length) { pt = &(iter->stroke->points[iter->start + (iter->stride * index)]); iter->p = pt->p; iter->no = pt->no; iter->size = pt->size; } - else - { + else { iter->p = NULL; iter->no = NULL; iter->size = 0; @@ -1358,14 +1240,12 @@ void initStrokeIterator(BArcIterator *arg, SK_Stroke *stk, int start, int end) initIteratorFct(iter); iter->stroke = stk; - if (start < end) - { + if (start < end) { iter->start = start + 1; iter->end = end - 1; iter->stride = 1; } - else - { + else { iter->start = start - 1; iter->end = end + 1; iter->stride = -1; @@ -1409,8 +1289,7 @@ static void* nextPoint(void *arg) SK_Point *result = NULL; iter->index++; - if (iter->index < iter->length) - { + if (iter->index < iter->length) { result = setIteratorValues(iter, iter->index); } @@ -1425,8 +1304,7 @@ static void* nextNPoint(void *arg, int n) iter->index += n; /* check if passed end */ - if (iter->index < iter->length) - { + if (iter->index < iter->length) { result = setIteratorValues(iter, iter->index); } @@ -1440,8 +1318,7 @@ static void* peekPoint(void *arg, int n) int index = iter->index + n; /* check if passed end */ - if (index < iter->length) - { + if (index < iter->length) { result = setIteratorValues(iter, index); } @@ -1453,8 +1330,7 @@ static void* previousPoint(void *arg) SK_StrokeIterator *iter = (SK_StrokeIterator*)arg; SK_Point *result = NULL; - if (iter->index > 0) - { + if (iter->index > 0) { iter->index--; result = setIteratorValues(iter, iter->index); } @@ -1466,12 +1342,10 @@ static int iteratorStopped(void *arg) { SK_StrokeIterator *iter = (SK_StrokeIterator*)arg; - if (iter->index >= iter->length) - { + if (iter->index >= iter->length) { return 1; } - else - { + else { return 0; } } @@ -1495,45 +1369,36 @@ static void sk_convertStroke(bContext *C, SK_Stroke *stk) copy_m3_m4(tmat, obedit->obmat); transpose_m3(tmat); - for (i = 0; i < stk->nb_points; i++) - { + for (i = 0; i < stk->nb_points; i++) { SK_Point *pt = stk->points + i; - if (pt->type == PT_EXACT) - { - if (head == NULL) - { + if (pt->type == PT_EXACT) { + if (head == NULL) { head_index = i; head = pt; } - else - { + else { EditBone *bone = NULL; EditBone *new_parent; - if (i - head_index > 1) - { + if (i - head_index > 1) { SK_StrokeIterator sk_iter; BArcIterator *iter = (BArcIterator*)&sk_iter; initStrokeIterator(iter, stk, head_index, i); - if (ts->bone_sketching_convert == SK_CONVERT_CUT_ADAPTATIVE) - { + if (ts->bone_sketching_convert == SK_CONVERT_CUT_ADAPTATIVE) { bone = subdivideArcBy(ts, arm, arm->edbo, iter, invmat, tmat, nextAdaptativeSubdivision); } - else if (ts->bone_sketching_convert == SK_CONVERT_CUT_LENGTH) - { + else if (ts->bone_sketching_convert == SK_CONVERT_CUT_LENGTH) { bone = subdivideArcBy(ts, arm, arm->edbo, iter, invmat, tmat, nextLengthSubdivision); } - else if (ts->bone_sketching_convert == SK_CONVERT_CUT_FIXED) - { + else if (ts->bone_sketching_convert == SK_CONVERT_CUT_FIXED) { bone = subdivideArcBy(ts, arm, arm->edbo, iter, invmat, tmat, nextFixedSubdivision); } } - if (bone == NULL) - { + if (bone == NULL) { bone = ED_armature_edit_bone_add(arm, "Bone"); copy_v3_v3(bone->head, head->p); @@ -1548,14 +1413,12 @@ static void sk_convertStroke(bContext *C, SK_Stroke *stk) bone->flag |= BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL; /* move to end of chain */ - while (bone->parent != NULL) - { + while (bone->parent != NULL) { bone = bone->parent; bone->flag |= BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL; } - if (parent != NULL) - { + if (parent != NULL) { bone->parent = parent; bone->flag |= BONE_CONNECTED; } @@ -1573,16 +1436,12 @@ static void sk_convert(bContext *C, SK_Sketch *sketch) ToolSettings *ts = CTX_data_tool_settings(C); SK_Stroke *stk; - for (stk = sketch->strokes.first; stk; stk = stk->next) - { - if (stk->selected == 1) - { - if (ts->bone_sketching_convert == SK_CONVERT_RETARGET) - { + for (stk = sketch->strokes.first; stk; stk = stk->next) { + if (stk->selected == 1) { + if (ts->bone_sketching_convert == SK_CONVERT_RETARGET) { sk_retargetStroke(C, stk); } - else - { + else { sk_convertStroke(C, stk); } // XXX @@ -1600,8 +1459,7 @@ static int sk_getSelfIntersections(bContext *C, ListBase *list, SK_Stroke *gestu int added = 0; int s_i; - for (s_i = 0; s_i < gesture->nb_points - 1; s_i++) - { + for (s_i = 0; s_i < gesture->nb_points - 1; s_i++) { float s_p1[3] = {0, 0, 0}; float s_p2[3] = {0, 0, 0}; int g_i; @@ -1610,8 +1468,7 @@ static int sk_getSelfIntersections(bContext *C, ListBase *list, SK_Stroke *gestu project_float(ar, gesture->points[s_i + 1].p, s_p2); /* start checking from second next, because two consecutive cannot intersect */ - for (g_i = s_i + 2; g_i < gesture->nb_points - 1; g_i++) - { + for (g_i = s_i + 2; g_i < gesture->nb_points - 1; g_i++) { float g_p1[3] = {0, 0, 0}; float g_p2[3] = {0, 0, 0}; float vi[3]; @@ -1620,8 +1477,7 @@ static int sk_getSelfIntersections(bContext *C, ListBase *list, SK_Stroke *gestu project_float(ar, gesture->points[g_i].p, g_p1); project_float(ar, gesture->points[g_i + 1].p, g_p2); - if (isect_line_line_strict_v3(s_p1, s_p2, g_p1, g_p2, vi, &lambda)) - { + if (isect_line_line_strict_v3(s_p1, s_p2, g_p1, g_p2, vi, &lambda)) { SK_Intersection *isect = MEM_callocN(sizeof(SK_Intersection), "Intersection"); isect->gesture_index = g_i; @@ -1647,24 +1503,18 @@ static int cmpIntersections(void *i1, void *i2) { SK_Intersection *isect1 = i1, *isect2 = i2; - if (isect1->stroke == isect2->stroke) - { - if (isect1->before < isect2->before) - { + if (isect1->stroke == isect2->stroke) { + if (isect1->before < isect2->before) { return -1; } - else if (isect1->before > isect2->before) - { + else if (isect1->before > isect2->before) { return 1; } - else - { - if (isect1->lambda < isect2->lambda) - { + else { + if (isect1->lambda < isect2->lambda) { return -1; } - else if (isect1->lambda > isect2->lambda) - { + else if (isect1->lambda > isect2->lambda) { return 1; } } @@ -1683,13 +1533,11 @@ static int sk_getIntersections(bContext *C, ListBase *list, SK_Sketch *sketch, S SK_Stroke *stk; int added = 0; - for (stk = sketch->strokes.first; stk; stk = stk->next) - { + for (stk = sketch->strokes.first; stk; stk = stk->next) { int s_added = 0; int s_i; - for (s_i = 0; s_i < stk->nb_points - 1; s_i++) - { + for (s_i = 0; s_i < stk->nb_points - 1; s_i++) { float s_p1[3] = {0, 0, 0}; float s_p2[3] = {0, 0, 0}; int g_i; @@ -1697,8 +1545,7 @@ static int sk_getIntersections(bContext *C, ListBase *list, SK_Sketch *sketch, S project_float(ar, stk->points[s_i].p, s_p1); project_float(ar, stk->points[s_i + 1].p, s_p2); - for (g_i = 0; g_i < gesture->nb_points - 1; g_i++) - { + for (g_i = 0; g_i < gesture->nb_points - 1; g_i++) { float g_p1[3] = {0, 0, 0}; float g_p2[3] = {0, 0, 0}; float vi[3]; @@ -1707,8 +1554,7 @@ static int sk_getIntersections(bContext *C, ListBase *list, SK_Sketch *sketch, S project_float(ar, gesture->points[g_i].p, g_p1); project_float(ar, gesture->points[g_i + 1].p, g_p2); - if (isect_line_line_strict_v3(s_p1, s_p2, g_p1, g_p2, vi, &lambda)) - { + if (isect_line_line_strict_v3(s_p1, s_p2, g_p1, g_p2, vi, &lambda)) { SK_Intersection *isect = MEM_callocN(sizeof(SK_Intersection), "Intersection"); float ray_start[3], ray_end[3]; float mval[2]; @@ -1759,15 +1605,13 @@ static int sk_getSegments(SK_Stroke *segments, SK_Stroke *gesture) initStrokeIterator(iter, gesture, 0, gesture->nb_points - 1); - for (i = 1, j = 0; i < gesture->nb_points; i++) - { + for (i = 1, j = 0; i < gesture->nb_points; i++) { float n[3]; /* Calculate normal */ sub_v3_v3v3(n, gesture->points[i].p, vec); - if (calcArcCorrelation(iter, j, i, vec, n) < CORRELATION_THRESHOLD) - { + if (calcArcCorrelation(iter, j, i, vec, n) < CORRELATION_THRESHOLD) { j = i - 1; sk_appendStrokePoint(segments, &gesture->points[j]); vec = segments->points[segments->nb_points - 1].p; @@ -1782,8 +1626,7 @@ static int sk_getSegments(SK_Stroke *segments, SK_Stroke *gesture) int sk_detectCutGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch)) { - if (gest->nb_segments == 1 && gest->nb_intersections == 1) - { + if (gest->nb_segments == 1 && gest->nb_intersections == 1) { return 1; } @@ -1794,8 +1637,7 @@ void sk_applyCutGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED { SK_Intersection *isect; - for (isect = gest->intersections.first; isect; isect = isect->next) - { + for (isect = gest->intersections.first; isect; isect = isect->next) { SK_Point pt; pt.type = PT_EXACT; @@ -1809,8 +1651,7 @@ void sk_applyCutGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED int sk_detectTrimGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch)) { - if (gest->nb_segments == 2 && gest->nb_intersections == 1 && gest->nb_self_intersections == 0) - { + if (gest->nb_segments == 2 && gest->nb_intersections == 1 && gest->nb_self_intersections == 0) { float s1[3], s2[3]; float angle; @@ -1819,8 +1660,7 @@ int sk_detectTrimGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSE angle = RAD2DEGF(angle_v2v2(s1, s2)); - if (angle > 60 && angle < 120) - { + if (angle > 60 && angle < 120) { return 1; } } @@ -1835,8 +1675,7 @@ void sk_applyTrimGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSE sub_v3_v3v3(trim_dir, gest->segments->points[2].p, gest->segments->points[1].p); - for (isect = gest->intersections.first; isect; isect = isect->next) - { + for (isect = gest->intersections.first; isect; isect = isect->next) { SK_Point pt; float stroke_dir[3]; @@ -1848,14 +1687,12 @@ void sk_applyTrimGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSE sub_v3_v3v3(stroke_dir, isect->stroke->points[isect->after].p, isect->stroke->points[isect->before].p); /* same direction, trim end */ - if (dot_v3v3(stroke_dir, trim_dir) > 0) - { + if (dot_v3v3(stroke_dir, trim_dir) > 0) { sk_replaceStrokePoint(isect->stroke, &pt, isect->after); sk_trimStroke(isect->stroke, 0, isect->after); } /* else, trim start */ - else - { + else { sk_replaceStrokePoint(isect->stroke, &pt, isect->before); sk_trimStroke(isect->stroke, isect->before, isect->stroke->nb_points - 1); } @@ -1865,15 +1702,12 @@ void sk_applyTrimGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSE int sk_detectCommandGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch)) { - if (gest->nb_segments > 2 && gest->nb_intersections == 2 && gest->nb_self_intersections == 1) - { + if (gest->nb_segments > 2 && gest->nb_intersections == 2 && gest->nb_self_intersections == 1) { SK_Intersection *isect, *self_isect; /* get the the last intersection of the first pair */ - for ( isect = gest->intersections.first; isect; isect = isect->next ) - { - if (isect->stroke == isect->next->stroke) - { + for ( isect = gest->intersections.first; isect; isect = isect->next ) { + if (isect->stroke == isect->next->stroke) { isect = isect->next; break; } @@ -1881,8 +1715,7 @@ int sk_detectCommandGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UN self_isect = gest->self_intersections.first; - if (isect && isect->gesture_index < self_isect->gesture_index) - { + if (isect && isect->gesture_index < self_isect->gesture_index) { return 1; } } @@ -1899,16 +1732,13 @@ void sk_applyCommandGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UN // command = pupmenu("Action %t|Flatten %x1|Straighten %x2|Polygonize %x3"); if (command < 1) return; - for (isect = gest->intersections.first; isect; isect = isect->next) - { + for (isect = gest->intersections.first; isect; isect = isect->next) { SK_Intersection *i2; i2 = isect->next; - if (i2 && i2->stroke == isect->stroke) - { - switch (command) - { + if (i2 && i2->stroke == isect->stroke) { + switch (command) { case 1: sk_flattenStroke(isect->stroke, isect->before, i2->after); break; @@ -1927,8 +1757,7 @@ void sk_applyCommandGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UN int sk_detectDeleteGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch)) { - if (gest->nb_segments == 2 && gest->nb_intersections == 2) - { + if (gest->nb_segments == 2 && gest->nb_intersections == 2) { float s1[3], s2[3]; float angle; @@ -1937,8 +1766,7 @@ int sk_detectDeleteGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNU angle = RAD2DEGF(angle_v2v2(s1, s2)); - if (angle > 120) - { + if (angle > 120) { return 1; } } @@ -1950,11 +1778,9 @@ void sk_applyDeleteGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *ske { SK_Intersection *isect; - for (isect = gest->intersections.first; isect; isect = isect->next) - { + for (isect = gest->intersections.first; isect; isect = isect->next) { /* only delete strokes that are crossed twice */ - if (isect->next && isect->next->stroke == isect->stroke) - { + if (isect->next && isect->next->stroke == isect->stroke) { isect = isect->next; sk_removeStroke(sketch, isect->stroke); @@ -1965,8 +1791,7 @@ void sk_applyDeleteGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *ske int sk_detectMergeGesture(bContext *C, SK_Gesture *gest, SK_Sketch *UNUSED(sketch)) { ARegion *ar = CTX_wm_region(C); - if (gest->nb_segments > 2 && gest->nb_intersections == 2) - { + if (gest->nb_segments > 2 && gest->nb_intersections == 2) { short start_val[2], end_val[2]; short dist; @@ -1976,26 +1801,21 @@ int sk_detectMergeGesture(bContext *C, SK_Gesture *gest, SK_Sketch *UNUSED(sketc dist = MAX2(ABS(start_val[0] - end_val[0]), ABS(start_val[1] - end_val[1])); /* if gesture is a circle */ - if ( dist <= 20 ) - { + if ( dist <= 20 ) { SK_Intersection *isect; /* check if it circled around an exact point */ - for (isect = gest->intersections.first; isect; isect = isect->next) - { + for (isect = gest->intersections.first; isect; isect = isect->next) { /* only delete strokes that are crossed twice */ - if (isect->next && isect->next->stroke == isect->stroke) - { + if (isect->next && isect->next->stroke == isect->stroke) { int start_index, end_index; int i; start_index = MIN2(isect->after, isect->next->after); end_index = MAX2(isect->before, isect->next->before); - for (i = start_index; i <= end_index; i++) - { - if (isect->stroke->points[i].type == PT_EXACT) - { + for (i = start_index; i <= end_index; i++) { + if (isect->stroke->points[i].type == PT_EXACT) { return 1; /* at least one exact point found, stop detect here */ } } @@ -2015,22 +1835,18 @@ void sk_applyMergeGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUS SK_Intersection *isect; /* check if it circled around an exact point */ - for (isect = gest->intersections.first; isect; isect = isect->next) - { + for (isect = gest->intersections.first; isect; isect = isect->next) { /* only merge strokes that are crossed twice */ - if (isect->next && isect->next->stroke == isect->stroke) - { + if (isect->next && isect->next->stroke == isect->stroke) { int start_index, end_index; int i; start_index = MIN2(isect->after, isect->next->after); end_index = MAX2(isect->before, isect->next->before); - for (i = start_index; i <= end_index; i++) - { + for (i = start_index; i <= end_index; i++) { /* if exact, switch to continuous */ - if (isect->stroke->points[i].type == PT_EXACT) - { + if (isect->stroke->points[i].type == PT_EXACT) { isect->stroke->points[i].type = PT_CONTINUOUS; } } @@ -2043,34 +1859,28 @@ void sk_applyMergeGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUS int sk_detectReverseGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch)) { - if (gest->nb_segments > 2 && gest->nb_intersections == 2 && gest->nb_self_intersections == 0) - { + if (gest->nb_segments > 2 && gest->nb_intersections == 2 && gest->nb_self_intersections == 0) { SK_Intersection *isect; /* check if it circled around an exact point */ - for (isect = gest->intersections.first; isect; isect = isect->next) - { + for (isect = gest->intersections.first; isect; isect = isect->next) { /* only delete strokes that are crossed twice */ - if (isect->next && isect->next->stroke == isect->stroke) - { + if (isect->next && isect->next->stroke == isect->stroke) { float start_v[3], end_v[3]; float angle; - if (isect->gesture_index < isect->next->gesture_index) - { + if (isect->gesture_index < isect->next->gesture_index) { sub_v3_v3v3(start_v, isect->p, gest->stk->points[0].p); sub_v3_v3v3(end_v, sk_lastStrokePoint(gest->stk)->p, isect->next->p); } - else - { + else { sub_v3_v3v3(start_v, isect->next->p, gest->stk->points[0].p); sub_v3_v3v3(end_v, sk_lastStrokePoint(gest->stk)->p, isect->p); } angle = RAD2DEGF(angle_v2v2(start_v, end_v)); - if (angle > 120) - { + if (angle > 120) { return 1; } @@ -2087,11 +1897,9 @@ void sk_applyReverseGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UN { SK_Intersection *isect; - for (isect = gest->intersections.first; isect; isect = isect->next) - { + for (isect = gest->intersections.first; isect; isect = isect->next) { /* only reverse strokes that are crossed twice */ - if (isect->next && isect->next->stroke == isect->stroke) - { + if (isect->next && isect->next->stroke == isect->stroke) { sk_reverseStroke(isect->stroke); /* skip next */ @@ -2102,8 +1910,7 @@ void sk_applyReverseGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UN int sk_detectConvertGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch)) { - if (gest->nb_segments == 3 && gest->nb_self_intersections == 1) - { + if (gest->nb_segments == 3 && gest->nb_self_intersections == 1) { return 1; } return 0; @@ -2142,10 +1949,8 @@ static void sk_applyGesture(bContext *C, SK_Sketch *sketch) sk_initGesture(C, &gest, sketch); /* detect and apply */ - for (act = GESTURE_ACTIONS; act->apply != NULL; act++) - { - if (act->detect(C, &gest, sketch)) - { + for (act = GESTURE_ACTIONS; act->apply != NULL; act++) { + if (act->detect(C, &gest, sketch)) { act->apply(C, &gest, sketch); break; } @@ -2173,8 +1978,7 @@ static int sk_selectStroke(bContext *C, SK_Sketch *sketch, const int mval[2], in hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect); - if (hits>0) - { + if (hits>0) { int besthitresult = -1; if (hits == 1) { @@ -2185,18 +1989,15 @@ static int sk_selectStroke(bContext *C, SK_Sketch *sketch, const int mval[2], in /* loop and get best hit */ } - if (besthitresult > 0) - { + if (besthitresult > 0) { SK_Stroke *selected_stk = BLI_findlink(&sketch->strokes, besthitresult - 1); - if (extend == 0) - { + if (extend == 0) { sk_selectAllSketch(sketch, -1); selected_stk->selected = 1; } - else - { + else { selected_stk->selected ^= 1; } @@ -2232,50 +2033,41 @@ static void sk_drawSketch(Scene *scene, View3D *UNUSED(v3d), SK_Sketch *sketch, glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); - if (with_names) - { + if (with_names) { int id; - for (id = 1, stk = sketch->strokes.first; stk; id++, stk = stk->next) - { + for (id = 1, stk = sketch->strokes.first; stk; id++, stk = stk->next) { sk_drawStroke(stk, id, NULL, -1, -1); } glLoadName(-1); } - else - { + else { float selected_rgb[3] = {1, 0, 0}; float unselected_rgb[3] = {1, 0.5, 0}; - for (stk = sketch->strokes.first; stk; stk = stk->next) - { + for (stk = sketch->strokes.first; stk; stk = stk->next) { int start = -1; int end = -1; - if (sk_hasOverdraw(sketch, stk)) - { + if (sk_hasOverdraw(sketch, stk)) { sk_adjustIndexes(sketch, &start, &end); } sk_drawStroke(stk, -1, (stk->selected==1?selected_rgb:unselected_rgb), start, end); - if (stk->selected == 1) - { + if (stk->selected == 1) { sk_drawStrokeSubdivision(ts, stk); } } - if (sketch->active_stroke != NULL) - { + if (sketch->active_stroke != NULL) { SK_Point *last = sk_lastStrokePoint(sketch->active_stroke); - if (ts->bone_sketching & BONE_SKETCHING_QUICK) - { + if (ts->bone_sketching & BONE_SKETCHING_QUICK) { sk_drawStrokeSubdivision(ts, sketch->active_stroke); } - if (last != NULL) - { + if (last != NULL) { GLUquadric *quad = gluNewQuadric(); gluQuadricNormals(quad, GLU_SMOOTH); @@ -2284,8 +2076,7 @@ static void sk_drawSketch(Scene *scene, View3D *UNUSED(v3d), SK_Sketch *sketch, glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - switch (sketch->next_point.mode) - { + switch (sketch->next_point.mode) { case PT_SNAP: glColor3f(0, 1, 0); break; @@ -2345,8 +2136,7 @@ static void sk_drawSketch(Scene *scene, View3D *UNUSED(v3d), SK_Sketch *sketch, glDisable(GL_DEPTH_TEST); /* only draw gesture in active area */ - if (sketch->gesture != NULL /*&& area_is_active_area(G.vd->area)*/) - { + if (sketch->gesture != NULL /* && area_is_active_area(G.vd->area) */) { float gesture_rgb[3] = {0, 0.5, 1}; sk_drawStroke(sketch->gesture, -1, gesture_rgb, -1, -1); } @@ -2356,20 +2146,16 @@ static int sk_finish_stroke(bContext *C, SK_Sketch *sketch) { ToolSettings *ts = CTX_data_tool_settings(C); - if (sketch->active_stroke != NULL) - { + if (sketch->active_stroke != NULL) { SK_Stroke *stk = sketch->active_stroke; sk_endStroke(C, sketch); - if (ts->bone_sketching & BONE_SKETCHING_QUICK) - { - if (ts->bone_sketching_convert == SK_CONVERT_RETARGET) - { + if (ts->bone_sketching & BONE_SKETCHING_QUICK) { + if (ts->bone_sketching_convert == SK_CONVERT_RETARGET) { sk_retargetStroke(C, stk); } - else - { + else { sk_convertStroke(C, stk); } // XXX @@ -2389,8 +2175,7 @@ static int sk_finish_stroke(bContext *C, SK_Sketch *sketch) static void sk_start_draw_stroke(SK_Sketch *sketch) { - if (sketch->active_stroke == NULL) - { + if (sketch->active_stroke == NULL) { sk_startStroke(sketch); sk_selectAllSketch(sketch, -1); @@ -2405,8 +2190,7 @@ static void sk_start_draw_gesture(SK_Sketch *sketch) static int sk_draw_stroke(bContext *C, SK_Sketch *sketch, SK_Stroke *stk, SK_DrawData *dd, short snap) { - if (sk_stroke_filtermval(dd)) - { + if (sk_stroke_filtermval(dd)) { sk_addStrokePoint(C, sketch, stk, dd, snap); sk_updateDrawData(dd); sk_updateNextPoint(sketch, stk); @@ -2428,19 +2212,16 @@ static int ValidSketchViewContext(ViewContext *vc) { return 1; } - else - { + else { return 0; } } int BDR_drawSketchNames(ViewContext *vc) { - if (ValidSketchViewContext(vc)) - { + if (ValidSketchViewContext(vc)) { SK_Sketch *sketch = viewcontextSketch(vc, 0); - if (sketch) - { + if (sketch) { sk_drawSketch(vc->scene, vc->v3d, sketch, 1); return 1; } @@ -2451,11 +2232,9 @@ int BDR_drawSketchNames(ViewContext *vc) void BDR_drawSketch(const bContext *C) { - if (ED_operator_sketch_mode(C)) - { + if (ED_operator_sketch_mode(C)) { SK_Sketch *sketch = contextSketch(C, 0); - if (sketch) - { + if (sketch) { sk_drawSketch(CTX_data_scene(C), CTX_wm_view3d(C), sketch, 0); } } @@ -2464,8 +2243,7 @@ void BDR_drawSketch(const bContext *C) static int sketch_delete(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event)) { SK_Sketch *sketch = contextSketch(C, 0); - if (sketch) - { + if (sketch) { sk_deleteSelectedStrokes(sketch); // allqueue(REDRAWVIEW3D, 0); } @@ -2478,8 +2256,7 @@ void BIF_sk_selectStroke(bContext *C, const int mval[2], short extend) ToolSettings *ts = CTX_data_tool_settings(C); SK_Sketch *sketch = contextSketch(C, 0); - if (sketch != NULL && ts->bone_sketching & BONE_SKETCHING) - { + if (sketch != NULL && ts->bone_sketching & BONE_SKETCHING) { if (sk_selectStroke(C, sketch, mval, extend)) ED_area_tag_redraw(CTX_wm_area(C)); } @@ -2487,11 +2264,9 @@ void BIF_sk_selectStroke(bContext *C, const int mval[2], short extend) void BIF_convertSketch(bContext *C) { - if (ED_operator_sketch_full_mode(C)) - { + if (ED_operator_sketch_full_mode(C)) { SK_Sketch *sketch = contextSketch(C, 0); - if (sketch) - { + if (sketch) { sk_convert(C, sketch); // BIF_undo_push("Convert Sketch"); // allqueue(REDRAWVIEW3D, 0); @@ -2502,11 +2277,9 @@ void BIF_convertSketch(bContext *C) void BIF_deleteSketch(bContext *C) { - if (ED_operator_sketch_full_mode(C)) - { + if (ED_operator_sketch_full_mode(C)) { SK_Sketch *sketch = contextSketch(C, 0); - if (sketch) - { + if (sketch) { sk_deleteSelectedStrokes(sketch); // BIF_undo_push("Convert Sketch"); // allqueue(REDRAWVIEW3D, 0); @@ -2535,12 +2308,10 @@ SK_Sketch* contextSketch(const bContext *C, int create) Object *obedit = CTX_data_edit_object(C); SK_Sketch *sketch = NULL; - if (obedit && obedit->type == OB_ARMATURE) - { + if (obedit && obedit->type == OB_ARMATURE) { bArmature *arm = obedit->data; - if (arm->sketch == NULL && create) - { + if (arm->sketch == NULL && create) { arm->sketch = createSketch(); } sketch = arm->sketch; @@ -2554,12 +2325,10 @@ SK_Sketch* viewcontextSketch(ViewContext *vc, int create) Object *obedit = vc->obedit; SK_Sketch *sketch = NULL; - if (obedit && obedit->type == OB_ARMATURE) - { + if (obedit && obedit->type == OB_ARMATURE) { bArmature *arm = obedit->data; - if (arm->sketch == NULL && create) - { + if (arm->sketch == NULL && create) { arm->sketch = createSketch(); } sketch = arm->sketch; @@ -2571,8 +2340,7 @@ SK_Sketch* viewcontextSketch(ViewContext *vc, int create) static int sketch_convert(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event)) { SK_Sketch *sketch = contextSketch(C, 0); - if (sketch != NULL) - { + if (sketch != NULL) { sk_convert(C, sketch); ED_area_tag_redraw(CTX_wm_area(C)); } @@ -2582,8 +2350,7 @@ static int sketch_convert(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(e static int sketch_cancel(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event)) { SK_Sketch *sketch = contextSketch(C, 0); - if (sketch != NULL) - { + if (sketch != NULL) { sk_cancelStroke(sketch); ED_area_tag_redraw(CTX_wm_area(C)); return OPERATOR_FINISHED; @@ -2594,10 +2361,8 @@ static int sketch_cancel(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(ev static int sketch_finish(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event)) { SK_Sketch *sketch = contextSketch(C, 0); - if (sketch != NULL) - { - if (sk_finish_stroke(C, sketch)) - { + if (sketch != NULL) { + if (sk_finish_stroke(C, sketch)) { ED_area_tag_redraw(CTX_wm_area(C)); return OPERATOR_FINISHED; } @@ -2608,8 +2373,7 @@ static int sketch_finish(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(ev static int sketch_select(bContext *C, wmOperator *UNUSED(op), wmEvent *event) { SK_Sketch *sketch = contextSketch(C, 0); - if (sketch) - { + if (sketch) { short extend = 0; if (sk_selectStroke(C, sketch, event->mval, extend)) ED_area_tag_redraw(CTX_wm_area(C)); @@ -2677,8 +2441,7 @@ static int sketch_draw_modal(bContext *C, wmOperator *op, wmEvent *event, short SK_Sketch *sketch = contextSketch(C, 1); /* create just to be sure */ int retval = OPERATOR_RUNNING_MODAL; - switch (event->type) - { + switch (event->type) { case LEFTCTRLKEY: case RIGHTCTRLKEY: snap = event->ctrl; @@ -2697,10 +2460,8 @@ static int sketch_draw_modal(bContext *C, wmOperator *op, wmEvent *event, short retval = OPERATOR_CANCELLED; break; case LEFTMOUSE: - if (event->val == KM_RELEASE) - { - if (gesture == 0) - { + if (event->val == KM_RELEASE) { + if (gesture == 0) { sk_endContinuousStroke(stk); sk_filterLastContinuousStroke(stk); sk_updateNextPoint(sketch, stk); @@ -2708,13 +2469,11 @@ static int sketch_draw_modal(bContext *C, wmOperator *op, wmEvent *event, short MEM_freeN(op->customdata); retval = OPERATOR_FINISHED; } - else - { + else { sk_endContinuousStroke(stk); sk_filterLastContinuousStroke(stk); - if (stk->nb_points > 1) - { + if (stk->nb_points > 1) { /* apply gesture here */ sk_applyGesture(C, sketch); } @@ -2750,8 +2509,7 @@ static int sketch_draw_preview(bContext *C, wmOperator *op, wmEvent *event) short snap = RNA_boolean_get(op->ptr, "snap"); SK_Sketch *sketch = contextSketch(C, 0); - if (sketch) - { + if (sketch) { SK_DrawData dd; sk_initDrawData(&dd, event->mval); @@ -2775,8 +2533,7 @@ int ED_operator_sketch_mode_active_stroke(bContext *C) { return 1; } - else - { + else { return 0; } } @@ -2793,8 +2550,7 @@ static int ED_operator_sketch_mode_gesture(bContext *C) { return 1; } - else - { + else { return 0; } } @@ -2811,8 +2567,7 @@ int ED_operator_sketch_full_mode(bContext *C) { return 1; } - else - { + else { return 0; } } @@ -2828,8 +2583,7 @@ int ED_operator_sketch_mode(const bContext *C) { return 1; } - else - { + else { return 0; } } diff --git a/source/blender/editors/armature/poselib.c b/source/blender/editors/armature/poselib.c index 2799d7994bc..ea2b28380e0 100644 --- a/source/blender/editors/armature/poselib.c +++ b/source/blender/editors/armature/poselib.c @@ -897,10 +897,12 @@ static void poselib_apply_pose (tPoseLib_PreviewData *pld) } else if (pchan->bone) { /* only ok if bone is visible and selected */ - if ( (pchan->bone->flag & BONE_SELECTED) && - (pchan->bone->flag & BONE_HIDDEN_P)==0 && - (pchan->bone->layer & arm->layer) ) + if ((pchan->bone->flag & BONE_SELECTED) && + (pchan->bone->flag & BONE_HIDDEN_P) == 0 && + (pchan->bone->layer & arm->layer)) + { ok = 1; + } } if (ok) diff --git a/source/blender/editors/armature/reeb.c b/source/blender/editors/armature/reeb.c index 546bcb1f40f..f5e7770a7fc 100644 --- a/source/blender/editors/armature/reeb.c +++ b/source/blender/editors/armature/reeb.c @@ -183,16 +183,14 @@ void REEB_freeGraph(ReebGraph *rg) ReebNode *node; // free nodes - for ( node = rg->nodes.first; node; node = node->next ) - { + for (node = rg->nodes.first; node; node = node->next) { BLI_freeNode((BGraph*)rg, (BNode*)node); } BLI_freelistN(&rg->nodes); // free arcs arc = rg->arcs.first; - while ( arc ) - { + while ( arc ) { ReebArc *next = arc->next; REEB_freeArc((BArc*)arc); arc = next; @@ -202,8 +200,7 @@ void REEB_freeGraph(ReebGraph *rg) BLI_edgehash_free(rg->emap, NULL); /* free linked graph */ - if (rg->link_up) - { + if (rg->link_up) { REEB_freeGraph(rg->link_up); } @@ -229,8 +226,7 @@ ReebGraph * newReebGraph(void) void BIF_flagMultiArcs(ReebGraph *rg, int flag) { - for ( ; rg; rg = rg->link_up) - { + for ( ; rg; rg = rg->link_up) { BLI_flagArcs((BGraph*)rg, flag); } } @@ -318,8 +314,7 @@ ReebNode *BIF_NodeFromIndex(ReebArc *arc, ReebNode *node) ReebNode *BIF_lowestLevelNode(ReebNode *node) { - while (node->link_down) - { + while (node->link_down) { node = node->link_down; } @@ -407,8 +402,7 @@ ReebGraph *BIF_graphForMultiNode(ReebGraph *rg, ReebNode *node) { ReebGraph *multi_rg = rg; - while (multi_rg && multi_rg->multi_level != node->multi_level) - { + while (multi_rg && multi_rg->multi_level != node->multi_level) { multi_rg = multi_rg->link_up; } @@ -484,15 +478,12 @@ void repositionNodes(ReebGraph *rg) BNode *node = NULL; // Reset node positions - for (node = rg->nodes.first; node; node = node->next) - { + for (node = rg->nodes.first; node; node = node->next) { node->p[0] = node->p[1] = node->p[2] = 0; } - for (arc = rg->arcs.first; arc; arc = arc->next) - { - if (((ReebArc*)arc)->bcount > 0) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { + if (((ReebArc*)arc)->bcount > 0) { float p[3]; copy_v3_v3(p, ((ReebArc*)arc)->buckets[0].p); @@ -512,22 +503,17 @@ void verifyNodeDegree(ReebGraph *rg) ReebNode *node = NULL; ReebArc *arc = NULL; - for (node = rg->nodes.first; node; node = node->next) - { + for (node = rg->nodes.first; node; node = node->next) { int count = 0; - for (arc = rg->arcs.first; arc; arc = arc->next) - { - if (arc->head == node || arc->tail == node) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { + if (arc->head == node || arc->tail == node) { count++; } } - if (count != node->degree) - { + if (count != node->degree) { printf("degree error in node %i: expected %i got %i\n", node->index, count, node->degree); } - if (node->degree == 0) - { + if (node->degree == 0) { printf("zero degree node %i with weight %f\n", node->index, node->weight); } } @@ -539,25 +525,20 @@ static void verifyBucketsArc(ReebGraph *UNUSED(rg), ReebArc *arc) ReebNode *head = (ReebNode*)arc->head; ReebNode *tail = (ReebNode*)arc->tail; - if (arc->bcount > 0) - { + if (arc->bcount > 0) { int i; - for (i = 0; i < arc->bcount; i++) - { - if (arc->buckets[i].nv == 0) - { + for (i = 0; i < arc->bcount; i++) { + if (arc->buckets[i].nv == 0) { printArc(arc); printf("count error in bucket %i/%i\n", i+1, arc->bcount); } } - if (ceilf(head->weight) != arc->buckets[0].val) - { + if (ceilf(head->weight) != arc->buckets[0].val) { printArc(arc); printf("alloc error in first bucket: %f should be %f\n", arc->buckets[0].val, ceil(head->weight)); } - if (floorf(tail->weight) != arc->buckets[arc->bcount - 1].val) - { + if (floorf(tail->weight) != arc->buckets[arc->bcount - 1].val) { printArc(arc); printf("alloc error in last bucket: %f should be %f\n", arc->buckets[arc->bcount - 1].val, floor(tail->weight)); } @@ -568,8 +549,7 @@ void verifyBuckets(ReebGraph *rg) { #ifdef DEBUG_REEB ReebArc *arc = NULL; - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { verifyBucketsArc(rg, arc); } #endif @@ -580,8 +560,7 @@ void verifyFaces(ReebGraph *rg) #ifdef DEBUG_REEB int total = 0; ReebArc *arc = NULL; - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { total += BLI_ghash_size(arc->faces); } @@ -592,10 +571,8 @@ void verifyArcs(ReebGraph *rg) { ReebArc *arc; - for (arc = rg->arcs.first; arc; arc = arc->next) - { - if (arc->head->weight > arc->tail->weight) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { + if (arc->head->weight > arc->tail->weight) { printf("FLIPPED ARC!\n"); } } @@ -606,14 +583,11 @@ static void verifyMultiResolutionLinks(ReebGraph *rg, int level) #ifdef DEBUG_REEB ReebGraph *lower_rg = rg->link_up; - if (lower_rg) - { + if (lower_rg) { ReebArc *arc; - for (arc = rg->arcs.first; arc; arc = arc->next) - { - if (BLI_findindex(&lower_rg->arcs, arc->link_up) == -1) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { + if (BLI_findindex(&lower_rg->arcs, arc->link_up) == -1) { printf("missing arc %p for level %i\n", (void *)arc->link_up, level); printf("Source arc was ---\n"); printArc(arc); @@ -647,13 +621,11 @@ static void removeVertFromBucket(EmbedBucket *b, float co[3]) static void mergeBuckets(EmbedBucket *bDst, EmbedBucket *bSrc) { - if (bDst->nv > 0 && bSrc->nv > 0) - { + if (bDst->nv > 0 && bSrc->nv > 0) { bDst->nv += bSrc->nv; interp_v3_v3v3(bDst->p, bDst->p, bSrc->p, (float)bSrc->nv / (float)(bDst->nv)); } - else if (bSrc->nv > 0) - { + else if (bSrc->nv > 0) { bDst->nv = bSrc->nv; copy_v3_v3(bDst->p, bSrc->p); } @@ -661,19 +633,16 @@ static void mergeBuckets(EmbedBucket *bDst, EmbedBucket *bSrc) static void mergeArcBuckets(ReebArc *aDst, ReebArc *aSrc, float start, float end) { - if (aDst->bcount > 0 && aSrc->bcount > 0) - { + if (aDst->bcount > 0 && aSrc->bcount > 0) { int indexDst = 0, indexSrc = 0; start = MAX3(start, aDst->buckets[0].val, aSrc->buckets[0].val); - while (indexDst < aDst->bcount && aDst->buckets[indexDst].val < start) - { + while (indexDst < aDst->bcount && aDst->buckets[indexDst].val < start) { indexDst++; } - while (indexSrc < aSrc->bcount && aSrc->buckets[indexSrc].val < start) - { + while (indexSrc < aSrc->bcount && aSrc->buckets[indexSrc].val < start) { indexSrc++; } @@ -693,8 +662,7 @@ void flipArcBuckets(ReebArc *arc) { int i, j; - for (i = 0, j = arc->bcount - 1; i < j; i++, j--) - { + for (i = 0, j = arc->bcount - 1; i < j; i++, j--) { EmbedBucket tmp; tmp = arc->buckets[i]; @@ -714,20 +682,16 @@ static void allocArcBuckets(ReebArc *arc) float start = ceil(arc->head->weight); arc->bcount = countArcBuckets(arc); - if (arc->bcount > 0) - { + if (arc->bcount > 0) { arc->buckets = MEM_callocN(sizeof(EmbedBucket) * arc->bcount, "embed bucket"); - for (i = 0; i < arc->bcount; i++) - { + for (i = 0; i < arc->bcount; i++) { arc->buckets[i].val = start + i; } } - else - { + else { arc->buckets = NULL; } - } static void resizeArcBuckets(ReebArc *arc) @@ -735,15 +699,13 @@ static void resizeArcBuckets(ReebArc *arc) EmbedBucket *oldBuckets = arc->buckets; int oldBCount = arc->bcount; - if (countArcBuckets(arc) == oldBCount) - { + if (countArcBuckets(arc) == oldBCount) { return; } allocArcBuckets(arc); - if (oldBCount != 0 && arc->bcount != 0) - { + if (oldBCount != 0 && arc->bcount != 0) { int oldStart = (int)oldBuckets[0].val; int oldEnd = (int)oldBuckets[oldBCount - 1].val; int newStart = (int)arc->buckets[0].val; @@ -752,12 +714,10 @@ static void resizeArcBuckets(ReebArc *arc) int newOffset = 0; int len; - if (oldStart < newStart) - { + if (oldStart < newStart) { oldOffset = newStart - oldStart; } - else - { + else { newOffset = oldStart - newStart; } @@ -766,8 +726,7 @@ static void resizeArcBuckets(ReebArc *arc) memcpy(arc->buckets + newOffset, oldBuckets + oldOffset, len * sizeof(EmbedBucket)); } - if (oldBuckets != NULL) - { + if (oldBuckets != NULL) { MEM_freeN(oldBuckets); } } @@ -777,10 +736,8 @@ static void reweightBuckets(ReebArc *arc) int i; float start = ceil((arc->head)->weight); - if (arc->bcount > 0) - { - for (i = 0; i < arc->bcount; i++) - { + if (arc->bcount > 0) { + for (i = 0; i < arc->bcount; i++) { arc->buckets[i].val = start + i; } } @@ -793,8 +750,7 @@ static void interpolateBuckets(ReebArc *arc, float *start_p, float *end_p, int s total = end_index - start_index + 2; - for (j = start_index; j <= end_index; j++) - { + for (j = start_index; j <= end_index; j++) { EmbedBucket *empty = arc->buckets + j; empty->nv = 1; interp_v3_v3v3(empty->p, start_p, end_p, (float)(j - start_index + 1) / total); @@ -810,14 +766,11 @@ static void fillArcEmptyBuckets(ReebArc *arc) start_p = arc->head->p; - for (i = 0; i < arc->bcount; i++) - { + for (i = 0; i < arc->bcount; i++) { EmbedBucket *bucket = arc->buckets + i; - if (missing) - { - if (bucket->nv > 0) - { + if (missing) { + if (bucket->nv > 0) { missing = 0; end_p = bucket->p; @@ -826,14 +779,11 @@ static void fillArcEmptyBuckets(ReebArc *arc) interpolateBuckets(arc, start_p, end_p, start_index, end_index); } } - else - { - if (bucket->nv == 0) - { + else { + if (bucket->nv == 0) { missing = 1; - if (i > 0) - { + if (i > 0) { start_p = arc->buckets[i - 1].p; } start_index = i; @@ -841,8 +791,7 @@ static void fillArcEmptyBuckets(ReebArc *arc) } } - if (missing) - { + if (missing) { end_p = arc->tail->p; end_index = arc->bcount - 1; @@ -859,8 +808,7 @@ static void ExtendArcBuckets(ReebArc *arc) float average_length = 0, length; int padding_head = 0, padding_tail = 0; - if (arc->bcount == 0) - { + if (arc->bcount == 0) { return; /* failsafe, shouldn't happen */ } @@ -881,19 +829,16 @@ static void ExtendArcBuckets(ReebArc *arc) last_bucket = arc->buckets + (arc->bcount - 1); length = len_v3v3(first_bucket->p, arc->head->p); - if (length > 2 * average_length) - { + if (length > 2 * average_length) { padding_head = (int)floor(length / average_length); } length = len_v3v3(last_bucket->p, arc->tail->p); - if (length > 2 * average_length) - { + if (length > 2 * average_length) { padding_tail = (int)floor(length / average_length); } - if (padding_head + padding_tail > 0) - { + if (padding_head + padding_tail > 0) { EmbedBucket *old_buckets = arc->buckets; arc->buckets = MEM_callocN(sizeof(EmbedBucket) * (padding_head + arc->bcount + padding_tail), "embed bucket"); @@ -904,13 +849,11 @@ static void ExtendArcBuckets(ReebArc *arc) MEM_freeN(old_buckets); } - if (padding_head > 0) - { + if (padding_head > 0) { interpolateBuckets(arc, arc->head->p, first_bucket->p, 0, padding_head); } - if (padding_tail > 0) - { + if (padding_tail > 0) { interpolateBuckets(arc, last_bucket->p, arc->tail->p, arc->bcount - padding_tail, arc->bcount - 1); } } @@ -920,8 +863,7 @@ static void extendGraphBuckets(ReebGraph *rg) { ReebArc *arc; - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { ExtendArcBuckets(arc); } } @@ -941,8 +883,7 @@ static void calculateArcLength(ReebArc *arc) vec0 = arc->head->p; vec1 = arc->head->p; /* in case there's no embedding */ - while (IT_next(iter)) - { + while (IT_next(iter)) { vec1 = iter->p; arc->length += len_v3v3(vec0, vec1); @@ -957,8 +898,7 @@ static void calculateGraphLength(ReebGraph *rg) { ReebArc *arc; - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { calculateArcLength(arc); } } @@ -975,8 +915,7 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) copy_v3_v3(axis, root_node->symmetry_axis); /* first pass, merge incrementally */ - for (i = 0; i < count - 1; i++) - { + for (i = 0; i < count - 1; i++) { ReebNode *node1, *node2; ReebArc *arc1, *arc2; float tangent[3]; @@ -999,8 +938,7 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) /* Merge buckets * there shouldn't be any null arcs here, but just to be safe * */ - if (arc1->bcount > 0 && arc2->bcount > 0) - { + if (arc1->bcount > 0 && arc2->bcount > 0) { ReebArcIterator arc_iter1, arc_iter2; BArcIterator *iter1 = (BArcIterator*)&arc_iter1; BArcIterator *iter2 = (BArcIterator*)&arc_iter2; @@ -1013,19 +951,16 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) bucket2 = IT_next(iter2); /* Make sure they both start at the same value */ - while (bucket1 && bucket2 && bucket1->val < bucket2->val) - { + while (bucket1 && bucket2 && bucket1->val < bucket2->val) { bucket1 = IT_next(iter1); } - while (bucket1 && bucket2 && bucket2->val < bucket1->val) - { + while (bucket1 && bucket2 && bucket2->val < bucket1->val) { bucket2 = IT_next(iter2); } - for ( ;bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) - { + for ( ;bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) { bucket2->nv += bucket1->nv; /* add counts */ /* mirror on axis */ @@ -1037,8 +972,7 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) } /* second pass, mirror back on previous arcs */ - for (i = count - 1; i > 0; i--) - { + for (i = count - 1; i > 0; i--) { ReebNode *node1, *node2; ReebArc *arc1, *arc2; float tangent[3]; @@ -1061,8 +995,7 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) /* Copy buckets * there shouldn't be any null arcs here, but just to be safe * */ - if (arc1->bcount > 0 && arc2->bcount > 0) - { + if (arc1->bcount > 0 && arc2->bcount > 0) { ReebArcIterator arc_iter1, arc_iter2; BArcIterator *iter1 = (BArcIterator*)&arc_iter1; BArcIterator *iter2 = (BArcIterator*)&arc_iter2; @@ -1075,19 +1008,16 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) bucket2 = IT_next(iter2); /* Make sure they both start at the same value */ - while (bucket1 && bucket1->val < bucket2->val) - { + while (bucket1 && bucket1->val < bucket2->val) { bucket1 = IT_next(iter1); } - while (bucket2 && bucket2->val < bucket1->val) - { + while (bucket2 && bucket2->val < bucket1->val) { bucket2 = IT_next(iter2); } - for ( ;bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) - { + for ( ;bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) { /* copy and mirror back to bucket2 */ bucket2->nv = bucket1->nv; copy_v3_v3(bucket2->p, bucket1->p); @@ -1122,8 +1052,7 @@ void REEB_AxialSymmetry(BNode* root_node, BNode* node1, BNode* node2, struct BAr /* Merge buckets * there shouldn't be any null arcs here, but just to be safe * */ - if (arc1->bcount > 0 && arc2->bcount > 0) - { + if (arc1->bcount > 0 && arc2->bcount > 0) { ReebArcIterator arc_iter1, arc_iter2; BArcIterator *iter1 = (BArcIterator*)&arc_iter1; BArcIterator *iter2 = (BArcIterator*)&arc_iter2; @@ -1136,19 +1065,16 @@ void REEB_AxialSymmetry(BNode* root_node, BNode* node1, BNode* node2, struct BAr bucket2 = IT_next(iter2); /* Make sure they both start at the same value */ - while (bucket1 && bucket1->val < bucket2->val) - { + while (bucket1 && bucket1->val < bucket2->val) { bucket1 = IT_next(iter1); } - while (bucket2 && bucket2->val < bucket1->val) - { + while (bucket2 && bucket2->val < bucket1->val) { bucket2 = IT_next(iter2); } - for ( ;bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) - { + for ( ; bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) { bucket1->nv += bucket2->nv; /* add counts */ /* mirror on axis */ @@ -1175,7 +1101,7 @@ void postprocessGraph(ReebGraph *rg, char mode) ReebArc *arc; float fac1 = 0, fac2 = 1, fac3 = 0; - switch(mode) + switch (mode) { case SKGEN_AVERAGE: fac1 = fac2 = fac3 = 1.0f / 3.0f; @@ -1490,16 +1416,13 @@ static int compareArcs(void *varc1, void *varc2) float len1 = lengthArc(arc1); float len2 = lengthArc(arc2); - if (len1 < len2) - { + if (len1 < len2) { return -1; } - if (len1 > len2) - { + if (len1 > len2) { return 1; } - else - { + else { return 0; } } @@ -1508,13 +1431,10 @@ static void filterArc(ReebGraph *rg, ReebNode *newNode, ReebNode *removedNode, R { ReebArc *arc = NULL, *nextArc = NULL; - if (merging) - { + if (merging) { /* first pass, merge buckets for arcs that spawned the two nodes into the source arc*/ - for (arc = rg->arcs.first; arc; arc = arc->next) - { - if (arc->head == srcArc->head && arc->tail == srcArc->tail && arc != srcArc) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { + if (arc->head == srcArc->head && arc->tail == srcArc->tail && arc != srcArc) { ReebNode *head = srcArc->head; ReebNode *tail = srcArc->tail; mergeArcBuckets(srcArc, arc, head->weight, tail->weight); @@ -1524,47 +1444,38 @@ static void filterArc(ReebGraph *rg, ReebNode *newNode, ReebNode *removedNode, R /* second pass, replace removedNode by newNode, remove arcs that are collapsed in a loop */ arc = rg->arcs.first; - while (arc) - { + while (arc) { nextArc = arc->next; - if (arc->head == removedNode || arc->tail == removedNode) - { - if (arc->head == removedNode) - { + if (arc->head == removedNode || arc->tail == removedNode) { + if (arc->head == removedNode) { arc->head = newNode; } - else - { + else { arc->tail = newNode; } // Remove looped arcs - if (arc->head == arc->tail) - { + if (arc->head == arc->tail) { // v1 or v2 was already newNode, since we're removing an arc, decrement degree NodeDegreeDecrement(rg, newNode); // If it's srcArc, it'll be removed later, so keep it for now - if (arc != srcArc) - { + if (arc != srcArc) { BLI_remlink(&rg->arcs, arc); REEB_freeArc((BArc*)arc); } } - else - { + else { /* flip arcs that flipped, can happen on diamond shapes, mostly on null arcs */ - if (arc->head->weight > arc->tail->weight) - { + if (arc->head->weight > arc->tail->weight) { flipArc(arc); } //newNode->degree++; // incrementing degree since we're adding an arc NodeDegreeIncrement(rg, newNode); mergeArcFaces(rg, arc, srcArc); - if (merging) - { + if (merging) { ReebNode *head = arc->head; ReebNode *tail = arc->tail; @@ -1587,12 +1498,10 @@ void filterNullReebGraph(ReebGraph *rg) ReebArc *arc = NULL, *nextArc = NULL; arc = rg->arcs.first; - while (arc) - { + while (arc) { nextArc = arc->next; // Only collapse arcs too short to have any embed bucket - if (arc->bcount == 0) - { + if (arc->bcount == 0) { ReebNode *newNode = (ReebNode*)arc->head; ReebNode *removedNode = (ReebNode*)arc->tail; float blend; @@ -1623,12 +1532,14 @@ static int filterInternalExternalReebGraph(ReebGraph *rg, float threshold_intern BLI_sortlist(&rg->arcs, compareArcs); - for (arc = rg->arcs.first; arc; arc = nextArc) - { + for (arc = rg->arcs.first; arc; arc = nextArc) { nextArc = arc->next; - // Only collapse non-terminal arcs that are shorter than threshold - if (threshold_internal > 0 && arc->head->degree > 1 && arc->tail->degree > 1 && (lengthArc(arc) < threshold_internal)) + /* Only collapse non-terminal arcs that are shorter than threshold */ + if ((threshold_internal > 0) && + (arc->head->degree > 1) && + (arc->tail->degree > 1) && + (lengthArc(arc) < threshold_internal)) { ReebNode *newNode = NULL; ReebNode *removedNode = NULL; @@ -1650,26 +1561,25 @@ static int filterInternalExternalReebGraph(ReebGraph *rg, float threshold_intern } // Only collapse terminal arcs that are shorter than threshold - else if (threshold_external > 0 && (arc->head->degree == 1 || arc->tail->degree == 1) && (lengthArc(arc) < threshold_external)) + else if ((threshold_external > 0) && + (arc->head->degree == 1 || arc->tail->degree == 1) && + (lengthArc(arc) < threshold_external)) { ReebNode *terminalNode = NULL; ReebNode *middleNode = NULL; ReebNode *removedNode = NULL; // Assign terminal and middle nodes - if (arc->head->degree == 1) - { + if (arc->head->degree == 1) { terminalNode = arc->head; middleNode = arc->tail; } - else - { + else { terminalNode = arc->tail; middleNode = arc->head; } - if (middleNode->degree == 2 && middleNode != rg->nodes.first) - { + if (middleNode->degree == 2 && middleNode != rg->nodes.first) { #if 1 // If middle node is a normal node, it will be removed later // Only if middle node is not the root node @@ -1685,8 +1595,7 @@ static int filterInternalExternalReebGraph(ReebGraph *rg, float threshold_intern #endif } // Otherwise, just plain remove of the arc - else - { + else { removedNode = terminalNode; // removing arc, so we need to decrease the degree of the remaining node @@ -1713,13 +1622,10 @@ static int filterCyclesReebGraph(ReebGraph *rg, float UNUSED(distance_threshold) ReebArc *next2; int filtered = 0; - for (arc1 = rg->arcs.first; arc1; arc1 = arc1->next) - { - for (arc2 = arc1->next; arc2; arc2 = next2) - { + for (arc1 = rg->arcs.first; arc1; arc1 = arc1->next) { + for (arc2 = arc1->next; arc2; arc2 = next2) { next2 = arc2->next; - if (arc1 != arc2 && arc1->head == arc2->head && arc1->tail == arc2->tail) - { + if (arc1 != arc2 && arc1->head == arc2->head && arc1->tail == arc2->tail) { mergeArcEdges(rg, arc1, arc2, MERGE_APPEND); mergeArcFaces(rg, arc1, arc2); mergeArcBuckets(arc1, arc2, arc1->head->weight, arc1->tail->weight); @@ -1848,8 +1754,7 @@ int filterSmartReebGraph(ReebGraph *UNUSED(rg), float UNUSED(threshold)) if (avg_angle > threshold) merging = 1; - if (merging) - { + if (merging) { ReebNode *terminalNode = NULL; ReebNode *middleNode = NULL; ReebNode *newNode = NULL; @@ -1857,39 +1762,33 @@ int filterSmartReebGraph(ReebGraph *UNUSED(rg), float UNUSED(threshold)) int merging = 0; // Assign terminal and middle nodes - if (arc->head->degree == 1) - { + if (arc->head->degree == 1) { terminalNode = arc->head; middleNode = arc->tail; } - else - { + else { terminalNode = arc->tail; middleNode = arc->head; } // If middle node is a normal node, merge to terminal node - if (middleNode->degree == 2) - { + if (middleNode->degree == 2) { merging = 1; newNode = terminalNode; removedNode = middleNode; } // Otherwise, just plain remove of the arc - else - { + else { merging = 0; newNode = middleNode; removedNode = terminalNode; } // Merging arc - if (merging) - { + if (merging) { filterArc(rg, newNode, removedNode, arc, 1); } - else - { + else { // removing arc, so we need to decrease the degree of the remaining node //newNode->degree--; NodeDegreeDecrement(rg, newNode); @@ -1920,29 +1819,24 @@ static void filterGraph(ReebGraph *rg, short options, float threshold_internal, calculateGraphLength(rg); - if ((options & SKGEN_FILTER_EXTERNAL) == 0) - { + if ((options & SKGEN_FILTER_EXTERNAL) == 0) { threshold_external = 0; } - if ((options & SKGEN_FILTER_INTERNAL) == 0) - { + if ((options & SKGEN_FILTER_INTERNAL) == 0) { threshold_internal = 0; } - if (threshold_internal > 0 || threshold_external > 0) - { + if (threshold_internal > 0 || threshold_external > 0) { /* filter until there's nothing more to do */ - while (done == 1) - { + while (done == 1) { done = 0; /* no work done yet */ done = filterInternalExternalReebGraph(rg, threshold_internal, threshold_external); } } - if (options & SKGEN_FILTER_SMART) - { + if (options & SKGEN_FILTER_SMART) { filterSmartReebGraph(rg, 0.5); filterCyclesReebGraph(rg, 0.5); } @@ -1963,8 +1857,7 @@ static void finalizeGraph(ReebGraph *rg, char passes, char method) sortArcs(rg); - for (i = 0; i < passes; i++) - { + for (i = 0; i < passes; i++) { postprocessGraph(rg, method); } @@ -1979,12 +1872,10 @@ static int compareVerts( const void* a, const void* b ) EditVert *vb = *(EditVert**)b; int value = 0; - if (weightData(va) < weightData(vb)) - { + if (weightData(va) < weightData(vb)) { value = -1; } - else if (weightData(va) > weightData(vb)) - { + else if (weightData(va) > weightData(vb)) { value = 1; } @@ -2001,26 +1892,21 @@ static void spreadWeight(EditMesh *em) verts = MEM_callocN(sizeof(EditVert*) * totvert, "verts array"); - for (eve = em->verts.first, i = 0; eve; eve = eve->next, i++) - { + for (eve = em->verts.first, i = 0; eve; eve = eve->next, i++) { verts[i] = eve; } - while (work_needed == 1) - { + while (work_needed == 1) { work_needed = 0; qsort(verts, totvert, sizeof(EditVert*), compareVerts); - for (i = 0; i < totvert; i++) - { + for (i = 0; i < totvert; i++) { eve = verts[i]; - if (i == 0 || (weightData(eve) - lastWeight) > FLT_EPSILON) - { + if (i == 0 || (weightData(eve) - lastWeight) > FLT_EPSILON) { lastWeight = weightData(eve); } - else - { + else { work_needed = 1; weightSetData(eve, lastWeight + FLT_EPSILON * 2); lastWeight = weightData(eve); @@ -2044,8 +1930,7 @@ void REEB_exportGraph(ReebGraph *rg, int count) char filename[128]; FILE *f; - if (count == -1) - { + if (count == -1) { strcpy(filename, "test.txt"); } else { @@ -2053,15 +1938,13 @@ void REEB_exportGraph(ReebGraph *rg, int count) } f = BLI_fopen(filename, "w"); - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { int i; float p[3]; exportNode(f, "v1", arc->head); - for (i = 0; i < arc->bcount; i++) - { + for (i = 0; i < arc->bcount; i++) { fprintf(f, "b nv:%i %f %f %f\n", arc->buckets[i].nv, arc->buckets[i].p[0], arc->buckets[i].p[1], arc->buckets[i].p[2]); } @@ -2082,12 +1965,10 @@ static void removeZeroNodes(ReebGraph *rg) { ReebNode *node, *next_node; - for (node = rg->nodes.first; node; node = next_node) - { + for (node = rg->nodes.first; node; node = next_node) { next_node = node->next; - if (node->degree == 0) - { + if (node->degree == 0) { BLI_removeNode((BGraph*)rg, (BNode*)node); } } @@ -2098,63 +1979,51 @@ void removeNormalNodes(ReebGraph *rg) ReebArc *arc, *nextArc; // Merge degree 2 nodes - for (arc = rg->arcs.first; arc; arc = nextArc) - { + for (arc = rg->arcs.first; arc; arc = nextArc) { nextArc = arc->next; - while (arc->head->degree == 2 || arc->tail->degree == 2) - { + while (arc->head->degree == 2 || arc->tail->degree == 2) { // merge at v1 - if (arc->head->degree == 2) - { + if (arc->head->degree == 2) { ReebArc *connectedArc = (ReebArc*)BLI_findConnectedArc((BGraph*)rg, (BArc*)arc, (BNode*)arc->head); /* If arcs are one after the other */ - if (arc->head == connectedArc->tail) - { + if (arc->head == connectedArc->tail) { /* remove furthest arc */ - if (arc->tail->weight < connectedArc->head->weight) - { + if (arc->tail->weight < connectedArc->head->weight) { mergeConnectedArcs(rg, arc, connectedArc); nextArc = arc->next; } - else - { + else { mergeConnectedArcs(rg, connectedArc, arc); break; /* arc was removed, move to next */ } } /* Otherwise, arcs are side by side */ - else - { + else { /* Don't do anything, we need to keep the lowest node, even if degree 2 */ break; } } - // merge at v2 - if (arc->tail->degree == 2) - { + /* merge at v2 */ + if (arc->tail->degree == 2) { ReebArc *connectedArc = (ReebArc*)BLI_findConnectedArc((BGraph*)rg, (BArc*)arc, (BNode*)arc->tail); /* If arcs are one after the other */ - if (arc->tail == connectedArc->head) - { + if (arc->tail == connectedArc->head) { /* remove furthest arc */ - if (arc->head->weight < connectedArc->tail->weight) - { + if (arc->head->weight < connectedArc->tail->weight) { mergeConnectedArcs(rg, arc, connectedArc); nextArc = arc->next; } - else - { + else { mergeConnectedArcs(rg, connectedArc, arc); break; /* arc was removed, move to next */ } } /* Otherwise, arcs are side by side */ - else - { + else { /* Don't do anything, we need to keep the lowest node, even if degree 2 */ break; } @@ -2176,13 +2045,11 @@ static ReebArc *nextArcMappedToEdge(ReebArc *arc, ReebEdge *e) ReebArc *result = NULL; /* Find the ReebEdge in the edge list */ - for (edge = arc->edges.first; edge && !edgeEquals(edge, e); edge = edge->next) - { } + for (edge = arc->edges.first; edge && !edgeEquals(edge, e); edge = edge->next) { } nextEdge = edge->nextEdge; - if (nextEdge != NULL) - { + if (nextEdge != NULL) { result = nextEdge->arc; } @@ -2211,51 +2078,42 @@ void mergeArcEdges(ReebGraph *rg, ReebArc *aDst, ReebArc *aSrc, MergeDirection d { ReebEdge *e = NULL; - if (direction == MERGE_APPEND) - { - for (e = aSrc->edges.first; e; e = e->next) - { + if (direction == MERGE_APPEND) { + for (e = aSrc->edges.first; e; e = e->next) { e->arc = aDst; // Edge is stolen by new arc } BLI_movelisttolist(&aDst->edges , &aSrc->edges); } - else - { - for (e = aSrc->edges.first; e; e = e->next) - { + else { + for (e = aSrc->edges.first; e; e = e->next) { ReebEdge *newEdge = copyEdge(e); newEdge->arc = aDst; BLI_addtail(&aDst->edges, newEdge); - if (direction == MERGE_LOWER) - { + if (direction == MERGE_LOWER) { void **p = BLI_edgehash_lookup_p(rg->emap, e->v1->index, e->v2->index); newEdge->nextEdge = e; // if edge was the first in the list, point the edit edge to the new reeb edge instead. - if (*p == e) - { + if (*p == e) { *p = (void*)newEdge; } // otherwise, advance in the list until the predecessor is found then insert it there - else - { + else { ReebEdge *previous = (ReebEdge*)*p; - while (previous->nextEdge != e) - { + while (previous->nextEdge != e) { previous = previous->nextEdge; } previous->nextEdge = newEdge; } } - else - { + else { newEdge->nextEdge = e->nextEdge; e->nextEdge = newEdge; } @@ -2275,13 +2133,11 @@ int mergeConnectedArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) mergeArcFaces(rg, a0, a1); // Bring a0 to the combine length of both arcs - if (a0->tail == a1->head) - { + if (a0->tail == a1->head) { removedNode = a0->tail; a0->tail = a1->tail; } - else if (a0->head == a1->tail) - { + else if (a0->head == a1->tail) { removedNode = a0->head; a0->head = a1->head; } @@ -2303,11 +2159,9 @@ int mergeConnectedArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) { int result = 0; - // TRIANGLE POINTS DOWN - if (a0->head->weight == a1->head->weight) // heads are the same - { - if (a0->tail->weight == a1->tail->weight) // tails also the same, arcs can be totally merge together - { + /* TRIANGLE POINTS DOWN */ + if (a0->head->weight == a1->head->weight) { /* heads are the same */ + if (a0->tail->weight == a1->tail->weight) { /* tails also the same, arcs can be totally merge together */ mergeArcEdges(rg, a0, a1, MERGE_APPEND); mergeArcFaces(rg, a0, a1); @@ -2325,8 +2179,7 @@ int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) REEB_freeArc((BArc*)a1); result = 1; } - else if (a0->tail->weight > a1->tail->weight) // a1->tail->weight is in the middle - { + else if (a0->tail->weight > a1->tail->weight) { /* a1->tail->weight is in the middle */ mergeArcEdges(rg, a1, a0, MERGE_LOWER); mergeArcFaces(rg, a1, a0); @@ -2340,8 +2193,7 @@ int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) a0->head = a1->tail; resizeArcBuckets(a0); } - else // a0>n2 is in the middle - { + else { /* a0>n2 is in the middle */ mergeArcEdges(rg, a0, a1, MERGE_LOWER); mergeArcFaces(rg, a0, a1); @@ -2356,11 +2208,9 @@ int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) resizeArcBuckets(a1); } } - // TRIANGLE POINTS UP - else if (a0->tail->weight == a1->tail->weight) // tails are the same - { - if (a0->head->weight > a1->head->weight) // a0->head->weight is in the middle - { + /* TRIANGLE POINTS UP */ + else if (a0->tail->weight == a1->tail->weight) { /* tails are the same */ + if (a0->head->weight > a1->head->weight) { /* a0->head->weight is in the middle */ mergeArcEdges(rg, a0, a1, MERGE_HIGHER); mergeArcFaces(rg, a0, a1); @@ -2374,8 +2224,7 @@ int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) a1->tail = a0->head; resizeArcBuckets(a1); } - else // a1->head->weight is in the middle - { + else { /* a1->head->weight is in the middle */ mergeArcEdges(rg, a1, a0, MERGE_HIGHER); mergeArcFaces(rg, a1, a0); @@ -2390,9 +2239,8 @@ int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) resizeArcBuckets(a0); } } - else - { - // Need something here (OR NOT) + else { + /* Need something here (OR NOT) */ } return result; @@ -2401,18 +2249,14 @@ int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) static void glueByMergeSort(ReebGraph *rg, ReebArc *a0, ReebArc *a1, ReebEdge *e0, ReebEdge *e1) { int total = 0; - while (total == 0 && a0 != a1 && a0 != NULL && a1 != NULL) - { + while (total == 0 && a0 != a1 && a0 != NULL && a1 != NULL) { total = mergeArcs(rg, a0, a1); - if (total == 0) // if it wasn't a total merge, go forward - { - if (a0->tail->weight < a1->tail->weight) - { + if (total == 0) // if it wasn't a total merge, go forward { + if (a0->tail->weight < a1->tail->weight) { a0 = nextArcMappedToEdge(a0, e0); } - else - { + else { a1 = nextArcMappedToEdge(a1, e1); } } @@ -2437,8 +2281,7 @@ static ReebEdge * createArc(ReebGraph *rg, ReebNode *node1, ReebNode *node2) edge = BLI_edgehash_lookup(rg->emap, node1->index, node2->index); // Only add existing edges that haven't been added yet - if (edge == NULL) - { + if (edge == NULL) { ReebArc *arc; ReebNode *v1, *v2; float len, offset; @@ -2451,13 +2294,11 @@ static ReebEdge * createArc(ReebGraph *rg, ReebNode *node1, ReebNode *node2) arc->symmetry_level = 0; arc->faces = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "createArc gh"); - if (node1->weight <= node2->weight) - { + if (node1->weight <= node2->weight) { v1 = node1; v2 = node2; } - else - { + else { v1 = node2; v2 = node1; } @@ -2497,8 +2338,7 @@ static ReebEdge * createArc(ReebGraph *rg, ReebNode *node1, ReebNode *node2) addVertToBucket(&(arc->buckets[arc->bcount - 1]), arc->tail->co); } #else - for (i = 0; i < arc->bcount; i++) - { + for (i = 0; i < arc->bcount; i++) { float co[3]; float f = (arc->buckets[i].val - offset) / len; @@ -2532,20 +2372,17 @@ static void addTriangleToGraph(ReebGraph *rg, ReebNode * n1, ReebNode * n2, Reeb /* The rest of the algorithm assumes that e1 is the longest edge */ - if (len1 >= len2 && len1 >= len3) - { + if (len1 >= len2 && len1 >= len3) { e1 = re1; e2 = re2; e3 = re3; } - else if (len2 >= len1 && len2 >= len3) - { + else if (len2 >= len1 && len2 >= len3) { e1 = re2; e2 = re1; e3 = re3; } - else - { + else { e1 = re3; e2 = re2; e3 = re1; @@ -2554,8 +2391,7 @@ static void addTriangleToGraph(ReebGraph *rg, ReebNode * n1, ReebNode * n2, Reeb /* And e2 is the lowest edge * If e3 is lower than e2, swap them */ - if (e3->v1->weight < e2->v1->weight) - { + if (e3->v1->weight < e2->v1->weight) { ReebEdge *etmp = e2; e2 = e3; e3 = etmp; @@ -2595,10 +2431,8 @@ ReebGraph * generateReebGraph(EditMesh *em, int subdivisions) renormalizeWeight(em, (float)rg->resolution); /* Adding vertice */ - for (index = 0, eve = em->verts.first; eve; eve = eve->next) - { - if (eve->h == 0) - { + for (index = 0, eve = em->verts.first; eve; eve = eve->next) { + if (eve->h == 0) { addNode(rg, eve); eve->f2 = 0; index++; @@ -2606,10 +2440,8 @@ ReebGraph * generateReebGraph(EditMesh *em, int subdivisions) } /* Adding face, edge per edge */ - for (efa = em->faces.first; efa; efa = efa->next) - { - if (efa->h == 0) - { + for (efa = em->faces.first; efa; efa = efa->next) { + if (efa->h == 0) { ReebNode *n1, *n2, *n3; n1 = nodeData(efa->v1); @@ -2618,15 +2450,13 @@ ReebGraph * generateReebGraph(EditMesh *em, int subdivisions) addTriangleToGraph(rg, n1, n2, n3, efa); - if (efa->v4) - { + if (efa->v4) { ReebNode *n4 = nodeData(efa->v4); addTriangleToGraph(rg, n1, n3, n4, efa); } #ifdef DEBUG_REEB countfaces++; - if (countfaces % 100 == 0) - { + if (countfaces % 100 == 0) { printf("\rface %i of %i", countfaces, totfaces); } #endif @@ -2656,8 +2486,7 @@ void renormalizeWeight(EditMesh *em, float newmax) eve = em->verts.first; minimum = weightData(eve); maximum = minimum; - for (; eve; eve = eve->next) - { + for (; eve; eve = eve->next) { maximum = MAX2(maximum, weightData(eve)); minimum = MIN2(minimum, weightData(eve)); } @@ -2665,8 +2494,7 @@ void renormalizeWeight(EditMesh *em, float newmax) range = maximum - minimum; /* Normalize weights */ - for (eve = em->verts.first; eve; eve = eve->next) - { + for (eve = em->verts.first; eve; eve = eve->next) { float weight = (weightData(eve) - minimum) / range * newmax; weightSetData(eve, weight); } @@ -2681,8 +2509,7 @@ int weightFromLoc(EditMesh *em, int axis) return 0; /* Copy coordinate in weight */ - for (eve = em->verts.first; eve; eve = eve->next) - { + for (eve = em->verts.first; eve; eve = eve->next) { weightSetData(eve, eve->co[axis]); } @@ -2745,8 +2572,7 @@ int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges) int rval; /* Find local extrema */ - for (eve = em->verts.first; eve; eve = eve->next) - { + for (eve = em->verts.first; eve; eve = eve->next) { totvert++; } @@ -2759,52 +2585,42 @@ int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges) nlBegin(NL_SYSTEM); /* Find local extrema */ - for (index = 0, eve = em->verts.first; eve; index++, eve = eve->next) - { - if (eve->h == 0) - { + for (index = 0, eve = em->verts.first; eve; index++, eve = eve->next) { + if (eve->h == 0) { EditEdge *eed; int maximum = 1; int minimum = 1; NextEdgeForVert(indexed_edges, -1); /* Reset next edge */ - for (eed = NextEdgeForVert(indexed_edges, index); eed && (maximum || minimum); eed = NextEdgeForVert(indexed_edges, index)) - { + for (eed = NextEdgeForVert(indexed_edges, index); eed && (maximum || minimum); eed = NextEdgeForVert(indexed_edges, index)) { EditVert *eve2; - if (eed->v1 == eve) - { + if (eed->v1 == eve) { eve2 = eed->v2; } - else - { + else { eve2 = eed->v1; } - if (eve2->h == 0) - { + if (eve2->h == 0) { /* Adjacent vertex is bigger, not a local maximum */ - if (weightData(eve2) > weightData(eve)) - { + if (weightData(eve2) > weightData(eve)) { maximum = 0; } /* Adjacent vertex is smaller, not a local minimum */ - else if (weightData(eve2) < weightData(eve)) - { + else if (weightData(eve2) < weightData(eve)) { minimum = 0; } } } - if (maximum || minimum) - { + if (maximum || minimum) { float w = weightData(eve); eve->f1 = 0; nlSetVariable(0, index, w); nlLockVariable(index); } - else - { + else { eve->f1 = 1; } } @@ -2813,38 +2629,30 @@ int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges) nlBegin(NL_MATRIX); /* Zero edge weight */ - for (eed = em->edges.first; eed; eed = eed->next) - { + for (eed = em->edges.first; eed; eed = eed->next) { eed->tmp.l = 0; } /* Add faces count to the edge weight */ - for (efa = em->faces.first; efa; efa = efa->next) - { - if (efa->h == 0) - { + for (efa = em->faces.first; efa; efa = efa->next) { + if (efa->h == 0) { efa->e1->tmp.l++; efa->e2->tmp.l++; efa->e3->tmp.l++; - if (efa->e4) - { + if (efa->e4) { efa->e4->tmp.l++; } } } /* Add faces angle to the edge weight */ - for (efa = em->faces.first; efa; efa = efa->next) - { - if (efa->h == 0) - { - if (efa->v4 == NULL) - { + for (efa = em->faces.first; efa; efa = efa->next) { + if (efa->h == 0) { + if (efa->v4 == NULL) { addTriangle(efa->v1, efa->v2, efa->v3, efa->e1->tmp.l, efa->e2->tmp.l, efa->e3->tmp.l); } - else - { + else { addTriangle(efa->v1, efa->v2, efa->v3, efa->e1->tmp.l, efa->e2->tmp.l, 2); addTriangle(efa->v3, efa->v4, efa->v1, efa->e3->tmp.l, efa->e4->tmp.l, 2); } @@ -2857,16 +2665,13 @@ int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges) success = nlSolveAdvanced(NULL, NL_TRUE); - if (success) - { + if (success) { rval = 1; - for (index = 0, eve = em->verts.first; eve; index++, eve = eve->next) - { + for (index = 0, eve = em->verts.first; eve; index++, eve = eve->next) { weightSetData(eve, nlGetVariable(0, index)); } } - else - { + else { rval = 0; } @@ -2881,20 +2686,17 @@ EditEdge * NextEdgeForVert(EdgeIndex *indexed_edges, int index) static int offset = -1; /* Reset method, call with NULL mesh pointer */ - if (index == -1) - { + if (index == -1) { offset = -1; return NULL; } /* first pass, start at the head of the list */ - if (offset == -1) - { + if (offset == -1) { offset = indexed_edges->offset[index]; } /* subsequent passes, start on the next edge */ - else - { + else { offset++; } @@ -2916,23 +2718,19 @@ static void shortestPathsFromVert(EditMesh *em, EditVert *starting_vert, EdgeInd BLI_heap_insert(edge_heap, FLT_MAX, NULL); /* Initialize edge flag */ - for (eed= em->edges.first; eed; eed= eed->next) - { + for (eed= em->edges.first; eed; eed= eed->next) { eed->f1 = 0; } - while (BLI_heap_size(edge_heap) > 0) - { + while (BLI_heap_size(edge_heap) > 0) { float current_weight; current_eve->f1 = 1; /* mark vertex as selected */ /* Add all new edges connected to current_eve to the list */ NextEdgeForVert(indexed_edges, -1); // Reset next edge - for (eed = NextEdgeForVert(indexed_edges, indexData(current_eve)); eed; eed = NextEdgeForVert(indexed_edges, indexData(current_eve))) - { - if (eed->f1 == 0) - { + for (eed = NextEdgeForVert(indexed_edges, indexData(current_eve)); eed; eed = NextEdgeForVert(indexed_edges, indexData(current_eve))) { + if (eed->f1 == 0) { BLI_heap_insert(edge_heap, weightData(current_eve) + eed->tmp.fp, eed); eed->f1 = 1; } @@ -2945,16 +2743,13 @@ static void shortestPathsFromVert(EditMesh *em, EditVert *starting_vert, EdgeInd select_eed = BLI_heap_popmin(edge_heap); } while (select_eed != NULL && select_eed->v1->f1 != 0 && select_eed->v2->f1); - if (select_eed != NULL) - { + if (select_eed != NULL) { select_eed->f1 = 2; - if (select_eed->v1->f1 == 0) /* v1 is the new vertex */ - { + if (select_eed->v1->f1 == 0) /* v1 is the new vertex */ { current_eve = select_eed->v1; } - else /* otherwise, it's v2 */ - { + else { /* otherwise, it's v2 */ current_eve = select_eed->v2; } @@ -2983,10 +2778,8 @@ static void buildIndexedEdges(EditMesh *em, EdgeIndex *indexed_edges) indexed_edges->offset = MEM_callocN(totvert * sizeof(int), "EdgeIndex offset"); - for (eed = em->edges.first; eed; eed = eed->next) - { - if (eed->v1->h == 0 && eed->v2->h == 0) - { + for (eed = em->edges.first; eed; eed = eed->next) { + if (eed->v1->h == 0 && eed->v2->h == 0) { tot_indexed += 2; indexed_edges->offset[indexData(eed->v1)]++; indexed_edges->offset[indexData(eed->v2)]++; @@ -2998,10 +2791,8 @@ static void buildIndexedEdges(EditMesh *em, EdgeIndex *indexed_edges) indexed_edges->edges = MEM_callocN(tot_indexed * sizeof(EditEdge*), "EdgeIndex edges"); /* setting vert offsets */ - for (eve = em->verts.first; eve; eve = eve->next) - { - if (eve->h == 0) - { + for (eve = em->verts.first; eve; eve = eve->next) { + if (eve->h == 0) { int d = indexed_edges->offset[indexData(eve)]; indexed_edges->offset[indexData(eve)] = offset; offset += d + 1; @@ -3009,24 +2800,18 @@ static void buildIndexedEdges(EditMesh *em, EdgeIndex *indexed_edges) } /* adding edges in array */ - for (eed = em->edges.first; eed; eed= eed->next) - { - if (eed->v1->h == 0 && eed->v2->h == 0) - { + for (eed = em->edges.first; eed; eed= eed->next) { + if (eed->v1->h == 0 && eed->v2->h == 0) { int i; - for (i = indexed_edges->offset[indexData(eed->v1)]; i < tot_indexed; i++) - { - if (indexed_edges->edges[i] == NULL) - { + for (i = indexed_edges->offset[indexData(eed->v1)]; i < tot_indexed; i++) { + if (indexed_edges->edges[i] == NULL) { indexed_edges->edges[i] = eed; break; } } - for (i = indexed_edges->offset[indexData(eed->v2)]; i < tot_indexed; i++) - { - if (indexed_edges->edges[i] == NULL) - { + for (i = indexed_edges->offset[indexData(eed->v2)]; i < tot_indexed; i++) { + if (indexed_edges->edges[i] == NULL) { indexed_edges->edges[i] = eed; break; } @@ -3044,80 +2829,64 @@ int weightFromDistance(EditMesh *em, EdgeIndex *indexed_edges) totvert = BLI_countlist(&em->verts); - if (em == NULL || totvert == 0) - { + if (em == NULL || totvert == 0) { return 0; } totedge = BLI_countlist(&em->edges); - if (totedge == 0) - { + if (totedge == 0) { return 0; } /* Initialize vertice flag and find at least one selected vertex */ - for (eve = em->verts.first; eve; eve = eve->next) - { + for (eve = em->verts.first; eve; eve = eve->next) { eve->f1 = 0; - if (eve->f & SELECT) - { + if (eve->f & SELECT) { vCount = 1; } } - if (vCount == 0) - { + if (vCount == 0) { return 0; /* no selected vert, failure */ } - else - { + else { EditEdge *eed; int allDone = 0; /* Calculate edge weight */ - for (eed = em->edges.first; eed; eed= eed->next) - { - if (eed->v1->h == 0 && eed->v2->h == 0) - { + for (eed = em->edges.first; eed; eed= eed->next) { + if (eed->v1->h == 0 && eed->v2->h == 0) { eed->tmp.fp = len_v3v3(eed->v1->co, eed->v2->co); } } /* Apply dijkstra spf for each selected vert */ - for (eve = em->verts.first; eve; eve = eve->next) - { - if (eve->f & SELECT) - { + for (eve = em->verts.first; eve; eve = eve->next) { + if (eve->f & SELECT) { shortestPathsFromVert(em, eve, indexed_edges); } } /* connect unselected islands */ - while (allDone == 0) - { + while (allDone == 0) { EditVert *selected_eve = NULL; float selected_weight = 0; float min_distance = FLT_MAX; allDone = 1; - for (eve = em->verts.first; eve; eve = eve->next) - { + for (eve = em->verts.first; eve; eve = eve->next) { /* for every vertex visible that hasn't been processed yet */ - if (eve->h == 0 && eve->f1 != 1) - { + if (eve->h == 0 && eve->f1 != 1) { EditVert *closest_eve; /* find the closest processed vertex */ - for (closest_eve = em->verts.first; closest_eve; closest_eve = closest_eve->next) - { + for (closest_eve = em->verts.first; closest_eve; closest_eve = closest_eve->next) { /* vertex is already processed and distance is smaller than current minimum */ - if (closest_eve->f1 == 1) - { + if (closest_eve->f1 == 1) { float distance = len_v3v3(closest_eve->co, eve->co); - if (distance < min_distance) - { + if (distance < min_distance) { min_distance = distance; selected_eve = eve; selected_weight = weightData(closest_eve); @@ -3127,8 +2896,7 @@ int weightFromDistance(EditMesh *em, EdgeIndex *indexed_edges) } } - if (selected_eve) - { + if (selected_eve) { allDone = 0; weightSetData(selected_eve, selected_weight + min_distance); @@ -3137,10 +2905,8 @@ int weightFromDistance(EditMesh *em, EdgeIndex *indexed_edges) } } - for (eve = em->verts.first; eve && vCount == 0; eve = eve->next) - { - if (eve->f1 == 0) - { + for (eve = em->verts.first; eve && vCount == 0; eve = eve->next) { + if (eve->f1 == 0) { printf("vertex not reached\n"); break; } @@ -3173,13 +2939,11 @@ static void initIteratorFct(ReebArcIterator *iter) static void setIteratorValues(ReebArcIterator *iter, EmbedBucket *bucket) { - if (bucket) - { + if (bucket) { iter->p = bucket->p; iter->no = bucket->no; } - else - { + else { iter->p = NULL; iter->no = NULL; } @@ -3193,14 +2957,12 @@ void initArcIterator(BArcIterator *arg, ReebArc *arc, ReebNode *head) initIteratorFct(iter); iter->arc = arc; - if (head == arc->head) - { + if (head == arc->head) { iter->start = 0; iter->end = arc->bcount - 1; iter->stride = 1; } - else - { + else { iter->start = arc->bcount - 1; iter->end = 0; iter->stride = -1; @@ -3218,14 +2980,12 @@ void initArcIteratorStart(BArcIterator *arg, struct ReebArc *arc, struct ReebNod initIteratorFct(iter); iter->arc = arc; - if (head == arc->head) - { + if (head == arc->head) { iter->start = start; iter->end = arc->bcount - 1; iter->stride = 1; } - else - { + else { iter->start = arc->bcount - 1 - start; iter->end = 0; iter->stride = -1; @@ -3235,8 +2995,7 @@ void initArcIteratorStart(BArcIterator *arg, struct ReebArc *arc, struct ReebNod iter->length = arc->bcount - start; - if (start >= arc->bcount) - { + if (start >= arc->bcount) { iter->start = iter->end; /* stop iterator since it's past its end */ } } @@ -3251,12 +3010,10 @@ void initArcIterator2(BArcIterator *arg, ReebArc *arc, int start, int end) iter->start = start; iter->end = end; - if (end > start) - { + if (end > start) { iter->stride = 1; } - else - { + else { iter->stride = -1; } @@ -3270,12 +3027,10 @@ static void* headNode(void *arg) ReebArcIterator *iter = (ReebArcIterator*)arg; ReebNode *node; - if (iter->start < iter->end) - { + if (iter->start < iter->end) { node = iter->arc->head; } - else - { + else { node = iter->arc->tail; } @@ -3291,12 +3046,10 @@ static void* tailNode(void *arg) ReebArcIterator *iter = (ReebArcIterator*)arg; ReebNode *node; - if (iter->start < iter->end) - { + if (iter->start < iter->end) { node = iter->arc->tail; } - else - { + else { node = iter->arc->head; } @@ -3314,8 +3067,7 @@ static void* nextBucket(void *arg) iter->index++; - if (iter->index < iter->length) - { + if (iter->index < iter->length) { result = &(iter->arc->buckets[iter->start + (iter->stride * iter->index)]); } @@ -3331,8 +3083,7 @@ static void* nextNBucket(void *arg, int n) iter->index += n; /* check if passed end */ - if (iter->index < iter->length) - { + if (iter->index < iter->length) { result = &(iter->arc->buckets[iter->start + (iter->stride * iter->index)]); } @@ -3347,8 +3098,7 @@ static void* peekBucket(void *arg, int n) int index = iter->index + n; /* check if passed end */ - if (index < iter->length) - { + if (index < iter->length) { result = &(iter->arc->buckets[iter->start + (iter->stride * index)]); } @@ -3361,8 +3111,7 @@ static void* previousBucket(void *arg) ReebArcIterator *iter = (ReebArcIterator*)arg; EmbedBucket *result = NULL; - if (iter->index > 0) - { + if (iter->index > 0) { iter->index--; result = &(iter->arc->buckets[iter->start + (iter->stride * iter->index)]); } @@ -3375,12 +3124,10 @@ static int iteratorStopped(void *arg) { ReebArcIterator *iter = (ReebArcIterator*)arg; - if (iter->index >= iter->length) - { + if (iter->index >= iter->length) { return 1; } - else - { + else { return 0; } } |