@@ -29,13 +29,22 @@ def test_maxvolume(pbd_material, show_viewer, box_obj_path):
2929
3030 # Mesh without any maximum-element-volume constraint
3131 pbd1 = scene .add_entity (
32- morph = gs .morphs .Mesh (file = box_obj_path , nobisect = False , verbose = 1 ),
32+ morph = gs .morphs .Mesh (
33+ file = box_obj_path ,
34+ nobisect = False ,
35+ verbose = 1 ,
36+ ),
3337 material = pbd_material ,
3438 )
3539
3640 # Mesh with maximum element volume limited to 0.001
3741 pbd2 = scene .add_entity (
38- morph = gs .morphs .Mesh (file = box_obj_path , nobisect = False , maxvolume = 0.001 , verbose = 1 ),
42+ morph = gs .morphs .Mesh (
43+ file = box_obj_path ,
44+ nobisect = False ,
45+ maxvolume = 0.001 ,
46+ verbose = 1 ,
47+ ),
3948 material = pbd_material ,
4049 )
4150
@@ -154,18 +163,37 @@ def test_cloth_attach_rigid_link(show_viewer):
154163 box_height = 2.25
155164
156165 scene = gs .Scene (
157- sim_options = gs .options .SimOptions (dt = 2e-2 , substeps = 10 , gravity = (0.0 , 0.0 , 0.0 )),
158- pbd_options = gs .options .PBDOptions (particle_size = particle_size ),
166+ sim_options = gs .options .SimOptions (
167+ dt = 2e-2 ,
168+ substeps = 10 ,
169+ gravity = (0.0 , 0.0 , 0.0 ),
170+ ),
171+ pbd_options = gs .options .PBDOptions (
172+ particle_size = particle_size ,
173+ ),
174+ viewer_options = gs .options .ViewerOptions (
175+ camera_pos = (2.5 , 2.0 , 4.0 ),
176+ camera_lookat = (- 1.0 , - 1.0 , 1.0 ),
177+ ),
159178 show_viewer = show_viewer ,
160179 )
161- scene .add_entity (gs .morphs .Plane (), gs .materials .Rigid (needs_coup = True , coup_friction = 0.0 ))
180+ scene .add_entity (
181+ gs .morphs .Plane (),
182+ material = gs .materials .Rigid (
183+ needs_coup = True ,
184+ coup_friction = 0.0 ,
185+ ),
186+ )
162187
163188 box = scene .add_entity (
164189 morph = gs .morphs .Box (
165190 pos = (0.25 , 0.25 , box_height ),
166191 size = (0.25 , 0.25 , 0.25 ),
167192 ),
168- material = gs .materials .Rigid (needs_coup = True , coup_friction = 0.0 ),
193+ material = gs .materials .Rigid (
194+ needs_coup = True ,
195+ coup_friction = 0.0 ,
196+ ),
169197 )
170198 cloth = scene .add_entity (
171199 morph = gs .morphs .Mesh (
@@ -174,9 +202,10 @@ def test_cloth_attach_rigid_link(show_viewer):
174202 scale = 0.5 ,
175203 ),
176204 material = gs .materials .PBD .Cloth (),
177- surface = gs .surfaces .Default (color = (0.2 , 0.4 , 0.8 , 1.0 )),
205+ surface = gs .surfaces .Default (
206+ color = (0.2 , 0.4 , 0.8 , 1.0 ),
207+ ),
178208 )
179-
180209 scene .build (n_envs = 2 )
181210
182211 particles_idx = [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ]
@@ -190,38 +219,28 @@ def test_cloth_attach_rigid_link(show_viewer):
190219 cloth_pos0 = cloth .get_particles_pos ()[:, particles_idx ].clone ()
191220 link_pos0 = scene .rigid_solver .links [box_link_idx ].get_pos ().clone ()
192221
193- for _ in range (25 ):
222+ for _ in range (20 ):
194223 scene .step ()
195224
196225 # wait for the box to stop
197226 box .set_dofs_velocity (np .zeros_like (vel ), dofs_idx_local = [0 , 1 , 2 ])
198- for _ in range (5 ):
227+ for _ in range (10 ):
199228 scene .step ()
200229
201230 # Check that the attached particles followed the link displacement per env
202231 cloth_pos1 = cloth .get_particles_pos ()[:, particles_idx ].clone ()
203232 link_pos1 = scene .rigid_solver .links [box_link_idx ].get_pos ().clone ()
233+ assert_allclose ((cloth_pos1 - cloth_pos0 ).movedim (0 , - 2 ), link_pos1 - link_pos0 , atol = 2e-5 )
204234
205- cloth_disp = cloth_pos1 - cloth_pos0
206- link_disp = link_pos1 - link_pos0
207- # broadcast link_disp to match cloth_disp shape
208- link_disp = link_disp .unsqueeze (1 )
209-
210- assert_allclose (cloth_disp , link_disp , atol = 2e-5 )
211-
212- # Release cloth and revert box's speed
235+ # Release cloth and restore box's speed
213236 box .set_dofs_velocity (vel , dofs_idx_local = [0 , 1 , 2 ])
214237 cloth .release_particle (particles_idx )
215- for i in range (25 ):
238+ for _ in range (15 ):
216239 scene .step ()
217240
218241 # Make sure that the cloth is laying on the ground without moving
219- cloth_pos2 = cloth .get_particles_pos ()[:, particles_idx ].clone ()
220- link_pos2 = scene .rigid_solver .links [box_link_idx ].get_pos ().clone ()
221- cloth_disp = cloth_pos2 - cloth_pos1
242+ cloth_pos2 = cloth .get_particles_pos ()[:, particles_idx ]
243+ link_pos2 = scene .rigid_solver .links [box_link_idx ].get_pos ()
222244 link_disp = link_pos2 - link_pos1
223- link_disp = link_disp .unsqueeze (1 )
224-
225- link_disp = link_disp .norm (dim = - 1 )
226- cloth_disp = cloth_disp .norm (dim = - 1 )
227- assert (link_disp - cloth_disp ).norm (dim = - 1 ).mean () > 0.1
245+ cloth_disp = cloth_pos2 - cloth_pos1
246+ assert ((cloth_disp .movedim (0 , - 2 ) - link_disp ).norm (dim = - 1 ) > 0.2 ).all ()
0 commit comments