TianxingChen
commited on
Commit
•
6627296
1
Parent(s):
8487e45
Delete models.py
Browse files
models.py
DELETED
@@ -1,65 +0,0 @@
|
|
1 |
-
import trimesh
|
2 |
-
import json
|
3 |
-
import numpy as np
|
4 |
-
|
5 |
-
|
6 |
-
id = ''
|
7 |
-
try:
|
8 |
-
file_path = f"./base{id}.glb"
|
9 |
-
save_path = f"./model_data{id}.json"
|
10 |
-
with open(file_path, 'rb') as file_obj:
|
11 |
-
mesh = trimesh.load(file_obj, file_type='glb')
|
12 |
-
except:
|
13 |
-
file_path = f"./textured{id}.obj"
|
14 |
-
save_path = f"./model_data{id}.json"
|
15 |
-
with open(file_path, 'rb') as file_obj:
|
16 |
-
mesh = trimesh.load(file_obj, file_type='obj')
|
17 |
-
|
18 |
-
oriented_bounding_box = mesh.bounding_box_oriented
|
19 |
-
red_color = [1.0, 0.0, 0.0, 0.5] # 红色, A=1 表示不透明
|
20 |
-
|
21 |
-
scale = [0.05,0.05,0.05]
|
22 |
-
|
23 |
-
target_sphere = trimesh.creation.icosphere(subdivisions=2, radius=0.1)
|
24 |
-
target_trans_matrix_sphere = trimesh.transformations.translation_matrix([0,0,0])
|
25 |
-
target_sphere.apply_transform(target_trans_matrix_sphere)
|
26 |
-
target_sphere.visual.vertex_colors = np.array([red_color] * len(target_sphere.vertices))
|
27 |
-
target_trans_list = target_trans_matrix_sphere.tolist()
|
28 |
-
|
29 |
-
contact_sphere = trimesh.creation.icosphere(subdivisions=2, radius=0.1)
|
30 |
-
contact_trans_matrix_sphere = trimesh.transformations.translation_matrix([0,0,0])
|
31 |
-
contact_sphere.apply_transform(contact_trans_matrix_sphere)
|
32 |
-
contact_sphere.visual.vertex_colors = np.array([red_color] * len(contact_sphere.vertices))
|
33 |
-
contact_trans_list = contact_trans_matrix_sphere.tolist()
|
34 |
-
|
35 |
-
# 创建一个场景
|
36 |
-
scene = trimesh.Scene(mesh)
|
37 |
-
|
38 |
-
# axis1
|
39 |
-
axis1 = trimesh.creation.axis(axis_length=1.5)
|
40 |
-
# 旋转矩阵的参数顺序是 (X, Y, Z) to endpose axis
|
41 |
-
trans_matrix1 = trimesh.transformations.euler_matrix(0,0,0)
|
42 |
-
# 应用旋转矩阵到坐标轴
|
43 |
-
axis1.apply_transform(trans_matrix1)
|
44 |
-
transform_matrix_list1 = trans_matrix1.tolist()
|
45 |
-
|
46 |
-
data = {
|
47 |
-
'center': oriented_bounding_box.centroid.tolist(), # 中心点
|
48 |
-
'extents': oriented_bounding_box.extents.tolist(), # 尺寸
|
49 |
-
'scale': scale,
|
50 |
-
'target_pose': target_trans_list,
|
51 |
-
'contact_pose' : [contact_trans_list],
|
52 |
-
'trans_matrix' : transform_matrix_list1
|
53 |
-
}
|
54 |
-
with open(save_path, 'w') as json_file:
|
55 |
-
json.dump(data, json_file, indent=4)
|
56 |
-
|
57 |
-
# 将坐标轴添加到场景
|
58 |
-
axis = trimesh.creation.axis(axis_length=1.5,origin_size= 0.05)
|
59 |
-
# axis.apply_transform(trimesh.transformations.euler_matrix(0, -1.57, 0))
|
60 |
-
# scene.add_geometry(axis)
|
61 |
-
scene.add_geometry(axis1)
|
62 |
-
# # 可视化网格和坐标轴
|
63 |
-
scene.add_geometry(target_sphere)
|
64 |
-
scene.add_geometry(contact_sphere)
|
65 |
-
scene.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|