fix(sim): Fix .obj mesh compose issue. (#46)
This commit is contained in:
parent
6a750a37be
commit
0fb691bd22
@ -45,16 +45,23 @@ def decompose_convex_coacd(
|
||||
mesh = coacd.Mesh(mesh.vertices, mesh.faces)
|
||||
|
||||
result = coacd.run_coacd(mesh, **params)
|
||||
combined = sum([trimesh.Trimesh(*m) for m in result])
|
||||
|
||||
meshes = []
|
||||
for v, f in result:
|
||||
meshes.append(trimesh.Trimesh(v, f))
|
||||
|
||||
# Compute collision_scale because convex decomposition usually makes the mesh larger.
|
||||
if auto_scale:
|
||||
convex_mesh_shape = np.ptp(combined.vertices, axis=0)
|
||||
all_mesh = sum([trimesh.Trimesh(*m) for m in result])
|
||||
convex_mesh_shape = np.ptp(all_mesh.vertices, axis=0)
|
||||
visual_mesh_shape = np.ptp(mesh.vertices, axis=0)
|
||||
rescale = visual_mesh_shape / convex_mesh_shape
|
||||
combined.vertices *= rescale
|
||||
scale_factor *= visual_mesh_shape / convex_mesh_shape
|
||||
|
||||
combined = trimesh.Scene()
|
||||
for mesh_part in meshes:
|
||||
mesh_part.vertices *= scale_factor
|
||||
combined.add_geometry(mesh_part)
|
||||
|
||||
combined.vertices *= scale_factor
|
||||
combined.export(outfile)
|
||||
|
||||
|
||||
|
||||
@ -282,16 +282,12 @@ class URDFGenerator(object):
|
||||
d_params = dict(
|
||||
threshold=0.05, max_convex_hull=100, verbose=False
|
||||
)
|
||||
filename = f"{os.path.splitext(obj_name)[0]}_collision.ply"
|
||||
filename = f"{os.path.splitext(obj_name)[0]}_collision.obj"
|
||||
output_path = os.path.join(mesh_folder, filename)
|
||||
decompose_convex_mesh(
|
||||
mesh_output_path, output_path, **d_params
|
||||
)
|
||||
obj_filename = filename.replace(".ply", ".obj")
|
||||
trimesh.load(output_path).export(
|
||||
f"{mesh_folder}/{obj_filename}"
|
||||
)
|
||||
collision_mesh = f"{self.output_mesh_dir}/{obj_filename}"
|
||||
collision_mesh = f"{self.output_mesh_dir}/{filename}"
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Convex decomposition failed for {output_path}, {e}."
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user