Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/armature/editarmature_retarget.c')
-rw-r--r--source/blender/editors/armature/editarmature_retarget.c834
1 files changed, 279 insertions, 555 deletions
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);
}
}