martelzhang commited on
Commit
69f15ae
·
verified ·
1 Parent(s): 8e17ad5

Upload 21 files

Browse files
.gitattributes CHANGED
@@ -57,3 +57,10 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
57
  # Video files - compressed
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
57
  # Video files - compressed
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
60
+ objects/badminton_annotated/badminton.glb filter=lfs diff=lfs merge=lfs -text
61
+ objects/barrel_annotated/barrel.glb filter=lfs diff=lfs merge=lfs -text
62
+ objects/card_annotated/card.glb filter=lfs diff=lfs merge=lfs -text
63
+ objects/pokeball_annotated/pokeball.glb filter=lfs diff=lfs merge=lfs -text
64
+ objects/terminal_annotated/terminal.glb filter=lfs diff=lfs merge=lfs -text
65
+ objects/vase_annotated/vase.glb filter=lfs diff=lfs merge=lfs -text
66
+ scenes/table/table.glb filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,7 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+ # RoboMonsterAssets Dataset Card
5
+
6
+ ![RoboMonster](./images/RoboMonster.png)
7
+ This repository contains basic assets for RoboMonster, also can be used in [RoboFactory](https://arxiv.org/pdf/2503.16408).
images/RoboMonster.png ADDED

Git LFS Details

  • SHA256: 79819449860b103e467bbf6389b45ee016c643e9fe04ed3d01550b9689656783
  • Pointer size: 132 Bytes
  • Size of remote file: 1 MB
objects/badminton_annotated/badminton.glb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:61d9b08f3d4d266cc75894241c5bf72a10b9e4c1d09fe2d00cd944106dd3fe23
3
+ size 29643428
objects/badminton_annotated/model_data.json ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "center": [
3
+ -0.006283712626541173,
4
+ 0.058497379234403825,
5
+ 0.008940475031173898
6
+ ],
7
+ "extents": [
8
+ 0.1144325742987233,
9
+ 0.12652459843631073,
10
+ 0.1200626571787099
11
+ ],
12
+ "scale": [
13
+ 1.0,
14
+ 1.0,
15
+ 1.0
16
+ ],
17
+ "target_pose": [
18
+ [
19
+ [
20
+ 1.0,
21
+ 0.0,
22
+ 0.0,
23
+ -0.006283712626541173
24
+ ],
25
+ [
26
+ 0.0,
27
+ 1.0,
28
+ 0.0,
29
+ 0.058497379234403825
30
+ ],
31
+ [
32
+ 0.0,
33
+ 0.0,
34
+ 1.0,
35
+ 0.008940475031173898
36
+ ],
37
+ [
38
+ 0.0,
39
+ 0.0,
40
+ 0.0,
41
+ 1.0
42
+ ]
43
+ ]
44
+ ],
45
+ "contact_points_pose": [
46
+ [
47
+ [
48
+ 1.0,
49
+ 0.0,
50
+ 0.0,
51
+ 0.0
52
+ ],
53
+ [
54
+ 0.0,
55
+ 1.0,
56
+ 0.0,
57
+ 0.09
58
+ ],
59
+ [
60
+ 0.0,
61
+ 0.0,
62
+ 1.0,
63
+ 0.035
64
+ ],
65
+ [
66
+ 0.0,
67
+ 0.0,
68
+ 0.0,
69
+ 1.0
70
+ ]
71
+ ]
72
+ ],
73
+ "transform_matrix": [
74
+ [
75
+ 1.0,
76
+ 0.0,
77
+ 0.0,
78
+ 0.0
79
+ ],
80
+ [
81
+ 0.0,
82
+ 1.0,
83
+ 0.0,
84
+ 0.0
85
+ ],
86
+ [
87
+ -0.0,
88
+ 0.0,
89
+ 1.0,
90
+ 0.0
91
+ ],
92
+ [
93
+ 0.0,
94
+ 0.0,
95
+ 0.0,
96
+ 1.0
97
+ ]
98
+ ],
99
+ "functional_matrix": [],
100
+ "orientation_point": [
101
+ [
102
+ 1.0,
103
+ 0.0,
104
+ 0.0,
105
+ 0.04388070051143324
106
+ ],
107
+ [
108
+ 0.0,
109
+ 1.0,
110
+ 0.0,
111
+ 0.059131446253697525
112
+ ],
113
+ [
114
+ 0.0,
115
+ 0.0,
116
+ 1.0,
117
+ 0.04747939193221155
118
+ ],
119
+ [
120
+ 0.0,
121
+ 0.0,
122
+ 0.0,
123
+ 1.0
124
+ ]
125
+ ],
126
+ "contact_points_group": [
127
+ [
128
+ 0
129
+ ]
130
+ ],
131
+ "contact_points_mask": [
132
+ true
133
+ ],
134
+ "contact_points_discription": [
135
+ "Single contact at world origin (editable at top)."
136
+ ],
137
+ "target_point_discription": [
138
+ "Object centroid."
139
+ ],
140
+ "functional_point_discription": [
141
+ ""
142
+ ],
143
+ "orientation_point_discription": [
144
+ "OBB +Y reference."
145
+ ]
146
+ }
objects/badminton_annotated/models.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # model_card_scaled.py
2
+ import trimesh
3
+ import json
4
+ import numpy as np
5
+
6
+ PI = np.pi
7
+
8
+ # === 你可以调这些参数(contact在世界坐标系) ===
9
+ MODEL_SCALE = 1.0 # 几何整体缩放
10
+ MARKER_FRAC = 0.02 # 标注物相对尺寸(基于OBB对角线)
11
+ CONTACT_POS = (0.0, 0.09, 0.035) # contact 世界坐标位置 —— 默认原点
12
+ CONTACT_RPY = (0.0, 0.0, 0.0) # contact 欧拉角(XYZ顺序), 单位: 弧度
13
+ CONTACT_RADIUS_SCALE = 1.0 # contact 球半径系数(相对于默认 r = diag*MARKER_FRAC*1.0)
14
+ AXIS_ORIGIN_SIZE_SCALE = 1.0 # contact处坐标轴的“轴心球”尺寸缩放
15
+
16
+ def create_model_data(id="badminton"):
17
+ file_path = f"./{id}.glb"
18
+ save_path = f"./model_data.json"
19
+
20
+ # 1) 读模型并烘焙为单一 Trimesh
21
+ with open(file_path, "rb") as f:
22
+ loaded = trimesh.load(f, file_type="glb")
23
+ mesh = loaded.to_mesh() if isinstance(loaded, trimesh.Scene) else loaded
24
+
25
+ # 2) 缩放
26
+ mesh.apply_scale(MODEL_SCALE)
27
+ scene = trimesh.Scene(mesh)
28
+
29
+ # 3) 尺寸 & 标注尺度
30
+ obb = mesh.bounding_box_oriented
31
+ center = np.asarray(obb.centroid)
32
+ ext = np.asarray(obb.extents)
33
+ diag = float(np.linalg.norm(ext)) + 1e-12
34
+
35
+ axis_len = diag * MARKER_FRAC * 6.0
36
+ origin_sz = diag * MARKER_FRAC * 0.6
37
+ r_target = diag * MARKER_FRAC * 1.2
38
+ r_contact = diag * MARKER_FRAC * 1.0 * float(CONTACT_RADIUS_SCALE)
39
+
40
+ red = [1.0, 0.0, 0.0, 0.5]
41
+ green = [0.0, 1.0, 0.0, 0.5]
42
+
43
+ # 4) Target point:OBB 质心
44
+ target_sphere = trimesh.creation.icosphere(subdivisions=2, radius=r_target)
45
+ T_target = trimesh.transformations.translation_matrix(center)
46
+ target_sphere.apply_transform(T_target)
47
+ target_sphere.visual.vertex_colors = np.array([red] * len(target_sphere.vertices))
48
+ scene.add_geometry(target_sphere)
49
+ target_points_list = [T_target.tolist()]
50
+
51
+ # 5) 仅一个 contact:固定在世界坐标 CONTACT_POS(默认原点)
52
+ contact_sphere = trimesh.creation.icosphere(subdivisions=2, radius=r_contact)
53
+ T_contact = (
54
+ trimesh.transformations.translation_matrix(np.asarray(CONTACT_POS)) @
55
+ trimesh.transformations.euler_matrix(*CONTACT_RPY)
56
+ )
57
+ contact_sphere.apply_transform(T_contact)
58
+ contact_sphere.visual.vertex_colors = np.array([red] * len(contact_sphere.vertices))
59
+ # 可视化局部坐标轴
60
+ axis = trimesh.creation.axis(origin_size=origin_sz * float(AXIS_ORIGIN_SIZE_SCALE))
61
+ axis.apply_transform(T_contact)
62
+ scene.add_geometry(axis)
63
+ scene.add_geometry(contact_sphere)
64
+
65
+ contact_points_list = [T_contact.tolist()]
66
+ contact_desc = ["Single contact at world origin (editable at top)."]
67
+
68
+ # 6) Orientation 参考点(仍放 OBB +Y 顶端,便于对齐/校验)
69
+ # 如不需要,注释掉这段亦可
70
+ # 从 OBB primitive 拿旋转矩阵 R_obb(若不可用则回退单位阵)
71
+ if hasattr(obb, "primitive") and hasattr(obb.primitive, "transform"):
72
+ R_obb = np.asarray(obb.primitive.transform)[:3, :3]
73
+ else:
74
+ R_obb = np.eye(3)
75
+ orient = trimesh.creation.icosphere(subdivisions=2, radius=origin_sz)
76
+ T_orient = trimesh.transformations.translation_matrix(center + R_obb[:, 1] * (ext[1] / 2.0))
77
+ orient.apply_transform(T_orient)
78
+ orient.visual.vertex_colors = np.array([green] * len(orient.vertices))
79
+ scene.add_geometry(orient)
80
+
81
+ # 7) 写 JSON
82
+ transform_matrix = trimesh.transformations.euler_matrix(0, 0, 0).tolist()
83
+ data = {
84
+ "center": center.tolist(),
85
+ "extents": ext.tolist(),
86
+ "scale": [MODEL_SCALE, MODEL_SCALE, MODEL_SCALE],
87
+ "target_pose": target_points_list,
88
+ "contact_points_pose": contact_points_list, # 只有1个
89
+ "transform_matrix": transform_matrix,
90
+ "functional_matrix": [],
91
+ "orientation_point": T_orient.tolist(),
92
+ "contact_points_group": [[0]], # 单组:仅索引0
93
+ "contact_points_mask": [True], # 单个有效
94
+ "contact_points_discription": contact_desc,
95
+ "target_point_discription": ["Object centroid."],
96
+ "functional_point_discription": [""],
97
+ "orientation_point_discription": ["OBB +Y reference."]
98
+ }
99
+ with open(save_path, "w") as f:
100
+ json.dump(data, f, indent=4, separators=(",", ": "))
101
+
102
+ scene.show()
103
+
104
+ if __name__ == "__main__":
105
+ create_model_data("badminton")
objects/barrel_annotated/barrel.glb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:87e1b0d099bdb111d5739a0bf227abbe8a5a3989d46189ea7f1e21d91a771ca6
3
+ size 7928680
objects/barrel_annotated/model_data.json ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "center": [
3
+ -0.002382030388980383,
4
+ 0.047954217310709216,
5
+ -0.14811597562402742
6
+ ],
7
+ "extents": [
8
+ 0.133843028759591,
9
+ 0.13199282088810027,
10
+ 0.530750415103979
11
+ ],
12
+ "scale": [
13
+ 1.0,
14
+ 1.0,
15
+ 1.0
16
+ ],
17
+ "target_pose": [
18
+ [
19
+ [
20
+ 6.123233995736766e-17,
21
+ 6.123233995736766e-17,
22
+ 1.0,
23
+ 0.0
24
+ ],
25
+ [
26
+ -1.0,
27
+ 3.749399456654644e-33,
28
+ 6.123233995736766e-17,
29
+ 0.045
30
+ ],
31
+ [
32
+ 0.0,
33
+ -1.0,
34
+ 6.123233995736766e-17,
35
+ -0.45
36
+ ],
37
+ [
38
+ 0.0,
39
+ 0.0,
40
+ 0.0,
41
+ 1.0
42
+ ]
43
+ ]
44
+ ],
45
+ "contact_points_pose": [
46
+ [
47
+ [
48
+ 6.123233995736766e-17,
49
+ -6.123233995736766e-17,
50
+ -1.0,
51
+ -0.035
52
+ ],
53
+ [
54
+ 1.0,
55
+ 3.749399456654644e-33,
56
+ 6.123233995736766e-17,
57
+ 0.045
58
+ ],
59
+ [
60
+ 0.0,
61
+ -1.0,
62
+ 6.123233995736766e-17,
63
+ -0.5
64
+ ],
65
+ [
66
+ 0.0,
67
+ 0.0,
68
+ 0.0,
69
+ 1.0
70
+ ]
71
+ ]
72
+ ],
73
+ "transform_matrix": [
74
+ [
75
+ 1.0,
76
+ 0.0,
77
+ 0.0,
78
+ 0.0
79
+ ],
80
+ [
81
+ 0.0,
82
+ 1.0,
83
+ 0.0,
84
+ 0.0
85
+ ],
86
+ [
87
+ -0.0,
88
+ 0.0,
89
+ 1.0,
90
+ 0.0
91
+ ],
92
+ [
93
+ 0.0,
94
+ 0.0,
95
+ 0.0,
96
+ 1.0
97
+ ]
98
+ ],
99
+ "functional_matrix": [],
100
+ "orientation_point": [
101
+ [
102
+ 1.0,
103
+ 0.0,
104
+ 0.0,
105
+ -0.0533792786507395
106
+ ],
107
+ [
108
+ 0.0,
109
+ 1.0,
110
+ 0.0,
111
+ 0.006064180689306108
112
+ ],
113
+ [
114
+ 0.0,
115
+ 0.0,
116
+ 1.0,
117
+ -0.1479379501046653
118
+ ],
119
+ [
120
+ 0.0,
121
+ 0.0,
122
+ 0.0,
123
+ 1.0
124
+ ]
125
+ ],
126
+ "contact_points_group": [
127
+ [
128
+ 0
129
+ ]
130
+ ],
131
+ "contact_points_mask": [
132
+ true
133
+ ],
134
+ "contact_points_discription": [
135
+ "Single contact at CONTACT_POS."
136
+ ],
137
+ "target_point_discription": [
138
+ "User-defined target at TARGET_POS."
139
+ ],
140
+ "functional_point_discription": [
141
+ ""
142
+ ],
143
+ "orientation_point_discription": [
144
+ "OBB +Y reference."
145
+ ]
146
+ }
objects/barrel_annotated/models.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # model_card_scaled.py
2
+ import trimesh
3
+ import json
4
+ import numpy as np
5
+
6
+ PI = np.pi
7
+
8
+ # === 可调参数 ===
9
+ MODEL_SCALE = 1.0 # 几何整体缩放
10
+ MARKER_FRAC = 0.02 # 标注物相对尺寸(基于 OBB 对角线)
11
+
12
+ CONTACT_POS = (-0.035, 0.045, -0.5) # 目标点位置
13
+ CONTACT_RPY = (-PI/2, 0.0, PI/2) # 目标点姿态 (XYZ/弧度)
14
+ CONTACT_RADIUS_SCALE = 1.2 # 目标标记球半径系数
15
+
16
+ TARGET_POS = (0., 0.045, -0.45) # 抓取/吸附点位置
17
+ TARGET_RPY = (-PI/2, 0.0, -PI/2) # 抓取点姿态 (XYZ/弧度)
18
+ TARGET_RADIUS_SCALE = 1.0 # 抓取标记球半径系数
19
+
20
+
21
+ # 可视化小坐标轴大小(两者共用)
22
+ AXIS_ORIGIN_SIZE_SCALE = 1.0
23
+
24
+ def create_model_data(id="barrel"):
25
+ file_path = f"./{id}.glb"
26
+ save_path = f"./model_data.json"
27
+
28
+ # 1) 读模型并烘焙为单一 Trimesh
29
+ with open(file_path, "rb") as f:
30
+ loaded = trimesh.load(f, file_type="glb")
31
+ mesh = loaded.to_mesh() if isinstance(loaded, trimesh.Scene) else loaded
32
+
33
+ # 2) 缩放
34
+ mesh.apply_scale(MODEL_SCALE)
35
+ scene = trimesh.Scene(mesh)
36
+
37
+ # 3) 尺寸 & 标注尺度
38
+ obb = mesh.bounding_box_oriented
39
+ center = np.asarray(obb.centroid)
40
+ ext = np.asarray(obb.extents)
41
+ diag = float(np.linalg.norm(ext)) + 1e-12
42
+
43
+ origin_sz = diag * MARKER_FRAC * 0.6
44
+ r_target = diag * MARKER_FRAC * float(TARGET_RADIUS_SCALE)
45
+ r_contact = diag * MARKER_FRAC * float(CONTACT_RADIUS_SCALE)
46
+
47
+ red = [1.0, 0.0, 0.0, 0.5]
48
+ green = [0.0, 1.0, 0.0, 0.5]
49
+
50
+ # 4) target 点
51
+ target_sphere = trimesh.creation.icosphere(subdivisions=2, radius=r_target)
52
+ T_target = (
53
+ trimesh.transformations.translation_matrix(np.asarray(TARGET_POS)) @
54
+ trimesh.transformations.euler_matrix(*TARGET_RPY)
55
+ )
56
+ target_sphere.apply_transform(T_target)
57
+ target_sphere.visual.vertex_colors = np.array([red] * len(target_sphere.vertices))
58
+ axis_t = trimesh.creation.axis(origin_size=origin_sz * float(AXIS_ORIGIN_SIZE_SCALE))
59
+ axis_t.apply_transform(T_target)
60
+ scene.add_geometry(axis_t)
61
+ scene.add_geometry(target_sphere)
62
+ target_points_list = [T_target.tolist()]
63
+
64
+ # 5) contact 点(新增)
65
+ contact_sphere = trimesh.creation.icosphere(subdivisions=2, radius=r_contact)
66
+ T_contact = (
67
+ trimesh.transformations.translation_matrix(np.asarray(CONTACT_POS)) @
68
+ trimesh.transformations.euler_matrix(*CONTACT_RPY)
69
+ )
70
+ contact_sphere.apply_transform(T_contact)
71
+ contact_sphere.visual.vertex_colors = np.array([red] * len(contact_sphere.vertices))
72
+ axis_c = trimesh.creation.axis(origin_size=origin_sz * float(AXIS_ORIGIN_SIZE_SCALE))
73
+ axis_c.apply_transform(T_contact)
74
+ scene.add_geometry(axis_c)
75
+ scene.add_geometry(contact_sphere)
76
+ contact_points_list = [T_contact.tolist()]
77
+
78
+ # 6) Orientation 参考点(OBB +Y 顶端)
79
+ if hasattr(obb, "primitive") and hasattr(obb.primitive, "transform"):
80
+ R_obb = np.asarray(obb.primitive.transform)[:3, :3]
81
+ else:
82
+ R_obb = np.eye(3)
83
+ orient = trimesh.creation.icosphere(subdivisions=2, radius=origin_sz)
84
+ T_orient = trimesh.transformations.translation_matrix(center + R_obb[:, 1] * (ext[1] / 2.0))
85
+ orient.apply_transform(T_orient)
86
+ orient.visual.vertex_colors = np.array([green] * len(orient.vertices))
87
+ scene.add_geometry(orient)
88
+
89
+ # 7) 写 JSON
90
+ transform_matrix = trimesh.transformations.euler_matrix(0, 0, 0).tolist()
91
+ data = {
92
+ "center": center.tolist(),
93
+ "extents": ext.tolist(),
94
+ "scale": [MODEL_SCALE, MODEL_SCALE, MODEL_SCALE],
95
+ "target_pose": target_points_list, # 一个 target
96
+ "contact_points_pose": contact_points_list, # 一个 contact
97
+ "transform_matrix": transform_matrix,
98
+ "functional_matrix": [],
99
+ "orientation_point": T_orient.tolist(),
100
+ "contact_points_group": [[0]], # 单组:仅索引0
101
+ "contact_points_mask": [True],
102
+ "contact_points_discription": ["Single contact at CONTACT_POS."],
103
+ "target_point_discription": ["User-defined target at TARGET_POS."],
104
+ "functional_point_discription": [""],
105
+ "orientation_point_discription": ["OBB +Y reference."]
106
+ }
107
+ with open(save_path, "w") as f:
108
+ json.dump(data, f, indent=4, separators=(",", ": "))
109
+
110
+ scene.show()
111
+
112
+ if __name__ == "__main__":
113
+ create_model_data("barrel")
objects/card_annotated/card.glb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:750bd1e7956c6ac6ccbde79721b0b5dcc08142c3ccd5e4d050bdaa6aacd4d91b
3
+ size 15320752
objects/card_annotated/model_data.json ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "center": [
3
+ 0.0,
4
+ -0.00016811525191823935,
5
+ 0.0
6
+ ],
7
+ "extents": [
8
+ 0.1720472085289657,
9
+ 0.0006833084868800526,
10
+ 0.10832602018490434
11
+ ],
12
+ "scale": [
13
+ 1,
14
+ 1,
15
+ 1
16
+ ],
17
+ "target_pose": [
18
+ [
19
+ [
20
+ 1.0,
21
+ 0.0,
22
+ 0.0,
23
+ 0.0
24
+ ],
25
+ [
26
+ 0.0,
27
+ 1.0,
28
+ 0.0,
29
+ -0.00016811525191823935
30
+ ],
31
+ [
32
+ 0.0,
33
+ 0.0,
34
+ 1.0,
35
+ 0.0
36
+ ],
37
+ [
38
+ 0.0,
39
+ 0.0,
40
+ 0.0,
41
+ 1.0
42
+ ]
43
+ ]
44
+ ],
45
+ "contact_points_pose": [
46
+ [
47
+ [
48
+ -1.0,
49
+ 0.0,
50
+ -1.2246467991473532e-16,
51
+ 0.04301180213224143
52
+ ],
53
+ [
54
+ 0.0,
55
+ 1.0,
56
+ 0.0,
57
+ -0.00016811525191823935
58
+ ],
59
+ [
60
+ 1.2246467991473532e-16,
61
+ 0.0,
62
+ -1.0,
63
+ -0.027081505046226084
64
+ ],
65
+ [
66
+ 0.0,
67
+ 0.0,
68
+ 0.0,
69
+ 1.0
70
+ ]
71
+ ],
72
+ [
73
+ [
74
+ -1.0,
75
+ 1.2246467991473532e-16,
76
+ -7.498798913309288e-33,
77
+ 0.0
78
+ ],
79
+ [
80
+ 0.0,
81
+ 6.123233995736766e-17,
82
+ 1.0,
83
+ -0.00016811525191823935
84
+ ],
85
+ [
86
+ 1.2246467991473532e-16,
87
+ 1.0,
88
+ -6.123233995736766e-17,
89
+ 0.027081505046226084
90
+ ],
91
+ [
92
+ 0.0,
93
+ 0.0,
94
+ 0.0,
95
+ 1.0
96
+ ]
97
+ ],
98
+ [
99
+ [
100
+ -1.0,
101
+ 1.2246467991473532e-16,
102
+ 7.498798913309288e-33,
103
+ 0.0
104
+ ],
105
+ [
106
+ 0.0,
107
+ 6.123233995736766e-17,
108
+ -1.0,
109
+ -0.00016811525191823935
110
+ ],
111
+ [
112
+ -1.2246467991473532e-16,
113
+ -1.0,
114
+ -6.123233995736766e-17,
115
+ -0.027081505046226084
116
+ ],
117
+ [
118
+ 0.0,
119
+ 0.0,
120
+ 0.0,
121
+ 1.0
122
+ ]
123
+ ]
124
+ ],
125
+ "transform_matrix": [
126
+ [
127
+ 1.0,
128
+ 0.0,
129
+ 0.0,
130
+ 0.0
131
+ ],
132
+ [
133
+ 0.0,
134
+ 1.0,
135
+ 0.0,
136
+ 0.0
137
+ ],
138
+ [
139
+ -0.0,
140
+ 0.0,
141
+ 1.0,
142
+ 0.0
143
+ ],
144
+ [
145
+ 0.0,
146
+ 0.0,
147
+ 0.0,
148
+ 1.0
149
+ ]
150
+ ],
151
+ "functional_matrix": [],
152
+ "orientation_point": [
153
+ [
154
+ 1.0,
155
+ 0.0,
156
+ 0.0,
157
+ 0.0
158
+ ],
159
+ [
160
+ 0.0,
161
+ 1.0,
162
+ 0.0,
163
+ 0.00017353899152178697
164
+ ],
165
+ [
166
+ 0.0,
167
+ 0.0,
168
+ 1.0,
169
+ 0.0
170
+ ],
171
+ [
172
+ 0.0,
173
+ 0.0,
174
+ 0.0,
175
+ 1.0
176
+ ]
177
+ ],
178
+ "contact_points_group": [
179
+ [
180
+ 0,
181
+ 1
182
+ ]
183
+ ],
184
+ "contact_points_mask": [
185
+ true,
186
+ true
187
+ ],
188
+ "contact_points_discription": [
189
+ "Suction point of the upper right corner to the midpoint by half",
190
+ "Grasp on midpoint of the bottom edge",
191
+ "Grasp on midpoint of the bottom edge"
192
+ ],
193
+ "target_point_discription": [
194
+ "Object centroid."
195
+ ],
196
+ "functional_point_discription": [
197
+ ""
198
+ ],
199
+ "orientation_point_discription": [
200
+ "OBB +Y reference."
201
+ ]
202
+ }
objects/card_annotated/models.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # model_card_scaled.py
2
+ import trimesh
3
+ import json
4
+ import numpy as np
5
+
6
+ PI = np.pi
7
+
8
+ # === 你可以只调这两个参数 ===
9
+ MODEL_SCALE = 1 # 让卡变大(几何整体缩放倍数)
10
+ MARKER_FRAC = 0.02 # 标注物尺寸占物体对角线的比例(越小→球和坐标轴越小)
11
+
12
+ def create_model_data(id="card"):
13
+ file_path = f"./{id}.glb"
14
+ save_path = f"./model_data.json"
15
+
16
+ # 1) 读模型并烘焙为单一 Trimesh
17
+ with open(file_path, "rb") as f:
18
+ loaded = trimesh.load(f, file_type="glb")
19
+ mesh = loaded.to_mesh() if isinstance(loaded, trimesh.Scene) else loaded
20
+
21
+ # 2) 放大卡(整体缩放)
22
+ mesh.apply_scale(MODEL_SCALE) # <— 放大卡,trimesh 内置缩放方法
23
+ scene = trimesh.Scene(mesh)
24
+
25
+ # 3) 根据放大后的尺寸自适应计算标注尺寸
26
+ obb = mesh.bounding_box_oriented
27
+ center = obb.centroid
28
+ ext = obb.extents
29
+ diag = float(np.linalg.norm(ext)) + 1e-12
30
+
31
+ # 标注的统一尺度(你也可分别给不同大小)
32
+ axis_len = diag * MARKER_FRAC * 6.0 # 坐标轴长度
33
+ origin_sz = diag * MARKER_FRAC * 0.6 # 轴心小球尺寸
34
+ r_target = diag * MARKER_FRAC * 1.2 # 目标点球半径
35
+ r_contact0 = diag * MARKER_FRAC * 1.0 # 抓取点球半径(1)
36
+ r_contact1 = diag * MARKER_FRAC * 1.0 # 抓取点球半径(2)
37
+
38
+ red = [1.0, 0.0, 0.0, 0.5]
39
+ green = [0.0, 1.0, 0.0, 0.5]
40
+ blue = [0.0, 0.0, 1.0, 0.5]
41
+
42
+ # 4) Target point:取 OBB 质心
43
+ target_sphere = trimesh.creation.icosphere(subdivisions=2, radius=r_target)
44
+ T_target = trimesh.transformations.translation_matrix(center)
45
+ target_sphere.apply_transform(T_target)
46
+ target_sphere.visual.vertex_colors = np.array([red] * len(target_sphere.vertices))
47
+ scene.add_geometry(target_sphere)
48
+ target_points_list = [T_target.tolist()]
49
+
50
+ # 5) 随便放两个 contact(先粗标,后续你再调)
51
+ contact_points_list, contact_desc = [], []
52
+
53
+ def add_contact(radius, pos, euler_xyz, desc):
54
+ sph = trimesh.creation.icosphere(subdivisions=2, radius=radius)
55
+ T = trimesh.transformations.translation_matrix(pos) @ \
56
+ trimesh.transformations.euler_matrix(*euler_xyz)
57
+ sph.apply_transform(T)
58
+ sph.visual.vertex_colors = np.array([red] * len(sph.vertices))
59
+ # 坐标轴(更小)
60
+ axis = trimesh.creation.axis(origin_size=origin_sz) # 指定轴心球大小
61
+ # 默认 axis_length 会随 origin_size 缩放;如要强行指定:axis = trimesh.creation.axis(origin_size=origin_sz); axis.apply_scale(axis_len / (origin_sz*10))
62
+ axis.apply_transform(T)
63
+ scene.add_geometry(axis)
64
+ scene.add_geometry(sph)
65
+ contact_points_list.append(T.tolist())
66
+ contact_desc.append(desc)
67
+
68
+ ex, ey, ez = ext
69
+ print(ext)
70
+ print(center)
71
+ c = center
72
+ add_contact(r_contact0, [c[0] + 0.25 * ex, c[1], c[2] - 0.25 * ez], [0, -PI, 0], "Suction point of the upper right corner to the midpoint by half")
73
+ add_contact(r_contact1, [c[0], c[1], c[2] + 0.25 * ez], [-PI/2, -PI, 0], "Grasp on midpoint of the bottom edge")
74
+ add_contact(r_contact1, [c[0], c[1], c[2] - 0.25 * ez], [PI/2, PI, 0], "Grasp on midpoint of the bottom edge")
75
+ # 6) Orientation 参考点(小绿球)
76
+ orient = trimesh.creation.icosphere(subdivisions=2, radius=origin_sz)
77
+ T_orient = trimesh.transformations.translation_matrix([c[0], c[1] + ey/2.0, c[2]])
78
+ orient.apply_transform(T_orient)
79
+ orient.visual.vertex_colors = np.array([green] * len(orient.vertices))
80
+ scene.add_geometry(orient)
81
+
82
+ # 7) 世界坐标轴(可选,按比例更小)
83
+ # world_axis = trimesh.creation.axis(origin_size=origin_sz)
84
+ # scene.add_geometry(world_axis)
85
+
86
+ # 8) 写 JSON(把 scale 也写成 [MODEL_SCALE]*3,与你的 motionplanner 用法保持一致)
87
+ transform_matrix = trimesh.transformations.euler_matrix(0, 0, 0).tolist()
88
+ data = {
89
+ "center": center.tolist(),
90
+ "extents": ext.tolist(),
91
+ "scale": [MODEL_SCALE, MODEL_SCALE, MODEL_SCALE], # <— 与几何缩放一致
92
+ "target_pose": target_points_list,
93
+ "contact_points_pose": contact_points_list,
94
+ "transform_matrix": transform_matrix,
95
+ "functional_matrix": [],
96
+ "orientation_point": T_orient.tolist(),
97
+ "contact_points_group": [[0, 1]],
98
+ "contact_points_mask": [True, True],
99
+ "contact_points_discription": contact_desc,
100
+ "target_point_discription": ["Object centroid."],
101
+ "functional_point_discription": [""],
102
+ "orientation_point_discription": ["OBB +Y reference."]
103
+ }
104
+ with open(save_path, "w") as f:
105
+ json.dump(data, f, indent=4, separators=(",", ": "))
106
+
107
+ scene.show()
108
+
109
+ if __name__ == "__main__":
110
+ create_model_data("card")
objects/pokeball_annotated/model_data.json ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "center": [
3
+ 0.02495441054302816,
4
+ 0.04039958576682315,
5
+ 1.608605873181978e-05
6
+ ],
7
+ "extents": [
8
+ 0.11410288889507963,
9
+ 0.08259069446084513,
10
+ 0.11193267813583267
11
+ ],
12
+ "scale": [
13
+ 0.04,
14
+ 0.04,
15
+ 0.04
16
+ ],
17
+ "target_pose": [
18
+ [
19
+ [
20
+ 1.0,
21
+ 0.0,
22
+ 0.0,
23
+ 0.02495441054302816
24
+ ],
25
+ [
26
+ 0.0,
27
+ 1.0,
28
+ 0.0,
29
+ 0.04039958576682315
30
+ ],
31
+ [
32
+ 0.0,
33
+ 0.0,
34
+ 1.0,
35
+ 1.608605873181978e-05
36
+ ],
37
+ [
38
+ 0.0,
39
+ 0.0,
40
+ 0.0,
41
+ 1.0
42
+ ]
43
+ ]
44
+ ],
45
+ "contact_points_pose": [
46
+ [
47
+ [
48
+ 1.0,
49
+ 0.0,
50
+ 0.0,
51
+ 0.02495441054302816
52
+ ],
53
+ [
54
+ 0.0,
55
+ 1.0,
56
+ 0.0,
57
+ 0.04039958576682315
58
+ ],
59
+ [
60
+ 0.0,
61
+ 0.0,
62
+ 1.0,
63
+ 1.608605873181978e-05
64
+ ],
65
+ [
66
+ 0.0,
67
+ 0.0,
68
+ 0.0,
69
+ 1.0
70
+ ]
71
+ ]
72
+ ],
73
+ "transform_matrix": [
74
+ [
75
+ 1.0,
76
+ 0.0,
77
+ 0.0,
78
+ 0.0
79
+ ],
80
+ [
81
+ 0.0,
82
+ 1.0,
83
+ 0.0,
84
+ 0.0
85
+ ],
86
+ [
87
+ -0.0,
88
+ 0.0,
89
+ 1.0,
90
+ 0.0
91
+ ],
92
+ [
93
+ 0.0,
94
+ 0.0,
95
+ 0.0,
96
+ 1.0
97
+ ]
98
+ ],
99
+ "functional_matrix": [],
100
+ "orientation_point": [
101
+ [
102
+ 1.0,
103
+ 0.0,
104
+ 0.0,
105
+ 0.05335633953734738
106
+ ],
107
+ [
108
+ 0.0,
109
+ 1.0,
110
+ 0.0,
111
+ 0.041464989916579646
112
+ ],
113
+ [
114
+ 0.0,
115
+ 0.0,
116
+ 1.0,
117
+ 0.029974407878895572
118
+ ],
119
+ [
120
+ 0.0,
121
+ 0.0,
122
+ 0.0,
123
+ 1.0
124
+ ]
125
+ ],
126
+ "contact_points_group": [
127
+ [
128
+ 0
129
+ ]
130
+ ],
131
+ "contact_points_mask": [
132
+ true
133
+ ],
134
+ "contact_points_discription": [
135
+ "Single contact at OBB centroid (+ offset)."
136
+ ],
137
+ "target_point_discription": [
138
+ "Object centroid."
139
+ ],
140
+ "functional_point_discription": [
141
+ ""
142
+ ],
143
+ "orientation_point_discription": [
144
+ "OBB +Y reference."
145
+ ]
146
+ }
objects/pokeball_annotated/models.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # model_pokeball_scaled.py
2
+ import trimesh
3
+ import json
4
+ import numpy as np
5
+
6
+ PI = np.pi
7
+
8
+ # === 你可以调这些参数(contact默认放在物体OBB质心,可加偏移) ===
9
+ MODEL_SCALE = 0.04 # 几何整体缩放
10
+ MARKER_FRAC = 0.1 # 标注物相对尺寸(基于OBB对角线)
11
+ CONTACT_POS = (0.0, 0.0, 0.0) # contact 相对OBB质心的偏移(世界系)
12
+ CONTACT_RPY = (0.0, 0.0, 0.0) # contact 欧拉角(XYZ顺序), 单位: 弧度
13
+ CONTACT_RADIUS_SCALE = 1.0 # contact 球半径系数(相对于默认 r = diag*MARKER_FRAC*1.0)
14
+ AXIS_ORIGIN_SIZE_SCALE = 1.0 # contact处坐标轴的“轴心球”尺寸缩放
15
+
16
+ def create_model_data(id="pokeball"):
17
+ file_path = f"./{id}.glb"
18
+ save_path = f"./model_data.json"
19
+
20
+ # 1) 读模型并烘焙为单一 Trimesh
21
+ with open(file_path, "rb") as f:
22
+ loaded = trimesh.load(f, file_type="glb")
23
+ mesh = loaded.to_mesh() if isinstance(loaded, trimesh.Scene) else loaded
24
+
25
+ # 2) 缩放
26
+ mesh.apply_scale(MODEL_SCALE)
27
+ scene = trimesh.Scene(mesh)
28
+
29
+ # 3) 尺寸 & 标注尺度
30
+ obb = mesh.bounding_box_oriented
31
+ center = np.asarray(obb.centroid)
32
+ ext = np.asarray(obb.extents)
33
+ diag = float(np.linalg.norm(ext)) + 1e-12
34
+
35
+ axis_len = diag * MARKER_FRAC * 6.0
36
+ origin_sz = diag * MARKER_FRAC * 0.6
37
+ r_target = diag * MARKER_FRAC * 1.2
38
+ r_contact = diag * MARKER_FRAC * 1.0 * float(CONTACT_RADIUS_SCALE)
39
+
40
+ red = [1.0, 0.0, 0.0, 0.5]
41
+ green = [0.0, 1.0, 0.0, 0.5]
42
+
43
+ # 4) Target point:OBB 质心
44
+ target_sphere = trimesh.creation.icosphere(subdivisions=2, radius=r_target)
45
+ T_target = trimesh.transformations.translation_matrix(center)
46
+ target_sphere.apply_transform(T_target)
47
+ target_sphere.visual.vertex_colors = np.array([red] * len(target_sphere.vertices))
48
+ scene.add_geometry(target_sphere)
49
+ target_points_list = [T_target.tolist()]
50
+
51
+ # 5) contact:默认放在球中心(OBB质心),可用CONTACT_POS作小偏移
52
+ contact_sphere = trimesh.creation.icosphere(subdivisions=2, radius=r_contact)
53
+ contact_world_pos = center + np.asarray(CONTACT_POS, dtype=float)
54
+ T_contact = (
55
+ trimesh.transformations.translation_matrix(contact_world_pos) @
56
+ trimesh.transformations.euler_matrix(*CONTACT_RPY)
57
+ )
58
+ contact_sphere.apply_transform(T_contact)
59
+ contact_sphere.visual.vertex_colors = np.array([red] * len(contact_sphere.vertices))
60
+ # 可视化局部坐标轴
61
+ axis = trimesh.creation.axis(origin_size=origin_sz * float(AXIS_ORIGIN_SIZE_SCALE))
62
+ axis.apply_transform(T_contact)
63
+ scene.add_geometry(axis)
64
+ scene.add_geometry(contact_sphere)
65
+
66
+ contact_points_list = [T_contact.tolist()]
67
+ contact_desc = ["Single contact at OBB centroid (+ offset)."]
68
+
69
+ # 6) Orientation 参考点(仍放 OBB +Y 顶端)
70
+ if hasattr(obb, "primitive") and hasattr(obb.primitive, "transform"):
71
+ R_obb = np.asarray(obb.primitive.transform)[:3, :3]
72
+ else:
73
+ R_obb = np.eye(3)
74
+ orient = trimesh.creation.icosphere(subdivisions=2, radius=origin_sz)
75
+ T_orient = trimesh.transformations.translation_matrix(center + R_obb[:, 1] * (ext[1] / 2.0))
76
+ orient.apply_transform(T_orient)
77
+ orient.visual.vertex_colors = np.array([green] * len(orient.vertices))
78
+ scene.add_geometry(orient)
79
+
80
+ # 7) 写 JSON
81
+ transform_matrix = trimesh.transformations.euler_matrix(0, 0, 0).tolist()
82
+ data = {
83
+ "center": center.tolist(),
84
+ "extents": ext.tolist(),
85
+ "scale": [MODEL_SCALE, MODEL_SCALE, MODEL_SCALE],
86
+ "target_pose": target_points_list,
87
+ "contact_points_pose": contact_points_list,
88
+ "transform_matrix": transform_matrix,
89
+ "functional_matrix": [],
90
+ "orientation_point": T_orient.tolist(),
91
+ "contact_points_group": [[0]],
92
+ "contact_points_mask": [True],
93
+ "contact_points_discription": contact_desc,
94
+ "target_point_discription": ["Object centroid."],
95
+ "functional_point_discription": [""],
96
+ "orientation_point_discription": ["OBB +Y reference."]
97
+ }
98
+ with open(save_path, "w") as f:
99
+ json.dump(data, f, indent=4, separators=(",", ": "))
100
+
101
+ scene.show()
102
+
103
+ if __name__ == "__main__":
104
+ create_model_data("pokeball")
objects/pokeball_annotated/pokeball.glb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d61cb06b2246b194afe28bf2c8b496cc0b9db45b49da4e5fd87e84e1b12d5437
3
+ size 1190088
objects/terminal_annotated/model_data.json ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "center": [
3
+ 1.873558015222015e-05,
4
+ 0.013033718940315799,
5
+ 0.0002804949212231114
6
+ ],
7
+ "extents": [
8
+ 0.10652180400216095,
9
+ 0.1324749116214104,
10
+ 0.2671022324721998
11
+ ],
12
+ "scale": [
13
+ 1.0,
14
+ 1.0,
15
+ 1.0
16
+ ],
17
+ "target_pose": [
18
+ [
19
+ [
20
+ 0.9999999677295611,
21
+ 1.9492489748571025e-05,
22
+ 0.0002533000586885312,
23
+ 3.3830883349644526e-06
24
+ ],
25
+ [
26
+ 4.686187494245504e-05,
27
+ 0.965789604421175,
28
+ -0.2593268936997374,
29
+ 0.09404479607843289
30
+ ],
31
+ [
32
+ -0.00024968949029762795,
33
+ 0.2593268972012604,
34
+ 0.965789572341266,
35
+ -0.04600163069907902
36
+ ],
37
+ [
38
+ 0.0,
39
+ 0.0,
40
+ 0.0,
41
+ 1.0
42
+ ]
43
+ ]
44
+ ],
45
+ "contact_points_pose": [],
46
+ "transform_matrix": [
47
+ [
48
+ 1.0,
49
+ 0.0,
50
+ 0.0,
51
+ 0.0
52
+ ],
53
+ [
54
+ 0.0,
55
+ 1.0,
56
+ 0.0,
57
+ 0.0
58
+ ],
59
+ [
60
+ -0.0,
61
+ 0.0,
62
+ 1.0,
63
+ 0.0
64
+ ],
65
+ [
66
+ 0.0,
67
+ 0.0,
68
+ 0.0,
69
+ 1.0
70
+ ]
71
+ ],
72
+ "functional_matrix": [],
73
+ "orientation_point": [
74
+ [
75
+ 0.9999999677295611,
76
+ 1.9492489748571025e-05,
77
+ 0.0002533000586885312,
78
+ 3.3830883349644526e-06
79
+ ],
80
+ [
81
+ 4.686187494245504e-05,
82
+ 0.965789604421175,
83
+ -0.2593268936997374,
84
+ 0.09404479607843289
85
+ ],
86
+ [
87
+ -0.00024968949029762795,
88
+ 0.2593268972012604,
89
+ 0.965789572341266,
90
+ -0.04600163069907902
91
+ ],
92
+ [
93
+ 0.0,
94
+ 0.0,
95
+ 0.0,
96
+ 1.0
97
+ ]
98
+ ],
99
+ "contact_points_group": [],
100
+ "contact_points_mask": [],
101
+ "contact_points_discription": [],
102
+ "target_point_discription": [
103
+ "OBB +Z face center → local -Z offset → local Z rot → local +Y offset."
104
+ ],
105
+ "functional_point_discription": [
106
+ ""
107
+ ],
108
+ "orientation_point_discription": [
109
+ "Same as target for schema compatibility."
110
+ ]
111
+ }
objects/terminal_annotated/models.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # models_terminal.py
2
+ # 目标:读取 ./terminal.glb → 以 OBB 对齐 target pose,位置在 OBB +Z 面中心;
3
+ # 然后沿“target pose 的局部 -Z”偏移,再“绕其局部 Z 轴”旋转(可正可负);
4
+ # 最后“在此基础上”沿“target pose 的局部 +Y 轴”再平移一点;
5
+ # 输出 ./model_data.json,并在预览中画出加长坐标轴与小球。
6
+
7
+ import trimesh
8
+ import json
9
+ import numpy as np
10
+
11
+ PI = np.pi
12
+
13
+ # === 可调参数 ===
14
+ MODEL_SCALE = 1.0 # 几何整体缩放倍数
15
+ MARKER_FRAC = 0.02 # 标注物相对物体对角线比例(越小→球/坐标轴更小)
16
+ OFFSET_FRAC_Z = 0.746 # 沿局部 -Z 平移 extents[2] * 此比例
17
+ ROT_Z_DEG = -90.0 # 随后绕局部 Z 轴旋转(度)
18
+ OFFSET_FRAC_Y = 0.5 # 【新增】在此基础上,沿“局部 +Y”再平移 extents[1] * 此比例
19
+
20
+ def _to_fused_mesh(obj):
21
+ if isinstance(obj, trimesh.Trimesh):
22
+ return obj
23
+ if isinstance(obj, trimesh.Scene):
24
+ try:
25
+ return obj.to_mesh()
26
+ except Exception:
27
+ geoms = list(obj.dump().geometry.values())
28
+ return trimesh.util.concatenate(geoms)
29
+ raise TypeError(f"Unsupported type: {type(obj)}")
30
+
31
+ def create_model_data(id="terminal"):
32
+ file_path = f"./{id}.glb"
33
+ save_path = f"./model_data.json"
34
+
35
+ # 1) 读模型并融合为单一 Trimesh
36
+ with open(file_path, "rb") as f:
37
+ loaded = trimesh.load(f, file_type="glb")
38
+ mesh = _to_fused_mesh(loaded)
39
+
40
+ # 2) 全局缩放
41
+ mesh.apply_scale(MODEL_SCALE)
42
+ scene = trimesh.Scene(mesh)
43
+
44
+ # 3) OBB 与自适应标注尺寸
45
+ obb = mesh.bounding_box_oriented
46
+ center = obb.centroid # 世界系下 OBB 质心
47
+ ext = obb.extents # [ex, ey, ez]
48
+ diag = float(np.linalg.norm(ext)) + 1e-12
49
+
50
+ axis_len = diag * MARKER_FRAC * 12.0 # 加长坐标轴
51
+ origin_sz = diag * MARKER_FRAC * 0.6
52
+ r_target = diag * MARKER_FRAC * 1.2
53
+
54
+ red = [1.0, 0.0, 0.0, 0.5]
55
+ green = [0.0, 1.0, 0.0, 0.5]
56
+ blue = [0.0, 0.0, 1.0, 0.5]
57
+
58
+ # 4) 以 OBB 对齐的“初始 target pose”(在 OBB 的 +Z 面中心)
59
+ T_obb = obb.primitive.transform # 4x4
60
+ R_obb = T_obb[:3, :3]
61
+ top_center = center + R_obb[:, 2] * (ext[2] / 2.0)
62
+
63
+ T_target = np.eye(4, dtype=float)
64
+ T_target[:3, :3] = R_obb
65
+ T_target[:3, 3] = top_center
66
+
67
+ # 5) 局部链:先沿 -Z 偏移,再绕 Z 旋转,再沿 +Y 偏移(均在“局部系”)
68
+ offset_dist_z = ext[2] * OFFSET_FRAC_Z
69
+ T_offset_z = trimesh.transformations.translation_matrix([0.0, 0.0, -offset_dist_z])
70
+ Rz_local = trimesh.transformations.rotation_matrix(np.deg2rad(ROT_Z_DEG), [0.0, 0.0, 1.0])
71
+ offset_dist_y = ext[1] * OFFSET_FRAC_Y # 【新增】沿局部 +Y 的距离
72
+ T_offset_y = trimesh.transformations.translation_matrix([0.0, offset_dist_y, 0.0])
73
+
74
+ # 组合顺序采用右乘:表示“在当前局部坐标系下”依次执行
75
+ T_final = T_target @ T_offset_z @ Rz_local @ T_offset_y
76
+
77
+ # 6) 可视化:目标点小球 + 加长坐标轴(都放在 T_final 处)
78
+ target_sphere = trimesh.creation.icosphere(subdivisions=2, radius=r_target)
79
+ target_sphere.apply_transform(T_final)
80
+ target_sphere.visual.vertex_colors = np.array([red] * len(target_sphere.vertices))
81
+ scene.add_geometry(target_sphere)
82
+
83
+ axis = trimesh.creation.axis(
84
+ origin_size=origin_sz,
85
+ axis_length=axis_len,
86
+ axis_radius=origin_sz * 0.3,
87
+ )
88
+ axis.apply_transform(T_final)
89
+ scene.add_geometry(axis)
90
+
91
+ print("extents =", ext)
92
+ print("center =", center)
93
+ print("target pose (before offset/rot) =\n", T_target)
94
+ print("final target pose (after z-offset, z-rot, y-offset) =\n", T_final)
95
+
96
+ # 7) 写 JSON(只保留 target 相关字段,其它保持 schema)
97
+ transform_matrix = trimesh.transformations.euler_matrix(0, 0, 0).tolist()
98
+ data = {
99
+ "center": center.tolist(),
100
+ "extents": ext.tolist(),
101
+ "scale": [MODEL_SCALE, MODEL_SCALE, MODEL_SCALE],
102
+ "target_pose": [T_final.tolist()],
103
+ "contact_points_pose": [],
104
+ "transform_matrix": transform_matrix,
105
+ "functional_matrix": [],
106
+ "orientation_point": T_final.tolist(),
107
+ "contact_points_group": [],
108
+ "contact_points_mask": [],
109
+ "contact_points_discription": [],
110
+ "target_point_discription": [
111
+ "OBB +Z face center → local -Z offset → local Z rot → local +Y offset."
112
+ ],
113
+ "functional_point_discription": [""],
114
+ "orientation_point_discription": ["Same as target for schema compatibility."]
115
+ }
116
+ with open(save_path, "w", encoding="utf-8") as f:
117
+ json.dump(data, f, indent=4, ensure_ascii=False, separators=(",", ": "))
118
+
119
+ scene.show()
120
+
121
+ if __name__ == "__main__":
122
+ create_model_data("terminal")
objects/terminal_annotated/terminal.glb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:59b1ad1d08b0030ca162487a82bd5c11bf630a29e6951f5c8f7a4e5beadea8a2
3
+ size 4712676
objects/vase_annotated/model_data.json ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "center": [
3
+ 1.1124276707721084e-16,
4
+ 0.07359927428680288,
5
+ -8.558756869537667e-09
6
+ ],
7
+ "extents": [
8
+ 0.14719890510160538,
9
+ 0.19665762109662338,
10
+ 0.14719854857360673
11
+ ],
12
+ "scale": [
13
+ 0.004,
14
+ 0.004,
15
+ 0.004
16
+ ],
17
+ "contact_points_pose": [
18
+ [
19
+ [
20
+ -1.0,
21
+ 1.2246467991473532e-16,
22
+ 1.4997597826618576e-32,
23
+ 2.403561242065095e-16
24
+ ],
25
+ [
26
+ 1.2246467991473532e-16,
27
+ 1.0,
28
+ 1.2246467991473532e-16,
29
+ 0.14719854857360576
30
+ ],
31
+ [
32
+ 0.0,
33
+ 1.2246467991473532e-16,
34
+ -1.0,
35
+ -1.7117513744652586e-08
36
+ ],
37
+ [
38
+ 0.0,
39
+ 0.0,
40
+ 0.0,
41
+ 1.0
42
+ ]
43
+ ]
44
+ ],
45
+ "transform_matrix": [
46
+ [
47
+ 1.0,
48
+ 0.0,
49
+ 0.0,
50
+ 0.0
51
+ ],
52
+ [
53
+ 0.0,
54
+ 1.0,
55
+ 0.0,
56
+ 0.0
57
+ ],
58
+ [
59
+ 0.0,
60
+ 0.0,
61
+ 1.0,
62
+ 0.0
63
+ ],
64
+ [
65
+ 0.0,
66
+ 0.0,
67
+ 0.0,
68
+ 1.0
69
+ ]
70
+ ],
71
+ "functional_matrix": [],
72
+ "orientation_point": [
73
+ [
74
+ -1.0,
75
+ 1.2246467991473532e-16,
76
+ 1.4997597826618576e-32,
77
+ 2.403561242065095e-16
78
+ ],
79
+ [
80
+ 1.2246467991473532e-16,
81
+ 1.0,
82
+ 1.2246467991473532e-16,
83
+ 0.14719854857360576
84
+ ],
85
+ [
86
+ 0.0,
87
+ 1.2246467991473532e-16,
88
+ -1.0,
89
+ -1.7117513744652586e-08
90
+ ],
91
+ [
92
+ 0.0,
93
+ 0.0,
94
+ 0.0,
95
+ 1.0
96
+ ]
97
+ ],
98
+ "contact_points_group": [],
99
+ "contact_points_mask": [],
100
+ "contact_points_discription": [],
101
+ "target_point_discription": [
102
+ "Grasp pose at the top edge center."
103
+ ],
104
+ "functional_point_discription": [
105
+ ""
106
+ ],
107
+ "orientation_point_discription": [
108
+ "Grasp pose with adjustable offset and rotation."
109
+ ]
110
+ }
objects/vase_annotated/models.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import trimesh
2
+ import json
3
+ import numpy as np
4
+
5
+ PI = np.pi
6
+
7
+ # 可以是标量(各向同性)或三元组(各向异性)
8
+ # 例如:1.0 或 [0.08, 0.4, 0.08]
9
+ MODEL_SCALE = 0.004
10
+
11
+ GRASP_OFFSET = [0., 0., 0.] # 相对“顶部中心”的偏移
12
+ GRASP_ROT = [PI, 0.0, PI] # 欧拉角 (rx, ry, rz), 弧度
13
+
14
+ def _to_scale_vec(scale):
15
+ """将标量/数组统一成 3 维缩放向量 [sx, sy, sz]."""
16
+ arr = np.asarray(scale, dtype=float)
17
+ if arr.ndim == 0:
18
+ return [float(arr)] * 3
19
+ if arr.shape == (3,):
20
+ return arr.tolist()
21
+ raise ValueError(f"MODEL_SCALE 需为标量或长度为3的向量,收到形状: {arr.shape}")
22
+
23
+ def create_model_data(id="vase"):
24
+ file_path = f"./{id}.glb"
25
+ save_path = f"./model_data.json"
26
+
27
+ # 1) 读模型并融合为单一 Trimesh
28
+ with open(file_path, "rb") as f:
29
+ loaded = trimesh.load(f, file_type="glb")
30
+ mesh = loaded.to_mesh() if isinstance(loaded, trimesh.Scene) else loaded
31
+
32
+ # 2) 应用缩放(标量或三元向量都可)
33
+ scale_vec = _to_scale_vec(MODEL_SCALE)
34
+ mesh.apply_scale(scale_vec) # 支持 float 或 (3,) 向量
35
+
36
+ # 3) OBB 信息
37
+ obb = mesh.bounding_box_oriented
38
+ center = obb.centroid
39
+ ext = obb.extents
40
+ diag = np.linalg.norm(ext)
41
+
42
+ # 4) 计算“底部中心” -> 原点的平移
43
+ rotation_matrix = obb.transform[:3, :3]
44
+ bottom_center = center - rotation_matrix[:, 2] * (ext[2] / 2.0)
45
+ mesh.apply_translation(-bottom_center)
46
+
47
+ # 5) 更新 OBB
48
+ obb = mesh.bounding_box_oriented
49
+ center = obb.centroid
50
+ ext = obb.extents
51
+ rotation_matrix = obb.transform[:3, :3]
52
+
53
+ # 6) 顶部中心(现在模型底部已对齐原点,Z 轴正向为“上”)
54
+ top_center = center + rotation_matrix[:, 2] * (ext[2] / 2.0)
55
+
56
+ # 7) 组合抓取位姿:先平移到顶部中心 -> 旋转 -> 偏移
57
+ grasp_translation = trimesh.transformations.translation_matrix(top_center)
58
+ grasp_rotation = trimesh.transformations.euler_matrix(*GRASP_ROT)
59
+ grasp_offset = trimesh.transformations.translation_matrix(GRASP_OFFSET)
60
+ grasp_transform = grasp_translation @ grasp_rotation @ grasp_offset
61
+
62
+ # 8) 可视化
63
+ scene = trimesh.Scene(mesh)
64
+ grasp_sphere = trimesh.creation.icosphere(subdivisions=2, radius=diag * 0.05)
65
+ grasp_sphere.apply_transform(grasp_transform)
66
+ grasp_sphere.visual.vertex_colors = np.array([[1.0, 0.0, 0.0, 0.5]] * len(grasp_sphere.vertices))
67
+ scene.add_geometry(grasp_sphere)
68
+
69
+ grasp_axis = trimesh.creation.axis(origin_size=0.05, axis_length=diag * 0.2)
70
+ grasp_axis.apply_transform(grasp_transform)
71
+ scene.add_geometry(grasp_axis)
72
+
73
+ # 9) 保存 JSON(注意 scale 为三元向量)
74
+ data = {
75
+ "center": center.tolist(),
76
+ "extents": ext.tolist(),
77
+ "scale": scale_vec,
78
+ "contact_points_pose": [grasp_transform.tolist()],
79
+ "transform_matrix": trimesh.transformations.identity_matrix().tolist(),
80
+ "functional_matrix": [],
81
+ "orientation_point": grasp_transform.tolist(),
82
+ "contact_points_group": [],
83
+ "contact_points_mask": [],
84
+ "contact_points_discription": [],
85
+ "target_point_discription": ["Grasp pose at the top edge center."],
86
+ "functional_point_discription": [""],
87
+ "orientation_point_discription": ["Grasp pose with adjustable offset and rotation."]
88
+ }
89
+ with open(save_path, "w", encoding="utf-8") as f:
90
+ json.dump(data, f, indent=4, ensure_ascii=False, separators=(",", ": "))
91
+
92
+ # 10) 显示场景
93
+ scene.show()
94
+
95
+ if __name__ == "__main__":
96
+ create_model_data("vase")
objects/vase_annotated/vase.glb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:61d555a1a7b08993d89bda91da2f8c158cc1733d8fef111d3861b0222a3f90c2
3
+ size 17631184
scenes/table/table.glb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb0ebd8ad6438c1160f095d902bf55415f9d643f8c6990a186a052251fe7951a
3
+ size 3891588