Repository: ynput/OpenPype
Issue: Maya: loading references and speed 💨

### Problem

When loading maya reference (via Loader) into Maya, Lot of connections are made between each and every object in reference and container set. Referencing - speedwise - is ok, but loading scenes with those references pointing to some heavy data (like rigs with many many controls/bones/null/....) can lead to many minutes overheaad compared to "vanilla maya". This is because Maya will save to scene file instruction to initialize those attribute connections, array of them, etc. This can add almost 100% (or possibly more) to the scene size and multiple loading times.

### Solution

When loadin reference, connect only reference node itself to the set.

### Additional musings

That should be part of our brightly sparkling new initiative - **Make Artist Faster Again!** (or **MAFA**). When testing framework is done, we should utilize it to profile are core processes to optimize them.

Changed files:
openpype/tools/mayalookassigner/commands.py, openpype/hosts/maya/api/plugin.py

diff --git a/openpype/hosts/maya/api/plugin.py b/openpype/hosts/maya/api/plugin.py
index 257908c768..121f7a08a7 100644
--- a/openpype/hosts/maya/api/plugin.py
+++ b/openpype/hosts/maya/api/plugin.py
@@ -99,14 +99,24 @@ class ReferenceLoader(api.Loader):
             nodes = self[:]
             if not nodes:
                 return
-
-            loaded_containers.append(containerise(
-                name=name,
-                namespace=namespace,
-                nodes=nodes,
-                context=context,
-                loader=self.__class__.__name__
-            ))
+            # FIXME: there is probably better way to do this for looks.
+            if "look" in self.families:
+                loaded_containers.append(containerise(
+                    name=name,
+                    namespace=namespace,
+                    nodes=nodes,
+                    context=context,
+                    loader=self.__class__.__name__
+                ))
+            else:
+                ref_node = self._get_reference_node(nodes)
+                loaded_containers.append(containerise(
+                    name=name,
+                    namespace=namespace,
+                    nodes=[ref_node],
+                    context=context,
+                    loader=self.__class__.__name__
+                ))
 
             c += 1
             namespace = None
@@ -235,9 +245,6 @@ class ReferenceLoader(api.Loader):
             self.log.info("Setting %s.verticesOnlySet to False", node)
             cmds.setAttr("{}.verticesOnlySet".format(node), False)
 
-        # Add new nodes of the reference to the container
-        cmds.sets(content, forceElement=node)
-
         # Remove any placeHolderList attribute entries from the set that
         # are remaining from nodes being removed from the referenced file.
         members = cmds.sets(node, query=True)
diff --git a/openpype/tools/mayalookassigner/commands.py b/openpype/tools/mayalookassigner/commands.py
index 2add5d3499..a53251cdef 100644
--- a/openpype/tools/mayalookassigner/commands.py
+++ b/openpype/tools/mayalookassigner/commands.py
@@ -103,12 +103,19 @@ def create_asset_id_hash(nodes):
     """
     node_id_hash = defaultdict(list)
     for node in nodes:
-        value = lib.get_id(node)
-        if value is None:
-            continue
+        # iterate over content of reference node
+        if cmds.nodeType(node) == "reference":
+            ref_hashes = create_asset_id_hash(
+                cmds.referenceQuery(node, nodes=True))
+            for asset_id, ref_nodes in ref_hashes.items():
+                node_id_hash[asset_id] += ref_nodes
+        else:
+            value = lib.get_id(node)
+            if value is None:
+                continue
 
-        asset_id = value.split(":")[0]
-        node_id_hash[asset_id].append(node)
+            asset_id = value.split(":")[0]
+            node_id_hash[asset_id].append(node)
 
     return dict(node_id_hash)
 
@@ -135,18 +142,19 @@ def create_items_from_nodes(nodes):
     id_hashes = create_asset_id_hash(nodes)
 
     # get ids from alembic
-    vray_proxy_nodes = cmds.ls(nodes, type="VRayProxy")
-    for vp in vray_proxy_nodes:
-        path = cmds.getAttr("{}.fileName".format(vp))
-        ids = vray_proxies.get_alembic_ids_cache(path)
-        parent_id = {}
-        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))
-        id_hashes.update(parent_id)
+    if cmds.pluginInfo('vrayformaya', query=True, loaded=True):
+        vray_proxy_nodes = cmds.ls(nodes, type="VRayProxy")
+        for vp in vray_proxy_nodes:
+            path = cmds.getAttr("{}.fileName".format(vp))
+            ids = vray_proxies.get_alembic_ids_cache(path)
+            parent_id = {}
+            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))
+            id_hashes.update(parent_id)
 
     if not id_hashes:
         return asset_view_items