Skip to content

Commit

Permalink
Fixed manual_id kwarg to be recognized by generate_report in register…
Browse files Browse the repository at this point in the history
…_node.

Mid-fixing registration of nodes in the Hand rig build process.

Turned the flag detection into pop to avoid pushing kwargs etc in registration functions.
  • Loading branch information
AndresMWeber committed Mar 5, 2018
1 parent 9b3dfe3 commit 191184a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 45 deletions.
2 changes: 2 additions & 0 deletions anvil/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
DEFAULT_FK_SHAPE = CUBE
DEFAULT_DIGIT_FK_SHAPE = PYRAMID_PIN
DEFAULT_PV_SHAPE = TRIANGLE
SKIP_REGISTER = 'skip_register'
SKIP_REPORT = 'skip_report'

# PATHS
BASE_DIR = os.path.dirname(os.path.abspath(anvil.__file__))
Expand Down
4 changes: 1 addition & 3 deletions anvil/grouping/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def build_layout(self):

@register_built_nodes
@generate_build_report
def register_node(self, node, manual_id=None):
if manual_id:
node = (manual_id, node)
def register_node(self, node, **kwargs):
return node

def connect_rendering_delegate(self, assignee=None):
Expand Down
1 change: 0 additions & 1 deletion anvil/grouping/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def build(cls, reference_object=None, parent=None, meta_data=None, name_tokens=N
instance.build_node(ob.Curve, hierarchy_id='control', **kwargs)
instance.build_node(ob.Transform, hierarchy_id='offset_group', **kwargs)
instance.build_node(ob.Transform, hierarchy_id='connection_group', **kwargs)
print(instance, instance.hierarchy)
instance.controller = instance.hierarchy.curve.control
instance.offset_group = instance.hierarchy.node.offset_group
instance.connection_group = instance.hierarchy.node.connection_group
Expand Down
11 changes: 3 additions & 8 deletions anvil/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def register_built_nodes(f):

@wraps(f)
def wrapper(abstract_grouping, *args, **kwargs):
skip_register = False
if kwargs.get('skip_register'):
skip_register = kwargs.pop('skip_register')
skip_register = kwargs.pop('skip_register', False)

results = f(abstract_grouping, *args, **kwargs)
if skip_register:
Expand Down Expand Up @@ -84,11 +82,8 @@ def wrapper(abstract_grouping, *args, **kwargs):
A top level key will not be present if the result nodes from the wrapped function are not of that type.
The top level key possibilities are: ['control', 'joint', 'node', 'set']
"""
skip_report = False
if kwargs.get('skip_report'):
skip_report = kwargs.pop('skip_report')

custom_hierarchy_ids = kwargs.get('hierarchy_id', None)
skip_report = kwargs.pop('skip_report', False)
custom_hierarchy_ids = kwargs.pop('hierarchy_id', None)
nodes_built = f(abstract_grouping, *args, **kwargs)

if skip_report:
Expand Down
7 changes: 5 additions & 2 deletions anvil/sub_rig_templates/base_sub_rig_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def build_ik_chain(self, layout_joints, ik_end_index=-1, solver=cfg.IK_RP_SOLVER
:return: (NonLinearHierarchyNodeSet(Control), LinearHierarchyNodeSet(Joint))
"""
parent = list(reversed(to_size_list(parent, 3)))
kwargs['skip_register'] = True
kwargs['skip_report'] = True
kwargs[cfg.SKIP_REGISTER] = True
kwargs[cfg.SKIP_REPORT] = True
ik_chain = nt.LinearHierarchyNodeSet(layout_joints, duplicate=duplicate, parent=parent.pop(), **kwargs)

handle, effector = self.build_ik(ik_chain,
Expand Down Expand Up @@ -157,6 +157,8 @@ def build_fk_chain(self, chain_start=None, chain_end=None, shape=None, duplicate
fk_controls = nt.NonLinearHierarchyNodeSet()
control_parent = parent.pop()
for node, shape in zip(fk_chain, to_size_list(shape or self.DEFAULT_FK_SHAPE, len(fk_chain))):
print('parenting fk control %s to %s' % (node, control_parent))

control = self.build_node(nt.Control,
reference_object=node,
shape=shape,
Expand All @@ -168,4 +170,5 @@ def build_fk_chain(self, chain_start=None, chain_end=None, shape=None, duplicate

control_parent = fk_controls[-1].node.connection_group
rt.dcc.connections.parent(control_parent, node, maintainOffset=True)
print(type(fk_chain))
return fk_chain, fk_controls
58 changes: 32 additions & 26 deletions anvil/sub_rig_templates/hand.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,43 @@ def build(self, parent=None, solver=None, meta_data=None, **kwargs):
super(Hand, self).build(meta_data=meta_data, parent=parent, **kwargs)
solver = solver or cfg.IK_SC_SOLVER

for layout_joints, base_name in zip(self.layout_joints, self.get_finger_base_names()):
self.build_digit(layout_joints, solver=solver, name_tokens={cfg.NAME: base_name}, **self.build_kwargs)
for index, digit_info in enumerate(zip(self.layout_joints, self.get_finger_base_names())):
layout_joints, label = digit_info
self.build_digit(layout_joints, index, solver=solver, name_tokens={cfg.NAME: label}, **self.build_kwargs)

self.rename()

def build_digit(self, digit_joints, **kwargs):
digit_nodes = {}
if self.has_fk:
digit_nodes[cfg.FK] = self.build_fk_chain(digit_joints,
parent=[self.group_joints, self.group_controls],
shape='pyramid_pin', **kwargs)
if self.has_ik:
digit_nodes[cfg.IK] = self.build_ik_chain(digit_joints,
parent=[self.group_joints, self.group_nodes, self.group_controls,
[self.group_controls,
self.group_nodes,
self.group_nodes]],
shape='cube', **kwargs)
def build_digit(self, digit_joints, index, **kwargs):
kwargs[cfg.SKIP_REGISTER] = True
kwargs[cfg.SKIP_REPORT] = True
fk_chain = None
ik_chain = None

if self.has_fk and self.has_ik:
self.build_blend_chain(digit_joints,
[digit_nodes[cfg.IK][cfg.SET_TYPE][cfg.DEFAULT][-1],
digit_nodes[cfg.FK][cfg.SET_TYPE][cfg.DEFAULT][-1]],
parent=self.group_joints,
**kwargs)
if self.has_fk:
fk_chain, fk_controls = self.build_fk_chain(digit_joints,
parent=[self.group_joints, self.group_controls],
shape='pyramid_pin', **kwargs)
self.register_node(fk_chain, hierarchy_id='%s_chain_%s' % (cfg.FK, index))
self.register_node(fk_controls, hierarchy_id='%s_%s_%s' % (cfg.FK, cfg.CONTROL_TYPE, index))

if self.has_ik:
ik_chain, ik_controls, handle, effector = self.build_ik_chain(digit_joints,
parent=[self.group_joints,
self.group_nodes,
self.group_controls,
[self.group_controls,
self.group_nodes]],
shape='cube', **kwargs)
self.register_node(ik_chain, hierarchy_id='%s_chain_%s' % (cfg.IK, index))
self.register_node(ik_controls, hierarchy_id='%s_%s_%s' % (cfg.IK, cfg.CONTROL_TYPE, index))
self.register_node(handle, hierarchy_id='%s_%s_%s' % (cfg.IK, cfg.IK_HANDLE, index))
self.register_node(effector, hierarchy_id='%s_%s_%s' % (cfg.IK, cfg.IK_EFFECTOR, index))

if self.has_fk and self.has_ik:
blend_chain = self.build_blend_chain(digit_joints, [fk_chain, ik_chain],
parent=self.group_joints,
**kwargs)
self.register_node(blend_chain, hierarchy_id='%s_chain_%s' % (cfg.BLEND, index))

def get_finger_base_names(self):
num_fingers = len(self.layout_joints)
Expand All @@ -69,26 +80,21 @@ def get_finger_base_names(self):
else:
return [cfg.FINGER + c for c in string.uppercase[:num_fingers]]


def rename(self, *input_dicts, **name_tokens):
super(Hand, self).rename(*input_dicts, **name_tokens)


def set_up_fist_pose(self):
# for now just hook it up to the controls
pass


def set_up_spread_pose(self):
# for now just hook it up to the controls
pass


def set_up_curl_pose(self):
# for now just hook it up to the controls
pass


def connect_curl_fist(self, control, axis=cfg.X):
phalanges = self.fk_chain if hasattr(self, '%s_chain' % cfg.FK) else self.blend_chain
control.add_attr('curl', defaultValue=0, attributeType=cfg.FLOAT)
Expand Down
11 changes: 6 additions & 5 deletions tests/acceptance/test_hand.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from anvil.sub_rig_templates import Hand
from tests.base_test import TestBase, clean_up_scene
import string
from pprint import pprint


class TestHandBase(TestBase):
Expand Down Expand Up @@ -39,20 +40,20 @@ def test_build_no_kwargs_no_errors(self):
self.assertIsNotNone(self.hand)

def test_number_of_controls(self):
print(self.hand.hierarchy)
controls = [node for key, node in iteritems(self.hand.hierarchy) if isinstance(node, nt.Control)]

controls = [node for node in self.hand._flat_hierarchy() if isinstance(node, nt.Control)]
self.assertEqual(len(controls), 15)

def test_number_of_control_top_groups(self):
print(self.hand.hierarchy)
pprint(self.hand.hierarchy)
self.assertEqual(len(self.hand.group_controls.get_children()), 10)

def test_number_of_joint_chains(self):
print(self.hand.hierarchy)
pprint(self.hand.hierarchy)
self.assertEqual(len(self.hand.group_joints.get_children()), 15)

def test_number_of_nodes(self):
print(self.hand.hierarchy)
pprint(self.hand.hierarchy)
self.assertEqual(len(self.hand.group_nodes.get_children()), 5)


Expand Down

0 comments on commit 191184a

Please sign in to comment.