def process_import(self, context, name, namespace, group, options):
        import maya.cmds as cmds

        cmds.loadPlugin("AtomsProxyMaya", quiet=True)
        if not cmds.pluginInfo("AtomsProxyMaya", query=True, loaded=True):
            self.log.warning("Could not load AtomsProxyMaya plugin")
            return

        representation = context["representation"]

        entry_path = self.file_path(representation)
        entry_path = os.path.expandvars(entry_path)

        variation_file = representation["data"]["variationFile"]
        variation_path = os.path.dirname(entry_path) + "/" + variation_file

        nodes = list()

        with capsule.namespaced(namespace):
            node = "tcAtomsProxy"
            shape = cmds.createNode("tcAtomsProxy", name=node + "Shape")
            parent = cmds.listRelatives(shape, parent=True)
            node = cmds.rename(parent, node)

            nodes = [shape, node]

        cmds.setAttr(shape + ".cachePath", entry_path, type="string")
        cmds.setAttr(shape + ".variationsPath", variation_path, type="string")
        cmds.connectAttr("time1.outTime", shape + ".time", f=True)

        group = cmds.group(node, name=group, world=True)
        nodes.append(group)

        lib.lock_transform(group)
        self[:] = nodes
    def process_import(self, context, name, namespace, group, options):
        from maya import cmds
        from reveries.maya import capsule, arnold

        representation = context["representation"]
        entry_path, use_sequence = self.retrive(representation)

        with capsule.namespaced(namespace):
            standin = arnold.create_standin(entry_path)
            transform = cmds.listRelatives(standin, parent=True)[0]
            group = cmds.group(transform, name=group, world=True)

        if use_sequence:
            cmds.setAttr(standin + ".useFrameExtension", True)
            cmds.connectAttr("time1.outTime", standin + ".frameNumber")

        self[:] = [standin, transform, group]
    def process_import(self, context, name, namespace, group, options):
        from maya import cmds
        from reveries.maya import capsule, arnold

        representation = context["representation"]
        use_sequence = "startFrame" in representation["data"]
        entry_path = self.file_path(representation)

        with capsule.namespaced(namespace):
            volume = arnold.create_volume(entry_path)
            transform = cmds.listRelatives(volume, parent=True)[0]
            group = cmds.group(transform, name=group, world=True)

        if use_sequence:
            cmds.setAttr(volume + ".useFrameExtension", True)

        self[:] = [volume, transform, group]
Ejemplo n.º 4
0
    def extract_anim(self, packager):
        cmds.loadPlugin("animImportExport", quiet=True)

        package_path = packager.create_package()

        entry_file = packager.file_name("anim")
        entry_path = os.path.join(package_path, entry_file)

        sele_file = packager.file_name("mel")
        sele_path = os.path.join(package_path, sele_file)

        # Save animated nodes with order
        with capsule.maintained_selection():
            cmds.select(self.data["outAnim"], replace=True)

            with contextlib.nested(
                    capsule.namespaced(self.data["animatedNamespace"],
                                       new=False),
                    capsule.relative_namespaced()):
                # Save with basename
                with open(sele_path, "w") as fp:
                    fp.write("select -r\n" + "\n".join(cmds.ls(sl=True)) + ";")

        context_data = self.context.data
        start = context_data.get("startFrame")
        end = context_data.get("endFrame")

        with contextlib.nested(
                capsule.no_refresh(),
                capsule.maintained_selection(),
                capsule.undo_chunk(),
        ):
            lib.bake(self.data["outAnim"],
                     frame_range=(start, end),
                     shape=False)

            cmds.select(self.data["outAnim"], replace=True, noExpand=True)
            cmds.file(entry_path,
                      force=True,
                      typ="animExport",
                      exportSelectedAnim=True,
                      options=("options=keys;"
                               "hierarchy=none;"
                               "precision=17;"
                               "intValue=17;"
                               "nodeNames=1;"
                               "verboseUnits=0;"
                               "whichRange=1;"
                               "helpPictures=0;"
                               "useChannelBox=0;"
                               "controlPoints=0;"
                               "shapes=0;"
                               "copyKeyCmd="
                               "-animation objects "
                               "-option keys "
                               "-hierarchy none "
                               "-controlPoints 0 "
                               "-shape 0"))

        packager.add_data({
            "entryFileName": entry_file,
            "animatedAssetId": self.data["animatedAssetId"]
        })
