mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
load and update sets in look loader
This commit is contained in:
parent
72e0c42543
commit
ecbd2b910e
3 changed files with 40 additions and 22 deletions
|
|
@ -105,7 +105,20 @@ class LookLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
|||
# Load relationships
|
||||
shader_relation = api.get_representation_path(json_representation)
|
||||
with open(shader_relation, "r") as f:
|
||||
relationships = json.load(f)
|
||||
json_data = json.load(f)
|
||||
|
||||
for rel, data in json_data["relationships"].items():
|
||||
# process only non-shading nodes
|
||||
current_node = "{}:{}".format(container["namespace"], rel)
|
||||
if current_node in shader_nodes:
|
||||
continue
|
||||
print("processing {}".format(rel))
|
||||
current_members = set(cmds.ls(cmds.sets(current_node, query=True) or [], long=True))
|
||||
new_members = {"{}".format(m["name"]) for m in data["members"] or []}
|
||||
dif = new_members.difference(current_members)
|
||||
|
||||
# add to set
|
||||
cmds.sets(dif, forceElement="{}:{}".format(container["namespace"], rel))
|
||||
|
||||
# update of reference could result in failed edits - material is not
|
||||
# present because of renaming etc.
|
||||
|
|
@ -120,7 +133,7 @@ class LookLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
|||
cmds.file(cr=reference_node) # cleanReference
|
||||
|
||||
# reapply shading groups from json representation on orig nodes
|
||||
openpype.hosts.maya.api.lib.apply_shaders(relationships,
|
||||
openpype.hosts.maya.api.lib.apply_shaders(json_data,
|
||||
shader_nodes,
|
||||
orig_nodes)
|
||||
|
||||
|
|
@ -128,12 +141,13 @@ class LookLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
|||
"All successful edits were kept intact.\n",
|
||||
"Failed and removed edits:"]
|
||||
msg.extend(failed_edits)
|
||||
|
||||
msg = ScrollMessageBox(QtWidgets.QMessageBox.Warning,
|
||||
"Some reference edit failed",
|
||||
msg)
|
||||
msg.exec_()
|
||||
|
||||
attributes = relationships.get("attributes", [])
|
||||
attributes = json_data.get("attributes", [])
|
||||
|
||||
# region compute lookup
|
||||
nodes_by_id = defaultdict(list)
|
||||
|
|
|
|||
|
|
@ -273,21 +273,21 @@ class CollectLook(pyblish.api.InstancePlugin):
|
|||
if cmds.getAttr("{}.{}".format(obj_set, attr), type=True) in disabled_types: # noqa
|
||||
continue
|
||||
|
||||
# self.log.debug("{}: {}".format(attr, cmds.getAttr("{}.{}".format(obj_set, attr), type=True))) # noqa
|
||||
node_attrs.append((
|
||||
attr,
|
||||
cmds.getAttr("{}.{}".format(obj_set, attr))
|
||||
cmds.getAttr("{}.{}".format(obj_set, attr)),
|
||||
cmds.getAttr(
|
||||
"{}.{}".format(obj_set, attr), type=True)
|
||||
))
|
||||
|
||||
render_nodes.append(
|
||||
{
|
||||
"name": obj_set,
|
||||
"type": cmds.nodeType(obj_set),
|
||||
"members": cmds.ls(cmds.sets(
|
||||
obj_set, query=True), long=True),
|
||||
"attributes": node_attrs
|
||||
}
|
||||
)
|
||||
for member in cmds.ls(cmds.sets(obj_set, query=True), long=True):
|
||||
member_data = self.collect_member_data(member,
|
||||
instance_lookup)
|
||||
if not member_data:
|
||||
continue
|
||||
|
||||
# Add information of the node to the members list
|
||||
sets[obj_set]["members"].append(member_data)
|
||||
|
||||
# Get all nodes of the current objectSet (shadingEngine)
|
||||
for member in cmds.ls(cmds.sets(obj_set, query=True), long=True):
|
||||
|
|
@ -302,7 +302,7 @@ class CollectLook(pyblish.api.InstancePlugin):
|
|||
# Remove sets that didn't have any members assigned in the end
|
||||
# Thus the data will be limited to only what we need.
|
||||
self.log.info("obj_set {}".format(sets[obj_set]))
|
||||
if not sets[obj_set]["members"] or (not obj_set.endswith("SG")):
|
||||
if not sets[obj_set]["members"]:
|
||||
self.log.info(
|
||||
"Removing redundant set information: {}".format(obj_set))
|
||||
sets.pop(obj_set, None)
|
||||
|
|
@ -313,8 +313,7 @@ class CollectLook(pyblish.api.InstancePlugin):
|
|||
# Store data on the instance
|
||||
instance.data["lookData"] = {
|
||||
"attributes": attributes,
|
||||
"relationships": sets,
|
||||
"render_nodes": render_nodes
|
||||
"relationships": sets
|
||||
}
|
||||
|
||||
# Collect file nodes used by shading engines (if we have any)
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ class ValidateLookSets(pyblish.api.InstancePlugin):
|
|||
def process(self, instance):
|
||||
"""Process all the nodes in the instance"""
|
||||
|
||||
self.log.debug(instance.data.get("lookData"))
|
||||
invalid = self.get_invalid(instance)
|
||||
if invalid:
|
||||
raise RuntimeError("'{}' has invalid look "
|
||||
|
|
@ -60,6 +61,8 @@ class ValidateLookSets(pyblish.api.InstancePlugin):
|
|||
"'{}'".format(instance.name))
|
||||
|
||||
relationships = instance.data["lookData"]["relationships"]
|
||||
render_nodes_data = instance.data["lookData"].get("render_nodes") or []
|
||||
render_node_names = [n["name"] for n in render_nodes_data]
|
||||
invalid = []
|
||||
|
||||
renderlayer = instance.data.get("renderlayer", "defaultRenderLayer")
|
||||
|
|
@ -73,8 +76,10 @@ class ValidateLookSets(pyblish.api.InstancePlugin):
|
|||
# check if any objectSets are not present ion the relationships
|
||||
missing_sets = [s for s in sets if s not in relationships]
|
||||
if missing_sets:
|
||||
for set in missing_sets:
|
||||
if '_SET' not in set:
|
||||
for missing_set in missing_sets:
|
||||
cls.log.debug(missing_set)
|
||||
|
||||
if '_SET' not in missing_set:
|
||||
# A set of this node is not coming along, this is wrong!
|
||||
cls.log.error("Missing sets '{}' for node "
|
||||
"'{}'".format(missing_sets, node))
|
||||
|
|
@ -82,8 +87,8 @@ class ValidateLookSets(pyblish.api.InstancePlugin):
|
|||
continue
|
||||
|
||||
# Ensure the node is in the sets that are collected
|
||||
for shaderset, data in relationships.items():
|
||||
if shaderset not in sets:
|
||||
for shader_set, data in relationships.items():
|
||||
if shader_set not in sets:
|
||||
# no need to check for a set if the node
|
||||
# isn't in it anyway
|
||||
continue
|
||||
|
|
@ -94,7 +99,7 @@ class ValidateLookSets(pyblish.api.InstancePlugin):
|
|||
# The node is not found in the collected set
|
||||
# relationships
|
||||
cls.log.error("Missing '{}' in collected set node "
|
||||
"'{}'".format(node, shaderset))
|
||||
"'{}'".format(node, shader_set))
|
||||
invalid.append(node)
|
||||
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue