示例#1
0
    def _traverse_up_linear_tree(self,
                                 downstream_node,
                                 upstream_node,
                                 node_filter=None):
        node_filter = node_filter if node_filter is not None else self.node_filter
        all_descendants = self._traverse_down_linear_tree(upstream_node)
        if not str(downstream_node) in all_descendants:
            raise IndexError(
                'Node %r is not a descendant of %s --> %s (filter=%s)' %
                (downstream_node, upstream_node, all_descendants,
                 self.node_filter))

        current_node = anvil.factory(downstream_node)
        chain_path = [current_node]

        while anvil.factory(current_node).get_parent():
            current_node = anvil.factory(current_node.get_parent())
            if any([
                    current_node.type() in node_filter, node_filter is None,
                    node_filter == []
            ]):
                chain_path.insert(0, current_node)
            if current_node == upstream_node:
                return iter(chain_path)
        raise IndexError('Could not find path between start(%s) --> last(%s)' %
                         (downstream_node, upstream_node))
示例#2
0
 def _process_end_node(self, end_node_candidate, node_filter=None):
     """ Returns the last item found of type
     """
     try:
         return anvil.factory(end_node_candidate)
     except (RuntimeError, IOError):
         return self._get_linear_end(node_filter=node_filter)
示例#3
0
 def initialize_sub_rig_attributes(self, controller=None, attr_dict=None):
     attr_dict = self.BUILT_IN_ATTRIBUTES if attr_dict is None else attr_dict
     if attr_dict:
         controller = self.root if controller is None else anvil.factory(
             controller)
         for attr, attr_kwargs in iteritems(attr_dict):
             controller.add_attr(attr, **attr_kwargs)
示例#4
0
 def _get_linear_end(self, node_filter=None):
     node_filter = node_filter or self.node_filter
     last_node = self.get_level(self.depth(), node_filter=node_filter)
     if last_node:
         return anvil.factory(list(last_node)[0])
     else:
         raise ValueError('Could not find last node at depth %d' %
                          self.depth())
示例#5
0
    def find_child(self, child):
        if isinstance(child, int):
            return self[child]

        child = anvil.factory(child)
        for node in self:
            if node == child:
                return node

        raise IndexError('Child not found in hierarchy %s' % list(self))
示例#6
0
    def _process_top_node(self, top_node, end_node, duplicate=False):
        if isinstance(top_node, list) and end_node is None:
            top_node, end_node = top_node[0], top_node[-1]

        elif isinstance(top_node, self.__class__):
            top_node, end_node = top_node.head, top_node.tail

        if duplicate:
            top_node, end_node = self.duplicate_chain(top_node,
                                                      end_node=end_node)

        return anvil.factory(top_node), end_node
示例#7
0
文件: base.py 项目: bugrevelio/Anvil
    def connect_rendering_delegate(self, assignee=None):
        # TODO: API Attribute dependent...dangerous.
        assignee = anvil.factory(assignee) if assignee is not None else self.root

        for attr, attr_kwargs in iteritems(self.RENDERING_ATTRIBUTES):
            attr_name = '%s_rendering' % attr
            group_name = 'group_%s' % attr

            rendering_attribute = assignee.add_attr(attr_name, **attr_kwargs)

            if hasattr(self, group_name):
                target_group = getattr(self, group_name)
                target_group.overrideEnabled.set(1)
                rendering_attribute.connect(target_group.visibility, force=True)
                assignee.buffer_connect(attr_name, target_group.overrideDisplayType, -1, force=True)
示例#8
0
def get_node_hierarchy_as_dict(node_or_nodes, tree=None, node_filter=None):
    nodes = to_list(node_or_nodes)

    if tree is None:
        tree = dict()

    for tree_child in nodes:
        anvil_node = anvil.factory(tree_child)
        try:
            relative_tree = tree[anvil_node]
        except KeyError:
            tree[anvil_node] = dict()
            relative_tree = tree[anvil_node]

        node_filter_kwargs = {cfg.TYPE: node_filter} if node_filter else {}
        children = rt.dcc.scene.list_relatives(tree_child, fullPath=True, children=True, **node_filter_kwargs) or []
        if children:
            get_node_hierarchy_as_dict(children, relative_tree, node_filter=node_filter)
    return tree
示例#9
0
    def connect_rendering_delegate(self, assignee=None):
        # TODO: API Attribute dependent...dangerous.
        assignee = anvil.factory(
            assignee) if assignee is not None else self.root

        for attr, attr_kwargs in iteritems(self.RENDERING_ATTRIBUTES):
            attr_name = '%s_rendering' % attr
            group_name = 'group_%s' % attr

            rendering_attribute = assignee.add_attr(attr_name, **attr_kwargs)

            if hasattr(self, group_name):
                target_group = getattr(self, group_name)
                target_group.overrideEnabled.set(1)
                rendering_attribute.connect(target_group.visibility,
                                            force=True)
                assignee.buffer_connect(attr_name,
                                        target_group.overrideDisplayType,
                                        -1,
                                        force=True)
示例#10
0
 def node(self):
     return anvil.factory(self.name().split(cfg.ATTR_DELIMITER)[0])
示例#11
0
 def test_joints_mixed(self):
     chain = nt.LinearHierarchyNodeSet(self.joints_mixed[0])
     self.assertEqual(chain.get_hierarchy(as_list=True),
                      [anvil.factory(j) for j in self.joints_total])
示例#12
0
文件: base.py 项目: bugrevelio/Anvil
 def initialize_sub_rig_attributes(self, controller=None, attr_dict=None):
     attr_dict = self.BUILT_IN_ATTRIBUTES if attr_dict is None else attr_dict
     if attr_dict:
         controller = self.root if controller is None else anvil.factory(controller)
         for attr, attr_kwargs in iteritems(attr_dict):
             controller.add_attr(attr, **attr_kwargs)
示例#13
0
 def node(self):
     return anvil.factory(self.name().split(cfg.ATTR_DELIMITER)[0])
示例#14
0
 def test_joints_mixed(self):
     chain = nt.LinearHierarchyNodeSet(self.joints_mixed[0])
     self.assertEqual(chain.get_hierarchy(as_list=True), [anvil.factory(j) for j in self.joints_total])