Esempio n. 1
0
def check_uv_border_crossing():
    """checks if any of the uv shells are crossing uv borders
    """
    # skip if this is a representation
    v = staging.get('version')
    if v and Representation.repr_separator in v.take_name:
        return

    all_meshes = pm.ls(type='mesh')
    mesh_count = len(all_meshes)

    nodes_with_uvs_crossing_borders = []

    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    if not pm.general.about(batch=1) and mesh_count:
        pdm.use_ui = True

    caller = pdm.register(mesh_count, 'check_out_of_space_uvs()')

    for node in all_meshes:
        all_uvs = node.getUVs()
        uv_shell_ids = node.getUvShellsIds()

        # prepare an empty dict of lists
        uvs_per_shell = {}
        for shell_id in range(uv_shell_ids[1]):
            uvs_per_shell[shell_id] = [[], []]

        for uv_id in range(len(uv_shell_ids[0])):
            u = all_uvs[0][uv_id]
            v = all_uvs[1][uv_id]
            shell_id = uv_shell_ids[0][uv_id]

            uvs_per_shell[shell_id][0].append(u)
            uvs_per_shell[shell_id][1].append(v)

        # now check all uvs per shell
        for shell_id in range(uv_shell_ids[1]):
            us = sorted(uvs_per_shell[shell_id][0])
            vs = sorted(uvs_per_shell[shell_id][1])

            # check first and last u and v values
            if int(us[0]) != int(us[-1]) or int(vs[0]) != int(vs[-1]):
                # they are not equal it is crossing spaces
                nodes_with_uvs_crossing_borders.append(node)
                break

        caller.step()

    if len(nodes_with_uvs_crossing_borders):
        # get transform nodes
        tra_nodes = map(lambda x: x.getParent(),
                        nodes_with_uvs_crossing_borders)
        pm.select(tra_nodes)
        raise RuntimeError(
            """There are nodes with <b>UV-Shells</b> that are crossing
            <b>UV BORDERS</b>:<br><br>%s""" %
            '<br>'.join(map(lambda x: x.name(), tra_nodes[:MAX_NODE_DISPLAY])))
Esempio n. 2
0
def check_uvs():
    """checks uvs with no uv area

    The area of a 2d polygon calculation is based on the answer of Darius Bacon
    in http://stackoverflow.com/questions/451426/how-do-i-calculate-the-surface-area-of-a-2d-polygon
    """

    # skip if this is a representation
    v = staging.get('version')
    if v and Representation.repr_separator in v.take_name:
        return

    def area(p):
        return 0.5 * abs(sum(x0 * y1 - x1 * y0
                             for ((x0, y0), (x1, y1)) in segments(p)))

    def segments(p):
        return zip(p, p[1:] + [p[0]])

    all_meshes = pm.ls(type='mesh')
    mesh_count = len(all_meshes)

    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    if not pm.general.about(batch=1) and mesh_count:
        pdm.use_ui = True

    caller = pdm.register(mesh_count, 'check_uvs()')

    meshes_with_zero_uv_area = []
    for node in all_meshes:
        all_uvs = node.getUVs()
        try:
            for i in range(node.numFaces()):
                uvs = []
                for j in range(node.numPolygonVertices(i)):
                    # uvs.append(node.getPolygonUV(i, j))
                    uv_id = node.getPolygonUVid(i, j)
                    uvs.append((all_uvs[0][uv_id], all_uvs[1][uv_id]))
                if area(uvs) == 0.0:
                    meshes_with_zero_uv_area.append(node)
                    break
        except RuntimeError:
            meshes_with_zero_uv_area.append(node)

        caller.step()

    if len(meshes_with_zero_uv_area):
        pm.select([node.getParent() for node in meshes_with_zero_uv_area])
        raise RuntimeError(
            """There are meshes with no uvs or faces with zero uv area:<br><br>
            %s""" %
            '<br>'.join(
                map(lambda x: x.name(),
                    meshes_with_zero_uv_area[:MAX_NODE_DISPLAY])
            )
        )
