Esempio n. 1
0
    def ls_subset_groups(cls):
        groups = set()

        for node in lib.lsAttrs({"id": AVALON_CONTAINER_ID}):
            try:
                group = pipeline.get_group_from_container(node)
            except Exception as e:
                cls.log.warning(e)
            else:
                groups.add(group)

        return groups
    def process(self, containers):
        from maya import cmds
        from avalon.maya.pipeline import AVALON_CONTAINERS
        from avalon.tools import cbsceneinventory
        from reveries.maya import hierarchy, pipeline
        from reveries.maya.vendor import sticker
        from reveries import REVERIES_ICONS

        if not self.consent():
            return

        dimmed_icon = REVERIES_ICONS + "/package-01-dimmed.png"

        for container in containers:
            if not self.is_compatible(container):
                continue

            node = container["objectName"]
            members = cmds.sets(node, query=True) or []

            reference_node = self._get_reference_node(members)
            if reference_node is not None:
                # Import Reference
                cmds.file(importReference=True, referenceNode=reference_node)

            namespace = container["namespace"]

            for child in hierarchy.get_sub_container_nodes(container):
                # Update sub-containers' namespace entry
                child_ns = cmds.getAttr(child + ".namespace")
                new_ns = child_ns[len(namespace):]
                cmds.setAttr(child + ".namespace", new_ns, type="string")
                # Add to root container
                cmds.sets(child, forceElement=AVALON_CONTAINERS)

            # Merge namespace to root
            cmds.namespace(removeNamespace=namespace,
                           mergeNamespaceWithRoot=True)

            # Update subset group icon
            group = pipeline.get_group_from_container(node)
            if group is not None:
                sticker.put(group, dimmed_icon)

            # Delete container
            cmds.delete(node)

        # Refresh GUI
        cbsceneinventory.app.window.refresh()

        # Update Icon
        sticker.reveal()
    def ls_subset_groups(cls):
        from avalon.maya.pipeline import AVALON_CONTAINER_ID
        from reveries.maya import lib, pipeline

        groups = set()

        for node in lib.lsAttrs({"id": AVALON_CONTAINER_ID}):
            try:
                group = pipeline.get_group_from_container(node)
            except Exception as e:
                cls.log.warning(e)
            else:
                groups.add(group)

        return groups
    def parse_sub_matrix(self, data):
        """
        """
        import maya.cmds as cmds
        from reveries.lib import DEFAULT_MATRIX
        from reveries.maya.hierarchy import container_from_id_path
        from reveries.maya.pipeline import get_group_from_container

        current_NS = cmds.namespaceInfo(currentNamespace=True,
                                        absoluteName=True)
        for container_id, sub_matrix in data["subMatrix"].items():

            container = container_from_id_path(container_id,
                                               current_NS,
                                               self.cached_container_by_id)

            full_NS = cmds.getAttr(container + ".namespace")
            nodes = cmds.namespaceInfo(full_NS, listOnlyDependencyNodes=True)
            # Collect hidden nodes' address
            hidden = data.get("hidden", {}).get(container_id, [])

            transform_id_map = self.transform_by_id(nodes)

            for address in sub_matrix:
                is_hidden = False

                if address == "GROUP":
                    _, matrix = sub_matrix[address].popitem()
                    transform = get_group_from_container(container)

                else:
                    transform = transform_id_map.get(address)
                    matrix = sub_matrix[address]

                    if address in hidden and transform is not None:
                        is_hidden = True

                if matrix == "<default>":
                    matrix = DEFAULT_MATRIX

                yield transform, matrix, is_hidden
