-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsimpleJoint01.py
More file actions
96 lines (72 loc) · 2.84 KB
/
simpleJoint01.py
File metadata and controls
96 lines (72 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from pxr import Usd, UsdGeom, UsdPhysics, UsdShade, Sdf, Gf, Tf
# Get stage.
stage = omni.usd.get_context().get_stage()
# Y-Up.
UsdGeom.SetStageUpAxis(stage, UsdGeom.Tokens.y)
rootPath = '/World'
# Physics scene definition.
scene = UsdPhysics.Scene.Define(stage, rootPath + '/physicsScene')
scene.CreateGravityDirectionAttr().Set(Gf.Vec3f(0.0, -1.0, 0.0))
scene.CreateGravityMagnitudeAttr().Set(981.0)
hPos = 15.0
# --------------------------------------------.
# cube0.
# --------------------------------------------.
cube0Path = rootPath + '/cube0'
cube0Geom = UsdGeom.Cube.Define(stage, cube0Path)
# Set cube size.
cube0Geom.CreateSizeAttr(10.0)
# Set color.
cube0Geom.CreateDisplayColorAttr([(0.0, 1.0, 0.0)])
# Set position.
UsdGeom.XformCommonAPI(cube0Geom).SetTranslate((0.0, hPos, 0.0))
# Set scale.
UsdGeom.XformCommonAPI(cube0Geom).SetScale((2.0, 0.5, 0.5))
# --------------------------------------------.
# cube1.
# --------------------------------------------.
cube1Path = rootPath + '/cube1'
cube1Geom = UsdGeom.Cube.Define(stage, cube1Path)
# Set cube size.
cube1Geom.CreateSizeAttr(10.0)
# Set color.
cube1Geom.CreateDisplayColorAttr([(0.0, 0.0, 1.0)])
# Set position.
UsdGeom.XformCommonAPI(cube1Geom).SetTranslate((21.0, hPos, 0.0))
# Set scale.
UsdGeom.XformCommonAPI(cube1Geom).SetScale((2.0, 0.5, 0.5))
# --------------------------------------------.
# Physics settings.
# --------------------------------------------.
# cube0 : static body
cube0Prim = stage.GetPrimAtPath(cube0Path)
UsdPhysics.CollisionAPI.Apply(cube0Prim)
# cube1 : dynamic body
cube1Prim = stage.GetPrimAtPath(cube1Path)
UsdPhysics.CollisionAPI.Apply(cube1Prim)
UsdPhysics.RigidBodyAPI.Apply(cube1Prim)
# Setup joint.
jointPath = rootPath + '/revoluteJoint'
revoluteJoint = UsdPhysics.RevoluteJoint.Define(stage, jointPath)
# define revolute joint axis and its limits, defined in degrees
revoluteJoint.CreateAxisAttr("Z")
revoluteJoint.CreateLowerLimitAttr(-90.0)
revoluteJoint.CreateUpperLimitAttr(90.0)
# define revolute joint bodies
revoluteJoint.CreateBody0Rel().SetTargets([cube0Path])
revoluteJoint.CreateBody1Rel().SetTargets([cube1Path])
# define revolute joint local poses for bodies
revoluteJoint.CreateLocalPos0Attr().Set(Gf.Vec3f(5.25, 0.0, 0.0))
revoluteJoint.CreateLocalRot0Attr().Set(Gf.Quatf(1.0))
revoluteJoint.CreateLocalPos1Attr().Set(Gf.Vec3f(-5.25, 0.0, 0.0))
revoluteJoint.CreateLocalRot1Attr().Set(Gf.Quatf(1.0))
# set break force/torque
revoluteJoint.CreateBreakForceAttr().Set(1e20)
revoluteJoint.CreateBreakTorqueAttr().Set(1e20)
# optionally add angular drive for example
angularDriveAPI = UsdPhysics.DriveAPI.Apply(stage.GetPrimAtPath(jointPath), "angular")
angularDriveAPI.CreateTypeAttr("force")
angularDriveAPI.CreateMaxForceAttr(1e20)
angularDriveAPI.CreateTargetVelocityAttr(1.0)
angularDriveAPI.CreateDampingAttr(1e10)
angularDriveAPI.CreateStiffnessAttr(0.0)