Skip to content

extract_multiverse_look

ExtractMultiverseLook

Bases: MayaExtractorPlugin

Extractor for Multiverse USD look data.

This will extract:

  • the shading networks that are assigned in MEOW as Maya material overrides to a Multiverse Compound
  • settings for a Multiverse Write Override operation.

Relevant settings are visible in the Maya set node created by a Multiverse USD Look instance creator.

The input data contained in the set is:

  • a single Multiverse Compound node with any number of Maya material overrides (typically set in MEOW)

Upon publish two files will be written:

  • a .usda override file containing material assignment information
  • a .ma file containing shading networks
when layering the material assignment override on a loaded Compound,

remember to set a matching attribute override with the namespace of the loaded compound in order for the material assignment to resolve.

Source code in client/ayon_maya/plugins/publish/extract_multiverse_look.py
  9
 10
 11
 12
 13
 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
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
class ExtractMultiverseLook(plugin.MayaExtractorPlugin):
    """Extractor for Multiverse USD look data.

    This will extract:

    - the shading networks that are assigned in MEOW as Maya material overrides
      to a Multiverse Compound
    - settings for a Multiverse Write Override operation.

    Relevant settings are visible in the Maya set node created by a Multiverse
    USD Look instance creator.

    The input data contained in the set is:

    - a single Multiverse Compound node with any number of Maya material
      overrides (typically set in MEOW)

    Upon publish two files will be written:

    - a .usda override file containing material assignment information
    - a .ma file containing shading networks

    Note: when layering the material assignment override on a loaded Compound,
          remember to set a matching attribute override with the namespace of
          the loaded compound in order for the material assignment to resolve.
    """

    label = "Extract Multiverse USD Look"
    families = ["mvLook"]
    scene_type = "usda"
    file_formats = ["usda", "usd"]

    @property
    def options(self):
        """Overridable options for Multiverse USD Export

        Given in the following format
            - {NAME: EXPECTED TYPE}

        If the overridden option's type does not match,
        the option is not included and a warning is logged.

        """

        return {
            "writeAll": bool,
            "writeTransforms": bool,
            "writeVisibility": bool,
            "writeAttributes": bool,
            "writeMaterials": bool,
            "writeVariants": bool,
            "writeVariantsDefinition": bool,
            "writeActiveState": bool,
            "writeNamespaces": bool,
            "numTimeSamples": int,
            "timeSamplesSpan": float
        }

    @property
    def default_options(self):
        """The default options for Multiverse USD extraction."""

        return {
            "writeAll": False,
            "writeTransforms": False,
            "writeVisibility": False,
            "writeAttributes": True,
            "writeMaterials": True,
            "writeVariants": False,
            "writeVariantsDefinition": False,
            "writeActiveState": False,
            "writeNamespaces": True,
            "numTimeSamples": 1,
            "timeSamplesSpan": 0.0
        }

    def get_file_format(self, instance):
        fileFormat = instance.data["fileFormat"]
        if fileFormat in range(len(self.file_formats)):
            self.scene_type = self.file_formats[fileFormat]

    def process(self, instance):
        # Load plugin first
        cmds.loadPlugin("MultiverseForMaya", quiet=True)

        # Define output file path
        staging_dir = self.staging_dir(instance)
        self.get_file_format(instance)
        file_name = "{0}.{1}".format(instance.name, self.scene_type)
        file_path = os.path.join(staging_dir, file_name)
        file_path = file_path.replace('\\', '/')

        # Parse export options
        options = self.default_options
        self.log.debug("Export options: {0}".format(options))

        # Perform extraction
        self.log.debug("Performing extraction ...")

        with maintained_selection():
            members = instance.data("setMembers")
            members = cmds.ls(members,
                              dag=True,
                              shapes=False,
                              type="mvUsdCompoundShape",
                              noIntermediate=True,
                              long=True)
            self.log.debug('Collected object {}'.format(members))
            if len(members) > 1:
                self.log.error('More than one member: {}'.format(members))

            import multiverse

            over_write_opts = multiverse.OverridesWriteOptions()
            options_discard_keys = {
                "numTimeSamples",
                "timeSamplesSpan",
                "frameStart",
                "frameEnd",
                "handleStart",
                "handleEnd",
                "step",
                "fps"
            }
            for key, value in options.items():
                if key in options_discard_keys:
                    continue
                setattr(over_write_opts, key, value)

            for member in members:
                # @TODO: Make sure there is only one here.

                self.log.debug("Writing Override for '{}'".format(member))
                multiverse.WriteOverrides(file_path, member, over_write_opts)

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

        representation = {
            'name': self.scene_type,
            'ext': self.scene_type,
            'files': file_name,
            'stagingDir': staging_dir
        }
        instance.data["representations"].append(representation)

        self.log.debug("Extracted instance {} to {}".format(
            instance.name, file_path))

default_options property

The default options for Multiverse USD extraction.

options property

Overridable options for Multiverse USD Export

Given in the following format - {NAME: EXPECTED TYPE}

If the overridden option's type does not match, the option is not included and a warning is logged.