Esempio n. 3
0
    def select_zero_uv_area_faces(cls):
        """selects faces with zero UV area
        """
        def area(p):
            return 0.5 * abs(sum(x0 * y1 - x1 * y0
                                 for ((x0, y0), (x1, y1)) in segments(p)))

        def segments(p):
            return zip(p, p[1:] + [p[0]])

        all_meshes = pm.ls(
            [node.getShape() for node in pm.ls(sl=1)],
            type='mesh'
        )

        mesh_count = len(all_meshes)

        from anima.env.mayaEnv import MayaMainProgressBarWrapper
        from anima.ui.progress_dialog import ProgressDialogManager
        wrp = MayaMainProgressBarWrapper()
        pdm = ProgressDialogManager(dialog=wrp)

        if not pm.general.about(batch=1) and mesh_count:
            pdm.use_ui = True

        caller = pdm.register(mesh_count, 'check_uvs()')

        faces_with_zero_uv_area = []
        for node in all_meshes:
            all_uvs = node.getUVs()
            for i in range(node.numFaces()):
                uvs = []
                try:
                    for j in range(node.numPolygonVertices(i)):
                        # uvs.append(node.getPolygonUV(i, j))
                        uv_id = node.getPolygonUVid(i, j)
                        uvs.append((all_uvs[0][uv_id], all_uvs[1][uv_id]))
                    if area(uvs) == 0.0:
                        # meshes_with_zero_uv_area.append(node)
                        # break
                        faces_with_zero_uv_area.append(
                            '%s.f[%s]' % (node.fullPath(), i)
                        )
                except RuntimeError:
                    faces_with_zero_uv_area.append(
                        '%s.f[%s]' % (node.fullPath(), i)
                    )

            caller.step()

        if len(faces_with_zero_uv_area) == 0:
            pm.warning('No Zero UV area polys found!!!')
            return []
        else:
            pm.select(faces_with_zero_uv_area)
            return faces_with_zero_uv_area
Esempio n. 4
0
def check_uvs():
    """checks uvs with no uv area

    The area of a 2d polygon calculation is based on the answer of Darius Bacon
    in http://stackoverflow.com/questions/451426/how-do-i-calculate-the-surface-area-of-a-2d-polygon
    """

    # skip if this is a representation
    v = staging.get('version')
    if v and Representation.repr_separator in v.take_name:
        return

    def area(p):
        return 0.5 * abs(
            sum(x0 * y1 - x1 * y0 for ((x0, y0), (x1, y1)) in segments(p)))

    def segments(p):
        return zip(p, p[1:] + [p[0]])

    all_meshes = pm.ls(type='mesh')
    mesh_count = len(all_meshes)

    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    if not pm.general.about(batch=1) and mesh_count:
        pdm.use_ui = True

    caller = pdm.register(mesh_count, 'check_uvs()')

    meshes_with_zero_uv_area = []
    for node in all_meshes:
        all_uvs = node.getUVs()
        try:
            for i in range(node.numFaces()):
                uvs = []
                for j in range(node.numPolygonVertices(i)):
                    # uvs.append(node.getPolygonUV(i, j))
                    uv_id = node.getPolygonUVid(i, j)
                    uvs.append((all_uvs[0][uv_id], all_uvs[1][uv_id]))
                if area(uvs) == 0.0:
                    meshes_with_zero_uv_area.append(node)
                    break
        except RuntimeError:
            meshes_with_zero_uv_area.append(node)

        caller.step()

    if len(meshes_with_zero_uv_area):
        pm.select([node.getParent() for node in meshes_with_zero_uv_area])
        raise RuntimeError(
            """There are meshes with no uvs or faces with zero uv area:<br><br>
            %s""" % '<br>'.join(
                map(lambda x: x.name(),
                    meshes_with_zero_uv_area[:MAX_NODE_DISPLAY])))
