Пример #1
0
def connect_cacheversion(cacheversion, nodes=None, behavior=0):
    nodes = nodes or cmds.ls(type=DYNAMIC_NODES)
    nodes = filter_invisible_nodes_for_manager(nodes)
    for node in nodes:
        if not cacheversion_contains_node(node, cacheversion):
            continue
        xml_file = find_file_match(node, cacheversion, extension='xml')
        if not xml_file:
            cmds.warning("no cache to connect for {}".format(xml_file))
            continue
        cachefile = import_ncache(node, xml_file, behavior=behavior)
        cmds.rename(cachefile, cacheversion.name + CACHENODENAME_SUFFIX)
Пример #2
0
    def _gather_attributes_datas(self, nodes):
        attributes = {}
        for node in nodes:
            xml = find_file_match(node, self.cacheversion, extension='xml')
            attributes.update(extract_xml_attributes(xml))

        nodes = set([key.split(".")[0] for key in attributes.keys()])
        datas = {node: [] for node in nodes}
        for attribute, value in attributes.items():
            key = attribute.split(".")[0]
            datas[key].append([attribute, value])

        return datas
Пример #3
0
def apply_settings(cacheversion, nodes):
    for node in nodes:
        filename = find_file_match(node, cacheversion, extension='xml')
        xml_attributes = extract_xml_attributes(filename)
        xml_attributes = clean_namespaces_in_attributes_dict(xml_attributes)
        for key, value in xml_attributes.items():
            attributes = cmds.ls([key, "*" + key, "*:" + key, "*:*:" + key])
            for attribute in attributes:
                try:
                    cmds.setAttr(attribute, value)
                except RuntimeError:
                    msg = (
                        attribute + " is locked, connected, invalid or "
                        "doesn't in current scene. This attribute is skipped")
                    cmds.warning(msg)
Пример #4
0
def compare_node_and_version(node, cacheversion):
    filename = find_file_match(node, cacheversion, extension='xml')
    xml_attributes = extract_xml_attributes(filename)
    xml_attributes = clean_namespaces_in_attributes_dict(xml_attributes)
    node_attributes = list_node_attributes_values(node)
    node_attributes = clean_namespaces_in_attributes_dict(node_attributes)
    differences = {}
    for key, value in xml_attributes.items():
        current_value = node_attributes.get(key)
        # in case of value are store in format like: "-1e5", that's stored in
        # string instead of float. So we reconverted it to float
        if isinstance(value, str):
            value = float(value)
        # value in xml are slightly less precise than the current value
        # in maya, it doesn't compare the exact result but the difference
        if current_value is None or abs(current_value - value) < 1e-6:
            continue
        differences[key] = (current_value, value)
    return differences
Пример #5
0
def plug_cacheversion(cacheversion, groupname, suffix, inattr, nodes=None):
    """ This function will plug a ncache to a given attribute.
    Basically, it create a static mesh based on the dynamic node input.
    Import the ncache as geo cache file and drive the created mesh with.
    And finally connect it to the input attribute given.
    """
    if not cmds.objExists(groupname):
        cmds.group(name=groupname, world=True, empty=True)
    group_content = cmds.listRelatives(groupname)
    group_content = cmds.ls(group_content,
                            shapes=True,
                            dag=True,
                            noIntermediate=True)

    nodes = nodes or cmds.ls(type='nCloth')
    new_input_meshes = []
    for node in nodes:
        if not cacheversion_contains_node(node, cacheversion):
            continue
        ensure_original_input_is_stored(node)
        input_mesh = get_orignial_input_mesh(node)
        mesh = create_mesh_for_geo_cache(input_mesh, suffix)
        new_input_meshes.append(cmds.listRelatives(mesh, parent=True)[0])
        xml_file = find_file_match(node, cacheversion, extension='xml')
        attach_geo_cache(mesh, xml_file)
        clean_inputmesh_connection(node, inattr)
        cmds.connectAttr(mesh + '.worldMesh[0]', node + '.' + inattr)
    cmds.parent(new_input_meshes, groupname)
    # Parse the original group content and clean all the shape which are
    # not used anymore.
    content_to_clean = [
        cmds.listRelatives(node, parent=True)[0] for node in group_content
        if not cmds.ls(cmds.listConnections(node, type='nCloth'))
    ]
    if content_to_clean:
        cmds.delete(content_to_clean)