mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Reduce code duplication - merge animation + pointcache extractor logic
This commit is contained in:
parent
a99cc8f497
commit
6d894e8ef0
2 changed files with 30 additions and 119 deletions
|
|
@ -1,111 +0,0 @@
|
||||||
import os
|
|
||||||
|
|
||||||
from maya import cmds
|
|
||||||
|
|
||||||
import openpype.api
|
|
||||||
from openpype.hosts.maya.api.lib import (
|
|
||||||
extract_alembic,
|
|
||||||
suspended_refresh,
|
|
||||||
maintained_selection,
|
|
||||||
iter_visible_in_frame_range
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ExtractAnimation(openpype.api.Extractor):
|
|
||||||
"""Produce an alembic of just point positions and normals.
|
|
||||||
|
|
||||||
Positions and normals, uvs, creases are preserved, but nothing more,
|
|
||||||
for plain and predictable point caches.
|
|
||||||
|
|
||||||
Plugin can run locally or remotely (on a farm - if instance is marked with
|
|
||||||
"farm" it will be skipped in local processing, but processed on farm)
|
|
||||||
"""
|
|
||||||
|
|
||||||
label = "Extract Animation"
|
|
||||||
hosts = ["maya"]
|
|
||||||
families = ["animation"]
|
|
||||||
targets = ["local", "remote"]
|
|
||||||
|
|
||||||
def process(self, instance):
|
|
||||||
if instance.data.get("farm"):
|
|
||||||
self.log.debug("Should be processed on farm, skipping.")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Collect the out set nodes
|
|
||||||
out_sets = [node for node in instance if node.endswith("out_SET")]
|
|
||||||
if len(out_sets) != 1:
|
|
||||||
raise RuntimeError("Couldn't find exactly one out_SET: "
|
|
||||||
"{0}".format(out_sets))
|
|
||||||
out_set = out_sets[0]
|
|
||||||
roots = cmds.sets(out_set, query=True)
|
|
||||||
|
|
||||||
# Include all descendants
|
|
||||||
nodes = roots + cmds.listRelatives(roots,
|
|
||||||
allDescendents=True,
|
|
||||||
fullPath=True) or []
|
|
||||||
|
|
||||||
# Collect the start and end including handles
|
|
||||||
start = instance.data["frameStartHandle"]
|
|
||||||
end = instance.data["frameEndHandle"]
|
|
||||||
|
|
||||||
self.log.info("Extracting animation..")
|
|
||||||
dirname = self.staging_dir(instance)
|
|
||||||
|
|
||||||
parent_dir = self.staging_dir(instance)
|
|
||||||
filename = "{name}.abc".format(**instance.data)
|
|
||||||
path = os.path.join(parent_dir, filename)
|
|
||||||
|
|
||||||
options = {
|
|
||||||
"step": instance.data.get("step", 1.0) or 1.0,
|
|
||||||
"attr": ["cbId"],
|
|
||||||
"writeVisibility": True,
|
|
||||||
"writeCreases": True,
|
|
||||||
"uvWrite": True,
|
|
||||||
"selection": True,
|
|
||||||
"worldSpace": instance.data.get("worldSpace", True),
|
|
||||||
"writeColorSets": instance.data.get("writeColorSets", False),
|
|
||||||
"writeFaceSets": instance.data.get("writeFaceSets", False)
|
|
||||||
}
|
|
||||||
|
|
||||||
if not instance.data.get("includeParentHierarchy", True):
|
|
||||||
# Set the root nodes if we don't want to include parents
|
|
||||||
# The roots are to be considered the ones that are the actual
|
|
||||||
# direct members of the set
|
|
||||||
options["root"] = roots
|
|
||||||
|
|
||||||
if int(cmds.about(version=True)) >= 2017:
|
|
||||||
# Since Maya 2017 alembic supports multiple uv sets - write them.
|
|
||||||
options["writeUVSets"] = True
|
|
||||||
|
|
||||||
if instance.data.get("visibleOnly", False):
|
|
||||||
# If we only want to include nodes that are visible in the frame
|
|
||||||
# range then we need to do our own check. Alembic's `visibleOnly`
|
|
||||||
# flag does not filter out those that are only hidden on some
|
|
||||||
# frames as it counts "animated" or "connected" visibilities as
|
|
||||||
# if it's always visible.
|
|
||||||
nodes = list(iter_visible_in_frame_range(nodes,
|
|
||||||
start=start,
|
|
||||||
end=end))
|
|
||||||
|
|
||||||
with suspended_refresh():
|
|
||||||
with maintained_selection():
|
|
||||||
cmds.select(nodes, noExpand=True)
|
|
||||||
extract_alembic(file=path,
|
|
||||||
startFrame=float(start),
|
|
||||||
endFrame=float(end),
|
|
||||||
**options)
|
|
||||||
|
|
||||||
if "representations" not in instance.data:
|
|
||||||
instance.data["representations"] = []
|
|
||||||
|
|
||||||
representation = {
|
|
||||||
'name': 'abc',
|
|
||||||
'ext': 'abc',
|
|
||||||
'files': filename,
|
|
||||||
"stagingDir": dirname,
|
|
||||||
}
|
|
||||||
instance.data["representations"].append(representation)
|
|
||||||
|
|
||||||
instance.context.data["cleanupFullPaths"].append(path)
|
|
||||||
|
|
||||||
self.log.info("Extracted {} to {}".format(instance, dirname))
|
|
||||||
|
|
@ -33,7 +33,7 @@ class ExtractAlembic(openpype.api.Extractor):
|
||||||
self.log.debug("Should be processed on farm, skipping.")
|
self.log.debug("Should be processed on farm, skipping.")
|
||||||
return
|
return
|
||||||
|
|
||||||
nodes = instance[:]
|
nodes, roots = self.get_members_and_roots(instance)
|
||||||
|
|
||||||
# Collect the start and end including handles
|
# Collect the start and end including handles
|
||||||
start = float(instance.data.get("frameStartHandle", 1))
|
start = float(instance.data.get("frameStartHandle", 1))
|
||||||
|
|
@ -46,10 +46,6 @@ class ExtractAlembic(openpype.api.Extractor):
|
||||||
attr_prefixes = instance.data.get("attrPrefix", "").split(";")
|
attr_prefixes = instance.data.get("attrPrefix", "").split(";")
|
||||||
attr_prefixes = [value for value in attr_prefixes if value.strip()]
|
attr_prefixes = [value for value in attr_prefixes if value.strip()]
|
||||||
|
|
||||||
# Get extra export arguments
|
|
||||||
writeColorSets = instance.data.get("writeColorSets", False)
|
|
||||||
writeFaceSets = instance.data.get("writeFaceSets", False)
|
|
||||||
|
|
||||||
self.log.info("Extracting pointcache..")
|
self.log.info("Extracting pointcache..")
|
||||||
dirname = self.staging_dir(instance)
|
dirname = self.staging_dir(instance)
|
||||||
|
|
||||||
|
|
@ -63,8 +59,8 @@ class ExtractAlembic(openpype.api.Extractor):
|
||||||
"attrPrefix": attr_prefixes,
|
"attrPrefix": attr_prefixes,
|
||||||
"writeVisibility": True,
|
"writeVisibility": True,
|
||||||
"writeCreases": True,
|
"writeCreases": True,
|
||||||
"writeColorSets": writeColorSets,
|
"writeColorSets": instance.data.get("writeColorSets", False),
|
||||||
"writeFaceSets": writeFaceSets,
|
"writeFaceSets": instance.data.get("writeFaceSets", False),
|
||||||
"uvWrite": True,
|
"uvWrite": True,
|
||||||
"selection": True,
|
"selection": True,
|
||||||
"worldSpace": instance.data.get("worldSpace", True)
|
"worldSpace": instance.data.get("worldSpace", True)
|
||||||
|
|
@ -74,7 +70,7 @@ class ExtractAlembic(openpype.api.Extractor):
|
||||||
# Set the root nodes if we don't want to include parents
|
# Set the root nodes if we don't want to include parents
|
||||||
# The roots are to be considered the ones that are the actual
|
# The roots are to be considered the ones that are the actual
|
||||||
# direct members of the set
|
# direct members of the set
|
||||||
options["root"] = instance.data.get("setMembers")
|
options["root"] = roots
|
||||||
|
|
||||||
if int(cmds.about(version=True)) >= 2017:
|
if int(cmds.about(version=True)) >= 2017:
|
||||||
# Since Maya 2017 alembic supports multiple uv sets - write them.
|
# Since Maya 2017 alembic supports multiple uv sets - write them.
|
||||||
|
|
@ -112,3 +108,29 @@ class ExtractAlembic(openpype.api.Extractor):
|
||||||
instance.context.data["cleanupFullPaths"].append(path)
|
instance.context.data["cleanupFullPaths"].append(path)
|
||||||
|
|
||||||
self.log.info("Extracted {} to {}".format(instance, dirname))
|
self.log.info("Extracted {} to {}".format(instance, dirname))
|
||||||
|
|
||||||
|
def get_members_and_roots(self, instance):
|
||||||
|
return instance[:], instance.data.get("setMembers")
|
||||||
|
|
||||||
|
|
||||||
|
class ExtractAnimation(ExtractAlembic):
|
||||||
|
label = "Extract Animation"
|
||||||
|
families = ["animation"]
|
||||||
|
|
||||||
|
def get_members_and_roots(self, instance):
|
||||||
|
|
||||||
|
# Collect the out set nodes
|
||||||
|
out_sets = [node for node in instance if node.endswith("out_SET")]
|
||||||
|
if len(out_sets) != 1:
|
||||||
|
raise RuntimeError("Couldn't find exactly one out_SET: "
|
||||||
|
"{0}".format(out_sets))
|
||||||
|
out_set = out_sets[0]
|
||||||
|
roots = cmds.sets(out_set, query=True)
|
||||||
|
|
||||||
|
# Include all descendants
|
||||||
|
nodes = roots + cmds.listRelatives(roots,
|
||||||
|
allDescendents=True,
|
||||||
|
fullPath=True) or []
|
||||||
|
|
||||||
|
return nodes, roots
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue