def patch_spaceswitch_data_into_network(sel=None):
    if sel is None:
        sel = pymel.selected()

    networks = libSerialization.get_connected_networks(sel, key=lambda
        net: libSerialization.is_network_from_class(net, 'BaseCtrl'))

    for net in networks:
        ctrl_instance = libSerialization.import_network(net)
        data = ctrl_instance.get_spaceswitch_enum_targets()

        if data:
            # Create missing attributes if needed
            if not net.hasAttr('targets_indexes'):
                log.info('targets_indexes attribute is missing on network {0}. It will be created'.format(net))
                pymel.addAttr(net, longName='targets_indexes', at='long', multi=True)
            if not net.hasAttr('targets'):
                log.info('targets attribute is missing on network {0}. It will be created'.format(net))
                pymel.addAttr(net, longName='targets', at='message', multi=True)
            if not net.hasAttr('local_index'):
                log.info('targets_indexes attribute is missing on network {0}. It will be created'.format(net))
                pymel.addAttr(net, longName='local_index', at='long')

            # Add data if needed
            for index, (name, obj) in data.items():
                target_data = net.targets.get()
                indexes_data = net.targets_indexes.get()
                if obj not in target_data:
                    if index not in indexes_data:
                        if obj is not None:
                            if isinstance(obj, pymel.nt.Joint):
                                log.info('Patching network {0} space switch data named {1} - Index {2} on object {3}'
                                     .format(net.name(), name, index, obj))
                                pymel.connectAttr(obj.message, net.targets[len(target_data)])
                            elif isinstance(obj, pymel.nt.Transform):
                                key = lambda network: libSerialization.is_network_from_class(network, 'Node')
                                ctrl_net = libSerialization.get_connected_networks(obj, key)
                                if ctrl_net > 0:
                                    log.info('Patching network {0} space switch data named {1} - '
                                             'Index {2} on object {3}'.format(net.name(), name, index, ctrl_net[0]))
                                    pymel.connectAttr(ctrl_net[0].message, net.targets[len(target_data)])
                            net.targets_indexes[len(target_data)].set(index)
                        elif name == 'Local':
                            log.info('Patching network {0} space switch data named {1} - Index {2} as local index'
                                     .format(net.name(), name, index))
                            net.local_index.set(index)
                    else:
                        if obj is not None:
                            log.warning('Object {0} have not been found in attribute targets but index {1} yes.'
                                        'This object will not be patched to prevent any index conflict. '
                                        'Look at your data to understand'.format(obj, index))
                else:
                    log.info('Space Switch object {0} is already included in the targets attributes'.format(obj))
示例#2
0
def run():
    nets = pymel.ls(type='network')
    net_rig = next(iter(net for net in nets if libSerialization.is_network_from_class(net, 'Rig')), None)

    for net in nets:
        if not libSerialization.is_network_from_class(net, 'Module'):
            continue
        if not net.hasAttr('rig'):
            print("Adding attribute 'rig' on {0}".format(net))
            pymel.addAttr(net, longName='rig', niceName='rig', attributeType='message')
        if not net.rig.isDestination():
            print("Connecting attribute 'rig' on {0}".format(net))
            pymel.connectAttr(net_rig.message, net.rig)
示例#3
0
    def _fill_widget_influences(self, qt_parent, data):
        obj = pymel.PyNode(data.val) if data.val else None
        #obj, children_data = data
        if obj:
            obj_name = obj.stripNamespace()

            fnFilter = lambda x: libSerialization.is_network_from_class(x, 'Module')
            networks = libSerialization.get_connected_networks(obj, key=fnFilter, recursive=False)

            textBrush = QtGui.QBrush(QtCore.Qt.white)

            if self._is_influence(obj):  # todo: listen to the Rig class
                qItem = QtGui.QTreeWidgetItem(0)
                qItem.obj = obj
                qItem.networks = networks
                qItem.setText(0, obj_name)
                qItem.setForeground(0, textBrush)
                ui_shared._set_icon_from_type(obj, qItem)
                qItem.setCheckState(0, QtCore.Qt.Checked if networks else QtCore.Qt.Unchecked)
                if qItem.flags() & QtCore.Qt.ItemIsUserCheckable:
                    qItem.setFlags(qItem.flags() ^ QtCore.Qt.ItemIsUserCheckable)
                qt_parent.addChild(qItem)
                qt_parent = qItem

        for child_data in data.children:
            self._fill_widget_influences(qt_parent, child_data)
示例#4
0
    def _fill_widget_influences(self, qt_parent, data):
        obj = pymel.PyNode(data.val) if data.val else None
        #obj, children_data = data
        if obj:
            obj_name = obj.stripNamespace()

            fnFilter = lambda x: libSerialization.is_network_from_class(
                x, 'Module')
            networks = libSerialization.get_connected_networks(obj,
                                                               key=fnFilter,
                                                               recursive=False)

            textBrush = QtGui.QBrush(QtCore.Qt.white)

            if self._is_influence(obj):  # todo: listen to the Rig class
                qItem = QtGui.QTreeWidgetItem(0)
                qItem.obj = obj
                qItem.networks = networks
                qItem.setText(0, obj_name)
                qItem.setForeground(0, textBrush)
                ui_shared._set_icon_from_type(obj, qItem)
                qItem.setCheckState(
                    0, QtCore.Qt.Checked if networks else QtCore.Qt.Unchecked)
                if qItem.flags() & QtCore.Qt.ItemIsUserCheckable:
                    qItem.setFlags(qItem.flags()
                                   ^ QtCore.Qt.ItemIsUserCheckable)
                qt_parent.addChild(qItem)
                qt_parent = qItem

        for child_data in data.children:
            self._fill_widget_influences(qt_parent, child_data)
