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
                ],
            )
Esempio n. 2
0
    def extract_mayabinary(self, nodes, outpath):
        import maya.cmds as cmds
        from reveries.maya import capsule

        geo_id_and_hash = None

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

            mesh_nodes = cmds.ls(nodes,
                                 type="mesh",
                                 noIntermediate=True,
                                 long=True)
            clay_shader = "initialShadingGroup"

            # Perform extraction
            cmds.select(nodes, noExpand=True)

            with capsule.undo_chunk_when_no_undo():

                # Remove mesh history, for removing all intermediate nodes
                transforms = cmds.ls(nodes, type="transform")
                cmds.delete(transforms, constructionHistory=True)
                # Remove all stray shapes, ensure no intermediate nodes
                all_meshes = set(cmds.ls(nodes, type="mesh", long=True))
                cmds.delete(list(all_meshes - set(mesh_nodes)))

                geo_id_and_hash = self.hash(set(mesh_nodes))

                with capsule.assign_shader(mesh_nodes,
                                           shadingEngine=clay_shader):
                    cmds.file(
                        outpath,
                        force=True,
                        typ="mayaBinary",
                        exportSelectedStrict=True,
                        preserveReferences=False,
                        # Shader assignment is the responsibility of
                        # riggers, for animators, and lookdev, for
                        # rendering.
                        shader=False,
                        # Construction history inherited from collection
                        # This enables a selective export of nodes
                        # relevant to this particular plug-in.
                        constructionHistory=False,
                        channels=False,
                        constraints=False,
                        expressions=False,
                    )

        return geo_id_and_hash
    def extract(self):

        with contextlib.nested(
            capsule.no_undo(),
            capsule.no_display_layers(self.member),
            capsule.no_smooth_preview(),
            capsule.maintained_selection(),
            capsule.without_extension(),
        ):
            super(ExtractModel, self).extract()