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

[usdPhysics] Fix python bindings for metrics and kilogramsPerUnit metadata registration. #1606

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pxr/usd/usdGeom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ pxr_register_test(testUsdGeomMesh
EXPECTED_RETURN_CODE 0
)

pxr_register_test(testUsdGeomMetrics
PYTHON
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdGeomMetrics"
EXPECTED_RETURN_CODE 0
)


pxr_register_test(testUsdGeomSubset
PYTHON
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdGeomSubset"
Expand Down
11 changes: 11 additions & 0 deletions pxr/usd/usdPhysics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,14 @@ pxr_library(usdPhysics
examples/usdPhysicsSpheresWithMaterial.usda
)

pxr_test_scripts(
testenv/testUsdPhysicsMetrics.py
)


pxr_register_test(testUsdPhysicsMetrics
PYTHON
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdPhysicsMetrics"
EXPECTED_RETURN_CODE 0
)

2 changes: 2 additions & 0 deletions pxr/usd/usdPhysics/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ TF_WRAP_MODULE
TF_WRAP(UsdPhysicsMaterialAPI);
TF_WRAP(UsdPhysicsScene);

TF_WRAP(Metrics);

// Mass
TF_WRAP(UsdPhysicsMassAPI);

Expand Down
10 changes: 10 additions & 0 deletions pxr/usd/usdPhysics/plugInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
"Plugins": [
{
"Info": {
"SdfMetadata": {
"kilogramsPerUnit": {
"appliesTo": [
"layers"
],
"default": 1.0,
"displayGroup": "Stage",
"type": "double"
}
},
"Types": {
"UsdPhysicsArticulationRootAPI": {
"alias": {
Expand Down
46 changes: 46 additions & 0 deletions pxr/usd/usdPhysics/testenv/testUsdPhysicsMetrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/pxrpythonsubst
#
# Copyright 2021 Pixar
#
# Licensed under the Apache License, Version 2.0 (the "Apache License")
# with the following modification; you may not use this file except in
# compliance with the Apache License and the following modification to it:
# Section 6. Trademarks. is deleted and replaced with:
#
# 6. Trademarks. This License does not grant permission to use the trade
# names, trademarks, service marks, or product names of the Licensor
# and its affiliates, except as required to comply with Section 4(c) of
# the License and to reproduce the content of the NOTICE file.
#
# You may obtain a copy of the Apache License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.

import sys, os, unittest
from pxr import Tf, Usd, UsdPhysics

class TestUsdPhysicsMetrics(unittest.TestCase):

def test_kilogramsPerUnit(self):
stage = Usd.Stage.CreateInMemory()
self.assertTrue(stage)

self.assertEqual(UsdPhysics.GetStageKilogramsPerUnit(stage),
UsdPhysics.MassUnits.kilograms)
self.assertFalse(UsdPhysics.StageHasAuthoredKilogramsPerUnit(stage))

self.assertTrue(UsdPhysics.SetStageKilogramsPerUnit(stage,
UsdPhysics.MassUnits.grams))
self.assertTrue(UsdPhysics.StageHasAuthoredKilogramsPerUnit(stage))
authored = UsdPhysics.GetStageKilogramsPerUnit(stage)
self.assertTrue(UsdPhysics.MassUnitsAre(authored, UsdPhysics.MassUnits.grams))


if __name__ == "__main__":
unittest.main()