fixing vray look assigning

This commit is contained in:
Ondrej Samohel 2021-12-17 18:38:56 +01:00
parent 501497089a
commit 5d06c85a34
No known key found for this signature in database
GPG key ID: 02376E18990A97C6
4 changed files with 42 additions and 25 deletions

View file

@ -24,7 +24,6 @@ from .commands import (
)
from .vray_proxies import vrayproxy_assign_look
module = sys.modules[__name__]
module.window = None
@ -210,7 +209,7 @@ class App(QtWidgets.QWidget):
# Assign the first matching look relevant for this asset
# (since assigning multiple to the same nodes makes no sense)
assign_look = next((subset for subset in item["looks"]
if subset["name"] in looks), None)
if subset["name"] in looks), None)
if not assign_look:
self.echo("{} No matching selected "
"look for {}".format(prefix, asset))
@ -229,11 +228,14 @@ class App(QtWidgets.QWidget):
if cmds.pluginInfo('vrayformaya', query=True, loaded=True):
self.echo("Getting vray proxy nodes ...")
vray_proxies = set(cmds.ls(type="VRayProxy"))
nodes = list(set(item["nodes"]).difference(vray_proxies))
vray_proxies = set(cmds.ls(type="VRayProxy", long=True))
if vray_proxies:
for vp in vray_proxies:
vrayproxy_assign_look(vp, subset_name)
if vp in nodes:
vrayproxy_assign_look(vp, subset_name)
nodes = list(set(item["nodes"]).difference(vray_proxies))
# Assign look
if nodes:

View file

@ -8,7 +8,6 @@ from openpype.hosts.maya.api import lib
from avalon import io, api
from .vray_proxies import get_alembic_ids_cache
log = logging.getLogger(__name__)
@ -68,7 +67,9 @@ def get_selected_nodes():
selection = cmds.ls(selection=True, long=True)
hierarchy = list_descendents(selection)
return list(set(selection + hierarchy))
selected_nodes = list(set(selection + hierarchy))
log.warning("selected nodes: {}".format(selected_nodes))
return selected_nodes
def get_all_asset_nodes():
@ -79,17 +80,23 @@ def get_all_asset_nodes():
"""
host = api.registered_host()
containers = host.ls()
nodes = []
log.debug("got {}".format(containers))
for container in host.ls():
# We are not interested in looks but assets!
if container["loader"] == "LookLoader":
log.warning("skipping {}".format(container))
continue
# Gather all information
container_name = container["objectName"]
log.warning("--- listing: {}".format(container_name))
nodes += cmds.sets(container_name, query=True, nodesOnly=True) or []
nodes = list(set(nodes))
log.warning("returning {}".format(nodes))
return nodes
@ -102,13 +109,24 @@ def create_asset_id_hash(nodes):
dict
"""
node_id_hash = defaultdict(list)
# log.warning(pformat(nodes))
for node in nodes:
# iterate over content of reference node
if cmds.nodeType(node) == "reference":
ref_hashes = create_asset_id_hash(
cmds.referenceQuery(node, nodes=True))
list(set(cmds.referenceQuery(node, nodes=True, dp=True))))
for asset_id, ref_nodes in ref_hashes.items():
node_id_hash[asset_id] += ref_nodes
elif cmds.pluginInfo('vrayformaya', query=True,
loaded=True) and cmds.nodeType(
node) == "VRayProxy":
path = cmds.getAttr("{}.fileName".format(node))
ids = get_alembic_ids_cache(path)
for k, _ in ids.items():
pid = k.split(":")[0]
if not node_id_hash.get(pid):
node_id_hash[pid] = [node]
else:
value = lib.get_id(node)
if value is None:
@ -151,12 +169,12 @@ def create_items_from_nodes(nodes):
for k, _ in ids.items():
pid = k.split(":")[0]
if not parent_id.get(pid):
parent_id.update({pid: [vp]})
print("Adding ids from alembic {}".format(path))
parent_id[pid] = [vp]
log.warning("Adding ids from alembic {}".format(path))
id_hashes.update(parent_id)
if not id_hashes:
log.warning("No id hashes")
return asset_view_items
for _id, id_nodes in id_hashes.items():

View file

@ -41,7 +41,11 @@ def get_alembic_paths_by_property(filename, attr, verbose=False):
filename = filename.replace("\\", "/")
filename = str(filename) # path must be string
archive = alembic.Abc.IArchive(filename)
try:
archive = alembic.Abc.IArchive(filename)
except RuntimeError:
# invalid file format
return {}
root = archive.getTop()
iterator = list(root.children)
@ -201,9 +205,7 @@ def load_look(version_id):
with avalon.maya.maintained_selection():
container_node = api.load(loader, look_representation)
# Get container members
shader_nodes = cmds.sets(container_node, query=True)
return shader_nodes
return cmds.sets(container_node, query=True)
def get_latest_version(asset_id, subset):

View file

@ -20,7 +20,6 @@ MODELINDEX = QtCore.QModelIndex()
class AssetOutliner(QtWidgets.QWidget):
refreshed = QtCore.Signal()
selection_changed = QtCore.Signal()
@ -84,14 +83,13 @@ class AssetOutliner(QtWidgets.QWidget):
"""
selection_model = self.view.selectionModel()
items = [row.data(TreeModel.ItemRole) for row in
selection_model.selectedRows(0)]
return items
return [row.data(TreeModel.ItemRole)
for row in selection_model.selectedRows(0)]
def get_all_assets(self):
"""Add all items from the current scene"""
items = []
with lib.preserve_expanded_rows(self.view):
with lib.preserve_selection(self.view):
self.clear()
@ -118,7 +116,7 @@ class AssetOutliner(QtWidgets.QWidget):
# Collect all nodes by hash (optimization)
if not selection:
nodes = cmds.ls(dag=True, long=True)
nodes = cmds.ls(dag=True, long=True)
else:
nodes = commands.get_selected_nodes()
id_nodes = commands.create_asset_id_hash(nodes)
@ -187,7 +185,6 @@ class AssetOutliner(QtWidgets.QWidget):
class LookOutliner(QtWidgets.QWidget):
menu_apply_action = QtCore.Signal()
def __init__(self, parent=None):
@ -237,9 +234,7 @@ class LookOutliner(QtWidgets.QWidget):
"""
datas = [i.data(TreeModel.ItemRole) for i in self.view.get_indices()]
items = [d for d in datas if d is not None] # filter Nones
return items
return [d for d in datas if d is not None]
def right_mouse_menu(self, pos):
"""Build RMB menu for look view"""