From dbf7afaeaa42141ce00c94fba762a0fa8a0d71fd Mon Sep 17 00:00:00 2001 From: Matthew Bennice Date: Fri, 16 Feb 2024 14:55:27 -0800 Subject: [PATCH] Canonical USD example for MuJoCo Physics. This contains three items: floor - a static floor centered at origin of sides 100m x 100m two_cubes - a standard example where 2 cubes have a hinge joint between them. two_cubes_scene - a scene made up of the floor at (0, 0, 0) and two_cubes at (0, 0, 30). PiperOrigin-RevId: 607809323 Change-Id: I9931d89441653ce7aaf5145ee42c71c0c8f9ffcb --- test/usd/testdata/floor/Floor.usda | 19 +++++++++ test/usd/testdata/floor/Floor_geo.usda | 16 ++++++++ test/usd/testdata/floor/Floor_physics.usda | 20 ++++++++++ test/usd/testdata/two_cubes/FirstCube.usda | 27 +++++++++++++ .../usd/testdata/two_cubes/FirstCube_geo.usda | 16 ++++++++ .../testdata/two_cubes/FirstCube_physics.usda | 23 +++++++++++ test/usd/testdata/two_cubes/SecondCube.usda | 26 ++++++++++++ .../testdata/two_cubes/SecondCube_geo.usda | 16 ++++++++ .../two_cubes/SecondCube_physics.usda | 23 +++++++++++ test/usd/testdata/two_cubes/TwoCubes.usda | 40 +++++++++++++++++++ .../testdata/two_cubes/TwoCubes_physics.usda | 34 ++++++++++++++++ .../two_cubes_scene/TwoCubes_scene.usda | 28 +++++++++++++ 12 files changed, 288 insertions(+) create mode 100644 test/usd/testdata/floor/Floor.usda create mode 100644 test/usd/testdata/floor/Floor_geo.usda create mode 100644 test/usd/testdata/floor/Floor_physics.usda create mode 100644 test/usd/testdata/two_cubes/FirstCube.usda create mode 100644 test/usd/testdata/two_cubes/FirstCube_geo.usda create mode 100644 test/usd/testdata/two_cubes/FirstCube_physics.usda create mode 100644 test/usd/testdata/two_cubes/SecondCube.usda create mode 100644 test/usd/testdata/two_cubes/SecondCube_geo.usda create mode 100644 test/usd/testdata/two_cubes/SecondCube_physics.usda create mode 100644 test/usd/testdata/two_cubes/TwoCubes.usda create mode 100644 test/usd/testdata/two_cubes/TwoCubes_physics.usda create mode 100644 test/usd/testdata/two_cubes_scene/TwoCubes_scene.usda diff --git a/test/usd/testdata/floor/Floor.usda b/test/usd/testdata/floor/Floor.usda new file mode 100644 index 00000000..b3547295 --- /dev/null +++ b/test/usd/testdata/floor/Floor.usda @@ -0,0 +1,19 @@ +#usda 1.0 +( + defaultPrim = "root" + upAxis = "Z" +) + +def Xform "root" () { + def "floor_geo" ( + prepend references = [@./Floor_geo.usda@] + ) + { + + } + def "floor_collision" ( + prepend references = [@./Floor_physics.usda@] + ) + { + } +} diff --git a/test/usd/testdata/floor/Floor_geo.usda b/test/usd/testdata/floor/Floor_geo.usda new file mode 100644 index 00000000..e674eb27 --- /dev/null +++ b/test/usd/testdata/floor/Floor_geo.usda @@ -0,0 +1,16 @@ +#usda 1.0 +( + defaultPrim = "root" + metersPerUnit = 1.0 + upAxis = "Z" +) + +def Cube "root" () +{ + color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] + double size = 100 + quatf xformOp:orient = (1, 0, 0, 0) + float3 xformOp:scale = (1, 1, 0.01) + double3 xformOp:translate = (0, 0, -0.5) + uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"] +} diff --git a/test/usd/testdata/floor/Floor_physics.usda b/test/usd/testdata/floor/Floor_physics.usda new file mode 100644 index 00000000..be6934e9 --- /dev/null +++ b/test/usd/testdata/floor/Floor_physics.usda @@ -0,0 +1,20 @@ +#usda 1.0 +( + defaultPrim = "root" + metersPerUnit = 1.0 + upAxis = "Z" +) + +def Cube "root" ( + prepend apiSchemas = ["PhysicsCollisionAPI"] +) +{ + double size = 100 + bool physics:collisionEnabled = 1 + double size = 1.0 + quatf xformOp:orient = (1, 0, 0, 0) + float3 xformOp:scale = (1, 1, 0.01) + double3 xformOp:translate = (0, 0, -0.5) + uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"] + token visibility = "invisible" +} diff --git a/test/usd/testdata/two_cubes/FirstCube.usda b/test/usd/testdata/two_cubes/FirstCube.usda new file mode 100644 index 00000000..238d4b09 --- /dev/null +++ b/test/usd/testdata/two_cubes/FirstCube.usda @@ -0,0 +1,27 @@ +#usda 1.0 +( + defaultPrim = "root" + upAxis = "Z" +) + +def Xform "root"( + assetInfo = { + asset identifier = @./FirstCube.usda@ + string name = "FirstCube" + } + kind = "component" + prepend apiSchemas = ["PhysicsRigidBodyAPI"] +) +{ + def "FirstCube_geometry" ( + prepend references = [@./FirstCube_geo.usda@] + ) + { + } + def "FirstCube_collision" ( + prepend references = [@./FirstCube_physics.usda@] + ) + { + } +} + diff --git a/test/usd/testdata/two_cubes/FirstCube_geo.usda b/test/usd/testdata/two_cubes/FirstCube_geo.usda new file mode 100644 index 00000000..2a661bb7 --- /dev/null +++ b/test/usd/testdata/two_cubes/FirstCube_geo.usda @@ -0,0 +1,16 @@ +#usda 1.0 +( + defaultPrim = "root" + metersPerUnit = 1.0 + upAxis = "Z" +) + +def Cube "root" () +{ + color3f[] primvars:displayColor = [(1.0, 0, 0)] + double size = 1.0 + quatf xformOp:orient = (1, 0, 0, 0) + float3 xformOp:scale = (1.0, 1.0, 1.0) + double3 xformOp:translate = (0, 0, 0) + uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"] +} diff --git a/test/usd/testdata/two_cubes/FirstCube_physics.usda b/test/usd/testdata/two_cubes/FirstCube_physics.usda new file mode 100644 index 00000000..1f046226 --- /dev/null +++ b/test/usd/testdata/two_cubes/FirstCube_physics.usda @@ -0,0 +1,23 @@ +#usda 1.0 +( + defaultPrim = "root" + metersPerUnit = 1.0 + upAxis = "Z" + kilogramsPerUnit = 1.0 +) + +def Cube "root" ( + prepend apiSchemas = ["PhysicsCollisionAPI", "PhysicsMassAPI"] +) +{ + color3f[] primvars:displayColor = [(1.0, 1.0, 0)] + float physics:mass = 1 + bool physics:collisionEnabled = 1 + double size = 1.0 + quatf xformOp:orient = (1, 0, 0, 0) + float3 xformOp:scale = (1.0, 1.0, 1.0) + double3 xformOp:translate = (0, 0, 0) + uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"] + token visibility = "invisible" +} + diff --git a/test/usd/testdata/two_cubes/SecondCube.usda b/test/usd/testdata/two_cubes/SecondCube.usda new file mode 100644 index 00000000..cdc0f60c --- /dev/null +++ b/test/usd/testdata/two_cubes/SecondCube.usda @@ -0,0 +1,26 @@ +#usda 1.0 +( + defaultPrim = "root" + upAxis = "Z" +) + +def Xform "root"( + assetInfo = { + asset identifier = @./SecondCube.usda@ + string name = "SecondCube" + } + kind = "component" +) +{ + def "SecondCube_geometry" ( + prepend references = [@./SecondCube_geo.usda@] + ) + { + } + def "SecondCube_collision" ( + prepend references = [@./SecondCube_physics.usda@] + ) + { + } +} + diff --git a/test/usd/testdata/two_cubes/SecondCube_geo.usda b/test/usd/testdata/two_cubes/SecondCube_geo.usda new file mode 100644 index 00000000..897fd1ca --- /dev/null +++ b/test/usd/testdata/two_cubes/SecondCube_geo.usda @@ -0,0 +1,16 @@ +#usda 1.0 +( + defaultPrim = "root" + metersPerUnit = 1.0 + upAxis = "Z" +) + +def Cube "root" () +{ + color3f[] primvars:displayColor = [(0, 0, 1)] + double size = 1.0 + quatf xformOp:orient = (1, 0, 0, 0) + float3 xformOp:scale = (1.0, 1.0, 1.0) + double3 xformOp:translate = (0.0, 0, 0) + uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"] +} diff --git a/test/usd/testdata/two_cubes/SecondCube_physics.usda b/test/usd/testdata/two_cubes/SecondCube_physics.usda new file mode 100644 index 00000000..e2b1808c --- /dev/null +++ b/test/usd/testdata/two_cubes/SecondCube_physics.usda @@ -0,0 +1,23 @@ +#usda 1.0 +( + defaultPrim = "root" + metersPerUnit = 1.0 + upAxis = "Z" + kilogramsPerUnit = 1.0 +) + +def Cube "root" ( + prepend apiSchemas = ["PhysicsCollisionAPI", "PhysicsMassAPI"] +) +{ + color3f[] primvars:displayColor = [(0, 1, 1)] + float physics:mass = 1 + bool physics:collisionEnabled = 1 + double size = 1.0 + quatf xformOp:orient = (1, 0, 0, 0) + float3 xformOp:scale = (1.0, 1.0, 1.0) + double3 xformOp:translate = (0.0, 0, 0) + uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"] + token visibility = "invisible" +} + diff --git a/test/usd/testdata/two_cubes/TwoCubes.usda b/test/usd/testdata/two_cubes/TwoCubes.usda new file mode 100644 index 00000000..ae0deb46 --- /dev/null +++ b/test/usd/testdata/two_cubes/TwoCubes.usda @@ -0,0 +1,40 @@ +#usda 1.0 +# Two Cubes linked together with a single hinge joint at the top of the two +# cubes. +# USD Quaternions are WXYZ +# X=Right, Y=Forward, Z=Up +( + defaultPrim = "root" + upAxis = "Z" + metersPerUnit = 1.0 + kilogramsPerUnit = 1.0 + subLayers = [ + @./TwoCubes_physics.usda@, + ] +) + +def Xform "root"( + assetInfo = { + asset identifier = @./TwoCubes.usda@ + string name = "TwoCubes" + } + kind = "component" +) +{ + def "first_cube" ( + prepend references = [@./FirstCube.usda@] + ) + { + } + + def "second_cube" ( + prepend references = [@./SecondCube.usda@] + ) + { + quatf xformOp:orient = (1, 0, 0, 0) + float3 xformOp:scale = (1.0, 1.0, 1.0) + double3 xformOp:translate = (1.0, 0, 0) + uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"] + } +} + diff --git a/test/usd/testdata/two_cubes/TwoCubes_physics.usda b/test/usd/testdata/two_cubes/TwoCubes_physics.usda new file mode 100644 index 00000000..389c1fb6 --- /dev/null +++ b/test/usd/testdata/two_cubes/TwoCubes_physics.usda @@ -0,0 +1,34 @@ +#usda 1.0 +( + defaultPrim = "root" + upAxis = "Z" + metersPerUnit = 1.0 +) +over "root" { + def Scope "Joints" + { + def PhysicsJoint "two_cubes_joint" ( + prepend apiSchemas = ["PhysicsLimitAPI", "PhysicsLimitAPI:transY", "PhysicsLimitAPI:transZ", "PhysicsLimitAPI:rotX", "PhysicsLimitAPI:rotY", "PhysicsDriveAPI:rotZ"] + ) + { + rel physics:body0 = + rel physics:body1 = + float limit:rotX:physics:high = 0 + float limit:rotX:physics:low = 0 + float limit:rotY:physics:high = 0 + float limit:rotY:physics:low = -2 + float limit:rotZ:physics:high = 0 + float limit:rotZ:physics:low = 0 + float limit:transX:physics:high = 0 + float limit:transX:physics:low = 0 + float limit:transY:physics:high = 0 + float limit:transY:physics:low = 0 + float limit:transZ:physics:high = 0 + float limit:transZ:physics:low = 0 + point3f physics:localPos0 = (0, 1.0, 0) + point3f physics:localPos1 = (-0.5, 0, 0.5) + quatf physics:localRot0 = (1, 0, 0, 0) + quatf physics:localRot1 = (1, 0, 0, 0) + } + } +} diff --git a/test/usd/testdata/two_cubes_scene/TwoCubes_scene.usda b/test/usd/testdata/two_cubes_scene/TwoCubes_scene.usda new file mode 100644 index 00000000..e11a22e7 --- /dev/null +++ b/test/usd/testdata/two_cubes_scene/TwoCubes_scene.usda @@ -0,0 +1,28 @@ +#usda 1.0 +( + defaultPrim = "root" + metersPerUnit = 1.0 + upAxis = "Z" + kilogramsPerUnit = 1.0 +) + +def Xform "root"( + kind = "assembly" +) +{ + def "Floor" ( + prepend references = [@../floor/Floor.usda@] + ) + { + } + + def "TwoCubes" ( + prepend references = [@../two_cubes/TwoCubes.usda@] + ) + { + double3 xformOp:translate = (0, 0, 30.0) + quatf xformOp:orient = (1, 0, 0, 0) + float3 xformOp:scale = (1.0, 1.0, 1.0) + uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"] + } +}