From da1c7f0756a0093dd43dc82c83ced9f5ddbaf57d Mon Sep 17 00:00:00 2001 From: aardschok Date: Mon, 16 Oct 2017 11:10:55 +0200 Subject: [PATCH 1/6] removed function and cosmetics --- .../plugins/maya/publish/collect_look.py | 57 +++++-------------- 1 file changed, 15 insertions(+), 42 deletions(-) diff --git a/colorbleed/plugins/maya/publish/collect_look.py b/colorbleed/plugins/maya/publish/collect_look.py index 02aa15c835..7962656124 100644 --- a/colorbleed/plugins/maya/publish/collect_look.py +++ b/colorbleed/plugins/maya/publish/collect_look.py @@ -73,9 +73,6 @@ class CollectLook(pyblish.api.InstancePlugin): def collect(self, instance): - # Whether to log information verbosely - verbose = instance.data.get("verbose", False) - self.log.info("Looking for look associations " "for %s" % instance.data['name']) @@ -89,20 +86,25 @@ class CollectLook(pyblish.api.InstancePlugin): self.log.info("Gathering set relations..") for objset in sets: self.log.debug("From %s.." % objset) - content = cmds.sets(objset, query=True) objset_members = sets[objset]["members"] - for member in cmds.ls(content, long=True): + + # Get all nodes of the current objectSet + for member in cmds.ls(cmds.sets(objset, query=True), long=True): member_data = self.collect_member_data(member, objset_members, - instance_lookup, - verbose) + instance_lookup) if not member_data: continue + # Add information of the node to the members list sets[objset]["members"].append(member_data) - # Remove sets that didn't have any members assigned in the end - sets = self.remove_sets_without_members(sets) + # Remove sets that didn't have any members assigned in the end + # Thus the data will be limited to only what we need. + if not sets[objset]["members"]: + self.log.info("Removing redundant set information: " + "%s" % objset) + sets.pop(objset) self.log.info("Gathering attribute changes to instance members..") @@ -118,6 +120,7 @@ class CollectLook(pyblish.api.InstancePlugin): # Collect file nodes used by shading engines (if we have any) files = list() if looksets: + # Get the entire node chain of the look sets history = cmds.listHistory(looksets) files = cmds.ls(history, type="file", long=True) @@ -158,32 +161,12 @@ class CollectLook(pyblish.api.InstancePlugin): return sets - def remove_sets_without_members(self, sets): - """Remove any set which does not have any members - - Args: - sets (dict): collection if sets with data as value - - Returns: - dict - """ - - for objset, data in sets.items(): - if not data['members']: - self.log.info("Removing redundant set information: " - "%s" % objset) - sets.pop(objset) - - return sets - - def collect_member_data(self, member, objset_members, instance_members, - verbose=False): + def collect_member_data(self, member, objset_members, instance_members): """Get all information of the node Args: member (str): the name of the node to check objset_members (list): the objectSet members instance_members (set): the collected instance members - verbose (bool): get debug information Returns: dict @@ -194,8 +177,7 @@ class CollectLook(pyblish.api.InstancePlugin): # Only include valid members of the instance if node not in instance_members: - if verbose: - self.log.info("Skipping member %s" % member) + # Skip nodes which are not in the instance members return if member in [m["name"] for m in objset_members]: @@ -205,13 +187,7 @@ class CollectLook(pyblish.api.InstancePlugin): self.log.error("Node '{}' has no attribute 'cbId'".format(node)) return - member_data = {"name": node, "uuid": lib.get_id(node)} - - # Include components information when components are assigned - if components: - member_data["components"] = components - - return member_data + return {"name": node, "uuid": lib.get_id(node)} def collect_attributes_changed(self, instance): """Collect all userDefined attributes which have changed @@ -233,9 +209,6 @@ class CollectLook(pyblish.api.InstancePlugin): attributes = [] for node in instance: - # get history to ignore original shapes - cmds.listHistory(node) - # Collect changes to "custom" attributes node_attrs = get_look_attrs(node) From cadb9f5aa5fd9a060cd8d5b738c440f24170aea1 Mon Sep 17 00:00:00 2001 From: aardschok Date: Mon, 16 Oct 2017 11:20:38 +0200 Subject: [PATCH 2/6] improved docstrings validator --- colorbleed/plugins/maya/publish/validate_look_sets.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/colorbleed/plugins/maya/publish/validate_look_sets.py b/colorbleed/plugins/maya/publish/validate_look_sets.py index e73c81fea4..0d16239215 100644 --- a/colorbleed/plugins/maya/publish/validate_look_sets.py +++ b/colorbleed/plugins/maya/publish/validate_look_sets.py @@ -19,6 +19,16 @@ class ValidateLookSets(pyblish.api.InstancePlugin): transform. In essence, ensure item the shader is assigned to has the Colorbleed ID! + Displacement shaders: + Ensure all geometry is added to the displacement objectSet. + It is best practice to add the transform group of the shape to the + displacement objectSet + Example content: + [asset_GRP|geometry_GRP|body_GES, + asset_GRP|geometry_GRP|L_eye_GES, + asset_GRP|geometry_GRP|R_eye_GES, + asset_GRP|geometry_GRP|wings_GEOShape] + """ order = colorbleed.api.ValidateContentsOrder From 5e05ae323a32f3ce6886e0d5ab46c843b7cc007a Mon Sep 17 00:00:00 2001 From: aardschok Date: Mon, 16 Oct 2017 12:59:37 +0200 Subject: [PATCH 3/6] refactored based on feedback --- .../plugins/maya/publish/collect_look.py | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/colorbleed/plugins/maya/publish/collect_look.py b/colorbleed/plugins/maya/publish/collect_look.py index 7962656124..173a26dc32 100644 --- a/colorbleed/plugins/maya/publish/collect_look.py +++ b/colorbleed/plugins/maya/publish/collect_look.py @@ -78,13 +78,15 @@ class CollectLook(pyblish.api.InstancePlugin): # Discover related object sets self.log.info("Gathering sets..") - sets = self.gather_sets(instance) + sets = self.collect_sets(instance) # Lookup with absolute names (from root namespace) instance_lookup = set(cmds.ls(instance, long=True)) self.log.info("Gathering set relations..") - for objset in sets: + # Ensure iteration happen in a list so we can remove keys from the + # dict within the loop + for objset in list(sets): self.log.debug("From %s.." % objset) objset_members = sets[objset]["members"] @@ -104,14 +106,11 @@ class CollectLook(pyblish.api.InstancePlugin): if not sets[objset]["members"]: self.log.info("Removing redundant set information: " "%s" % objset) - sets.pop(objset) + sets.pop(objset, None) self.log.info("Gathering attribute changes to instance members..") attributes = self.collect_attributes_changed(instance) - looksets = cmds.ls(sets.keys(), long=True) - - self.log.info("Found the following sets:\n{}".format(looksets)) # Store data on the instance instance.data["lookData"] = {"attributes": attributes, @@ -119,13 +118,16 @@ class CollectLook(pyblish.api.InstancePlugin): # Collect file nodes used by shading engines (if we have any) files = list() + looksets = sets.keys() if looksets: + self.log.info("Found the following sets:\n{}".format(looksets)) # Get the entire node chain of the look sets history = cmds.listHistory(looksets) files = cmds.ls(history, type="file", long=True) - # Collect textures - instance.data["resources"] = [self.collect_resource(n) for n in files] + # Collect textures if any file nodes are found + instance.data["resources"] = [self.collect_resource(n) + for n in files] # Log a warning when no relevant sets were retrieved for the look. if not instance.data["lookData"]["relationships"]: @@ -134,8 +136,8 @@ class CollectLook(pyblish.api.InstancePlugin): self.log.info("Collected look for %s" % instance) - def gather_sets(self, instance): - """Gather all objectSets which are of importance for publishing + def collect_sets(self, instance): + """Collect all objectSets which are of importance for publishing It checks if all nodes in the instance are related to any objectSet which need to be @@ -187,7 +189,11 @@ class CollectLook(pyblish.api.InstancePlugin): self.log.error("Node '{}' has no attribute 'cbId'".format(node)) return - return {"name": node, "uuid": lib.get_id(node)} + member_data = {"name": node, "uuid": lib.get_id(node)} + if components: + member_data["components"] = components + + return member def collect_attributes_changed(self, instance): """Collect all userDefined attributes which have changed From c18db31a91252fa8a9cc64c45015807190029ac6 Mon Sep 17 00:00:00 2001 From: aardschok Date: Mon, 16 Oct 2017 14:08:02 +0200 Subject: [PATCH 4/6] updated docstrings to match best practice --- colorbleed/plugins/maya/publish/validate_look_sets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colorbleed/plugins/maya/publish/validate_look_sets.py b/colorbleed/plugins/maya/publish/validate_look_sets.py index 0d16239215..bf0567cc88 100644 --- a/colorbleed/plugins/maya/publish/validate_look_sets.py +++ b/colorbleed/plugins/maya/publish/validate_look_sets.py @@ -27,7 +27,7 @@ class ValidateLookSets(pyblish.api.InstancePlugin): [asset_GRP|geometry_GRP|body_GES, asset_GRP|geometry_GRP|L_eye_GES, asset_GRP|geometry_GRP|R_eye_GES, - asset_GRP|geometry_GRP|wings_GEOShape] + asset_GRP|geometry_GRP|wings_GEO] """ From fd78f969f7c4b9c53cf888a082d71e6dda05aa14 Mon Sep 17 00:00:00 2001 From: aardschok Date: Mon, 16 Oct 2017 14:12:23 +0200 Subject: [PATCH 5/6] fixed return varaible --- colorbleed/plugins/maya/publish/collect_look.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colorbleed/plugins/maya/publish/collect_look.py b/colorbleed/plugins/maya/publish/collect_look.py index 173a26dc32..334929b5e6 100644 --- a/colorbleed/plugins/maya/publish/collect_look.py +++ b/colorbleed/plugins/maya/publish/collect_look.py @@ -193,7 +193,7 @@ class CollectLook(pyblish.api.InstancePlugin): if components: member_data["components"] = components - return member + return member_data def collect_attributes_changed(self, instance): """Collect all userDefined attributes which have changed From be5ceee226a0580907b020cf3a4e6ad745dd549e Mon Sep 17 00:00:00 2001 From: aardschok Date: Mon, 16 Oct 2017 14:27:29 +0200 Subject: [PATCH 6/6] clean up and optimization --- .../plugins/maya/publish/collect_look.py | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/colorbleed/plugins/maya/publish/collect_look.py b/colorbleed/plugins/maya/publish/collect_look.py index 334929b5e6..2df35499bc 100644 --- a/colorbleed/plugins/maya/publish/collect_look.py +++ b/colorbleed/plugins/maya/publish/collect_look.py @@ -30,14 +30,16 @@ def get_look_attrs(node): result = cmds.listAttr(node, userDefined=True, changedSinceFileOpen=True) or [] + # `cbId` is added when a scene is saved, ignore by default + if "cbId" in result: + result.remove("cbId") + # For shapes allow render stat changes if cmds.objectType(node, isAType="shape"): attrs = cmds.listAttr(node, changedSinceFileOpen=True) or [] - valid = [attr for attr in attrs if attr in SHAPE_ATTRS] - result.extend(valid) - - if "cbId" in result: - result.remove("cbId") + for attr in attrs: + if attr in SHAPE_ATTRS: + result.append(attr) return result @@ -80,7 +82,7 @@ class CollectLook(pyblish.api.InstancePlugin): self.log.info("Gathering sets..") sets = self.collect_sets(instance) - # Lookup with absolute names (from root namespace) + # Lookup set (optimization) instance_lookup = set(cmds.ls(instance, long=True)) self.log.info("Gathering set relations..") @@ -88,12 +90,10 @@ class CollectLook(pyblish.api.InstancePlugin): # dict within the loop for objset in list(sets): self.log.debug("From %s.." % objset) - objset_members = sets[objset]["members"] # Get all nodes of the current objectSet for member in cmds.ls(cmds.sets(objset, query=True), long=True): member_data = self.collect_member_data(member, - objset_members, instance_lookup) if not member_data: continue @@ -109,7 +109,6 @@ class CollectLook(pyblish.api.InstancePlugin): sets.pop(objset, None) self.log.info("Gathering attribute changes to instance members..") - attributes = self.collect_attributes_changed(instance) # Store data on the instance @@ -163,11 +162,10 @@ class CollectLook(pyblish.api.InstancePlugin): return sets - def collect_member_data(self, member, objset_members, instance_members): + def collect_member_data(self, member, instance_members): """Get all information of the node Args: member (str): the name of the node to check - objset_members (list): the objectSet members instance_members (set): the collected instance members Returns: @@ -179,17 +177,14 @@ class CollectLook(pyblish.api.InstancePlugin): # Only include valid members of the instance if node not in instance_members: - # Skip nodes which are not in the instance members return - if member in [m["name"] for m in objset_members]: - return - - if not cmds.attributeQuery("cbId", node=node, exists=True): + node_id = lib.get_id(node) + if not node_id: self.log.error("Node '{}' has no attribute 'cbId'".format(node)) return - member_data = {"name": node, "uuid": lib.get_id(node)} + member_data = {"name": node, "uuid": node_id} if components: member_data["components"] = components