def extract_setPackage(self, packager):
        entry_file = packager.file_name("abc")
        instances_file = packager.file_name("json")
        package_path = packager.create_package()
        entry_path = os.path.join(package_path, entry_file)
        instances_path = os.path.join(package_path, instances_file)

        self.parse_matrix()

        self.log.info("Dumping setdress members data ..")
        with open(instances_path, "w") as fp:
            json.dump(self.data["subsetData"], fp, ensure_ascii=False)
            self.log.debug("Dumped: {}".format(instances_path))

        self.log.info("Extracting hierarchy ..")
        cmds.select(self.data["subsetSlots"])
        io.export_alembic(file=entry_path,
                          startFrame=1.0,
                          endFrame=1.0,
                          selection=True,
                          uvWrite=True,
                          writeVisibility=True,
                          writeCreases=True,
                          attr=[lib.AVALON_ID_ATTR_LONG])

        packager.add_data({
            "entryFileName": entry_file,
        })

        self.log.debug("Exported: {}".format(entry_path))

        cmds.select(clear=True)
Exemplo n.º 2
0
    def extract_alembic(self, nodes, outpath):
        import maya.cmds as cmds
        from reveries.maya import capsule, io, lib

        with contextlib.nested(
                capsule.no_undo(),
                capsule.no_display_layers(nodes),
                capsule.no_smooth_preview(),
                capsule.maintained_selection(),
                capsule.without_extension(),
        ):

            cmds.select(nodes, noExpand=True)

            frame = cmds.currentTime(query=True)
            io.export_alembic(
                outpath,
                frame,
                frame,
                selection=True,
                renderableOnly=True,
                writeCreases=True,
                worldSpace=True,
                uvWrite=True,
                writeUVSets=True,
                attr=[
                    lib.AVALON_ID_ATTR_LONG,
                ],
                attrPrefix=[
                    "ai",  # Write out Arnold attributes
                ],
            )
Exemplo n.º 3
0
    def extract_Alembic(self, packager):
        entry_file = packager.file_name("abc")
        package_path = packager.create_package()
        entry_path = os.path.join(package_path, entry_file)

        cmds.select(self.member, noExpand=True)

        frame = cmds.currentTime(query=True)
        io.export_alembic(
            entry_path,
            frame,
            frame,
            selection=True,
            renderableOnly=True,
            writeCreases=True,
            worldSpace=True,
            attr=[
                lib.AVALON_ID_ATTR_LONG,
            ],
            attrPrefix=[
                "ai",  # Write out Arnold attributes
            ],
        )

        packager.add_data({
            "entryFileName": entry_file,
        })
Exemplo n.º 4
0
    def extract_Alembic(self):
        entry_file = self.file_name("ma")
        cache_file = self.file_name("abc")
        package_path = self.create_package()
        entry_path = os.path.join(package_path, entry_file)
        cache_path = os.path.join(package_path, cache_file)

        root = cmds.ls(sl=True, long=True)

        with capsule.maintained_selection():
            # Selection may change if there are duplicate named nodes and
            # require instancing them to resolve

            with capsule.delete_after() as delete_bin:

                # (NOTE) We need to check any duplicate named nodes, or
                #        error will raised during Alembic export.
                result = lib.ls_duplicated_name(root)
                duplicated = [n for m in result.values() for n in m]
                if duplicated:
                    # Create instance to avoid duplicated names
                    instanced = cmds.instance(duplicated)
                    # Instance nodes will be deleted after the export
                    delete_bin.extend(instanced)
                    # Update root nodes
                    root = list(set(root) - set(duplicated)) + instanced

                io.export_alembic(
                    cache_path,
                    self.start_frame,
                    self.end_frame,
                    selection=False,
                    renderableOnly=True,
                    writeCreases=True,
                    worldSpace=True,
                    root=root,
                    attr=[
                        lib.AVALON_ID_ATTR_LONG,
                    ],
                    attrPrefix=[
                        "ai",  # Write out Arnold attributes
                    ],
                )

        io.wrap_abc(entry_path, [(cache_file, "ROOT")])

        self.add_data({"entryFileName": entry_file})
        self.add_range_data()
    def extract_Alembic(self):

        entry_file = self.file_name("abc")
        package_path = self.create_package()
        entry_path = os.path.join(package_path, entry_file)

        with avalon.maya.maintained_selection():
            io.export_alembic(entry_path, self.start, self.end)

        self.add_data({
            "entryFileName": entry_file,
            "cameraUUID": self.camera_uuid,
            "startFrame": self.start,
            "endFrame": self.end,
            "byFrameStep": self.step,
        })
 def _export_alembic():
     io.export_alembic(
         outpath,
         start,
         end,
         selection=True,
         renderableOnly=True,
         writeVisibility=True,
         writeCreases=True,
         worldSpace=True,
         eulerFilter=euler_filter,
         attr=[
             lib.AVALON_ID_ATTR_LONG,
         ],
         attrPrefix=[
             "ai",  # Write out Arnold attributes
             "avnlook_",  # Write out lookDev controls
         ],
     )
Exemplo n.º 7
0
    def extract_Alembic(self, packager):

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

        euler_filter = self.data.get("eulerFilter", False)

        with avalon.maya.maintained_selection():
            io.export_alembic(entry_path,
                              self.start,
                              self.end,
                              eulerFilter=euler_filter)

        packager.add_data({
            "entryFileName": entry_file,
            "cameraUUID": self.camera_uuid,
            "startFrame": self.start,
            "endFrame": self.end,
            "byFrameStep": self.step,
        })