Esempio n. 5
0
def check_component_edits_on_references():
    """check if there are component edits on references
    """
    # skip if this is a representation
    v = staging.get('version')
    if v and Representation.repr_separator in v.take_name:
        return

    import maya.cmds
    reference_query = maya.cmds.referenceQuery

    references_with_component_edits = []

    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    all_refs = pm.listReferences(recursive=True)
    ref_count = len(all_refs)

    if not pm.general.about(batch=1) and ref_count:
        pdm.use_ui = True

    caller = pdm.register(
        ref_count,
        'Checking component edits on %i reference nodes' % ref_count
    )

    for ref in all_refs:
        all_edits = reference_query(ref.refNode.name(), es=True)
        # joined_edits = '\n'.join(all_edits)
        # if '.pt[' in joined_edits or '.pnts[' in joined_edits:
        #     references_with_component_edits.append(ref)
        for edit in all_edits:
            if '.pt[' in edit or '.pnts[' in edit:
                references_with_component_edits.append(ref)
                break
        caller.step()

    caller.end_progress()

    if len(references_with_component_edits):
        raise PublishError(
            'There are <b>component edits</b> on the following References:'
            '<br><br>%s<br><br>Please remove them!!!' %
            '<br>'.join(
                map(lambda x: x.refNode.name(),
                    references_with_component_edits[:MAX_NODE_DISPLAY])
            )
        )
Esempio n. 6
0
def check_component_edits_on_references():
    """check if there are component edits on references
    """
    # skip if this is a representation
    v = staging.get('version')
    if v and Representation.repr_separator in v.take_name:
        return

    import maya.cmds
    reference_query = maya.cmds.referenceQuery

    references_with_component_edits = []

    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    all_refs = pm.listReferences(recursive=True)
    ref_count = len(all_refs)

    if not pm.general.about(batch=1) and ref_count:
        pdm.use_ui = True

    caller = pdm.register(
        ref_count,
        'Checking component edits on %i reference nodes' % ref_count)

    for ref in all_refs:
        all_edits = reference_query(ref.refNode.name(), es=True)
        # joined_edits = '\n'.join(all_edits)
        # if '.pt[' in joined_edits or '.pnts[' in joined_edits:
        #     references_with_component_edits.append(ref)
        for edit in all_edits:
            if '.pt[' in edit or '.pnts[' in edit:
                references_with_component_edits.append(ref)
                break
        caller.step()

    caller.end_progress()

    if len(references_with_component_edits):
        raise PublishError(
            'There are <b>component edits</b> on the following References:'
            '<br><br>%s<br><br>Please remove them!!!' % '<br>'.join(
                map(lambda x: x.refNode.name(),
                    references_with_component_edits[:MAX_NODE_DISPLAY])))
Esempio n. 7
0
def check_out_of_space_uvs():
    """checks if there are uvs with u values that are bigger than 10.0
    """

    # skip if this is a representation
    v = staging.get('version')
    if v and Representation.repr_separator in v.take_name:
        return

    all_meshes = pm.ls(type='mesh')
    mesh_count = len(all_meshes)
    nodes_with_out_of_space_uvs = []

    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    if not pm.general.about(batch=1) and mesh_count:
        pdm.use_ui = True

    caller = pdm.register(mesh_count, 'check_out_of_space_uvs()')

    for node in all_meshes:
        u, v = node.getUVs()
        u = sorted(u)
        if u[0] < 0.0 or u[-1] > 10.0 or v[0] < 0.0:
            nodes_with_out_of_space_uvs.append(node)

        caller.step()

    if len(nodes_with_out_of_space_uvs):
        # get transform nodes
        tra_nodes = map(
            lambda x: x.getParent(),
            nodes_with_out_of_space_uvs
        )
        pm.select(tra_nodes)
        raise RuntimeError(
            """There are nodes which have a UV value bigger than <b>10</b>:
            <br><br>%s""" %
            '<br>'.join(
                map(lambda x: x.name(),
                    tra_nodes[:MAX_NODE_DISPLAY])
            )
        )