Esempio n. 5
0
    def parse_sub_matrix(self, data, container_id_map):
        """
        """
        import maya.cmds as cmds
        from reveries.lib import DEFAULT_MATRIX
        from reveries.maya.pipeline import get_group_from_container

        def d(mx):
            return DEFAULT_MATRIX if mx == "<default>" else mx

        for container_id, sub_matrix in data["subMatrix"].items():

            container = container_id_map.get(container_id)
            if not container:
                # Possibly been removed in parent asset
                continue

            full_NS = cmds.getAttr(container + ".namespace")
            nodes = cmds.namespaceInfo(full_NS, listOnlyDependencyNodes=True)
            # Collect hidden nodes' address
            hidden = data.get("hidden", {}).get(container_id, {})
            # Collect inheritsTransform
            inherits = data.get("inheritsTransform", {}).get(container_id, {})

            transform_id_map = self.transform_by_id(nodes)

            for address in sub_matrix:
                is_hidden = False

                if address == "GROUP":
                    _, matrix = sub_matrix[address].popitem()
                    _, _inherits = inherits.get(address, {"": None}).popitem()
                    transform = get_group_from_container(container)

                    yield transform, d(matrix), is_hidden, _inherits

                else:
                    transforms = transform_id_map.get(address)
                    matrix = sub_matrix[address]

                    if address in hidden and transforms is not None:
                        is_hidden = True

                    if isinstance(matrix, dict):
                        # (NOTE) New data model for duplicated AvalonID..
                        for transform in transforms or []:
                            short = transform.split("|")[-1].split(":")[-1]
                            _matrix = matrix.get(short)

                            if _matrix is None:
                                continue

                            _hidden = is_hidden and short in hidden[address]
                            _inherits = inherits.get(address, {}).get(short)

                            yield transform, d(_matrix), _hidden, _inherits

                    else:
                        transform = transforms[-1] if transforms else None
                        # `inherits` must be None because we didn't collect
                        # this attribute while using previous data model.
                        yield transform, d(matrix), is_hidden, None

            # Alembic, If any..
            # (NOTE) Shouldn't be loaded here with matrix, need decouple
            alembic = data.get("alembic", {}).get(container_id)
            if alembic:
                abc = cmds.ls(nodes, type="AlembicNode")
                if abc:
                    abc = abc[0]  # Should have one and only one alembic node
                    yield "<alembic>", alembic, abc, None
def ls_subset_groups():
    groups = set()
    for node in lib.lsAttrs({"id": AVALON_CONTAINER_ID}):
        groups.add(pipeline.get_group_from_container(node))
    return groups
    def process(self, containers):
        from maya import cmds
        from avalon.maya.pipeline import AVALON_CONTAINERS
        from avalon.tools import sceneinventory
        from reveries.maya import hierarchy, pipeline, lib, capsule
        from reveries.maya.vendor import sticker
        from reveries import REVERIES_ICONS

        if not self.consent():
            return

        dimmed_icon = REVERIES_ICONS + "/package-01-dimmed.png"

        # Copy Look's textures first
        try:
            with capsule.undo_chunk(undo_on_exit=False):
                for container in containers:
                    if container["loader"] == "LookLoader":
                        self.unpack_textures(container)
        except Exception as e:
            cmds.undo()
            raise e

        # Unpack
        for container in containers:
            if not self.is_compatible(container):
                continue

            node = container["objectName"]
            members = cmds.sets(node, query=True) or []

            reference_node = lib.get_highest_reference_node(members)
            if reference_node is not None:
                # Import Reference
                cmds.file(importReference=True, referenceNode=reference_node)

            namespace = container["namespace"]

            for child in hierarchy.get_sub_container_nodes(container):
                # Update sub-containers' namespace entry
                child_ns = cmds.getAttr(child + ".namespace")
                new_ns = child_ns[len(namespace):]
                cmds.setAttr(child + ".namespace", new_ns, type="string")
                # Add to root container
                cmds.sets(child, forceElement=AVALON_CONTAINERS)

            # Merge namespace to root
            cmds.namespace(removeNamespace=namespace,
                           mergeNamespaceWithRoot=True)

            # Update subset group icon
            group = pipeline.get_group_from_container(node)
            if group is not None:
                sticker.put(group, dimmed_icon)

            # Delete container
            cmds.delete(node)

        # Refresh GUI
        sceneinventory.app.window.refresh()

        # Update Icon
        sticker.reveal()