(
input_path: str,
output_path: str,
num_images: int,
backend: str,
light_mode: str,
camera_pose: str,
camera_dist_min: float,
camera_dist_max: float,
fast_mode: bool,
)
| 449 | |
| 450 | |
| 451 | def save_rendering_dataset( |
| 452 | input_path: str, |
| 453 | output_path: str, |
| 454 | num_images: int, |
| 455 | backend: str, |
| 456 | light_mode: str, |
| 457 | camera_pose: str, |
| 458 | camera_dist_min: float, |
| 459 | camera_dist_max: float, |
| 460 | fast_mode: bool, |
| 461 | ): |
| 462 | assert light_mode in ["random", "uniform", "camera"] |
| 463 | assert camera_pose in ["random", "z-circular", "z-circular-elevated"] |
| 464 | |
| 465 | import_model(input_path) |
| 466 | bpy.context.scene.render.engine = backend |
| 467 | normalize_scene() |
| 468 | if light_mode == "random": |
| 469 | create_random_lights() |
| 470 | elif light_mode == "uniform": |
| 471 | create_uniform_light(backend) |
| 472 | create_camera() |
| 473 | create_vertex_color_shaders() |
| 474 | for i in range(num_images): |
| 475 | t = i / max(num_images - 1, 1) # same as np.linspace(0, 1, num_images) |
| 476 | place_camera( |
| 477 | t, |
| 478 | camera_pose_mode=camera_pose, |
| 479 | camera_dist_min=camera_dist_min, |
| 480 | camera_dist_max=camera_dist_max, |
| 481 | ) |
| 482 | if light_mode == "camera": |
| 483 | create_camera_light() |
| 484 | render_scene( |
| 485 | os.path.join(output_path, f"{i:05}.png"), |
| 486 | fast_mode=fast_mode, |
| 487 | ) |
| 488 | write_camera_metadata(os.path.join(output_path, f"{i:05}.json")) |
| 489 | with open(os.path.join(output_path, "info.json"), "w") as f: |
| 490 | info = dict( |
| 491 | backend=backend, |
| 492 | light_mode=light_mode, |
| 493 | fast_mode=fast_mode, |
| 494 | format_version=FORMAT_VERSION, |
| 495 | channels=["R", "G", "B", "A", "D"], |
| 496 | scale=0.5, # The scene is bounded by [-scale, scale]. |
| 497 | ) |
| 498 | json.dump(info, f) |
| 499 | |
| 500 | |
| 501 | def main(): |
no test coverage detected