ynput / ayon-maya

Maya addon for AYON
Apache License 2.0
5 stars 6 forks source link

AY-6685_Maya USD: Rig in USD Asset as MayaReference prim #10

Open BigRoy opened 9 months ago

BigRoy commented 9 months ago

Is there an existing issue for this?

Please describe the feature you have in mind and explain what the current shortcomings are?

Working within a USD Pipeline usually means you want your animation output for e.g. a rig to be overlaid on top of a loaded USD Asset to merge the animated point data with the model and look of the asset, usually for use by downstream lighting department.

The USD reference usually provides:

- asset (referenced usd asset)
  - geo
  - mtl

The output data from a rig should then be overlaid over the /asset/geo path in the shot to move the character around.

Currently, publishing an animation from a rig usually means completely separate Alembic or USD data that would need to somehow be identified to get overlaid over a particular USD asset structure in a shot.

What if we could load an asset, and it itself, has a reference to the rig embedded?

How would you imagine the implementation of the feature?

Maya USD allows to embed maya scene files (mayaAscii or mayaBinary) to be included into USD as a MayaReference prim referencing the file. When a Maya USD Proxy finds such a prim it can enable the prim as a regular maya reference to load the native maya data, like for example a rig file.

I'd like to propose to - whenever publishing a rig from Maya to write out a USD Asset Contribution where an extra layer gets added to the USD asset representing the rig as a reference.

Basically someone (e.g. either in Maya or Houdini) lays out assets in a scene, by loading the asset USD. If that asset now contains the MayaReference prim (which can be loaded fine in Houdini; just the internal data of the maya scene couldn't be loaded) then in Maya one could now enable that reference inside the USD Asset to load the actual rig.

So assets laid out in any USD supporting host could in Maya be switched to their rig for animating. Nice!

In essence we'd need:

  1. On publishing a Maya rig, create a USD asset contribution that references in this rig version in a USD layer
  2. On Maya, when the Maya USD reference rig is loaded (and its detected its loaded within USD asset) then publish the animation cache as USD that gets added as a variant on the loaded asset in the shot's anim layer.

That way, the animator in Maya can just read a USD Layout with loaded assets, enable the reference, animate and publish.

Plus side to this would be, that when they've published their animation to the shot's layers they can also disable their reference and switch it over it to the published cache (since it's also a USD contribution). Meaning they can use the cached USD data as proxy in their scene whilst maybe e.g. continuing to animate on another character.

Are there any labels you wish to add?

Describe alternatives you've considered:

Loading rigs manually, then publishing and manually overlaying (e.g. referencing) the output over the USD data over an asset, after the fact.

Additional context:

No response

[cuID:OP-7978]

BigRoy commented 5 days ago

Just for reference. This is a simple Maya reference inside the USD data:

#usda 1.0

def Xform "Xform1" (
    variants = {
        string Representation = "MayaReference"
    }
    prepend variantSets = "Representation"
)
{
    variantSet "Representation" = {
        "MayaReference" {
            def MayaReference "MayaReference1"
            {
                bool mayaAutoEdit = 0
                string mayaNamespace = "test"
                asset mayaReference = @C:/Users/User/Desktop/test.ma@
            }

        }
    }
}

And some quick code to generate the relevant prim specs via Sdf:

from pxr import Usd, Sdf

layer = Sdf.Layer.CreateAnonymous()

parent = layer.pseudoRoot
prim_name = "rigMain"

def create_maya_reference_prim_spec(
    parent,
    prim_name: str,
    path: str,
    namespace: str):
    """Create MayaReference Prim Spec"""
    prim_spec = Sdf.PrimSpec(
        parent,
        prim_name,
        Sdf.SpecifierDef,
        "MayaReference"
    )
    reference_spec = Sdf.AttributeSpec(prim_spec, "mayaReference", Sdf.ValueTypeNames.Asset)
    reference_spec.default = path
    auto_edit_spec = Sdf.AttributeSpec(prim_spec, "mayaAutoEdit", Sdf.ValueTypeNames.Bool)
    auto_edit_spec.default = False
    namespace_spec = Sdf.AttributeSpec(prim_spec, "mayaNamespace", Sdf.ValueTypeNames.String)
    namespace_spec.default = namespace
    return prim_spec

create_maya_reference_prim_spec(
    layer.pseudoRoot,
    "rigMain",
    path="E:/test.ma",
    namespace="test"
)

print(layer.ExportToString())

Results in:

#sdf 1.4.32

def MayaReference "rigMain"
{
    bool mayaAutoEdit = 0
    string mayaNamespace = "test"
    asset mayaReference = @E:/test.ma@
}