finished up the extractor

This commit is contained in:
Kayla Man 2023-09-15 22:26:08 +08:00
parent d6dc61c031
commit 28a3cf943d
2 changed files with 104 additions and 4 deletions

View file

@ -0,0 +1,70 @@
import pyblish.api
from openpype.lib import EnumDef
from openpype.pipeline.publish import OpenPypePyblishPluginMixin
class CollectTyCacheData(pyblish.api.InstancePlugin,
OpenPypePyblishPluginMixin):
"""Collect Review Data for Preview Animation"""
order = pyblish.api.CollectorOrder + 0.02
label = "Collect tyCache attribute Data"
hosts = ['max']
families = ["tycache"]
def process(self, instance):
all_tyc_attributes_dict = {}
attr_values = self.get_attr_values_from_data(instance.data)
tycache_boolean_attributes = attr_values.get("all_tyc_attrs")
if tycache_boolean_attributes:
for attrs in tycache_boolean_attributes:
all_tyc_attributes_dict[attrs] = True
self.log.debug(f"Found tycache attributes: {tycache_boolean_attributes}")
@classmethod
def get_attribute_defs(cls):
tyc_attr_enum = ["tycacheChanAge", "tycacheChanGroups", "tycacheChanPos",
"tycacheChanRot", "tycacheChanScale", "tycacheChanVel",
"tycacheChanSpin", "tycacheChanShape", "tycacheChanMatID",
"tycacheChanMapping", "tycacheChanMaterials",
"tycacheChanCustomFloat"
]
return [
EnumDef("all_tyc_attrs",
tyc_attr_enum,
default=None,
multiselection=True
)
]
"""
.tycacheChanCustomFloat : boolean
.tycacheChanCustomVector : boolean
.tycacheChanCustomTM : boolean
.tycacheChanPhysX : boolean
.tycacheMeshBackup : boolean
.tycacheCreateObject : boolean
.tycacheCreateObjectIfNotCreated : boolean
.tycacheLayer : string
.tycacheObjectName : string
.tycacheAdditionalCloth : boolean
.tycacheAdditionalSkin : boolean
.tycacheAdditionalSkinID : boolean
.tycacheAdditionalSkinIDValue : integer
.tycacheAdditionalTerrain : boolean
.tycacheAdditionalVDB : boolean
.tycacheAdditionalSplinePaths : boolean
.tycacheAdditionalTyMesher : boolean
.tycacheAdditionalGeo : boolean
.tycacheAdditionalObjectList_deprecated : node array
.tycacheAdditionalObjectList : maxObject array
.tycacheAdditionalGeoActivateModifiers : boolean
.tycacheSplines: boolean
.tycacheSplinesAdditionalSplines : boolean
.tycacheSplinesAdditionalSplinesObjectList_deprecated : node array
.tycacheSplinesAdditionalObjectList : maxObject array
"""

View file

@ -38,16 +38,20 @@ class ExtractTyCache(publish.Extractor):
filename = "{name}.tyc".format(**instance.data)
path = os.path.join(stagingdir, filename)
filenames = self.get_file(path, start, end)
additional_attributes = instance.data.get("tyc_attrs", {})
with maintained_selection():
job_args = None
if instance.data["tycache_type"] == "tycache":
job_args = self.export_particle(
instance.data["members"],
start, end, path)
start, end, path,
additional_attributes)
elif instance.data["tycache_type"] == "tycachespline":
job_args = self.export_particle(
instance.data["members"],
start, end, path,
additional_attributes,
tycache_spline_enabled=True)
for job in job_args:
@ -74,7 +78,8 @@ class ExtractTyCache(publish.Extractor):
return filenames
def export_particle(self, members, start, end,
filepath, tycache_spline_enabled=False):
filepath, additional_attributes,
tycache_spline_enabled=False):
"""Sets up all job arguments for attributes.
Those attributes are to be exported in MAX Script.
@ -94,8 +99,7 @@ class ExtractTyCache(publish.Extractor):
for operator in opt_list:
if tycache_spline_enabled:
export_mode = f'{operator}.exportMode=3'
has_tyc_spline = f'{operator}.tycacheSplines=true'
job_args.extend([export_mode, has_tyc_spline])
job_args.append(export_mode)
else:
export_mode = f'{operator}.exportMode=2'
job_args.append(export_mode)
@ -107,6 +111,11 @@ class ExtractTyCache(publish.Extractor):
tycache_filename = f'{operator}.tyCacheFilename="{filepath}"'
job_args.append(tycache_filename)
# TODO: add the additional job args for tycache attributes
if additional_attributes:
additional_args = self.get_additional_attribute_args(
operator, additional_attributes
)
job_args.extend(additional_args)
tycache_export = f"{operator}.exportTyCache()"
job_args.append(tycache_export)
@ -137,3 +146,24 @@ class ExtractTyCache(publish.Extractor):
opt_list.append(opt)
return opt_list
def get_additional_attribute_args(self, operator, attrs):
"""Get Additional args with the attributes pre-set by user
Args:
operator (str): export particle operator
attrs (dict): a dict which stores the additional attributes
added by user
Returns:
additional_args(list): a list of additional args for MAX script
"""
additional_args = []
for key, value in attrs.items():
tyc_attribute = None
if isinstance(value, bool):
tyc_attribute = f"{operator}.{key}=True"
elif isinstance(value, str):
tyc_attribute = f"{operator}.{key}={value}"
additional_args.append(tyc_attribute)
return additional_args