Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1955 from davidlatwe/feature/maya-publish-augment…
Browse files Browse the repository at this point in the history
…ed-model
  • Loading branch information
mkolar authored Sep 24, 2021
2 parents 82fcb58 + da7dda6 commit bf39741
Show file tree
Hide file tree
Showing 4 changed files with 281 additions and 85 deletions.
1 change: 1 addition & 0 deletions openpype/hosts/maya/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def uninstall():
pyblish.deregister_plugin_path(PUBLISH_PATH)
avalon.deregister_plugin_path(avalon.Loader, LOAD_PATH)
avalon.deregister_plugin_path(avalon.Creator, CREATE_PATH)
avalon.deregister_plugin_path(avalon.InventoryAction, INVENTORY_PATH)

menu.uninstall()

Expand Down
92 changes: 92 additions & 0 deletions openpype/hosts/maya/plugins/inventory/import_modelrender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from avalon import api, io


class ImportModelRender(api.InventoryAction):

label = "Import Model Render Sets"
icon = "industry"
color = "#55DDAA"

scene_type_regex = "meta.render.m[ab]"
look_data_type = "meta.render.json"

@staticmethod
def is_compatible(container):
return (
container.get("loader") == "ReferenceLoader"
and container.get("name", "").startswith("model")
)

def process(self, containers):
from maya import cmds

for container in containers:
con_name = container["objectName"]
nodes = []
for n in cmds.sets(con_name, query=True, nodesOnly=True) or []:
if cmds.nodeType(n) == "reference":
nodes += cmds.referenceQuery(n, nodes=True)
else:
nodes.append(n)

repr_doc = io.find_one({
"_id": io.ObjectId(container["representation"]),
})
version_id = repr_doc["parent"]

print("Importing render sets for model %r" % con_name)
self.assign_model_render_by_version(nodes, version_id)

def assign_model_render_by_version(self, nodes, version_id):
"""Assign nodes a specific published model render data version by id.
This assumes the nodes correspond with the asset.
Args:
nodes(list): nodes to assign render data to
version_id (bson.ObjectId): database id of the version of model
Returns:
None
"""
import json
from maya import cmds
from avalon import maya, io, pipeline
from openpype.hosts.maya.api import lib

# Get representations of shader file and relationships
look_repr = io.find_one({
"type": "representation",
"parent": version_id,
"name": {"$regex": self.scene_type_regex},
})
if not look_repr:
print("No model render sets for this model version..")
return

json_repr = io.find_one({
"type": "representation",
"parent": version_id,
"name": self.look_data_type,
})

context = pipeline.get_representation_context(look_repr["_id"])
maya_file = pipeline.get_representation_path_from_context(context)

context = pipeline.get_representation_context(json_repr["_id"])
json_file = pipeline.get_representation_path_from_context(context)

# Import the look file
with maya.maintained_selection():
shader_nodes = cmds.file(maya_file,
i=True, # import
returnNewNodes=True)
# imprint context data

# Load relationships
shader_relation = json_file
with open(shader_relation, "r") as f:
relationships = json.load(f)

# Assign relationships
lib.apply_shaders(relationships, shader_nodes, nodes)
63 changes: 61 additions & 2 deletions openpype/hosts/maya/plugins/publish/collect_look.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ class CollectLook(pyblish.api.InstancePlugin):

def process(self, instance):
"""Collect the Look in the instance with the correct layer settings"""

with lib.renderlayer(instance.data["renderlayer"]):
renderlayer = instance.data.get("renderlayer", "defaultRenderLayer")
with lib.renderlayer(renderlayer):
self.collect(instance)

def collect(self, instance):
Expand Down Expand Up @@ -357,6 +357,23 @@ def collect(self, instance):
for vray_node in vray_plugin_nodes:
history.extend(cmds.listHistory(vray_node))

# handling render attribute sets
render_set_types = [
"VRayDisplacement",
"VRayLightMesh",
"VRayObjectProperties",
"RedshiftObjectId",
"RedshiftMeshParameters",
]
render_sets = cmds.ls(look_sets, type=render_set_types)
if render_sets:
history.extend(
cmds.listHistory(render_sets,
future=False,
pruneDagObjects=True)
or []
)

files = cmds.ls(history, type="file", long=True)
files.extend(cmds.ls(history, type="aiImage", long=True))
files.extend(cmds.ls(history, type="RedshiftNormalMap", long=True))
Expand Down Expand Up @@ -550,3 +567,45 @@ def collect_resource(self, node):
"source": source, # required for resources
"files": files,
"color_space": color_space} # required for resources


class CollectModelRenderSets(CollectLook):
"""Collect render attribute sets for model instance.
Collects additional render attribute sets so they can be
published with model.
"""

order = pyblish.api.CollectorOrder + 0.21
families = ["model"]
label = "Collect Model Render Sets"
hosts = ["maya"]
maketx = True

def collect_sets(self, instance):
"""Collect all related objectSets except shadingEngines
Args:
instance (list): all nodes to be published
Returns:
dict
"""

sets = {}
for node in instance:
related_sets = lib.get_related_sets(node)
if not related_sets:
continue

for objset in related_sets:
if objset in sets:
continue

if "shadingEngine" in cmds.nodeType(objset, inherited=True):
continue

sets[objset] = {"uuid": lib.get_id(objset), "members": list()}

return sets
Loading

0 comments on commit bf39741

Please sign in to comment.