-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: add validator SkelBindingAPIAppliedChecker #3166
Conversation
- 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
Filed as internal issue #USD-9849 |
/AzurePipelines run |
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"); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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>, " \ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
pxr/usd/usdSkel/validators.cpp
Outdated
|
||
for (const TfToken &primToken : primPropertyNames){ | ||
for (const TfToken &skelToken : skelPropertyNames){ | ||
if (skelToken == primToken){ |
There was a problem hiding this comment.
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.
pxr/usd/usdSkel/validators.cpp
Outdated
else { | ||
if (usdPrim.GetTypeName() != UsdSkelTokens->SkelRoot) { | ||
UsdPrim parentPrim = usdPrim.GetParent(); | ||
while (!parentPrim.IsPseudoRoot()) { |
There was a problem hiding this comment.
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())
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
Made the suggested changes. Thanks so much for the review & ideas. |
Just curious why is this a draft PR? |
There was a problem hiding this 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.
- 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
pxr/usd/usdSkel/validators.cpp
Outdated
UsdValidationErrorVector errors; | ||
|
||
if (!usdPrim.HasAPI<UsdSkelBindingAPI>()){ | ||
std::vector<TfToken> primPropertyNames = usdPrim.GetPropertyNames(); |
There was a problem hiding this comment.
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
.
pxr/usd/usdSkel/validators.cpp
Outdated
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")}); |
There was a problem hiding this comment.
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
pxr/usd/usdSkel/validators.cpp
Outdated
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this 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.
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
Description of Change(s)
add validator SkelBindingAPIAppliedChecker
Fixes Issue(s)