| import trimesh |
| import numpy as np |
| from PIL import Image |
| import io |
|
|
| |
| def load_random_object(): |
| |
| object_path = "example.obj" |
| return trimesh.load(object_path) |
|
|
| |
| def capture_views(obj): |
| views = {} |
| |
| view_angles = { |
| 'front': [0, 0, 0], |
| 'top': [90, 0, 0], |
| 'bottom': [-90, 0, 0], |
| 'side': [0, 90, 0] |
| } |
|
|
| for view_name, angles in view_angles.items(): |
| |
| obj_copy = obj.copy() |
| |
| rotation_matrix = trimesh.transformations.euler_matrix(*np.radians(angles))[:3, :3] |
| obj_copy.apply_transform(rotation_matrix) |
|
|
| |
| scene = obj_copy.scene() |
| png_data = scene.save_image(resolution=[600, 600]) |
|
|
| |
| views[view_name] = Image.open(io.BytesIO(png_data)) |
| return views |
| |