-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
172 lines (142 loc) · 3.3 KB
/
example.py
File metadata and controls
172 lines (142 loc) · 3.3 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import newton
import tetgen
import trimesh
import warp as wp
from newton import ModelBuilder
import newtonclips
newtonclips.SAVE_DIR = '.clips'
cfg = ModelBuilder.ShapeConfig(mu=1e3)
builder = ModelBuilder('Z')
builder.add_ground_plane(cfg=cfg)
builder.add_shape_plane(
body=-1,
plane=(0.1, 0.0, 1.0, 1.0),
width=5,
length=5,
cfg=cfg,
key='shape_plane',
)
builder.add_shape_box(
body=builder.add_body(),
xform=([0.0, 0.0, 4.5], [0.0, 0.0, 0.0, 1.0]),
hx=0.5,
hy=0.2,
hz=0.1,
cfg=cfg,
key='shape_box',
)
builder.add_shape_sphere(
body=builder.add_body(),
xform=([-1.0, 3.0, 2.0], [0.0, 0.0, 0.0, 1.0]),
radius=1.0,
cfg=cfg,
key='shape_sphere',
)
builder.add_shape_capsule(
body=builder.add_body(),
xform=([-1.0, -3.0, 2.0], [0.0, 0.0, 0.0, 1.0]),
radius=1.0,
half_height=0.5,
cfg=cfg,
key='shape_capsule',
)
mesh = trimesh.creation.torus(1.0, 0.5)
builder.add_shape_mesh(
body=builder.add_body(),
xform=([0, -3, 5], [0, 0, 0, 1]),
mesh=newton.Mesh(mesh.vertices, mesh.faces.flatten()),
cfg=cfg,
key='shape_mesh',
)
tet = tetgen.TetGen(mesh.vertices, mesh.faces)
vertices, indices = tet.tetrahedralize()
builder.add_soft_mesh(
pos=(0, 3, 5),
rot=(0.0, 0.0, 0.0, 1.0),
vel=(0.0, 0.0, 0.0),
scale=1.0,
vertices=vertices.tolist(),
indices=indices.flatten().tolist(),
density=1e2,
k_mu=5e4,
k_lambda=5e4,
k_damp=0.0,
# key='soft_mesh',
)
dim, cell = 15, 0.1
center_x = dim * cell * 0.5
center_y = dim * cell * 0.5
builder.add_cloth_grid(
pos=(-center_x + 1.0, -center_y - 0.5, 4),
dim_x=dim,
dim_y=dim,
cell_x=cell,
cell_y=cell,
mass=0.1,
fix_bottom=True,
rot=(0.0, 0.0, 0.0, 1.0),
vel=(0.0, 0.0, 0.0),
# key='cloth_grid',
)
dim, cell = 15, 0.1
center = dim * cell * 0.5
builder.add_soft_grid(
pos=wp.types.vec3(-center, -center, 2.0),
rot=wp.quat_identity(),
vel=wp.types.vec3(),
dim_x=dim,
dim_y=dim,
dim_z=dim,
cell_x=cell,
cell_y=cell,
cell_z=cell,
density=1e2,
k_mu=5e4,
k_lambda=5e4,
k_damp=0.0,
# key='soft_grid',
)
dim, cell = 10, 0.1
center = dim * cell * 0.5
builder.add_particle_grid(
pos=wp.types.vec3(-center, -center, 5.0),
rot=wp.quat_identity(),
vel=wp.types.vec3(),
dim_x=dim,
dim_y=dim,
dim_z=dim,
cell_x=cell,
cell_y=cell,
cell_z=cell,
mass=0.1,
jitter=0.1,
)
builder.color()
model = builder.finalize()
rigid_solver = newton.solvers.SolverSemiImplicit(model)
state_0 = model.state()
state_1 = model.state()
control = model.control()
import newton.viewer
renderer = newton.viewer.ViewerGL()
# renderer = newtonclips.ViewerUE()
renderer.set_model(model)
renderer.show_particles = True
fps = 60
frame_dt = 1.0 / fps
sim_substeps = 500
sim_dt = frame_dt / sim_substeps
sim_time = 0.0
for _ in range(num_frames := 500):
for _ in range(sim_substeps):
contacts = model.collide(state_0)
state_0.clear_forces()
state_1.clear_forces()
rigid_solver.step(state_0, state_1, control, contacts, sim_dt)
state_0, state_1 = state_1, state_0
sim_time += frame_dt
renderer.begin_frame(sim_time)
renderer.log_state(state_0)
renderer.end_frame()
# renderer.save()
# newtonclips.save_record(fps=fps)