Autodesk / Autodesk/maya-usd

SchemaApiAdaptor not triggering when exporting skeletons/joints with applied API schema

Open
#2,714 4 comments 0 reactions 1 assignee Claimed by @santosg87 View on GitHub
bug
Dominant language
Wolfram Language
Stars
905
Forks
223
Avg merge
2d 9h
Merged PRs (30d)
17

Description

**Describe the bug**
* When exporting a skeleton / joints previously imported with maya-usd with a custom `SchemaApiAdaptor`, the adaptor will not get triggered, and the export logic will not get executed.
* When exporting a skeleton / joints previously imported with maya-usd with a custom API schema without a custom adaptor, the data associated with the custom API schema will not get exported again to the `usd`

This is a follow-up from [this discussion](https://github.com/Autodesk/maya-usd/discussions/2621), upon further study I do believe this is a bug/oversight/missing feature on the side of `maya-usd`

**Steps to reproduce**

1. Clone [this illustration repository](https://github.com/BeardedPlatypus/maya-usd-skeleton-issue-example)
2. Open the cloned repositories directory in VS Code
3. Start the `Maya 2022` task in VS Code (this will ensure the env is set correctly and will start Maya 2022)
4. Run the [run.py](https://github.com/BeardedPlatypus/maya-usd-skeleton-issue-example/blob/main/run.py) script within Maya through the script editor

The [run.py](https://github.com/BeardedPlatypus/maya-usd-skeleton-issue-example/blob/main/run.py) will execute an import and an export command which utilizes the adaptor defined in the [joint_example.py](https://github.com/BeardedPlatypus/maya-usd-skeleton-issue-example/blob/main/example/plug-ins/joint_example.py) for the `WithAdaptorAPI`, and imports and exports `WithoutAdaptorAPI` with the default behaviour.

**Observed behavior**

* The data is correctly imported on the corresponding Maya objects:
![image](https://user-images.githubusercontent.com/5596079/200985542-8384e468-3d68-4e1f-8a35-83f797dc2f41.png)
* The following can be observed in the Maya script window output (the messages are generated by [the SchemaApiAdaptor](https://github.com/BeardedPlatypus/maya-usd-skeleton-issue-example/blob/main/example/plug-ins/joint_example.py)
```
# Importing '<...>\usd_data\sample_data.usda' #
CanAdaptForImport: arm
ApplySchemaForImport: arm
CopyFromPrim: mayaObject: arm | prim: arm | value: this-will-be-altered
CanAdaptForImport: skeleton
ApplySchemaForImport: skeleton
CopyFromPrim: mayaObject: skeleton | prim: skeleton | value: this-will-be-altered
# Opening layer '<...>/maya-usd-skeleton-issue-example/usd_data/exported_data.usda' for writing #
CanAdaptForExport: arm
CanAdaptForExport: arm
CopyToPrim: mayaObject: arm | prim: arm
CanAdaptForExport: skeleton
CopyToPrim: mayaObject: skeleton | prim: skeleton
# Saving stage #
```
* The following can be observed in the exported usd file at `./usd_data/exported_data.usda`:
```
def Mesh "arm" (
prepend apiSchemas = ["WithoutAdaptorAPI", "WithAdaptorAPI", "MaterialBindingAPI"]
)
{
...
string example:data = "this-was-exported"
string example:default_data = "this-will-be-kept-the-same"
...
}

def Skeleton "skeleton" (
prepend apiSchemas = ["SkelBindingAPI"]
)
{
uniform matrix4d[] bindTransforms = ...
uniform token[] joints = ["joint1", "joint1/joint2", "joint1/joint2/joint3"]
uniform matrix4d[] restTransforms = ...
rel skel:animationSource =
matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) )
uniform token[] xformOpOrder = ["xformOp:transform"]

def SkelAnimation "Animation"
{
uniform token[] joints = ["joint1"]
quatf[] rotations = [(0.99960554, 0, 0.028086055, 0)]
half3[] scales = [(1, 1, 1)]
float3[] translations = [(0.16728887, 0, 0.03475939)]
}
}
```

**Expected behavior**

The import behaviour works as expected, however there is data missing on `skeleton` prim when the exported file is compared to the source file [`sample_data.usda`](https://github.com/BeardedPlatypus/maya-usd-skeleton-issue-example/blob/main/usd_data/sample_data.usda).

Based on the defined behaviour we would expect the following data to be present in the exported `usd` file:

```
def Mesh "arm" (
prepend apiSchemas = ["WithoutAdaptorAPI", "WithAdaptorAPI", "MaterialBindingAPI"]
)
{
...
string example:data = "this-was-exported"
string example:default_data = "this-will-be-kept-the-same"
...
}

def Skeleton "skeleton" (
prepend apiSchemas = ["WithoutAdaptorAPI", "WithAdaptorAPI", "SkelBindingAPI"]
)
{
...
string example:data = "this-was-exported"
string example:default_data = "this-will-be-kept-the-same"
...
}
```

Note the additional `WithoutAdaptorAPI` and `WithAdaptorAPI` as well as the corresponding data.

If executed properly, the adaptor should have printed more to the console as well:

```
# Importing '<...>\usd_data\sample_data.usda' #
CanAdaptForImport: arm
ApplySchemaForImport: arm
CopyFromPrim: mayaObject: arm | prim: arm | value: this-will-be-altered
CanAdaptForImport: skeleton
ApplySchemaForImport: skeleton
CopyFromPrim: mayaObject: skeleton | prim: skeleton | value: this-will-be-altered
# Opening layer '<...>/maya-usd-skeleton-issue-example/usd_data/exported_data.usda' for writing #
CanAdaptForExport: arm
CanAdaptForExport: arm
CopyToPrim: mayaObject: arm | prim: arm
CanAdaptForExport: skeleton
CopyToPrim: mayaObject: skeleton | prim: skeleton
# Saving stage #
```

Note the additonal `CopyToPrim` for the `skeleton` object.

**Specs (if applicable):**
- OS & version: Windows 10
- Maya version: Maya 2022
- Maya USD commit SHA: [0.19](https://github.com/Autodesk/maya-usd/releases/tag/v0.19.0) and [0.20](https://github.com/Autodesk/maya-usd/releases/tag/v0.20.0)

**Additional Context:**
See the [readme.md of the illustration repository](https://github.com/BeardedPlatypus/maya-usd-skeleton-issue-example/blob/main/README.md) for more details

I haven't had the chance yet to properly debug/step through the `maya-usd` code, but from reading the source code I gathered that the skeleton is created in the `meshWriter` after all `SchemaApiAdaptors` are already executed. It seemed to me that because there is no skeleton prim when executing the `SchemaApiAdaptors` the associated data is never copied at that point. When the skeleton is created, the `SchemaApiAdaptors` are not executed again, thus leading to the data loss.
However, given that I haven't actually debugged the code, I might be wrong in this analysis.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.