-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsimpleJoint02.py
More file actions
155 lines (118 loc) · 4.81 KB
/
simpleJoint02.py
File metadata and controls
155 lines (118 loc) · 4.81 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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))
# --------------------------------------------.
# cube2.
# --------------------------------------------.
cube2Path = rootPath + '/cube2'
cube2Geom = UsdGeom.Cube.Define(stage, cube2Path)
# Set cube size.
cube2Geom.CreateSizeAttr(10.0)
# Set color.
cube2Geom.CreateDisplayColorAttr([(0.0, 1.0, 1.0)])
# Set position.
UsdGeom.XformCommonAPI(cube2Geom).SetTranslate((42.0, hPos, 0.0))
# Set scale.
UsdGeom.XformCommonAPI(cube2Geom).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)
# cube2 : dynamic body
cube2Prim = stage.GetPrimAtPath(cube2Path)
UsdPhysics.CollisionAPI.Apply(cube2Prim)
UsdPhysics.RigidBodyAPI.Apply(cube2Prim)
# ----------------------------------------.
# 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(-50.0)
revoluteJoint.CreateUpperLimitAttr(50.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(100.0)
angularDriveAPI.CreateTargetVelocityAttr(1.0)
angularDriveAPI.CreateDampingAttr(100.0)
angularDriveAPI.CreateStiffnessAttr(0.0)
# ----------------------------------------.
# Setup joint2.
# ----------------------------------------.
jointPath2 = rootPath + '/revoluteJoint2'
revoluteJoint2 = UsdPhysics.RevoluteJoint.Define(stage, jointPath2)
# define revolute joint axis and its limits, defined in degrees
revoluteJoint2.CreateAxisAttr("Z")
revoluteJoint2.CreateLowerLimitAttr(-50.0)
revoluteJoint2.CreateUpperLimitAttr(50.0)
# define revolute joint bodies
revoluteJoint2.CreateBody0Rel().SetTargets([cube1Path])
revoluteJoint2.CreateBody1Rel().SetTargets([cube2Path])
# define revolute joint local poses for bodies
revoluteJoint2.CreateLocalPos0Attr().Set(Gf.Vec3f(5.25, 0.0, 0.0))
revoluteJoint2.CreateLocalRot0Attr().Set(Gf.Quatf(1.0))
revoluteJoint2.CreateLocalPos1Attr().Set(Gf.Vec3f(-5.25, 0.0, 0.0))
revoluteJoint2.CreateLocalRot1Attr().Set(Gf.Quatf(1.0))
# set break force/torque
revoluteJoint2.CreateBreakForceAttr().Set(1e20)
revoluteJoint2.CreateBreakTorqueAttr().Set(1e20)
# optionally add angular drive for example
#angularDriveAPI2 = UsdPhysics.DriveAPI.Apply(stage.GetPrimAtPath(jointPath2), "angular")
#angularDriveAPI2.CreateTypeAttr("force")
#angularDriveAPI2.CreateMaxForceAttr(100.0)
#angularDriveAPI2.CreateTargetVelocityAttr(1.0)
#angularDriveAPI2.CreateDampingAttr(100.0)
#angularDriveAPI2.CreateStiffnessAttr(0.0)