make sure the contextlib.nested used before material loading while it is compatible for both python2 and 3

This commit is contained in:
Kayla Man 2023-12-15 23:09:11 +08:00
parent 28a62bff59
commit 4648895291
3 changed files with 39 additions and 29 deletions

View file

@ -43,17 +43,13 @@ class ExtractPlayblast(publish.Extractor):
json.dumps(preset, indent=4, sort_keys=True)
)
)
if "textures" in preset["viewport_options"] and (
"reloadTextures" in preset["viewport_options"]
):
with lib.material_loading_mode():
lib.reload_textures()
# not supported by `capture`
preset["viewport_options"].pop("reloadTextures", None)
path = capture.capture(log=self.log, **preset)
else:
preset["viewport_options"].pop("reloadTextures", None)
path = capture.capture(log=self.log, **preset)
if preset["viewport_options"].get("reloadTextures"):
# Regenerate all UDIM tiles previews
lib.reload_all_udim_tile_previews()
# not supported by `capture`
preset["viewport_options"].pop("reloadTextures", None)
path = capture.capture(log=self.log, **preset)
self.log.debug("playblast path {}".format(path))
def process(self, instance):
@ -206,11 +202,23 @@ class ExtractPlayblast(publish.Extractor):
# TODO: Remove once dropping Python 2.
if getattr(contextlib, "nested", None):
# Python 3 compatibility.
with contextlib.nested(
lib.maintained_time(),
panel_camera(instance.data["panel"], preset["camera"])
):
self._capture(preset)
if preset["viewport_options"].get("textures"):
# If capture includes textures then ensure material
# load mode is set to `immediate` to ensure all
# textures have loaded when playblast starts
with contextlib.nested(
lib.maintained_time(),
panel_camera(instance.data["panel"], preset["camera"]),
lib.material_loading_mode()
):
self._capture(preset)
else:
with contextlib.nested(
lib.maintained_time(),
panel_camera(instance.data["panel"], preset["camera"])
):
self._capture(preset)
else:
# Python 2 compatibility.
with contextlib.ExitStack() as stack:
@ -218,6 +226,8 @@ class ExtractPlayblast(publish.Extractor):
stack.enter_context(
panel_camera(instance.data["panel"], preset["camera"])
)
if preset["viewport_options"].get("textures"):
stack.enter_context(lib.material_loading_mode())
self._capture(preset)

View file

@ -152,19 +152,18 @@ class ExtractThumbnail(publish.Extractor):
json.dumps(preset, indent=4, sort_keys=True)
)
)
if "reloadTextures" in preset["viewport_options"]:
lib.reload_all_udim_tile_previews()
preset["viewport_options"].pop("reloadTextures", None)
if "textures" in preset["viewport_options"]:
if "reloadTextures" in preset["viewport_options"]:
with lib.material_loading_mode():
lib.reload_textures()
preset["viewport_options"].pop("reloadTextures", None)
path = capture.capture(**preset)
else:
self.log.debug(
"Reload Textures during playblasting is disabled.")
preset["viewport_options"].pop("reloadTextures", None)
with lib.material_loading_mode():
path = capture.capture(**preset)
# not supported by `capture`
path = capture.capture(**preset)
else:
self.log.debug("Reload Textures during playblasting is disabled.")
path = capture.capture(**preset)
playblast = self._fix_playblast_output_path(path)
_, thumbnail = os.path.split(playblast)