Skip to content

Commit

Permalink
Merge pull request #93 from BigRoy/enhancement/usd_load_ayon_entity_uri
Browse files Browse the repository at this point in the history
Load to Maya USD Proxy Shape using AYON Entity URI for AYON USD Resolver
  • Loading branch information
BigRoy authored Sep 16, 2024
2 parents c624b33 + d463487 commit 30dd1ec
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 9 deletions.
52 changes: 52 additions & 0 deletions client/ayon_maya/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,47 @@ def get_reference_node_parents(*args, **kwargs):
return lib.get_reference_node_parents(*args, **kwargs)


def get_ayon_entity_uri_from_representation_context(context: dict) -> str:
"""Resolve AYON Entity URI from representation context.
Note:
The representation context is the `get_representation_context` dict
containing the `project`, `folder, `representation` and so forth.
It is not the representation entity `context` key.
Arguments:
context (dict): The representation context.
Raises:
RuntimeError: Unable to resolve to a single valid URI.
Returns:
str: The AYON entity URI.
"""
# TODO: This is a 1:1 copy from ayon-houdini and may be good to refactor
# and de-duplicate across the codebase, e.g. to core functionality
project_name = context["project"]["name"]
representation_id = context["representation"]["id"]
response = ayon_api.post(
f"projects/{project_name}/uris",
entityType="representation",
ids=[representation_id])
if response.status_code != 200:
raise RuntimeError(
f"Unable to resolve AYON entity URI for '{project_name}' "
f"representation id '{representation_id}': {response.text}"
)
uris = response.data["uris"]
if len(uris) != 1:
raise RuntimeError(
f"Unable to resolve AYON entity URI for '{project_name}' "
f"representation id '{representation_id}' to single URI. "
f"Received data: {response.data}"
)
return uris[0]["uri"]


@six.add_metaclass(ABCMeta)
class MayaCreatorBase(object):

Expand Down Expand Up @@ -639,6 +680,17 @@ class Loader(LoaderPlugin):
settings_category = SETTINGS_CATEGORY
load_settings = {} # defined in settings

use_ayon_entity_uri = False

@classmethod
def filepath_from_context(cls, context):
# TODO: This is a 1:1 copy from ayon-houdini and may be good to
# refactor and de-duplicate across the codebase, e.g. to core
if cls.use_ayon_entity_uri:
return get_ayon_entity_uri_from_representation_context(context)

return super().filepath_from_context(context)

@classmethod
def apply_settings(cls, project_settings):
super(Loader, cls).apply_settings(project_settings)
Expand Down
9 changes: 3 additions & 6 deletions client/ayon_maya/plugins/load/load_maya_usd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
import maya.cmds as cmds
from ayon_core.pipeline import get_representation_path
from ayon_core.pipeline.load import get_representation_path_from_context
from ayon_maya.api.lib import namespaced, unique_namespace
from ayon_maya.api.pipeline import containerise
from ayon_maya.api import plugin
Expand Down Expand Up @@ -29,7 +27,7 @@ def load(self, context, name=None, namespace=None, options=None):
# Make sure we can load the plugin
cmds.loadPlugin("mayaUsdPlugin", quiet=True)

path = get_representation_path_from_context(context)
path = self.filepath_from_context(context)

# Create the shape
cmds.namespace(addNamespace=namespace)
Expand Down Expand Up @@ -72,13 +70,12 @@ def update(self, container, context):
members = cmds.sets(node, query=True) or []
shapes = cmds.ls(members, type="mayaUsdProxyShape")

repre_entity = context["representation"]
path = get_representation_path(repre_entity)
path = self.filepath_from_context(context)
for shape in shapes:
cmds.setAttr("{}.filePath".format(shape), path, type="string")

cmds.setAttr("{}.representation".format(node),
repre_entity["id"],
context["representation"]["id"],
type="string")

def switch(self, container, context):
Expand Down
25 changes: 22 additions & 3 deletions server/settings/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ class LoaderEnabledModel(BaseSettingsModel):
enabled: bool = SettingsField(title="Enabled")


class LoaderEnabledUseAyonEntityURIModel(LoaderEnabledModel):
use_ayon_entity_uri: bool = SettingsField(
title="Use AYON Entity URI",
description=(
"Use the AYON Entity URI on load instead of the resolved filepath "
"so that the AYON USD Resolver will resolve the paths at runtime. "
"This should be enabled when using the AYON USD Resolver."
)
)


class ColorsSetting(BaseSettingsModel):
model: ColorRGBA_uint8 = SettingsField(
(209, 132, 30, 1.0), title="Model:")
Expand Down Expand Up @@ -122,9 +133,9 @@ class OxRigLoaderModel(LoaderEnabledModel):
create_cache_instance_on_load: bool = SettingsField(
title="Create Ornatrix Cache instance on load",
description=(
"When enabled, upon loading an Ornatrix Rig product a new Ornatrix cache "
"instance is automatically created as preparation to publishing "
"the output directly."
"When enabled, upon loading an Ornatrix Rig product a new "
"Ornatrix cache instance is automatically created as preparation "
"to publishing the output directly."
)
)

Expand Down Expand Up @@ -177,6 +188,10 @@ class LoadersModel(BaseSettingsModel):
default_factory=LoaderEnabledModel,
title="Matchmove Loader"
)
MayaUsdLoader: LoaderEnabledUseAyonEntityURIModel = SettingsField(
default_factory=LoaderEnabledUseAyonEntityURIModel,
title="Maya Load USD to Maya Proxy Loader"
)
MultiverseUsdLoader: LoaderEnabledModel = SettingsField(
default_factory=LoaderEnabledModel,
title="Multiverse USD Loader"
Expand Down Expand Up @@ -287,6 +302,10 @@ class LoadersModel(BaseSettingsModel):
"ImagePlaneLoader": {"enabled": True},
"LookLoader": {"enabled": True},
"MatchmoveLoader": {"enabled": True},
"MayaUsdLoader": {
"enabled": True,
"use_ayon_entity_uri": True
},
"MultiverseUsdLoader": {"enabled": True},
"MultiverseUsdOverLoader": {"enabled": True},
"RedshiftProxyLoader": {"enabled": True},
Expand Down

0 comments on commit 30dd1ec

Please sign in to comment.