示例#5
0
 def get_rig_network_from_module(network):
     for plug in network.message.outputs(plugs=True):
         plug_node = plug.node()
         if not isinstance(plug_node, pymel.nodetypes.Network):
             continue
         if libSerialization.is_network_from_class(plug_node, 'Rig'):
             return plug_node
     return None
示例#6
0
文件: __init__.py 项目: renaudll/omtk
 def get_rig_network_from_module(network):
     for plug in network.message.outputs(plugs=True):
         plug_node = plug.node()
         if not isinstance(plug_node, pymel.nodetypes.Network):
             continue
         if libSerialization.is_network_from_class(plug_node, 'Rig'):
             return plug_node
     return None
示例#7
0
def run():
    nets = pymel.ls(type='network')
    net_rig = next(
        iter(net for net in nets
             if libSerialization.is_network_from_class(net, 'Rig')), None)

    for net in nets:
        if not libSerialization.is_network_from_class(net, 'Module'):
            continue
        if not net.hasAttr('rig'):
            print("Adding attribute 'rig' on {0}".format(net))
            pymel.addAttr(net,
                          longName='rig',
                          niceName='rig',
                          attributeType='message')
        if not net.rig.isDestination():
            print("Connecting attribute 'rig' on {0}".format(net))
            pymel.connectAttr(net_rig.message, net.rig)
示例#8
0
def get_obj_mirror_def(obj):
    network_is_ctrl = lambda x: libSerialization.is_network_from_class(x, classCtrl.BaseCtrl.__name__.split('.')[-1])
    networks = libSerialization.get_connected_networks([obj], key=network_is_ctrl, recursive=False)
    network = next(iter(networks), None)

    if network:
        # HACK: We read the attributes directly
        try:
            return (
                network.attr('mirror_x').get(),
                network.attr('mirror_y').get(),
                network.attr('mirror_z').get(),
                network.attr('mirror_flip_pos_x').get(),
                network.attr('mirror_flip_pos_y').get(),
                network.attr('mirror_flip_pos_z').get(),
                network.attr('mirror_flip_rot_x').get(),
                network.attr('mirror_flip_rot_y').get(),
                network.attr('mirror_flip_rot_z').get()
            )
        except pymel.MayaAttributeError as e:
            print(str(e))

    # If we cannot resolve the ctrl data, take a guess?
    pymel.warning("Can't resolve mirror data for {0}".format(obj))
示例#9
0
def patch_spaceswitch_data_into_network(sel=None):
    if sel is None:
        sel = pymel.selected()

    networks = libSerialization.get_connected_networks(
        sel,
        key=lambda net: libSerialization.is_network_from_class(
            net, 'BaseCtrl'))

    for net in networks:
        ctrl_instance = libSerialization.import_network(net)
        data = ctrl_instance.get_spaceswitch_enum_targets()

        if data:
            # Create missing attributes if needed
            if not net.hasAttr('targets_indexes'):
                log.info(
                    'targets_indexes attribute is missing on network {0}. It will be created'
                    .format(net))
                pymel.addAttr(net,
                              longName='targets_indexes',
                              at='long',
                              multi=True)
            if not net.hasAttr('targets'):
                log.info(
                    'targets attribute is missing on network {0}. It will be created'
                    .format(net))
                pymel.addAttr(net,
                              longName='targets',
                              at='message',
                              multi=True)
            if not net.hasAttr('local_index'):
                log.info(
                    'targets_indexes attribute is missing on network {0}. It will be created'
                    .format(net))
                pymel.addAttr(net, longName='local_index', at='long')

            # Add data if needed
            for index, (name, obj) in data.items():
                target_data = net.targets.get()
                indexes_data = net.targets_indexes.get()
                if obj not in target_data:
                    if index not in indexes_data:
                        if obj is not None:
                            if isinstance(obj, pymel.nt.Joint):
                                log.info(
                                    'Patching network {0} space switch data named {1} - Index {2} on object {3}'
                                    .format(net.name(), name, index, obj))
                                pymel.connectAttr(
                                    obj.message, net.targets[len(target_data)])
                            elif isinstance(obj, pymel.nt.Transform):
                                key = lambda network: libSerialization.is_network_from_class(
                                    network, 'Node')
                                ctrl_net = libSerialization.get_connected_networks(
                                    obj, key)
                                if ctrl_net > 0:
                                    log.info(
                                        'Patching network {0} space switch data named {1} - '
                                        'Index {2} on object {3}'.format(
                                            net.name(), name, index,
                                            ctrl_net[0]))
                                    pymel.connectAttr(
                                        ctrl_net[0].message,
                                        net.targets[len(target_data)])
                            net.targets_indexes[len(target_data)].set(index)
                        elif name == 'Local':
                            log.info(
                                'Patching network {0} space switch data named {1} - Index {2} as local index'
                                .format(net.name(), name, index))
                            net.local_index.set(index)
                    else:
                        if obj is not None:
                            log.warning(
                                'Object {0} have not been found in attribute targets but index {1} yes.'
                                'This object will not be patched to prevent any index conflict. '
                                'Look at your data to understand'.format(
                                    obj, index))
                else:
                    log.info(
                        'Space Switch object {0} is already included in the targets attributes'
                        .format(obj))
示例#10
0
 def fn_key(network):
     return libSerialization.is_network_from_class(network, module_name)
示例#11
0
 def fn_skip(network):
     return libSerialization.is_network_from_class(network, 'Rig')