mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
fixed multiverse usd composition extractor
This commit is contained in:
parent
de8eac521c
commit
7320e570ca
1 changed files with 58 additions and 40 deletions
|
|
@ -1,10 +1,10 @@
|
|||
import os
|
||||
|
||||
import avalon.maya
|
||||
import openpype.api
|
||||
|
||||
from maya import cmds
|
||||
|
||||
import openpype.api
|
||||
from openpype.hosts.maya.api.lib import maintained_selection
|
||||
|
||||
|
||||
class ExtractMultiverseUsdComposition(openpype.api.Extractor):
|
||||
"""Extractor of Multiverse USD Composition."""
|
||||
|
|
@ -29,38 +29,43 @@ class ExtractMultiverseUsdComposition(openpype.api.Extractor):
|
|||
"stripNamespaces": bool,
|
||||
"mergeTransformAndShape": bool,
|
||||
"flattenContent": bool,
|
||||
"writePendingOverrides": bool,
|
||||
"writeTimeRange": bool,
|
||||
"timeRangeStart": int,
|
||||
"timeRangeEnd": int,
|
||||
"timeRangeIncrement": int,
|
||||
"timeRangeNumTimeSamples": int,
|
||||
"timeRangeSamplesSpan": float,
|
||||
"timeRangeFramesPerSecond": float
|
||||
"writePendingOverrides": bool
|
||||
}
|
||||
|
||||
@property
|
||||
def default_options(self):
|
||||
"""The default options for Multiverse USD extraction."""
|
||||
start_frame = int(cmds.playbackOptions(query=True,
|
||||
animationStartTime=True))
|
||||
end_frame = int(cmds.playbackOptions(query=True,
|
||||
animationEndTime=True))
|
||||
|
||||
return {
|
||||
"stripNamespaces": False,
|
||||
"mergeTransformAndShape": False,
|
||||
"flattenContent": False,
|
||||
"writePendingOverrides": False,
|
||||
"writeTimeRange": True,
|
||||
"timeRangeStart": start_frame,
|
||||
"timeRangeEnd": end_frame,
|
||||
"timeRangeIncrement": 1,
|
||||
"timeRangeNumTimeSamples": 0,
|
||||
"timeRangeSamplesSpan": 0.0,
|
||||
"timeRangeFramesPerSecond": 24.0
|
||||
"writePendingOverrides": False
|
||||
}
|
||||
|
||||
def parse_overrides(self, instance, options):
|
||||
"""Inspect data of instance to determine overridden options"""
|
||||
|
||||
for key in instance.data:
|
||||
if key not in self.options:
|
||||
continue
|
||||
|
||||
# Ensure the data is of correct type
|
||||
value = instance.data[key]
|
||||
if not isinstance(value, self.options[key]):
|
||||
self.log.warning(
|
||||
"Overridden attribute {key} was of "
|
||||
"the wrong type: {invalid_type} "
|
||||
"- should have been {valid_type}".format(
|
||||
key=key,
|
||||
invalid_type=type(value).__name__,
|
||||
valid_type=self.options[key].__name__))
|
||||
continue
|
||||
|
||||
options[key] = value
|
||||
|
||||
return options
|
||||
|
||||
def process(self, instance):
|
||||
# Load plugin firstly
|
||||
cmds.loadPlugin("MultiverseForMaya", quiet=True)
|
||||
|
|
@ -73,46 +78,59 @@ class ExtractMultiverseUsdComposition(openpype.api.Extractor):
|
|||
|
||||
# Parse export options
|
||||
options = self.default_options
|
||||
options = self.parse_overrides(instance, options)
|
||||
self.log.info("Export options: {0}".format(options))
|
||||
|
||||
# Perform extraction
|
||||
self.log.info("Performing extraction ...")
|
||||
|
||||
with avalon.maya.maintained_selection():
|
||||
with maintained_selection():
|
||||
members = instance.data("setMembers")
|
||||
members = cmds.ls(members,
|
||||
dag=True,
|
||||
shapes=True,
|
||||
type=("mvUsdCompoundShape"),
|
||||
type="mvUsdCompoundShape",
|
||||
noIntermediate=True,
|
||||
long=True)
|
||||
self.log.info('Collected object {}'.format(members))
|
||||
|
||||
# TODO: Deal with asset, composition, overide with options.
|
||||
import multiverse
|
||||
|
||||
time_opts = None
|
||||
if options["writeTimeRange"]:
|
||||
frame_start = instance.data['frameStart']
|
||||
frame_end = instance.data['frameEnd']
|
||||
handle_start = instance.data['handleStart']
|
||||
handle_end = instance.data['handleEnd']
|
||||
step = instance.data['step']
|
||||
fps = instance.data['fps']
|
||||
if frame_end != frame_start:
|
||||
time_opts = multiverse.TimeOptions()
|
||||
|
||||
time_opts.writeTimeRange = True
|
||||
|
||||
time_range_start = options["timeRangeStart"]
|
||||
time_range_end = options["timeRangeEnd"]
|
||||
time_opts.frameRange = (time_range_start, time_range_end)
|
||||
|
||||
time_opts.frameIncrement = options["timeRangeIncrement"]
|
||||
time_opts.numTimeSamples = options["timeRangeNumTimeSamples"]
|
||||
time_opts.timeSamplesSpan = options["timeRangeSamplesSpan"]
|
||||
time_opts.framePerSecond = options["timeRangeFramesPerSecond"]
|
||||
time_opts.frameRange = (
|
||||
frame_start - handle_start, frame_end + handle_end)
|
||||
time_opts.frameIncrement = step
|
||||
time_opts.numTimeSamples = instance.data["numTimeSamples"]
|
||||
time_opts.timeSamplesSpan = instance.data["timeSamplesSpan"]
|
||||
time_opts.framePerSecond = fps
|
||||
|
||||
comp_write_opts = multiverse.CompositionWriteOptions()
|
||||
options_items = getattr(options, "iteritems", options.items)
|
||||
for (k, v) in options_items():
|
||||
if k == "writeTimeRange" or k.startswith("timeRange"):
|
||||
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(comp_write_opts, k, v)
|
||||
comp_write_opts.timeOptions = time_opts
|
||||
setattr(asset_write_opts, key, value)
|
||||
|
||||
multiverse.WriteComposition(file_path, members, comp_write_opts)
|
||||
|
||||
if "representations" not in instance.data:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue