Skip to content

extract_matchmove_script_maya

Extract project for Maya.

ExtractMatchmoveScriptMaya

Bases: Extractor, ExtractScriptBase, OptionalPyblishPluginMixin

Extract Maya MEL script for matchmove.

This is using built-in export script from 3DEqualizer.

Source code in client/ayon_equalizer/plugins/publish/extract_matchmove_script_maya.py
 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
class ExtractMatchmoveScriptMaya(publish.Extractor,
                                 ExtractScriptBase,
                                 OptionalPyblishPluginMixin):
    """Extract Maya MEL script for matchmove.

    This is using built-in export script from 3DEqualizer.
    """

    label = "Extract Maya Script"
    families: ClassVar[list] = ["matchmove"]
    hosts: ClassVar[list] = ["equalizer"]
    optional = True

    order = pyblish.api.ExtractorOrder

    # intentionally ignoring complexity warning (PLR0915 and PLR0912) because
    # of the nature of the export scripts in 3DEqualizer.
    def process(self, instance: pyblish.api.Instance) -> None:  # noqa: C901,PLR0915,PLR0912
        """Extract Maya script from 3DEqualizer.

        This method is using export script shipped with 3DEqualizer to
        maintain as much compatibility as possible. Instead of invoking it
        from the UI, it calls directly the function that is doing the export.
        For that it needs to pass some data that are collected in 3dequalizer
        from the UI, so we need to determine them from the instance itself and
        from the state of the project.

        """
        if not self.is_active(instance.data):
            return
        attr_data = self.get_attr_values_from_data(instance.data)

        # import maya export script from 3DEqualizer
        exporter_path = instance.context.data["tde4_path"] / "sys_data" / "py_scripts" / "export_maya.py"  # noqa: E501
        self.log.debug("Importing %s", exporter_path.as_posix())
        exporter = import_filepath(exporter_path.as_posix())

        # get camera point group
        point_group = None
        point_groups = tde4.getPGroupList()
        for pg in point_groups:
            if tde4.getPGroupType(pg) == "CAMERA":
                point_group = pg
                break
        else:
            # this should never happen as it should be handled by validator
            error_msg = "No camera point group found."
            raise KnownPublishError(error_msg)

        # Here we subtract 1 because 3DE is computing the offset with an offset
        offset = tde4.getCameraFrameOffset(tde4.getCurrentCamera()) - 1
        overscan_width = attr_data["overscan_percent_width"] / 100.0
        overscan_height = attr_data["overscan_percent_height"] / 100.0

        staging_dir = self.staging_dir(instance)

        unit_scales = {
            "mm": 10.0,  # cm -> mm
            "cm": 1.0,  # cm -> cm
            "m": 0.01,  # cm -> m
            "in": 0.393701,  # cm -> in
            "ft": 0.0328084,  # cm -> ft
            "yd": 0.0109361  # cm -> yd
        }
        scale_factor = unit_scales[attr_data["units"]]
        model_selection_enum = instance.data["creator_attributes"]["model_selection"]  # noqa: E501

        with maintained_model_selection():
            # handle model selection
            # We are passing it to existing function that is expecting
            # this value to be an index of selection type.
            # 1 - No models
            # 2 - Selected models
            # 3 - All models
            if model_selection_enum == "__all__":
                model_selection = 3
            elif model_selection_enum == "__none__":
                model_selection = 1
            else:
                # take model from instance and set its selection flag on
                # turn off all others
                model_selection = 2
                point_groups = tde4.getPGroupList()
                for point_group in point_groups:
                    model_list = tde4.get3DModelList(point_group, 0)
                    if model_selection_enum in model_list:
                        model_selection = 2
                        tde4.set3DModelSelectionFlag(
                            point_group, instance.data["model_selection"], 1)
                        break

                    # clear all other model selections
                    for model in model_list:
                        tde4.set3DModelSelectionFlag(point_group, model, 0)

            file_path = Path(staging_dir) / "maya_export"
            if instance.context.data.get("tde4_version"):
                self.log.debug("Exporting to: %s", file_path.as_posix())

            # create representation data
            if "representations" not in instance.data:
                instance.data["representations"] = []

            if instance.context.data["tde4_version"].major == EQUALIZER_7:
                status = exporter._maya_export_mel_file(  # noqa: SLF001
                    f"{file_path.as_posix()}.mel",
                    point_group,
                    [
                        c["id"] for c in instance.data["cameras"]
                        if c["enabled"]
                    ],
                    model_selection,
                    overscan_width,
                    overscan_height,
                    1 if attr_data["export_uv_textures"] else 0,
                    scale_factor,
                    offset,
                    1 if attr_data["hide_reference_frame"] else 0,
                )

                representation = {
                    "name": "mel",
                    "ext": "mel",
                    "files": f"{file_path.name}.mel",
                    "stagingDir": staging_dir,
                }
            elif instance.context.data["tde4_version"].major == EQUALIZER_8:
                exporter.script_version = "4.7"
                status, npoly_warning = exporter._maya_export_python_file(  # noqa: SLF001
                    file_path.as_posix(),  # staging path,
                    point_group,  # camera point group,
                    [
                        c["id"] for c in instance.data["cameras"]
                        if c["enabled"]
                    ],
                    model_selection,
                    overscan_width,
                    overscan_height,
                    1 if attr_data["export_uv_textures"] else 0,
                    scale_factor,
                    offset,
                    1 if attr_data["hide_reference_frame"] else 0,
                    # scene_name
                    maya_valid_name(f"{instance.data['name']}_GRP"),
                    1 if attr_data["point_sets"] else 0,
                    1 if attr_data["export_2p5d"] else 0)
                if npoly_warning:
                    self.log.warning("npoly warning: %s", npoly_warning)
                representation = {
                    "name": "py",
                    "ext": "py",
                    "files": f"{file_path.name}.py",
                    "stagingDir": staging_dir,
                }

        if status != 1:
            # for EM102
            err_msg = f"Export failed {status}"
            raise KnownPublishError(err_msg)

        self.log.debug("output: %s", file_path.as_posix())
        instance.data["representations"].append(representation)

