diff options
author | Martin Poirier <theeth@yahoo.com> | 2008-08-20 02:16:01 +0400 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2008-08-20 02:16:01 +0400 |
commit | a3337a15f08fdc4d0f57ada8edb73b1f63a093a3 (patch) | |
tree | 38bd2c18899ef3665adc26ed50778894c7c370d6 /source/blender/blenlib | |
parent | 18bce23a6052540c2ded4bdc548f83106c71c117 (diff) |
Control bone commit from yesterday broke root bones. This is now fixed in a much more elegant way.
Remove yeh ol' primary symmetry axis flipping and replace by a smarter check on both armature and mesh arcs (works better for partial retargetting).
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_graph.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/graph.c | 59 |
2 files changed, 56 insertions, 5 deletions
diff --git a/source/blender/blenlib/BLI_graph.h b/source/blender/blenlib/BLI_graph.h index 0f75701a284..160c2e04cf5 100644 --- a/source/blender/blenlib/BLI_graph.h +++ b/source/blender/blenlib/BLI_graph.h @@ -93,7 +93,9 @@ float BLI_subtreeLength(BNode *node); void BLI_calcGraphLength(BGraph *graph); void BLI_replaceNode(BGraph *graph, BNode *node_src, BNode *node_replaced); +void BLI_replaceNodeInArc(BGraph *graph, BArc *arc, BNode *node_src, BNode *node_replaced); void BLI_removeDoubleNodes(BGraph *graph, float limit); +BNode * BLI_FindNodeByPosition(BGraph *graph, float *p, float limit); BArc * BLI_findConnectedArc(BGraph *graph, BArc *arc, BNode *v); diff --git a/source/blender/blenlib/intern/graph.c b/source/blender/blenlib/intern/graph.c index 277a9300f5b..cb8f4b59d8b 100644 --- a/source/blender/blenlib/intern/graph.c +++ b/source/blender/blenlib/intern/graph.c @@ -194,6 +194,34 @@ int BLI_hasAdjacencyList(BGraph *rg) return 1; } +void BLI_replaceNodeInArc(BGraph *graph, BArc *arc, BNode *node_src, BNode *node_replaced) +{ + if (arc->head == node_replaced) + { + arc->head = node_src; + node_src->degree++; + } + + if (arc->tail == node_replaced) + { + arc->tail = node_src; + node_src->degree++; + } + + if (arc->head == arc->tail) + { + node_src->degree -= 2; + + graph->free_arc(arc); + BLI_freelinkN(&graph->arcs, arc); + } + + if (node_replaced->degree == 0) + { + BLI_removeNode(graph, node_replaced); + } +} + void BLI_replaceNode(BGraph *graph, BNode *node_src, BNode *node_replaced) { BArc *arc, *next_arc; @@ -222,6 +250,11 @@ void BLI_replaceNode(BGraph *graph, BNode *node_src, BNode *node_replaced) BLI_freelinkN(&graph->arcs, arc); } } + + if (node_replaced->degree == 0) + { + BLI_removeNode(graph, node_replaced); + } } void BLI_removeDoubleNodes(BGraph *graph, float limit) @@ -235,13 +268,29 @@ void BLI_removeDoubleNodes(BGraph *graph, float limit) if (node_replaced != node_src && VecLenf(node_replaced->p, node_src->p) <= limit) { BLI_replaceNode(graph, node_src, node_replaced); - - BLI_removeNode(graph, node_replaced); } } } } + +BNode * BLI_FindNodeByPosition(BGraph *graph, float *p, float limit) +{ + BNode *closest_node = NULL, *node; + float min_distance; + + for(node = graph->nodes.first; node; node = node->next) + { + float distance = VecLenf(p, node->p); + if (distance <= limit && (closest_node == NULL || distance < min_distance)) + { + closest_node = node; + min_distance = distance; + } + } + + return closest_node; +} /************************************* SUBGRAPH DETECTION **********************************************/ void flagSubgraph(BNode *node, int subgraph) @@ -556,7 +605,7 @@ static void testRadialSymmetry(BGraph *graph, BNode* root_node, RadialArc* ring, for (i = 0; i < total; i++) { ring[i].arc->symmetry_group = group; - ring[i].arc->symmetry_flag = i; + ring[i].arc->symmetry_flag = SYM_SIDE_RADIAL + i; } if (graph->radial_symmetry) @@ -837,7 +886,7 @@ static void markdownSecondarySymmetry(BGraph *graph, BNode *node, int depth, int float axis[3] = {0, 0, 0}; int count = 0; int i; - + /* count the number of branches in this symmetry group * and determinte the axis of symmetry * */ @@ -869,7 +918,7 @@ static void markdownSecondarySymmetry(BGraph *graph, BNode *node, int depth, int { handleRadialSymmetry(graph, node, depth, axis, limit); } - + /* markdown secondary symetries */ for (i = 0; i < node->degree; i++) { |