This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1955 from davidlatwe/feature/maya-publish-augment…
…ed-model
- Loading branch information
Showing
4 changed files
with
281 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
openpype/hosts/maya/plugins/inventory/import_modelrender.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.