fix parenting for skeletal meshes

This commit is contained in:
Ondřej Samohel 2022-03-15 00:41:46 +01:00
parent 87b256387d
commit d31bee0c3e
No known key found for this signature in database
GPG key ID: 02376E18990A97C6
4 changed files with 33 additions and 12 deletions

View file

@ -198,5 +198,5 @@ class FBXExtractor:
path (str): Path to use for export.
"""
cmds.select(members, r=1, noExpand=True)
cmds.select(members, r=True, noExpand=True)
mel.eval('FBXExport -f "{}" -s'.format(path))

View file

@ -3085,11 +3085,20 @@ def set_colorspace():
@contextlib.contextmanager
def root_parent(nodes):
# type: (list) -> list
def parent_nodes(nodes, parent=None):
# type: (list, str) -> list
"""Context manager to un-parent provided nodes and return them back."""
import pymel.core as pm # noqa
parent_node = None
delete_parent = False
if parent:
if not cmds.objExists(parent):
parent_node = pm.createNode("transform", n=parent, ss=False)
delete_parent = True
else:
parent_node = pm.PyNode(parent)
node_parents = []
for node in nodes:
n = pm.PyNode(node)
@ -3100,9 +3109,14 @@ def root_parent(nodes):
node_parents.append((n, root))
try:
for node in node_parents:
node[0].setParent(world=True)
if not parent:
node[0].setParent(world=True)
else:
node[0].setParent(parent_node)
yield
finally:
for node in node_parents:
if node[1]:
node[0].setParent(node[1])
if delete_parent:
pm.delete(parent_node)

View file

@ -7,9 +7,8 @@ from maya import cmds # noqa
import pyblish.api
import openpype.api
from openpype.hosts.maya.api.lib import (
root_parent,
maintained_selection,
delete_after
parent_nodes,
maintained_selection
)
from openpype.hosts.maya.api import fbx
@ -43,10 +42,18 @@ class ExtractUnrealSkeletalMesh(openpype.api.Extractor):
self.log.info("Instance: {0}".format(instance[:]))
fbx_exporter.set_options_from_instance(instance)
parent = "{}{}".format(
instance.data["asset"],
instance.data.get("variant", "")
)
with maintained_selection():
with root_parent(to_extract):
rooted = [i.split("|")[-1] for i in to_extract]
self.log.info("Un-parenting: {}".format(to_extract))
with parent_nodes(to_extract, parent=parent):
rooted = [
"{}|{}".format(parent, i.split("|")[-1])
for i in to_extract
]
self.log.info("Un-parenting: {}".format(rooted, path))
fbx_exporter.export(rooted, path)
if "representations" not in instance.data:

View file

@ -7,7 +7,7 @@ from maya import cmds # noqa
import pyblish.api
import openpype.api
from openpype.hosts.maya.api.lib import (
root_parent,
parent_nodes,
maintained_selection,
delete_after
)
@ -43,7 +43,7 @@ class ExtractUnrealStaticMesh(openpype.api.Extractor):
fbx_exporter.set_options_from_instance(instance)
with maintained_selection():
with root_parent(members):
with parent_nodes(members):
self.log.info("Un-parenting: {}".format(members))
fbx_exporter.export(members, path)