Esempio n. 8
0
def check_out_of_space_uvs():
    """checks if there are uvs with u values that are bigger than 10.0
    """

    # skip if this is a representation
    v = staging.get('version')
    if v and Representation.repr_separator in v.take_name:
        return

    all_meshes = pm.ls(type='mesh')
    mesh_count = len(all_meshes)
    nodes_with_out_of_space_uvs = []

    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    if not pm.general.about(batch=1) and mesh_count:
        pdm.use_ui = True

    caller = pdm.register(mesh_count, 'check_out_of_space_uvs()')

    for node in all_meshes:
        u, v = node.getUVs()
        u = sorted(u)
        if u[0] < 0.0 or u[-1] > 10.0 or v[0] < 0.0:
            nodes_with_out_of_space_uvs.append(node)

        caller.step()

    if len(nodes_with_out_of_space_uvs):
        # get transform nodes
        tra_nodes = map(lambda x: x.getParent(), nodes_with_out_of_space_uvs)
        pm.select(tra_nodes)
        raise RuntimeError(
            """There are nodes which have a UV value bigger than <b>10</b>:
            <br><br>%s""" %
            '<br>'.join(map(lambda x: x.name(), tra_nodes[:MAX_NODE_DISPLAY])))
Esempio n. 9
0
def check_uv_border_crossing():
    """checks if any of the uv shells are crossing uv borders
    """
    # skip if this is a representation
    v = staging.get('version')
    if v and Representation.repr_separator in v.take_name:
        return

    all_meshes = pm.ls(type='mesh')
    mesh_count = len(all_meshes)

    nodes_with_uvs_crossing_borders = []

    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    if not pm.general.about(batch=1) and mesh_count:
        pdm.use_ui = True

    caller = pdm.register(mesh_count, 'check_out_of_space_uvs()')

    for node in all_meshes:
        all_uvs = node.getUVs()
        uv_shell_ids = node.getUvShellsIds()

        # prepare an empty dict of lists
        uvs_per_shell = {}
        for shell_id in range(uv_shell_ids[1]):
            uvs_per_shell[shell_id] = [[], []]

        for uv_id in range(len(uv_shell_ids[0])):
            u = all_uvs[0][uv_id]
            v = all_uvs[1][uv_id]
            shell_id = uv_shell_ids[0][uv_id]

            uvs_per_shell[shell_id][0].append(u)
            uvs_per_shell[shell_id][1].append(v)

        # now check all uvs per shell
        for shell_id in range(uv_shell_ids[1]):
            us = sorted(uvs_per_shell[shell_id][0])
            vs = sorted(uvs_per_shell[shell_id][1])

            # check first and last u and v values
            if int(us[0]) != int(us[-1]) or int(vs[0]) != int(vs[-1]):
                # they are not equal it is crossing spaces
                nodes_with_uvs_crossing_borders.append(node)
                break

        caller.step()

    if len(nodes_with_uvs_crossing_borders):
        # get transform nodes
        tra_nodes = map(
            lambda x: x.getParent(),
            nodes_with_uvs_crossing_borders
        )
        pm.select(tra_nodes)
        raise RuntimeError(
            """There are nodes with <b>UV-Shells</b> that are crossing
            <b>UV BORDERS</b>:<br><br>%s""" %
            '<br>'.join(
                map(lambda x: x.name(),
                    tra_nodes[:MAX_NODE_DISPLAY])
            )
        )
