Ejemplo n.º 1
0
 def fix_invalid_missing(cls, instance):
     asset_id = str(instance.context.data["assetDoc"]["_id"])
     with utils.id_namespace(asset_id):
         for node in cls.get_invalid_missing(instance):
             if utils.get_id_status(node) == utils.Identifier.Clean:
                 utils.upsert_id(node, namespace_only=True)
             else:
                 utils.upsert_id(node)
Ejemplo n.º 2
0
    def fix_invalid_asset_id(cls, instance):

        if instance.data["family"] in cls.loose_uuid:
            return

        invalid = cls.get_invalid_asset_id(instance)

        asset_id = str(instance.context.data["assetDoc"]["_id"])
        with utils.id_namespace(asset_id):
            for node in invalid:
                utils.upsert_id(node, namespace_only=True)
Ejemplo n.º 3
0
    def fix_invalid_duplicated(cls, instance):
        invalid = cls.get_invalid_duplicated(instance)

        if instance.data["family"] in cls.loose_uuid:
            # Do not renew id on these families
            utils.update_id_verifiers(invalid)
        else:
            # Re-assign unique id on duplicated
            asset_id = str(instance.context.data["assetDoc"]["_id"])
            with utils.id_namespace(asset_id):
                for node in invalid:
                    # Wipe out invalid Id's verifier so to force Id renew
                    varifier = node + "." + utils.Identifier.ATTR_VERIFIER
                    cmds.setAttr(varifier, "", type="string")
                    utils.upsert_id(node)
    def fix_invalid_duplicated(cls, instance):
        invalid = cls.get_invalid_duplicated(instance)

        if instance.data["family"] in [
                "reveries.setdress",
                "reveries.mayashare",
        ]:
            # Do not renew id on these families
            update_id_verifiers(invalid)
        else:
            # Re-assign unique id on duplicated
            asset_id = str(instance.context.data["assetDoc"]["_id"])
            with id_namespace(asset_id):
                for node in invalid:
                    upsert_id(node)
    def load(self, context, name=None, namespace=None, options=None):

        # (NOTE) AnimWire modifier has a bug that not able to find wires if
        #        namespace is applied.
        #        The hairSystem is okay to work with, but not able to update
        #        XGen preview. So you either simulate without the update, or
        #        build the simulation without namespace and save with .xgen
        #        file exported, then reference it with namespace.
        #
        #        https://forums.autodesk.com/t5/maya-dynamics/anim-wire-
        #        errors-when-using-namespaces/m-p/7329883#M5642
        #

        if not cmds.pluginInfo("xgenToolkit", query=True, loaded=True):
            cmds.loadPlugin("xgenToolkit", quiet=True)

        representation = context["representation"]

        asset = context["asset"]
        asset_name = asset["data"].get("shortName", asset["name"])
        family_name = context["version"]["data"]["families"][0].split(".")[-1]
        namespace = namespace or unique_root_namespace(asset_name, family_name)

        descriptions_data = representation["data"]["descriptionsData"]
        baked = representation["data"]["step"] != xgen.SHAPING
        bound_meshes = list()

        # Varify selection
        selected = cmds.ls(sl=True, long=True)

        all_bound_geos = set()
        for data in descriptions_data.values():
            for geo in data["bound"]:
                all_bound_geos.add("|" + geo)

        msg = ("Require bound geos: {0}\n"
               "Selected: {1}".format(all_bound_geos, selected))
        assert set(selected) == all_bound_geos, msg

        # Rename bound geos to namespace
        for node in selected:
            bound_meshes.append(node)

        # Copy maps
        local_map_dir = os.path.join(avalon.api.Session["AVALON_WORKDIR"],
                                     "xgen",
                                     "published",
                                     # Add username to ease out file lock issue
                                     getpass.getuser())
        map_dir = os.path.join(self.package_path, "maps")
        for palette in os.listdir(map_dir):
            palette_dir = os.path.join(map_dir, palette)
            local_palette_dir = os.path.join(local_map_dir, palette)

            # Copy
            copy_tree(palette_dir, local_palette_dir)

        # Import palette
        palette_nodes = list()
        xgen.preview_clear()

        for file in representation["data"]["palettes"]:

            xgen_path = os.path.join(self.package_path, file)
            xgen_path = xgen_path.replace("\\", "/")
            palette_node = xgen.import_palette(xgen_path,
                                               wrapPatches=True)
            palette_nodes.append(palette_node)

            # Set xgDataPath
            palette = os.path.splitext(file)[0]
            data_path = os.path.join(local_map_dir, palette).replace("\\", "/")
            xgen.set_data_path(palette_node, data_path)

            if not baked:
                # Bind grooming descriptions to geometry
                for desc in xgen.list_descriptions(palette_node):
                    groom = xgen.get_groom(desc)
                    if groom:
                        groom_dir = os.path.join(self.package_path,
                                                 "groom",
                                                 palette_node,
                                                 desc)
                        xgen.import_grooming(desc, groom, groom_dir)

            # Apply ID
            asset_id = str(asset["_id"])
            with utils.id_namespace(asset_id):
                for desc in xgen.list_descriptions(palette_node):
                    _desc = desc.rsplit(":", 1)[-1]
                    id = descriptions_data[_desc]["id"]
                    utils.upsert_id(desc, id)

            # Ensure tube shade disabled
            xgen.disable_tube_shade(palette_node)

        group_name = self.group_name(namespace, name)
        # Cannot be grouped
        # cmds.group(palette_nodes, name=group_name, world=True)
        # palette_nodes = cmds.ls(palette_nodes, long=True)

        # Containerising..
        nodes = palette_nodes[:]
        nodes += bound_meshes
        nodes += cmds.listRelatives(palette_nodes,
                                    allDescendents=True,
                                    fullPath=True)
        nodes += apply_namespace_wrapper(namespace, nodes)

        container_id = options.get("containerId",
                                   utils.generate_container_id())
        container = subset_containerising(name=name,
                                          namespace=namespace,
                                          container_id=container_id,
                                          nodes=nodes,
                                          context=context,
                                          cls_name=self.__class__.__name__,
                                          group_name=group_name)
        return container