Skip to content

Commit 0fb691b

Browse files
authored
fix(sim): Fix .obj mesh compose issue. (#46)
1 parent 6a750a3 commit 0fb691b

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

embodied_gen/data/convex_decomposer.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,23 @@ def decompose_convex_coacd(
4545
mesh = coacd.Mesh(mesh.vertices, mesh.faces)
4646

4747
result = coacd.run_coacd(mesh, **params)
48-
combined = sum([trimesh.Trimesh(*m) for m in result])
48+
49+
meshes = []
50+
for v, f in result:
51+
meshes.append(trimesh.Trimesh(v, f))
4952

5053
# Compute collision_scale because convex decomposition usually makes the mesh larger.
5154
if auto_scale:
52-
convex_mesh_shape = np.ptp(combined.vertices, axis=0)
55+
all_mesh = sum([trimesh.Trimesh(*m) for m in result])
56+
convex_mesh_shape = np.ptp(all_mesh.vertices, axis=0)
5357
visual_mesh_shape = np.ptp(mesh.vertices, axis=0)
54-
rescale = visual_mesh_shape / convex_mesh_shape
55-
combined.vertices *= rescale
58+
scale_factor *= visual_mesh_shape / convex_mesh_shape
59+
60+
combined = trimesh.Scene()
61+
for mesh_part in meshes:
62+
mesh_part.vertices *= scale_factor
63+
combined.add_geometry(mesh_part)
5664

57-
combined.vertices *= scale_factor
5865
combined.export(outfile)
5966

6067

embodied_gen/validators/urdf_convertor.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,12 @@ def generate_urdf(
282282
d_params = dict(
283283
threshold=0.05, max_convex_hull=100, verbose=False
284284
)
285-
filename = f"{os.path.splitext(obj_name)[0]}_collision.ply"
285+
filename = f"{os.path.splitext(obj_name)[0]}_collision.obj"
286286
output_path = os.path.join(mesh_folder, filename)
287287
decompose_convex_mesh(
288288
mesh_output_path, output_path, **d_params
289289
)
290-
obj_filename = filename.replace(".ply", ".obj")
291-
trimesh.load(output_path).export(
292-
f"{mesh_folder}/{obj_filename}"
293-
)
294-
collision_mesh = f"{self.output_mesh_dir}/{obj_filename}"
290+
collision_mesh = f"{self.output_mesh_dir}/{filename}"
295291
except Exception as e:
296292
logger.warning(
297293
f"Convex decomposition failed for {output_path}, {e}."

0 commit comments

Comments
 (0)