| 24 | |
| 25 | |
| 26 | def plot_3d_motion(save_path, kinematic_tree, joints, title, figsize=(10, 10), fps=120, radius=4): |
| 27 | matplotlib.use('Agg') |
| 28 | |
| 29 | title_sp = title.split(' ') |
| 30 | if len(title_sp) > 20: |
| 31 | title = '\n'.join([' '.join(title_sp[:10]), ' '.join(title_sp[10:20]), ' '.join(title_sp[20:])]) |
| 32 | elif len(title_sp) > 10: |
| 33 | title = '\n'.join([' '.join(title_sp[:10]), ' '.join(title_sp[10:])]) |
| 34 | |
| 35 | def init(): |
| 36 | ax.set_xlim3d([-radius / 4, radius / 4]) |
| 37 | ax.set_ylim3d([0, radius / 2]) |
| 38 | ax.set_zlim3d([0, radius / 2]) |
| 39 | # print(title) |
| 40 | fig.suptitle(title, fontsize=20) |
| 41 | ax.grid(b=False) |
| 42 | |
| 43 | def plot_xzPlane(minx, maxx, miny, minz, maxz): |
| 44 | ## Plot a plane XZ |
| 45 | verts = [ |
| 46 | [minx, miny, minz], |
| 47 | [minx, miny, maxz], |
| 48 | [maxx, miny, maxz], |
| 49 | [maxx, miny, minz] |
| 50 | ] |
| 51 | xz_plane = Poly3DCollection([verts]) |
| 52 | xz_plane.set_facecolor((0.5, 0.5, 0.5, 0.5)) |
| 53 | ax.add_collection3d(xz_plane) |
| 54 | |
| 55 | # return ax |
| 56 | |
| 57 | # (seq_len, joints_num, 3) |
| 58 | data = joints.copy().reshape(len(joints), -1, 3) |
| 59 | fig = plt.figure(figsize=figsize) |
| 60 | ax = p3.Axes3D(fig) |
| 61 | init() |
| 62 | MINS = data.min(axis=0).min(axis=0) |
| 63 | MAXS = data.max(axis=0).max(axis=0) |
| 64 | colors = ['red', 'blue', 'black', 'red', 'blue', |
| 65 | 'darkblue', 'darkblue', 'darkblue', 'darkblue', 'darkblue', |
| 66 | 'darkred', 'darkred', 'darkred', 'darkred', 'darkred'] |
| 67 | frame_number = data.shape[0] |
| 68 | # print(data.shape) |
| 69 | |
| 70 | height_offset = MINS[1] |
| 71 | data[:, :, 1] -= height_offset |
| 72 | trajec = data[:, 0, [0, 2]] |
| 73 | |
| 74 | data[..., 0] -= data[:, 0:1, 0] |
| 75 | data[..., 2] -= data[:, 0:1, 2] |
| 76 | |
| 77 | # print(trajec.shape) |
| 78 | |
| 79 | def update(index): |
| 80 | # print(index) |
| 81 | ax.lines = [] |
| 82 | ax.collections = [] |
| 83 | ax.view_init(elev=120, azim=-90) |