ayon-core/config/plugins/maya/publish/extract_model.py

78 lines
2.8 KiB
Python

import os
from maya import cmds
import avalon.maya
import config.api
from cb.utils.maya import context
class ExtractModel(config.api.Extractor):
"""Extract as Model (Maya Ascii)
Only extracts contents based on the original "setMembers" data to ensure
publishing the least amount of required shapes. From that it only takes
the shapes that are not intermediateObjects
During export it sets a temporary context to perform a clean extraction.
The context ensures:
- Smooth preview is turned off for the geometry
- Default shader is assigned (no materials are exported)
- Remove display layers
"""
label = "Model (Maya ASCII)"
hosts = ["maya"]
families = ["studio.model"]
def process(self, instance):
# Define extract output file path
stagingdir = self.staging_dir(instance)
filename = "{0}.ma".format(instance.name)
path = os.path.join(stagingdir, filename)
# Perform extraction
self.log.info("Performing extraction..")
# Get only the shape contents we need in such a way that we avoid
# taking along intermediateObjects
members = instance.data("setMembers")
members = cmds.ls(members,
dag=True,
shapes=True,
type=("mesh", "nurbsCurve"),
noIntermediate=True,
long=True)
with context.no_display_layers(instance):
with context.displaySmoothness(members,
divisionsU=0,
divisionsV=0,
pointsWire=4,
pointsShaded=1,
polygonObject=1):
with context.shader(members,
shadingEngine="initialShadingGroup"):
with avalon.maya.maintained_selection():
cmds.select(members, noExpand=True)
cmds.file(path,
force=True,
typ="mayaAscii",
exportSelected=True,
preserveReferences=False,
channels=False,
constraints=False,
expressions=False,
constructionHistory=False)
# Store reference for integration
if "files" not in instance.data:
instance.data["files"] = list()
instance.data["files"].append(filename)
self.log.info("Extracted instance '%s' to: %s" % (instance.name, path))