mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge pull request #5426 from BigRoy/feature/maya_extract_active_view_as_thumbnail
This commit is contained in:
commit
bef6445862
1 changed files with 60 additions and 0 deletions
|
|
@ -0,0 +1,60 @@
|
|||
import maya.api.OpenMaya as om
|
||||
import maya.api.OpenMayaUI as omui
|
||||
|
||||
import pyblish.api
|
||||
import tempfile
|
||||
|
||||
from openpype.hosts.maya.api.lib import IS_HEADLESS
|
||||
|
||||
|
||||
class ExtractActiveViewThumbnail(pyblish.api.InstancePlugin):
|
||||
"""Set instance thumbnail to a screengrab of current active viewport.
|
||||
|
||||
This makes it so that if an instance does not have a thumbnail set yet that
|
||||
it will get a thumbnail of the currently active view at the time of
|
||||
publishing as a fallback.
|
||||
|
||||
"""
|
||||
order = pyblish.api.ExtractorOrder + 0.49
|
||||
label = "Active View Thumbnail"
|
||||
families = ["workfile"]
|
||||
hosts = ["maya"]
|
||||
|
||||
def process(self, instance):
|
||||
if IS_HEADLESS:
|
||||
self.log.debug(
|
||||
"Skip extraction of active view thumbnail, due to being in"
|
||||
"headless mode."
|
||||
)
|
||||
return
|
||||
|
||||
thumbnail = instance.data.get("thumbnailPath")
|
||||
if not thumbnail:
|
||||
view_thumbnail = self.get_view_thumbnail(instance)
|
||||
if not view_thumbnail:
|
||||
return
|
||||
|
||||
self.log.debug("Setting instance thumbnail path to: {}".format(
|
||||
view_thumbnail
|
||||
))
|
||||
instance.data["thumbnailPath"] = view_thumbnail
|
||||
|
||||
def get_view_thumbnail(self, instance):
|
||||
cache_key = "__maya_view_thumbnail"
|
||||
context = instance.context
|
||||
|
||||
if cache_key not in context.data:
|
||||
# Generate only a single thumbnail, even for multiple instances
|
||||
with tempfile.NamedTemporaryFile(suffix="_thumbnail.jpg",
|
||||
delete=False) as f:
|
||||
path = f.name
|
||||
|
||||
view = omui.M3dView.active3dView()
|
||||
image = om.MImage()
|
||||
view.readColorBuffer(image, True)
|
||||
image.writeToFile(path, "jpg")
|
||||
self.log.debug("Generated thumbnail: {}".format(path))
|
||||
|
||||
context.data["cleanupFullPaths"].append(path)
|
||||
context.data[cache_key] = path
|
||||
return context.data[cache_key]
|
||||
Loading…
Add table
Add a link
Reference in a new issue