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

Physics rigid body mass computation and tests #1677

Merged

Conversation

AlesBorovicka
Copy link

Description of Change(s)

Exposing UsdPhysicsCollisionAPI::GetCollisionPhysicsMaterialPrim that gathers material prim for the collision and added tests for it.
Exposing UsdPhysicsRigidBodyAPI::ComputeMassProperties that can compute mass properties for the rigid body and added tests for it.
Added massProperties.h that include basic mass computer.

@jilliene
Copy link

Filed as internal issue #USD-7017


PXR_NAMESPACE_OPEN_SCOPE

GfQuatf IndexedRotation(uint32_t axis, float s, float c)
Copy link
Member

Choose a reason for hiding this comment

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

@AlesBorovicka , since this is a public header, our coding conventions require that every public function, type, and class, be prefixed with the ProperCase module name, so UsdPhysicsIndexedRotation() etc. We do not allow module namespaces, but do allow a nesting class of static methods, if you prefer. So UsdPhysicsMass::IndexedRotation() etc, if that seems more appealing. Thanks!

Copy link
Member

@spiffmon spiffmon left a comment

Choose a reason for hiding this comment

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

I haven't checked out the test, but left a few things in the code itself to follow up on - thanks, @AlesBorovicka !


const float COMPARE_TOLERANCE = 1e-05f;

struct MassApiData
Copy link
Member

Choose a reason for hiding this comment

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

Conventions: non-public types prefixed with "_", e.g. _MassApiData

};

// gather all the mass information for the gien prim, based on UsdPhysicsMassAPI
MassApiData ParseMassApi(const UsdPrim& usdPrim)
Copy link
Member

Choose a reason for hiding this comment

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

Conventions: non-public functions prefixed with "_", e.g. _ParseMassApi

Comment on lines 338 to 339
// no sentinel value we need to check for authored value
if (comAttribute.HasAuthoredValue())
Copy link
Member

Choose a reason for hiding this comment

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

We must have overlooked these properties in our epic discussion about sentinels last year. To recap, predicating computation results on "isAuthored" state is fragile, because simple (common, and unwitting) "breakdown" scene mutations can then change the outcome of a computation. Can we give centerOfMass and any other needful schema properties workable sentinel fallbacks, and then compare to sentinel here rather than HasAuthoredValue?

}

// custom get center of mass, using also transformation to apply scaling
bool GetCoM(const UsdPrim& usdPrim, GfVec3f& com, UsdGeomXformCache& xfCache)
Copy link
Member

Choose a reason for hiding this comment

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

Another coding convention: mutable objects passed by pointer rather than reference so that it's easy to tell at calling sites what's boing to be mutated. Of all the conventions I've called out, this is the one that there's some internal contention about, but it is still enforced.

}

// compute mass properties for given rigid body
float UsdPhysicsRigidBodyAPI::ComputeMassProperties(GfVec3f& _diagonalInertia, GfVec3f& _com, GfQuatf& _principalAxes, const MassInformationFn& massInfoFn) const
Copy link
Member

Choose a reason for hiding this comment

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

80 columns, please?

const UsdPrim collisionPrim = *it;
if (collisionPrim && collisionPrim.HasAPI<UsdPhysicsCollisionAPI>())
{
collisionPrims.push_back(collisionPrim);
Copy link
Member

Choose a reason for hiding this comment

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

If you remove the const above, which isn't buying you much, then you can std::move(collisionPrim) here, which does buy you several refcount increments.

Comment on lines 533 to 548
if (!hasMaterials)
{
std::vector<UsdShadeMaterial> generalMaterials = UsdShadeMaterialBindingAPI::ComputeBoundMaterials(collisionPrims);
for (size_t i = 0; i < physicsMaterials.size(); i++)
{
if (!physicsMaterials[i])
{
const UsdShadeMaterial& generalMaterial = generalMaterials[i];
if (generalMaterial && generalMaterial.GetPrim().HasAPI<UsdPhysicsMaterialAPI>())
{
physicsMaterials[i] = generalMaterial;
}
}
}

}
Copy link
Member

Choose a reason for hiding this comment

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

Ok, weird. I added a comment in what must have been a forked branch version of this code that you don't need this second pass, here.

@pixar-oss pixar-oss merged commit 69779ff into PixarAnimationStudios:dev Dec 18, 2021
@AlesBorovicka AlesBorovicka deleted the physics-mass-tests branch February 24, 2022 08:43
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.

4 participants