Esempio n. 10
0
    def generate_repr_of_all_references(cls,
                                        generate_gpu=True,
                                        generate_ass=True,
                                        generate_rs=True,
                                        skip_existing=False):
        """generates all representations of all references of this scene
        """
        from anima.ui.progress_dialog import ProgressDialogManager
        from anima.env.mayaEnv import Maya, repr_tools, auxiliary
        reload(auxiliary)
        reload(repr_tools)

        paths_visited = []
        versions_to_visit = []
        versions_cannot_be_published = []

        # generate a sorted version list
        # and visit each reference only once
        from anima.env.mayaEnv import MayaMainProgressBarWrapper
        wrp = MayaMainProgressBarWrapper()
        pdm = ProgressDialogManager(dialog=wrp)

        use_progress_window = False
        if not pm.general.about(batch=1):
            use_progress_window = True

        all_refs = pm.listReferences(recursive=True)

        pdm.use_ui = use_progress_window
        caller = pdm.register(len(all_refs), 'List References')

        for ref in reversed(all_refs):
            ref_path = str(ref.path)
            caller.step(message=ref_path)
            if ref_path not in paths_visited:
                v = ref.version
                if v is not None:
                    paths_visited.append(ref_path)
                    versions_to_visit.append(v)

        response = pm.confirmDialog(
            title='Do Create Representations?',
            message='Create all Repr. for all %s FileReferences?'
                    % len(versions_to_visit),
            button=['Yes', 'No'],
            defaultButton='No',
            cancelButton='No',
            dismissString='No'
        )
        if response == 'No':
            return

        # register a new caller
        caller = pdm.register(max_iteration=len(versions_to_visit),
                              title='Generate Reprs')

        m_env = Maya()
        source_version = m_env.get_current_version()
        gen = repr_tools.RepresentationGenerator()

        # open each version
        from stalker import Version
        for v in versions_to_visit:
            local_generate_gpu = generate_gpu
            local_generate_ass = generate_ass
            local_generate_rs = generate_rs

            # check if this is a repr
            if '@' in v.take_name:
                # use the parent
                v = v.parent
                if not v:
                    continue

            if skip_existing:
                # check if there is a GPU or ASS repr
                # generated from this version
                child_versions = Version.query.filter(Version.parent == v).all()
                for cv in child_versions:
                    if local_generate_gpu is True and '@GPU' in cv.take_name:
                        local_generate_gpu = False

                    if local_generate_ass is True and '@ASS' in cv.take_name:
                        local_generate_ass = False

                    if local_generate_rs is True and '@RS' in cv.take_name:
                        local_generate_rs = False

            gen.version = v
            # generate representations
            if local_generate_gpu:
                try:
                    gen.generate_gpu()
                except RuntimeError:
                    if v not in versions_cannot_be_published:
                        versions_cannot_be_published.append(v)

            if local_generate_ass:
                try:
                    gen.generate_ass()
                except RuntimeError:
                    if v not in versions_cannot_be_published:
                        versions_cannot_be_published.append(v)

            if local_generate_rs:
                try:
                    gen.generate_rs()
                except RuntimeError:
                    if v not in versions_cannot_be_published:
                        versions_cannot_be_published.append(v)

            caller.step()

        # now open the source version again
        m_env.open(source_version, force=True, skip_update_check=True)

        # and generate representation for the source
        gen.version = source_version

        # generate representations
        if not versions_cannot_be_published:
            if generate_gpu:
                gen.generate_gpu()
            if generate_ass:
                gen.generate_ass()
            if generate_rs:
                gen.generate_rs()
        else:
            pm.confirmDialog(
                title='Error',
                message='The following versions can not be published '
                        '(check script editor):\n\n%s' % (
                            '\n'.join(
                                map(lambda x: x.nice_name,
                                    versions_cannot_be_published)
                            )
                        ),
                button=['OK'],
                defaultButton='OK',
                cancelButton='OK',
                dismissString='OK'
            )

            pm.error(
                '\n'.join(
                    map(lambda x: x.absolute_full_path,
                        versions_cannot_be_published)
                )
            )