From eb61b4b2f05b482d7e98aa095b0f861cbe70be6b Mon Sep 17 00:00:00 2001 From: aardschok Date: Tue, 25 Jul 2017 13:42:30 +0200 Subject: [PATCH] improved extract to match integrator --- .../plugins/maya/publish/extract_alembic.py | 20 ++++++-- .../plugins/maya/publish/extract_look.py | 47 ++++++++----------- .../plugins/maya/publish/extract_textures.py | 41 ++++++++++++++++ 3 files changed, 76 insertions(+), 32 deletions(-) diff --git a/colorbleed/plugins/maya/publish/extract_alembic.py b/colorbleed/plugins/maya/publish/extract_alembic.py index c3abe59244..b15380e1d5 100644 --- a/colorbleed/plugins/maya/publish/extract_alembic.py +++ b/colorbleed/plugins/maya/publish/extract_alembic.py @@ -16,9 +16,7 @@ class ExtractAlembic(colorbleed.api.Extractor): """ label = "Alembic" - families = ["colorbleed.model", - "colorbleed.pointcache", - "colorbleed.proxy"] + families = ["colorbleed.model", "colorbleed.pointcache"] optional = True def process(self, instance): @@ -27,13 +25,27 @@ class ExtractAlembic(colorbleed.api.Extractor): filename = "%s.abc" % instance.name path = os.path.join(parent_dir, filename) + attrPrefix = instance.data.get("attrPrefix", []) + attrPrefix.append("cb") + options = copy.deepcopy(instance.data) + options['attrPrefix'] = attrPrefix + + # Ensure visibility keys are written + options['writeVisibility'] = True + + # Write creases + options['writeCreases'] = True + + # Ensure UVs are written + options['uvWrite'] = True + options['selection'] = True options["attr"] = ["cbId"] # force elect items to ensure all items get exported by Alembic members = instance.data("setMembers") - print members + print "Members : {}".format(members) cmds.select(members) with avalon.maya.suspended_refresh(): diff --git a/colorbleed/plugins/maya/publish/extract_look.py b/colorbleed/plugins/maya/publish/extract_look.py index 97c572565a..04c632e2d9 100644 --- a/colorbleed/plugins/maya/publish/extract_look.py +++ b/colorbleed/plugins/maya/publish/extract_look.py @@ -3,10 +3,11 @@ import json from maya import cmds +import pyblish.api import avalon.maya import colorbleed.api -import cb.utils.maya.context as context +from cb.utils.maya import context class ExtractLook(colorbleed.api.Extractor): @@ -18,9 +19,10 @@ class ExtractLook(colorbleed.api.Extractor): """ - label = "Look (Maya ASCII + JSON)" + label = "Extract Look (Maya ASCII + JSON)" hosts = ["maya"] - families = ["colorbleed.look"] + families = ["colorbleed.lookdev"] + order = pyblish.api.ExtractorOrder + 0.2 def process(self, instance): @@ -29,6 +31,7 @@ class ExtractLook(colorbleed.api.Extractor): maya_fname = "{0}.ma".format(instance.name) json_fname = "{0}.json".format(instance.name) + # Make texture dump folder maya_path = os.path.join(dir_path, maya_fname) json_path = os.path.join(dir_path, json_fname) @@ -40,40 +43,28 @@ class ExtractLook(colorbleed.api.Extractor): lookdata = instance.data["lookData"] sets = lookdata["sets"] - # Define the texture file node remapping - resource_remap = dict() - # required tags to be a look resource - required_tags = ["maya", "attribute", "look"] - resources = instance.data.get("resources", []) - for resource in resources: - resource_tags = resource.get("tags", []) - if all(tag in resource_tags for tag in required_tags): - node = resource['node'] - destination = resource['destination'] - resource_remap["{}.fileTextureName".format(node)] = destination - - # Extract in corect render layer + # Extract in correct render layer layer = instance.data.get("renderlayer", "defaultRenderLayer") with context.renderlayer(layer): # TODO: Ensure membership edits don't become renderlayer overrides with context.empty_sets(sets): - with context.attribute_values(resource_remap): - with avalon.maya.maintained_selection(): - cmds.select(sets, noExpand=True) - cmds.file(maya_path, - force=True, - typ="mayaAscii", - exportSelected=True, - preserveReferences=False, - channels=True, - constraints=True, - expressions=True, - constructionHistory=True) + with avalon.maya.maintained_selection(): + cmds.select(sets, noExpand=True) + cmds.file(maya_path, + force=True, + typ="mayaAscii", + exportSelected=True, + preserveReferences=False, + channels=True, + constraints=True, + expressions=True, + constructionHistory=True) # Write the JSON data self.log.info("Extract json..") data = {"attributes": lookdata["attributes"], "sets": lookdata["relationships"]} + with open(json_path, "w") as f: json.dump(data, f) diff --git a/colorbleed/plugins/maya/publish/extract_textures.py b/colorbleed/plugins/maya/publish/extract_textures.py index e69de29bb2..86380d4295 100644 --- a/colorbleed/plugins/maya/publish/extract_textures.py +++ b/colorbleed/plugins/maya/publish/extract_textures.py @@ -0,0 +1,41 @@ +import json +import os +import shutil + +import pyblish.api +import colorbleed.api +import colorbleed.maya.lib as lib + + +class ExtractTextures(colorbleed.api.Extractor): + + label = "Extract Textures" + hosts = ["maya"] + families = ["colorbleed.texture"] + order = pyblish.api.ExtractorOrder + 0.1 + + def process(self, instance): + + self.log.info("Extracting textures ...") + + dir_path = self.staging_dir(instance) + resources = instance.data["resources"] + for resource in resources: + self.copy_files(dir_path, resource["files"]) + + self.log.info("Storing cross instance information ...") + self.store_data(resources) + + def store_data(self, data): + tmp_dir = lib.maya_temp_folder() + tmp_file = os.path.join(tmp_dir, "resources.json") + with open(tmp_file, "w") as f: + json.dump(data, fp=f, + separators=[",", ":"], + ensure_ascii=False) + + def copy_files(self, dest, files): + for f in files: + fname = os.path.basename(f) + dest_file = os.path.join(dest, fname) + shutil.copy(f, dest_file)