Skip to content

Commit

Permalink
added root to control class.
Browse files Browse the repository at this point in the history
Added proper var definition on fk controls.
Added real to_flat_list definition for Map class to properly flatten objects.
Added testing specific names of each type of object.
  • Loading branch information
AndresMWeber committed Mar 27, 2018
1 parent 97573c5 commit adb0a1e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
2 changes: 0 additions & 2 deletions anvil/grouping/base_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,6 @@ def __getattr__(self, item):

def __str__(self):
try:
if self.root is None:
raise KeyError
return str(self.root)
except (KeyError, AttributeError):
return super(AbstractGrouping, self).__str__()
Expand Down
2 changes: 1 addition & 1 deletion anvil/grouping/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def build(cls, reference_object=None, parent=None, meta_data=None, name_tokens=N
instance.build_node(ob.Transform, hierarchy_id='offset_group', **kwargs)
instance.build_node(ob.Transform, hierarchy_id='connection_group', **kwargs)
instance.controller = instance.hierarchy.curve.control
instance.offset_group = instance.hierarchy.node.offset_group
instance.offset_group = instance.root = instance.hierarchy.node.offset_group
instance.connection_group = instance.hierarchy.node.connection_group

instance.controller.name_tokens.merge(instance.CTRL_NAME_TOKENS, force=True)
Expand Down
4 changes: 3 additions & 1 deletion anvil/sub_rig_templates/base_sub_rig_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ def build_fk_chain(self, layout_joints=None, chain_end=None, shape=None, duplica
parent=next(parent))
fk_controls = nt.NodeSet()
control_parent = next(parent)
for node, shape in zip(fk_chain, to_size_list(shape or self.DEFAULT_FK_SHAPE, len(fk_chain))):
for index, node_info in enumerate(zip(fk_chain, to_size_list(shape or self.DEFAULT_FK_SHAPE, len(fk_chain)))):
node, shape = node_info
if node.get_children():
name_tokens[cfg.VARIATION] = index
control = self.build_node(nt.Control,
reference_object=node,
shape=shape,
Expand Down
9 changes: 7 additions & 2 deletions anvil/utils/generic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from six import iteritems, itervalues
from collections import OrderedDict, MutableMapping
from functools import wraps
from collections import OrderedDict, MutableMapping, Iterable
from functools import wraps, reduce
import anvil.config as cfg


Expand Down Expand Up @@ -212,6 +212,11 @@ def flatten(self):
def to_flat_dict(self, full_path=False):
return dict_to_flat_dict(self, full_path=full_path)

def to_flat_list(self):
result = []
map(result.extend, [n if isinstance(n, Iterable) else to_list(n) for n in itervalues(self.to_flat_dict())])
return result

def __getattr__(self, attr):
return self.get(attr)

Expand Down
31 changes: 24 additions & 7 deletions tests/acceptance/test_hand.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from six import iteritems, itervalues
import string
import anvil.config as cfg
import anvil.node_types as nt
Expand Down Expand Up @@ -29,22 +30,39 @@ def from_template_file(cls, template_file, finger_start_joints=None, **kwargs):
class TestBuildHand(TestHandBase):
def setUp(self):
if self.hand is None:
self.__class__.hand = self.from_template_file(self.HAND_MERC, self.HAND_MERC_JOINTS)
self.__class__.hand = self.from_template_file(self.HAND_MERC,
self.HAND_MERC_JOINTS,
solver=cfg.IK_RP_SOLVER)

def test_number_of_controls_from_flat_hierarchy(self):
self.assertEqual(len([node for node in self.hand._flat_hierarchy() if isinstance(node, nt.Control)]), 25)
self.assertEqual(len(self.hand.hierarchy.control.to_flat_list()), 25)

def test_number_of_joints_from_flat_hierarchy(self):
self.assertEqual(len([node for node in self.hand._flat_hierarchy() if isinstance(node, nt.Joint)]), 60)
self.assertEqual(len(self.hand.hierarchy.joint.to_flat_list()), 60)

def test_number_of_joint_top_groups_from_get_children(self):
self.assertEqual(len(self.hand.group_joints.get_children()), 15)

def test_number_of_control_top_groups_from_get_children(self):
self.assertEqual(len(self.hand.group_controls.get_children()), 10)
self.assertEqual(len(self.hand.group_controls.get_children()), 15)

def test_number_of_nodes_from_get_children(self):
self.assertEqual(len(self.hand.group_nodes.get_children()), 5)
self.assertEqual(len(self.hand.group_nodes.get_children()), 15)

def test_control_names(self):
top_groups = ['A_fk_OGP', 'A_ik_OGP', 'A_pv_OGP']
self.assertIn([name + ending for ending in top_groups for name in self.TEMPLATE_CLASS.DEFAULT_NAMES],
self.hand.hierarchy.control.to_flat_list())

def test_joint_names(self):
top_groups = ['A_fk_JNT', 'A_ik_JNT', 'A_blend_JNT']
self.assertIn(['%s_%s' % (name, ending) for ending in top_groups for name in self.TEMPLATE_CLASS.DEFAULT_NAMES],
self.hand.hierarchy.joint.to_flat_list())

def test_node_names(self):
top_groups = ['IKHANDLE']
self.assertIn(['%s_%s' % (name, ending) for ending in top_groups for name in self.TEMPLATE_CLASS.DEFAULT_NAMES],
self.hand.hierarchy.node.to_flat_list())


class TestBuildDefaultHand(TestHandBase):
Expand All @@ -63,8 +81,7 @@ def test_build_no_kwargs_no_errors(self):
@clean_up_scene
@auto_save_result
def test_build_with_rp_solver(self):
rig = self.from_template_file(self.HAND_MERC, self.HAND_MERC_JOINTS, solver=cfg.IK_RP_SOLVER)
self.assertEqual(len([node for node in rig._flat_hierarchy() if isinstance(node, nt.Control)]), 30)
self.assertIsNotNone(self.from_template_file(self.HAND_MERC, self.HAND_MERC_JOINTS, solver=cfg.IK_RP_SOLVER))


class TestGetFingerBaseNames(TestHandBase):
Expand Down

0 comments on commit adb0a1e

Please sign in to comment.