mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-27 14:22:37 +01:00
Initial working publish of xgen
This commit is contained in:
parent
94f0f773f8
commit
bf2d4ee323
5 changed files with 185 additions and 9 deletions
39
openpype/hosts/maya/plugins/publish/collect_xgen.py
Normal file
39
openpype/hosts/maya/plugins/publish/collect_xgen.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
from maya import cmds
|
||||
|
||||
import pyblish.api
|
||||
from openpype.hosts.maya.api.lib import get_attribute_input
|
||||
|
||||
|
||||
class CollectXgen(pyblish.api.InstancePlugin):
|
||||
"""Collect Xgen"""
|
||||
|
||||
order = pyblish.api.CollectorOrder + 0.499999
|
||||
label = "Collect Xgen"
|
||||
families = ["xgen"]
|
||||
|
||||
def process(self, instance):
|
||||
data = {
|
||||
"xgenPalettes": cmds.ls(instance, type="xgmPalette", long=True),
|
||||
"xgmDescriptions": cmds.ls(
|
||||
instance, type="xgmDescription", long=True
|
||||
),
|
||||
"xgmSubdPatches": cmds.ls(instance, type="xgmSubdPatch", long=True)
|
||||
}
|
||||
data["xgenNodes"] = (
|
||||
data["xgenPalettes"] +
|
||||
data["xgmDescriptions"] +
|
||||
data["xgmSubdPatches"]
|
||||
)
|
||||
|
||||
if data["xgenPalettes"]:
|
||||
data["xgenPalette"] = data["xgenPalettes"][0]
|
||||
|
||||
data["xgenConnections"] = {}
|
||||
for node in data["xgmSubdPatches"]:
|
||||
data["xgenConnections"][node] = {}
|
||||
for attr in ["transform", "geometry"]:
|
||||
input = get_attribute_input("{}.{}".format(node, attr))
|
||||
data["xgenConnections"][node][attr] = input
|
||||
|
||||
self.log.info(data)
|
||||
instance.data.update(data)
|
||||
|
|
@ -20,8 +20,7 @@ class ExtractMayaSceneRaw(publish.Extractor):
|
|||
"mayaScene",
|
||||
"setdress",
|
||||
"layout",
|
||||
"camerarig",
|
||||
"xgen"]
|
||||
"camerarig"]
|
||||
scene_type = "ma"
|
||||
|
||||
def process(self, instance):
|
||||
|
|
|
|||
138
openpype/hosts/maya/plugins/publish/extract_xgen.py
Normal file
138
openpype/hosts/maya/plugins/publish/extract_xgen.py
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
import os
|
||||
import copy
|
||||
|
||||
from maya import cmds
|
||||
import pymel.core as pc
|
||||
import xgenm
|
||||
|
||||
from openpype.pipeline import publish
|
||||
from openpype.hosts.maya.api.lib import maintained_selection, attribute_values
|
||||
from openpype.lib import StringTemplate
|
||||
|
||||
|
||||
class ExtractXgenCache(publish.Extractor):
|
||||
"""Extract Xgen"""
|
||||
|
||||
label = "Extract Xgen"
|
||||
hosts = ["maya"]
|
||||
families = ["xgen"]
|
||||
scene_type = "ma"
|
||||
|
||||
def process(self, instance):
|
||||
if "representations" not in instance.data:
|
||||
instance.data["representations"] = []
|
||||
|
||||
staging_dir = self.staging_dir(instance)
|
||||
maya_filename = "{}.{}".format(instance.data["name"], self.scene_type)
|
||||
maya_filepath = os.path.join(staging_dir, maya_filename)
|
||||
|
||||
# Get published xgen file name.
|
||||
template_data = copy.deepcopy(instance.data["anatomyData"])
|
||||
template_data.update({"ext": "xgen"})
|
||||
templates = instance.context.data["anatomy"].templates["publish"]
|
||||
xgen_filename = StringTemplate(templates["file"]).format(template_data)
|
||||
name = instance.data["xgenPalette"].replace(":", "__").replace("|", "")
|
||||
value = xgen_filename.replace(".xgen", "__" + name + ".xgen")
|
||||
attribute_data = {
|
||||
"{}.xgFileName".format(instance.data["xgenPalette"]): xgen_filename
|
||||
}
|
||||
|
||||
# Export xgen palette files.
|
||||
xgen_path = os.path.join(staging_dir, value).replace("\\", "/")
|
||||
xgenm.exportPalette(
|
||||
instance.data["xgenPalette"].replace("|", ""), xgen_path
|
||||
)
|
||||
self.log.info("Extracted to {}".format(xgen_path))
|
||||
|
||||
representation = {
|
||||
"name": name,
|
||||
"ext": "xgen",
|
||||
"files": value,
|
||||
"stagingDir": staging_dir,
|
||||
}
|
||||
instance.data["representations"].append(representation)
|
||||
|
||||
# Collect nodes to export.
|
||||
duplicate_nodes = []
|
||||
for node, connections in instance.data["xgenConnections"].items():
|
||||
transform_name = connections["transform"].split(".")[0]
|
||||
|
||||
# Duplicate_transform subd patch geometry.
|
||||
duplicate_transform = pc.duplicate(transform_name)[0]
|
||||
pc.parent(duplicate_transform, world=True)
|
||||
duplicate_transform.name(stripNamespace=True)
|
||||
duplicate_shape = pc.listRelatives(
|
||||
duplicate_transform, shapes=True
|
||||
)[0]
|
||||
|
||||
pc.connectAttr(
|
||||
"{}.matrix".format(duplicate_transform),
|
||||
"{}.transform".format(node),
|
||||
force=True
|
||||
)
|
||||
pc.connectAttr(
|
||||
"{}.worldMesh".format(duplicate_shape),
|
||||
"{}.geometry".format(node),
|
||||
force=True
|
||||
)
|
||||
|
||||
duplicate_nodes.append(duplicate_transform)
|
||||
|
||||
# Import xgen onto the duplicate.
|
||||
with maintained_selection():
|
||||
cmds.select(duplicate_nodes)
|
||||
collection = xgenm.importPalette(xgen_path, [])
|
||||
|
||||
# Export Maya file.
|
||||
type = "mayaAscii" if self.scene_type == "ma" else "mayaBinary"
|
||||
with attribute_values(attribute_data):
|
||||
with maintained_selection():
|
||||
cmds.select(duplicate_nodes + [collection])
|
||||
cmds.file(
|
||||
maya_filepath,
|
||||
force=True,
|
||||
type=type,
|
||||
exportSelected=True,
|
||||
preserveReferences=True,
|
||||
constructionHistory=True,
|
||||
shader=True,
|
||||
constraints=True,
|
||||
expressions=True
|
||||
)
|
||||
|
||||
self.log.info("Extracted to {}".format(maya_filepath))
|
||||
|
||||
representation = {
|
||||
"name": self.scene_type,
|
||||
"ext": self.scene_type,
|
||||
"files": maya_filename,
|
||||
"stagingDir": staging_dir,
|
||||
"data": {"xgenName": collection}
|
||||
}
|
||||
instance.data["representations"].append(representation)
|
||||
|
||||
# Revert to original xgen connections.
|
||||
for node, connections in instance.data["xgenConnections"].items():
|
||||
for attr, src in connections.items():
|
||||
cmds.connectAttr(
|
||||
src, "{}.{}".format(node, attr), force=True
|
||||
)
|
||||
|
||||
cmds.delete(duplicate_nodes + [collection])
|
||||
|
||||
# Setup transfers.
|
||||
#needs to reduce resources to only what is used for the collections in
|
||||
#the objectset
|
||||
xgen_dir = os.path.join(
|
||||
os.path.dirname(instance.context.data["currentFile"]), "xgen"
|
||||
)
|
||||
transfers = []
|
||||
for root, dirs, files in os.walk(xgen_dir):
|
||||
for file in files:
|
||||
source = os.path.join(root, file)
|
||||
destination = source.replace(
|
||||
xgen_dir, instance.data["resourcesDir"]
|
||||
)
|
||||
transfers.append((source, destination))
|
||||
|
||||
instance.data["transfers"] = transfers
|
||||
|
|
@ -4,19 +4,18 @@ import pyblish.api
|
|||
|
||||
|
||||
class ValidateXgen(pyblish.api.InstancePlugin):
|
||||
"""Ensure Xgen objectset only contains collections."""
|
||||
"""Validate Xgen data."""
|
||||
|
||||
label = "Xgen"
|
||||
label = "Validate Xgen"
|
||||
order = pyblish.api.ValidatorOrder
|
||||
host = ["maya"]
|
||||
families = ["xgen"]
|
||||
|
||||
def process(self, instance):
|
||||
# Validate only xgen collections are in objectset.
|
||||
nodes = (
|
||||
cmds.ls(instance, type="xgmPalette", long=True) +
|
||||
cmds.ls(instance, type="transform", long=True) +
|
||||
cmds.ls(instance, type="xgmDescription", long=True) +
|
||||
cmds.ls(instance, type="xgmSubdPatch", long=True)
|
||||
instance.data["xgenNodes"] +
|
||||
cmds.ls(instance, type="transform", long=True)
|
||||
)
|
||||
remainder_nodes = []
|
||||
for node in instance:
|
||||
|
|
|
|||
|
|
@ -57,7 +57,8 @@ class CollectResourcesPath(pyblish.api.InstancePlugin):
|
|||
"background",
|
||||
"effect",
|
||||
"staticMesh",
|
||||
"skeletalMesh"
|
||||
"skeletalMesh",
|
||||
"xgen"
|
||||
]
|
||||
|
||||
def process(self, instance):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue