Skip to content

collect_render

Collect Render

CollectRender

Bases: InstancePlugin

Collect Render for Deadline

Source code in client/ayon_max/plugins/publish/collect_render.py
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
class CollectRender(pyblish.api.InstancePlugin):
    """Collect Render for Deadline"""

    order = pyblish.api.CollectorOrder + 0.02
    label = "Collect 3dsmax Render Layers"
    hosts = ['max']
    families = ["maxrender"]

    def process(self, instance):
        context = instance.context
        folder = rt.maxFilePath
        file = rt.maxFileName
        current_file = os.path.join(folder, file)
        filepath = current_file.replace("\\", "/")
        context.data['currentFile'] = current_file

        files_by_aov = RenderProducts().get_beauty(instance.name)
        aovs = RenderProducts().get_aovs(instance.name)
        files_by_aov.update(aovs)

        camera = rt.viewport.GetCamera()
        if instance.data.get("members"):
            camera_list = [member for member in instance.data["members"]
                           if rt.ClassOf(member) == rt.Camera.Classes]
            if camera_list:
                camera = camera_list[-1]

        instance.data["cameras"] = [camera.name] if camera else None        # noqa

        if instance.data.get("multiCamera"):
            cameras = instance.data.get("members")
            if not cameras:
                raise KnownPublishError("There should be at least"
                                        " one renderable camera in container")
            sel_cam = [
                c.name for c in cameras
                if rt.classOf(c) in rt.Camera.classes]
            container_name = instance.data.get("instance_node")
            render_dir = os.path.dirname(rt.rendOutputFilename)
            outputs = RenderSettings().batch_render_layer(
                container_name, render_dir, sel_cam
            )

            instance.data["cameras"] = sel_cam

            files_by_aov = RenderProducts().get_multiple_beauty(
                outputs, sel_cam)
            aovs = RenderProducts().get_multiple_aovs(
                outputs, sel_cam)
            files_by_aov.update(aovs)

        if "expectedFiles" not in instance.data:
            instance.data["expectedFiles"] = list()
            instance.data["files"] = list()
            instance.data["expectedFiles"].append(files_by_aov)
            instance.data["files"].append(files_by_aov)
        img_format = RenderProducts().image_format()
        # OCIO config not support in
        # most of the 3dsmax renderers
        # so this is currently hard coded
        # TODO: add options for redshift/vray ocio config
        instance.data["colorspaceConfig"] = ""
        instance.data["colorspaceDisplay"] = "sRGB"
        instance.data["colorspaceView"] = "ACES 1.0 SDR-video"

        if int(get_max_version()) >= 2024:
            colorspace_mgr = rt.ColorPipelineMgr      # noqa
            display = next(
                (display for display in colorspace_mgr.GetDisplayList()))
            view_transform = next(
                (view for view in colorspace_mgr.GetViewList(display)))
            instance.data["colorspaceConfig"] = colorspace_mgr.OCIOConfigPath
            instance.data["colorspaceDisplay"] = display
            instance.data["colorspaceView"] = view_transform

        instance.data["renderProducts"] = colorspace.ARenderProduct()
        instance.data["publishJobState"] = "Suspended"
        instance.data["attachTo"] = []
        renderer_class = get_current_renderer()
        renderer = str(renderer_class).split(":")[0]
        product_type = "maxrender"
        # also need to get the render dir for conversion
        data = {
            "folderPath": instance.data["folderPath"],
            "productName": str(instance.name),
            "publish": True,
            "maxversion": str(get_max_version()),
            "imageFormat": img_format,
            "productType": product_type,
            "family": product_type,
            "families": [product_type],
            "renderer": renderer,
            "source": filepath,
            "plugin": "3dsmax",
            "frameStart": instance.data["frameStartHandle"],
            "frameEnd": instance.data["frameEndHandle"],
            "farm": True
        }
        instance.data.update(data)

        # TODO: this should be unified with maya and its "multipart" flag
        #       on instance.
        if renderer == "Redshift_Renderer":
            instance.data.update(
                {"separateAovFiles": rt.Execute(
                    "renderers.current.separateAovFiles")})

        self.log.info("data: {0}".format(data))