Skip to content

extract_convert_to_exr

Plugin converting png files from ExtractSequence into exrs.

Requires

ExtractSequence - source of PNG ExtractReview - review was already created so we can convert to any exr

CollectExrUserOptions

Bases: ContextPlugin, AYONPyblishPluginMixin

Collect data for EXR conversion.

Source code in client/ayon_harmony/plugins/publish/extract_convert_to_exr.py
 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
class CollectExrUserOptions(
    pyblish.api.ContextPlugin,
    AYONPyblishPluginMixin
):
    """Collect data for EXR conversion."""
    order = pyblish.api.CollectorOrder - 0.45
    label = "Collect Sequence EXR"
    hosts = ["harmony"]
    settings_category = "harmony"

    multichannel_exr = False
    user_overrides = []

    @classmethod
    def apply_settings(cls, project_settings):
        plugin_settins = get_plugin_settings(
            ExtractConvertToEXR, project_settings, cls.log, "harmony"
        )
        apply_plugin_settings_automatically(
            cls, plugin_settins, cls.log
        )

    @classmethod
    def register_create_context_callbacks(cls, create_context):
        create_context.add_value_changed_callback(cls._on_value_change)

    @classmethod
    def _on_value_change(cls, event):
        event_data = event.data
        create_context: CreateContext = event_data["create_context"]
        for change in event_data["changes"]:
            instance: Optional[CreatedInstance] = change["instance"]
            if instance is not None:
                continue

            value = change["changes"]
            for key in (
                "publish_attributes",
                cls.__name__,
                "convert_to_exr",
            ):
                value = value.get(key)
                if value is None:
                    break

            if value is not None:
                create_context.set_context_publish_plugin_attr_defs(
                    cls.__name__,
                    cls.get_attr_defs_for_context(create_context)
                )
            break

    @classmethod
    def get_attr_defs_for_context(
        cls, create_context: CreateContext
    ) -> list[AbstractAttrDef]:
        has_create_exr = "create_exr" in cls.user_overrides
        has_multichannel_exr = "multichannel_exr" in cls.user_overrides

        if not has_create_exr and not has_multichannel_exr:
            return []

        items = []
        if has_create_exr:
            items.append({"value": "skip_exr", "label": "No conversion"})

        default = "create_exr"
        items.append({"value": "create_exr", "label": "Create EXR"})
        if has_multichannel_exr:
            items.append({
                "value": "multichannel_exr",
                "label": "Create multichannel EXR"
            })
            if cls.multichannel_exr:
                default = "multichannel_exr"

        attr_defs: list[AbstractAttrDef] = [
            EnumDef(
                "convert_to_exr",
                label="Convert to EXR",
                items=items,
                default=default,
                tooltip="Convert PNGs to EXR",
            )
        ]
        current_value = (
            create_context
            .publish_attributes
            .get(cls.__name__, {})
            .get("convert_to_exr")
        )
        if (
            current_value == "multichannel_exr"
            and "keep_passes" in cls.user_overrides
        ):
            attr_defs.append(
                BoolDef(
                    "keep_passes",
                    default=False,
                    label="Keep render passes",
                )
            )

        return attr_defs

    def process(self, context):
        attr_values = self.get_attr_values_from_data(context.data)
        context.data["convertExrData"] = {
            "user_value": attr_values.get("convert_to_exr"),
            "keep_passes": attr_values.get("keep_passes"),
        }