Ejemplo n.º 5
0
    def process_import(self, context, name, namespace, group, options):
        from maya import cmds, mel
        from reveries import plugins

        representation = context["representation"]
        asset_id = representation["data"]["animatedAssetId"]
        selected = cmds.ls(selection=True, long=True)

        # Collect namespace from selected nodes
        namespaces = defaultdict(set)
        for node in selected:
            ns = lib.get_ns(node)
            if ns == ":":
                continue
            namespaces[ns].add(node)

        for ns, nodes in namespaces.items():
            try:
                container = pipeline.get_container_from_namespace(ns)
            except RuntimeError:
                continue

            if asset_id != cmds.getAttr(container + ".assetId"):
                confirm = plugins.message_box_warning(
                    "Warning",
                    "Applying animation to different asset, are you sure ?",
                    optional=True,
                )
                if not confirm:
                    raise Exception("Operation canceled.")

            target_ns = ns
            members = nodes
            break

        else:
            raise Exception("No matched asset found.")

        cmds.loadPlugin("animImportExport", quiet=True)

        entry_path = self.file_path(representation).replace("\\", "/")
        sele_path = entry_path.rsplit("anim", 1)[0] + "mel"
        sele_path = os.path.expandvars(sele_path)

        with capsule.maintained_selection():
            # Select nodes with order
            with contextlib.nested(capsule.namespaced(target_ns, new=False),
                                   capsule.relative_namespaced()):
                self._selection_patch(sele_path)
                mel.eval("source \"%s\"" % sele_path)

            targets = cmds.ls(selection=True, long=True)
            nodes = cmds.file(entry_path,
                              force=True,
                              type="animImport",
                              i=True,
                              importTimeRange="keep",
                              ignoreVersion=True,
                              returnNewNodes=True,
                              options=("targetTime=4;"
                                       "option=replace;"
                                       "connect=0"))
            # Apply namespace by ourselves, since animImport does not
            # take -namespace flag
            namespaced_nodes = list()
            for node in nodes:
                node = cmds.rename(node, namespace + ":" + node)
                namespaced_nodes.append(node)

            # Delete not connected
            targets = set(targets)
            connected = list()
            for node in namespaced_nodes:
                future = cmds.listHistory(node, future=True)
                future = set(cmds.ls(future, long=True))
                if targets.intersection(future):
                    connected.append(node)
                else:
                    cmds.delete(node)

            if not connected:
                raise Exception("No animation been applied.")

            self[:] = connected

        # Remove assigned from selection
        unprocessed = list(set(selected) - members)
        cmds.select(unprocessed, replace=True, noExpand=True)
Ejemplo n.º 6
0
    def process(self, instance):
        from maya import cmds
        from reveries import utils
        from reveries.maya import lib, capsule

        cmds.loadPlugin("animImportExport", quiet=True)

        staging_dir = utils.stage_dir()
        script = "%s.mel" % instance.data["subset"]
        filename = "%s.anim" % instance.data["subset"]
        scriptpath = "%s/%s" % (staging_dir, script)
        outpath = "%s/%s" % (staging_dir, filename)

        animated_asset = instance.data["animatedAssetId"]

        instance.data["repr.anim._stage"] = staging_dir
        instance.data["repr.anim._files"] = [filename, script]
        instance.data["repr.anim.entryFileName"] = filename
        instance.data["repr.anim.animatedAssetId"] = animated_asset

        # Save animated nodes with order
        with capsule.maintained_selection():
            cmds.select(instance.data["outAnim"], replace=True)

            with contextlib.nested(
                    capsule.namespaced(instance.data["animatedNamespace"],
                                       new=False),
                    capsule.relative_namespaced()):
                # Save with basename
                with open(scriptpath, "w") as fp:
                    # Allow not existing nodes between assets
                    fp.write("select -r `ls\n" + "\n".join(cmds.ls(sl=True)) +
                             "`;")

        context_data = instance.context.data
        start = context_data["startFrame"]
        end = context_data["endFrame"]

        instance.data["startFrame"] = start
        instance.data["endFrame"] = end

        with contextlib.nested(
                capsule.no_refresh(),
                capsule.maintained_selection(),
                capsule.undo_chunk(),
        ):
            lib.bake(
                instance.data["outAnim"],
                frame_range=(start, end),
                shape=False,
                # Remove baked from layer so to bake out all keys like
                # animLayers being merged.
                remove_baked_attr_from_layer=True)

            cmds.select(instance.data["outAnim"], replace=True, noExpand=True)
            cmds.file(outpath,
                      force=True,
                      typ="animExport",
                      exportSelectedAnim=True,
                      options=("options=keys;"
                               "hierarchy=none;"
                               "precision=17;"
                               "intValue=17;"
                               "nodeNames=1;"
                               "verboseUnits=0;"
                               "whichRange=1;"
                               "helpPictures=0;"
                               "useChannelBox=0;"
                               "controlPoints=0;"
                               "shapes=0;"
                               "copyKeyCmd="
                               "-animation objects "
                               "-option keys "
                               "-hierarchy none "
                               "-controlPoints 0 "
                               "-shape 0"))