process(instance)

Extract Maya script from 3DEqualizer.

This method is using export script shipped with 3DEqualizer to maintain as much compatibility as possible. Instead of invoking it from the UI, it calls directly the function that is doing the export. For that it needs to pass some data that are collected in 3dequalizer from the UI, so we need to determine them from the instance itself and from the state of the project.

Source code in client/ayon_equalizer/plugins/publish/extract_matchmove_script_maya.py
 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
def process(self, instance: pyblish.api.Instance) -> None:  # noqa: C901,PLR0915,PLR0912
    """Extract Maya script from 3DEqualizer.

    This method is using export script shipped with 3DEqualizer to
    maintain as much compatibility as possible. Instead of invoking it
    from the UI, it calls directly the function that is doing the export.
    For that it needs to pass some data that are collected in 3dequalizer
    from the UI, so we need to determine them from the instance itself and
    from the state of the project.

    """
    if not self.is_active(instance.data):
        return
    attr_data = self.get_attr_values_from_data(instance.data)

    # import maya export script from 3DEqualizer
    exporter_path = instance.context.data["tde4_path"] / "sys_data" / "py_scripts" / "export_maya.py"  # noqa: E501
    self.log.debug("Importing %s", exporter_path.as_posix())
    exporter = import_filepath(exporter_path.as_posix())

    # get camera point group
    point_group = None
    point_groups = tde4.getPGroupList()
    for pg in point_groups:
        if tde4.getPGroupType(pg) == "CAMERA":
            point_group = pg
            break
    else:
        # this should never happen as it should be handled by validator
        error_msg = "No camera point group found."
        raise KnownPublishError(error_msg)

    # Here we subtract 1 because 3DE is computing the offset with an offset
    offset = tde4.getCameraFrameOffset(tde4.getCurrentCamera()) - 1
    overscan_width = attr_data["overscan_percent_width"] / 100.0
    overscan_height = attr_data["overscan_percent_height"] / 100.0

    staging_dir = self.staging_dir(instance)

    unit_scales = {
        "mm": 10.0,  # cm -> mm
        "cm": 1.0,  # cm -> cm
        "m": 0.01,  # cm -> m
        "in": 0.393701,  # cm -> in
        "ft": 0.0328084,  # cm -> ft
        "yd": 0.0109361  # cm -> yd
    }
    scale_factor = unit_scales[attr_data["units"]]
    model_selection_enum = instance.data["creator_attributes"]["model_selection"]  # noqa: E501

    with maintained_model_selection():
        # handle model selection
        # We are passing it to existing function that is expecting
        # this value to be an index of selection type.
        # 1 - No models
        # 2 - Selected models
        # 3 - All models
        if model_selection_enum == "__all__":
            model_selection = 3
        elif model_selection_enum == "__none__":
            model_selection = 1
        else:
            # take model from instance and set its selection flag on
            # turn off all others
            model_selection = 2
            point_groups = tde4.getPGroupList()
            for point_group in point_groups:
                model_list = tde4.get3DModelList(point_group, 0)
                if model_selection_enum in model_list:
                    model_selection = 2
                    tde4.set3DModelSelectionFlag(
                        point_group, instance.data["model_selection"], 1)
                    break

                # clear all other model selections
                for model in model_list:
                    tde4.set3DModelSelectionFlag(point_group, model, 0)

        file_path = Path(staging_dir) / "maya_export"
        if instance.context.data.get("tde4_version"):
            self.log.debug("Exporting to: %s", file_path.as_posix())

        # create representation data
        if "representations" not in instance.data:
            instance.data["representations"] = []

        if instance.context.data["tde4_version"].major == EQUALIZER_7:
            status = exporter._maya_export_mel_file(  # noqa: SLF001
                f"{file_path.as_posix()}.mel",
                point_group,
                [
                    c["id"] for c in instance.data["cameras"]
                    if c["enabled"]
                ],
                model_selection,
                overscan_width,
                overscan_height,
                1 if attr_data["export_uv_textures"] else 0,
                scale_factor,
                offset,
                1 if attr_data["hide_reference_frame"] else 0,
            )

            representation = {
                "name": "mel",
                "ext": "mel",
                "files": f"{file_path.name}.mel",
                "stagingDir": staging_dir,
            }
        elif instance.context.data["tde4_version"].major == EQUALIZER_8:
            exporter.script_version = "4.7"
            status, npoly_warning = exporter._maya_export_python_file(  # noqa: SLF001
                file_path.as_posix(),  # staging path,
                point_group,  # camera point group,
                [
                    c["id"] for c in instance.data["cameras"]
                    if c["enabled"]
                ],
                model_selection,
                overscan_width,
                overscan_height,
                1 if attr_data["export_uv_textures"] else 0,
                scale_factor,
                offset,
                1 if attr_data["hide_reference_frame"] else 0,
                # scene_name
                maya_valid_name(f"{instance.data['name']}_GRP"),
                1 if attr_data["point_sets"] else 0,
                1 if attr_data["export_2p5d"] else 0)
            if npoly_warning:
                self.log.warning("npoly warning: %s", npoly_warning)
            representation = {
                "name": "py",
                "ext": "py",
                "files": f"{file_path.name}.py",
                "stagingDir": staging_dir,
            }

    if status != 1:
        # for EM102
        err_msg = f"Export failed {status}"
        raise KnownPublishError(err_msg)

    self.log.debug("output: %s", file_path.as_posix())
    instance.data["representations"].append(representation)