Exemplo n.º 8
0
    def process(self, instance):
        from maya import cmds
        from reveries import utils
        from reveries.maya import io, lib

        staging_dir = utils.stage_dir()
        filename = "%s.abc" % instance.data["subset"]
        members = "%s.json" % instance.data["subset"]

        outpath = "%s/%s" % (staging_dir, filename)
        memberpath = "%s/%s" % (staging_dir, members)

        instance.data["repr.setPackage._stage"] = staging_dir
        instance.data["repr.setPackage._files"] = [filename, members]
        instance.data["repr.setPackage.entryFileName"] = filename

        self.parse_matrix(instance)

        self.log.info("Dumping setdress members data ..")
        with open(memberpath, "w") as fp:
            json.dump(instance.data["subsetData"], fp, ensure_ascii=False)
            self.log.debug("Dumped: {}".format(memberpath))

        self.log.info("Extracting hierarchy ..")
        cmds.select(instance.data["subsetSlots"])
        io.export_alembic(file=outpath,
                          startFrame=1.0,
                          endFrame=1.0,
                          selection=True,
                          uvWrite=True,
                          writeUVSets=True,
                          writeVisibility=True,
                          writeCreases=True,
                          attr=[lib.AVALON_ID_ATTR_LONG])

        self.log.debug("Exported: {}".format(outpath))

        cmds.select(clear=True)
    def extract_Alembic(self, packager):
        from reveries.maya import io, lib, capsule
        from maya import cmds

        packager.skip_stage()

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

        euler_filter = self.data.get("eulerFilter", False)

        root = self.data["outCache"]

        with capsule.maintained_selection():
            # Selection may change if there are duplicate named nodes and
            # require instancing them to resolve

            with capsule.delete_after() as delete_bin:

                # (NOTE) We need to check any duplicate named nodes, or
                #        error will raised during Alembic export.
                result = lib.ls_duplicated_name(root)
                duplicated = [n for m in result.values() for n in m]
                if duplicated:
                    # Duplicate it so we could have a unique named new node
                    unique_named = list()
                    for node in duplicated:
                        new_nodes = cmds.duplicate(node,
                                                   inputConnections=True,
                                                   renameChildren=True)
                        new_nodes = cmds.ls(new_nodes, long=True)
                        unique_named.append(new_nodes[0])
                        # New nodes will be deleted after the export
                        delete_bin.extend(new_nodes)

                    # Replace duplicat named nodes with unique named
                    root = list(set(root) - set(duplicated)) + unique_named

                for node in set(root):
                    # (NOTE) If a descendent is instanced, it will appear only
                    #        once on the list returned.
                    root += cmds.listRelatives(node,
                                               allDescendents=True,
                                               fullPath=True,
                                               noIntermediate=True) or []
                root = list(set(root))
                cmds.select(root, replace=True, noExpand=True)

                io.export_alembic(
                    entry_path,
                    self.start_frame,
                    self.end_frame,
                    selection=True,
                    renderableOnly=True,
                    writeVisibility=True,
                    writeCreases=True,
                    worldSpace=True,
                    eulerFilter=euler_filter,
                    attr=[
                        lib.AVALON_ID_ATTR_LONG,
                    ],
                    attrPrefix=[
                        "ai",  # Write out Arnold attributes
                    ],
                )

        # (NOTE) Deprecated
        # io.wrap_abc(entry_path, [(cache_file, "ROOT")])

        packager.add_data({"entryFileName": entry_file})
        self.add_range_data()
Exemplo n.º 10
0
    def extract_all(self,
                    cam_transform,
                    ma_outpath,
                    abc_outpath,
                    fbx_outpath,
                    start,
                    end,
                    step,
                    euler_filter,
                    do_bake,
                    donot_bake,
                    duplicate_input_graph=False):
        from maya import cmds
        from reveries.maya import io, lib, capsule

        with contextlib.nested(
                capsule.no_refresh(),
                capsule.no_undo(),
                capsule.attribute_states(donot_bake, lock=False,
                                         keyable=False),
                capsule.attribute_states(do_bake, lock=False, keyable=True),
                capsule.evaluation("off"),
        ):
            with capsule.delete_after() as delete_bin:

                # bake to worldspace
                frame_range = (start, end)
                baked_camera = lib.bake_to_world_space(
                    cam_transform,
                    frame_range,
                    step=step,
                    # Remove baked from layer so to bake out all keys like
                    # animLayers being merged.
                    remove_baked_attr_from_layer=True,
                    duplicate_input_graph=duplicate_input_graph)[0]
                delete_bin.append(baked_camera)

                cmds.select(
                    baked_camera,
                    hierarchy=True,  # With shape
                    replace=True,
                    noExpand=True)

                with avalon.maya.maintained_selection():
                    io.export_alembic(abc_outpath,
                                      start,
                                      end,
                                      eulerFilter=euler_filter)

                with capsule.undo_chunk_when_no_undo():
                    if euler_filter:
                        cmds.filterCurve(cmds.ls(sl=True))

                    with avalon.maya.maintained_selection():
                        cmds.file(
                            ma_outpath,
                            force=True,
                            typ="mayaAscii",
                            exportSelected=True,
                            preserveReferences=False,
                            constructionHistory=False,
                            channels=True,  # allow animation
                            constraints=False,
                            shader=False,
                            expressions=False)

                    with avalon.maya.maintained_selection():
                        io.export_fbx_set_camera()
                        io.export_fbx(fbx_outpath)