| | import trimesh |
| | import json |
| | import numpy as np |
| |
|
| |
|
| | id = 1 |
| | try: |
| | file_path = f"./base{id}.glb" |
| | save_path = f"./model_data{id}.json" |
| | with open(file_path, 'rb') as file_obj: |
| | mesh = trimesh.load(file_obj, file_type='glb') |
| | except: |
| | file_path = f"./textured{id}.obj" |
| | save_path = f"./model_data{id}.json" |
| | with open(file_path, 'rb') as file_obj: |
| | mesh = trimesh.load(file_obj, file_type='obj') |
| |
|
| | oriented_bounding_box = mesh.bounding_box_oriented |
| | red_color = [1.0, 0.0, 0.0, 0.5] |
| |
|
| | scale = [0.4,0.4,0.4] |
| |
|
| | target_sphere = trimesh.creation.icosphere(subdivisions=2, radius=0.01) |
| | target_trans_matrix_sphere = trimesh.transformations.translation_matrix([0,0.08,0]) |
| | target_sphere.apply_transform(target_trans_matrix_sphere) |
| | target_sphere.visual.vertex_colors = np.array([red_color] * len(target_sphere.vertices)) |
| | target_trans_list = target_trans_matrix_sphere.tolist() |
| |
|
| | contact_sphere = trimesh.creation.icosphere(subdivisions=2, radius=0.01) |
| | contact_trans_matrix_sphere = trimesh.transformations.translation_matrix([0,0,0]) |
| | contact_sphere.apply_transform(contact_trans_matrix_sphere) |
| | contact_sphere.visual.vertex_colors = np.array([red_color] * len(contact_sphere.vertices)) |
| | contact_trans_list = contact_trans_matrix_sphere.tolist() |
| |
|
| | |
| | scene = trimesh.Scene(mesh) |
| |
|
| | |
| | axis1 = trimesh.creation.axis(axis_length=1.5) |
| | |
| | trans_matrix1 = trimesh.transformations.euler_matrix(0,0,0) |
| | |
| | axis1.apply_transform(trans_matrix1) |
| | transform_matrix_list1 = trans_matrix1.tolist() |
| |
|
| | data = { |
| | 'center': oriented_bounding_box.centroid.tolist(), |
| | 'extents': oriented_bounding_box.extents.tolist(), |
| | 'scale': scale, |
| | 'target_pose': target_trans_list, |
| | 'contact_pose' : [contact_trans_list], |
| | 'trans_matrix' : transform_matrix_list1 |
| | } |
| | with open(save_path, 'w') as json_file: |
| | json.dump(data, json_file, indent=4) |
| |
|
| | |
| | axis = trimesh.creation.axis(axis_length=1.5,origin_size= 0.05) |
| | |
| | |
| | scene.add_geometry(axis1) |
| | |
| | scene.add_geometry(target_sphere) |
| | scene.add_geometry(contact_sphere) |
| | scene.show() |