Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add validator SkelBindingAPIAppliedChecker #3166

Merged

Conversation

beersandrew
Copy link
Contributor

Description of Change(s)

add validator SkelBindingAPIAppliedChecker

  • added a validation check for when a skel binding property is present but the skel binding api is not applied
  • added a validation check for when a skel binding api is applied to a prim that is not parented by a skel root
  • added a unit test

Fixes Issue(s)

  • I have verified that all unit tests pass with the proposed changes
  • I have submitted a signed Contributor License Agreement

- added a validation check for when a skel binding property is present but the skel binding api is not applied
- added a validation check for when a skel binding api is applied to a prim that is not parented by a skel root
- added a unit test
@jesschimein
Copy link
Contributor

Filed as internal issue #USD-9849

@jesschimein
Copy link
Contributor

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

TF_AXIOM(validator);

// Create Stage and mesh with a skel binding property
UsdStageRefPtr usdStage = UsdStage::CreateNew("/Users/andrewbeers/test.usda");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'm sure you'll remove it but good to just write it to a temp test location instead before it's merged in, and/or just keep it in memory if you don't need to write it out.


UsdValidationErrorVector errors = validator->Validate(mesh.GetPrim());

// test and verify error for not having a skel binding api applied
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smallest of nitpicks: Comment style should be sentence case just to match the rest of the comments.

TF_AXIOM(errors[0].GetSites()[0].IsPrim());
TF_AXIOM(errors[0].GetSites()[0].GetPrim().GetPath() ==
SdfPath("/SkelRoot/Mesh"));
expectedErrorMsg = "UsdSkelBindingAPI applied on prim: </SkelRoot/Mesh>, " \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: You can put the string inside parenthesis and avoid escaping the line break. It's a little cleaner and less fragile if someone forgets in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't know about this! thanks!


for (const TfToken &primToken : primPropertyNames){
for (const TfToken &skelToken : skelPropertyNames){
if (skelToken == primToken){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: If you invert this comparison + use a continue, you can unnest the contents of the check. Ever so slightly improves readability.

else {
if (usdPrim.GetTypeName() != UsdSkelTokens->SkelRoot) {
UsdPrim parentPrim = usdPrim.GetParent();
while (!parentPrim.IsPseudoRoot()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should also check if the parentPrim isn't null, just in case you get a bad prim here.
while (parentPrim && !parentPrim.IsPseudoRoot())

@dgovil
Copy link
Collaborator

dgovil commented Jul 16, 2024

LGTM! other than a couple small notes, most of which are just minor style ones.

- update comments to be in sentence form
- remove local path, update to an in memory stage
- remove \ from multi-line strings and wrap them in parenthesis instead
- reduce nesting in validation code
- check parentPrim for null before checking it's type
@beersandrew
Copy link
Contributor Author

LGTM! other than a couple small notes, most of which are just minor style ones.

Made the suggested changes. Thanks so much for the review & ideas.

@beersandrew beersandrew requested a review from dgovil July 16, 2024 21:22
@tallytalwar
Copy link
Contributor

Just curious why is this a draft PR?

Copy link
Contributor

@tallytalwar tallytalwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @beersandrew

Thanks for doing this. Left a few suggestions for you to consider. Let me know if you want to talk through any of these or more here or on slack.

pxr/usd/usdSkel/CMakeLists.txt Outdated Show resolved Hide resolved
pxr/usd/usdSkel/CMakeLists.txt Outdated Show resolved Hide resolved
pxr/usd/usdSkel/testenv/testUsdSkelValidators.cpp Outdated Show resolved Hide resolved
pxr/usd/usdSkel/validators.cpp Outdated Show resolved Hide resolved
pxr/usd/usdSkel/validators.cpp Outdated Show resolved Hide resolved
pxr/usd/usdSkel/validators.cpp Outdated Show resolved Hide resolved
pxr/usd/usdSkel/testenv/testUsdSkelValidators.cpp Outdated Show resolved Hide resolved
pxr/usd/usdSkel/validators.cpp Outdated Show resolved Hide resolved
pxr/usd/usdSkel/plugInfo.json Outdated Show resolved Hide resolved
- reenabled testUsdSkelRoot, accidentally removed in a previous commit
- removed sdr dependency from skel test
- removed unused headers
- added TestUsdSkelValidators test to verify validator existence
- removed SkelBindingApiChecker name from error messages
- refactored how skelPropertyNames are collected, stored, and checked against
- no need to catch multiple errors here
@beersandrew beersandrew marked this pull request as ready for review July 17, 2024 18:14
UsdValidationErrorVector errors;

if (!usdPrim.HasAPI<UsdSkelBindingAPI>()){
std::vector<TfToken> primPropertyNames = usdPrim.GetPropertyNames();
Copy link
Contributor

@tallytalwar tallytalwar Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Its a good practice to declare variables just before use. So I would move primPropertyNames below skelPropertyNames.

Also you can make this a const vector.

std::vector<TfToken> primPropertyNames = usdPrim.GetPropertyNames();
static const std::unordered_set<TfToken, TfHash> skelPropertyNames = []() {
UsdSchemaRegistry& usdSchemaRegistry = UsdSchemaRegistry::GetInstance();
std::unique_ptr<UsdPrimDefinition> primDef = usdSchemaRegistry.BuildComposedPrimDefinition(TfToken(), {TfToken("SkelBindingAPI")});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh apologies, I should have noticed this before, you can use UsdSkelTokens->SkelBindingAPI, instead of TfToken("SkelBindingAPI"). Such tokens are often generated along with the schema.

https://github.com/PixarAnimationStudios/OpenUSD/blob/release/pxr/usd/usdSkel/tokens.cpp#L55

static const std::unordered_set<TfToken, TfHash> skelPropertyNames = []() {
UsdSchemaRegistry& usdSchemaRegistry = UsdSchemaRegistry::GetInstance();
std::unique_ptr<UsdPrimDefinition> primDef = usdSchemaRegistry.BuildComposedPrimDefinition(TfToken(), {TfToken("SkelBindingAPI")});
std::vector<TfToken> vectorOfNames = primDef->GetPropertyNames();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const vector

- switched from using TfToken("SkelBindingAPI") to UsdSkelTokens->SkelBindingAPI
- use const vectors where possible
- refactoring / reordering of code for clarity
Copy link
Contributor

@tallytalwar tallytalwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a bunch @beersandrew. Will sync this in.

@jesschimein
Copy link
Contributor

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pixar-oss pixar-oss merged commit 7eb18f5 into PixarAnimationStudios:dev Aug 6, 2024
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants